Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / child / websocket_bridge.h
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_CHILD_WEBSOCKET_BRIDGE_H_
6 #define CONTENT_CHILD_WEBSOCKET_BRIDGE_H_
7
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "content/common/websocket.h"
14 #include "ipc/ipc_message.h"
15 #include "third_party/WebKit/public/platform/WebSocketHandle.h"
16 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/platform/WebURL.h"
18 #include "third_party/WebKit/public/platform/WebVector.h"
19
20 namespace content {
21
22 class WebSocketBridge : public blink::WebSocketHandle {
23  public:
24   WebSocketBridge();
25
26   // Handles an IPC message from the browser process.
27   bool OnMessageReceived(const IPC::Message& message);
28
29   // WebSocketHandle functions.
30   virtual void connect(const blink::WebURL& url,
31                        const blink::WebVector<blink::WebString>& protocols,
32                        const blink::WebString& origin,
33                        blink::WebSocketHandleClient* client) OVERRIDE;
34   virtual void send(bool fin,
35                     WebSocketHandle::MessageType type,
36                     const char* data,
37                     size_t size) OVERRIDE;
38   virtual void flowControl(int64_t quota) OVERRIDE;
39   virtual void close(unsigned short code,
40                      const blink::WebString& reason) OVERRIDE;
41
42   virtual void Disconnect();
43
44  private:
45   virtual ~WebSocketBridge();
46
47   void DidConnect(bool fail,
48                   const std::string& selected_protocol,
49                   const std::string& extensions);
50   void DidStartOpeningHandshake(const WebSocketHandshakeRequest& request);
51   void DidFinishOpeningHandshake(const WebSocketHandshakeResponse& response);
52   void DidFail(const std::string& message);
53   void DidReceiveData(bool fin,
54                       WebSocketMessageType type,
55                       const std::vector<char>& data);
56   void DidReceiveFlowControl(int64_t quota);
57   void DidClose(bool was_clean, unsigned short code, const std::string& reason);
58   void DidStartClosingHandshake();
59
60   int channel_id_;
61   blink::WebSocketHandleClient* client_;
62
63   static const int kInvalidChannelId = -1;
64 };
65
66 }  // namespace content
67
68 #endif  // CONTENT_CHILD_WEBSOCKET_BRIDGE_H_