diff options
-rw-r--r-- | chrome/browser/extensions/extension_ui_util.cc | 26 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_ui_util.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/browser.cc | 25 | ||||
-rw-r--r-- | chrome/browser/ui/browser_browsertest.cc | 123 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc | 15 | ||||
-rw-r--r-- | chrome/test/data/extensions/https_app/manifest.json | 13 |
6 files changed, 201 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_ui_util.cc b/chrome/browser/extensions/extension_ui_util.cc index 4cf4fa8..fe19155 100644 --- a/chrome/browser/extensions/extension_ui_util.cc +++ b/chrome/browser/extensions/extension_ui_util.cc @@ -7,7 +7,9 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/extension_constants.h" +#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/pref_names.h" +#include "content/public/browser/web_contents.h" #include "extensions/browser/extension_util.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" @@ -25,6 +27,13 @@ bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) { profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); } +bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { + return (app_url.scheme() == page_url.scheme() || + page_url.scheme() == url::kHttpsScheme) && + app_url.host() == page_url.host() && + app_url.port() == page_url.port(); +} + } // namespace namespace ui_util { @@ -60,5 +69,22 @@ bool ShouldNotBeVisible(const Extension* extension, util::IsEphemeralApp(extension->id(), context); } +bool ShouldShowLocationBar(const Extension* extension, + const content::WebContents* web_contents) { + // Default to not showing the location bar if either |extension| or + // |web_contents| are null. |extension| is null for the dev tools. + if (!extension || !web_contents) + return false; + + if (!extension->from_bookmark()) + return false; + + GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); + return !(IsSameOriginOrMoreSecure(launch_url, + web_contents->GetVisibleURL()) && + IsSameOriginOrMoreSecure(launch_url, + web_contents->GetLastCommittedURL())); +} + } // namespace ui_util } // namespace extensions diff --git a/chrome/browser/extensions/extension_ui_util.h b/chrome/browser/extensions/extension_ui_util.h index c49c2bc..92031ea 100644 --- a/chrome/browser/extensions/extension_ui_util.h +++ b/chrome/browser/extensions/extension_ui_util.h @@ -7,6 +7,7 @@ namespace content { class BrowserContext; +class WebContents; } namespace extensions { @@ -46,6 +47,11 @@ bool ShouldDisplayInExtensionSettings(const Extension* extension, bool ShouldNotBeVisible(const Extension* extension, content::BrowserContext* context); +// Returns true if the location bar should be shown for |web_contents| when +// viewed in the context of the app represented by |extension|. +bool ShouldShowLocationBar(const Extension* extension, + const content::WebContents* web_contents); + } // namespace ui_util } // namespace extensions diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 338eccf..21e292e 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -55,6 +55,7 @@ #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" #include "chrome/browser/extensions/browser_extension_window_controller.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_ui_util.h" #include "chrome/browser/extensions/extension_util.h" #include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/favicon/favicon_tab_helper.h" @@ -2413,19 +2414,33 @@ bool Browser::ShouldShowLocationBar() const { if (is_type_tabbed()) return true; - // Trusted app windows and system windows never show a location bar. - return !is_app() && !is_trusted_source(); + // Non-app windows that aren't tabbed or system windows should always show a + // location bar, unless they are from a trusted source. + if (!is_app()) + return !is_trusted_source(); + + if (ShouldUseWebAppFrame()) + return false; + + // Bookmark apps should show the location bar. + const std::string extension_id = + web_app::GetExtensionIdFromApplicationName(app_name()); + const extensions::Extension* extension = + extensions::ExtensionRegistry::Get(profile_)->GetExtensionById( + extension_id, extensions::ExtensionRegistry::EVERYTHING); + return extensions::ui_util::ShouldShowLocationBar( + extension, tab_strip_model_->GetActiveWebContents()); } bool Browser::ShouldUseWebAppFrame() const { - // Only use the web app frame for apps in ash, and only if bookmark apps are - // enabled. + // Only use the web app frame for apps in ash, and only if the web app frame + // is enabled. if (!is_app() || host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH || !IsWebAppFrameEnabled()) { return false; } - // Use the web app frame for hosted apps (which include bookmark apps). + // Use the web app frame for hosted apps. const std::string extension_id = web_app::GetExtensionIdFromApplicationName(app_name()); const extensions::Extension* extension = diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 94fad2d..c878620 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -49,6 +49,7 @@ #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" #include "chrome/browser/ui/tabs/pinned_tab_codec.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/pref_names.h" @@ -1386,6 +1387,128 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, ShouldShowLocationBar) { DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); } + +// Check that the location bar is shown correctly for bookmark apps. +IN_PROC_BROWSER_TEST_F(BrowserTest, ShouldShowLocationBarForBookmarkApp) { + base::CommandLine::ForCurrentProcess()->AppendSwitch( + switches::kEnableNewBookmarkApps); + ASSERT_TRUE(test_server()->Start()); + + // Setup the test server. + host_resolver()->AddRule("www.foo.com", "127.0.0.1"); + host_resolver()->AddRule("www.example.com", "127.0.0.1"); + + // Load a http bookmark app. + const Extension* http_bookmark_app = InstallExtensionWithSourceAndFlags( + test_data_dir_.AppendASCII("app/"), + 1, + extensions::Manifest::INTERNAL, + extensions::Extension::FROM_BOOKMARK); + ASSERT_TRUE(http_bookmark_app); + + // Load a https bookmark app. + const Extension* https_bookmark_app = InstallExtensionWithSourceAndFlags( + test_data_dir_.AppendASCII("https_app/"), + 1, + extensions::Manifest::INTERNAL, + extensions::Extension::FROM_BOOKMARK); + ASSERT_TRUE(https_bookmark_app); + + // Load a https bookmark app. + + // Launch them in window. + WebContents* app_window = OpenApplication(AppLaunchParams( + browser()->profile(), http_bookmark_app, + extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, + extensions::SOURCE_TEST)); + ASSERT_TRUE(app_window); + app_window = OpenApplication(AppLaunchParams( + browser()->profile(), https_bookmark_app, + extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW, + extensions::SOURCE_TEST)); + ASSERT_TRUE(app_window); + + // Find the new browsers. + Browser* http_app_browser = NULL; + Browser* https_app_browser = NULL; + for (chrome::BrowserIterator it; !it.done(); it.Next()) { + std::string app_id = + web_app::GetExtensionIdFromApplicationName((*it)->app_name()); + if (*it == browser()) { + continue; + } else if (app_id == http_bookmark_app->id()) { + http_app_browser = *it; + } else if (app_id == https_bookmark_app->id()) { + https_app_browser = *it; + } + } + ASSERT_TRUE(http_app_browser); + ASSERT_TRUE(https_app_browser); + ASSERT_TRUE(http_app_browser != browser()); + ASSERT_TRUE(https_app_browser != browser()); + ASSERT_TRUE(http_app_browser != https_app_browser); + + // Navigate to the app's launch page; the location bar should be hidden. + GURL url("http://www.example.com/empty.html"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_FALSE( + http_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + url = GURL("https://www.example.com/empty.html"); + ui_test_utils::NavigateToURL(https_app_browser, url); + EXPECT_FALSE( + https_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + + // Navigate to another page on the same origin; the location bar should still + // hidden. + url = GURL("http://www.example.com/blah"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_FALSE( + http_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + url = GURL("https://www.example.com/blah"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_FALSE( + https_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + + // Navigate to the https version of the site; the location bar should + // be hidden for both browsers. + url = GURL("https://www.example.com/blah"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_FALSE( + http_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + ui_test_utils::NavigateToURL(https_app_browser, url); + EXPECT_FALSE( + https_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + + // Navigate to the http version of the site; the location bar should + // be visible for the https version as it is now on a less secure version + // of its host. + url = GURL("http://www.example.com/blah"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_FALSE( + http_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + ui_test_utils::NavigateToURL(https_app_browser, url); + EXPECT_TRUE( + https_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + + // Navigate to different origin; the location bar should now be visible. + url = GURL("http://www.foo.com/blah"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_TRUE( + http_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + ui_test_utils::NavigateToURL(https_app_browser, url); + EXPECT_TRUE( + https_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + + // Navigate back to the app's origin; the location bar should now be hidden. + url = GURL("http://www.example.com/blah"); + ui_test_utils::NavigateToURL(http_app_browser, url); + EXPECT_FALSE( + http_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); + url = GURL("https://www.example.com/blah"); + ui_test_utils::NavigateToURL(https_app_browser, url); + EXPECT_FALSE( + https_app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); +} #endif // Open a normal browser window, a hosted app window, a legacy packaged app diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc index cdb00ce..32683c1 100644 --- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc +++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc @@ -26,8 +26,10 @@ #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" #include "chrome/browser/ui/views/tab_icon_view.h" #include "chrome/browser/ui/views/tabs/tab_strip.h" +#include "chrome/browser/web_applications/web_app.h" #include "components/signin/core/common/profile_management_switches.h" #include "content/public/browser/web_contents.h" +#include "extensions/browser/extension_registry.h" #include "grit/theme_resources.h" #include "ui/accessibility/ax_view_state.h" #include "ui/aura/client/aura_constants.h" @@ -523,8 +525,17 @@ bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { bool BrowserNonClientFrameViewAsh::UsePackagedAppHeaderStyle() const { // Use the packaged app style for apps that aren't using the newer WebApp - // style. - return browser_view()->browser()->is_app() && !UseWebAppHeaderStyle(); + // style, and that aren't bookmark apps. + if (!browser_view()->browser()->is_app() || UseWebAppHeaderStyle()) + return false; + + const std::string extension_id = web_app::GetExtensionIdFromApplicationName( + browser_view()->browser()->app_name()); + const extensions::Extension* extension = + extensions::ExtensionRegistry::Get(browser_view()->browser()->profile()) + ->GetExtensionById(extension_id, + extensions::ExtensionRegistry::EVERYTHING); + return !extension || !extension->from_bookmark(); } bool BrowserNonClientFrameViewAsh::UseWebAppHeaderStyle() const { diff --git a/chrome/test/data/extensions/https_app/manifest.json b/chrome/test/data/extensions/https_app/manifest.json new file mode 100644 index 0000000..59ec30b --- /dev/null +++ b/chrome/test/data/extensions/https_app/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "App Test", + "version": "1", + "manifest_version": 2, + "permissions": [ + "notifications" + ], + "app": { + "launch": { + "web_url": "https://www.example.com/empty.html" + } + } +} |