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/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/common/resource_type.h"
22 class PluginUrlRequest
;
23 class PluginUrlRequestDelegate
;
24 class PluginUrlRequestManager
;
26 class DECLSPEC_NOVTABLE PluginUrlRequestDelegate
{ // NOLINT
28 virtual void OnResponseStarted(
29 int request_id
, const char* mime_type
, const char* headers
, int size
,
30 base::Time last_modified
, const std::string
& redirect_url
,
31 int redirect_status
, const net::HostPortPair
& socket_address
,
32 uint64 upload_size
) = 0;
33 virtual void OnReadComplete(int request_id
, const std::string
& data
) = 0;
34 virtual void OnResponseEnd(int request_id
,
35 const net::URLRequestStatus
& status
) = 0;
36 virtual void AddPrivacyDataForUrl(const std::string
& url
,
37 const std::string
& policy_ref
,
39 virtual void OnCookiesRetrieved(bool success
, const GURL
& url
,
40 const std::string
& cookie_string
,
43 PluginUrlRequestDelegate() {}
44 ~PluginUrlRequestDelegate() {}
47 class DECLSPEC_NOVTABLE PluginUrlRequestManager
{ // NOLINT
49 PluginUrlRequestManager() : delegate_(NULL
), enable_frame_busting_(true) {}
50 virtual ~PluginUrlRequestManager() {}
52 void set_frame_busting(bool enable
) {
53 enable_frame_busting_
= enable
;
56 virtual void set_delegate(PluginUrlRequestDelegate
* delegate
) {
60 enum ThreadSafeFlags
{
61 NOT_THREADSAFE
= 0x00,
62 START_REQUEST_THREADSAFE
= 0x01,
63 STOP_REQUEST_THREADSAFE
= 0x02,
64 READ_REQUEST_THREADSAFE
= 0x04,
65 DOWNLOAD_REQUEST_THREADSAFE
= 0x08,
66 COOKIE_REQUEST_THREADSAFE
= 0x10
68 virtual ThreadSafeFlags
GetThreadSafeFlags() = 0;
70 // These are called directly from Automation Client when network related
71 // automation messages are received from Chrome.
72 // Strip 'tab' handle and forward to the virtual methods implemented by
74 void StartUrlRequest(int request_id
,
75 const AutomationURLRequest
& request_info
) {
76 StartRequest(request_id
, request_info
);
79 void ReadUrlRequest(int request_id
, int bytes_to_read
) {
80 ReadRequest(request_id
, bytes_to_read
);
83 void EndUrlRequest(int request_id
, const net::URLRequestStatus
& s
) {
84 EndRequest(request_id
);
87 void DownloadUrlRequestInHost(int request_id
) {
88 DownloadRequestInHost(request_id
);
91 void StopAllRequests() {
95 void GetCookiesFromHost(const GURL
& url
, int cookie_id
) {
96 GetCookiesForUrl(url
, cookie_id
);
99 void SetCookiesInHost(const GURL
& url
, const std::string
& cookie
) {
100 SetCookiesForUrl(url
, cookie
);
104 PluginUrlRequestDelegate
* delegate_
;
105 bool enable_frame_busting_
;
108 virtual void StartRequest(
109 int request_id
, const AutomationURLRequest
& request_info
) = 0;
110 virtual void ReadRequest(int request_id
, int bytes_to_read
) = 0;
111 virtual void EndRequest(int request_id
) = 0;
112 virtual void DownloadRequestInHost(int request_id
) = 0;
113 virtual void StopAll() = 0;
114 virtual void GetCookiesForUrl(const GURL
& url
, int cookie_id
) = 0;
115 virtual void SetCookiesForUrl(const GURL
& url
, const std::string
& cookie
) = 0;
118 // Used as base class. Holds Url request properties (url, method, referrer..)
119 class PluginUrlRequest
{
124 bool Initialize(PluginUrlRequestDelegate
* delegate
,
125 int remote_request_id
, const std::string
& url
, const std::string
& method
,
126 const std::string
& referrer
, const std::string
& extra_headers
,
127 net::UploadData
* upload_data
, ResourceType::Type resource_type
,
128 bool enable_frame_busting_
, int load_flags
);
132 return remote_request_id_
;
135 const std::string
& url() const {
139 const std::string
& method() const {
143 const std::string
& referrer() const {
147 const std::string
& extra_headers() const {
148 return extra_headers_
;
151 uint64
post_data_len() const {
152 return post_data_len_
;
155 bool is_chunked_upload() const {
156 return is_chunked_upload_
;
160 HRESULT
get_upload_data(IStream
** ret
) {
162 if (!upload_data_
.get())
164 *ret
= upload_data_
.get();
169 void set_url(const std::string
& url
) {
174 bool enable_frame_busting_
;
176 PluginUrlRequestDelegate
* delegate_
;
177 int remote_request_id_
;
178 uint64 post_data_len_
;
181 std::string referrer_
;
182 std::string extra_headers_
;
183 ResourceType::Type resource_type_
;
185 base::win::ScopedComPtr
<IStream
> upload_data_
;
186 bool is_chunked_upload_
;
187 // Contains the ip address and port of the destination host.
188 net::HostPortPair socket_address_
;
191 #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_