OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" | 5 #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ssl/security_state_tab_helper.h" | 9 #include "chrome/browser/ssl/security_state_tab_helper.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/browser/ui/location_bar/location_bar.h" | 12 #include "chrome/browser/ui/location_bar/location_bar.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/browser/web_applications/web_app.h" | 14 #include "chrome/browser/web_applications/web_app.h" |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 15 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
17 #include "components/security_state/core/security_state.h" | 16 #include "components/security_state/core/security_state.h" |
18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
19 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
21 #include "url/gurl.h" | 20 #include "url/gurl.h" |
22 | 21 |
23 namespace extensions { | 22 namespace extensions { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { | 26 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { |
28 const std::string www("www."); | 27 const std::string www("www."); |
29 return (app_url.scheme_piece() == page_url.scheme_piece() || | 28 return (app_url.scheme_piece() == page_url.scheme_piece() || |
30 page_url.scheme_piece() == url::kHttpsScheme) && | 29 page_url.scheme_piece() == url::kHttpsScheme) && |
31 (app_url.host_piece() == page_url.host_piece() || | 30 (app_url.host_piece() == page_url.host_piece() || |
32 www + app_url.host() == page_url.host_piece()) && | 31 www + app_url.host() == page_url.host_piece()) && |
33 app_url.port() == page_url.port(); | 32 app_url.port() == page_url.port(); |
34 } | 33 } |
35 | |
36 #if defined(USE_ASH) | |
37 bool IsWebAppFrameEnabled() { | |
38 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
39 switches::kEnableWebAppFrame); | |
40 } | |
41 #endif // USE_ASH | |
42 | |
43 } // namespace | 34 } // namespace |
44 | 35 |
45 // static | 36 // static |
46 bool HostedAppBrowserController::IsForHostedApp(Browser* browser) { | 37 bool HostedAppBrowserController::IsForHostedApp(Browser* browser) { |
47 const std::string extension_id = | 38 const std::string extension_id = |
48 web_app::GetExtensionIdFromApplicationName(browser->app_name()); | 39 web_app::GetExtensionIdFromApplicationName(browser->app_name()); |
49 const Extension* extension = | 40 const Extension* extension = |
50 ExtensionRegistry::Get(browser->profile())->GetExtensionById( | 41 ExtensionRegistry::Get(browser->profile())->GetExtensionById( |
51 extension_id, ExtensionRegistry::EVERYTHING); | 42 extension_id, ExtensionRegistry::EVERYTHING); |
52 return extension && extension->is_hosted_app(); | 43 return extension && extension->is_hosted_app(); |
53 } | 44 } |
54 | 45 |
55 HostedAppBrowserController::HostedAppBrowserController(Browser* browser) | 46 HostedAppBrowserController::HostedAppBrowserController(Browser* browser) |
56 : browser_(browser), | 47 : browser_(browser), |
57 extension_id_( | 48 extension_id_( |
58 web_app::GetExtensionIdFromApplicationName(browser->app_name())) { | 49 web_app::GetExtensionIdFromApplicationName(browser->app_name())) { |
59 const Extension* extension = | 50 const Extension* extension = |
60 ExtensionRegistry::Get(browser->profile())->GetExtensionById( | 51 ExtensionRegistry::Get(browser->profile())->GetExtensionById( |
61 extension_id_, ExtensionRegistry::EVERYTHING); | 52 extension_id_, ExtensionRegistry::EVERYTHING); |
62 DCHECK(extension); | 53 DCHECK(extension); |
63 #if defined(USE_ASH) | |
64 should_use_web_app_frame_ = | |
65 extension->from_bookmark() && IsWebAppFrameEnabled(); | |
66 #else | |
67 should_use_web_app_frame_ = false; | |
68 #endif | |
69 } | 54 } |
70 | 55 |
71 HostedAppBrowserController::~HostedAppBrowserController() { | 56 HostedAppBrowserController::~HostedAppBrowserController() { |
72 } | 57 } |
73 | 58 |
74 bool HostedAppBrowserController::SupportsLocationBar() const { | |
75 return !should_use_web_app_frame(); | |
76 } | |
77 | |
78 bool HostedAppBrowserController::ShouldShowLocationBar() const { | 59 bool HostedAppBrowserController::ShouldShowLocationBar() const { |
79 const Extension* extension = | 60 const Extension* extension = |
80 ExtensionRegistry::Get(browser_->profile())->GetExtensionById( | 61 ExtensionRegistry::Get(browser_->profile())->GetExtensionById( |
81 extension_id_, ExtensionRegistry::EVERYTHING); | 62 extension_id_, ExtensionRegistry::EVERYTHING); |
82 | 63 |
83 const content::WebContents* web_contents = | 64 const content::WebContents* web_contents = |
84 browser_->tab_strip_model()->GetActiveWebContents(); | 65 browser_->tab_strip_model()->GetActiveWebContents(); |
85 | 66 |
86 // Default to not showing the location bar if either |extension| or | 67 // Default to not showing the location bar if either |extension| or |
87 // |web_contents| are null. |extension| is null for the dev tools. | 68 // |web_contents| are null. |extension| is null for the dev tools. |
(...skipping 18 matching lines...) Expand all Loading... |
106 | 87 |
107 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); | 88 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); |
108 return !(IsSameOriginOrMoreSecure(launch_url, | 89 return !(IsSameOriginOrMoreSecure(launch_url, |
109 web_contents->GetVisibleURL()) && | 90 web_contents->GetVisibleURL()) && |
110 IsSameOriginOrMoreSecure(launch_url, | 91 IsSameOriginOrMoreSecure(launch_url, |
111 web_contents->GetLastCommittedURL())); | 92 web_contents->GetLastCommittedURL())); |
112 } | 93 } |
113 | 94 |
114 void HostedAppBrowserController::UpdateLocationBarVisibility( | 95 void HostedAppBrowserController::UpdateLocationBarVisibility( |
115 bool animate) const { | 96 bool animate) const { |
116 if (!SupportsLocationBar()) | |
117 return; | |
118 | |
119 browser_->window()->GetLocationBar()->UpdateLocationBarVisibility( | 97 browser_->window()->GetLocationBar()->UpdateLocationBarVisibility( |
120 ShouldShowLocationBar(), animate); | 98 ShouldShowLocationBar(), animate); |
121 } | 99 } |
122 | 100 |
123 } // namespace extensions | 101 } // namespace extensions |
OLD | NEW |