Commit b13ae8ca authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Allow tabbed System Web Apps to override new tab URL

If System Web Apps support tabs, then the new tab '+' button
will load the app launch URL rather than the default
chrome://newtab/.

Bug: 990158
Change-Id: I66bc86335135fefe22fbc954d17a52ea88528f02
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1748974Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686397}
parent 5fa517c5
......@@ -159,6 +159,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/ssl_insecure_content.h"
#include "chrome/common/url_constants.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
......@@ -655,6 +656,12 @@ bool Browser::is_devtools() const {
///////////////////////////////////////////////////////////////////////////////
// Browser, State Storage and Retrieval for UI:
GURL Browser::GetNewTabURL() const {
if (app_controller_)
return app_controller_->GetAppLaunchURL();
return GURL(chrome::kChromeUINewTabURL);
}
gfx::Image Browser::GetCurrentPageIcon() const {
WebContents* web_contents = tab_strip_model_->GetActiveWebContents();
// |web_contents| can be NULL since GetCurrentPageIcon() is called by the
......
......@@ -350,6 +350,8 @@ class Browser : public TabStripModelObserver,
// State Storage and Retrieval for UI ///////////////////////////////////////
GURL GetNewTabURL() const;
// Gets the Favicon of the page in the selected tab.
gfx::Image GetCurrentPageIcon() const;
......
......@@ -28,8 +28,7 @@ void AddTabAt(Browser* browser,
// WebContents, but we want to include the time it takes to create the
// WebContents object too.
base::TimeTicks new_tab_start_time = base::TimeTicks::Now();
NavigateParams params(browser,
url.is_empty() ? GURL(chrome::kChromeUINewTabURL) : url,
NavigateParams params(browser, url.is_empty() ? browser->GetNewTabURL() : url,
ui::PAGE_TRANSITION_TYPED);
params.disposition = foreground ? WindowOpenDisposition::NEW_FOREGROUND_TAB
: WindowOpenDisposition::NEW_BACKGROUND_TAB;
......
......@@ -9,6 +9,7 @@
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/web_applications/system_web_app_ui_utils.h"
#include "chrome/browser/web_applications/components/externally_installed_web_app_prefs.h"
......@@ -18,6 +19,7 @@
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/web_application_info.h"
#include "chrome/common/webui_url_constants.h"
#include "extensions/browser/extension_registry.h"
namespace web_app {
......@@ -109,16 +111,28 @@ IN_PROC_BROWSER_TEST_F(AppBrowserControllerBrowserTest, SomeTest) {
// Check URL of tab1.
EXPECT_EQ(GetActiveTabURL(), GetAppURL());
// Create tab2, check URL, number of tabs.
chrome::NewTab(app_browser_);
// Create tab2 with specific URL, check URL, number of tabs.
chrome::AddTabAt(app_browser_, GURL(chrome::kChromeUINewTabURL), -1, true);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 2);
EXPECT_EQ(GetActiveTabURL(), GURL("chrome://newtab/"));
// Create tab3 with default URL, check URL, number of tabs.
chrome::NewTab(app_browser_);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 3);
EXPECT_EQ(GetActiveTabURL(), GetAppURL());
// Switch to tab1, check URL.
chrome::SelectNextTab(app_browser_);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 2);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 3);
EXPECT_EQ(GetActiveTabURL(), GetAppURL());
// Switch to tab2, check URL.
chrome::SelectNextTab(app_browser_);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 3);
EXPECT_EQ(GetActiveTabURL(), GURL("chrome://newtab/"));
// Switch to tab3, check URL.
chrome::SelectNextTab(app_browser_);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 3);
EXPECT_EQ(GetActiveTabURL(), GetAppURL());
// Close tab3, check number of tabs.
chrome::CloseTab(app_browser_);
EXPECT_EQ(app_browser_->tab_strip_model()->count(), 2);
EXPECT_EQ(GetActiveTabURL(), GURL("chrome://newtab/"));
// Close tab2, check number of tabs.
......
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