Roll leveldb to r76.
[chromium-blink-merge.git] / chrome_frame / urlmon_url_request.h
blob24d8f5e57df0c0a73e7165ab1b4b292edb7803de
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_
8 #include <urlmon.h>
9 #include <atlbase.h>
10 #include <atlcom.h>
11 #include <map>
12 #include <string>
14 #include "chrome_frame/plugin_url_request.h"
15 #include "chrome_frame/urlmon_moniker.h"
16 #include "chrome_frame/utils.h"
18 namespace base {
19 class MessageLoop;
20 class Thread;
23 class UrlmonUrlRequest;
25 class UrlmonUrlRequestManager
26 : public PluginUrlRequestManager,
27 public PluginUrlRequestDelegate {
28 public:
29 // Contains the privacy information for all requests issued by this instance.
30 struct PrivacyInfo {
31 public:
32 struct PrivacyEntry {
33 PrivacyEntry() : flags(0) {}
34 std::wstring policy_ref;
35 int32 flags;
38 typedef std::map<std::wstring, PrivacyEntry> PrivacyRecords;
40 PrivacyInfo() : privacy_impacted(false) {}
42 bool privacy_impacted;
43 PrivacyRecords privacy_records;
46 UrlmonUrlRequestManager();
47 ~UrlmonUrlRequestManager();
49 // Use specific bind context when Chrome request this url.
50 // Used from ChromeActiveDocument's implementation of IPersistMoniker::Load().
51 void SetInfoForUrl(const std::wstring& url,
52 IMoniker* moniker, LPBC bind_context);
54 // Returns a copy of the url privacy information for this instance.
55 PrivacyInfo privacy_info() {
56 return privacy_info_;
59 virtual void AddPrivacyDataForUrl(const std::string& url,
60 const std::string& policy_ref,
61 int32 flags);
63 // This function passes the window on which notifications are to be fired.
64 void put_notification_window(HWND window) {
65 notification_window_ = window;
68 // This function passes information on whether ChromeFrame is running in
69 // privileged mode.
70 void set_privileged_mode(bool privileged_mode) {
71 privileged_mode_ = privileged_mode;
74 void set_container(IUnknown* container) {
75 container_ = container;
78 private:
79 friend class base::MessageLoop;
81 // PluginUrlRequestManager implementation.
82 virtual PluginUrlRequestManager::ThreadSafeFlags GetThreadSafeFlags();
83 virtual void StartRequest(int request_id,
84 const AutomationURLRequest& request_info);
85 virtual void ReadRequest(int request_id, int bytes_to_read);
86 virtual void EndRequest(int request_id);
87 virtual void DownloadRequestInHost(int request_id);
88 virtual void StopAll();
89 virtual void GetCookiesForUrl(const GURL& url, int cookie_id);
90 virtual void SetCookiesForUrl(const GURL& url, const std::string& cookie);
92 // PluginUrlRequestDelegate implementation
93 virtual void OnResponseStarted(
94 int request_id, const char* mime_type, const char* headers, int size,
95 base::Time last_modified, const std::string& redirect_url,
96 int redirect_status, const net::HostPortPair& socket_address,
97 uint64 upload_size);
98 virtual void OnReadComplete(int request_id, const std::string& data);
99 virtual void OnResponseEnd(int request_id,
100 const net::URLRequestStatus& status);
101 virtual void OnCookiesRetrieved(bool success, const GURL& url,
102 const std::string& cookie_string,
103 int cookie_id);
105 // This method is passed as a callback to UrlmonUrlRequest::TerminateBind.
106 // We simply forward moniker and bind_ctx to host ActiveX/ActiveDocument,
107 // so it may start NavigateWithBindContext.
108 void BindTerminated(IMoniker* moniker, IBindCtx* bind_ctx,
109 IStream* post_data, const char* request_headers);
111 // Helper function to initiate a download request in the host.
112 void DownloadRequestInHostHelper(UrlmonUrlRequest* request);
114 // Map for (request_id <-> UrlmonUrlRequest)
115 typedef std::map<int, scoped_refptr<UrlmonUrlRequest> > RequestMap;
116 RequestMap request_map_;
117 RequestMap background_request_map_;
119 // The caller is responsible for acquiring any locks needed to access the
120 // request map.
121 scoped_refptr<UrlmonUrlRequest> LookupRequest(int request_id,
122 RequestMap* request_map);
123 // The background_request_map_ is referenced from multiple threads. Lock to
124 // synchronize access.
125 base::Lock background_resource_map_lock_;
127 // Helper function to stop all requests in the request map.
128 void StopAllRequestsHelper(RequestMap* request_map,
129 base::Lock* request_map_lock);
130 // Helper function for initiating a new IE request.
131 void StartRequestHelper(int request_id,
132 const AutomationURLRequest& request_info,
133 RequestMap* request_map,
134 base::Lock* request_map_lock);
136 scoped_refptr<UrlmonUrlRequest> pending_request_;
137 scoped_ptr<base::Thread> background_thread_;
139 bool stopping_;
141 // Controls whether we download subresources on the page in a background
142 // worker thread.
143 bool background_worker_thread_enabled_;
145 PrivacyInfo privacy_info_;
146 // The window to be used to fire notifications on.
147 HWND notification_window_;
148 // Set to true if the ChromeFrame instance is running in privileged mode.
149 bool privileged_mode_;
150 // A pointer to the containing object. We maintain a weak reference to avoid
151 // lifetime issues.
152 IUnknown* container_;
155 #endif // CHROME_FRAME_URLMON_URL_REQUEST_H_