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