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_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" 12#include "content/common/content_export.h" 13#include "content/common/websocket.h" 14 15class GURL; 16 17namespace url { 18class Origin; 19} // namespace url 20 21namespace net { 22class WebSocketChannel; 23class URLRequestContext; 24} // namespace net 25 26namespace IPC { 27class Message; 28} // namespace IPC 29 30namespace content { 31 32class WebSocketDispatcherHost; 33 34// Host of net::WebSocketChannel. The lifetime of an instance of this class is 35// completely controlled by the WebSocketDispatcherHost object. 36class CONTENT_EXPORT WebSocketHost { 37 public: 38 WebSocketHost(int routing_id, 39 WebSocketDispatcherHost* dispatcher, 40 net::URLRequestContext* url_request_context); 41 virtual ~WebSocketHost(); 42 43 // The renderer process is going away. 44 // This function is virtual for testing. 45 virtual void GoAway(); 46 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); 50 51 int routing_id() const { return routing_id_; } 52 53 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, 59 const url::Origin& origin, 60 int render_frame_id); 61 62 void OnSendFrame(bool fin, 63 WebSocketMessageType type, 64 const std::vector<char>& data); 65 66 void OnFlowControl(int64 quota); 67 68 void OnDropChannel(bool was_clean, uint16 code, const std::string& reason); 69 70 // The channel we use to send events to the network. 71 scoped_ptr<net::WebSocketChannel> channel_; 72 73 // 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 79 // The ID used to route messages. 80 const int routing_id_; 81 82 DISALLOW_COPY_AND_ASSIGN(WebSocketHost); 83}; 84 85} // namespace content 86 87#endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_HOST_H_ 88