[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_URLMON_URL_REQUEST_H_ |
| 6 | #define CHROME_FRAME_URLMON_URL_REQUEST_H_ |
| 7 | |
| 8 | #include <urlmon.h> |
| 9 | #include <atlbase.h> |
| 10 | #include <atlcom.h> |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 11 | #include <map> |
[email protected] | 86de13d | 2009-11-24 01:21:35 | [diff] [blame] | 12 | #include <string> |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 13 | |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 14 | #include "base/threading/thread.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 15 | #include "chrome_frame/plugin_url_request.h" |
[email protected] | 051236f | 2010-03-12 22:06:14 | [diff] [blame] | 16 | #include "chrome_frame/urlmon_moniker.h" |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 17 | #include "chrome_frame/utils.h" |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 18 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 19 | class UrlmonUrlRequest; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 20 | |
[email protected] | 70daf0b | 2010-03-02 19:13:00 | [diff] [blame] | 21 | class UrlmonUrlRequestManager |
| 22 | : public PluginUrlRequestManager, |
| 23 | public PluginUrlRequestDelegate { |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 24 | public: |
[email protected] | b0938a4 | 2011-10-05 20:59:38 | [diff] [blame] | 25 | // Sub resources on the pages in chrome frame are fetched on this thread. |
| 26 | class ResourceFetcherThread : public base::Thread { |
| 27 | public: |
| 28 | explicit ResourceFetcherThread(const char* name); |
| 29 | virtual ~ResourceFetcherThread(); |
| 30 | |
| 31 | virtual void Init(); |
| 32 | virtual void CleanUp(); |
| 33 | }; |
| 34 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 35 | // Contains the privacy information for all requests issued by this instance. |
| 36 | struct PrivacyInfo { |
| 37 | public: |
| 38 | struct PrivacyEntry { |
| 39 | PrivacyEntry() : flags(0) {} |
| 40 | std::wstring policy_ref; |
| 41 | int32 flags; |
| 42 | }; |
| 43 | |
| 44 | typedef std::map<std::wstring, PrivacyEntry> PrivacyRecords; |
| 45 | |
| 46 | PrivacyInfo() : privacy_impacted(false) {} |
| 47 | |
| 48 | bool privacy_impacted; |
| 49 | PrivacyRecords privacy_records; |
| 50 | }; |
| 51 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 52 | UrlmonUrlRequestManager(); |
| 53 | ~UrlmonUrlRequestManager(); |
[email protected] | dda7d9c | 2009-11-11 23:01:47 | [diff] [blame] | 54 | |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 55 | // Use specific bind context when Chrome request this url. |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 56 | // Used from ChromeActiveDocument's implementation of IPersistMoniker::Load(). |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 57 | void SetInfoForUrl(const std::wstring& url, |
| 58 | IMoniker* moniker, LPBC bind_context); |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 59 | |
| 60 | // Returns a copy of the url privacy information for this instance. |
| 61 | PrivacyInfo privacy_info() { |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 62 | return privacy_info_; |
| 63 | } |
| 64 | |
| 65 | virtual void AddPrivacyDataForUrl(const std::string& url, |
| 66 | const std::string& policy_ref, |
| 67 | int32 flags); |
| 68 | |
| 69 | // This function passes the window on which notifications are to be fired. |
| 70 | void put_notification_window(HWND window) { |
| 71 | notification_window_ = window; |
| 72 | } |
| 73 | |
[email protected] | 7403d38f | 2010-03-22 22:50:49 | [diff] [blame] | 74 | // This function passes information on whether ChromeFrame is running in |
| 75 | // privileged mode. |
| 76 | void set_privileged_mode(bool privileged_mode) { |
| 77 | privileged_mode_ = privileged_mode; |
| 78 | } |
| 79 | |
[email protected] | 7db5d17 | 2010-05-20 21:11:25 | [diff] [blame] | 80 | void set_container(IUnknown* container) { |
| 81 | container_ = container; |
| 82 | } |
| 83 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 84 | private: |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 85 | friend class MessageLoop; |
[email protected] | 86de13d | 2009-11-24 01:21:35 | [diff] [blame] | 86 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 87 | // PluginUrlRequestManager implementation. |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 88 | virtual PluginUrlRequestManager::ThreadSafeFlags GetThreadSafeFlags(); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 89 | virtual void StartRequest(int request_id, |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 90 | const AutomationURLRequest& request_info); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 91 | virtual void ReadRequest(int request_id, int bytes_to_read); |
| 92 | virtual void EndRequest(int request_id); |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 93 | virtual void DownloadRequestInHost(int request_id); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 94 | virtual void StopAll(); |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 95 | virtual void GetCookiesForUrl(const GURL& url, int cookie_id); |
| 96 | virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie); |
[email protected] | c82d09a2 | 2010-03-26 23:28:40 | [diff] [blame] | 97 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 98 | // PluginUrlRequestDelegate implementation |
| 99 | virtual void OnResponseStarted(int request_id, const char* mime_type, |
[email protected] | 7ae8074 | 2010-03-25 22:02:27 | [diff] [blame] | 100 | const char* headers, int size, |
| 101 | base::Time last_modified, |
| 102 | const std::string& redirect_url, |
[email protected] | 0d282c2e | 2011-02-24 20:42:51 | [diff] [blame] | 103 | int redirect_status, |
| 104 | const net::HostPortPair& socket_address); |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 105 | virtual void OnReadComplete(int request_id, const std::string& data); |
[email protected] | 27a112c | 2011-01-06 04:19:30 | [diff] [blame] | 106 | virtual void OnResponseEnd(int request_id, |
| 107 | const net::URLRequestStatus& status); |
[email protected] | 27ad9835 | 2010-04-13 17:10:51 | [diff] [blame] | 108 | virtual void OnCookiesRetrieved(bool success, const GURL& url, |
| 109 | const std::string& cookie_string, |
| 110 | int cookie_id); |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 111 | |
[email protected] | 5cec0eb3 | 2010-04-28 21:00:54 | [diff] [blame] | 112 | // This method is passed as a callback to UrlmonUrlRequest::TerminateBind. |
| 113 | // We simply forward moniker and bind_ctx to host ActiveX/ActiveDocument, |
| 114 | // so it may start NavigateWithBindContext. |
[email protected] | f4fbae68 | 2011-02-28 22:18:33 | [diff] [blame] | 115 | void BindTerminated(IMoniker* moniker, IBindCtx* bind_ctx, |
[email protected] | 4736610c | 2011-03-04 06:43:35 | [diff] [blame] | 116 | IStream* post_data, const char* request_headers); |
[email protected] | 5cec0eb3 | 2010-04-28 21:00:54 | [diff] [blame] | 117 | |
[email protected] | b0938a4 | 2011-10-05 20:59:38 | [diff] [blame] | 118 | // Helper function to initiate a download request in the host. |
| 119 | void DownloadRequestInHostHelper(UrlmonUrlRequest* request); |
| 120 | |
[email protected] | 3eb07da | 2010-02-01 19:48:36 | [diff] [blame] | 121 | // Map for (request_id <-> UrlmonUrlRequest) |
| 122 | typedef std::map<int, scoped_refptr<UrlmonUrlRequest> > RequestMap; |
| 123 | RequestMap request_map_; |
[email protected] | b0938a4 | 2011-10-05 20:59:38 | [diff] [blame] | 124 | RequestMap background_request_map_; |
| 125 | |
| 126 | // The caller is responsible for acquiring any locks needed to access the |
| 127 | // request map. |
| 128 | scoped_refptr<UrlmonUrlRequest> LookupRequest(int request_id, |
| 129 | RequestMap* request_map); |
| 130 | // The background_request_map_ is referenced from multiple threads. Lock to |
| 131 | // synchronize access. |
| 132 | base::Lock background_resource_map_lock_; |
| 133 | |
| 134 | // Helper function to stop all requests in the request map. |
| 135 | void StopAllRequestsHelper(RequestMap* request_map, |
| 136 | base::Lock* request_map_lock); |
| 137 | // Helper function for initiating a new IE request. |
| 138 | void StartRequestHelper(int request_id, |
| 139 | const AutomationURLRequest& request_info, |
| 140 | RequestMap* request_map, |
| 141 | base::Lock* request_map_lock); |
| 142 | |
[email protected] | 3ee6112 | 2010-04-14 00:35:52 | [diff] [blame] | 143 | scoped_refptr<UrlmonUrlRequest> pending_request_; |
[email protected] | b0938a4 | 2011-10-05 20:59:38 | [diff] [blame] | 144 | scoped_ptr<ResourceFetcherThread> background_thread_; |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 145 | |
| 146 | bool stopping_; |
[email protected] | b0938a4 | 2011-10-05 20:59:38 | [diff] [blame] | 147 | |
| 148 | // Controls whether we download subresources on the page in a background |
| 149 | // worker thread. |
| 150 | bool background_worker_thread_enabled_; |
[email protected] | 0ce4640 | 2010-04-08 16:53:57 | [diff] [blame] | 151 | |
[email protected] | 80b5a8d | 2010-03-19 16:50:43 | [diff] [blame] | 152 | PrivacyInfo privacy_info_; |
| 153 | // The window to be used to fire notifications on. |
| 154 | HWND notification_window_; |
[email protected] | 7403d38f | 2010-03-22 22:50:49 | [diff] [blame] | 155 | // Set to true if the ChromeFrame instance is running in privileged mode. |
| 156 | bool privileged_mode_; |
[email protected] | 7db5d17 | 2010-05-20 21:11:25 | [diff] [blame] | 157 | // A pointer to the containing object. We maintain a weak reference to avoid |
| 158 | // lifetime issues. |
| 159 | IUnknown* container_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | #endif // CHROME_FRAME_URLMON_URL_REQUEST_H_ |