[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 | |
Hans Wennborg | 1790e6b | 2020-04-24 19:10:33 | [diff] [blame] | 9 | #include "base/check_op.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 10 | #include "base/command_line.h" |
tapted | 70cdc81 | 2017-03-23 20:48:19 | [diff] [blame] | 11 | #include "base/feature_list.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" |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 15 | #include "build/chromeos_buildflags.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" |
Alan Cutter | 70927ec9 | 2018-03-22 00:58:49 | [diff] [blame] | 18 | #include "chrome/browser/extensions/launch_util.h" |
[email protected] | 23a8536 | 2014-07-07 23:26:19 | [diff] [blame] | 19 | #include "chrome/browser/extensions/permissions_updater.h" |
rdevlin.cronin | cb9f86e | 2015-10-15 15:13:42 | [diff] [blame] | 20 | #include "chrome/browser/extensions/scripting_permissions_modifier.h" |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 21 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 22 | #include "chrome/browser/profiles/profile.h" |
Alan Cutter | 0996580 | 2018-03-27 07:25:29 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser.h" |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 24 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
Ben Wells | e13d3169 | 2018-08-31 00:22:33 | [diff] [blame] | 25 | #include "chrome/browser/web_applications/extensions/bookmark_app_util.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 26 | #include "chrome/common/chrome_switches.h" |
Alan Cutter | 70927ec9 | 2018-03-22 00:58:49 | [diff] [blame] | 27 | #include "chrome/common/extensions/api/url_handlers/url_handlers_parser.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 28 | #include "chrome/common/extensions/sync_helper.h" |
treib | b6af28cd | 2015-12-01 11:19:46 | [diff] [blame] | 29 | #include "components/variations/variations_associated_data.h" |
Evan Stade | 8915819 | 2021-01-27 18:45:23 | [diff] [blame] | 30 | #include "components/webapps/browser/banners/app_banner_manager.h" |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 31 | #include "content/public/browser/site_instance.h" |
Devlin Cronin | bffe949eb | 2018-01-12 03:03:40 | [diff] [blame] | 32 | #include "extensions/browser/disable_reason.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 33 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 34 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 35 | #include "extensions/browser/extension_system.h" |
[email protected] | 30e190f8 | 2014-05-26 16:44:39 | [diff] [blame] | 36 | #include "extensions/browser/extension_util.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 37 | #include "extensions/common/extension.h" |
[email protected] | 4b790884 | 2014-04-07 23:50:22 | [diff] [blame] | 38 | #include "extensions/common/extension_icon_set.h" |
Swapnil | f6f2f1d | 2021-01-14 18:50:43 | [diff] [blame] | 39 | #include "extensions/common/extension_urls.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 40 | #include "extensions/common/manifest.h" |
tfarina | 0bcdf36 | 2015-06-29 22:19:26 | [diff] [blame] | 41 | #include "extensions/common/manifest_handlers/app_isolation_info.h" |
[email protected] | 1f7de25 | 2013-11-06 22:02:00 | [diff] [blame] | 42 | #include "extensions/common/manifest_handlers/incognito_info.h" |
Danan S | 5f43088 | 2020-01-14 04:52:55 | [diff] [blame] | 43 | #include "extensions/common/manifest_handlers/permissions_parser.h" |
[email protected] | 4d67e9d | 2014-08-18 22:03:54 | [diff] [blame] | 44 | #include "extensions/common/permissions/permissions_data.h" |
mukai | 4245dfe8 | 2014-09-05 17:40:51 | [diff] [blame] | 45 | #include "extensions/grit/extensions_browser_resources.h" |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 46 | #include "ui/base/resource/resource_bundle.h" |
Michael Giuffrida | 7efeed14 | 2017-06-07 06:29:21 | [diff] [blame] | 47 | #include "url/gurl.h" |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 48 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 49 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Yeunjoo Choi | e409e8e | 2021-07-06 11:09:39 | [diff] [blame] | 50 | #include "chrome/browser/ash/file_manager/app_id.h" |
Yeunjoo Choi | 15ab1ac | 2021-02-04 17:15:07 | [diff] [blame] | 51 | #include "chrome/browser/ash/profiles/profile_helper.h" |
treib | 1325119 | 2016-06-29 07:13:15 | [diff] [blame] | 52 | #endif |
| 53 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 54 | namespace extensions { |
| 55 | namespace util { |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 56 | |
[email protected] | b33c8c2 | 2014-05-29 19:51:08 | [diff] [blame] | 57 | namespace { |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 58 | // Returns |extension_id|. See note below. |
| 59 | std::string ReloadExtensionIfEnabled(const std::string& extension_id, |
| 60 | content::BrowserContext* context) { |
| 61 | ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 62 | bool extension_is_enabled = |
| 63 | registry->enabled_extensions().Contains(extension_id); |
| 64 | |
| 65 | if (!extension_is_enabled) |
| 66 | return extension_id; |
| 67 | |
| 68 | // When we reload the extension the ID may be invalidated if we've passed it |
| 69 | // by const ref everywhere. Make a copy to be safe. http://crbug.com/103762 |
| 70 | std::string id = extension_id; |
| 71 | ExtensionService* service = |
| 72 | ExtensionSystem::Get(context)->extension_service(); |
| 73 | CHECK(service); |
| 74 | service->ReloadExtension(id); |
| 75 | return id; |
| 76 | } |
| 77 | |
[email protected] | 277c414 | 2014-06-19 20:08:54 | [diff] [blame] | 78 | } // namespace |
[email protected] | b33c8c2 | 2014-05-29 19:51:08 | [diff] [blame] | 79 | |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 80 | bool HasIsolatedStorage(const std::string& extension_id, |
| 81 | content::BrowserContext* context) { |
| 82 | const Extension* extension = |
| 83 | ExtensionRegistry::Get(context)->enabled_extensions().GetByID( |
| 84 | extension_id); |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 85 | |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 86 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 87 | const bool is_policy_extension = |
| 88 | extension && Manifest::IsPolicyLocation(extension->location()); |
| 89 | Profile* profile = Profile::FromBrowserContext(context); |
Yeunjoo Choi | 36f21d54 | 2022-01-13 03:12:33 | [diff] [blame] | 90 | if (profile && ash::ProfileHelper::IsSigninProfile(profile) && |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 91 | is_policy_extension) { |
| 92 | return true; |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | return extension && AppIsolationInfo::HasIsolatedStorage(extension); |
| 97 | } |
| 98 | |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 99 | void SetIsIncognitoEnabled(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 100 | content::BrowserContext* context, |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 101 | bool enabled) { |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 102 | ExtensionRegistry* registry = ExtensionRegistry::Get(context); |
| 103 | const Extension* extension = |
| 104 | registry->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 105 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 106 | if (extension) { |
kundaji | e548e744 | 2015-09-18 23:19:09 | [diff] [blame] | 107 | if (!util::CanBeIncognitoEnabled(extension)) |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 108 | return; |
| 109 | |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 110 | // TODO(treib,kalman): Should this be Manifest::IsComponentLocation(..)? |
Gyuyoung Kim | 5626c75 | 2021-03-18 22:58:11 | [diff] [blame] | 111 | // (which also checks for kExternalComponent). |
| 112 | if (extension->location() == mojom::ManifestLocation::kComponent) { |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 113 | // This shouldn't be called for component extensions unless it is called |
| 114 | // by sync, for syncable component extensions. |
| 115 | // See http://crbug.com/112290 and associated CLs for the sordid history. |
treib | 1325119 | 2016-06-29 07:13:15 | [diff] [blame] | 116 | bool syncable = sync_helper::IsSyncableComponentExtension(extension); |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 117 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
treib | 1325119 | 2016-06-29 07:13:15 | [diff] [blame] | 118 | // For some users, the file manager app somehow ended up being synced even |
| 119 | // though it's supposed to be unsyncable; see crbug.com/576964. If the bad |
| 120 | // data ever gets cleaned up, this hack should be removed. |
| 121 | syncable = syncable || extension->id() == file_manager::kFileManagerAppId; |
| 122 | #endif |
| 123 | DCHECK(syncable); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 124 | |
| 125 | // 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] | 126 | DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id, context)); |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 127 | return; |
| 128 | } |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 129 | } |
| 130 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 131 | ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 132 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 133 | // if the value changed and the extension is actually enabled, since there is |
| 134 | // no UI otherwise. |
| 135 | bool old_enabled = extension_prefs->IsIncognitoEnabled(extension_id); |
| 136 | if (enabled == old_enabled) |
| 137 | return; |
| 138 | |
| 139 | extension_prefs->SetIsIncognitoEnabled(extension_id, enabled); |
| 140 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 141 | std::string id = ReloadExtensionIfEnabled(extension_id, context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 142 | |
| 143 | // Reloading the extension invalidates the |extension| pointer. |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 144 | extension = registry->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 145 | if (extension) { |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 146 | Profile* profile = Profile::FromBrowserContext(context); |
| 147 | ExtensionSyncService::Get(profile)->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 148 | } |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 151 | bool CanLoadInIncognito(const Extension* extension, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 152 | content::BrowserContext* context) { |
| 153 | CHECK(extension); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 154 | if (extension->is_hosted_app()) |
| 155 | return true; |
| 156 | // Packaged apps and regular extensions need to be enabled specifically for |
| 157 | // incognito (and split mode should be set). |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 158 | return IncognitoInfo::IsSplitMode(extension) && |
| 159 | IsIncognitoEnabled(extension->id(), context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 162 | bool AllowFileAccess(const std::string& extension_id, |
| 163 | content::BrowserContext* context) { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 164 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
Oscar Johansson | 7f4c1b93 | 2018-06-12 06:11:58 | [diff] [blame] | 165 | ::switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 166 | ExtensionPrefs::Get(context)->AllowFileAccess(extension_id); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 169 | void SetAllowFileAccess(const std::string& extension_id, |
| 170 | content::BrowserContext* context, |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 171 | bool allow) { |
| 172 | // Reload to update browser state. Only bother if the value changed and the |
| 173 | // extension is actually enabled, since there is no UI otherwise. |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 174 | if (allow == AllowFileAccess(extension_id, context)) |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 175 | return; |
| 176 | |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 177 | ExtensionPrefs::Get(context)->SetAllowFileAccess(extension_id, allow); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 178 | |
thestig | 7b4bd93 | 2014-09-09 22:44:31 | [diff] [blame] | 179 | ReloadExtensionIfEnabled(extension_id, context); |
[email protected] | a7ff4b7 | 2013-10-17 20:56:02 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 182 | bool IsAppLaunchable(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 183 | content::BrowserContext* context) { |
[email protected] | 47e1940 | 2014-06-27 09:01:14 | [diff] [blame] | 184 | int reason = ExtensionPrefs::Get(context)->GetDisableReasons(extension_id); |
Minh X. Nguyen | 4547901 | 2017-08-18 21:35:36 | [diff] [blame] | 185 | return !((reason & disable_reason::DISABLE_UNSUPPORTED_REQUIREMENT) || |
| 186 | (reason & disable_reason::DISABLE_CORRUPTED)); |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | bool IsAppLaunchableWithoutEnabling(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 190 | content::BrowserContext* context) { |
| 191 | return ExtensionRegistry::Get(context)->GetExtensionById( |
| 192 | extension_id, ExtensionRegistry::ENABLED) != NULL; |
[email protected] | f5ea096 | 2013-11-22 09:20:47 | [diff] [blame] | 193 | } |
| 194 | |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 195 | bool ShouldSync(const Extension* extension, |
| 196 | content::BrowserContext* context) { |
Swapnil | f6f2f1d | 2021-01-14 18:50:43 | [diff] [blame] | 197 | ExtensionManagement* extension_management = |
| 198 | ExtensionManagementFactory::GetForBrowserContext(context); |
| 199 | // Update URL is overridden only for non webstore extensions and offstore |
| 200 | // extensions should not be synced. |
| 201 | if (extension_management->IsUpdateUrlOverridden(extension->id())) { |
| 202 | const GURL update_url = |
| 203 | extension_management->GetEffectiveUpdateURL(*extension); |
| 204 | DCHECK(!extension_urls::IsWebstoreUpdateUrl(update_url)) |
| 205 | << "Update URL cannot be overridden to be the webstore URL!"; |
| 206 | return false; |
| 207 | } |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 208 | return sync_helper::IsSyncable(extension) && |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 209 | !ExtensionPrefs::Get(context)->DoNotSync(extension->id()); |
| 210 | } |
| 211 | |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 212 | bool IsExtensionIdle(const std::string& extension_id, |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 213 | content::BrowserContext* context) { |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 214 | std::vector<std::string> ids_to_check; |
| 215 | ids_to_check.push_back(extension_id); |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 216 | |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 217 | const Extension* extension = |
| 218 | ExtensionRegistry::Get(context) |
| 219 | ->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); |
| 220 | if (extension && extension->is_shared_module()) { |
| 221 | // We have to check all the extensions that use this shared module for idle |
| 222 | // to tell whether it is really 'idle'. |
| 223 | SharedModuleService* service = ExtensionSystem::Get(context) |
| 224 | ->extension_service() |
| 225 | ->shared_module_service(); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 226 | std::unique_ptr<ExtensionSet> dependents = |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 227 | service->GetDependentExtensions(extension); |
| 228 | for (ExtensionSet::const_iterator i = dependents->begin(); |
| 229 | i != dependents->end(); |
| 230 | i++) { |
| 231 | ids_to_check.push_back((*i)->id()); |
| 232 | } |
| 233 | } |
| 234 | |
reillyg | 0ea3fa90 | 2014-10-28 15:30:23 | [diff] [blame] | 235 | ProcessManager* process_manager = ProcessManager::Get(context); |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 236 | for (std::vector<std::string>::const_iterator i = ids_to_check.begin(); |
| 237 | i != ids_to_check.end(); |
| 238 | i++) { |
| 239 | const std::string id = (*i); |
| 240 | ExtensionHost* host = process_manager->GetBackgroundHostForExtension(id); |
| 241 | if (host) |
| 242 | return false; |
| 243 | |
rdevlin.cronin | 3d426152 | 2015-02-10 00:48:15 | [diff] [blame] | 244 | scoped_refptr<content::SiteInstance> site_instance = |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 245 | process_manager->GetSiteInstanceForURL( |
| 246 | Extension::GetBaseURLFromExtensionId(id)); |
| 247 | if (site_instance && site_instance->HasProcess()) |
| 248 | return false; |
| 249 | |
rdevlin.cronin | 6ae04a01 | 2015-04-03 20:19:40 | [diff] [blame] | 250 | if (!process_manager->GetRenderFrameHostsForExtension(id).empty()) |
elijahtaylor | 0def443 | 2014-10-06 18:15:11 | [diff] [blame] | 251 | return false; |
| 252 | } |
| 253 | return true; |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 254 | } |
| 255 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 256 | std::unique_ptr<base::DictionaryValue> GetExtensionInfo( |
| 257 | const Extension* extension) { |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 258 | DCHECK(extension); |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 259 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 260 | |
| 261 | dict->SetString("id", extension->id()); |
| 262 | dict->SetString("name", extension->name()); |
| 263 | |
| 264 | GURL icon = extensions::ExtensionIconSource::GetIconURL( |
estade | 32426e0 | 2016-12-18 01:26:17 | [diff] [blame] | 265 | extension, extension_misc::EXTENSION_ICON_SMALLISH, |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 266 | ExtensionIconSet::MATCH_BIGGER, |
estade | 32426e0 | 2016-12-18 01:26:17 | [diff] [blame] | 267 | false); // Not grayscale. |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 268 | dict->SetString("icon", icon.spec()); |
| 269 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 270 | return dict; |
[email protected] | bb2feea | 2014-03-18 22:08:13 | [diff] [blame] | 271 | } |
| 272 | |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 273 | const gfx::ImageSkia& GetDefaultAppIcon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 274 | return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 275 | IDR_APP_DEFAULT_ICON); |
| 276 | } |
| 277 | |
| 278 | const gfx::ImageSkia& GetDefaultExtensionIcon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 279 | return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
[email protected] | 7eb20e3 | 2014-04-30 08:50:56 | [diff] [blame] | 280 | IDR_EXTENSION_DEFAULT_ICON); |
| 281 | } |
| 282 | |
Danan S | 5f43088 | 2020-01-14 04:52:55 | [diff] [blame] | 283 | std::unique_ptr<const PermissionSet> GetInstallPromptPermissionSetForExtension( |
| 284 | const Extension* extension, |
| 285 | Profile* profile, |
| 286 | bool include_optional_permissions) { |
| 287 | // Initialize permissions if they have not already been set so that |
| 288 | // any transformations are correctly reflected in the install prompt. |
| 289 | PermissionsUpdater(profile, PermissionsUpdater::INIT_FLAG_TRANSIENT) |
| 290 | .InitializePermissions(extension); |
| 291 | |
| 292 | std::unique_ptr<const PermissionSet> permissions_to_display = |
| 293 | extension->permissions_data()->active_permissions().Clone(); |
| 294 | |
| 295 | if (include_optional_permissions) { |
| 296 | const PermissionSet& optional_permissions = |
| 297 | PermissionsParser::GetOptionalPermissions(extension); |
| 298 | permissions_to_display = PermissionSet::CreateUnion(*permissions_to_display, |
| 299 | optional_permissions); |
| 300 | } |
| 301 | return permissions_to_display; |
| 302 | } |
| 303 | |
Lukasz Anforowicz | 507151f | 2021-05-04 20:27:03 | [diff] [blame] | 304 | std::vector<content::BrowserContext*> GetAllRelatedProfiles( |
| 305 | Profile* profile, |
| 306 | const Extension& extension) { |
Lukasz Anforowicz | 223d253 | 2021-03-09 17:04:07 | [diff] [blame] | 307 | std::vector<content::BrowserContext*> related_contexts; |
Lukasz Anforowicz | 223d253 | 2021-03-09 17:04:07 | [diff] [blame] | 308 | related_contexts.push_back(profile->GetOriginalProfile()); |
Lukasz Anforowicz | 507151f | 2021-05-04 20:27:03 | [diff] [blame] | 309 | |
| 310 | // The returned `related_contexts` should include all the related incognito |
| 311 | // profiles if the extension is globally allowed in incognito (this is a |
| 312 | // global, rather than per-profile toggle - this is why we it can be checked |
| 313 | // globally here, rather than once for every incognito profile looped over |
| 314 | // below). |
| 315 | if (IsIncognitoEnabled(extension.id(), profile)) { |
| 316 | std::vector<Profile*> off_the_record_profiles = |
| 317 | profile->GetAllOffTheRecordProfiles(); |
| 318 | related_contexts.reserve(related_contexts.size() + |
| 319 | off_the_record_profiles.size()); |
| 320 | for (Profile* off_the_record_profile : off_the_record_profiles) |
| 321 | related_contexts.push_back(off_the_record_profile); |
| 322 | } |
Lukasz Anforowicz | 223d253 | 2021-03-09 17:04:07 | [diff] [blame] | 323 | |
| 324 | return related_contexts; |
| 325 | } |
| 326 | |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 327 | } // namespace util |
| 328 | } // namespace extensions |