diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-01 04:15:00 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-01 04:15:00 +0000 |
commit | 32b7c4995d5f5ecc034999c02c28ded2190c6888 (patch) | |
tree | 8c497d9e6360444b65959e7b4f2911bea781b917 | |
parent | 771f68f817de7ce98949b29a68aa8778c7553640 (diff) | |
download | chromium_src-32b7c4995d5f5ecc034999c02c28ded2190c6888.zip chromium_src-32b7c4995d5f5ecc034999c02c28ded2190c6888.tar.gz chromium_src-32b7c4995d5f5ecc034999c02c28ded2190c6888.tar.bz2 |
window.open() from an extension should always goes in normal browser. When the split incognito stuff lands, I will change this to allow window.open() to go to incognito if you're in split mode.
BUG=52298
TEST=browser_tests --gtest_filter=ExtensionApiTest.WindowOpen
Review URL: http://codereview.chromium.org/3249012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58120 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 93 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_host.cc b/chrome/browser/extensions/extension_host.cc index f43501b..39e3cd9 100644 --- a/chrome/browser/extensions/extension_host.cc +++ b/chrome/browser/extensions/extension_host.cc @@ -15,6 +15,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_shutdown.h" +#include "chrome/browser/browser_window.h" #include "chrome/browser/browsing_instance.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/dom_ui/dom_ui_factory.h" @@ -509,6 +510,8 @@ void ExtensionHost::CreateNewWindow( int route_id, WindowContainerType window_container_type, const string16& frame_name) { + // TODO(aa): Use the browser's profile if the extension is split mode + // incognito. delegate_view_helper_.CreateNewWindow( route_id, render_view_host()->process()->profile(), @@ -545,10 +548,14 @@ void ExtensionHost::ShowCreatedWindow(int route_id, if (!contents) return; - Browser* browser = extension_function_dispatcher_->GetCurrentBrowser( - profile_->GetExtensionsService()->IsIncognitoEnabled(extension_)); - if (!browser) - return; + Browser* browser = BrowserList::FindBrowserWithType( + contents->profile(), + Browser::TYPE_NORMAL, + false); // Match incognito exactly. + if (!browser) { + browser = Browser::Create(contents->profile()); + browser->window()->Show(); + } browser->AddTabContents(contents, disposition, initial_pos, user_gesture); } diff --git a/chrome/browser/extensions/window_open_apitest.cc b/chrome/browser/extensions/window_open_apitest.cc new file mode 100644 index 0000000..2360241 --- /dev/null +++ b/chrome/browser/extensions/window_open_apitest.cc @@ -0,0 +1,17 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/command_line.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/common/chrome_switches.h" + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpen) { + CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableExperimentalExtensionApis); + + ResultCatcher catcher; + ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ + .AppendASCII("window_open").AppendASCII("spanning"))); + EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 7c838ec..7b6befc 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1751,6 +1751,7 @@ 'browser/extensions/page_action_apitest.cc', 'browser/extensions/permissions_apitest.cc', 'browser/extensions/stubs_apitest.cc', + 'browser/extensions/window_open_apitest.cc', 'browser/find_bar_host_browsertest.cc', 'browser/first_run/first_run_browsertest.cc', 'browser/geolocation/access_token_store_browsertest.cc', diff --git a/chrome/test/data/extensions/api_test/window_open/spanning/background.html b/chrome/test/data/extensions/api_test/window_open/spanning/background.html new file mode 100755 index 0000000..17c3ecc --- /dev/null +++ b/chrome/test/data/extensions/api_test/window_open/spanning/background.html @@ -0,0 +1,52 @@ +<script> +var nextTest = null; +openFromNormalShouldOpenInNormal(); + +function openFromNormalShouldOpenInNormal() { + nextTest = openFromExtensionHostInIncognitoBrowserShouldOpenInNormalBrowser; + chrome.windows.getAll({populate: true}, function(windows) { + chrome.test.assertEq(1, windows.length); + chrome.test.assertFalse(windows[0].incognito); + chrome.test.assertEq(1, windows[0].tabs.length); + chrome.test.assertFalse(windows[0].tabs[0].incognito); + + // The rest of the test continues in infobar.html. + chrome.experimental.infobars.show({tabId: windows[0].tabs[0].id, + path: "infobar.html"}); + }); +} + +function openFromExtensionHostInIncognitoBrowserShouldOpenInNormalBrowser() { + nextTest = null; + chrome.windows.getCurrent(function(normalWin) { + chrome.test.assertFalse(normalWin.incognito); + // Create an incognito window. + chrome.windows.create({ incognito: true }, function(incognitoWin) { + // Remove the normal window. We keep running because of the incognito + // window. + chrome.windows.remove(normalWin.id, function() { + chrome.tabs.getAllInWindow(incognitoWin.id, function(tabs) { + chrome.test.assertEq(1, tabs.length); + // The rest of the test continues in infobar.html. + chrome.experimental.infobars.show({tabId: tabs[0].id, + path: "infobar.html"}); + }); + }); + }); + }); +} + +function verifyCreatedTab(tab) { + // The new tab should be a normal tab, and it should be in a normal + // window. + chrome.test.assertFalse(tab.incognito); + chrome.windows.get(tab.windowId, function(win) { + chrome.test.assertFalse(win.incognito); + if (nextTest) { + nextTest(); + } else { + chrome.test.notifyPass(); + } + }); +} +</script> diff --git a/chrome/test/data/extensions/api_test/window_open/spanning/foo.html b/chrome/test/data/extensions/api_test/window_open/spanning/foo.html new file mode 100755 index 0000000..a4d20dd --- /dev/null +++ b/chrome/test/data/extensions/api_test/window_open/spanning/foo.html @@ -0,0 +1 @@ +foo!
\ No newline at end of file diff --git a/chrome/test/data/extensions/api_test/window_open/spanning/infobar.html b/chrome/test/data/extensions/api_test/window_open/spanning/infobar.html new file mode 100755 index 0000000..f5d4a60 --- /dev/null +++ b/chrome/test/data/extensions/api_test/window_open/spanning/infobar.html @@ -0,0 +1,5 @@ +<script> +chrome.test.listenOnce(chrome.tabs.onCreated, + chrome.extension.getBackgroundPage().verifyCreatedTab); +window.open('foo.html'); +</script> diff --git a/chrome/test/data/extensions/api_test/window_open/spanning/manifest.json b/chrome/test/data/extensions/api_test/window_open/spanning/manifest.json new file mode 100644 index 0000000..991756d --- /dev/null +++ b/chrome/test/data/extensions/api_test/window_open/spanning/manifest.json @@ -0,0 +1,6 @@ +{ + "name": "window.open test - spanning", + "version": "1", + "permissions": ["experimental", "tabs"], + "background_page": "background.html" +} |