| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_CHILD_WEBSOCKET_BRIDGE_H_ | 5 #ifndef CONTENT_CHILD_WEBSOCKET_BRIDGE_H_ |
| 6 #define CONTENT_CHILD_WEBSOCKET_BRIDGE_H_ | 6 #define CONTENT_CHILD_WEBSOCKET_BRIDGE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "content/common/websocket.h" | 13 #include "content/common/websocket.mojom.h" |
| 14 #include "ipc/ipc_message.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
| 15 #include "third_party/WebKit/public/platform/WebVector.h" | 15 #include "third_party/WebKit/public/platform/WebVector.h" |
| 16 #include "third_party/WebKit/public/platform/modules/websockets/WebSocketHandle.
h" | 16 #include "third_party/WebKit/public/platform/modules/websockets/WebSocketHandle.
h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 class WebSecurityOrigin; | 19 class WebSecurityOrigin; |
| 20 class WebString; | 20 class WebString; |
| 21 class WebURL; | 21 class WebURL; |
| 22 } // namespace blink | 22 } // namespace blink |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 class ServiceRegistry; |
| 25 | 26 |
| 26 class WebSocketBridge : public blink::WebSocketHandle { | 27 class WebSocketBridge : public blink::WebSocketHandle, |
| 28 public mojom::WebSocketClient { |
| 27 public: | 29 public: |
| 28 WebSocketBridge(); | 30 WebSocketBridge(); |
| 29 | 31 |
| 30 // Handles an IPC message from the browser process. | 32 void Initialize(ServiceRegistry* registry); |
| 31 bool OnMessageReceived(const IPC::Message& message); | |
| 32 | 33 |
| 33 // WebSocketHandle functions. | 34 // WebSocketHandle functions. |
| 34 void connect(const blink::WebURL& url, | 35 void connect(const blink::WebURL& url, |
| 35 const blink::WebVector<blink::WebString>& protocols, | 36 const blink::WebVector<blink::WebString>& protocols, |
| 36 const blink::WebSecurityOrigin& origin, | 37 const blink::WebSecurityOrigin& origin, |
| 37 blink::WebSocketHandleClient* client) override; | 38 blink::WebSocketHandleClient* client) override; |
| 38 void send(bool fin, | 39 void send(bool fin, |
| 39 WebSocketHandle::MessageType type, | 40 WebSocketHandle::MessageType type, |
| 40 const char* data, | 41 const char* data, |
| 41 size_t size) override; | 42 size_t size) override; |
| 42 void flowControl(int64_t quota) override; | 43 void flowControl(int64_t quota) override; |
| 43 void close(unsigned short code, const blink::WebString& reason) override; | 44 void close(unsigned short code, const blink::WebString& reason) override; |
| 44 | 45 |
| 45 void Disconnect(); | 46 void Disconnect(); |
| 46 | 47 |
| 47 void set_render_frame_id(int id) { | |
| 48 render_frame_id_ = id; | |
| 49 } | |
| 50 | |
| 51 private: | 48 private: |
| 52 ~WebSocketBridge() override; | 49 ~WebSocketBridge() override; |
| 53 | 50 |
| 54 void DidConnect(const std::string& selected_protocol, | 51 void OnFailChannel(const mojo::String& reason) override; |
| 55 const std::string& extensions); | 52 void OnStartOpeningHandshake( |
| 56 void DidStartOpeningHandshake(const WebSocketHandshakeRequest& request); | 53 mojom::WebSocketHandshakeRequestPtr request) override; |
| 57 void DidFinishOpeningHandshake(const WebSocketHandshakeResponse& response); | 54 void OnFinishOpeningHandshake( |
| 58 void DidFail(const std::string& message); | 55 mojom::WebSocketHandshakeResponsePtr response) override; |
| 59 void DidReceiveData(bool fin, | 56 void OnAddChannelResponse(const mojo::String& selected_protocol, |
| 60 WebSocketMessageType type, | 57 const mojo::String& extensions) override; |
| 61 const std::vector<char>& data); | 58 void OnBlobSent() override; |
| 62 void DidReceiveFlowControl(int64_t quota); | 59 void OnDataFrame(bool fin, mojom::WebSocketMessageType type, |
| 63 void DidClose(bool was_clean, unsigned short code, const std::string& reason); | 60 mojo::Array<uint8_t> data) override; |
| 64 void DidStartClosingHandshake(); | 61 void OnFlowControl(int64_t quota) override; |
| 62 void OnDropChannel(bool was_clean, uint16_t code, |
| 63 const mojo::String& reason) override; |
| 64 void OnClosingHandshake() override; |
| 65 | 65 |
| 66 int channel_id_; | |
| 67 int render_frame_id_; | |
| 68 blink::WebSocketHandleClient* client_; | 66 blink::WebSocketHandleClient* client_; |
| 69 | 67 |
| 70 static const int kInvalidChannelId = -1; | 68 mojom::WebSocketPtr websocket_; |
| 69 mojo::Binding<mojom::WebSocketClient> client_binding_; |
| 71 }; | 70 }; |
| 72 | 71 |
| 73 } // namespace content | 72 } // namespace content |
| 74 | 73 |
| 75 #endif // CONTENT_CHILD_WEBSOCKET_BRIDGE_H_ | 74 #endif // CONTENT_CHILD_WEBSOCKET_BRIDGE_H_ |
| OLD | NEW |