[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 1 | // Copyright 2013 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_util.h" |
| 6 | |
tbarzic | 858a848 | 2016-12-07 01:04:50 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 9 | #include "base/command_line.h" |
tapted | 70cdc81 | 2017-03-23 20:48:19 | [diff] [blame] | 10 | #include "base/feature_list.h" |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 11 | #include "base/logging.h" |
treib | 3202d59 | 2015-07-31 08:33:16 | [diff] [blame] | 12 | #include "base/metrics/field_trial.h" |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 13 | #include "base/values.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 14 | #include "build/build_config.h" |
Matt Giuca | d487043 | 2017-11-24 01:04:38 | [diff] [blame] | 15 | #include "chrome/browser/banners/app_banner_manager.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 18 | #include "chrome/browser/extensions/permissions_updater.h" |
rdevlin.cronin | cb9f86e | 2015-10-15 15:13:42 | [diff] [blame] | 19 | #include "chrome/browser/extensions/scripting_permissions_modifier.h" |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 20 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 22 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
tapted | 70cdc81 | 2017-03-23 20:48:19 | [diff] [blame] | 23 | #include "chrome/common/chrome_features.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 24 | #include "chrome/common/chrome_switches.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 25 | #include "chrome/common/extensions/sync_helper.h" |
treib | b6af28cd | 2015-12-01 11:19:46 | [diff] [blame] | 26 | #include "components/variations/variations_associated_data.h" |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 27 | #include "content/public/browser/site_instance.h" |
Devlin Cronin | bffe949eb | 2018-01-12 03:03:40 | [diff] [blame^] | 28 | #include "extensions/browser/disable_reason.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 29 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 30 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 31 | #include "extensions/browser/extension_system.h" |
[email protected] | 30e190f8 | 2014-05-26 16:44:39 | [diff] [blame] | 32 | #include "extensions/browser/extension_util.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 33 | #include "extensions/common/extension.h" |
[email protected] | 4b790884 | 2014-04-07 23:50:22 | [diff] [blame] | 34 | #include "extensions/common/extension_icon_set.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 35 | #include "extensions/common/manifest.h" |
tfarina | 0bcdf36 | 2015-06-29 22:19:26 | [diff] [blame] | 36 | #include "extensions/common/manifest_handlers/app_isolation_info.h" |
[email protected] | 1f7de25 | 2013-11-06 22:02:00 | [diff] [blame] | 37 | #include "extensions/common/manifest_handlers/incognito_info.h" |
[email protected] | 4d67e9d | 2014-08-18 22:03:54 | [diff] [blame] | 38 | #include "extensions/common/permissions/permissions_data.h" |
mukai | 4245dfe8 | 2014-09-05 17:40:51 | [diff] [blame] | 39 | #include "extensions/grit/extensions_browser_resources.h" |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 40 | #include "ui/base/resource/resource_bundle.h" |
Michael Giuffrida | 7efeed14 | 2017-06-07 06:29:21 | [diff] [blame] | 41 | #include "url/gurl.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 42 | |
treib | 1325119 | 2016-06-29 07:13:15 | [diff] [blame] | 43 | #if defined(OS_CHROMEOS) |
| 44 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 45 | #endif |
| 46 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 47 | namespace extensions { |
| 48 | namespace util { |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 49 | |
[email protected] | b33c8c2 | 2014-05-29 19:51:08 | [diff] [blame] | 50 | namespace { |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 51 | // The entry into the prefs used to flag an extension as installed by custodian. |
| 52 | // It is relevant only for supervised users. |
| 53 | const char kWasInstalledByCustodianPrefName[] = "was_installed_by_custodian"; |
| 54 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 55 | // Returns |extension_id|. See note below. |
| 56 | std::string ReloadExtensionIfEnabled(const std::string& extension_id, |
| 57 | content::BrowserContext* context) { |
| 58 | ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 59 | bool extension_is_enabled = |
| 60 | registry->enabled_extensions().Contains(extension_id); |
| 61 | |
| 62 | if (!extension_is_enabled) |
| 63 | return extension_id; |
| 64 | |
| 65 | // When we reload the extension the ID may be invalidated if we've passed it |
| 66 | // by const ref everywhere. Make a copy to be safe. http://crbug.com/103762 |
| 67 | std::string id = extension_id; |
| 68 | ExtensionService* service = |
| 69 | ExtensionSystem::Get(context)->extension_service(); |
| 70 | CHECK(service); |
| 71 | service->ReloadExtension(id); |
| 72 | return id; |
| 73 | } |
| 74 | |
[email protected] | 277c414 | 2014-06-19 20:08:54 | [diff] [blame] | 75 | } // namespace |
[email protected] | b33c8c2 | 2014-05-29 19:51:08 | [diff] [blame] | 76 | |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 77 | void SetIsIncognitoEnabled(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 78 | content::BrowserContext* context, |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 79 | bool enabled) { |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 80 | ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 81 | const Extension* extension = |
| 82 | registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 83 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 84 | if (extension) { |
kundaji | e548e744 | 2015-09-18 23:19:09 | [diff] [blame] | 85 | if (!util::CanBeIncognitoEnabled(extension)) |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 86 | return; |
| 87 | |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 88 | // TODO(treib,kalman): Should this be Manifest::IsComponentLocation(..)? |
| 89 | // (which also checks for EXTERNAL_COMPONENT). |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 90 | if (extension->location() == Manifest::COMPONENT) { |
| 91 | // This shouldn't be called for component extensions unless it is called |
| 92 | // by sync, for syncable component extensions. |
| 93 | // See http://crbug.com/112290 and associated CLs for the sordid history. |
treib | 1325119 | 2016-06-29 07:13:15 | [diff] [blame] | 94 | bool syncable = sync_helper::IsSyncableComponentExtension(extension); |
| 95 | #if defined(OS_CHROMEOS) |
| 96 | // For some users, the file manager app somehow ended up being synced even |
| 97 | // though it's supposed to be unsyncable; see crbug.com/576964. If the bad |
| 98 | // data ever gets cleaned up, this hack should be removed. |
| 99 | syncable = syncable || extension->id() == file_manager::kFileManagerAppId; |
| 100 | #endif |
| 101 | DCHECK(syncable); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 102 | |
| 103 | // If we are here, make sure the we aren't trying to change the value. |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 104 | DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id, context)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 105 | return; |
| 106 | } |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 107 | } |
| 108 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 109 | ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 110 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 111 | // if the value changed and the extension is actually enabled, since there is |
| 112 | // no UI otherwise. |
| 113 | bool old_enabled = extension_prefs->IsIncognitoEnabled(extension_id); |
| 114 | if (enabled == old_enabled) |
| 115 | return; |
| 116 | |
| 117 | extension_prefs->SetIsIncognitoEnabled(extension_id, enabled); |
| 118 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 119 | std::string id = ReloadExtensionIfEnabled(extension_id, context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 120 | |
| 121 | // Reloading the extension invalidates the |extension| pointer. |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 122 | extension = registry->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 123 | if (extension) { |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 124 | Profile* profile = Profile::FromBrowserContext(context); |
| 125 | ExtensionSyncService::Get(profile)->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 126 | } |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | bool CanCrossIncognito(const Extension* extension, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 130 | content::BrowserContext* context) { |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 131 | // We allow the extension to see events and data from another profile iff it |
| 132 | // uses "spanning" behavior and it has incognito access. "split" mode |
| 133 | // extensions only see events for a matching profile. |
| 134 | CHECK(extension); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 135 | return IsIncognitoEnabled(extension->id(), context) && |
| 136 | !IncognitoInfo::IsSplitMode(extension); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | bool CanLoadInIncognito(const Extension* extension, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 140 | content::BrowserContext* context) { |
| 141 | CHECK(extension); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 142 | if (extension->is_hosted_app()) |
| 143 | return true; |
| 144 | // Packaged apps and regular extensions need to be enabled specifically for |
| 145 | // incognito (and split mode should be set). |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 146 | return IncognitoInfo::IsSplitMode(extension) && |
| 147 | IsIncognitoEnabled(extension->id(), context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 150 | bool AllowFileAccess(const std::string& extension_id, |
| 151 | content::BrowserContext* context) { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 152 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 153 | switches::kDisableExtensionsFileAccessCheck) || |
| 154 | ExtensionPrefs::Get(context)->AllowFileAccess(extension_id); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 155 | } |
| 156 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 157 | void SetAllowFileAccess(const std::string& extension_id, |
| 158 | content::BrowserContext* context, |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 159 | bool allow) { |
| 160 | // Reload to update browser state. Only bother if the value changed and the |
| 161 | // extension is actually enabled, since there is no UI otherwise. |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 162 | if (allow == AllowFileAccess(extension_id, context)) |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 163 | return; |
| 164 | |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 165 | ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 166 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 167 | ReloadExtensionIfEnabled(extension_id, context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 168 | } |
| 169 | |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 170 | void SetWasInstalledByCustodian(const std::string& extension_id, |
| 171 | content::BrowserContext* context, |
| 172 | bool installed_by_custodian) { |
| 173 | if (installed_by_custodian == WasInstalledByCustodian(extension_id, context)) |
| 174 | return; |
| 175 | |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 176 | ExtensionPrefs* prefs = ExtensionPrefs::Get(context); |
| 177 | |
| 178 | prefs->UpdateExtensionPref( |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 179 | extension_id, kWasInstalledByCustodianPrefName, |
vabr | fb687dc | 2017-03-22 11:40:57 | [diff] [blame] | 180 | installed_by_custodian ? base::MakeUnique<base::Value>(true) : nullptr); |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 181 | ExtensionService* service = |
| 182 | ExtensionSystem::Get(context)->extension_service(); |
| 183 | |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 184 | if (!installed_by_custodian) { |
| 185 | // If installed_by_custodian changes to false, the extension may need to |
| 186 | // be unloaded now. |
| 187 | service->ReloadExtension(extension_id); |
| 188 | return; |
| 189 | } |
| 190 | |
mamir | e960964 | 2016-06-28 22:17:54 | [diff] [blame] | 191 | ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 192 | // If it is already enabled, do nothing. |
| 193 | if (registry->enabled_extensions().Contains(extension_id)) |
| 194 | return; |
| 195 | |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 196 | // If the extension was disabled due to management policy, try to re-enable |
| 197 | // it. Example is a pre-installed extension that was disabled when a |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 198 | // supervised user flag has been received. |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 199 | // Note: EnableExtension will fail if the extension still needs to be disabled |
| 200 | // due to manangement policy. |
| 201 | if (registry->disabled_extensions().Contains(extension_id) && |
| 202 | prefs->GetDisableReasons(extension_id) == |
| 203 | disable_reason::DISABLE_BLOCKED_BY_POLICY) { |
| 204 | service->EnableExtension(extension_id); |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
| 208 | bool WasInstalledByCustodian(const std::string& extension_id, |
| 209 | content::BrowserContext* context) { |
| 210 | bool installed_by_custodian = false; |
| 211 | ExtensionPrefs* prefs = ExtensionPrefs::Get(context); |
| 212 | prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName, |
| 213 | &installed_by_custodian); |
| 214 | return installed_by_custodian; |
| 215 | } |
| 216 | |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 217 | bool IsAppLaunchable(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 218 | content::BrowserContext* context) { |
[email protected] | 47e1940 | 2014-06-27 09:01:14 | [diff] [blame] | 219 | int reason = ExtensionPrefs::Get(context)->GetDisableReasons(extension_id); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 220 | return !((reason & disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT) || |
| 221 | (reason & disable_reason::DISABLE_CORRUPTED)); |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 225 | content::BrowserContext* context) { |
| 226 | return ExtensionRegistry::Get(context)->GetExtensionById( |
| 227 | extension_id, ExtensionRegistry::ENABLED) != NULL; |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 228 | } |
| 229 | |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 230 | bool ShouldSync(const Extension* extension, |
| 231 | content::BrowserContext* context) { |
| 232 | return sync_helper::IsSyncable(extension) && |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 233 | !ExtensionPrefs::Get(context)->DoNotSync(extension->id()); |
| 234 | } |
| 235 | |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 236 | bool IsExtensionIdle(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 237 | content::BrowserContext* context) { |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 238 | std::vector<std::string> ids_to_check; |
| 239 | ids_to_check.push_back(extension_id); |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 240 | |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 241 | const Extension* extension = |
| 242 | ExtensionRegistry::Get(context) |
| 243 | ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 244 | if (extension && extension->is_shared_module()) { |
| 245 | // We have to check all the extensions that use this shared module for idle |
| 246 | // to tell whether it is really 'idle'. |
| 247 | SharedModuleService* service = ExtensionSystem::Get(context) |
| 248 | ->extension_service() |
| 249 | ->shared_module_service(); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 250 | std::unique_ptr<ExtensionSet> dependents = |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 251 | service->GetDependentExtensions(extension); |
| 252 | for (ExtensionSet::const_iterator i = dependents->begin(); |
| 253 | i != dependents->end(); |
| 254 | i++) { |
| 255 | ids_to_check.push_back((*i)->id()); |
| 256 | } |
| 257 | } |
| 258 | |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 259 | ProcessManager* process_manager = ProcessManager::Get(context); |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 260 | for (std::vector<std::string>::const_iterator i = ids_to_check.begin(); |
| 261 | i != ids_to_check.end(); |
| 262 | i++) { |
| 263 | const std::string id = (*i); |
| 264 | ExtensionHost* host = process_manager->GetBackgroundHostForExtension(id); |
| 265 | if (host) |
| 266 | return false; |
| 267 | |
rdevlin.cronin | 3d426152 | 2015-02-10 00:48:15 | [diff] [blame] | 268 | scoped_refptr<content::SiteInstance> site_instance = |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 269 | process_manager->GetSiteInstanceForURL( |
| 270 | Extension::GetBaseURLFromExtensionId(id)); |
| 271 | if (site_instance && site_instance->HasProcess()) |
| 272 | return false; |
| 273 | |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 274 | if (!process_manager->GetRenderFrameHostsForExtension(id).empty()) |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 275 | return false; |
| 276 | } |
| 277 | return true; |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 278 | } |
| 279 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 280 | std::unique_ptr<base::DictionaryValue> GetExtensionInfo( |
| 281 | const Extension* extension) { |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 282 | DCHECK(extension); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 283 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 284 | |
| 285 | dict->SetString("id", extension->id()); |
| 286 | dict->SetString("name", extension->name()); |
| 287 | |
| 288 | GURL icon = extensions::ExtensionIconSource::GetIconURL( |
estade | 32426e0 | 2016-12-18 01:26:17 | [diff] [blame] | 289 | extension, extension_misc::EXTENSION_ICON_SMALLISH, |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 290 | ExtensionIconSet::MATCH_BIGGER, |
estade | 32426e0 | 2016-12-18 01:26:17 | [diff] [blame] | 291 | false); // Not grayscale. |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 292 | dict->SetString("icon", icon.spec()); |
| 293 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 294 | return dict; |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 297 | const gfx::ImageSkia& GetDefaultAppIcon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 298 | return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 299 | IDR_APP_DEFAULT_ICON); |
| 300 | } |
| 301 | |
| 302 | const gfx::ImageSkia& GetDefaultExtensionIcon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 303 | return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 304 | IDR_EXTENSION_DEFAULT_ICON); |
| 305 | } |
| 306 | |
benwells | c431c0ae | 2015-01-27 22:04:06 | [diff] [blame] | 307 | bool IsNewBookmarkAppsEnabled() { |
dominickn | fa0e3df | 2016-01-14 05:38:32 | [diff] [blame] | 308 | #if defined(OS_MACOSX) |
benwells | c421ccdb | 2017-06-28 05:10:32 | [diff] [blame] | 309 | return base::FeatureList::IsEnabled(features::kBookmarkApps) || |
benwells | 0eee229 | 2017-06-28 08:41:22 | [diff] [blame] | 310 | base::FeatureList::IsEnabled(features::kAppBanners) || |
Matt Giuca | d487043 | 2017-11-24 01:04:38 | [diff] [blame] | 311 | banners::AppBannerManager::IsExperimentalAppBannersEnabled(); |
dominickn | fa0e3df | 2016-01-14 05:38:32 | [diff] [blame] | 312 | #else |
tapted | 70cdc81 | 2017-03-23 20:48:19 | [diff] [blame] | 313 | return true; |
dominickn | fa0e3df | 2016-01-14 05:38:32 | [diff] [blame] | 314 | #endif |
benwells | 39f23ae | 2014-08-27 08:01:52 | [diff] [blame] | 315 | } |
| 316 | |
dominickn | 2b10cbd | 2015-08-20 02:09:18 | [diff] [blame] | 317 | bool CanHostedAppsOpenInWindows() { |
| 318 | #if defined(OS_MACOSX) |
| 319 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
Giovanni Ortuño Urquidi | 45020e23 | 2017-07-12 06:10:17 | [diff] [blame] | 320 | switches::kEnableHostedAppsInWindows) || |
| 321 | base::FeatureList::IsEnabled(features::kDesktopPWAWindowing); |
dominickn | 2b10cbd | 2015-08-20 02:09:18 | [diff] [blame] | 322 | #else |
| 323 | return true; |
| 324 | #endif |
| 325 | } |
| 326 | |
mamir | 192d788 | 2016-06-22 17:10:16 | [diff] [blame] | 327 | bool IsExtensionSupervised(const Extension* extension, Profile* profile) { |
| 328 | return WasInstalledByCustodian(extension->id(), profile) && |
| 329 | profile->IsSupervised(); |
treib | bb9a196 | 2015-02-25 13:40:59 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 332 | } // namespace util |
| 333 | } // namespace extensions |