web_engine_url_loader_throttle_provider.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "fuchsia_web/webengine/renderer/web_engine_url_loader_throttle_provider.h"
  5. #include "components/url_rewrite/common/url_loader_throttle.h"
  6. #include "components/url_rewrite/mojom/url_request_rewrite.mojom.h"
  7. #include "content/public/renderer/render_frame.h"
  8. #include "fuchsia_web/webengine/common/cors_exempt_headers.h"
  9. #include "fuchsia_web/webengine/renderer/web_engine_content_renderer_client.h"
  10. WebEngineURLLoaderThrottleProvider::WebEngineURLLoaderThrottleProvider(
  11. WebEngineContentRendererClient* content_renderer_client)
  12. : content_renderer_client_(content_renderer_client) {
  13. DETACH_FROM_SEQUENCE(sequence_checker_);
  14. }
  15. WebEngineURLLoaderThrottleProvider::~WebEngineURLLoaderThrottleProvider() {
  16. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  17. }
  18. std::unique_ptr<blink::URLLoaderThrottleProvider>
  19. WebEngineURLLoaderThrottleProvider::Clone() {
  20. // This should only happen for service workers, which we do not support here.
  21. NOTREACHED();
  22. return nullptr;
  23. }
  24. blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>>
  25. WebEngineURLLoaderThrottleProvider::CreateThrottles(
  26. int render_frame_id,
  27. const blink::WebURLRequest& request) {
  28. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  29. DCHECK_NE(render_frame_id, MSG_ROUTING_NONE);
  30. blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>> throttles;
  31. const auto& rules =
  32. content_renderer_client_
  33. ->GetWebEngineRenderFrameObserverForRenderFrameId(render_frame_id)
  34. ->url_request_rules_receiver()
  35. ->GetCachedRules();
  36. if (rules) {
  37. throttles.emplace_back(std::make_unique<url_rewrite::URLLoaderThrottle>(
  38. rules, base::BindRepeating(&IsHeaderCorsExempt)));
  39. }
  40. return throttles;
  41. }
  42. void WebEngineURLLoaderThrottleProvider::SetOnline(bool is_online) {}