[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 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 CHROME_FRAME_PLUGIN_URL_REQUEST_H_ |
| 6 | #define CHROME_FRAME_PLUGIN_URL_REQUEST_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 12 | #include "base/time.h" |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 13 | #include "base/win/scoped_comptr.h" |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 14 | #include "chrome_frame/chrome_frame_delegate.h" |
[email protected] | 4736610c | 2011-03-04 06:43:35 | [diff] [blame] | 15 | #include "chrome_frame/urlmon_upload_data_stream.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 16 | #include "ipc/ipc_message.h" |
[email protected] | 0d282c2e | 2011-02-24 20:42:51 | [diff] [blame] | 17 | #include "net/base/host_port_pair.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 18 | #include "net/base/upload_data.h" |
| 19 | #include "net/url_request/url_request_status.h" |
[email protected] | 6063340 | 2010-10-01 16:33:37 | [diff] [blame] | 20 | #include "webkit/glue/resource_type.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 21 | |
| 22 | class PluginUrlRequest; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 23 | class PluginUrlRequestDelegate; |
| 24 | class PluginUrlRequestManager; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 25 | |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 26 | class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 27 | public: |
[email protected] | 7335ab0 | 2012-08-30 22:30:42 | [diff] [blame] | 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; |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 33 | virtual void OnReadComplete(int request_id, const std::string& data) = 0; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 34 | virtual void OnResponseEnd(int request_id, |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 35 | const net::URLRequestStatus& status) = 0; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 36 | virtual void AddPrivacyDataForUrl(const std::string& url, |
| 37 | const std::string& policy_ref, |
| 38 | int32 flags) {} |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 39 | virtual void OnCookiesRetrieved(bool success, const GURL& url, |
| 40 | const std::string& cookie_string, |
| 41 | int cookie_id) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 42 | protected: |
| 43 | PluginUrlRequestDelegate() {} |
| 44 | ~PluginUrlRequestDelegate() {} |
| 45 | }; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 46 | |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 47 | class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 48 | public: |
| 49 | PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {} |
| 50 | virtual ~PluginUrlRequestManager() {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 51 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 52 | void set_frame_busting(bool enable) { |
| 53 | enable_frame_busting_ = enable; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 54 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 55 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 56 | virtual void set_delegate(PluginUrlRequestDelegate* delegate) { |
| 57 | delegate_ = delegate; |
| 58 | } |
| 59 | |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 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 |
| 67 | }; |
| 68 | virtual ThreadSafeFlags GetThreadSafeFlags() = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 69 | |
| 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 |
| 73 | // derived classes. |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 74 | void StartUrlRequest(int request_id, |
| 75 | const AutomationURLRequest& request_info) { |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 76 | StartRequest(request_id, request_info); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 77 | } |
| 78 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 79 | void ReadUrlRequest(int request_id, int bytes_to_read) { |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 80 | ReadRequest(request_id, bytes_to_read); |
| 81 | } |
| 82 | |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 83 | void EndUrlRequest(int request_id, const net::URLRequestStatus& s) { |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 84 | EndRequest(request_id); |
| 85 | } |
| 86 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 87 | void DownloadUrlRequestInHost(int request_id) { |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 88 | DownloadRequestInHost(request_id); |
| 89 | } |
| 90 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 91 | void StopAllRequests() { |
| 92 | StopAll(); |
| 93 | } |
| 94 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 95 | void GetCookiesFromHost(const GURL& url, int cookie_id) { |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 96 | GetCookiesForUrl(url, cookie_id); |
[email protected] | c82d09a2 | 2010-03-26 23:28:40 | [diff] [blame] | 97 | } |
| 98 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 99 | void SetCookiesInHost(const GURL& url, const std::string& cookie) { |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 100 | SetCookiesForUrl(url, cookie); |
[email protected] | c82d09a2 | 2010-03-26 23:28:40 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 103 | protected: |
| 104 | PluginUrlRequestDelegate* delegate_; |
| 105 | bool enable_frame_busting_; |
| 106 | |
| 107 | private: |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 108 | virtual void StartRequest( |
| 109 | int request_id, const AutomationURLRequest& request_info) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 110 | virtual void ReadRequest(int request_id, int bytes_to_read) = 0; |
| 111 | virtual void EndRequest(int request_id) = 0; |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 112 | virtual void DownloadRequestInHost(int request_id) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 113 | virtual void StopAll() = 0; |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 114 | virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0; |
| 115 | virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | // Used as base class. Holds Url request properties (url, method, referrer..) |
| 119 | class PluginUrlRequest { |
| 120 | public: |
| 121 | PluginUrlRequest(); |
| 122 | ~PluginUrlRequest(); |
| 123 | |
| 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, |
[email protected] | 6063340 | 2010-10-01 16:33:37 | [diff] [blame] | 127 | net::UploadData* upload_data, ResourceType::Type resource_type, |
[email protected] | d9ffd55 | 2010-10-21 18:45:33 | [diff] [blame] | 128 | bool enable_frame_busting_, int load_flags); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 129 | |
| 130 | // Accessors. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 131 | int id() const { |
| 132 | return remote_request_id_; |
| 133 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 134 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 135 | const std::string& url() const { |
| 136 | return url_; |
| 137 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 138 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 139 | const std::string& method() const { |
| 140 | return method_; |
| 141 | } |
[email protected] | 885362ca | 2009-10-27 21:50:07 | [diff] [blame] | 142 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 143 | const std::string& referrer() const { |
| 144 | return referrer_; |
| 145 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 146 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 147 | const std::string& extra_headers() const { |
| 148 | return extra_headers_; |
| 149 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 150 | |
| 151 | uint64 post_data_len() const { |
| 152 | return post_data_len_; |
| 153 | } |
| 154 | |
[email protected] | 8f17016 | 2011-01-26 23:42:42 | [diff] [blame] | 155 | bool is_chunked_upload() const { |
| 156 | return is_chunked_upload_; |
| 157 | } |
| 158 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 159 | protected: |
[email protected] | 4736610c | 2011-03-04 06:43:35 | [diff] [blame] | 160 | HRESULT get_upload_data(IStream** ret) { |
| 161 | DCHECK(ret); |
| 162 | if (!upload_data_.get()) |
| 163 | return S_FALSE; |
| 164 | *ret = upload_data_.get(); |
| 165 | (*ret)->AddRef(); |
| 166 | return S_OK; |
| 167 | } |
| 168 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 169 | void set_url(const std::string& url) { |
| 170 | url_ = url; |
| 171 | } |
| 172 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 173 | void SendData(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 174 | bool enable_frame_busting_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 175 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 176 | PluginUrlRequestDelegate* delegate_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 177 | int remote_request_id_; |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 178 | uint64 post_data_len_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 179 | std::string url_; |
| 180 | std::string method_; |
| 181 | std::string referrer_; |
| 182 | std::string extra_headers_; |
[email protected] | 6063340 | 2010-10-01 16:33:37 | [diff] [blame] | 183 | ResourceType::Type resource_type_; |
[email protected] | d9ffd55 | 2010-10-21 18:45:33 | [diff] [blame] | 184 | int load_flags_; |
[email protected] | 8ee65ba | 2011-04-12 20:53:23 | [diff] [blame] | 185 | base::win::ScopedComPtr<IStream> upload_data_; |
[email protected] | 8f17016 | 2011-01-26 23:42:42 | [diff] [blame] | 186 | bool is_chunked_upload_; |
[email protected] | 0d282c2e | 2011-02-24 20:42:51 | [diff] [blame] | 187 | // Contains the ip address and port of the destination host. |
| 188 | net::HostPortPair socket_address_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 189 | }; |
| 190 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 191 | #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_ |