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