cast_url_loader_throttle_provider.cc 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2020 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 "chromecast/renderer/cast_url_loader_throttle_provider.h"
  5. #include <string>
  6. #include <utility>
  7. #include "base/callback.h"
  8. #include "base/memory/ptr_util.h"
  9. #include "chromecast/common/activity_filtering_url_loader_throttle.h"
  10. #include "chromecast/renderer/cast_activity_url_filter_manager.h"
  11. #include "chromecast/renderer/cast_url_rewrite_rules_store.h"
  12. #include "components/url_rewrite/common/url_loader_throttle.h"
  13. #include "third_party/blink/public/common/loader/url_loader_throttle.h"
  14. namespace chromecast {
  15. CastURLLoaderThrottleProvider::CastURLLoaderThrottleProvider(
  16. blink::URLLoaderThrottleProviderType type,
  17. CastActivityUrlFilterManager* url_filter_manager,
  18. CastURLRewriteRulesStore* url_rewrite_rules_store,
  19. base::RepeatingCallback<bool(base::StringPiece)>
  20. is_cors_exempt_header_callback)
  21. : type_(type),
  22. cast_activity_url_filter_manager_(url_filter_manager),
  23. url_rewrite_rules_store_(url_rewrite_rules_store),
  24. is_cors_exempt_header_callback_(
  25. std::move(is_cors_exempt_header_callback)) {
  26. DCHECK(url_rewrite_rules_store_);
  27. DETACH_FROM_THREAD(thread_checker_);
  28. }
  29. CastURLLoaderThrottleProvider::~CastURLLoaderThrottleProvider() {
  30. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  31. }
  32. CastURLLoaderThrottleProvider::CastURLLoaderThrottleProvider(
  33. const chromecast::CastURLLoaderThrottleProvider& other)
  34. : type_(other.type_),
  35. cast_activity_url_filter_manager_(
  36. other.cast_activity_url_filter_manager_),
  37. url_rewrite_rules_store_(other.url_rewrite_rules_store_),
  38. is_cors_exempt_header_callback_(other.is_cors_exempt_header_callback_) {
  39. DETACH_FROM_THREAD(thread_checker_);
  40. }
  41. std::unique_ptr<blink::URLLoaderThrottleProvider>
  42. CastURLLoaderThrottleProvider::Clone() {
  43. return base::WrapUnique(new CastURLLoaderThrottleProvider(*this));
  44. }
  45. blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>>
  46. CastURLLoaderThrottleProvider::CreateThrottles(
  47. int render_frame_id,
  48. const blink::WebURLRequest& request) {
  49. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  50. blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>> throttles;
  51. if (cast_activity_url_filter_manager_) {
  52. auto* activity_url_filter =
  53. cast_activity_url_filter_manager_->GetActivityUrlFilterForRenderFrameID(
  54. render_frame_id);
  55. if (activity_url_filter) {
  56. throttles.emplace_back(
  57. std::make_unique<ActivityFilteringURLLoaderThrottle>(
  58. activity_url_filter));
  59. }
  60. }
  61. auto rules =
  62. url_rewrite_rules_store_->GetUrlRequestRewriteRules(render_frame_id);
  63. if (rules) {
  64. throttles.emplace_back(std::make_unique<url_rewrite::URLLoaderThrottle>(
  65. rules, is_cors_exempt_header_callback_));
  66. }
  67. return throttles;
  68. }
  69. void CastURLLoaderThrottleProvider::SetOnline(bool is_online) {}
  70. } // namespace chromecast