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

Side by Side Diff: chrome/browser/tab_contents/web_contents.cc

Issue 18093: Changes to insure that when in app-mode, links open in the default browser. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/tab_contents/web_contents.h" 5 #include "chrome/browser/tab_contents/web_contents.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_version_info.h" 9 #include "base/file_version_info.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "chrome/app/locales/locale_settings.h" 11 #include "chrome/app/locales/locale_settings.h"
12 #include "chrome/browser/autofill_manager.h" 12 #include "chrome/browser/autofill_manager.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/browser.h" 14 #include "chrome/browser/browser.h"
15 #include "chrome/browser/cache_manager_host.h" 15 #include "chrome/browser/cache_manager_host.h"
16 #include "chrome/browser/character_encoding.h" 16 #include "chrome/browser/character_encoding.h"
17 #include "chrome/browser/dom_operation_notification_details.h" 17 #include "chrome/browser/dom_operation_notification_details.h"
18 #include "chrome/browser/download/download_manager.h" 18 #include "chrome/browser/download/download_manager.h"
19 #include "chrome/browser/download/download_request_manager.h" 19 #include "chrome/browser/download/download_request_manager.h"
20 #include "chrome/browser/external_protocol_handler.h"
20 #include "chrome/browser/find_notification_details.h" 21 #include "chrome/browser/find_notification_details.h"
21 #include "chrome/browser/google_util.h" 22 #include "chrome/browser/google_util.h"
22 #include "chrome/browser/js_before_unload_handler.h" 23 #include "chrome/browser/js_before_unload_handler.h"
23 #include "chrome/browser/jsmessage_box_handler.h" 24 #include "chrome/browser/jsmessage_box_handler.h"
24 #include "chrome/browser/load_from_memory_cache_details.h" 25 #include "chrome/browser/load_from_memory_cache_details.h"
25 #include "chrome/browser/load_notification_details.h" 26 #include "chrome/browser/load_notification_details.h"
26 #include "chrome/browser/modal_html_dialog_delegate.h" 27 #include "chrome/browser/modal_html_dialog_delegate.h"
27 #include "chrome/browser/password_manager/password_manager.h" 28 #include "chrome/browser/password_manager/password_manager.h"
28 #include "chrome/browser/plugin_installer.h" 29 #include "chrome/browser/plugin_installer.h"
29 #include "chrome/browser/plugin_service.h" 30 #include "chrome/browser/plugin_service.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // HACK!! This code suppresses javascript: URLs from being added to 383 // HACK!! This code suppresses javascript: URLs from being added to
383 // session history, which is what we want to do for javascript: URLs that 384 // session history, which is what we want to do for javascript: URLs that
384 // do not generate content. What we really need is a message from the 385 // do not generate content. What we really need is a message from the
385 // renderer telling us that a new page was not created. The same message 386 // renderer telling us that a new page was not created. The same message
386 // could be used for mailto: URLs and the like. 387 // could be used for mailto: URLs and the like.
387 if (entry->url().SchemeIs("javascript")) 388 if (entry->url().SchemeIs("javascript"))
388 return false; 389 return false;
389 } 390 }
390 391
391 // Clear any provisional password saves - this stops password infobars 392 // Clear any provisional password saves - this stops password infobars
392 // showing up on pages the user navigates to while the right page is 393 // showing up on pages the user navigates to while the right page is
393 // loading. 394 // loading.
394 GetPasswordManager()->ClearProvisionalSave(); 395 GetPasswordManager()->ClearProvisionalSave();
395 396
396 if (reload && !profile()->IsOffTheRecord()) { 397 if (reload && !profile()->IsOffTheRecord()) {
397 HistoryService* history = 398 HistoryService* history =
398 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); 399 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
399 if (history) 400 if (history)
400 history->SetFavIconOutOfDateForPage(entry->url()); 401 history->SetFavIconOutOfDateForPage(entry->url());
401 } 402 }
402 403
403 return true; 404 return true;
404 } 405 }
405 406
406 void WebContents::Stop() { 407 void WebContents::Stop() {
407 render_manager_.Stop(); 408 render_manager_.Stop();
408 printing_.Stop(); 409 printing_.Stop();
409 } 410 }
410 411
411 void WebContents::Cut() { 412 void WebContents::Cut() {
412 render_view_host()->Cut(); 413 render_view_host()->Cut();
413 } 414 }
414 415
415 void WebContents::Copy() { 416 void WebContents::Copy() {
416 render_view_host()->Copy(); 417 render_view_host()->Copy();
417 } 418 }
418 419
419 void WebContents::Paste() { 420 void WebContents::Paste() {
420 render_view_host()->Paste(); 421 render_view_host()->Paste();
421 } 422 }
422 423
423 void WebContents::DisassociateFromPopupCount() { 424 void WebContents::DisassociateFromPopupCount() {
424 render_view_host()->DisassociateFromPopupCount(); 425 render_view_host()->DisassociateFromPopupCount();
425 } 426 }
426 427
427 void WebContents::DidBecomeSelected() { 428 void WebContents::DidBecomeSelected() {
428 TabContents::DidBecomeSelected(); 429 TabContents::DidBecomeSelected();
429 430
430 if (render_widget_host_view()) 431 if (render_widget_host_view())
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 } 613 }
613 614
614 bool WebContents::IsActiveEntry(int32 page_id) { 615 bool WebContents::IsActiveEntry(int32 page_id) {
615 NavigationEntry* active_entry = controller()->GetActiveEntry(); 616 NavigationEntry* active_entry = controller()->GetActiveEntry();
616 return (active_entry != NULL && 617 return (active_entry != NULL &&
617 active_entry->site_instance() == GetSiteInstance() && 618 active_entry->site_instance() == GetSiteInstance() &&
618 active_entry->page_id() == page_id); 619 active_entry->page_id() == page_id);
619 } 620 }
620 621
621 void WebContents::SetInitialFocus(bool reverse) { 622 void WebContents::SetInitialFocus(bool reverse) {
622 render_view_host()->SetInitialFocus(reverse); 623 render_view_host()->SetInitialFocus(reverse);
623 } 624 }
624 625
625 // Notifies the RenderWidgetHost instance about the fact that the page is 626 // Notifies the RenderWidgetHost instance about the fact that the page is
626 // loading, or done loading and calls the base implementation. 627 // loading, or done loading and calls the base implementation.
627 void WebContents::SetIsLoading(bool is_loading, 628 void WebContents::SetIsLoading(bool is_loading,
628 LoadNotificationDetails* details) { 629 LoadNotificationDetails* details) {
629 if (!is_loading) { 630 if (!is_loading) {
630 load_state_ = net::LOAD_STATE_IDLE; 631 load_state_ = net::LOAD_STATE_IDLE;
631 load_state_host_.clear(); 632 load_state_host_.clear();
632 } 633 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 678
678 // Hide any visible hung renderer warning for this web contents' process. 679 // Hide any visible hung renderer warning for this web contents' process.
679 HungRendererWarning::HideForWebContents(this); 680 HungRendererWarning::HideForWebContents(this);
680 } 681 }
681 682
682 void WebContents::DidNavigate(RenderViewHost* rvh, 683 void WebContents::DidNavigate(RenderViewHost* rvh,
683 const ViewHostMsg_FrameNavigate_Params& params) { 684 const ViewHostMsg_FrameNavigate_Params& params) {
684 if (PageTransition::IsMainFrame(params.transition)) 685 if (PageTransition::IsMainFrame(params.transition))
685 render_manager_.DidNavigateMainFrame(rvh); 686 render_manager_.DidNavigateMainFrame(rvh);
686 687
688 // This is the first chance a new frame has to launch an external browser
689 // since it is the first message from the renderer to the WebContents
690 // containing the URL.
691 if (delegate() && delegate()->ShouldOpenURLInDefaultBrowser()) {
692 OpenUrlInDefaultBrowserAndClosePage(params.url, rvh);
693 return;
694 }
695
687 // We can't do anything about navigations when we're inactive. 696 // We can't do anything about navigations when we're inactive.
688 if (!controller() || !is_active()) 697 if (!controller() || !is_active())
689 return; 698 return;
690 699
691 // Update the site of the SiteInstance if it doesn't have one yet. 700 // Update the site of the SiteInstance if it doesn't have one yet.
692 if (!GetSiteInstance()->has_site()) 701 if (!GetSiteInstance()->has_site())
693 GetSiteInstance()->SetSite(params.url); 702 GetSiteInstance()->SetSite(params.url);
694 703
695 // Need to update MIME type here because it's referred to in 704 // Need to update MIME type here because it's referred to in
696 // UpdateNavigationCommands() called by RendererDidNavigate() to 705 // UpdateNavigationCommands() called by RendererDidNavigate() to
697 // determine whether or not to enable the encoding menu. 706 // determine whether or not to enable the encoding menu.
698 // It's updated only for the main frame. For a subframe, 707 // It's updated only for the main frame. For a subframe,
699 // RenderView::UpdateURL does not set params.contents_mime_type. 708 // RenderView::UpdateURL does not set params.contents_mime_type.
700 // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) 709 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
701 // TODO(jungshik): Add a test for the encoding menu to avoid 710 // TODO(jungshik): Add a test for the encoding menu to avoid
702 // regressing it again. 711 // regressing it again.
703 if (PageTransition::IsMainFrame(params.transition)) 712 if (PageTransition::IsMainFrame(params.transition))
704 contents_mime_type_ = params.contents_mime_type; 713 contents_mime_type_ = params.contents_mime_type;
705 714
706 NavigationController::LoadCommittedDetails details; 715 NavigationController::LoadCommittedDetails details;
707 if (!controller()->RendererDidNavigate(params, &details)) 716 if (!controller()->RendererDidNavigate(params, &details))
708 return; // No navigation happened. 717 return; // No navigation happened.
709 718
710 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen 719 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
711 // for the appropriate notification (best) or you can add it to 720 // for the appropriate notification (best) or you can add it to
712 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if 721 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 if (errored) 960 if (errored)
952 fav_icon_helper_.FavIconDownloadFailed(id); 961 fav_icon_helper_.FavIconDownloadFailed(id);
953 else 962 else
954 fav_icon_helper_.SetFavIcon(id, image_url, image); 963 fav_icon_helper_.SetFavIcon(id, image_url, image);
955 if (web_app_.get() && !errored) 964 if (web_app_.get() && !errored)
956 web_app_->SetImage(image_url, image); 965 web_app_->SetImage(image_url, image);
957 } 966 }
958 967
959 void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, 968 void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer,
960 WindowOpenDisposition disposition) { 969 WindowOpenDisposition disposition) {
961 OpenURL(url, referrer, disposition, PageTransition::LINK); 970 if (!delegate() || !delegate()->ShouldOpenURLInDefaultBrowser()) {
971 OpenURL(url, referrer, disposition, PageTransition::LINK);
972 } else {
973 OpenUrlInDefaultBrowserAndClosePage(url, render_view_host());
974 return;
975 }
962 } 976 }
963 977
964 void WebContents::DomOperationResponse(const std::string& json_string, 978 void WebContents::DomOperationResponse(const std::string& json_string,
965 int automation_id) { 979 int automation_id) {
966 DomOperationNotificationDetails details(json_string, automation_id); 980 DomOperationNotificationDetails details(json_string, automation_id);
967 NotificationService::current()->Notify( 981 NotificationService::current()->Notify(
968 NOTIFY_DOM_OPERATION_RESPONSE, Source<WebContents>(this), 982 NOTIFY_DOM_OPERATION_RESPONSE, Source<WebContents>(this),
969 Details<DomOperationNotificationDetails>(&details)); 983 Details<DomOperationNotificationDetails>(&details));
970 } 984 }
971 985
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 void WebContents::PasswordFormsSeen( 1080 void WebContents::PasswordFormsSeen(
1067 const std::vector<PasswordForm>& forms) { 1081 const std::vector<PasswordForm>& forms) {
1068 GetPasswordManager()->PasswordFormsSeen(forms); 1082 GetPasswordManager()->PasswordFormsSeen(forms);
1069 } 1083 }
1070 1084
1071 void WebContents::AutofillFormSubmitted( 1085 void WebContents::AutofillFormSubmitted(
1072 const AutofillForm& form) { 1086 const AutofillForm& form) {
1073 GetAutofillManager()->AutofillFormSubmitted(form); 1087 GetAutofillManager()->AutofillFormSubmitted(form);
1074 } 1088 }
1075 1089
1076 void WebContents::GetAutofillSuggestions(const std::wstring& field_name, 1090 void WebContents::GetAutofillSuggestions(const std::wstring& field_name,
1077 const std::wstring& user_text, int64 node_id, int request_id) { 1091 const std::wstring& user_text, int64 node_id, int request_id) {
1078 GetAutofillManager()->FetchValuesForName(field_name, user_text, 1092 GetAutofillManager()->FetchValuesForName(field_name, user_text,
1079 kMaxAutofillMenuItems, node_id, request_id); 1093 kMaxAutofillMenuItems, node_id, request_id);
1080 } 1094 }
1081 1095
1082 // Checks to see if we should generate a keyword based on the OSDD, and if 1096 // Checks to see if we should generate a keyword based on the OSDD, and if
1083 // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. 1097 // necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
1084 void WebContents::PageHasOSDD(RenderViewHost* render_view_host, 1098 void WebContents::PageHasOSDD(RenderViewHost* render_view_host,
1085 int32 page_id, const GURL& url, 1099 int32 page_id, const GURL& url,
1086 bool autodetected) { 1100 bool autodetected) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1281 1295
1282 void WebContents::OnJSOutOfMemory() { 1296 void WebContents::OnJSOutOfMemory() {
1283 AddInfoBar(new SimpleAlertInfoBarDelegate( 1297 AddInfoBar(new SimpleAlertInfoBarDelegate(
1284 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL)); 1298 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
1285 } 1299 }
1286 1300
1287 bool WebContents::CanBlur() const { 1301 bool WebContents::CanBlur() const {
1288 return delegate() ? delegate()->CanBlur() : true; 1302 return delegate() ? delegate()->CanBlur() : true;
1289 } 1303 }
1290 1304
1291 void WebContents::RendererUnresponsive(RenderViewHost* rvh, 1305 void WebContents::RendererUnresponsive(RenderViewHost* rvh,
1292 bool is_during_unload) { 1306 bool is_during_unload) {
1293 if (is_during_unload) { 1307 if (is_during_unload) {
1294 // Hang occurred while firing the beforeunload/unload handler. 1308 // Hang occurred while firing the beforeunload/unload handler.
1295 // Pretend the handler fired so tab closing continues as if it had. 1309 // Pretend the handler fired so tab closing continues as if it had.
1296 rvh->UnloadListenerHasFired(); 1310 rvh->UnloadListenerHasFired();
1297 1311
1298 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) { 1312 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) {
1299 return; 1313 return;
1300 } 1314 }
1301 1315
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 return false; // Nothing changed, don't bother. 1686 return false; // Nothing changed, don't bother.
1673 1687
1674 entry->set_title(final_title); 1688 entry->set_title(final_title);
1675 1689
1676 // Update the history system for this page. 1690 // Update the history system for this page.
1677 if (!profile()->IsOffTheRecord() && !received_page_title_) { 1691 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1678 HistoryService* hs = 1692 HistoryService* hs =
1679 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); 1693 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1680 if (hs) 1694 if (hs)
1681 hs->SetPageTitle(entry->display_url(), final_title); 1695 hs->SetPageTitle(entry->display_url(), final_title);
1682 1696
1683 // Don't allow the title to be saved again for explicitly set ones. 1697 // Don't allow the title to be saved again for explicitly set ones.
1684 received_page_title_ = explicit_set; 1698 received_page_title_ = explicit_set;
1685 } 1699 }
1686 1700
1687 // Lastly, set the title for the view. 1701 // Lastly, set the title for the view.
1688 view_->SetPageTitle(final_title); 1702 view_->SetPageTitle(final_title);
1689 1703
1690 return true; 1704 return true;
1691 } 1705 }
1692 1706
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 // The favicon url isn't valid. This means there really isn't a favicon, 1801 // The favicon url isn't valid. This means there really isn't a favicon,
1788 // or the favicon url wasn't obtained before the load started. This assumes 1802 // or the favicon url wasn't obtained before the load started. This assumes
1789 // the later. 1803 // the later.
1790 // TODO(sky): Need a way to set the favicon that doesn't involve generating 1804 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1791 // its url. 1805 // its url.
1792 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); 1806 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1793 } 1807 }
1794 new_url->set_safe_for_autoreplace(true); 1808 new_url->set_safe_for_autoreplace(true);
1795 url_model->Add(new_url); 1809 url_model->Add(new_url);
1796 } 1810 }
1811
1812 void WebContents::OpenUrlInDefaultBrowserAndClosePage(const GURL& url,
1813 RenderViewHost* rvh) {
1814 if (!url.is_empty() && rvh && rvh->process()) {
1815 ExternalProtocolHandler::LaunchUrl(url, rvh->routing_id(),
1816 rvh->process()->host_id());
1817 }
1818 ShouldClosePage(true);
1819 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698