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_URLMON_URL_REQUEST_H_
6 #define CHROME_FRAME_URLMON_URL_REQUEST_H_
14 #include "base/threading/thread.h"
15 #include "chrome_frame/plugin_url_request.h"
16 #include "chrome_frame/urlmon_moniker.h"
17 #include "chrome_frame/utils.h"
19 class UrlmonUrlRequest
;
21 class UrlmonUrlRequestManager
22 : public PluginUrlRequestManager
,
23 public PluginUrlRequestDelegate
{
25 // Sub resources on the pages in chrome frame are fetched on this thread.
26 class ResourceFetcherThread
: public base::Thread
{
28 explicit ResourceFetcherThread(const char* name
);
29 virtual ~ResourceFetcherThread();
32 virtual void CleanUp();
35 // Contains the privacy information for all requests issued by this instance.
39 PrivacyEntry() : flags(0) {}
40 std::wstring policy_ref
;
44 typedef std::map
<std::wstring
, PrivacyEntry
> PrivacyRecords
;
46 PrivacyInfo() : privacy_impacted(false) {}
48 bool privacy_impacted
;
49 PrivacyRecords privacy_records
;
52 UrlmonUrlRequestManager();
53 ~UrlmonUrlRequestManager();
55 // Use specific bind context when Chrome request this url.
56 // Used from ChromeActiveDocument's implementation of IPersistMoniker::Load().
57 void SetInfoForUrl(const std::wstring
& url
,
58 IMoniker
* moniker
, LPBC bind_context
);
60 // Returns a copy of the url privacy information for this instance.
61 PrivacyInfo
privacy_info() {
65 virtual void AddPrivacyDataForUrl(const std::string
& url
,
66 const std::string
& policy_ref
,
69 // This function passes the window on which notifications are to be fired.
70 void put_notification_window(HWND window
) {
71 notification_window_
= window
;
74 // This function passes information on whether ChromeFrame is running in
76 void set_privileged_mode(bool privileged_mode
) {
77 privileged_mode_
= privileged_mode
;
80 void set_container(IUnknown
* container
) {
81 container_
= container
;
85 friend class MessageLoop
;
87 // PluginUrlRequestManager implementation.
88 virtual PluginUrlRequestManager::ThreadSafeFlags
GetThreadSafeFlags();
89 virtual void StartRequest(int request_id
,
90 const AutomationURLRequest
& request_info
);
91 virtual void ReadRequest(int request_id
, int bytes_to_read
);
92 virtual void EndRequest(int request_id
);
93 virtual void DownloadRequestInHost(int request_id
);
94 virtual void StopAll();
95 virtual void GetCookiesForUrl(const GURL
& url
, int cookie_id
);
96 virtual void SetCookiesForUrl(const GURL
& url
, const std::string
& cookie
);
98 // PluginUrlRequestDelegate implementation
99 virtual void OnResponseStarted(int request_id
, const char* mime_type
,
100 const char* headers
, int size
,
101 base::Time last_modified
,
102 const std::string
& redirect_url
,
104 const net::HostPortPair
& socket_address
);
105 virtual void OnReadComplete(int request_id
, const std::string
& data
);
106 virtual void OnResponseEnd(int request_id
,
107 const net::URLRequestStatus
& status
);
108 virtual void OnCookiesRetrieved(bool success
, const GURL
& url
,
109 const std::string
& cookie_string
,
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.
115 void BindTerminated(IMoniker
* moniker
, IBindCtx
* bind_ctx
,
116 IStream
* post_data
, const char* request_headers
);
118 // Helper function to initiate a download request in the host.
119 void DownloadRequestInHostHelper(UrlmonUrlRequest
* request
);
121 // Map for (request_id <-> UrlmonUrlRequest)
122 typedef std::map
<int, scoped_refptr
<UrlmonUrlRequest
> > RequestMap
;
123 RequestMap request_map_
;
124 RequestMap background_request_map_
;
126 // The caller is responsible for acquiring any locks needed to access the
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_
;
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
);
143 scoped_refptr
<UrlmonUrlRequest
> pending_request_
;
144 scoped_ptr
<ResourceFetcherThread
> background_thread_
;
148 // Controls whether we download subresources on the page in a background
150 bool background_worker_thread_enabled_
;
152 PrivacyInfo privacy_info_
;
153 // The window to be used to fire notifications on.
154 HWND notification_window_
;
155 // Set to true if the ChromeFrame instance is running in privileged mode.
156 bool privileged_mode_
;
157 // A pointer to the containing object. We maintain a weak reference to avoid
159 IUnknown
* container_
;
162 #endif // CHROME_FRAME_URLMON_URL_REQUEST_H_