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_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_
10 #include "base/callback_forward.h"
11 #include "base/id_map.h"
12 #include "base/memory/weak_ptr.h"
13 #include "content/browser/ssl/ssl_error_handler.h"
14 #include "content/public/browser/browser_message_filter.h"
15 #include "net/socket_stream/socket_stream.h"
24 class ResourceContext
;
25 class SocketStreamHost
;
27 // Dispatches ViewHostMsg_SocketStream_* messages sent from renderer.
28 // It also acts as SocketStream::Delegate so that it sends
29 // ViewMsg_SocketStream_* messages back to renderer.
30 class SocketStreamDispatcherHost
31 : public BrowserMessageFilter
,
32 public net::SocketStream::Delegate
,
33 public SSLErrorHandler::Delegate
{
35 typedef base::Callback
<net::URLRequestContext
*(ResourceType::Type
)>
36 GetRequestContextCallback
;
37 SocketStreamDispatcherHost(
38 int render_process_id
,
39 const GetRequestContextCallback
& request_context_callback
,
40 ResourceContext
* resource_context
);
42 // BrowserMessageFilter:
43 virtual bool OnMessageReceived(const IPC::Message
& message
,
44 bool* message_was_ok
) OVERRIDE
;
46 // Make this object inactive.
47 // Remove all active SocketStreamHost objects.
50 // SocketStream::Delegate:
51 virtual void OnConnected(net::SocketStream
* socket
,
52 int max_pending_send_allowed
) OVERRIDE
;
53 virtual void OnSentData(net::SocketStream
* socket
, int amount_sent
) OVERRIDE
;
54 virtual void OnReceivedData(net::SocketStream
* socket
,
55 const char* data
, int len
) OVERRIDE
;
56 virtual void OnClose(net::SocketStream
* socket
) OVERRIDE
;
57 virtual void OnError(const net::SocketStream
* socket
, int error
) OVERRIDE
;
58 virtual void OnSSLCertificateError(net::SocketStream
* socket
,
59 const net::SSLInfo
& ssl_info
,
61 virtual bool CanGetCookies(net::SocketStream
* socket
,
62 const GURL
& url
) OVERRIDE
;
63 virtual bool CanSetCookie(net::SocketStream
* request
,
65 const std::string
& cookie_line
,
66 net::CookieOptions
* options
) OVERRIDE
;
68 // SSLErrorHandler::Delegate methods:
69 virtual void CancelSSLRequest(const GlobalRequestID
& id
,
71 const net::SSLInfo
* ssl_info
) OVERRIDE
;
72 virtual void ContinueSSLRequest(const GlobalRequestID
& id
) OVERRIDE
;
75 virtual ~SocketStreamDispatcherHost();
78 // Message handlers called by OnMessageReceived.
79 void OnConnect(int render_frame_id
, const GURL
& url
, int socket_id
);
80 void OnSendData(int socket_id
, const std::vector
<char>& data
);
81 void OnCloseReq(int socket_id
);
83 void DeleteSocketStreamHost(int socket_id
);
85 net::URLRequestContext
* GetURLRequestContext();
87 IDMap
<SocketStreamHost
> hosts_
;
88 int render_process_id_
;
89 GetRequestContextCallback request_context_callback_
;
90 ResourceContext
* resource_context_
;
92 base::WeakPtrFactory
<SocketStreamDispatcherHost
> weak_ptr_factory_
;
95 DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcherHost
);
98 } // namespace content
100 #endif // CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_