Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: chrome_frame/chrome_active_document.cc

Issue 3061036: Handle automation server crashes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome_frame/chrome_active_document.h ('k') | chrome_frame/chrome_frame_activex.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // Implementation of ChromeActiveDocument 5 // Implementation of ChromeActiveDocument
6 #include "chrome_frame/chrome_active_document.h" 6 #include "chrome_frame/chrome_active_document.h"
7 7
8 #include <hlink.h> 8 #include <hlink.h>
9 #include <htiface.h> 9 #include <htiface.h>
10 #include <initguid.h> 10 #include <initguid.h>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 0 // The Last data must be 0 to indicate the end of the encoding id array. 61 0 // The Last data must be 0 to indicate the end of the encoding id array.
62 }; 62 };
63 63
64 ChromeActiveDocument::ChromeActiveDocument() 64 ChromeActiveDocument::ChromeActiveDocument()
65 : first_navigation_(true), 65 : first_navigation_(true),
66 is_automation_client_reused_(false), 66 is_automation_client_reused_(false),
67 popup_allowed_(false), 67 popup_allowed_(false),
68 accelerator_table_(NULL) { 68 accelerator_table_(NULL) {
69 TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, ""); 69 TRACE_EVENT_BEGIN("chromeframe.createactivedocument", this, "");
70 70
71 url_fetcher_.set_frame_busting(false); 71 url_fetcher_->set_frame_busting(false);
72 memset(&navigation_info_, 0, sizeof(navigation_info_)); 72 memset(&navigation_info_, 0, sizeof(navigation_info_));
73 } 73 }
74 74
75 HRESULT ChromeActiveDocument::FinalConstruct() { 75 HRESULT ChromeActiveDocument::FinalConstruct() {
76 // If we have a cached ChromeActiveDocument instance in TLS, then grab 76 // If we have a cached ChromeActiveDocument instance in TLS, then grab
77 // ownership of the cached document's automation client. This is an 77 // ownership of the cached document's automation client. This is an
78 // optimization to get Chrome active documents to load faster. 78 // optimization to get Chrome active documents to load faster.
79 ChromeActiveDocument* cached_document = g_active_doc_cache.Get(); 79 ChromeActiveDocument* cached_document = g_active_doc_cache.Get();
80 if (cached_document && cached_document->IsValid()) { 80 if (cached_document && cached_document->IsValid()) {
81 DCHECK(automation_client_.get() == NULL); 81 DCHECK(automation_client_.get() == NULL);
82 automation_client_.swap(cached_document->automation_client_); 82 automation_client_.swap(cached_document->automation_client_);
83 DLOG(INFO) << "Reusing automation client instance from " 83 DLOG(INFO) << "Reusing automation client instance from "
84 << cached_document; 84 << cached_document;
85 DCHECK(automation_client_.get() != NULL); 85 DCHECK(automation_client_.get() != NULL);
86 automation_client_->Reinitialize(this, &url_fetcher_); 86 automation_client_->Reinitialize(this, url_fetcher_.get());
87 is_automation_client_reused_ = true; 87 is_automation_client_reused_ = true;
88 } else { 88 } else {
89 // The FinalConstruct implementation in the ChromeFrameActivexBase class 89 // The FinalConstruct implementation in the ChromeFrameActivexBase class
90 // i.e. Base creates an instance of the ChromeFrameAutomationClient class 90 // i.e. Base creates an instance of the ChromeFrameAutomationClient class
91 // and initializes it, which would spawn a new Chrome process, etc. 91 // and initializes it, which would spawn a new Chrome process, etc.
92 // We don't want to be doing this if we have a cached document, whose 92 // We don't want to be doing this if we have a cached document, whose
93 // automation client instance can be reused. 93 // automation client instance can be reused.
94 HRESULT hr = BaseActiveX::FinalConstruct(); 94 HRESULT hr = BaseActiveX::FinalConstruct();
95 if (FAILED(hr)) 95 if (FAILED(hr))
96 return hr; 96 return hr;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 ChromeFrameUrl cf_url; 270 ChromeFrameUrl cf_url;
271 if (!cf_url.Parse(url)) { 271 if (!cf_url.Parse(url)) {
272 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url; 272 DLOG(WARNING) << __FUNCTION__ << " Failed to parse url:" << url;
273 return E_INVALIDARG; 273 return E_INVALIDARG;
274 } 274 }
275 275
276 if (!CanNavigateInFullTabMode(cf_url, security_manager_)) { 276 if (!CanNavigateInFullTabMode(cf_url, security_manager_)) {
277 return E_INVALIDARG; 277 return E_INVALIDARG;
278 } 278 }
279 279
280 std::string referrer = mgr ? mgr->referrer() : EmptyString(); 280 std::string referrer(mgr ? mgr->referrer() : EmptyString());
281
281 // With CTransaction patch we have more robust way to grab the referrer for 282 // With CTransaction patch we have more robust way to grab the referrer for
282 // each top-level-switch-to-CF request by peeking at our sniffing data 283 // each top-level-switch-to-CF request by peeking at our sniffing data
283 // object that lives inside the bind context. 284 // object that lives inside the bind context.
284 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) { 285 if (g_patch_helper.state() == PatchHelper::PATCH_PROTOCOL && info) {
285 scoped_refptr<ProtData> prot_data = info->get_prot_data(); 286 scoped_refptr<ProtData> prot_data = info->get_prot_data();
286 if (prot_data) 287 if (prot_data)
287 referrer = prot_data->referrer(); 288 referrer = prot_data->referrer();
288 } 289 }
289 290
290 if (!LaunchUrl(cf_url, referrer)) { 291 if (!LaunchUrl(cf_url, referrer)) {
291 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url; 292 NOTREACHED() << __FUNCTION__ << " Failed to launch url:" << url;
292 return E_INVALIDARG; 293 return E_INVALIDARG;
293 } 294 }
294 295
295 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab()) 296 if (!cf_url.is_chrome_protocol() && !cf_url.attach_to_external_tab())
296 url_fetcher_.SetInfoForUrl(cf_url.url(), moniker_name, bind_context); 297 url_fetcher_->SetInfoForUrl(cf_url.url(), moniker_name, bind_context);
297 298
298 THREAD_SAFE_UMA_HISTOGRAM_CUSTOM_COUNTS("ChromeFrame.FullTabLaunchType", 299 THREAD_SAFE_UMA_HISTOGRAM_CUSTOM_COUNTS("ChromeFrame.FullTabLaunchType",
299 cf_url.is_chrome_protocol(), 300 cf_url.is_chrome_protocol(),
300 0, 1, 2); 301 0, 1, 2);
301 return S_OK; 302 return S_OK;
302 } 303 }
303 304
304 STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name, 305 STDMETHODIMP ChromeActiveDocument::Save(IMoniker* moniker_name,
305 LPBC bind_context, 306 LPBC bind_context,
306 BOOL remember) { 307 BOOL remember) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid, 366 STDMETHODIMP ChromeActiveDocument::Exec(const GUID* cmd_group_guid,
366 DWORD command_id, 367 DWORD command_id,
367 DWORD cmd_exec_opt, 368 DWORD cmd_exec_opt,
368 VARIANT* in_args, 369 VARIANT* in_args,
369 VARIANT* out_args) { 370 VARIANT* out_args) {
370 DLOG(INFO) << __FUNCTION__ << " Cmd id =" << command_id; 371 DLOG(INFO) << __FUNCTION__ << " Cmd id =" << command_id;
371 // Bail out if we have been uninitialized. 372 // Bail out if we have been uninitialized.
372 if (automation_client_.get() && automation_client_->tab()) { 373 if (automation_client_.get() && automation_client_->tab()) {
373 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt, 374 return ProcessExecCommand(cmd_group_guid, command_id, cmd_exec_opt,
374 in_args, out_args); 375 in_args, out_args);
376 } else if (command_id == OLECMDID_REFRESH && cmd_group_guid == NULL) {
377 // If the automation server has crashed and the user is refreshing the
378 // page, let OnRefreshPage attempt to recover.
379 OnRefreshPage(cmd_group_guid, command_id, cmd_exec_opt, in_args, out_args);
375 } 380 }
381
376 return OLECMDERR_E_NOTSUPPORTED; 382 return OLECMDERR_E_NOTSUPPORTED;
377 } 383 }
378 384
379 STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream, 385 STDMETHODIMP ChromeActiveDocument::LoadHistory(IStream* stream,
380 IBindCtx* bind_context) { 386 IBindCtx* bind_context) {
381 // Read notes in ChromeActiveDocument::SaveHistory 387 // Read notes in ChromeActiveDocument::SaveHistory
382 DCHECK(stream); 388 DCHECK(stream);
383 LARGE_INTEGER offset = {0}; 389 LARGE_INTEGER offset = {0};
384 ULARGE_INTEGER cur_pos = {0}; 390 ULARGE_INTEGER cur_pos = {0};
385 STATSTG statstg = {0}; 391 STATSTG statstg = {0};
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 VARIANT* out_args) { 843 VARIANT* out_args) {
838 // Always return URLZONE_INTERNET since that is the Chrome's behaviour. 844 // Always return URLZONE_INTERNET since that is the Chrome's behaviour.
839 // Correct step is to use MapUrlToZone(). 845 // Correct step is to use MapUrlToZone().
840 if (out_args != NULL) { 846 if (out_args != NULL) {
841 out_args->vt = VT_UI4; 847 out_args->vt = VT_UI4;
842 out_args->ulVal = URLZONE_INTERNET; 848 out_args->ulVal = URLZONE_INTERNET;
843 } 849 }
844 } 850 }
845 851
846 void ChromeActiveDocument::OnDisplayPrivacyInfo() { 852 void ChromeActiveDocument::OnDisplayPrivacyInfo() {
847 privacy_info_ = url_fetcher_.privacy_info(); 853 privacy_info_ = url_fetcher_->privacy_info();
848 Reset(); 854 Reset();
849 DoPrivacyDlg(m_hWnd, url_, this, TRUE); 855 DoPrivacyDlg(m_hWnd, url_, this, TRUE);
850 } 856 }
851 857
852 void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid, 858 void ChromeActiveDocument::OnGetZoomRange(const GUID* cmd_group_guid,
853 DWORD command_id, 859 DWORD command_id,
854 DWORD cmd_exec_opt, 860 DWORD cmd_exec_opt,
855 VARIANT* in_args, 861 VARIANT* in_args,
856 VARIANT* out_args) { 862 VARIANT* out_args) {
857 if (out_args != NULL) { 863 if (out_args != NULL) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 return hr; 988 return hr;
983 } 989 }
984 990
985 bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url, 991 bool ChromeActiveDocument::LaunchUrl(const ChromeFrameUrl& cf_url,
986 const std::string& referrer) { 992 const std::string& referrer) {
987 DCHECK(automation_client_.get() != NULL); 993 DCHECK(automation_client_.get() != NULL);
988 DCHECK(!cf_url.url().empty()); 994 DCHECK(!cf_url.url().empty());
989 995
990 url_.Allocate(cf_url.url().c_str()); 996 url_.Allocate(cf_url.url().c_str());
991 997
992 std::string utf8_url; 998 std::string utf8_url(WideToUTF8(cf_url.url()));
993 WideToUTF8(url_, url_.Length(), &utf8_url); 999 DLOG(INFO) << "this:" << this << " url is:" << utf8_url;
994
995 DLOG(INFO) << "this:" << this << " url is:" << url_;
996 1000
997 if (cf_url.attach_to_external_tab()) { 1001 if (cf_url.attach_to_external_tab()) {
998 dimensions_ = cf_url.dimensions(); 1002 dimensions_ = cf_url.dimensions();
999 automation_client_->AttachExternalTab(cf_url.cookie()); 1003 automation_client_->AttachExternalTab(cf_url.cookie());
1000 SetWindowDimensions(); 1004 SetWindowDimensions();
1001 } else if (!automation_client_->InitiateNavigation(utf8_url, 1005 } else if (!automation_client_->InitiateNavigation(utf8_url,
1002 referrer, 1006 referrer,
1003 is_privileged_)) { 1007 is_privileged_)) {
1004 DLOG(ERROR) << "Invalid URL: " << url_; 1008 DLOG(ERROR) << "Invalid URL: " << url_;
1005 Error(L"Invalid URL"); 1009 Error(L"Invalid URL");
1006 url_.Reset(); 1010 url_.Reset();
1007 return false; 1011 return false;
1008 } 1012 }
1009 1013
1010 if (is_automation_client_reused_) 1014 if (is_automation_client_reused_)
1011 return true; 1015 return true;
1012 1016
1013 automation_client_->SetUrlFetcher(&url_fetcher_); 1017 automation_client_->SetUrlFetcher(url_fetcher_.get());
1014 1018
1019 GURL url(utf8_url);
1015 return InitializeAutomation(GetHostProcessName(false), L"", IsIEInPrivate(), 1020 return InitializeAutomation(GetHostProcessName(false), L"", IsIEInPrivate(),
1016 false, GURL(utf8_url), GURL(referrer)); 1021 false, url, GURL(referrer));
1017 } 1022 }
1018 1023
1019 1024
1020 HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid, 1025 HRESULT ChromeActiveDocument::OnRefreshPage(const GUID* cmd_group_guid,
1021 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) { 1026 DWORD command_id, DWORD cmd_exec_opt, VARIANT* in_args, VARIANT* out_args) {
1027 DLOG(INFO) << __FUNCTION__;
1022 popup_allowed_ = false; 1028 popup_allowed_ = false;
1023 if (in_args->vt == VT_I4 && 1029 if (in_args->vt == VT_I4 &&
1024 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) { 1030 in_args->lVal & OLECMDIDF_REFRESH_PAGEACTION_POPUPWINDOW) {
1025 popup_allowed_ = true; 1031 popup_allowed_ = true;
1026 1032
1027 // Ask the yellow security band to change the text and icon and to remain 1033 // Ask the yellow security band to change the text and icon and to remain
1028 // visible. 1034 // visible.
1029 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED, 1035 IEExec(&CGID_DocHostCommandHandler, OLECMDID_PAGEACTIONBLOCKED,
1030 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL); 1036 0x80000000 | OLECMDIDF_WINDOWSTATE_USERVISIBLE_VALID, NULL, NULL);
1031 } 1037 }
1032 1038
1033 TabProxy* tab_proxy = GetTabProxy(); 1039 TabProxy* tab_proxy = GetTabProxy();
1034 if (tab_proxy) 1040 if (tab_proxy) {
1035 tab_proxy->ReloadAsync(); 1041 tab_proxy->ReloadAsync();
1042 } else {
1043 DLOG(ERROR) << "No automation proxy";
1044 // The current url request manager (url_fetcher_) has been switched to
1045 // a stopping state so we need to reset it and get a new one for the new
1046 // automation server.
1047 ResetUrlRequestManager();
1048 url_fetcher_->set_frame_busting(false);
1049 // And now launch the current URL again. This starts a new server process.
1050 DCHECK(navigation_info_.url.is_valid());
1051 ChromeFrameUrl cf_url;
1052 cf_url.Parse(UTF8ToWide(navigation_info_.url.spec()));
1053 LaunchUrl(cf_url, navigation_info_.referrer.spec());
1054 }
1036 1055
1037 return S_OK; 1056 return S_OK;
1038 } 1057 }
1039 1058
1040
1041 HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid, 1059 HRESULT ChromeActiveDocument::SetPageFontSize(const GUID* cmd_group_guid,
1042 DWORD command_id, 1060 DWORD command_id,
1043 DWORD cmd_exec_opt, 1061 DWORD cmd_exec_opt,
1044 VARIANT* in_args, 1062 VARIANT* in_args,
1045 VARIANT* out_args) { 1063 VARIANT* out_args) {
1046 if (!automation_client_.get()) { 1064 if (!automation_client_.get()) {
1047 NOTREACHED() << "Invalid automation client"; 1065 NOTREACHED() << "Invalid automation client";
1048 return E_FAIL; 1066 return E_FAIL;
1049 } 1067 }
1050 1068
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 web_browser2->put_Height(dimensions_.height()); 1271 web_browser2->put_Height(dimensions_.height());
1254 web_browser2->put_Left(dimensions_.x()); 1272 web_browser2->put_Left(dimensions_.x());
1255 web_browser2->put_Top(dimensions_.y()); 1273 web_browser2->put_Top(dimensions_.y());
1256 web_browser2->put_MenuBar(VARIANT_FALSE); 1274 web_browser2->put_MenuBar(VARIANT_FALSE);
1257 web_browser2->put_ToolBar(VARIANT_FALSE); 1275 web_browser2->put_ToolBar(VARIANT_FALSE);
1258 1276
1259 dimensions_.set_height(0); 1277 dimensions_.set_height(0);
1260 dimensions_.set_width(0); 1278 dimensions_.set_width(0);
1261 } 1279 }
1262 } 1280 }
OLDNEW
« no previous file with comments | « chrome_frame/chrome_active_document.h ('k') | chrome_frame/chrome_frame_activex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698