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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "content/common/content_export.h"
13 #include "content/common/websocket.h"
22 class WebSocketChannel
;
23 class URLRequestContext
;
32 class WebSocketDispatcherHost
;
34 // Host of net::WebSocketChannel. The lifetime of an instance of this class is
35 // completely controlled by the WebSocketDispatcherHost object.
36 class CONTENT_EXPORT WebSocketHost
{
38 WebSocketHost(int routing_id
,
39 WebSocketDispatcherHost
* dispatcher
,
40 net::URLRequestContext
* url_request_context
);
41 virtual ~WebSocketHost();
43 // The renderer process is going away.
44 // This function is virtual for testing.
45 virtual void GoAway();
47 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived
48 // delegates to this method after looking up the |routing_id|.
49 virtual bool OnMessageReceived(const IPC::Message
& message
);
51 int routing_id() const { return routing_id_
; }
54 // Handlers for each message type, dispatched by OnMessageReceived(), as
55 // defined in content/common/websocket_messages.h
57 void OnAddChannelRequest(const GURL
& socket_url
,
58 const std::vector
<std::string
>& requested_protocols
,
59 const url::Origin
& origin
,
62 void OnSendFrame(bool fin
,
63 WebSocketMessageType type
,
64 const std::vector
<char>& data
);
66 void OnFlowControl(int64 quota
);
68 void OnDropChannel(bool was_clean
, uint16 code
, const std::string
& reason
);
70 // The channel we use to send events to the network.
71 scoped_ptr
<net::WebSocketChannel
> channel_
;
73 // The WebSocketHostDispatcher that created this object.
74 WebSocketDispatcherHost
* const dispatcher_
;
76 // The URL request context for the channel.
77 net::URLRequestContext
* const url_request_context_
;
79 // The ID used to route messages.
80 const int routing_id_
;
82 DISALLOW_COPY_AND_ASSIGN(WebSocketHost
);
85 } // namespace content
87 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_