blob: 39c1e41edbed3d56985f1bba437898bfae234c80 [file] [log] [blame]
[email protected]dab33eb2013-10-08 02:27:511// 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_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
6#define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
7
8#include <string>
9#include <vector>
10
11#include "base/memory/scoped_ptr.h"
[email protected]d24a8472013-10-21 09:05:1012#include "content/common/content_export.h"
[email protected]dab33eb2013-10-08 02:27:5113#include "content/common/websocket.h"
14
15class GURL;
16
[email protected]7824cf82014-03-13 10:22:5717namespace url {
18class Origin;
19} // namespace url
20
[email protected]dab33eb2013-10-08 02:27:5121namespace net {
22class WebSocketChannel;
23class URLRequestContext;
24} // namespace net
25
26namespace IPC {
27class Message;
28} // namespace IPC
29
30namespace content {
31
32class WebSocketDispatcherHost;
33
[email protected]f485985e2013-10-24 13:47:4434// Host of net::WebSocketChannel. The lifetime of an instance of this class is
35// completely controlled by the WebSocketDispatcherHost object.
[email protected]d24a8472013-10-21 09:05:1036class CONTENT_EXPORT WebSocketHost {
[email protected]dab33eb2013-10-08 02:27:5137 public:
38 WebSocketHost(int routing_id,
39 WebSocketDispatcherHost* dispatcher,
40 net::URLRequestContext* url_request_context);
[email protected]d24a8472013-10-21 09:05:1041 virtual ~WebSocketHost();
[email protected]dab33eb2013-10-08 02:27:5142
[email protected]e778f322014-07-28 10:00:5343 // The renderer process is going away.
44 // This function is virtual for testing.
45 virtual void GoAway();
46
[email protected]dab33eb2013-10-08 02:27:5147 // General message dispatch. WebSocketDispatcherHost::OnMessageReceived
48 // delegates to this method after looking up the |routing_id|.
[email protected]e44d1342014-05-16 21:29:3349 virtual bool OnMessageReceived(const IPC::Message& message);
[email protected]dab33eb2013-10-08 02:27:5150
[email protected]e778f322014-07-28 10:00:5351 int routing_id() const { return routing_id_; }
52
[email protected]dab33eb2013-10-08 02:27:5153 private:
54 // Handlers for each message type, dispatched by OnMessageReceived(), as
55 // defined in content/common/websocket_messages.h
56
57 void OnAddChannelRequest(const GURL& socket_url,
58 const std::vector<std::string>& requested_protocols,
[email protected]a62449522014-06-05 11:11:1559 const url::Origin& origin,
60 int render_frame_id);
[email protected]dab33eb2013-10-08 02:27:5161
62 void OnSendFrame(bool fin,
63 WebSocketMessageType type,
64 const std::vector<char>& data);
65
66 void OnFlowControl(int64 quota);
67
[email protected]d7569442013-11-05 05:59:3968 void OnDropChannel(bool was_clean, uint16 code, const std::string& reason);
[email protected]dab33eb2013-10-08 02:27:5169
70 // The channel we use to send events to the network.
71 scoped_ptr<net::WebSocketChannel> channel_;
72
[email protected]a62449522014-06-05 11:11:1573 // The WebSocketHostDispatcher that created this object.
74 WebSocketDispatcherHost* const dispatcher_;
75
76 // The URL request context for the channel.
77 net::URLRequestContext* const url_request_context_;
78
[email protected]dab33eb2013-10-08 02:27:5179 // The ID used to route messages.
[email protected]a62449522014-06-05 11:11:1580 const int routing_id_;
[email protected]dab33eb2013-10-08 02:27:5181
82 DISALLOW_COPY_AND_ASSIGN(WebSocketHost);
83};
84
85} // namespace content
86
87#endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_