aw_url_loader_throttle_provider.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright 2018 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 "android_webview/renderer/aw_url_loader_throttle_provider.h"
  5. #include <memory>
  6. #include "base/feature_list.h"
  7. #include "base/memory/ptr_util.h"
  8. #include "components/safe_browsing/content/renderer/renderer_url_loader_throttle.h"
  9. #include "components/safe_browsing/core/common/features.h"
  10. #include "content/public/common/content_features.h"
  11. #include "content/public/renderer/render_thread.h"
  12. #include "third_party/blink/public/common/loader/resource_type_util.h"
  13. namespace android_webview {
  14. AwURLLoaderThrottleProvider::AwURLLoaderThrottleProvider(
  15. blink::ThreadSafeBrowserInterfaceBrokerProxy* broker,
  16. blink::URLLoaderThrottleProviderType type)
  17. : type_(type) {
  18. DETACH_FROM_THREAD(thread_checker_);
  19. broker->GetInterface(safe_browsing_remote_.InitWithNewPipeAndPassReceiver());
  20. }
  21. AwURLLoaderThrottleProvider::AwURLLoaderThrottleProvider(
  22. const AwURLLoaderThrottleProvider& other)
  23. : type_(other.type_) {
  24. DETACH_FROM_THREAD(thread_checker_);
  25. if (other.safe_browsing_) {
  26. other.safe_browsing_->Clone(
  27. safe_browsing_remote_.InitWithNewPipeAndPassReceiver());
  28. }
  29. }
  30. std::unique_ptr<blink::URLLoaderThrottleProvider>
  31. AwURLLoaderThrottleProvider::Clone() {
  32. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  33. if (safe_browsing_remote_)
  34. safe_browsing_.Bind(std::move(safe_browsing_remote_));
  35. return base::WrapUnique(new AwURLLoaderThrottleProvider(*this));
  36. }
  37. AwURLLoaderThrottleProvider::~AwURLLoaderThrottleProvider() {
  38. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  39. }
  40. blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>>
  41. AwURLLoaderThrottleProvider::CreateThrottles(
  42. int render_frame_id,
  43. const blink::WebURLRequest& request) {
  44. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  45. blink::WebVector<std::unique_ptr<blink::URLLoaderThrottle>> throttles;
  46. // Some throttles have already been added in the browser for frame resources.
  47. // Don't add them for frame requests.
  48. bool is_frame_resource =
  49. blink::IsRequestDestinationFrame(request.GetRequestDestination());
  50. DCHECK(!is_frame_resource ||
  51. type_ == blink::URLLoaderThrottleProviderType::kFrame);
  52. if (!is_frame_resource) {
  53. if (safe_browsing_remote_)
  54. safe_browsing_.Bind(std::move(safe_browsing_remote_));
  55. throttles.emplace_back(
  56. std::make_unique<safe_browsing::RendererURLLoaderThrottle>(
  57. safe_browsing_.get(), render_frame_id));
  58. }
  59. return throttles;
  60. }
  61. void AwURLLoaderThrottleProvider::SetOnline(bool is_online) {}
  62. } // namespace android_webview