OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/extension_ui_util.h" | 5 #include "chrome/browser/extensions/extension_ui_util.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/common/extensions/extension_constants.h" | 9 #include "chrome/common/extensions/extension_constants.h" |
10 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | |
11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
12 #include "content/public/browser/web_contents.h" | |
13 #include "extensions/browser/extension_util.h" | 11 #include "extensions/browser/extension_util.h" |
14 #include "extensions/common/constants.h" | 12 #include "extensions/common/constants.h" |
15 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
16 | 14 |
17 namespace extensions { | 15 namespace extensions { |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) { | 19 bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) { |
22 Profile* profile = Profile::FromBrowserContext(context); | 20 Profile* profile = Profile::FromBrowserContext(context); |
23 DCHECK(profile); | 21 DCHECK(profile); |
24 | 22 |
25 return (app->id() == extensions::kWebStoreAppId || | 23 return (app->id() == extensions::kWebStoreAppId || |
26 app->id() == extension_misc::kEnterpriseWebStoreAppId) && | 24 app->id() == extension_misc::kEnterpriseWebStoreAppId) && |
27 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); | 25 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); |
28 } | 26 } |
29 | 27 |
30 bool IsSameOriginOrMoreSecure(const GURL& app_url, const GURL& page_url) { | |
31 return (app_url.scheme() == page_url.scheme() || | |
32 page_url.scheme() == url::kHttpsScheme) && | |
33 app_url.host() == page_url.host() && | |
34 app_url.port() == page_url.port(); | |
35 } | |
36 | |
37 } // namespace | 28 } // namespace |
38 | 29 |
39 namespace ui_util { | 30 namespace ui_util { |
40 | 31 |
41 bool ShouldDisplayInAppLauncher(const Extension* extension, | 32 bool ShouldDisplayInAppLauncher(const Extension* extension, |
42 content::BrowserContext* context) { | 33 content::BrowserContext* context) { |
43 return CanDisplayInAppLauncher(extension, context) && | 34 return CanDisplayInAppLauncher(extension, context) && |
44 !util::IsEphemeralApp(extension->id(), context); | 35 !util::IsEphemeralApp(extension->id(), context); |
45 } | 36 } |
46 | 37 |
(...skipping 15 matching lines...) Expand all Loading... |
62 return extension->ShouldDisplayInExtensionSettings() && | 53 return extension->ShouldDisplayInExtensionSettings() && |
63 !util::IsEphemeralApp(extension->id(), context); | 54 !util::IsEphemeralApp(extension->id(), context); |
64 } | 55 } |
65 | 56 |
66 bool ShouldNotBeVisible(const Extension* extension, | 57 bool ShouldNotBeVisible(const Extension* extension, |
67 content::BrowserContext* context) { | 58 content::BrowserContext* context) { |
68 return extension->ShouldNotBeVisible() || | 59 return extension->ShouldNotBeVisible() || |
69 util::IsEphemeralApp(extension->id(), context); | 60 util::IsEphemeralApp(extension->id(), context); |
70 } | 61 } |
71 | 62 |
72 bool ShouldShowLocationBar(const Extension* extension, | |
73 const content::WebContents* web_contents) { | |
74 // Default to not showing the location bar if either |extension| or | |
75 // |web_contents| are null. |extension| is null for the dev tools. | |
76 if (!extension || !web_contents) | |
77 return false; | |
78 | |
79 if (!extension->from_bookmark()) | |
80 return false; | |
81 | |
82 // Don't show a location bar until a navigation has occurred. | |
83 if (web_contents->GetLastCommittedURL().is_empty()) | |
84 return false; | |
85 | |
86 GURL launch_url = AppLaunchInfo::GetLaunchWebURL(extension); | |
87 return !(IsSameOriginOrMoreSecure(launch_url, | |
88 web_contents->GetVisibleURL()) && | |
89 IsSameOriginOrMoreSecure(launch_url, | |
90 web_contents->GetLastCommittedURL())); | |
91 } | |
92 | |
93 } // namespace ui_util | 63 } // namespace ui_util |
94 } // namespace extensions | 64 } // namespace extensions |
OLD | NEW |