[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "chrome/browser/extensions/extension_ui_util.h" | ||||
6 | |||||
Adrian Elder | 66bf512 | 2017-11-28 01:56:33 | [diff] [blame] | 7 | #include "base/strings/string_util.h" |
8 | #include "base/strings/utf_string_conversions.h" | ||||
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile.h" |
10 | #include "chrome/common/extensions/extension_constants.h" | ||||
11 | #include "chrome/common/pref_names.h" | ||||
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 12 | #include "components/prefs/pref_service.h" |
Adrian Elder | 66bf512 | 2017-11-28 01:56:33 | [diff] [blame] | 13 | #include "extensions/browser/extension_registry.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 14 | #include "extensions/browser/extension_util.h" |
hanxi | a3182da | 2014-09-02 22:51:19 | [diff] [blame] | 15 | #include "extensions/common/constants.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 16 | #include "extensions/common/extension.h" |
David Bertoni | 3cd201f7 | 2018-11-15 21:37:23 | [diff] [blame] | 17 | #include "extensions/common/image_util.h" |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 18 | |
19 | namespace extensions { | ||||
20 | |||||
21 | namespace { | ||||
22 | |||||
23 | bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) { | ||||
24 | Profile* profile = Profile::FromBrowserContext(context); | ||||
25 | DCHECK(profile); | ||||
26 | |||||
Tim Judkins | b83106c | 2022-05-17 01:32:25 | [diff] [blame] | 27 | return app->id() == extensions::kWebStoreAppId && |
28 | profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon); | ||||
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 29 | } |
30 | |||||
31 | } // namespace | ||||
32 | |||||
33 | namespace ui_util { | ||||
34 | |||||
35 | bool ShouldDisplayInAppLauncher(const Extension* extension, | ||||
36 | content::BrowserContext* context) { | ||||
benwells | 1dd4acd | 2015-12-09 02:20:24 | [diff] [blame] | 37 | return CanDisplayInAppLauncher(extension, context); |
[email protected] | 0e5c10fa | 2014-06-11 17:14:57 | [diff] [blame] | 38 | } |
39 | |||||
40 | bool CanDisplayInAppLauncher(const Extension* extension, | ||||
41 | content::BrowserContext* context) { | ||||
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 42 | return extension->ShouldDisplayInAppLauncher() && |
[email protected] | 0e5c10fa | 2014-06-11 17:14:57 | [diff] [blame] | 43 | !IsBlockedByPolicy(extension, context); |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 44 | } |
45 | |||||
46 | bool ShouldDisplayInNewTabPage(const Extension* extension, | ||||
47 | content::BrowserContext* context) { | ||||
48 | return extension->ShouldDisplayInNewTabPage() && | ||||
benwells | 1dd4acd | 2015-12-09 02:20:24 | [diff] [blame] | 49 | !IsBlockedByPolicy(extension, context); |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 50 | } |
51 | |||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 52 | std::u16string GetEnabledExtensionNameForUrl(const GURL& url, |
Adrian Elder | 66bf512 | 2017-11-28 01:56:33 | [diff] [blame] | 53 | content::BrowserContext* context) { |
54 | if (!url.SchemeIs(extensions::kExtensionScheme)) | ||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 55 | return std::u16string(); |
Adrian Elder | 66bf512 | 2017-11-28 01:56:33 | [diff] [blame] | 56 | |
57 | extensions::ExtensionRegistry* extension_registry = | ||||
58 | extensions::ExtensionRegistry::Get(context); | ||||
59 | const extensions::Extension* extension = | ||||
60 | extension_registry->enabled_extensions().GetByID(url.host()); | ||||
61 | return extension ? base::CollapseWhitespace( | ||||
62 | base::UTF8ToUTF16(extension->name()), false) | ||||
Jan Wilken Dörrie | f27844b | 2021-03-11 23:18:48 | [diff] [blame] | 63 | : std::u16string(); |
Adrian Elder | 66bf512 | 2017-11-28 01:56:33 | [diff] [blame] | 64 | } |
65 | |||||
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 66 | } // namespace ui_util |
67 | } // namespace extensions |