Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_CONNECTOR_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_CONNECTOR_IMPL_H_ |
| 7 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 8 | #include <optional> |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 11 | |
Danil Somsikov | 4c7ee57 | 2021-07-01 12:02:04 | [diff] [blame] | 12 | #include "base/unguessable_token.h" |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 13 | #include "content/public/browser/content_browser_client.h" |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 14 | #include "net/base/isolation_info.h" |
Chris Fredrickson | 9ffdf5b | 2024-07-09 20:05:09 | [diff] [blame] | 15 | #include "net/storage_access_api/status.h" |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 16 | #include "services/network/public/mojom/network_context.mojom.h" |
| 17 | #include "services/network/public/mojom/websocket.mojom.h" |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 18 | #include "third_party/blink/public/mojom/websockets/websocket_connector.mojom.h" |
| 19 | #include "url/origin.h" |
| 20 | |
| 21 | class GURL; |
| 22 | |
| 23 | namespace content { |
| 24 | |
| 25 | class WebSocketConnectorImpl final : public blink::mojom::WebSocketConnector { |
| 26 | public: |
| 27 | using WebSocketFactory = ContentBrowserClient::WebSocketFactory; |
| 28 | |
| 29 | // Called on the UI thread. |
| 30 | // - For frames, |frame_id| should be their own id. |
| 31 | // - For dedicated workers, |frame_id| should be its response document's |
| 32 | // frame's id. |
| 33 | // - For shared workers and service workers, |frame_id| should be |
Tom Sepez | cc69c44 | 2025-07-17 02:00:30 | [diff] [blame] | 34 | // IPC::mojom::kRoutingIdNone because they do not have a frame. |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 35 | WebSocketConnectorImpl(int process_id, |
| 36 | int frame_id, |
Ehimare Okoyomon | 4446d8c | 2019-10-23 12:47:32 | [diff] [blame] | 37 | const url::Origin& origin, |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 38 | const net::IsolationInfo& isolation_info); |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 39 | ~WebSocketConnectorImpl() override; |
| 40 | |
| 41 | // WebSocketConnector implementation |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 42 | void Connect(const GURL& url, |
| 43 | const std::vector<std::string>& requested_protocols, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 44 | const net::SiteForCookies& site_for_cookies, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 45 | const std::optional<std::string>& user_agent, |
Chris Fredrickson | 9ffdf5b | 2024-07-09 20:05:09 | [diff] [blame] | 46 | net::StorageAccessApiStatus storage_access_api_status, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 47 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
Danil Somsikov | 4c7ee57 | 2021-07-01 12:02:04 | [diff] [blame] | 48 | handshake_client, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 49 | const std::optional<base::UnguessableToken>& |
Danil Somsikov | 4c7ee57 | 2021-07-01 12:02:04 | [diff] [blame] | 50 | throttling_profile_id) override; |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | static void ConnectCalledByContentBrowserClient( |
| 54 | const std::vector<std::string>& requested_protocols, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 55 | const net::SiteForCookies& site_for_cookies, |
Chris Fredrickson | 9ffdf5b | 2024-07-09 20:05:09 | [diff] [blame] | 56 | net::StorageAccessApiStatus storage_access_api_status, |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 57 | const net::IsolationInfo& isolation_info, |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 58 | int process_id, |
| 59 | int frame_id, |
| 60 | const url::Origin& origin, |
| 61 | uint32_t options, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 62 | std::optional<base::UnguessableToken> throttling_profile_id, |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 63 | const GURL& url, |
| 64 | std::vector<network::mojom::HttpHeaderPtr> additional_headers, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 65 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
| 66 | handshake_client, |
Dave Tapuska | cb5cbcb | 2021-02-09 19:10:45 | [diff] [blame] | 67 | mojo::PendingRemote<network::mojom::WebSocketAuthenticationHandler> |
| 68 | auth_handler, |
Julie Jeongeun Kim | 147816a | 2019-08-28 00:43:47 | [diff] [blame] | 69 | mojo::PendingRemote<network::mojom::TrustedHeaderClient> |
| 70 | trusted_header_client); |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 71 | |
| 72 | const int process_id_; |
| 73 | const int frame_id_; |
| 74 | const url::Origin origin_; |
Matt Menke | 29a538d | 2020-04-29 16:12:17 | [diff] [blame] | 75 | const net::IsolationInfo isolation_info_; |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace content |
| 79 | |
| 80 | #endif // CONTENT_BROWSER_WEBSOCKETS_WEBSOCKET_CONNECTOR_IMPL_H_ |