Chromium Code Reviews| Index: chrome/browser/ui/extensions/shell_window.cc |
| diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc |
| index bcfe4d28c14d6a0ffc9add047aea9043438e5922..ffaf9afb2463eb67e7af7c64ec378a9dc403b44c 100644 |
| --- a/chrome/browser/ui/extensions/shell_window.cc |
| +++ b/chrome/browser/ui/extensions/shell_window.cc |
| @@ -13,6 +13,7 @@ |
| #include "chrome/browser/infobars/infobar_tab_helper.h" |
| #include "chrome/browser/intents/web_intents_util.h" |
| #include "chrome/browser/lifetime/application_lifetime.h" |
| +#include "chrome/browser/platform_util.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sessions/session_id.h" |
| #include "chrome/browser/ui/browser.h" |
| @@ -63,6 +64,40 @@ void SuspendRenderViewHost(RenderViewHost* rvh) { |
| } // namespace |
| +// ExternalWebContentImpl is Web content delegate for link navigation. |
| +// It helps to open URL in system default browser. |
| +class ExternalWebContentImpl : public content::WebContentsDelegate { |
| + public: |
| + ExternalWebContentImpl() {} |
| + virtual ~ExternalWebContentImpl() {} |
| + |
| + private: |
| + // content::WebContentsDelegate implementation. |
| + virtual content::WebContents* OpenURLFromTab( |
| + content::WebContents* source, |
| + const content::OpenURLParams& params) OVERRIDE; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExternalWebContentImpl); |
| +}; |
| + |
| +content::WebContents* ExternalWebContentImpl::OpenURLFromTab( |
| + content::WebContents* source, |
| + const content::OpenURLParams& params) { |
| +#if defined(OS_MACOSX) |
| + // This must run on the UI thread on OS X. |
| + platform_util::OpenExternal(params.url); |
| +#else |
| + // Otherwise put this work on the file thread. On Windows ShellExecute may |
| + // block for a significant amount of time, and it shouldn't hurt on Linux. |
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&platform_util::OpenExternal, params.url)); |
| +#endif |
| + |
| + return NULL; |
| +} |
| + |
| ShellWindow::CreateParams::CreateParams() |
| : frame(ShellWindow::CreateParams::FRAME_CHROME), |
| bounds(-1, -1, kDefaultWidth, kDefaultHeight), |
| @@ -259,6 +294,12 @@ void ShellWindow::AddNewContents(WebContents* source, |
| DCHECK(source == web_contents_); |
| DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| profile_); |
| + |
| +#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_POSIX) |
|
Mihai Parparita -not on Chrome
2012/09/05 18:15:10
What platform are you looking to avoid here? Chrom
|
| + if (!external_content_delegate_.get()) |
| + external_content_delegate_.reset(new ExternalWebContentImpl()); |
|
Mihai Parparita -not on Chrome
2012/09/05 18:15:10
Seems like ExternalWebContentImpl could be a singl
|
| + new_contents->SetDelegate(external_content_delegate_.get()); |
| +#else |
| Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); |
| // Force all links to open in a new tab, even if they were trying to open a |
| // new window. |
| @@ -266,6 +307,7 @@ void ShellWindow::AddNewContents(WebContents* source, |
| disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, |
| user_gesture); |
| +#endif |
| } |
| void ShellWindow::HandleKeyboardEvent( |