blob: 2122fb066f05db8dbf376a6567535583a1b13c9a [file] [log] [blame]
[email protected]411f8ae2014-05-22 11:12:231// 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 Elder66bf5122017-11-28 01:56:337#include "base/strings/string_util.h"
8#include "base/strings/utf_string_conversions.h"
[email protected]411f8ae2014-05-22 11:12:239#include "chrome/browser/profiles/profile.h"
10#include "chrome/common/extensions/extension_constants.h"
11#include "chrome/common/pref_names.h"
brettwb1fc1b82016-02-02 00:19:0812#include "components/prefs/pref_service.h"
Adrian Elder66bf5122017-11-28 01:56:3313#include "extensions/browser/extension_registry.h"
[email protected]411f8ae2014-05-22 11:12:2314#include "extensions/browser/extension_util.h"
hanxia3182da2014-09-02 22:51:1915#include "extensions/common/constants.h"
[email protected]411f8ae2014-05-22 11:12:2316#include "extensions/common/extension.h"
David Bertoni3cd201f72018-11-15 21:37:2317#include "extensions/common/image_util.h"
[email protected]411f8ae2014-05-22 11:12:2318
19namespace extensions {
20
21namespace {
22
23bool IsBlockedByPolicy(const Extension* app, content::BrowserContext* context) {
24 Profile* profile = Profile::FromBrowserContext(context);
25 DCHECK(profile);
26
Tim Judkinsb83106c2022-05-17 01:32:2527 return app->id() == extensions::kWebStoreAppId &&
28 profile->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon);
[email protected]411f8ae2014-05-22 11:12:2329}
30
31} // namespace
32
33namespace ui_util {
34
35bool ShouldDisplayInAppLauncher(const Extension* extension,
36 content::BrowserContext* context) {
benwells1dd4acd2015-12-09 02:20:2437 return CanDisplayInAppLauncher(extension, context);
[email protected]0e5c10fa2014-06-11 17:14:5738}
39
40bool CanDisplayInAppLauncher(const Extension* extension,
41 content::BrowserContext* context) {
[email protected]411f8ae2014-05-22 11:12:2342 return extension->ShouldDisplayInAppLauncher() &&
[email protected]0e5c10fa2014-06-11 17:14:5743 !IsBlockedByPolicy(extension, context);
[email protected]411f8ae2014-05-22 11:12:2344}
45
46bool ShouldDisplayInNewTabPage(const Extension* extension,
47 content::BrowserContext* context) {
48 return extension->ShouldDisplayInNewTabPage() &&
benwells1dd4acd2015-12-09 02:20:2449 !IsBlockedByPolicy(extension, context);
[email protected]411f8ae2014-05-22 11:12:2350}
51
Jan Wilken Dörrief27844b2021-03-11 23:18:4852std::u16string GetEnabledExtensionNameForUrl(const GURL& url,
Adrian Elder66bf5122017-11-28 01:56:3353 content::BrowserContext* context) {
54 if (!url.SchemeIs(extensions::kExtensionScheme))
Jan Wilken Dörrief27844b2021-03-11 23:18:4855 return std::u16string();
Adrian Elder66bf5122017-11-28 01:56:3356
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örrief27844b2021-03-11 23:18:4863 : std::u16string();
Adrian Elder66bf5122017-11-28 01:56:3364}
65
[email protected]411f8ae2014-05-22 11:12:2366} // namespace ui_util
67} // namespace extensions