Commit cfa620c7 authored by rockot@chromium.org's avatar rockot@chromium.org

Open new-window links externally from within packaged apps.

From within a packaged app, clicking target=_blank links or calling window.open will now launch the given URL using the system's default handler. 

This behavior only affects Linux, OS X, and Windows builds. 

BUG=145646,227011

Review URL: https://chromiumcodereview.appspot.com/15720009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203909 0039d316-1c4b-4281-b951-d872f2087c98
parent 0b59171c
......@@ -22,6 +22,10 @@ namespace utils = extension_function_test_utils;
namespace extensions {
PlatformAppBrowserTest::PlatformAppBrowserTest() {
ShellWindow::DisableExternalOpenForTesting();
}
void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
// Skips ExtensionApiTest::SetUpCommandLine.
ExtensionBrowserTest::SetUpCommandLine(command_line);
......
......@@ -21,6 +21,8 @@ class Extension;
class PlatformAppBrowserTest : public ExtensionApiTest {
public:
PlatformAppBrowserTest();
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
protected:
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.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"
......@@ -67,6 +68,23 @@ const int kPreferredIconSize = ash::kLauncherPreferredSize;
const int kPreferredIconSize = extension_misc::EXTENSION_ICON_SMALL;
#endif
static bool disable_external_open_for_testing_ = false;
class ShellWindowLinkDelegate : public content::WebContentsDelegate {
private:
virtual content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) OVERRIDE;
};
content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
platform_util::OpenExternal(params.url);
delete source;
return NULL;
}
} // namespace
ShellWindow::CreateParams::CreateParams()
......@@ -284,6 +302,20 @@ void ShellWindow::AddNewContents(WebContents* source,
bool* was_blocked) {
DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) ==
profile_);
#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
if (disable_external_open_for_testing_) {
Browser* browser =
chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop());
// Force all links to open in a new tab, even if they were trying to open a
// new window.
disposition =
disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
chrome::AddWebContents(browser, NULL, new_contents, disposition,
initial_pos, user_gesture, was_blocked);
} else {
new_contents->SetDelegate(new ShellWindowLinkDelegate());
}
#else
Browser* browser =
chrome::FindOrCreateTabbedBrowser(profile_, chrome::GetActiveDesktop());
// Force all links to open in a new tab, even if they were trying to open a
......@@ -292,6 +324,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, was_blocked);
#endif
}
void ShellWindow::HandleKeyboardEvent(
......@@ -605,3 +638,8 @@ SkRegion* ShellWindow::RawDraggableRegionsToSkRegion(
}
return sk_region;
}
void ShellWindow::DisableExternalOpenForTesting() {
disable_external_open_for_testing_ = true;
}
......@@ -204,6 +204,8 @@ class ShellWindow : public content::NotificationObserver,
return shell_window_contents_.get();
}
static void DisableExternalOpenForTesting();
protected:
virtual ~ShellWindow();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment