[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 1 | // Copyright (c) 2009 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 CHROME_FRAME_PLUGIN_URL_REQUEST_H_ |
| 6 | #define CHROME_FRAME_PLUGIN_URL_REQUEST_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 11 | #include "base/ref_counted.h" |
| 12 | #include "base/scoped_comptr_win.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 13 | #include "base/time.h" |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 14 | #include "chrome_frame/chrome_frame_delegate.h" |
| 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" |
| 17 | #include "net/base/upload_data.h" |
| 18 | #include "net/url_request/url_request_status.h" |
[email protected] | 6063340 | 2010-10-01 16:33:37 | [diff] [blame^] | 19 | #include "webkit/glue/resource_type.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 20 | |
| 21 | class PluginUrlRequest; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 22 | class PluginUrlRequestDelegate; |
| 23 | class PluginUrlRequestManager; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 24 | |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 25 | class DECLSPEC_NOVTABLE PluginUrlRequestDelegate { // NOLINT |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 26 | public: |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 27 | virtual void OnResponseStarted(int request_id, const char* mime_type, |
| 28 | const char* headers, int size, base::Time last_modified, |
[email protected] | 70daf0b | 2010-03-02 19:13:00 | [diff] [blame] | 29 | const std::string& redirect_url, int redirect_status) = 0; |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 30 | virtual void OnReadComplete(int request_id, const std::string& data) = 0; |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 31 | virtual void OnResponseEnd(int request_id, |
| 32 | const URLRequestStatus& status) = 0; |
| 33 | virtual void AddPrivacyDataForUrl(const std::string& url, |
| 34 | const std::string& policy_ref, |
| 35 | int32 flags) {} |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 36 | virtual void OnCookiesRetrieved(bool success, const GURL& url, |
| 37 | const std::string& cookie_string, |
| 38 | int cookie_id) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 39 | protected: |
| 40 | PluginUrlRequestDelegate() {} |
| 41 | ~PluginUrlRequestDelegate() {} |
| 42 | }; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 43 | |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 44 | class DECLSPEC_NOVTABLE PluginUrlRequestManager { // NOLINT |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 45 | public: |
| 46 | PluginUrlRequestManager() : delegate_(NULL), enable_frame_busting_(true) {} |
| 47 | virtual ~PluginUrlRequestManager() {} |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 48 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 49 | void set_frame_busting(bool enable) { |
| 50 | enable_frame_busting_ = enable; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 51 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 52 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 53 | virtual void set_delegate(PluginUrlRequestDelegate* delegate) { |
| 54 | delegate_ = delegate; |
| 55 | } |
| 56 | |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 57 | enum ThreadSafeFlags { |
| 58 | NOT_THREADSAFE = 0x00, |
| 59 | START_REQUEST_THREADSAFE = 0x01, |
| 60 | STOP_REQUEST_THREADSAFE = 0x02, |
| 61 | READ_REQUEST_THREADSAFE = 0x04, |
| 62 | DOWNLOAD_REQUEST_THREADSAFE = 0x08, |
| 63 | COOKIE_REQUEST_THREADSAFE = 0x10 |
| 64 | }; |
| 65 | virtual ThreadSafeFlags GetThreadSafeFlags() = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 66 | |
| 67 | // These are called directly from Automation Client when network related |
| 68 | // automation messages are received from Chrome. |
| 69 | // Strip 'tab' handle and forward to the virtual methods implemented by |
| 70 | // derived classes. |
| 71 | void StartUrlRequest(int tab, int request_id, |
| 72 | const IPC::AutomationURLRequest& request_info) { |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 73 | StartRequest(request_id, request_info); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void ReadUrlRequest(int tab, int request_id, int bytes_to_read) { |
| 77 | ReadRequest(request_id, bytes_to_read); |
| 78 | } |
| 79 | |
| 80 | void EndUrlRequest(int tab, int request_id, const URLRequestStatus& s) { |
| 81 | EndRequest(request_id); |
| 82 | } |
| 83 | |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 84 | void DownloadUrlRequestInHost(int tab, int request_id) { |
| 85 | DownloadRequestInHost(request_id); |
| 86 | } |
| 87 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 88 | void StopAllRequests() { |
| 89 | StopAll(); |
| 90 | } |
| 91 | |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 92 | void GetCookiesFromHost(int tab_handle, const GURL& url, int cookie_id) { |
| 93 | GetCookiesForUrl(url, cookie_id); |
[email protected] | c82d09a2 | 2010-03-26 23:28:40 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 96 | void SetCookiesInHost(int tab_handle, const GURL& url, |
[email protected] | c82d09a2 | 2010-03-26 23:28:40 | [diff] [blame] | 97 | const std::string& cookie) { |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 98 | SetCookiesForUrl(url, cookie); |
[email protected] | c82d09a2 | 2010-03-26 23:28:40 | [diff] [blame] | 99 | } |
| 100 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 101 | protected: |
| 102 | PluginUrlRequestDelegate* delegate_; |
| 103 | bool enable_frame_busting_; |
| 104 | |
| 105 | private: |
| 106 | virtual void StartRequest(int request_id, |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 107 | const IPC::AutomationURLRequest& request_info) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 108 | virtual void ReadRequest(int request_id, int bytes_to_read) = 0; |
| 109 | virtual void EndRequest(int request_id) = 0; |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 110 | virtual void DownloadRequestInHost(int request_id) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 111 | virtual void StopAll() = 0; |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 112 | virtual void GetCookiesForUrl(const GURL& url, int cookie_id) = 0; |
| 113 | virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie) = 0; |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | // Used as base class. Holds Url request properties (url, method, referrer..) |
| 117 | class PluginUrlRequest { |
| 118 | public: |
| 119 | PluginUrlRequest(); |
| 120 | ~PluginUrlRequest(); |
| 121 | |
| 122 | bool Initialize(PluginUrlRequestDelegate* delegate, |
| 123 | int remote_request_id, const std::string& url, const std::string& method, |
| 124 | const std::string& referrer, const std::string& extra_headers, |
[email protected] | 6063340 | 2010-10-01 16:33:37 | [diff] [blame^] | 125 | net::UploadData* upload_data, ResourceType::Type resource_type, |
| 126 | bool enable_frame_busting_); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 127 | |
| 128 | // Accessors. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 129 | int id() const { |
| 130 | return remote_request_id_; |
| 131 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 132 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 133 | const std::string& url() const { |
| 134 | return url_; |
| 135 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 136 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 137 | const std::string& method() const { |
| 138 | return method_; |
| 139 | } |
[email protected] | 885362ca | 2009-10-27 21:50:07 | [diff] [blame] | 140 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 141 | const std::string& referrer() const { |
| 142 | return referrer_; |
| 143 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 144 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 145 | const std::string& extra_headers() const { |
| 146 | return extra_headers_; |
| 147 | } |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 148 | |
| 149 | uint64 post_data_len() const { |
| 150 | return post_data_len_; |
| 151 | } |
| 152 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 153 | protected: |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 154 | HRESULT get_upload_data(IStream** ret) { |
| 155 | DCHECK(ret); |
| 156 | if (!upload_data_.get()) |
| 157 | return S_FALSE; |
| 158 | *ret = upload_data_.get(); |
| 159 | (*ret)->AddRef(); |
| 160 | return S_OK; |
| 161 | } |
| 162 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 163 | void set_url(const std::string& url) { |
| 164 | url_ = url; |
| 165 | } |
| 166 | |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 167 | void ClearPostData() { |
| 168 | upload_data_.Release(); |
| 169 | post_data_len_ = 0; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 172 | void SendData(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 173 | bool enable_frame_busting_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 174 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 175 | PluginUrlRequestDelegate* delegate_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 176 | int remote_request_id_; |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 177 | uint64 post_data_len_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 178 | std::string url_; |
| 179 | std::string method_; |
| 180 | std::string referrer_; |
| 181 | std::string extra_headers_; |
[email protected] | 6063340 | 2010-10-01 16:33:37 | [diff] [blame^] | 182 | ResourceType::Type resource_type_; |
[email protected] | c5a8328 | 2009-10-29 03:57:23 | [diff] [blame] | 183 | ScopedComPtr<IStream> upload_data_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 184 | }; |
| 185 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 186 | #endif // CHROME_FRAME_PLUGIN_URL_REQUEST_H_ |