diff options
author | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-02 21:39:23 +0000 |
---|---|---|
committer | tbarzic@chromium.org <tbarzic@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-02 21:39:23 +0000 |
commit | d31a85bdeb3860878205088c40711e5db6a215a6 (patch) | |
tree | f08ee3dee3ce12d904d5f901ecbc0a6accb742c9 | |
parent | 7e73aa3b28742560d4988cb7a1af8c932c7f73cf (diff) | |
download | chromium_src-d31a85bdeb3860878205088c40711e5db6a215a6.zip chromium_src-d31a85bdeb3860878205088c40711e5db6a215a6.tar.gz chromium_src-d31a85bdeb3860878205088c40711e5db6a215a6.tar.bz2 |
Merge 123056 - Fix chrome crash on clicking Scratchpad's "Send to tab"
The crash happens when scratchpad app tries transision from panel window to tabbedd window.
When the "Send to tab" button is clicked, the app closes the panel window and right after that it tries to open itself in a new tab (by calling tabs.create() in callback from tabs.remove(panel_tab).
The problem is that when we try to create new tab, panel browser window is still in browser list (eventhough it is being closed), and it is the browser returned by GetCurrentBrowser.
So, we end up trying to create a new tab in the panel window that is just about to go away (browser navigator does not exchange the params.browser with a tabbed browser because the panel browser has empty tabstrip_model, so creating new tab is allowed)
BUG=chromium-os:25804
TEST=confirmed that crash is not happening locally (on M18 chrome with this patch applied)
Review URL: https://chromiumcodereview.appspot.com/9403032
TBR=tbarzic@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9545018
git-svn-id: svn://svn.chromium.org/chrome/branches/1025/src@124737 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_tabs_module.cc | 7 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_tabs_test.cc | 25 | ||||
-rw-r--r-- | chrome/test/data/extensions/api_test/tabs/basics/crud2.js | 13 |
3 files changed, 45 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index 62e6c18..44947e3 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -868,6 +868,13 @@ bool CreateTabFunction::RunImpl() { if (!GetBrowserFromWindowID(this, window_id, &browser)) return false; + // Ensure the selected browser is tabbed. + if (!browser->is_type_tabbed() && browser->IsAttemptingToCloseBrowser()) + browser = Browser::GetTabbedBrowser(profile(), include_incognito()); + + if (!browser || !browser->window()) + return false; + // TODO(jstritar): Add a constant, chrome.tabs.TAB_ID_ACTIVE, that // represents the active tab. content::NavigationController* opener = NULL; diff --git a/chrome/browser/extensions/extension_tabs_test.cc b/chrome/browser/extensions/extension_tabs_test.cc index 1578b7a..bee8ae1 100644 --- a/chrome/browser/extensions/extension_tabs_test.cc +++ b/chrome/browser/extensions/extension_tabs_test.cc @@ -383,6 +383,31 @@ IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, keys::kIncognitoModeIsDisabled)); } +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { + // Test creates new popup window, closes it right away and then tries to open + // a new tab in it. Tab should not be opened in the popup window, but in a + // tabbed browser window. + Browser* popup_browser = + Browser::CreateForType(Browser::TYPE_POPUP, browser()->profile()); + int window_id = ExtensionTabUtil::GetWindowId(popup_browser); + popup_browser->CloseWindow(); + + scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); + // Without a callback the function will not generate a result. + create_tab_function->set_has_callback(true); + + static const char kNewBlankTabArgs[] = + "[{\"url\": \"about:blank\", \"windowId\": %u}]"; + + scoped_ptr<base::DictionaryValue> result(ToDictionary( + RunFunctionAndReturnResult( + create_tab_function.get(), + base::StringPrintf(kNewBlankTabArgs, window_id), + browser()))); + + EXPECT_NE(window_id, GetInteger(result.get(), "windowId")); +} + IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, InvalidUpdateWindowState) { int window_id = ExtensionTabUtil::GetWindowId(browser()); diff --git a/chrome/test/data/extensions/api_test/tabs/basics/crud2.js b/chrome/test/data/extensions/api_test/tabs/basics/crud2.js index 34a3e5c..300ac72 100644 --- a/chrome/test/data/extensions/api_test/tabs/basics/crud2.js +++ b/chrome/test/data/extensions/api_test/tabs/basics/crud2.js @@ -123,5 +123,18 @@ chrome.test.runTests([ assertTrue(window.id != tab.windowId); })); })); + }, + + // Creation of a tab in an empty non-tabbed window should be allowed. + function testOpenWindowInEmptyPopup() { + chrome.windows.create( + {type: 'popup'}, + pass(function(window) { + chrome.tabs.create( + {url: 'about:blank', windowId: window.id}, + pass(function(tab) { + assertEq(window.id, tab.windowId); + })); + })); } ]); |