summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/websocket_host.h
diff options
context:
space:
mode:
authorricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 02:27:51 +0000
committerricea@chromium.org <ricea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-08 02:27:51 +0000
commitdab33ebca0faeda44104cd87e9cd6e631194b0b2 (patch)
tree40c0b926ae9b2c0bf89d611b4fb67f34bc72fe86 /content/browser/renderer_host/websocket_host.h
parent72643a5fc7badce86d7763267196e51d8e744573 (diff)
downloadchromium_src-dab33ebca0faeda44104cd87e9cd6e631194b0b2.zip
chromium_src-dab33ebca0faeda44104cd87e9cd6e631194b0b2.tar.gz
chromium_src-dab33ebca0faeda44104cd87e9cd6e631194b0b2.tar.bz2
Create WebSocketDispatcherHost and WebSocketHost classes. WebSocketDispatcherHost creates, destroys and routes messages to WebSocketHost objects. WebSocketHost objects own and communicate with net::WebSocketChannel.
Input validation is delegated to net::WebSocketChannel. Unit tests seem to be unfashionable for these sorts of glue classes, so I haven't created any. The code to insert WebSocketDispatcherHost as a message filter is not included in this CL, so WebSocket IPCs are still unhandled and this CL changes no behaviour. There is a known bug in this CL that the WebSocketChannel can be deleted while it is looping through incoming messages, causing a use-after-free error. This will be fixed in a followup CL. See design for fix at https://docs.google.com/document/d/1fMxcEFiVj-H5vmuxhPqsxJAl98GS6_yZ-wqB6j9Wmy0/pub BUG=301353 Review URL: https://codereview.chromium.org/12637007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/websocket_host.h')
-rw-r--r--content/browser/renderer_host/websocket_host.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/content/browser/renderer_host/websocket_host.h b/content/browser/renderer_host/websocket_host.h
new file mode 100644
index 0000000..e2b7d12
--- /dev/null
+++ b/content/browser/renderer_host/websocket_host.h
@@ -0,0 +1,69 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
+#define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_
+
+#include <string>
+#include <vector>
+
+#include "base/memory/scoped_ptr.h"
+#include "content/common/websocket.h"
+
+class GURL;
+
+namespace net {
+class WebSocketChannel;
+class URLRequestContext;
+} // namespace net
+
+namespace IPC {
+class Message;
+} // namespace IPC
+
+namespace content {
+
+class WebSocketDispatcherHost;
+
+// Host of WebSocketChannel. The lifetime of an instance of this class is
+// completely controlled by the WebSocketDispatcherHost.
+class WebSocketHost {
+ public:
+ WebSocketHost(int routing_id,
+ WebSocketDispatcherHost* dispatcher,
+ net::URLRequestContext* url_request_context);
+ ~WebSocketHost();
+
+ // General message dispatch. WebSocketDispatcherHost::OnMessageReceived
+ // delegates to this method after looking up the |routing_id|.
+ bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok);
+
+ private:
+ // Handlers for each message type, dispatched by OnMessageReceived(), as
+ // defined in content/common/websocket_messages.h
+
+ void OnAddChannelRequest(const GURL& socket_url,
+ const std::vector<std::string>& requested_protocols,
+ const GURL& origin);
+
+ void OnSendFrame(bool fin,
+ WebSocketMessageType type,
+ const std::vector<char>& data);
+
+ void OnFlowControl(int64 quota);
+
+ void OnDropChannel(uint16 code, const std::string& reason);
+
+ // The channel we use to send events to the network.
+ scoped_ptr<net::WebSocketChannel> channel_;
+
+ // The ID used to route messages.
+ int routing_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebSocketHost);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_