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_ACTIVEX_BASE_H_ | 5 #ifndef CHROME_FRAME_CHROME_FRAME_ACTIVEX_BASE_H_ |
6 #define CHROME_FRAME_CHROME_FRAME_ACTIVEX_BASE_H_ | 6 #define CHROME_FRAME_CHROME_FRAME_ACTIVEX_BASE_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
10 #include <atlctl.h> | 10 #include <atlctl.h> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 public IPropertyNotifySinkCP<T>, | 158 public IPropertyNotifySinkCP<T>, |
159 public CComCoClass<T, &class_id>, | 159 public CComCoClass<T, &class_id>, |
160 public CComControl<T>, | 160 public CComControl<T>, |
161 public ChromeFramePlugin<T> { | 161 public ChromeFramePlugin<T> { |
162 protected: | 162 protected: |
163 typedef std::set<ScopedComPtr<IDispatch> > EventHandlers; | 163 typedef std::set<ScopedComPtr<IDispatch> > EventHandlers; |
164 typedef ChromeFrameActivexBase<T, class_id> Base; | 164 typedef ChromeFrameActivexBase<T, class_id> Base; |
165 | 165 |
166 public: | 166 public: |
167 ChromeFrameActivexBase() | 167 ChromeFrameActivexBase() |
168 : ready_state_(READYSTATE_UNINITIALIZED), | 168 : ready_state_(READYSTATE_UNINITIALIZED) { |
169 worker_thread_("ChromeFrameWorker_Thread") { | |
170 m_bWindowOnly = TRUE; | 169 m_bWindowOnly = TRUE; |
171 } | 170 } |
172 | 171 |
173 ~ChromeFrameActivexBase() { | 172 ~ChromeFrameActivexBase() { |
174 } | 173 } |
175 | 174 |
176 DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE | OLEMISC_CANTLINKINSIDE | | 175 DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE | OLEMISC_CANTLINKINSIDE | |
177 OLEMISC_INSIDEOUT | OLEMISC_ACTIVATEWHENVISIBLE | | 176 OLEMISC_INSIDEOUT | OLEMISC_ACTIVATEWHENVISIBLE | |
178 OLEMISC_SETCLIENTSITEFIRST) | 177 OLEMISC_SETCLIENTSITEFIRST) |
179 | 178 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 referrer_header += UTF8ToWide(referrer.spec()); | 457 referrer_header += UTF8ToWide(referrer.spec()); |
459 referrer_header += L"\r\n\r\n"; | 458 referrer_header += L"\r\n\r\n"; |
460 http_headers.Set(referrer_header.c_str()); | 459 http_headers.Set(referrer_header.c_str()); |
461 } | 460 } |
462 | 461 |
463 web_browser2->Navigate2(url.AsInput(), &flags, &empty, &empty, | 462 web_browser2->Navigate2(url.AsInput(), &flags, &empty, &empty, |
464 http_headers.AsInput()); | 463 http_headers.AsInput()); |
465 web_browser2->put_Visible(VARIANT_TRUE); | 464 web_browser2->put_Visible(VARIANT_TRUE); |
466 } | 465 } |
467 | 466 |
468 virtual void OnRequestStart(int tab_handle, int request_id, | |
469 const IPC::AutomationURLRequest& request_info) { | |
470 // The worker thread may have been stopped. This could happen if the | |
471 // ActiveX instance was reused. | |
472 if (!worker_thread_.message_loop()) { | |
473 base::Thread::Options options; | |
474 options.message_loop_type = MessageLoop::TYPE_UI; | |
475 worker_thread_.StartWithOptions(options); | |
476 worker_thread_.message_loop()->PostTask( | |
477 FROM_HERE, NewRunnableMethod(this, &Base::OnWorkerStart)); | |
478 } | |
479 | |
480 scoped_refptr<CComObject<UrlmonUrlRequest> > request; | |
481 if (base_url_request_.get() && | |
482 GURL(base_url_request_->url()) == GURL(request_info.url)) { | |
483 request.swap(base_url_request_); | |
484 } else { | |
485 CComObject<UrlmonUrlRequest>* new_request = NULL; | |
486 CComObject<UrlmonUrlRequest>::CreateInstance(&new_request); | |
487 request = new_request; | |
488 } | |
489 | |
490 DCHECK(request.get() != NULL); | |
491 | |
492 if (request->Initialize( | |
493 automation_client_.get(), tab_handle, request_id, request_info.url, | |
494 request_info.method, request_info.referrer, | |
495 request_info.extra_request_headers, request_info.upload_data.get(), | |
496 static_cast<T*>(this)->is_frame_busting_enabled())) { | |
497 request->set_worker_thread(&worker_thread_); | |
498 // If Start is successful, it will add a self reference. | |
499 request->Start(); | |
500 request->set_parent_window(m_hWnd); | |
501 } | |
502 } | |
503 | |
504 virtual void OnRequestRead(int tab_handle, int request_id, | |
505 int bytes_to_read) { | |
506 automation_client_->ReadRequest(request_id, bytes_to_read); | |
507 } | |
508 | |
509 virtual void OnRequestEnd(int tab_handle, int request_id, | |
510 const URLRequestStatus& status) { | |
511 automation_client_->RemoveRequest(request_id, true); | |
512 } | |
513 | |
514 virtual void OnDownloadRequestInHost(int tab_handle, int request_id) { | 467 virtual void OnDownloadRequestInHost(int tab_handle, int request_id) { |
515 DLOG(INFO) << "TODO: Let the host browser handle this download"; | 468 DLOG(INFO) << "TODO: Let the host browser handle this download"; |
516 PluginUrlRequest* request = automation_client_->LookupRequest(request_id); | 469 ScopedComPtr<IBindCtx> bind_context; |
517 if (request) { | 470 ScopedComPtr<IMoniker> moniker; |
518 static_cast<UrlmonUrlRequest*>(request)->TransferToHost(doc_site_); | 471 url_fetcher_.StealMonikerFromRequest(request_id, moniker.Receive()); |
| 472 if (moniker) { |
| 473 ::CreateBindCtx(0, bind_context.Receive()); |
| 474 DCHECK(bind_context); |
| 475 NavigateBrowserToMoniker(doc_site_, moniker, NULL, bind_context, NULL); |
519 } | 476 } |
520 automation_client_->RemoveRequest(request_id, false); | |
521 } | 477 } |
522 | 478 |
523 virtual void OnSetCookieAsync(int tab_handle, const GURL& url, | 479 virtual void OnSetCookieAsync(int tab_handle, const GURL& url, |
524 const std::string& cookie) { | 480 const std::string& cookie) { |
525 std::string name; | 481 std::string name; |
526 std::string data; | 482 std::string data; |
527 | 483 |
528 size_t name_end = cookie.find('='); | 484 size_t name_end = cookie.find('='); |
529 if (std::string::npos != name_end) { | 485 if (std::string::npos != name_end) { |
530 net::CookieMonster::ParsedCookie parsed_cookie = cookie; | 486 net::CookieMonster::ParsedCookie parsed_cookie = cookie; |
(...skipping 29 matching lines...) Expand all Loading... |
560 // Only fire the 'interactive' ready state if we aren't there already. | 516 // Only fire the 'interactive' ready state if we aren't there already. |
561 if (ready_state_ < READYSTATE_INTERACTIVE) { | 517 if (ready_state_ < READYSTATE_INTERACTIVE) { |
562 ready_state_ = READYSTATE_INTERACTIVE; | 518 ready_state_ = READYSTATE_INTERACTIVE; |
563 FireOnChanged(DISPID_READYSTATE); | 519 FireOnChanged(DISPID_READYSTATE); |
564 } | 520 } |
565 return 0; | 521 return 0; |
566 } | 522 } |
567 | 523 |
568 LRESULT OnDestroy(UINT message, WPARAM wparam, LPARAM lparam, | 524 LRESULT OnDestroy(UINT message, WPARAM wparam, LPARAM lparam, |
569 BOOL& handled) { // NO_LINT | 525 BOOL& handled) { // NO_LINT |
570 if (worker_thread_.message_loop()) { | 526 DLOG(INFO) << __FUNCTION__; |
571 if (automation_client_.get()) | |
572 automation_client_->CleanupRequests(); | |
573 | |
574 worker_thread_.message_loop()->PostTask( | |
575 FROM_HERE, NewRunnableMethod(this, &Base::OnWorkerStop)); | |
576 | |
577 MSG msg = {0}; | |
578 while (GetMessage(&msg, NULL, WM_USER, | |
579 WM_WORKER_THREAD_UNINITIALIZED_MSG)) { | |
580 if (msg.hwnd == m_hWnd && | |
581 msg.message == WM_WORKER_THREAD_UNINITIALIZED_MSG) { | |
582 break; | |
583 } | |
584 | |
585 TranslateMessage(&msg); | |
586 DispatchMessage(&msg); | |
587 } | |
588 worker_thread_.Stop(); | |
589 } | |
590 return 0; | 527 return 0; |
591 } | 528 } |
592 | 529 |
593 // ChromeFrameDelegate override | 530 // ChromeFrameDelegate override |
594 virtual void OnAutomationServerReady() { | 531 virtual void OnAutomationServerReady() { |
595 ChromeFramePlugin<T>::OnAutomationServerReady(); | 532 ChromeFramePlugin<T>::OnAutomationServerReady(); |
596 | 533 |
597 ready_state_ = READYSTATE_COMPLETE; | 534 ready_state_ = READYSTATE_COMPLETE; |
598 FireOnChanged(DISPID_READYSTATE); | 535 FireOnChanged(DISPID_READYSTATE); |
599 } | 536 } |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 // should have first dibs anyway. | 1039 // should have first dibs anyway. |
1103 if (hr != S_OK && automation_client_.get()) { | 1040 if (hr != S_OK && automation_client_.get()) { |
1104 TabProxy* tab = automation_client_->tab(); | 1041 TabProxy* tab = automation_client_->tab(); |
1105 if (tab) { | 1042 if (tab) { |
1106 tab->ProcessUnhandledAccelerator(accel_message); | 1043 tab->ProcessUnhandledAccelerator(accel_message); |
1107 } | 1044 } |
1108 } | 1045 } |
1109 } | 1046 } |
1110 | 1047 |
1111 protected: | 1048 protected: |
1112 // The following functions are called to initialize and uninitialize the | |
1113 // worker thread. | |
1114 void OnWorkerStart() { | |
1115 CoInitialize(NULL); | |
1116 } | |
1117 | |
1118 void OnWorkerStop() { | |
1119 CoUninitialize(); | |
1120 PostMessage(WM_WORKER_THREAD_UNINITIALIZED_MSG, 0, 0); | |
1121 } | |
1122 | |
1123 ScopedBstr url_; | 1049 ScopedBstr url_; |
1124 ScopedComPtr<IOleDocumentSite> doc_site_; | 1050 ScopedComPtr<IOleDocumentSite> doc_site_; |
1125 | 1051 |
1126 // For more information on the ready_state_ property see: | 1052 // For more information on the ready_state_ property see: |
1127 // http://msdn.microsoft.com/en-us/library/aa768179(VS.85).aspx# | 1053 // http://msdn.microsoft.com/en-us/library/aa768179(VS.85).aspx# |
1128 READYSTATE ready_state_; | 1054 READYSTATE ready_state_; |
1129 | 1055 |
1130 // The following members contain IDispatch interfaces representing the | 1056 // The following members contain IDispatch interfaces representing the |
1131 // onload/onerror/onmessage handlers on the page. | 1057 // onload/onerror/onmessage handlers on the page. |
1132 ScopedVariant onload_handler_; | 1058 ScopedVariant onload_handler_; |
1133 ScopedVariant onerror_handler_; | 1059 ScopedVariant onerror_handler_; |
1134 ScopedVariant onmessage_handler_; | 1060 ScopedVariant onmessage_handler_; |
1135 | 1061 |
1136 EventHandlers onmessage_; | 1062 EventHandlers onmessage_; |
1137 EventHandlers onloaderror_; | 1063 EventHandlers onloaderror_; |
1138 EventHandlers onload_; | 1064 EventHandlers onload_; |
1139 EventHandlers onreadystatechanged_; | 1065 EventHandlers onreadystatechanged_; |
1140 EventHandlers onprivatemessage_; | 1066 EventHandlers onprivatemessage_; |
1141 EventHandlers onextensionready_; | 1067 EventHandlers onextensionready_; |
1142 | 1068 |
1143 // The UrlmonUrlRequest instance instantiated for downloading the base URL. | 1069 // Handle network requests when host network stack is used. Passed to the |
1144 scoped_refptr<CComObject<UrlmonUrlRequest> > base_url_request_; | 1070 // automation client on initialization. |
1145 | 1071 UrlmonUrlRequestManager url_fetcher_; |
1146 base::Thread worker_thread_; | |
1147 }; | 1072 }; |
1148 | 1073 |
1149 #endif // CHROME_FRAME_CHROME_FRAME_ACTIVEX_BASE_H_ | 1074 #endif // CHROME_FRAME_CHROME_FRAME_ACTIVEX_BASE_H_ |
OLD | NEW |