1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/extensions/bookmark_app_browser_controller.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ssl/connection_security_helper.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "chrome/browser/ui/location_bar/location_bar.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/web_applications/web_app.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
18 #include "content/public/browser/web_contents.h"
19 #include "extensions/browser/extension_registry.h"
20 #include "extensions/common/extension.h"
23 namespace extensions
{
27 bool IsSameOriginOrMoreSecure(const GURL
& app_url
, const GURL
& page_url
) {
28 return (app_url
.scheme() == page_url
.scheme() ||
29 page_url
.scheme() == url::kHttpsScheme
) &&
30 app_url
.host() == page_url
.host() &&
31 app_url
.port() == page_url
.port();
34 bool IsWebAppFrameEnabled() {
35 return base::CommandLine::ForCurrentProcess()->HasSwitch(
36 switches::kEnableWebAppFrame
);
42 bool BookmarkAppBrowserController::IsForBookmarkApp(Browser
* browser
) {
43 const std::string extension_id
=
44 web_app::GetExtensionIdFromApplicationName(browser
->app_name());
45 const Extension
* extension
=
46 ExtensionRegistry::Get(browser
->profile())->GetExtensionById(
47 extension_id
, ExtensionRegistry::EVERYTHING
);
48 return extension
&& extension
->from_bookmark();
51 BookmarkAppBrowserController::BookmarkAppBrowserController(Browser
* browser
)
54 web_app::GetExtensionIdFromApplicationName(browser
->app_name())),
55 should_use_web_app_frame_(browser
->host_desktop_type() ==
56 chrome::HOST_DESKTOP_TYPE_ASH
&&
57 IsWebAppFrameEnabled()) {
60 BookmarkAppBrowserController::~BookmarkAppBrowserController() {
63 bool BookmarkAppBrowserController::SupportsLocationBar() {
64 return !should_use_web_app_frame();
67 bool BookmarkAppBrowserController::ShouldShowLocationBar() {
68 const Extension
* extension
=
69 ExtensionRegistry::Get(browser_
->profile())->GetExtensionById(
70 extension_id_
, ExtensionRegistry::EVERYTHING
);
72 const content::WebContents
* web_contents
=
73 browser_
->tab_strip_model()->GetActiveWebContents();
75 // Default to not showing the location bar if either |extension| or
76 // |web_contents| are null. |extension| is null for the dev tools.
77 if (!extension
|| !web_contents
)
80 if (!extension
->from_bookmark())
83 // Don't show a location bar until a navigation has occurred.
84 if (web_contents
->GetLastCommittedURL().is_empty())
87 ConnectionSecurityHelper::SecurityLevel security_level
=
88 ConnectionSecurityHelper::GetSecurityLevelForWebContents(web_contents
);
89 if (security_level
== ConnectionSecurityHelper::SECURITY_ERROR
)
92 GURL launch_url
= AppLaunchInfo::GetLaunchWebURL(extension
);
93 return !(IsSameOriginOrMoreSecure(launch_url
,
94 web_contents
->GetVisibleURL()) &&
95 IsSameOriginOrMoreSecure(launch_url
,
96 web_contents
->GetLastCommittedURL()));
99 void BookmarkAppBrowserController::UpdateLocationBarVisibility(bool animate
) {
100 if (!SupportsLocationBar())
103 browser_
->window()->GetLocationBar()->UpdateLocationBarVisibility(
104 ShouldShowLocationBar(), animate
);
107 } // namespace extensions