diff options
author | brg@chromium.com <brg@chromium.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 00:02:44 +0000 |
---|---|---|
committer | brg@chromium.com <brg@chromium.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-23 00:02:44 +0000 |
commit | 1ebed56434c220f82cf220bbb72a136fea962c87 (patch) | |
tree | 7058028de7d017612d46ee49ba27b497c89cea7a /chrome/browser/tab_contents | |
parent | 3c4d38386f27b5fc4a7a8db717ea114725c34b4a (diff) | |
download | chromium_src-1ebed56434c220f82cf220bbb72a136fea962c87.zip chromium_src-1ebed56434c220f82cf220bbb72a136fea962c87.tar.gz chromium_src-1ebed56434c220f82cf220bbb72a136fea962c87.tar.bz2 |
Changes to insure that when in app-mode, links open in the default browser. This change should have no affect on Chrome when not in app-mode.Tested against Gmail. UITests added as app_mode_navigation_uitest.
Review URL: http://codereview.chromium.org/18093
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8523 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_delegate.h | 14 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.cc | 49 | ||||
-rw-r--r-- | chrome/browser/tab_contents/web_contents.h | 4 |
3 files changed, 48 insertions, 19 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index 599b64c..85458ba 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -30,8 +30,7 @@ class TabContentsDelegate : public PageNavigator { virtual void OpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition, - PageTransition::Type transition) - { + PageTransition::Type transition) { OpenURLFromTab(NULL, url, referrer, disposition, transition); } @@ -102,11 +101,14 @@ class TabContentsDelegate : public PageNavigator { // application. virtual bool IsApplication() { return false; } + // Check whether or not the url should be opened in the default browser. + virtual bool ShouldOpenURLInDefaultBrowser() const { return false; } + // Detach the given tab and convert it to a "webapp" view. The tab must be // a WebContents with a valid WebApp set. virtual void ConvertContentsToApplication(TabContents* source) { } - // Informs the TabContentsDelegate that some of our state has changed + // Informs the TabContentsDelegate that some of our state has changed // for this tab. virtual void ContentsStateChanged(TabContents* source) {} @@ -129,11 +131,11 @@ class TabContentsDelegate : public PageNavigator { // Tells us that we've finished firing this tab's beforeunload event. // The proceed bool tells us whether the user chose to proceed closing the // tab. Returns true if the tab can continue on firing it's unload event. - // If we're closing the entire browser, then we'll want to delay firing + // If we're closing the entire browser, then we'll want to delay firing // unload events until all the beforeunload events have fired. virtual void BeforeUnloadFired(TabContents* tab, - bool proceed, - bool* proceed_to_fire_unload) { + bool proceed, + bool* proceed_to_fire_unload) { *proceed_to_fire_unload = true; } diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc index cf36173..05a026a 100644 --- a/chrome/browser/tab_contents/web_contents.cc +++ b/chrome/browser/tab_contents/web_contents.cc @@ -17,6 +17,7 @@ #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/download_request_manager.h" +#include "chrome/browser/external_protocol_handler.h" #include "chrome/browser/find_notification_details.h" #include "chrome/browser/google_util.h" #include "chrome/browser/js_before_unload_handler.h" @@ -389,7 +390,7 @@ bool WebContents::NavigateToPendingEntry(bool reload) { } // Clear any provisional password saves - this stops password infobars - // showing up on pages the user navigates to while the right page is + // showing up on pages the user navigates to while the right page is // loading. GetPasswordManager()->ClearProvisionalSave(); @@ -417,7 +418,7 @@ void WebContents::Copy() { } void WebContents::Paste() { - render_view_host()->Paste(); + render_view_host()->Paste(); } void WebContents::DisassociateFromPopupCount() { @@ -619,7 +620,7 @@ bool WebContents::IsActiveEntry(int32 page_id) { } void WebContents::SetInitialFocus(bool reverse) { - render_view_host()->SetInitialFocus(reverse); + render_view_host()->SetInitialFocus(reverse); } // Notifies the RenderWidgetHost instance about the fact that the page is @@ -684,22 +685,30 @@ void WebContents::DidNavigate(RenderViewHost* rvh, if (PageTransition::IsMainFrame(params.transition)) render_manager_.DidNavigateMainFrame(rvh); + // This is the first chance a new frame has to launch an external browser + // since it is the first message from the renderer to the WebContents + // containing the URL. + if (delegate() && delegate()->ShouldOpenURLInDefaultBrowser()) { + OpenUrlInDefaultBrowserAndClosePage(params.url, rvh); + return; + } + // We can't do anything about navigations when we're inactive. if (!controller() || !is_active()) - return; + return; // Update the site of the SiteInstance if it doesn't have one yet. if (!GetSiteInstance()->has_site()) GetSiteInstance()->SetSite(params.url); - // Need to update MIME type here because it's referred to in + // Need to update MIME type here because it's referred to in // UpdateNavigationCommands() called by RendererDidNavigate() to - // determine whether or not to enable the encoding menu. - // It's updated only for the main frame. For a subframe, + // determine whether or not to enable the encoding menu. + // It's updated only for the main frame. For a subframe, // RenderView::UpdateURL does not set params.contents_mime_type. // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) - // TODO(jungshik): Add a test for the encoding menu to avoid - // regressing it again. + // TODO(jungshik): Add a test for the encoding menu to avoid + // regressing it again. if (PageTransition::IsMainFrame(params.transition)) contents_mime_type_ = params.contents_mime_type; @@ -958,7 +967,12 @@ void WebContents::DidDownloadImage( void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, WindowOpenDisposition disposition) { - OpenURL(url, referrer, disposition, PageTransition::LINK); + if (!delegate() || !delegate()->ShouldOpenURLInDefaultBrowser()) { + OpenURL(url, referrer, disposition, PageTransition::LINK); + } else { + OpenUrlInDefaultBrowserAndClosePage(url, render_view_host()); + return; + } } void WebContents::DomOperationResponse(const std::string& json_string, @@ -1073,7 +1087,7 @@ void WebContents::AutofillFormSubmitted( GetAutofillManager()->AutofillFormSubmitted(form); } -void WebContents::GetAutofillSuggestions(const std::wstring& field_name, +void WebContents::GetAutofillSuggestions(const std::wstring& field_name, const std::wstring& user_text, int64 node_id, int request_id) { GetAutofillManager()->FetchValuesForName(field_name, user_text, kMaxAutofillMenuItems, node_id, request_id); @@ -1288,7 +1302,7 @@ bool WebContents::CanBlur() const { return delegate() ? delegate()->CanBlur() : true; } -void WebContents::RendererUnresponsive(RenderViewHost* rvh, +void WebContents::RendererUnresponsive(RenderViewHost* rvh, bool is_during_unload) { if (is_during_unload) { // Hang occurred while firing the beforeunload/unload handler. @@ -1679,7 +1693,7 @@ bool WebContents::UpdateTitleForEntry(NavigationEntry* entry, profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); if (hs) hs->SetPageTitle(entry->display_url(), final_title); - + // Don't allow the title to be saved again for explicitly set ones. received_page_title_ = explicit_set; } @@ -1794,3 +1808,12 @@ void WebContents::GenerateKeywordIfNecessary( new_url->set_safe_for_autoreplace(true); url_model->Add(new_url); } + +void WebContents::OpenUrlInDefaultBrowserAndClosePage(const GURL& url, + RenderViewHost* rvh) { + if (!url.is_empty() && rvh && rvh->process()) { + ExternalProtocolHandler::LaunchUrl(url, rvh->routing_id(), + rvh->process()->host_id()); + } + ShouldClosePage(true); +}
\ No newline at end of file diff --git a/chrome/browser/tab_contents/web_contents.h b/chrome/browser/tab_contents/web_contents.h index c3094a4..c780fe9 100644 --- a/chrome/browser/tab_contents/web_contents.h +++ b/chrome/browser/tab_contents/web_contents.h @@ -480,6 +480,10 @@ class WebContents : public TabContents, void GenerateKeywordIfNecessary( const ViewHostMsg_FrameNavigate_Params& params); + // Helper function to launch the external browser. + void OpenUrlInDefaultBrowserAndClosePage(const GURL& url, + RenderViewHost* rvh); + // Data ---------------------------------------------------------------------- // The corresponding view. |