cast_websocket_handshake_throttle_provider.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #ifndef CHROMECAST_RENDERER_CAST_WEBSOCKET_HANDSHAKE_THROTTLE_PROVIDER_H_
  5. #define CHROMECAST_RENDERER_CAST_WEBSOCKET_HANDSHAKE_THROTTLE_PROVIDER_H_
  6. #include <memory>
  7. #include "base/threading/thread_checker.h"
  8. #include "chromecast/renderer/cast_activity_url_filter_manager.h"
  9. #include "third_party/blink/public/platform/websocket_handshake_throttle_provider.h"
  10. namespace chromecast {
  11. // This class allows cast_shell to provide a WebSocketHandshakeThrottle
  12. // implementation to delay or block WebSocket handshakes.
  13. // This must be constructed on the render thread, and then used and destructed
  14. // on a single thread, which can be different from the render thread.
  15. class CastWebSocketHandshakeThrottleProvider
  16. : public blink::WebSocketHandshakeThrottleProvider {
  17. public:
  18. explicit CastWebSocketHandshakeThrottleProvider(
  19. CastActivityUrlFilterManager* url_filter_manager);
  20. CastWebSocketHandshakeThrottleProvider& operator=(
  21. const CastWebSocketHandshakeThrottleProvider&) = delete;
  22. ~CastWebSocketHandshakeThrottleProvider() override;
  23. // blink::WebSocketHandshakeThrottleProvider implementation:
  24. std::unique_ptr<blink::WebSocketHandshakeThrottleProvider> Clone(
  25. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  26. std::unique_ptr<blink::WebSocketHandshakeThrottle> CreateThrottle(
  27. int render_frame_id,
  28. scoped_refptr<base::SingleThreadTaskRunner> task_runner) override;
  29. private:
  30. // This copy constructor works in conjunction with Clone(), not intended for
  31. // general use.
  32. CastWebSocketHandshakeThrottleProvider(
  33. const CastWebSocketHandshakeThrottleProvider& other);
  34. CastActivityUrlFilterManager* const cast_activity_url_filter_manager_;
  35. THREAD_CHECKER(thread_checker_);
  36. };
  37. } // namespace chromecast
  38. #endif // CHROMECAST_RENDERER_CAST_WEBSOCKET_HANDSHAKE_THROTTLE_PROVIDER_H_