blob: 037de1d85fcf1adfc94c2f324b809a8556dc94b2 [file] [log] [blame]
[email protected]27a112c2011-01-06 04:19:301// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// 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]051236f2010-03-12 22:06:1411#include <map>
[email protected]86de13d2009-11-24 01:21:3512#include <string>
[email protected]f7817822009-09-24 05:11:5813
[email protected]34b99632011-01-01 01:01:0614#include "base/threading/thread.h"
[email protected]f7817822009-09-24 05:11:5815#include "chrome_frame/plugin_url_request.h"
[email protected]051236f2010-03-12 22:06:1416#include "chrome_frame/urlmon_moniker.h"
[email protected]3eb07da2010-02-01 19:48:3617#include "chrome_frame/utils.h"
[email protected]f7817822009-09-24 05:11:5818
[email protected]3eb07da2010-02-01 19:48:3619class UrlmonUrlRequest;
[email protected]f7817822009-09-24 05:11:5820
[email protected]70daf0b2010-03-02 19:13:0021class UrlmonUrlRequestManager
22 : public PluginUrlRequestManager,
23 public PluginUrlRequestDelegate {
[email protected]f7817822009-09-24 05:11:5824 public:
[email protected]b0938a42011-10-05 20:59:3825 // 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]80b5a8d2010-03-19 16:50:4335 // 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]3eb07da2010-02-01 19:48:3652 UrlmonUrlRequestManager();
53 ~UrlmonUrlRequestManager();
[email protected]dda7d9c2009-11-11 23:01:4754
[email protected]0ce46402010-04-08 16:53:5755 // Use specific bind context when Chrome request this url.
[email protected]3eb07da2010-02-01 19:48:3656 // Used from ChromeActiveDocument's implementation of IPersistMoniker::Load().
[email protected]0ce46402010-04-08 16:53:5757 void SetInfoForUrl(const std::wstring& url,
58 IMoniker* moniker, LPBC bind_context);
[email protected]80b5a8d2010-03-19 16:50:4359
60 // Returns a copy of the url privacy information for this instance.
61 PrivacyInfo privacy_info() {
[email protected]80b5a8d2010-03-19 16:50:4362 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]7403d38f2010-03-22 22:50:4974 // 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]7db5d172010-05-20 21:11:2580 void set_container(IUnknown* container) {
81 container_ = container;
82 }
83
[email protected]f7817822009-09-24 05:11:5884 private:
[email protected]3eb07da2010-02-01 19:48:3685 friend class MessageLoop;
[email protected]86de13d2009-11-24 01:21:3586
[email protected]3eb07da2010-02-01 19:48:3687 // PluginUrlRequestManager implementation.
[email protected]27ad98352010-04-13 17:10:5188 virtual PluginUrlRequestManager::ThreadSafeFlags GetThreadSafeFlags();
[email protected]3eb07da2010-02-01 19:48:3689 virtual void StartRequest(int request_id,
[email protected]f5494d42010-12-23 22:15:3490 const AutomationURLRequest& request_info);
[email protected]3eb07da2010-02-01 19:48:3691 virtual void ReadRequest(int request_id, int bytes_to_read);
92 virtual void EndRequest(int request_id);
[email protected]7ae80742010-03-25 22:02:2793 virtual void DownloadRequestInHost(int request_id);
[email protected]3eb07da2010-02-01 19:48:3694 virtual void StopAll();
[email protected]27ad98352010-04-13 17:10:5195 virtual void GetCookiesForUrl(const GURL& url, int cookie_id);
96 virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie);
[email protected]c82d09a22010-03-26 23:28:4097
[email protected]3eb07da2010-02-01 19:48:3698 // PluginUrlRequestDelegate implementation
99 virtual void OnResponseStarted(int request_id, const char* mime_type,
[email protected]7ae80742010-03-25 22:02:27100 const char* headers, int size,
101 base::Time last_modified,
102 const std::string& redirect_url,
[email protected]0d282c2e2011-02-24 20:42:51103 int redirect_status,
104 const net::HostPortPair& socket_address);
[email protected]0ce46402010-04-08 16:53:57105 virtual void OnReadComplete(int request_id, const std::string& data);
[email protected]27a112c2011-01-06 04:19:30106 virtual void OnResponseEnd(int request_id,
107 const net::URLRequestStatus& status);
[email protected]27ad98352010-04-13 17:10:51108 virtual void OnCookiesRetrieved(bool success, const GURL& url,
109 const std::string& cookie_string,
110 int cookie_id);
[email protected]3eb07da2010-02-01 19:48:36111
[email protected]5cec0eb32010-04-28 21:00:54112 // 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]f4fbae682011-02-28 22:18:33115 void BindTerminated(IMoniker* moniker, IBindCtx* bind_ctx,
[email protected]4736610c2011-03-04 06:43:35116 IStream* post_data, const char* request_headers);
[email protected]5cec0eb32010-04-28 21:00:54117
[email protected]b0938a42011-10-05 20:59:38118 // Helper function to initiate a download request in the host.
119 void DownloadRequestInHostHelper(UrlmonUrlRequest* request);
120
[email protected]3eb07da2010-02-01 19:48:36121 // Map for (request_id <-> UrlmonUrlRequest)
122 typedef std::map<int, scoped_refptr<UrlmonUrlRequest> > RequestMap;
123 RequestMap request_map_;
[email protected]b0938a42011-10-05 20:59:38124 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]3ee61122010-04-14 00:35:52143 scoped_refptr<UrlmonUrlRequest> pending_request_;
[email protected]b0938a42011-10-05 20:59:38144 scoped_ptr<ResourceFetcherThread> background_thread_;
[email protected]0ce46402010-04-08 16:53:57145
146 bool stopping_;
[email protected]b0938a42011-10-05 20:59:38147
148 // Controls whether we download subresources on the page in a background
149 // worker thread.
150 bool background_worker_thread_enabled_;
[email protected]0ce46402010-04-08 16:53:57151
[email protected]80b5a8d2010-03-19 16:50:43152 PrivacyInfo privacy_info_;
153 // The window to be used to fire notifications on.
154 HWND notification_window_;
[email protected]7403d38f2010-03-22 22:50:49155 // Set to true if the ChromeFrame instance is running in privileged mode.
156 bool privileged_mode_;
[email protected]7db5d172010-05-20 21:11:25157 // A pointer to the containing object. We maintain a weak reference to avoid
158 // lifetime issues.
159 IUnknown* container_;
[email protected]f7817822009-09-24 05:11:58160};
161
162#endif // CHROME_FRAME_URLMON_URL_REQUEST_H_