aw_websocket_handshake_throttle_provider.cc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_websocket_handshake_throttle_provider.h"
  5. #include <utility>
  6. #include "base/feature_list.h"
  7. #include "base/memory/ptr_util.h"
  8. #include "components/safe_browsing/content/renderer/websocket_sb_handshake_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/platform/websocket_handshake_throttle.h"
  13. namespace android_webview {
  14. AwWebSocketHandshakeThrottleProvider::AwWebSocketHandshakeThrottleProvider(
  15. blink::ThreadSafeBrowserInterfaceBrokerProxy* broker) {
  16. DETACH_FROM_THREAD(thread_checker_);
  17. broker->GetInterface(safe_browsing_remote_.InitWithNewPipeAndPassReceiver());
  18. }
  19. AwWebSocketHandshakeThrottleProvider::~AwWebSocketHandshakeThrottleProvider() {
  20. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  21. }
  22. AwWebSocketHandshakeThrottleProvider::AwWebSocketHandshakeThrottleProvider(
  23. const AwWebSocketHandshakeThrottleProvider& other) {
  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::WebSocketHandshakeThrottleProvider>
  31. AwWebSocketHandshakeThrottleProvider::Clone(
  32. scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
  33. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  34. if (safe_browsing_remote_) {
  35. safe_browsing_.Bind(std::move(safe_browsing_remote_),
  36. std::move(task_runner));
  37. }
  38. return base::WrapUnique(new AwWebSocketHandshakeThrottleProvider(*this));
  39. }
  40. std::unique_ptr<blink::WebSocketHandshakeThrottle>
  41. AwWebSocketHandshakeThrottleProvider::CreateThrottle(
  42. int render_frame_id,
  43. scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
  44. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  45. if (safe_browsing_remote_) {
  46. safe_browsing_.Bind(std::move(safe_browsing_remote_),
  47. std::move(task_runner));
  48. }
  49. return std::make_unique<safe_browsing::WebSocketSBHandshakeThrottle>(
  50. safe_browsing_.get(), render_frame_id);
  51. }
  52. } // namespace android_webview