OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ | 5 #ifndef CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ |
6 #define CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ | 6 #define CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlwin.h> | 9 #include <atlwin.h> |
10 #include <string> | 10 #include <string> |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Interval for sending UMA data | 141 // Interval for sending UMA data |
142 int uma_send_interval_; | 142 int uma_send_interval_; |
143 }; | 143 }; |
144 | 144 |
145 // Handles all automation requests initiated from the chrome frame objects. | 145 // Handles all automation requests initiated from the chrome frame objects. |
146 // These include the chrome tab/chrome frame activex/chrome frame npapi | 146 // These include the chrome tab/chrome frame activex/chrome frame npapi |
147 // plugin objects. | 147 // plugin objects. |
148 class ChromeFrameAutomationClient | 148 class ChromeFrameAutomationClient |
149 : public CWindowImpl<ChromeFrameAutomationClient>, | 149 : public CWindowImpl<ChromeFrameAutomationClient>, |
150 public TaskMarshallerThroughWindowsMessages<ChromeFrameAutomationClient>, | 150 public TaskMarshallerThroughWindowsMessages<ChromeFrameAutomationClient>, |
151 public PluginRequestHandler, | 151 public base::RefCountedThreadSafe<ChromeFrameAutomationClient>, |
| 152 public PluginUrlRequestDelegate, |
152 public TabProxy::TabProxyDelegate, | 153 public TabProxy::TabProxyDelegate, |
153 public ProxyFactory::LaunchDelegate { | 154 public ProxyFactory::LaunchDelegate { |
154 public: | 155 public: |
155 ChromeFrameAutomationClient(); | 156 ChromeFrameAutomationClient(); |
156 ~ChromeFrameAutomationClient(); | 157 ~ChromeFrameAutomationClient(); |
157 | 158 |
158 // Called from UI thread. | 159 // Called from UI thread. |
159 virtual bool Initialize(ChromeFrameDelegate* chrome_frame_delegate, | 160 virtual bool Initialize(ChromeFrameDelegate* chrome_frame_delegate, |
160 int automation_server_launch_timeout, | 161 int automation_server_launch_timeout, |
161 bool perform_version_check, | 162 bool perform_version_check, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // Returns the version number of plugin dll. | 221 // Returns the version number of plugin dll. |
221 std::wstring GetVersion() const; | 222 std::wstring GetVersion() const; |
222 | 223 |
223 // BitBlts the contents of the chrome window to the print dc. | 224 // BitBlts the contents of the chrome window to the print dc. |
224 void Print(HDC print_dc, const RECT& print_bounds); | 225 void Print(HDC print_dc, const RECT& print_bounds); |
225 | 226 |
226 // Called in full tab mode and indicates a request to chrome to print | 227 // Called in full tab mode and indicates a request to chrome to print |
227 // the whole tab. | 228 // the whole tab. |
228 void PrintTab(); | 229 void PrintTab(); |
229 | 230 |
230 // PluginRequestHandler | |
231 bool AddRequest(PluginUrlRequest* request); | |
232 void RemoveRequest(PluginUrlRequest* request); | |
233 virtual bool Send(IPC::Message* msg); | |
234 | |
235 // URL request related | |
236 bool ReadRequest(int request_id, int bytes_to_read); | |
237 void RemoveRequest(int request_id, bool abort); | |
238 PluginUrlRequest* LookupRequest(int request_id) const; | |
239 bool IsValidRequest(PluginUrlRequest* request) const; | |
240 void CleanupRequests(); | |
241 | |
242 void set_use_chrome_network(bool use_chrome_network) { | 231 void set_use_chrome_network(bool use_chrome_network) { |
243 use_chrome_network_ = use_chrome_network; | 232 use_chrome_network_ = use_chrome_network; |
244 } | 233 } |
245 bool use_chrome_network() const { | 234 bool use_chrome_network() const { |
246 return use_chrome_network_; | 235 return use_chrome_network_; |
247 } | 236 } |
248 | 237 |
249 #ifdef UNIT_TEST | 238 #ifdef UNIT_TEST |
250 void set_proxy_factory(ProxyFactory* factory) { | 239 void set_proxy_factory(ProxyFactory* factory) { |
251 proxy_factory_ = factory; | 240 proxy_factory_ = factory; |
252 } | 241 } |
253 #endif | 242 #endif |
254 | 243 |
255 void set_handle_top_level_requests(bool handle_top_level_requests) { | 244 void set_handle_top_level_requests(bool handle_top_level_requests) { |
256 handle_top_level_requests_ = handle_top_level_requests; | 245 handle_top_level_requests_ = handle_top_level_requests; |
257 } | 246 } |
258 | 247 |
259 // Called if the same instance of the ChromeFrameAutomationClient object | 248 // Called if the same instance of the ChromeFrameAutomationClient object |
260 // is reused. | 249 // is reused. |
261 bool Reinitialize(ChromeFrameDelegate* chrome_frame_delegate); | 250 bool Reinitialize(ChromeFrameDelegate* chrome_frame_delegate, |
| 251 PluginUrlRequestManager* url_fetcher); |
262 | 252 |
263 // Attaches an existing external tab to this automation client instance. | 253 // Attaches an existing external tab to this automation client instance. |
264 void AttachExternalTab(intptr_t external_tab_cookie); | 254 void AttachExternalTab(intptr_t external_tab_cookie); |
265 | 255 |
266 void SetPageFontSize(enum AutomationPageFontSize); | 256 void SetPageFontSize(enum AutomationPageFontSize); |
267 | 257 |
268 protected: | 258 protected: |
269 // ChromeFrameAutomationProxy::LaunchDelegate implementation. | 259 // ChromeFrameAutomationProxy::LaunchDelegate implementation. |
270 virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy, | 260 virtual void LaunchComplete(ChromeFrameAutomationProxy* proxy, |
271 AutomationLaunchResult result); | 261 AutomationLaunchResult result); |
272 // TabProxyDelegate implementation | 262 // TabProxyDelegate implementation |
273 virtual void OnMessageReceived(TabProxy* tab, const IPC::Message& msg); | 263 virtual void OnMessageReceived(TabProxy* tab, const IPC::Message& msg); |
274 | 264 |
275 void CreateExternalTab(); | 265 void CreateExternalTab(); |
276 void CreateExternalTabComplete(HWND chrome_window, HWND tab_window, | 266 void CreateExternalTabComplete(HWND chrome_window, HWND tab_window, |
277 int tab_handle); | 267 int tab_handle); |
278 // Called in UI thread. Here we fire event to the client notifying for | 268 // Called in UI thread. Here we fire event to the client notifying for |
279 // the result of Initialize() method call. | 269 // the result of Initialize() method call. |
280 void InitializeComplete(AutomationLaunchResult result); | 270 void InitializeComplete(AutomationLaunchResult result); |
281 | 271 |
282 private: | 272 private: |
283 typedef std::map<int, scoped_refptr<PluginUrlRequest> > RequestMap; | |
284 | |
285 // Usage: From bkgnd thread invoke: | 273 // Usage: From bkgnd thread invoke: |
286 // CallDelegate(FROM_HERE, NewRunnableMethod(chrome_frame_delegate_, | 274 // CallDelegate(FROM_HERE, NewRunnableMethod(chrome_frame_delegate_, |
287 // ChromeFrameDelegate::Something, | 275 // ChromeFrameDelegate::Something, |
288 // param1, | 276 // param1, |
289 // param2)); | 277 // param2)); |
290 void CallDelegate(const tracked_objects::Location& from_here, | 278 void CallDelegate(const tracked_objects::Location& from_here, |
291 Task* delegate_task); | 279 Task* delegate_task); |
292 // The workhorse method called in main/GUI thread which is going to | 280 // The workhorse method called in main/GUI thread which is going to |
293 // execute ChromeFrameDelegate method encapsulated in delegate_task. | 281 // execute ChromeFrameDelegate method encapsulated in delegate_task. |
294 void CallDelegateImpl(Task* delegate_task); | 282 void CallDelegateImpl(Task* delegate_task); |
(...skipping 21 matching lines...) Expand all Loading... |
316 GURL url_; | 304 GURL url_; |
317 GURL referrer_; | 305 GURL referrer_; |
318 | 306 |
319 // Handle to the underlying chrome window. This is a child of the external | 307 // Handle to the underlying chrome window. This is a child of the external |
320 // tab window. | 308 // tab window. |
321 HWND tab_window_; | 309 HWND tab_window_; |
322 | 310 |
323 // Keeps track of the version of Chrome we're talking to. | 311 // Keeps track of the version of Chrome we're talking to. |
324 std::string automation_server_version_; | 312 std::string automation_server_version_; |
325 | 313 |
326 // Map of outstanding requests | |
327 RequestMap request_map_; | |
328 | |
329 typedef enum InitializationState { | 314 typedef enum InitializationState { |
330 UNINITIALIZED = 0, | 315 UNINITIALIZED = 0, |
331 INITIALIZING, | 316 INITIALIZING, |
332 INITIALIZED, | 317 INITIALIZED, |
333 UNINITIALIZING, | 318 UNINITIALIZING, |
334 }; | 319 }; |
335 | 320 |
336 InitializationState init_state_; | 321 InitializationState init_state_; |
337 bool use_chrome_network_; | 322 bool use_chrome_network_; |
338 bool handle_top_level_requests_; | 323 bool handle_top_level_requests_; |
339 ProxyFactory* proxy_factory_; | 324 ProxyFactory* proxy_factory_; |
340 int tab_handle_; | 325 int tab_handle_; |
341 // Only used if we attach to an existing tab. | 326 // Only used if we attach to an existing tab. |
342 intptr_t external_tab_cookie_; | 327 intptr_t external_tab_cookie_; |
343 | 328 |
344 // Set to true if we received a navigation request prior to the automation | 329 // Set to true if we received a navigation request prior to the automation |
345 // server being initialized. | 330 // server being initialized. |
346 bool navigate_after_initialization_; | 331 bool navigate_after_initialization_; |
347 | 332 |
348 ChromeFrameLaunchParams chrome_launch_params_; | 333 ChromeFrameLaunchParams chrome_launch_params_; |
| 334 |
| 335 // When host network stack is used, this object is in charge of |
| 336 // handling network requests. |
| 337 PluginUrlRequestManager* url_fetcher_; |
| 338 bool thread_safe_url_fetcher_; |
| 339 |
| 340 bool ProcessUrlRequestMessage(TabProxy* tab, const IPC::Message& msg, |
| 341 bool ui_thread); |
| 342 |
| 343 // PluginUrlRequestDelegate implementation. Simply adds tab's handle |
| 344 // as parameter and forwards to Chrome via IPC. |
| 345 virtual void OnResponseStarted(int request_id, const char* mime_type, |
| 346 const char* headers, int size, base::Time last_modified, |
| 347 const std::string& peristent_cookies, const std::string& redirect_url, |
| 348 int redirect_status); |
| 349 virtual void OnReadComplete(int request_id, const void* buffer, int len); |
| 350 virtual void OnResponseEnd(int request_id, const URLRequestStatus& status); |
| 351 |
| 352 public: |
| 353 void SetUrlFetcher(PluginUrlRequestManager* url_fetcher) { |
| 354 DCHECK(url_fetcher != NULL); |
| 355 url_fetcher_ = url_fetcher; |
| 356 thread_safe_url_fetcher_ = url_fetcher->IsThreadSafe(); |
| 357 url_fetcher_->set_delegate(this); |
| 358 } |
349 }; | 359 }; |
350 | 360 |
351 #endif // CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ | 361 #endif // CHROME_FRAME_CHROME_FRAME_AUTOMATION_H_ |
OLD | NEW |