1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_WEBSOCKET_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_WEBSOCKET_HOST_H_
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "ppapi/host/host_message_context.h"
14 #include "ppapi/host/resource_host.h"
15 #include "ppapi/proxy/resource_message_params.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSocket.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSocketClient.h"
26 class RendererPpapiHost
;
28 class CONTENT_EXPORT PepperWebSocketHost
29 : public ppapi::host::ResourceHost
,
30 public NON_EXPORTED_BASE(::WebKit::WebSocketClient
) {
32 explicit PepperWebSocketHost(RendererPpapiHost
* host
,
34 PP_Resource resource
);
35 virtual ~PepperWebSocketHost();
37 virtual int32_t OnResourceMessageReceived(
38 const IPC::Message
& msg
,
39 ppapi::host::HostMessageContext
* context
) OVERRIDE
;
41 // WebSocketClient implementation.
42 virtual void didConnect();
43 virtual void didReceiveMessage(const WebKit::WebString
& message
);
44 virtual void didReceiveArrayBuffer(const WebKit::WebArrayBuffer
& binaryData
);
45 virtual void didReceiveMessageError();
46 virtual void didUpdateBufferedAmount(unsigned long buffered_amount
);
47 virtual void didStartClosingHandshake();
48 virtual void didClose(unsigned long unhandled_buffered_amount
,
49 ClosingHandshakeCompletionStatus status
,
51 const WebKit::WebString
& reason
);
53 // IPC message handlers.
54 int32_t OnHostMsgConnect(ppapi::host::HostMessageContext
* context
,
55 const std::string
& url
,
56 const std::vector
<std::string
>& protocols
);
57 int32_t OnHostMsgClose(ppapi::host::HostMessageContext
* context
,
59 const std::string
& reason
);
60 int32_t OnHostMsgSendText(ppapi::host::HostMessageContext
* context
,
61 const std::string
& message
);
62 int32_t OnHostMsgSendBinary(ppapi::host::HostMessageContext
* context
,
63 const std::vector
<uint8_t>& message
);
64 int32_t OnHostMsgFail(ppapi::host::HostMessageContext
* context
,
65 const std::string
& message
);
67 // Non-owning pointer.
68 RendererPpapiHost
* renderer_ppapi_host_
;
70 // IPC reply parameters.
71 ppapi::host::ReplyMessageContext connect_reply_
;
72 ppapi::host::ReplyMessageContext close_reply_
;
74 // The server URL to which this instance connects.
77 // A flag to indicate if opening handshake is going on.
80 // A flag to indicate if client initiated closing handshake is performed.
81 bool initiating_close_
;
83 // A flag to indicate if server initiated closing handshake is performed.
84 bool accepting_close_
;
86 // Becomes true if any error is detected. Incoming data will be disposed
87 // if this variable is true.
88 bool error_was_received_
;
90 // Keeps the WebKit side WebSocket object. This is used for calling WebKit
91 // side functions via WebKit API.
92 scoped_ptr
<WebKit::WebSocket
> websocket_
;
94 DISALLOW_COPY_AND_ASSIGN(PepperWebSocketHost
);
97 } // namespace content
99 #endif // CONTENT_RENDERER_PEPPER_PEPPER_WEBSOCKET_HOST_H_