1 // Copyright (c) 2011 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 CHROME_FRAME_PLUGIN_URL_REQUEST_H_
6 #define CHROME_FRAME_PLUGIN_URL_REQUEST_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/time.h"
13 #include "base/win/scoped_comptr.h"
14 #include "chrome_frame/chrome_frame_delegate.h"
15 #include "chrome_frame/urlmon_upload_data_stream.h"
16 #include "ipc/ipc_message.h"
17 #include "net/base/host_port_pair.h"
18 #include "net/base/upload_data.h"
19 #include "net/url_request/url_request_status.h"
20 #include "webkit/glue/resource_type.h"
22 class PluginUrlRequest
;
23 class PluginUrlRequestDelegate
;
24 class PluginUrlRequestManager
;
26 class DECLSPEC_NOVTABLE PluginUrlRequestDelegate
{ // NOLINT
28 virtual void OnResponseStarted(int request_id
, const char* mime_type
,
29 const char* headers
, int size
, base::Time last_modified
,
30 const std::string
& redirect_url
, int redirect_status
,
31 const net::HostPortPair
& socket_address
) = 0;
32 virtual void OnReadComplete(int request_id
, const std::string
& data
) = 0;
33 virtual void OnResponseEnd(int request_id
,
34 const net::URLRequestStatus
& status
) = 0;
35 virtual void AddPrivacyDataForUrl(const std::string
& url
,
36 const std::string
& policy_ref
,
38 virtual void OnCookiesRetrieved(bool success
, const GURL
& url
,
39 const std::string
& cookie_string
,
42 PluginUrlRequestDelegate() {}
43 ~PluginUrlRequestDelegate() {}
46 class DECLSPEC_NOVTABLE PluginUrlRequestManager
{ // NOLINT
48 PluginUrlRequestManager() : delegate_(NULL
), enable_frame_busting_(true) {}
49 virtual ~PluginUrlRequestManager() {}
51 void set_frame_busting(bool enable
) {
52 enable_frame_busting_
= enable
;
55 virtual void set_delegate(PluginUrlRequestDelegate
* delegate
) {
59 enum ThreadSafeFlags
{
60 NOT_THREADSAFE
= 0x00,
61 START_REQUEST_THREADSAFE
= 0x01,
62 STOP_REQUEST_THREADSAFE
= 0x02,
63 READ_REQUEST_THREADSAFE
= 0x04,
64 DOWNLOAD_REQUEST_THREADSAFE
= 0x08,
65 COOKIE_REQUEST_THREADSAFE
= 0x10
67 virtual ThreadSafeFlags
GetThreadSafeFlags() = 0;
69 // These are called directly from Automation Client when network related
70 // automation messages are received from Chrome.
71 // Strip 'tab' handle and forward to the virtual methods implemented by
73 void StartUrlRequest(int request_id
,
74 const AutomationURLRequest
& request_info
) {
75 StartRequest(request_id
, request_info
);
78 void ReadUrlRequest(int request_id
, int bytes_to_read
) {
79 ReadRequest(request_id
, bytes_to_read
);
82 void EndUrlRequest(int request_id
, const net::URLRequestStatus
& s
) {
83 EndRequest(request_id
);
86 void DownloadUrlRequestInHost(int request_id
) {
87 DownloadRequestInHost(request_id
);
90 void StopAllRequests() {
94 void GetCookiesFromHost(const GURL
& url
, int cookie_id
) {
95 GetCookiesForUrl(url
, cookie_id
);
98 void SetCookiesInHost(const GURL
& url
, const std::string
& cookie
) {
99 SetCookiesForUrl(url
, cookie
);
103 PluginUrlRequestDelegate
* delegate_
;
104 bool enable_frame_busting_
;
107 virtual void StartRequest(
108 int request_id
, const AutomationURLRequest
& request_info
) = 0;
109 virtual void ReadRequest(int request_id
, int bytes_to_read
) = 0;
110 virtual void EndRequest(int request_id
) = 0;
111 virtual void DownloadRequestInHost(int request_id
) = 0;
112 virtual void StopAll() = 0;
113 virtual void GetCookiesForUrl(const GURL
& url
, int cookie_id
) = 0;
114 virtual void SetCookiesForUrl(const GURL
& url
, const std::string
& cookie
) = 0;
117 // Used as base class. Holds Url request properties (url, method, referrer..)
118 class PluginUrlRequest
{
123 bool Initialize(PluginUrlRequestDelegate
* delegate
,
124 int remote_request_id
, const std::string
& url
, const std::string
& method
,
125 const std::string
& referrer
, const std::string
& extra_headers
,
126 net::UploadData
* upload_data
, ResourceType::Type resource_type
,
127 bool enable_frame_busting_
, int load_flags
);
131 return remote_request_id_
;
134 const std::string
& url() const {
138 const std::string
& method() const {
142 const std::string
& referrer() const {
146 const std::string
& extra_headers() const {
147 return extra_headers_
;
150 uint64
post_data_len() const {
151 return post_data_len_
;
154 bool is_chunked_upload() const {
155 return is_chunked_upload_
;
159 HRESULT
get_upload_data(IStream
** ret
) {
161 if (!upload_data_
.get())
163 *ret
= upload_data_
.get();
168 void set_url(const std::string
& url
) {
172 void ClearPostData() {
173 upload_data_
.Release();
178 bool enable_frame_busting_
;
180 PluginUrlRequestDelegate
* delegate_
;
181 int remote_request_id_
;
182 uint64 post_data_len_
;
185 std::string referrer_
;
186 std::string extra_headers_
;
187 ResourceType::Type resource_type_
;
189 base::win::ScopedComPtr
<IStream
> upload_data_
;
190 bool is_chunked_upload_
;
191 // Contains the ip address and port of the destination host.
192 net::HostPortPair socket_address_
;
195 #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_