[email protected] | 098fa7a | 2013-03-08 22:11:17 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 5 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 6 | |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 8 | #include <iterator> |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 9 | #include <set> |
[email protected] | 654512b | 2010-09-01 02:09:42 | [diff] [blame] | 10 | |
[email protected] | 62433d3 | 2011-10-12 22:33:12 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 12 | #include "base/metrics/histogram.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 13 | #include "base/strings/string_number_conversions.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 14 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 15 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 16 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 17 | #include "base/threading/thread_restrictions.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 18 | #include "base/time/time.h" |
[email protected] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 19 | #include "chrome/browser/browser_process.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 20 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | ad44576 | 2013-01-23 00:47:44 | [diff] [blame] | 21 | #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 22 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 23 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 24 | #include "chrome/browser/extensions/data_deleter.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_assets_manager.h" |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_disabled_ui.h" |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_error_controller.h" |
[email protected] | 00b3824 | 2012-07-18 18:43:22 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 617342a4 | 2013-12-18 23:34:03 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | e5d6b471 | 2014-06-04 20:07:23 | [diff] [blame] | 32 | #include "chrome/browser/extensions/external_install_ui.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 33 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 34 | #include "chrome/browser/extensions/install_verifier.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 35 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | f3d3b38 | 2014-03-14 21:19:28 | [diff] [blame] | 36 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 37 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 38 | #include "chrome/browser/extensions/shared_module_service.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 39 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 40 | #include "chrome/browser/extensions/updater/extension_cache.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 41 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 42 | #include "chrome/browser/profiles/profile.h" |
[email protected] | b5a507b2 | 2013-11-08 20:41:57 | [diff] [blame] | 43 | #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 44 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 45 | #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 46 | #include "chrome/browser/ui/webui/theme_source.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 47 | #include "chrome/common/chrome_switches.h" |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 48 | #include "chrome/common/crash_keys.h" |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 49 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 15d4d2d | 2013-08-09 06:49:03 | [diff] [blame] | 50 | #include "chrome/common/extensions/features/feature_channel.h" |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 51 | #include "chrome/common/extensions/manifest_url_handler.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 52 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 53 | #include "chrome/common/url_constants.h" |
[email protected] | 7a83dd07 | 2013-09-03 12:09:17 | [diff] [blame] | 54 | #include "components/startup_metric_utils/startup_metric_utils.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 55 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 56 | #include "content/public/browser/notification_service.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 57 | #include "content/public/browser/render_process_host.h" |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 58 | #include "content/public/browser/storage_partition.h" |
[email protected] | 3442353 | 2013-11-21 18:13:10 | [diff] [blame] | 59 | #include "extensions/browser/event_router.h" |
[email protected] | 22401dc | 2014-03-21 01:38:57 | [diff] [blame] | 60 | #include "extensions/browser/extension_host.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 61 | #include "extensions/browser/extension_prefs.h" |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 62 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 63 | #include "extensions/browser/extension_system.h" |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 64 | #include "extensions/browser/pref_names.h" |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 65 | #include "extensions/browser/runtime_data.h" |
[email protected] | a9aa62b31 | 2013-11-29 05:35:06 | [diff] [blame] | 66 | #include "extensions/browser/update_observer.h" |
[email protected] | fb820c0 | 2014-03-13 15:07:08 | [diff] [blame] | 67 | #include "extensions/common/extension_messages.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 68 | #include "extensions/common/feature_switch.h" |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 69 | #include "extensions/common/file_util.h" |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 70 | #include "extensions/common/manifest_constants.h" |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 71 | #include "extensions/common/manifest_handlers/background_info.h" |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 72 | #include "extensions/common/manifest_handlers/permissions_parser.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 73 | #include "extensions/common/one_shot_event.h" |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 74 | #include "extensions/common/permissions/permission_message_provider.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 75 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | 79a6064 | 2012-10-20 21:03:18 | [diff] [blame] | 76 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 77 | #if defined(OS_CHROMEOS) |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 78 | #include "chrome/browser/chromeos/extensions/install_limiter.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 79 | #include "webkit/browser/fileapi/file_system_backend.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 80 | #include "webkit/browser/fileapi/file_system_context.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 81 | #endif |
| 82 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 83 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 84 | using content::BrowserThread; |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 85 | using content::DevToolsAgentHost; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 86 | using extensions::CrxInstaller; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 87 | using extensions::Extension; |
| 88 | using extensions::ExtensionIdSet; |
| 89 | using extensions::ExtensionInfo; |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 90 | using extensions::ExtensionRegistry; |
[email protected] | 289c44b | 2013-12-17 03:26:57 | [diff] [blame] | 91 | using extensions::ExtensionSet; |
[email protected] | 215a7be | 2012-10-22 19:53:42 | [diff] [blame] | 92 | using extensions::FeatureSwitch; |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 93 | using extensions::InstallVerifier; |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 94 | using extensions::ManagementPolicy; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 95 | using extensions::Manifest; |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 96 | using extensions::PermissionMessage; |
| 97 | using extensions::PermissionMessages; |
| 98 | using extensions::PermissionSet; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 99 | using extensions::SharedModuleInfo; |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 100 | using extensions::SharedModuleService; |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 101 | using extensions::UnloadedExtensionInfo; |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 102 | |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 103 | namespace errors = extensions::manifest_errors; |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 104 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 105 | namespace { |
| 106 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 107 | // Histogram values for logging events related to externally installed |
| 108 | // extensions. |
| 109 | enum ExternalExtensionEvent { |
| 110 | EXTERNAL_EXTENSION_INSTALLED = 0, |
| 111 | EXTERNAL_EXTENSION_IGNORED, |
| 112 | EXTERNAL_EXTENSION_REENABLED, |
| 113 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 114 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY, |
| 115 | }; |
| 116 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 117 | // Prompt the user this many times before considering an extension acknowledged. |
| 118 | static const int kMaxExtensionAcknowledgePromptCount = 3; |
| 119 | |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 120 | // Wait this many seconds after an extensions becomes idle before updating it. |
| 121 | static const int kUpdateIdleDelay = 5; |
| 122 | |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 123 | static bool IsCWSSharedModule(const Extension* extension) { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 124 | return extension->from_webstore() && |
| 125 | SharedModuleInfo::IsSharedModule(extension); |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | class SharedModuleProvider : public extensions::ManagementPolicy::Provider { |
| 129 | public: |
| 130 | SharedModuleProvider() {} |
| 131 | virtual ~SharedModuleProvider() {} |
| 132 | |
| 133 | virtual std::string GetDebugPolicyProviderName() const OVERRIDE { |
| 134 | return "SharedModuleProvider"; |
| 135 | } |
| 136 | |
| 137 | virtual bool UserMayModifySettings(const Extension* extension, |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 138 | base::string16* error) const OVERRIDE { |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 139 | return !IsCWSSharedModule(extension); |
| 140 | } |
| 141 | |
| 142 | virtual bool MustRemainEnabled(const Extension* extension, |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 143 | base::string16* error) const OVERRIDE { |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 144 | return IsCWSSharedModule(extension); |
| 145 | } |
| 146 | |
| 147 | private: |
| 148 | DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); |
| 149 | }; |
| 150 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 151 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 152 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 153 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 154 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 155 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 156 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 157 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 158 | // Check if the providers know about this extension. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 159 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 160 | for (i = external_extension_providers_.begin(); |
| 161 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 162 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 163 | if (i->get()->HasExtension(id)) |
| 164 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 167 | // We get the list of external extensions to check from preferences. |
| 168 | // It is possible that an extension has preferences but is not loaded. |
| 169 | // For example, an extension that requires experimental permissions |
| 170 | // will not be loaded if the experimental command line flag is not used. |
| 171 | // In this case, do not uninstall. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 172 | if (!GetInstalledExtension(id)) { |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 173 | // We can't call UninstallExtension with an unloaded/invalid |
| 174 | // extension ID. |
| 175 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 176 | << "with id: " << id; |
| 177 | return; |
| 178 | } |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 179 | UninstallExtension(id, true, NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 180 | } |
| 181 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 182 | void ExtensionService::SetFileTaskRunnerForTesting( |
| 183 | base::SequencedTaskRunner* task_runner) { |
| 184 | file_task_runner_ = task_runner; |
| 185 | } |
| 186 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 187 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 188 | external_extension_providers_.clear(); |
| 189 | } |
| 190 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 191 | void ExtensionService::AddProviderForTesting( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 192 | extensions::ExternalProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 193 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 194 | external_extension_providers_.push_back( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 195 | linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 196 | } |
| 197 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 198 | bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 199 | const std::string& id, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 200 | const std::string& install_parameter, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 201 | const GURL& update_url, |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 202 | Manifest::Location location, |
| 203 | int creation_flags, |
| 204 | bool mark_acknowledged) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 205 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 206 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 207 | |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 208 | if (Manifest::IsExternalLocation(location)) { |
| 209 | // All extensions that are not user specific can be cached. |
| 210 | extensions::ExtensionCache::GetInstance()->AllowCaching(id); |
| 211 | } |
| 212 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 213 | const Extension* extension = GetExtensionById(id, true); |
| 214 | if (extension) { |
| 215 | // Already installed. Skip this install if the current location has |
| 216 | // higher priority than |location|. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 217 | Manifest::Location current = extension->location(); |
| 218 | if (current == Manifest::GetHigherPriorityLocation(current, location)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 219 | return false; |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 220 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 221 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 222 | |
| 223 | // Add |id| to the set of pending extensions. If it can not be added, |
| 224 | // then there is already a pending record from a higher-priority install |
| 225 | // source. In this case, signal that this extension will not be |
| 226 | // installed by returning false. |
| 227 | if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 228 | id, |
| 229 | install_parameter, |
| 230 | update_url, |
| 231 | location, |
| 232 | creation_flags, |
| 233 | mark_acknowledged)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 234 | return false; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 235 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 236 | |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 237 | update_once_all_providers_are_ready_ = true; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 238 | return true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 241 | // static |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 242 | // This function is used to implement the command-line switch |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 243 | // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 244 | // statements within this function are used to inform the user if the uninstall |
| 245 | // cannot be done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 246 | bool ExtensionService::UninstallExtensionHelper( |
| 247 | ExtensionService* extensions_service, |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 248 | const std::string& extension_id) { |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 249 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 250 | if (!extensions_service->GetInstalledExtension(extension_id)) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 251 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 252 | << "id: " << extension_id; |
| 253 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 254 | } |
| 255 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 256 | // The following call to UninstallExtension will not allow an uninstall of a |
| 257 | // policy-controlled extension. |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 258 | base::string16 error; |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 259 | if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 260 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 261 | << ": " << error; |
| 262 | return false; |
| 263 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 264 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 265 | return true; |
| 266 | } |
| 267 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 268 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 269 | const CommandLine* command_line, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 270 | const base::FilePath& install_directory, |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 271 | extensions::ExtensionPrefs* extension_prefs, |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 272 | extensions::Blacklist* blacklist, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 273 | bool autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 274 | bool extensions_enabled, |
| 275 | extensions::OneShotEvent* ready) |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 276 | : extensions::Blacklist::Observer(blacklist), |
| 277 | profile_(profile), |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 278 | system_(extensions::ExtensionSystem::Get(profile)), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 279 | extension_prefs_(extension_prefs), |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 280 | blacklist_(blacklist), |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 281 | extension_sync_service_(NULL), |
[email protected] | 5fdfa56 | 2013-12-27 17:43:59 | [diff] [blame] | 282 | registry_(extensions::ExtensionRegistry::Get(profile)), |
[email protected] | 6c9bedf | 2014-05-21 03:55:51 | [diff] [blame] | 283 | pending_extension_manager_(profile), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 284 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 285 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 286 | show_extensions_prompts_(true), |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 287 | install_updates_when_idle_(true), |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 288 | ready_(ready), |
[email protected] | dff1e04 | 2012-04-27 10:59:18 | [diff] [blame] | 289 | update_once_all_providers_are_ready_(false), |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 290 | browser_terminating_(false), |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 291 | installs_delayed_for_gc_(false), |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 292 | is_first_run_(false), |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 293 | shared_module_service_(new extensions::SharedModuleService(profile_)) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 294 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 295 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 296 | // Figure out if extension installation should be enabled. |
[email protected] | 367d9b17 | 2013-12-03 00:31:02 | [diff] [blame] | 297 | if (extensions::ExtensionsBrowserClient::Get()->AreExtensionsDisabled( |
| 298 | *command_line, profile)) |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 299 | extensions_enabled_ = false; |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 300 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 301 | registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 302 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 303 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 304 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 305 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 306 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 307 | registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 308 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 309 | registrar_.Add(this, |
| 310 | chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, |
| 311 | content::Source<Profile>(profile_)); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 312 | pref_change_registrar_.Init(profile->GetPrefs()); |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 313 | base::Closure callback = |
| 314 | base::Bind(&ExtensionService::OnExtensionInstallPrefChanged, |
| 315 | base::Unretained(this)); |
[email protected] | 234fc5ff | 2014-01-16 23:32:28 | [diff] [blame] | 316 | pref_change_registrar_.Add(extensions::pref_names::kInstallAllowList, |
| 317 | callback); |
| 318 | pref_change_registrar_.Add(extensions::pref_names::kInstallDenyList, |
| 319 | callback); |
| 320 | pref_change_registrar_.Add(extensions::pref_names::kAllowedTypes, callback); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 321 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 322 | // Set up the ExtensionUpdater |
| 323 | if (autoupdate_enabled) { |
[email protected] | 501105b | 2013-09-26 05:42:02 | [diff] [blame] | 324 | int update_frequency = extensions::kDefaultUpdateFrequencySeconds; |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 325 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 326 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 327 | switches::kExtensionsUpdateFrequency), |
| 328 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 329 | } |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 330 | updater_.reset(new extensions::ExtensionUpdater( |
| 331 | this, |
| 332 | extension_prefs, |
| 333 | profile->GetPrefs(), |
| 334 | profile, |
| 335 | update_frequency, |
| 336 | extensions::ExtensionCache::GetInstance())); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 339 | component_loader_.reset( |
| 340 | new extensions::ComponentLoader(this, |
| 341 | profile->GetPrefs(), |
[email protected] | 55e16cd | 2013-12-18 04:36:08 | [diff] [blame] | 342 | g_browser_process->local_state(), |
| 343 | profile)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 344 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 345 | if (extensions_enabled_) { |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 346 | extensions::ExternalProviderImpl::CreateExternalProviders( |
| 347 | this, profile_, &external_extension_providers_); |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 348 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 349 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 350 | // Set this as the ExtensionService for app sorting to ensure it causes syncs |
| 351 | // if required. |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 352 | is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun(); |
| 353 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 354 | error_controller_.reset( |
| 355 | new extensions::ExtensionErrorController(profile_, is_first_run_)); |
| 356 | |
[email protected] | 9ce11d2 | 2012-08-08 23:20:13 | [diff] [blame] | 357 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 358 | extension_action_storage_manager_.reset( |
| 359 | new extensions::ExtensionActionStorageManager(profile_)); |
[email protected] | 9ce11d2 | 2012-08-08 23:20:13 | [diff] [blame] | 360 | #endif |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 361 | |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 362 | shared_module_policy_provider_.reset(new SharedModuleProvider); |
| 363 | |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 364 | // How long is the path to the Extensions directory? |
| 365 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 366 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 369 | const ExtensionSet* ExtensionService::extensions() const { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 370 | return ®istry_->enabled_extensions(); |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 373 | extensions::PendingExtensionManager* |
| 374 | ExtensionService::pending_extension_manager() { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 375 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 378 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 379 | // No need to unload extensions here because they are profile-scoped, and the |
| 380 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 381 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 382 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 383 | for (i = external_extension_providers_.begin(); |
| 384 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 385 | extensions::ExternalProviderInterface* provider = i->get(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 386 | provider->ServiceShutdown(); |
| 387 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 388 | } |
| 389 | |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 390 | void ExtensionService::Shutdown() { |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 391 | system_->management_policy()->UnregisterProvider( |
| 392 | shared_module_policy_provider_.get()); |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 393 | } |
| 394 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 395 | const Extension* ExtensionService::GetExtensionById( |
| 396 | const std::string& id, bool include_disabled) const { |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 397 | int include_mask = ExtensionRegistry::ENABLED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 398 | if (include_disabled) { |
| 399 | // Include blacklisted extensions here because there are hundreds of |
| 400 | // callers of this function, and many might assume that this includes those |
| 401 | // that have been disabled due to blacklisting. |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 402 | include_mask |= ExtensionRegistry::DISABLED | |
| 403 | ExtensionRegistry::BLACKLISTED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 404 | } |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 405 | return registry_->GetExtensionById(id, include_mask); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 408 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 409 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 410 | |
[email protected] | 3350d71 | 2013-11-18 09:32:24 | [diff] [blame] | 411 | base::Time begin_time = base::Time::Now(); |
| 412 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 413 | DCHECK(!is_ready()); // Can't redo init. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 414 | DCHECK_EQ(registry_->enabled_extensions().size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 415 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 416 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 417 | if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || |
| 418 | cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) { |
| 419 | // The sole purpose of this launch is to install a new extension from CWS |
| 420 | // and immediately terminate: loading already installed extensions is |
| 421 | // unnecessary and may interfere with the inline install dialog (e.g. if an |
| 422 | // extension listens to onStartup and opens a window). |
| 423 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 424 | } else { |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 425 | // LoadAllExtensions() calls OnLoadedInstalledExtensions(). |
| 426 | component_loader_->LoadAll(); |
| 427 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 428 | |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 429 | ReconcileKnownDisabled(); |
| 430 | |
[email protected] | 2edd5785 | 2013-08-14 22:07:40 | [diff] [blame] | 431 | // Attempt to re-enable extensions whose only disable reason is reloading. |
| 432 | std::vector<std::string> extensions_to_enable; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 433 | const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); |
| 434 | for (ExtensionSet::const_iterator iter = disabled_extensions.begin(); |
| 435 | iter != disabled_extensions.end(); ++iter) { |
[email protected] | 2edd5785 | 2013-08-14 22:07:40 | [diff] [blame] | 436 | const Extension* e = iter->get(); |
| 437 | if (extension_prefs_->GetDisableReasons(e->id()) == |
| 438 | Extension::DISABLE_RELOAD) { |
| 439 | extensions_to_enable.push_back(e->id()); |
| 440 | } |
| 441 | } |
| 442 | for (std::vector<std::string>::iterator it = extensions_to_enable.begin(); |
| 443 | it != extensions_to_enable.end(); ++it) { |
| 444 | EnableExtension(*it); |
| 445 | } |
| 446 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 447 | // Finish install (if possible) of extensions that were still delayed while |
| 448 | // the browser was shut down. |
| 449 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info( |
| 450 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 451 | for (size_t i = 0; i < delayed_info->size(); ++i) { |
| 452 | ExtensionInfo* info = delayed_info->at(i).get(); |
| 453 | scoped_refptr<const Extension> extension(NULL); |
| 454 | if (info->extension_manifest) { |
| 455 | std::string error; |
| 456 | extension = Extension::Create( |
| 457 | info->extension_path, |
| 458 | info->extension_location, |
| 459 | *info->extension_manifest, |
| 460 | extension_prefs_->GetDelayedInstallCreationFlags( |
| 461 | info->extension_id), |
| 462 | info->extension_id, |
| 463 | &error); |
| 464 | if (extension.get()) |
| 465 | delayed_installs_.Insert(extension); |
| 466 | } |
| 467 | } |
| 468 | MaybeFinishDelayedInstallations(); |
| 469 | |
| 470 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2( |
| 471 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 472 | UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
| 473 | delayed_info2->size() - delayed_info->size()); |
| 474 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 475 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 476 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 477 | // TODO(erikkay) this should probably be deferred to a future point |
| 478 | // rather than running immediately at startup. |
| 479 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 480 | |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 481 | system_->management_policy()->RegisterProvider( |
| 482 | shared_module_policy_provider_.get()); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 483 | |
| 484 | LoadGreylistFromPrefs(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 485 | } |
[email protected] | 3350d71 | 2013-11-18 09:32:24 | [diff] [blame] | 486 | |
| 487 | UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", |
| 488 | base::Time::Now() - begin_time); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 489 | } |
| 490 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 491 | void ExtensionService::LoadGreylistFromPrefs() { |
[email protected] | f47f717 | 2014-03-19 19:27:10 | [diff] [blame] | 492 | scoped_ptr<ExtensionSet> all_extensions = |
| 493 | registry_->GenerateInstalledExtensionsSet(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 494 | |
| 495 | for (ExtensionSet::const_iterator it = all_extensions->begin(); |
| 496 | it != all_extensions->end(); ++it) { |
| 497 | extensions::BlacklistState state = |
| 498 | extension_prefs_->GetExtensionBlacklistState((*it)->id()); |
| 499 | if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY || |
| 500 | state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED || |
| 501 | state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION) |
| 502 | greylist_.Insert(*it); |
| 503 | } |
| 504 | } |
| 505 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 506 | bool ExtensionService::UpdateExtension(const std::string& id, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 507 | const base::FilePath& extension_path, |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 508 | bool file_ownership_passed, |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 509 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 510 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 511 | if (browser_terminating_) { |
| 512 | LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown"; |
| 513 | // Leak the temp file at extension_path. We don't want to add to the disk |
| 514 | // I/O burden at shutdown, we can't rely on the I/O completing anyway, and |
| 515 | // the file is in the OS temp directory which should be cleaned up for us. |
| 516 | return false; |
| 517 | } |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 518 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 519 | const extensions::PendingExtensionInfo* pending_extension_info = |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 520 | pending_extension_manager()->GetById(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 521 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 522 | const Extension* extension = GetInstalledExtension(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 523 | if (!pending_extension_info && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 524 | LOG(WARNING) << "Will not update extension " << id |
| 525 | << " because it is not installed or pending"; |
| 526 | // Delete extension_path since we're not creating a CrxInstaller |
| 527 | // that would do it for us. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 528 | if (!GetFileTaskRunner()->PostTask( |
| 529 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 530 | base::Bind( |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 531 | &extensions::file_util::DeleteFile, extension_path, false))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 532 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 533 | |
| 534 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 535 | } |
| 536 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 537 | // We want a silent install only for non-pending extensions and |
| 538 | // pending extensions that have install_silently set. |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 539 | scoped_ptr<ExtensionInstallPrompt> client; |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 540 | if (pending_extension_info && !pending_extension_info->install_silently()) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 541 | client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 542 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 543 | scoped_refptr<CrxInstaller> installer( |
| 544 | CrxInstaller::Create(this, client.Pass())); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 545 | installer->set_expected_id(id); |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 546 | int creation_flags = Extension::NO_FLAGS; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 547 | if (pending_extension_info) { |
| 548 | installer->set_install_source(pending_extension_info->install_source()); |
| 549 | if (pending_extension_info->install_silently()) |
| 550 | installer->set_allow_silent_install(true); |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 551 | if (pending_extension_info->remote_install()) |
| 552 | installer->set_grant_permissions(false); |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 553 | creation_flags = pending_extension_info->creation_flags(); |
| 554 | if (pending_extension_info->mark_acknowledged()) |
| 555 | AcknowledgeExternalExtension(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 556 | } else if (extension) { |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 557 | installer->set_install_source(extension->location()); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 558 | } |
[email protected] | 7d8b707 | 2012-04-07 01:07:46 | [diff] [blame] | 559 | // If the extension was installed from or has migrated to the webstore, or |
[email protected] | fcb2c2c | 2012-10-17 21:08:45 | [diff] [blame] | 560 | // its auto-update URL is from the webstore, treat it as a webstore install. |
| 561 | // Note that we ignore some older extensions with blank auto-update URLs |
| 562 | // because we are mostly concerned with restrictions on NaCl extensions, |
| 563 | // which are newer. |
[email protected] | 7576451 | 2011-12-19 19:54:28 | [diff] [blame] | 564 | if ((extension && extension->from_webstore()) || |
[email protected] | 4a5fe3e2 | 2013-06-04 07:06:38 | [diff] [blame] | 565 | (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) || |
[email protected] | 963d13c | 2012-09-29 17:13:35 | [diff] [blame] | 566 | (!extension && extension_urls::IsWebstoreUpdateUrl( |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 567 | pending_extension_info->update_url()))) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 568 | creation_flags |= Extension::FROM_WEBSTORE; |
| 569 | } |
| 570 | |
| 571 | // Bookmark apps being updated is kind of a contradiction, but that's because |
| 572 | // we mark the default apps as bookmark apps, and they're hosted in the web |
| 573 | // store, thus they can get updated. See http://crbug.com/101605 for more |
| 574 | // details. |
| 575 | if (extension && extension->from_bookmark()) |
| 576 | creation_flags |= Extension::FROM_BOOKMARK; |
| 577 | |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 578 | if (extension && extension->was_installed_by_default()) |
| 579 | creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
| 580 | |
[email protected] | acc3c7c2 | 2014-03-19 06:23:39 | [diff] [blame] | 581 | if (extension && extension->was_installed_by_oem()) |
| 582 | creation_flags |= Extension::WAS_INSTALLED_BY_OEM; |
| 583 | |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 584 | if (extension) |
| 585 | installer->set_is_ephemeral(extension_prefs_->IsEphemeralApp(id)); |
[email protected] | ab6c7be4 | 2014-01-16 02:05:54 | [diff] [blame] | 586 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 587 | installer->set_creation_flags(creation_flags); |
| 588 | |
[email protected] | 044e8699 | 2014-01-24 22:59:11 | [diff] [blame] | 589 | installer->set_delete_source(file_ownership_passed); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 590 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 591 | installer->InstallCrx(extension_path); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 592 | |
| 593 | if (out_crx_installer) |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 594 | *out_crx_installer = installer.get(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 595 | |
| 596 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 597 | } |
| 598 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 599 | void ExtensionService::ReloadExtension( |
| 600 | // "transient" because the process of reloading may cause the reference |
| 601 | // to become invalid. Instead, use |extension_id|, a copy. |
| 602 | const std::string& transient_extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 603 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 604 | |
| 605 | // If the extension is already reloading, don't reload again. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 606 | if (extension_prefs_->GetDisableReasons(transient_extension_id) & |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 607 | Extension::DISABLE_RELOAD) { |
| 608 | return; |
| 609 | } |
| 610 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 611 | // Ignore attempts to reload a blacklisted extension. Sometimes this can |
| 612 | // happen in a convoluted reload sequence triggered by the termination of a |
| 613 | // blacklisted extension and a naive attempt to reload it. For an example see |
| 614 | // http://crbug.com/373842. |
| 615 | if (registry_->blacklisted_extensions().Contains(transient_extension_id)) |
| 616 | return; |
| 617 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 618 | base::FilePath path; |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 619 | |
| 620 | std::string extension_id = transient_extension_id; |
| 621 | const Extension* transient_current_extension = |
| 622 | GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 623 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 624 | // Disable the extension if it's loaded. It might not be loaded if it crashed. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 625 | if (transient_current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 626 | // If the extension has an inspector open for its background page, detach |
| 627 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 628 | // later. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 629 | // TODO(yoz): this is not incognito-safe! |
[email protected] | 98b6d94 | 2013-11-10 00:34:07 | [diff] [blame] | 630 | extensions::ProcessManager* manager = system_->process_manager(); |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 631 | extensions::ExtensionHost* host = |
| 632 | manager->GetBackgroundHostForExtension(extension_id); |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 633 | if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 634 | // Look for an open inspector for the background page. |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 635 | scoped_refptr<DevToolsAgentHost> agent_host = |
| 636 | DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); |
| 637 | agent_host->DisconnectRenderViewHost(); |
| 638 | orphaned_dev_tools_[extension_id] = agent_host; |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 641 | path = transient_current_extension->path(); |
[email protected] | 5807619 | 2013-07-19 19:43:50 | [diff] [blame] | 642 | // BeingUpgraded is set back to false when the extension is added. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 643 | system_->runtime_data()->SetBeingUpgraded(transient_current_extension, |
| 644 | true); |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 645 | DisableExtension(extension_id, Extension::DISABLE_RELOAD); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 646 | reloading_extensions_.insert(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 647 | } else { |
| 648 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 649 | } |
| 650 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 651 | transient_current_extension = NULL; |
| 652 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 653 | if (delayed_installs_.Contains(extension_id)) { |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 654 | FinishDelayedInstallation(extension_id); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 655 | return; |
| 656 | } |
| 657 | |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 658 | // If we're reloading a component extension, use the component extension |
| 659 | // loader's reloader. |
| 660 | if (component_loader_->Exists(extension_id)) { |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 661 | SetBeingReloaded(extension_id, true); |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 662 | component_loader_->Reload(extension_id); |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 663 | SetBeingReloaded(extension_id, false); |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 664 | return; |
| 665 | } |
| 666 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 667 | // Check the installed extensions to see if what we're reloading was already |
| 668 | // installed. |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 669 | SetBeingReloaded(extension_id, true); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 670 | scoped_ptr<ExtensionInfo> installed_extension( |
| 671 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 672 | if (installed_extension.get() && |
| 673 | installed_extension->extension_manifest.get()) { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 674 | extensions::InstalledLoader(this).Load(*installed_extension, false); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 675 | } else { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 676 | // Otherwise, the extension is unpacked (location LOAD). |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 677 | // We should always be able to remember the extension's path. If it's not in |
| 678 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 679 | CHECK(!path.empty()); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 680 | extensions::UnpackedInstaller::Create(this)->Load(path); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 681 | } |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 682 | // When reloading is done, mark this extension as done reloading. |
| 683 | SetBeingReloaded(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 684 | } |
| 685 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 686 | bool ExtensionService::UninstallExtension( |
| 687 | // "transient" because the process of uninstalling may cause the reference |
| 688 | // to become invalid. Instead, use |extenson->id()|. |
| 689 | const std::string& transient_extension_id, |
| 690 | bool external_uninstall, |
| 691 | base::string16* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 692 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 693 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 694 | scoped_refptr<const Extension> extension = |
| 695 | GetInstalledExtension(transient_extension_id); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 696 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 697 | // Callers should not send us nonexistent extensions. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 698 | CHECK(extension.get()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 699 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 700 | // Policy change which triggers an uninstall will always set |
| 701 | // |external_uninstall| to true so this is the only way to uninstall |
| 702 | // managed extensions. |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 703 | // Shared modules being uninstalled will also set |external_uninstall| to true |
| 704 | // so that we can guarantee users don't uninstall a shared module. |
| 705 | // (crbug.com/273300) |
| 706 | // TODO(rdevlin.cronin): This is probably not right. We should do something |
| 707 | // else, like include an enum IS_INTERNAL_UNINSTALL or IS_USER_UNINSTALL so |
| 708 | // we don't do this. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 709 | if (!external_uninstall && |
| 710 | !system_->management_policy()->UserMayModifySettings( |
| 711 | extension.get(), error)) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 712 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 713 | chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 714 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 715 | content::Details<const Extension>(extension.get())); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 716 | return false; |
| 717 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 718 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 719 | syncer::SyncChange sync_change; |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 720 | if (extension_sync_service_) { |
| 721 | sync_change = extension_sync_service_->PrepareToSyncUninstallExtension( |
| 722 | extension.get(), is_ready()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 723 | } |
| 724 | |
[email protected] | d820bc5 | 2014-03-13 05:35:23 | [diff] [blame] | 725 | system_->install_verifier()->Remove(extension->id()); |
[email protected] | ffd2f79e | 2013-11-14 00:11:46 | [diff] [blame] | 726 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 727 | if (IsUnacknowledgedExternalExtension(extension.get())) { |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 728 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 729 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 730 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 731 | if (extensions::ManifestURL::UpdatesFromGallery(extension.get())) { |
| 732 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
| 733 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 734 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 735 | } else { |
| 736 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
| 737 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 738 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 739 | } |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 740 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 741 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 742 | extension->GetType(), 100); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 743 | RecordPermissionMessagesHistogram(extension.get(), |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 744 | "Extensions.Permissions_Uninstall2"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 745 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 746 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 747 | // any of these resources. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 748 | UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 749 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 750 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 751 | if (!Manifest::IsUnpackedLocation(extension->location())) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 752 | if (!GetFileTaskRunner()->PostTask( |
| 753 | FROM_HERE, |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 754 | base::Bind(&ExtensionService::UninstallExtensionOnFileThread, |
| 755 | extension->id(), |
| 756 | profile_, |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 757 | install_directory_, |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 758 | extension->path()))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 759 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 762 | // Do not remove the data of ephemeral apps. They will be garbage collected by |
| 763 | // EphemeralAppService. |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 764 | if (!extension_prefs_->IsEphemeralApp(extension->id())) |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 765 | extensions::DataDeleter::StartDeleting(profile_, extension.get()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 766 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 767 | UntrackTerminatedExtension(extension->id()); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 768 | |
| 769 | // Notify interested parties that we've uninstalled this extension. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 770 | content::NotificationService::current()->Notify( |
[email protected] | bbf8d30b | 2014-05-29 16:45:07 | [diff] [blame] | 771 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 772 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 773 | content::Details<const Extension>(extension.get())); |
[email protected] | 1d7f248 | 2014-05-24 00:11:51 | [diff] [blame] | 774 | ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(extension.get()); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 775 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 776 | if (extension_sync_service_) { |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 777 | extension_sync_service_->ProcessSyncUninstallExtension(extension->id(), |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 778 | sync_change); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 779 | } |
| 780 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 781 | delayed_installs_.Remove(extension->id()); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 782 | |
[email protected] | 757d60a | 2014-05-23 00:11:44 | [diff] [blame] | 783 | extension_prefs_->OnExtensionUninstalled( |
| 784 | extension->id(), extension->location(), external_uninstall); |
[email protected] | d4eda59 | 2013-09-18 03:37:57 | [diff] [blame] | 785 | |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 786 | // Track the uninstallation. |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 787 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 788 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 789 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 792 | // static |
| 793 | void ExtensionService::UninstallExtensionOnFileThread( |
| 794 | const std::string& id, |
| 795 | Profile* profile, |
| 796 | const base::FilePath& install_dir, |
| 797 | const base::FilePath& extension_path) { |
| 798 | extensions::ExtensionAssetsManager* assets_manager = |
| 799 | extensions::ExtensionAssetsManager::GetInstance(); |
| 800 | assets_manager->UninstallExtension(id, profile, install_dir, extension_path); |
| 801 | } |
| 802 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 803 | bool ExtensionService::IsExtensionEnabled( |
| 804 | const std::string& extension_id) const { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 805 | if (registry_->enabled_extensions().Contains(extension_id) || |
| 806 | registry_->terminated_extensions().Contains(extension_id)) { |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 807 | return true; |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 808 | } |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 809 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 810 | if (registry_->disabled_extensions().Contains(extension_id) || |
| 811 | registry_->blacklisted_extensions().Contains(extension_id)) { |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 812 | return false; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 813 | } |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 814 | |
| 815 | // If the extension hasn't been loaded yet, check the prefs for it. Assume |
| 816 | // enabled unless otherwise noted. |
| 817 | return !extension_prefs_->IsExtensionDisabled(extension_id) && |
[email protected] | 27e52832 | 2014-05-27 20:54:30 | [diff] [blame] | 818 | !extension_prefs_->IsExtensionBlacklisted(extension_id) && |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 819 | !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 820 | } |
| 821 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 822 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 823 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 824 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 825 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 826 | return; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 827 | const Extension* extension = |
| 828 | registry_->disabled_extensions().GetByID(extension_id); |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 829 | |
| 830 | ManagementPolicy* policy = system_->management_policy(); |
| 831 | if (extension && policy->MustRemainDisabled(extension, NULL, NULL)) { |
| 832 | UMA_HISTOGRAM_COUNTS_100("Extensions.EnableDeniedByPolicy", 1); |
| 833 | return; |
| 834 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 835 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 836 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 837 | extension_prefs_->ClearDisableReasons(extension_id); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 838 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 839 | // This can happen if sync enables an extension that is not |
| 840 | // installed yet. |
| 841 | if (!extension) |
| 842 | return; |
| 843 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 844 | if (IsUnacknowledgedExternalExtension(extension)) { |
| 845 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 846 | EXTERNAL_EXTENSION_REENABLED, |
| 847 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 848 | if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
| 849 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
| 850 | EXTERNAL_EXTENSION_REENABLED, |
| 851 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 852 | } else { |
| 853 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
| 854 | EXTERNAL_EXTENSION_REENABLED, |
| 855 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 856 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 857 | AcknowledgeExternalExtension(extension->id()); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 858 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 859 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 860 | // Move it over to the enabled list. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 861 | registry_->AddEnabled(make_scoped_refptr(extension)); |
| 862 | registry_->RemoveDisabled(extension->id()); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 863 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 864 | NotifyExtensionLoaded(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 865 | |
[email protected] | f74d7f3 | 2012-06-19 19:22:51 | [diff] [blame] | 866 | // Notify listeners that the extension was enabled. |
| 867 | content::NotificationService::current()->Notify( |
| 868 | chrome::NOTIFICATION_EXTENSION_ENABLED, |
| 869 | content::Source<Profile>(profile_), |
| 870 | content::Details<const Extension>(extension)); |
| 871 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 872 | if (extension_sync_service_) |
| 873 | extension_sync_service_->SyncEnableExtension(*extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 874 | } |
| 875 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 876 | void ExtensionService::DisableExtension( |
| 877 | const std::string& extension_id, |
| 878 | Extension::DisableReason disable_reason) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 879 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 880 | |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 881 | // The extension may have been disabled already. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 882 | if (!IsExtensionEnabled(extension_id)) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 883 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 884 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 885 | const Extension* extension = GetInstalledExtension(extension_id); |
| 886 | // |extension| can be NULL if sync disables an extension that is not |
| 887 | // installed yet. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 888 | if (extension && |
[email protected] | 505ccdc | 2013-06-20 20:15:35 | [diff] [blame] | 889 | disable_reason != Extension::DISABLE_RELOAD && |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 890 | !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 891 | return; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 892 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 893 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 894 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 895 | extension_prefs_->AddDisableReason(extension_id, disable_reason); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 896 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 897 | int include_mask = |
| 898 | ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; |
| 899 | extension = registry_->GetExtensionById(extension_id, include_mask); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 900 | if (!extension) |
| 901 | return; |
| 902 | |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 903 | // The extension is either enabled or terminated. |
| 904 | DCHECK(registry_->enabled_extensions().Contains(extension->id()) || |
| 905 | registry_->terminated_extensions().Contains(extension->id())); |
[email protected] | 64742de3 | 2013-04-22 08:44:34 | [diff] [blame] | 906 | |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 907 | // Move it over to the disabled list. Don't send a second unload notification |
| 908 | // for terminated extensions being disabled. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 909 | registry_->AddDisabled(make_scoped_refptr(extension)); |
| 910 | if (registry_->enabled_extensions().Contains(extension->id())) { |
| 911 | registry_->RemoveEnabled(extension->id()); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 912 | NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::REASON_DISABLE); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 913 | } else { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 914 | registry_->RemoveTerminated(extension->id()); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 915 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 916 | |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 917 | if (extension_sync_service_) |
| 918 | extension_sync_service_->SyncDisableExtension(*extension); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 919 | } |
| 920 | |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 921 | void ExtensionService::DisableUserExtensions( |
| 922 | const std::vector<std::string>& except_ids) { |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 923 | extensions::ManagementPolicy* management_policy = |
| 924 | system_->management_policy(); |
| 925 | extensions::ExtensionList to_disable; |
| 926 | |
[email protected] | 75181f6 | 2014-03-19 21:41:12 | [diff] [blame] | 927 | // TODO(rlp): Clean up this code. crbug.com/353266. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 928 | const ExtensionSet& enabled_set = registry_->enabled_extensions(); |
| 929 | for (ExtensionSet::const_iterator extension = enabled_set.begin(); |
| 930 | extension != enabled_set.end(); ++extension) { |
[email protected] | 75181f6 | 2014-03-19 21:41:12 | [diff] [blame] | 931 | if (management_policy->UserMayModifySettings(extension->get(), NULL) && |
| 932 | extension->get()->location() != Manifest::EXTERNAL_COMPONENT) |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 933 | to_disable.push_back(*extension); |
| 934 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 935 | const ExtensionSet& terminated_set = registry_->terminated_extensions(); |
| 936 | for (ExtensionSet::const_iterator extension = terminated_set.begin(); |
| 937 | extension != terminated_set.end(); ++extension) { |
[email protected] | 75181f6 | 2014-03-19 21:41:12 | [diff] [blame] | 938 | if (management_policy->UserMayModifySettings(extension->get(), NULL) && |
| 939 | extension->get()->location() != Manifest::EXTERNAL_COMPONENT) |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 940 | to_disable.push_back(*extension); |
| 941 | } |
| 942 | |
| 943 | for (extensions::ExtensionList::const_iterator extension = to_disable.begin(); |
| 944 | extension != to_disable.end(); ++extension) { |
[email protected] | 3082fe3 | 2013-08-06 11:12:38 | [diff] [blame] | 945 | if ((*extension)->was_installed_by_default() && |
| 946 | extension_urls::IsWebstoreUpdateUrl( |
| 947 | extensions::ManifestURL::GetUpdateURL(*extension))) |
| 948 | continue; |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 949 | const std::string& id = (*extension)->id(); |
| 950 | if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id)) |
| 951 | DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION); |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 955 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 956 | const Extension* extension) { |
| 957 | GrantPermissions(extension); |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 958 | RecordPermissionMessagesHistogram(extension, |
| 959 | "Extensions.Permissions_ReEnable2"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 960 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 961 | EnableExtension(extension->id()); |
| 962 | } |
| 963 | |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 964 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 965 | CHECK(extension); |
| 966 | extensions::PermissionsUpdater perms_updater(profile()); |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 967 | perms_updater.GrantActivePermissions(extension); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 968 | } |
| 969 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 970 | // static |
| 971 | void ExtensionService::RecordPermissionMessagesHistogram( |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 972 | const Extension* extension, const char* histogram) { |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 973 | // Since this is called from multiple sources, and since the histogram macros |
| 974 | // use statics, we need to manually lookup the histogram ourselves. |
| 975 | base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 976 | histogram, |
| 977 | 1, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 978 | PermissionMessage::kEnumBoundary, |
| 979 | PermissionMessage::kEnumBoundary + 1, |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 980 | base::HistogramBase::kUmaTargetedHistogramFlag); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 981 | |
[email protected] | a6910e7 | 2014-06-06 05:04:36 | [diff] [blame] | 982 | PermissionMessages permissions = |
| 983 | extension->permissions_data()->GetPermissionMessages(); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 984 | if (permissions.empty()) { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 985 | counter->Add(PermissionMessage::kNone); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 986 | } else { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 987 | for (PermissionMessages::iterator it = permissions.begin(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 988 | it != permissions.end(); ++it) |
| 989 | counter->Add(it->id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 993 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 994 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 995 | // was loaded, otherwise a race can arise where a renderer that is created |
| 996 | // for the extension may try to load an extension URL with an extension id |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 997 | // that the request context doesn't yet know about. The profile is responsible |
| 998 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 999 | // extension. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1000 | system_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1001 | |
[email protected] | d594931 | 2012-12-03 22:13:30 | [diff] [blame] | 1002 | // Tell renderers about the new extension, unless it's a theme (renderers |
| 1003 | // don't need to know about themes). |
[email protected] | a58f599c | 2012-12-01 03:08:19 | [diff] [blame] | 1004 | if (!extension->is_theme()) { |
[email protected] | 1964726 | 2011-12-16 09:57:49 | [diff] [blame] | 1005 | for (content::RenderProcessHost::iterator i( |
| 1006 | content::RenderProcessHost::AllHostsIterator()); |
| 1007 | !i.IsAtEnd(); i.Advance()) { |
| 1008 | content::RenderProcessHost* host = i.GetCurrentValue(); |
| 1009 | Profile* host_profile = |
| 1010 | Profile::FromBrowserContext(host->GetBrowserContext()); |
| 1011 | if (host_profile->GetOriginalProfile() == |
| 1012 | profile_->GetOriginalProfile()) { |
| 1013 | std::vector<ExtensionMsg_Loaded_Params> loaded_extensions( |
| 1014 | 1, ExtensionMsg_Loaded_Params(extension)); |
| 1015 | host->Send( |
| 1016 | new ExtensionMsg_Loaded(loaded_extensions)); |
| 1017 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1018 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1019 | } |
| 1020 | |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 1021 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 1022 | // extension. |
| 1023 | // |
| 1024 | // NOTE: It is important that this happen after notifying the renderers about |
| 1025 | // the new extensions so that if we navigate to an extension URL in |
[email protected] | fdc7619 | 2014-04-20 21:54:41 | [diff] [blame] | 1026 | // ExtensionRegistryObserver::OnLoaded or |
| 1027 | // NOTIFICATION_EXTENSION_LOADED_DEPRECATED, the |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1028 | // renderer is guaranteed to know about it. |
| 1029 | registry_->TriggerOnLoaded(extension); |
| 1030 | |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 1031 | content::NotificationService::current()->Notify( |
[email protected] | fdc7619 | 2014-04-20 21:54:41 | [diff] [blame] | 1032 | chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 1033 | content::Source<Profile>(profile_), |
| 1034 | content::Details<const Extension>(extension)); |
| 1035 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1036 | // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 1037 | // BrowserContextKeyedService and use ExtensionRegistryObserver. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1038 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1039 | GrantRightsForExtension(extension); |
| 1040 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1041 | // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 1042 | // work properly multi-profile. Besides which, it should be using |
| 1043 | // ExtensionRegistryObserver. See http://crbug.com/355029. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1044 | UpdateActiveExtensionsInCrashReporter(); |
| 1045 | |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1046 | const extensions::PermissionsData* permissions_data = |
[email protected] | a6910e7 | 2014-06-06 05:04:36 | [diff] [blame] | 1047 | extension->permissions_data(); |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1048 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1049 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1050 | // to make sure that the FaviconSource is registered with the |
| 1051 | // ChromeURLDataManager. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1052 | if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1053 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1054 | FaviconSource::FAVICON); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1055 | content::URLDataSource::Add(profile_, favicon_source); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1056 | } |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1057 | |
| 1058 | #if !defined(OS_ANDROID) |
| 1059 | // Same for chrome://theme/ resources. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1060 | if (permissions_data->HasHostPermission(GURL(chrome::kChromeUIThemeURL))) { |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1061 | ThemeSource* theme_source = new ThemeSource(profile_); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1062 | content::URLDataSource::Add(profile_, theme_source); |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1063 | } |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1064 | |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1065 | // Same for chrome://thumb/ resources. |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1066 | if (permissions_data->HasHostPermission( |
| 1067 | GURL(chrome::kChromeUIThumbnailURL))) { |
[email protected] | 420e6d9 | 2013-09-17 01:48:51 | [diff] [blame] | 1068 | ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1069 | content::URLDataSource::Add(profile_, thumbnail_source); |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1070 | } |
[email protected] | 54b25a8 | 2014-04-30 21:47:05 | [diff] [blame] | 1071 | #endif |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1072 | } |
| 1073 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1074 | void ExtensionService::NotifyExtensionUnloaded( |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1075 | const Extension* extension, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1076 | UnloadedExtensionInfo::Reason reason) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1077 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | e51232f3 | 2014-04-18 20:05:36 | [diff] [blame] | 1078 | |
| 1079 | registry_->TriggerOnUnloaded(extension, reason); |
| 1080 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1081 | content::NotificationService::current()->Notify( |
[email protected] | ec87053 | 2014-03-19 20:24:05 | [diff] [blame] | 1082 | chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1083 | content::Source<Profile>(profile_), |
| 1084 | content::Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1085 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1086 | for (content::RenderProcessHost::iterator i( |
| 1087 | content::RenderProcessHost::AllHostsIterator()); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1088 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1089 | content::RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1090 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1091 | Profile::FromBrowserContext(host->GetBrowserContext()); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1092 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1093 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1094 | } |
| 1095 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1096 | system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1097 | |
| 1098 | // TODO(kalman): Convert ExtensionSpecialStoragePolicy to a |
| 1099 | // BrowserContextKeyedService and use ExtensionRegistryObserver. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1100 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1101 | RevokeRightsForExtension(extension); |
| 1102 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1103 | #if defined(OS_CHROMEOS) |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 1104 | // Revoke external file access for the extension from its file system context. |
| 1105 | // It is safe to access the extension's storage partition at this point. The |
| 1106 | // storage partition may get destroyed only after the extension gets unloaded. |
[email protected] | 3a746ec | 2014-03-15 05:30:56 | [diff] [blame] | 1107 | GURL site = |
| 1108 | extensions::util::GetSiteForExtensionId(extension->id(), profile_); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 1109 | fileapi::FileSystemContext* filesystem_context = |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 1110 | BrowserContext::GetStoragePartitionForSite(profile_, site)-> |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 1111 | GetFileSystemContext(); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 1112 | if (filesystem_context && filesystem_context->external_backend()) { |
| 1113 | filesystem_context->external_backend()-> |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1114 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1115 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1116 | #endif |
| 1117 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1118 | // TODO(kalman): This is broken. The crash reporter is process-wide so doesn't |
| 1119 | // work properly multi-profile. Besides which, it should be using |
| 1120 | // ExtensionRegistryObserver::OnExtensionLoaded. See http://crbug.com/355029. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1121 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1122 | } |
| 1123 | |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1124 | content::BrowserContext* ExtensionService::GetBrowserContext() const { |
| 1125 | // Implemented in the .cc file to avoid adding a profile.h dependency to |
| 1126 | // extension_service.h. |
| 1127 | return profile_; |
| 1128 | } |
| 1129 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1130 | bool ExtensionService::is_ready() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1131 | return ready_->is_signaled(); |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1132 | } |
| 1133 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1134 | base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1135 | if (file_task_runner_.get()) |
| 1136 | return file_task_runner_.get(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1137 | |
| 1138 | // We should be able to interrupt any part of extension install process during |
| 1139 | // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks |
| 1140 | // will be ignored/deleted while we will block on started tasks. |
| 1141 | std::string token("ext_install-"); |
| 1142 | token.append(profile_->GetPath().AsUTF8Unsafe()); |
| 1143 | file_task_runner_ = BrowserThread::GetBlockingPool()-> |
| 1144 | GetSequencedTaskRunnerWithShutdownBehavior( |
| 1145 | BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), |
| 1146 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1147 | return file_task_runner_.get(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1148 | } |
| 1149 | |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 1150 | void ExtensionService::CheckManagementPolicy() { |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1151 | std::vector<std::string> to_unload; |
| 1152 | std::map<std::string, Extension::DisableReason> to_disable; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1153 | |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1154 | // Loop through the extensions list, finding extensions we need to unload or |
| 1155 | // disable. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1156 | const ExtensionSet& extensions = registry_->enabled_extensions(); |
| 1157 | for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 1158 | iter != extensions.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1159 | const Extension* extension = (iter->get()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 1160 | if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1161 | to_unload.push_back(extension->id()); |
| 1162 | Extension::DisableReason disable_reason = Extension::DISABLE_NONE; |
| 1163 | if (system_->management_policy()->MustRemainDisabled( |
| 1164 | extension, &disable_reason, NULL)) |
| 1165 | to_disable[extension->id()] = disable_reason; |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | 0d54b68 | 2013-11-05 14:15:36 | [diff] [blame] | 1168 | for (size_t i = 0; i < to_unload.size(); ++i) |
| 1169 | UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); |
| 1170 | |
| 1171 | for (std::map<std::string, Extension::DisableReason>::const_iterator i = |
| 1172 | to_disable.begin(); i != to_disable.end(); ++i) |
| 1173 | DisableExtension(i->first, i->second); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1174 | } |
| 1175 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1176 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1177 | // This can legitimately happen in unit tests. |
| 1178 | if (!updater_.get()) |
| 1179 | return; |
| 1180 | |
| 1181 | if (AreAllExternalProvidersReady()) { |
| 1182 | updater_->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1183 | } else { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1184 | // Sync can start updating before all the external providers are ready |
| 1185 | // during startup. Start the update as soon as those providers are ready, |
| 1186 | // but not before. |
| 1187 | update_once_all_providers_are_ready_ = true; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1188 | } |
| 1189 | } |
| 1190 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1191 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 1192 | // are typically part of some larger client application package. To support |
| 1193 | // these, the extension will register its location in the the preferences file |
| 1194 | // (and also, on Windows, in the registry) and this code will periodically |
| 1195 | // check that location for a .crx file, which it will then install locally if |
| 1196 | // a new version is available. |
| 1197 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 1198 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1199 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1200 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1201 | |
| 1202 | // Note that this installation is intentionally silent (since it didn't |
| 1203 | // go through the front-end). Extensions that are registered in this |
| 1204 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1205 | // trusted. In general, if something has HKLM or filesystem access, |
| 1206 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1207 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1208 | // Ask each external extension provider to give us a call back for each |
| 1209 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1210 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1211 | for (i = external_extension_providers_.begin(); |
| 1212 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1213 | extensions::ExternalProviderInterface* provider = i->get(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1214 | provider->VisitRegisteredExtension(); |
| 1215 | } |
| 1216 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1217 | // Do any required work that we would have done after completion of all |
| 1218 | // providers. |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 1219 | if (external_extension_providers_.empty()) |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1220 | OnAllExternalProvidersReady(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1221 | } |
| 1222 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1223 | void ExtensionService::OnExternalProviderReady( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1224 | const extensions::ExternalProviderInterface* provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1225 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1226 | CHECK(provider->IsReady()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1227 | |
| 1228 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1229 | // if all of them are finished. So we check them first. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1230 | if (AreAllExternalProvidersReady()) |
| 1231 | OnAllExternalProvidersReady(); |
| 1232 | } |
| 1233 | |
| 1234 | bool ExtensionService::AreAllExternalProvidersReady() const { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1235 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1236 | for (i = external_extension_providers_.begin(); |
| 1237 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1238 | if (!i->get()->IsReady()) |
| 1239 | return false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1240 | } |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1241 | return true; |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | void ExtensionService::OnAllExternalProvidersReady() { |
| 1245 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1246 | base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime(); |
| 1247 | UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1248 | |
| 1249 | // Install any pending extensions. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1250 | if (update_once_all_providers_are_ready_ && updater()) { |
| 1251 | update_once_all_providers_are_ready_ = false; |
[email protected] | 4e9b59d | 2013-12-18 06:47:14 | [diff] [blame] | 1252 | extensions::ExtensionUpdater::CheckParams params; |
| 1253 | params.callback = external_updates_finished_callback_; |
| 1254 | updater()->CheckNow(params); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | // Uninstall all the unclaimed extensions. |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 1258 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1259 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1260 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1261 | ExtensionInfo* info = extensions_info->at(i).get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1262 | if (Manifest::IsExternalLocation(info->extension_location)) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1263 | CheckExternalUninstall(info->extension_id); |
| 1264 | } |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1265 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 1266 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1267 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1268 | UpdateExternalExtensionAlert(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1269 | } |
| 1270 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1271 | void ExtensionService::AcknowledgeExternalExtension(const std::string& id) { |
| 1272 | extension_prefs_->AcknowledgeExternalExtension(id); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1273 | UpdateExternalExtensionAlert(); |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1274 | } |
| 1275 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1276 | bool ExtensionService::IsUnacknowledgedExternalExtension( |
| 1277 | const Extension* extension) { |
[email protected] | b82d18da | 2012-11-09 00:11:32 | [diff] [blame] | 1278 | if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
| 1279 | return false; |
| 1280 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1281 | return (Manifest::IsExternalLocation(extension->location()) && |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1282 | !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) && |
| 1283 | !(extension_prefs_->GetDisableReasons(extension->id()) & |
| 1284 | Extension::DISABLE_SIDELOAD_WIPEOUT)); |
| 1285 | } |
| 1286 | |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 1287 | void ExtensionService::ReconcileKnownDisabled() { |
[email protected] | 60a8bc96 | 2013-12-03 03:17:27 | [diff] [blame] | 1288 | ExtensionIdSet known_disabled_ids; |
| 1289 | if (!extension_prefs_->GetKnownDisabled(&known_disabled_ids)) { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1290 | extension_prefs_->SetKnownDisabled( |
| 1291 | registry_->disabled_extensions().GetIDs()); |
[email protected] | 018a568 | 2013-11-20 02:41:21 | [diff] [blame] | 1292 | UMA_HISTOGRAM_BOOLEAN("Extensions.KnownDisabledInitialized", true); |
| 1293 | return; |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 1294 | } |
[email protected] | 195c158 | 2013-10-29 18:42:23 | [diff] [blame] | 1295 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1296 | // Both |known_disabled_ids| and |extensions| are ordered (by definition |
[email protected] | 018a568 | 2013-11-20 02:41:21 | [diff] [blame] | 1297 | // of std::map and std::set). Iterate forward over both sets in parallel |
| 1298 | // to find matching IDs and disable the corresponding extensions. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1299 | const ExtensionSet& enabled_set = registry_->enabled_extensions(); |
| 1300 | ExtensionSet::const_iterator extensions_it = enabled_set.begin(); |
[email protected] | 018a568 | 2013-11-20 02:41:21 | [diff] [blame] | 1301 | ExtensionIdSet::const_iterator known_disabled_ids_it = |
| 1302 | known_disabled_ids.begin(); |
| 1303 | int known_disabled_count = 0; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1304 | while (extensions_it != enabled_set.end() && |
[email protected] | 018a568 | 2013-11-20 02:41:21 | [diff] [blame] | 1305 | known_disabled_ids_it != known_disabled_ids.end()) { |
| 1306 | const std::string& extension_id = extensions_it->get()->id(); |
| 1307 | const int comparison = extension_id.compare(*known_disabled_ids_it); |
| 1308 | if (comparison < 0) { |
| 1309 | ++extensions_it; |
| 1310 | } else if (comparison > 0) { |
| 1311 | ++known_disabled_ids_it; |
| 1312 | } else { |
| 1313 | ++known_disabled_count; |
| 1314 | // Advance |extensions_it| immediately as it will be invalidated upon |
| 1315 | // disabling the extension it points to. |
| 1316 | ++extensions_it; |
| 1317 | ++known_disabled_ids_it; |
| 1318 | DisableExtension(extension_id, Extension::DISABLE_KNOWN_DISABLED); |
| 1319 | } |
| 1320 | } |
| 1321 | UMA_HISTOGRAM_COUNTS_100("Extensions.KnownDisabledReDisabled", |
| 1322 | known_disabled_count); |
| 1323 | |
[email protected] | 195c158 | 2013-10-29 18:42:23 | [diff] [blame] | 1324 | // Update the list of known disabled to reflect every change to |
| 1325 | // |disabled_extensions_| from this point forward. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1326 | registry_->SetDisabledModificationCallback( |
[email protected] | 195c158 | 2013-10-29 18:42:23 | [diff] [blame] | 1327 | base::Bind(&extensions::ExtensionPrefs::SetKnownDisabled, |
| 1328 | base::Unretained(extension_prefs_))); |
[email protected] | 59ee99d | 2013-10-11 15:46:16 | [diff] [blame] | 1329 | } |
| 1330 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1331 | void ExtensionService::UpdateExternalExtensionAlert() { |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 1332 | if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1333 | return; |
| 1334 | |
| 1335 | const Extension* extension = NULL; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1336 | const ExtensionSet& disabled_extensions = registry_->disabled_extensions(); |
| 1337 | for (ExtensionSet::const_iterator iter = disabled_extensions.begin(); |
| 1338 | iter != disabled_extensions.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1339 | const Extension* e = iter->get(); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1340 | if (IsUnacknowledgedExternalExtension(e)) { |
| 1341 | extension = e; |
| 1342 | break; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | if (extension) { |
[email protected] | e5d6b471 | 2014-06-04 20:07:23 | [diff] [blame] | 1347 | if (!extensions::HasExternalInstallError(this)) { |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1348 | if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) > |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1349 | kMaxExtensionAcknowledgePromptCount) { |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1350 | // Stop prompting for this extension, and check if there's another |
| 1351 | // one that needs prompting. |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1352 | extension_prefs_->AcknowledgeExternalExtension(extension->id()); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1353 | UpdateExternalExtensionAlert(); |
| 1354 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 1355 | EXTERNAL_EXTENSION_IGNORED, |
| 1356 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 1357 | if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
| 1358 | UMA_HISTOGRAM_ENUMERATION( |
| 1359 | "Extensions.ExternalExtensionEventWebstore", |
| 1360 | EXTERNAL_EXTENSION_IGNORED, |
| 1361 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 1362 | } else { |
| 1363 | UMA_HISTOGRAM_ENUMERATION( |
| 1364 | "Extensions.ExternalExtensionEventNonWebstore", |
| 1365 | EXTERNAL_EXTENSION_IGNORED, |
| 1366 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 1367 | } |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1368 | return; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1369 | } |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 1370 | if (is_first_run_) |
| 1371 | extension_prefs_->SetExternalInstallFirstRun(extension->id()); |
| 1372 | // first_run is true if the extension was installed during a first run |
| 1373 | // (even if it's post-first run now). |
| 1374 | bool first_run = extension_prefs_->IsExternalInstallFirstRun( |
| 1375 | extension->id()); |
[email protected] | e5d6b471 | 2014-06-04 20:07:23 | [diff] [blame] | 1376 | extensions::AddExternalInstallError(this, extension, first_run); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1377 | } |
[email protected] | e5d6b471 | 2014-06-04 20:07:23 | [diff] [blame] | 1378 | } else { |
| 1379 | extensions::RemoveExternalInstallError(this); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1380 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1381 | } |
| 1382 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1383 | void ExtensionService::UnloadExtension( |
| 1384 | const std::string& extension_id, |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1385 | UnloadedExtensionInfo::Reason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 1386 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1387 | int include_mask = |
| 1388 | ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::TERMINATED; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1389 | scoped_refptr<const Extension> extension( |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 1390 | registry_->GetExtensionById(extension_id, include_mask)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1391 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1392 | // This method can be called via PostTask, so the extension may have been |
| 1393 | // unloaded by the time this runs. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1394 | if (!extension.get()) { |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1395 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 1396 | // clean up its RequestContexts. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1397 | system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1398 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1399 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1400 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1401 | // Keep information about the extension so that we can reload it later |
| 1402 | // even if it's not permanently installed. |
| 1403 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1404 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1405 | // Clean up if the extension is meant to be enabled after a reload. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1406 | reloading_extensions_.erase(extension->id()); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1407 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1408 | if (registry_->disabled_extensions().Contains(extension->id())) { |
| 1409 | registry_->RemoveDisabled(extension->id()); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1410 | // Make sure the profile cleans up its RequestContexts when an already |
| 1411 | // disabled extension is unloaded (since they are also tracking the disabled |
| 1412 | // extensions). |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1413 | system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 1414 | // Don't send the unloaded notification. It was sent when the extension |
| 1415 | // was disabled. |
[email protected] | 60a174a | 2013-08-02 20:29:28 | [diff] [blame] | 1416 | } else { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1417 | // Remove the extension from the enabled list. |
| 1418 | registry_->RemoveEnabled(extension->id()); |
[email protected] | 60a174a | 2013-08-02 20:29:28 | [diff] [blame] | 1419 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1420 | } |
| 1421 | |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 1422 | content::NotificationService::current()->Notify( |
| 1423 | chrome::NOTIFICATION_EXTENSION_REMOVED, |
| 1424 | content::Source<Profile>(profile_), |
| 1425 | content::Details<const Extension>(extension.get())); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1426 | } |
| 1427 | |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1428 | void ExtensionService::RemoveComponentExtension( |
| 1429 | const std::string& extension_id) { |
| 1430 | scoped_refptr<const Extension> extension( |
| 1431 | GetExtensionById(extension_id, false)); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1432 | UnloadExtension(extension_id, UnloadedExtensionInfo::REASON_UNINSTALL); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1433 | if (extension.get()) { |
| 1434 | content::NotificationService::current()->Notify( |
[email protected] | bbf8d30b | 2014-05-29 16:45:07 | [diff] [blame] | 1435 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1436 | content::Source<Profile>(profile_), |
| 1437 | content::Details<const Extension>(extension.get())); |
[email protected] | 1d7f248 | 2014-05-24 00:11:51 | [diff] [blame] | 1438 | ExtensionRegistry::Get(profile_)->TriggerOnUninstalled(extension.get()); |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 1439 | } |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1440 | } |
| 1441 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1442 | void ExtensionService::UnloadAllExtensionsForTest() { |
| 1443 | UnloadAllExtensionsInternal(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1444 | } |
| 1445 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1446 | void ExtensionService::ReloadExtensionsForTest() { |
| 1447 | // Calling UnloadAllExtensionsForTest here triggers a false-positive presubmit |
| 1448 | // warning about calling test code in production. |
| 1449 | UnloadAllExtensionsInternal(); |
[email protected] | eac8833 | 2012-12-26 17:57:45 | [diff] [blame] | 1450 | component_loader_->LoadAll(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 1451 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1452 | // Don't call SetReadyAndNotifyListeners() since tests call this multiple |
| 1453 | // times. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1454 | } |
| 1455 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1456 | void ExtensionService::SetReadyAndNotifyListeners() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1457 | ready_->Signal(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 1458 | content::NotificationService::current()->Notify( |
| 1459 | chrome::NOTIFICATION_EXTENSIONS_READY, |
| 1460 | content::Source<Profile>(profile_), |
| 1461 | content::NotificationService::NoDetails()); |
| 1462 | } |
| 1463 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1464 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 1465 | if (updater_) |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 1466 | updater_->Start(); |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 1467 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 1468 | OnBlacklistUpdated(); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1469 | } |
| 1470 | |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1471 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1472 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 1473 | // default extension state to DISABLED when the --disable-extensions flag |
| 1474 | // is set (http://crbug.com/29067). |
| 1475 | if (!extensions_enabled() && |
| 1476 | !extension->is_theme() && |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1477 | extension->location() != Manifest::COMPONENT && |
| 1478 | !Manifest::IsExternalLocation(extension->location())) { |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1479 | return; |
[email protected] | 330840c | 2012-08-29 22:21:01 | [diff] [blame] | 1480 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1481 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1482 | bool is_extension_upgrade = false; |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1483 | bool is_extension_installed = false; |
| 1484 | const Extension* old = GetInstalledExtension(extension->id()); |
| 1485 | if (old) { |
| 1486 | is_extension_installed = true; |
| 1487 | int version_compare_result = |
| 1488 | extension->version()->CompareTo(*(old->version())); |
| 1489 | is_extension_upgrade = version_compare_result > 0; |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1490 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 1491 | // that we aren't downgrading. |
| 1492 | if (!Manifest::IsUnpackedLocation(extension->location())) |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1493 | CHECK_GE(version_compare_result, 0); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1494 | } |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 1495 | system_->runtime_data()->SetBeingUpgraded(extension, is_extension_upgrade); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1496 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1497 | // The extension is now loaded, remove its data from unloaded extension map. |
| 1498 | unloaded_extension_paths_.erase(extension->id()); |
| 1499 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1500 | // If a terminated extension is loaded, remove it from the terminated list. |
| 1501 | UntrackTerminatedExtension(extension->id()); |
| 1502 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1503 | // If the extension was disabled for a reload, then enable it. |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1504 | bool reloading = reloading_extensions_.erase(extension->id()) > 0; |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1505 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1506 | // Check if the extension's privileges have changed and mark the |
| 1507 | // extension disabled if necessary. |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1508 | CheckPermissionsIncrease(extension, is_extension_installed); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1509 | |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1510 | if (is_extension_installed && !reloading) { |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1511 | // To upgrade an extension in place, unload the old one and then load the |
| 1512 | // new one. ReloadExtension disables the extension, which is sufficient. |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 1513 | UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_UPDATE); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1514 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1515 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1516 | if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 1517 | // Only prefs is checked for the blacklist. We rely on callers to check the |
| 1518 | // blacklist before calling into here, e.g. CrxInstaller checks before |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1519 | // installation then threads through the install and pending install flow |
| 1520 | // of this class, and we check when loading installed extensions. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1521 | registry_->AddBlacklisted(extension); |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1522 | } else if (!reloading && |
| 1523 | extension_prefs_->IsExtensionDisabled(extension->id())) { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1524 | registry_->AddDisabled(extension); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 1525 | if (extension_sync_service_) |
| 1526 | extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1527 | content::NotificationService::current()->Notify( |
| 1528 | chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 1529 | content::Source<Profile>(profile_), |
| 1530 | content::Details<const Extension>(extension)); |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 1531 | |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 1532 | // Show the extension disabled error if a permissions increase or a remote |
| 1533 | // installation is the reason it was disabled, and no other reasons exist. |
| 1534 | int reasons = extension_prefs_->GetDisableReasons(extension->id()); |
| 1535 | const int kReasonMask = Extension::DISABLE_PERMISSIONS_INCREASE | |
| 1536 | Extension::DISABLE_REMOTE_INSTALL; |
| 1537 | if (reasons & kReasonMask && !(reasons & ~kReasonMask)) { |
| 1538 | extensions::AddExtensionDisabledError( |
| 1539 | this, |
| 1540 | extension, |
| 1541 | extension_prefs_->HasDisableReason( |
| 1542 | extension->id(), Extension::DISABLE_REMOTE_INSTALL)); |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 1543 | } |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1544 | } else if (reloading) { |
| 1545 | // Replace the old extension with the new version. |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1546 | CHECK(!registry_->AddDisabled(extension)); |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 1547 | EnableExtension(extension->id()); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1548 | } else { |
| 1549 | // All apps that are displayed in the launcher are ordered by their ordinals |
| 1550 | // so we must ensure they have valid ordinals. |
| 1551 | if (extension->RequiresSortOrdinal()) { |
[email protected] | bd36b65 | 2013-02-27 02:13:25 | [diff] [blame] | 1552 | if (!extension->ShouldDisplayInNewTabPage()) { |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 1553 | extension_prefs_->app_sorting()->MarkExtensionAsHidden(extension->id()); |
[email protected] | bd36b65 | 2013-02-27 02:13:25 | [diff] [blame] | 1554 | } |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 1555 | extension_prefs_->app_sorting()->EnsureValidOrdinals( |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1556 | extension->id(), syncer::StringOrdinal()); |
| 1557 | } |
| 1558 | |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1559 | registry_->AddEnabled(extension); |
[email protected] | f8aefb13 | 2013-10-30 09:29:52 | [diff] [blame] | 1560 | if (extension_sync_service_) |
| 1561 | extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1562 | NotifyExtensionLoaded(extension); |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 1563 | } |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 1564 | system_->runtime_data()->SetBeingUpgraded(extension, false); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1565 | } |
| 1566 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1567 | void ExtensionService::AddComponentExtension(const Extension* extension) { |
| 1568 | const std::string old_version_string( |
| 1569 | extension_prefs_->GetVersionString(extension->id())); |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 1570 | const Version old_version(old_version_string); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1571 | |
[email protected] | 0181a7d | 2013-11-12 01:08:42 | [diff] [blame] | 1572 | VLOG(1) << "AddComponentExtension " << extension->name(); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1573 | if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
| 1574 | VLOG(1) << "Component extension " << extension->name() << " (" |
| 1575 | << extension->id() << ") installing/upgrading from '" |
| 1576 | << old_version_string << "' to " << extension->version()->GetString(); |
| 1577 | |
| 1578 | AddNewOrUpdatedExtension(extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1579 | Extension::ENABLED_COMPONENT, |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 1580 | extensions::NOT_BLACKLISTED, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1581 | false, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1582 | syncer::StringOrdinal(), |
| 1583 | std::string()); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1584 | return; |
| 1585 | } |
| 1586 | |
| 1587 | AddExtension(extension); |
| 1588 | } |
| 1589 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1590 | void ExtensionService::UpdateActivePermissions(const Extension* extension) { |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1591 | // If the extension has used the optional permissions API, it will have a |
| 1592 | // custom set of active permissions defined in the extension prefs. Here, |
| 1593 | // we update the extension's active permissions based on the prefs. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1594 | scoped_refptr<PermissionSet> active_permissions = |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 1595 | extension_prefs_->GetActivePermissions(extension->id()); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1596 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1597 | if (active_permissions.get()) { |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1598 | // We restrict the active permissions to be within the bounds defined in the |
| 1599 | // extension's manifest. |
| 1600 | // a) active permissions must be a subset of optional + default permissions |
| 1601 | // b) active permissions must contains all default permissions |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1602 | scoped_refptr<PermissionSet> total_permissions = PermissionSet::CreateUnion( |
| 1603 | extensions::PermissionsParser::GetRequiredPermissions(extension), |
| 1604 | extensions::PermissionsParser::GetOptionalPermissions(extension)); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1605 | |
| 1606 | // Make sure the active permissions contain no more than optional + default. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1607 | scoped_refptr<PermissionSet> adjusted_active = |
| 1608 | PermissionSet::CreateIntersection( |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1609 | total_permissions.get(), active_permissions.get()); |
| 1610 | |
| 1611 | // Make sure the active permissions contain the default permissions. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1612 | adjusted_active = PermissionSet::CreateUnion( |
[email protected] | d695bb1 | 2014-06-05 16:16:30 | [diff] [blame] | 1613 | extensions::PermissionsParser::GetRequiredPermissions(extension), |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 1614 | adjusted_active.get()); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1615 | |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 1616 | extensions::PermissionsUpdater perms_updater(profile()); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1617 | perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1618 | } |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1622 | bool is_extension_installed) { |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1623 | UpdateActivePermissions(extension); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1624 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1625 | // We keep track of all permissions the user has granted each extension. |
| 1626 | // This allows extensions to gracefully support backwards compatibility |
| 1627 | // by including unknown permissions in their manifests. When the user |
| 1628 | // installs the extension, only the recognized permissions are recorded. |
| 1629 | // When the unknown permissions become recognized (e.g., through browser |
| 1630 | // upgrade), we can prompt the user to accept these new permissions. |
| 1631 | // Extensions can also silently upgrade to less permissions, and then |
| 1632 | // silently upgrade to a version that adds these permissions back. |
| 1633 | // |
| 1634 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 1635 | // for an API that adds suggestions to the omnibox. An extension can |
| 1636 | // maintain backwards compatibility while still having "omnibox" in the |
| 1637 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 1638 | // will record the permissions it recognized, not including "omnibox." |
| 1639 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 1640 | // will disable the extension and prompt the user to approve the increase |
| 1641 | // in privileges. The extension could then release a new version that |
| 1642 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 1643 | // still remember that "omnibox" had been granted, so that if the |
| 1644 | // extension once again includes "omnibox" in an upgrade, the extension |
| 1645 | // can upgrade without requiring this user's approval. |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 1646 | int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1647 | |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1648 | bool auto_grant_permission = |
[email protected] | 1b563df | 2013-10-30 16:49:36 | [diff] [blame] | 1649 | (!is_extension_installed && extension->was_installed_by_default()) || |
[email protected] | 45928b68 | 2013-11-28 08:20:27 | [diff] [blame] | 1650 | extensions::ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode(); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1651 | // Silently grant all active permissions to default apps only on install. |
| 1652 | // After install they should behave like other apps. |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1653 | // Silently grant all active permissions to apps install in kiosk mode on both |
| 1654 | // install and update. |
| 1655 | if (auto_grant_permission) |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1656 | GrantPermissions(extension); |
| 1657 | |
| 1658 | bool is_privilege_increase = false; |
| 1659 | // We only need to compare the granted permissions to the current permissions |
| 1660 | // if the extension is not allowed to silently increase its permissions. |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1661 | if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) && |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 1662 | !auto_grant_permission) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1663 | // Add all the recognized permissions if the granted permissions list |
| 1664 | // hasn't been initialized yet. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1665 | scoped_refptr<PermissionSet> granted_permissions = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1666 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1667 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1668 | |
| 1669 | // Here, we check if an extension's privileges have increased in a manner |
| 1670 | // that requires the user's approval. This could occur because the browser |
| 1671 | // upgraded and recognized additional privileges, or an extension upgrades |
| 1672 | // to a version that requires additional privileges. |
[email protected] | c4100347 | 2013-10-19 15:37:25 | [diff] [blame] | 1673 | is_privilege_increase = |
| 1674 | extensions::PermissionMessageProvider::Get()->IsPrivilegeIncrease( |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame^] | 1675 | granted_permissions, |
| 1676 | extension->permissions_data()->active_permissions().get(), |
| 1677 | extension->GetType()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1678 | } |
| 1679 | |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 1680 | if (is_extension_installed) { |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1681 | // If the extension was already disabled, suppress any alerts for becoming |
| 1682 | // disabled on permissions increase. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1683 | bool previously_disabled = |
| 1684 | extension_prefs_->IsExtensionDisabled(extension->id()); |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1685 | // Legacy disabled extensions do not have a disable reason. Infer that if |
| 1686 | // there was no permission increase, it was likely disabled by the user. |
| 1687 | if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1688 | !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1689 | disable_reasons |= Extension::DISABLE_USER_ACTION; |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 1690 | } |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1691 | // Extensions that came to us disabled from sync need a similar inference, |
| 1692 | // except based on the new version's permissions. |
| 1693 | if (previously_disabled && |
| 1694 | disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) { |
| 1695 | // Remove the DISABLE_UNKNOWN_FROM_SYNC reason. |
| 1696 | extension_prefs_->ClearDisableReasons(extension->id()); |
| 1697 | if (!is_privilege_increase) |
| 1698 | disable_reasons |= Extension::DISABLE_USER_ACTION; |
| 1699 | } |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1700 | disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | // Extension has changed permissions significantly. Disable it. A |
[email protected] | 21db9ef | 2014-05-16 02:06:27 | [diff] [blame] | 1704 | // notification should be sent by the caller. If the extension is already |
| 1705 | // disabled because it was installed remotely, don't add another disable |
| 1706 | // reason, but instead always set the "did escalate permissions" flag, to |
| 1707 | // ensure enabling it will always show a warning. |
| 1708 | if (disable_reasons == Extension::DISABLE_REMOTE_INSTALL) { |
| 1709 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 1710 | } else if (is_privilege_increase) { |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1711 | disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1712 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 1713 | RecordPermissionMessagesHistogram(extension, |
| 1714 | "Extensions.Permissions_AutoDisable2"); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1715 | } |
[email protected] | 195c158 | 2013-10-29 18:42:23 | [diff] [blame] | 1716 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1717 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1718 | } |
| 1719 | if (disable_reasons != Extension::DISABLE_NONE) { |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 1720 | extension_prefs_->AddDisableReason( |
| 1721 | extension->id(), |
| 1722 | static_cast<Extension::DisableReason>(disable_reasons)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1723 | } |
| 1724 | } |
| 1725 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1726 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 1727 | std::set<std::string> extension_ids; |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 1728 | const ExtensionSet& extensions = registry_->enabled_extensions(); |
| 1729 | for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 1730 | iter != extensions.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1731 | const Extension* extension = iter->get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1732 | if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1733 | extension_ids.insert(extension->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1734 | } |
| 1735 | |
[email protected] | dcc4764 | 2014-03-26 22:03:49 | [diff] [blame] | 1736 | // TODO(kalman): This is broken. ExtensionService is per-profile. |
| 1737 | // crash_keys::SetActiveExtensions is per-process. See |
| 1738 | // http://crbug.com/355029. |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 1739 | crash_keys::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1740 | } |
| 1741 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 1742 | void ExtensionService::OnExtensionInstalled( |
[email protected] | 36a5c4c | 2011-12-14 16:34:50 | [diff] [blame] | 1743 | const Extension* extension, |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1744 | const syncer::StringOrdinal& page_ordinal, |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1745 | bool has_requirement_errors, |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 1746 | extensions::BlacklistState blacklist_state, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1747 | bool is_ephemeral, |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1748 | bool wait_for_idle) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1749 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1750 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1751 | const std::string& id = extension->id(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1752 | bool initial_enable = ShouldEnableOnInstall(extension); |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1753 | std::string install_parameter; |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 1754 | const extensions::PendingExtensionInfo* pending_extension_info = NULL; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1755 | if ((pending_extension_info = pending_extension_manager()->GetById(id))) { |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1756 | if (!pending_extension_info->ShouldAllowInstall(extension)) { |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1757 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 1758 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1759 | LOG(WARNING) << "ShouldAllowInstall() returned false for " |
| 1760 | << id << " of type " << extension->GetType() |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 1761 | << " and update URL " |
| 1762 | << extensions::ManifestURL::GetUpdateURL(extension).spec() |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1763 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 1764 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1765 | // Delete the extension directory since we're not going to |
| 1766 | // load it. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1767 | if (!GetFileTaskRunner()->PostTask( |
| 1768 | FROM_HERE, |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 1769 | base::Bind(&extensions::file_util::DeleteFile, |
| 1770 | extension->path(), |
| 1771 | true))) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1772 | NOTREACHED(); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1773 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1774 | return; |
| 1775 | } |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1776 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1777 | install_parameter = pending_extension_info->install_parameter(); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 1778 | pending_extension_manager()->Remove(id); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1779 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1780 | // We explicitly want to re-enable an uninstalled external |
| 1781 | // extension; if we're here, that means the user is manually |
| 1782 | // installing the extension. |
[email protected] | 46f3e10 | 2014-03-25 01:22:45 | [diff] [blame] | 1783 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) { |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1784 | initial_enable = true; |
| 1785 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 1786 | } |
| 1787 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 1788 | // Unsupported requirements overrides the management policy. |
| 1789 | if (has_requirement_errors) { |
| 1790 | initial_enable = false; |
| 1791 | extension_prefs_->AddDisableReason( |
| 1792 | id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| 1793 | // If the extension was disabled because of unsupported requirements but |
| 1794 | // now supports all requirements after an update and there are not other |
| 1795 | // disable reasons, enable it. |
| 1796 | } else if (extension_prefs_->GetDisableReasons(id) == |
| 1797 | Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
| 1798 | initial_enable = true; |
| 1799 | extension_prefs_->ClearDisableReasons(id); |
| 1800 | } |
| 1801 | |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 1802 | if (blacklist_state == extensions::BLACKLISTED_MALWARE) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1803 | // Installation of a blacklisted extension can happen from sync, policy, |
| 1804 | // etc, where to maintain consistency we need to install it, just never |
| 1805 | // load it (see AddExtension). Usually it should be the job of callers to |
| 1806 | // incercept blacklisted extension earlier (e.g. CrxInstaller, before even |
| 1807 | // showing the install dialogue). |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 1808 | extension_prefs_->AcknowledgeBlacklistedExtension(id); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1809 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
| 1810 | extension->location(), |
| 1811 | Manifest::NUM_LOCATIONS); |
| 1812 | } |
| 1813 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1814 | if (!GetInstalledExtension(extension->id())) { |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 1815 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 1816 | extension->GetType(), 100); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 1817 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1818 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 4c86be58 | 2014-06-04 08:39:11 | [diff] [blame] | 1819 | RecordPermissionMessagesHistogram(extension, |
| 1820 | "Extensions.Permissions_Install2"); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 1821 | } else { |
| 1822 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
| 1823 | extension->GetType(), 100); |
| 1824 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1825 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 1826 | } |
| 1827 | |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 1828 | // Certain extension locations are specific enough that we can |
| 1829 | // auto-acknowledge any extension that came from one of them. |
[email protected] | 4eef435 | 2014-02-12 02:21:36 | [diff] [blame] | 1830 | if (Manifest::IsPolicyLocation(extension->location()) || |
| 1831 | extension->location() == Manifest::EXTERNAL_COMPONENT) |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 1832 | AcknowledgeExternalExtension(extension->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1833 | const Extension::State initial_state = |
| 1834 | initial_enable ? Extension::ENABLED : Extension::DISABLED; |
[email protected] | 0f9e626 | 2013-11-05 23:49:19 | [diff] [blame] | 1835 | const bool blacklisted_for_malware = |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 1836 | blacklist_state == extensions::BLACKLISTED_MALWARE; |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 1837 | if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1838 | extension_prefs_->SetDelayedInstallInfo( |
| 1839 | extension, |
| 1840 | initial_state, |
[email protected] | 0f9e626 | 2013-11-05 23:49:19 | [diff] [blame] | 1841 | blacklisted_for_malware, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1842 | is_ephemeral, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1843 | extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1844 | page_ordinal, |
| 1845 | install_parameter); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1846 | |
| 1847 | // Transfer ownership of |extension|. |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1848 | delayed_installs_.Insert(extension); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1849 | |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 1850 | // Notify observers that app update is available. |
| 1851 | FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
[email protected] | a9aa62b31 | 2013-11-29 05:35:06 | [diff] [blame] | 1852 | OnAppUpdateAvailable(extension)); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 1853 | return; |
| 1854 | } |
| 1855 | |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1856 | extensions::SharedModuleService::ImportStatus status = |
| 1857 | shared_module_service_->SatisfyImports(extension); |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 1858 | if (installs_delayed_for_gc_) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1859 | extension_prefs_->SetDelayedInstallInfo( |
| 1860 | extension, |
| 1861 | initial_state, |
[email protected] | 0f9e626 | 2013-11-05 23:49:19 | [diff] [blame] | 1862 | blacklisted_for_malware, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1863 | is_ephemeral, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1864 | extensions::ExtensionPrefs::DELAY_REASON_GC, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1865 | page_ordinal, |
| 1866 | install_parameter); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1867 | delayed_installs_.Insert(extension); |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1868 | } else if (status != SharedModuleService::IMPORT_STATUS_OK) { |
| 1869 | if (status == SharedModuleService::IMPORT_STATUS_UNSATISFIED) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1870 | extension_prefs_->SetDelayedInstallInfo( |
| 1871 | extension, |
| 1872 | initial_state, |
[email protected] | 0f9e626 | 2013-11-05 23:49:19 | [diff] [blame] | 1873 | blacklisted_for_malware, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1874 | is_ephemeral, |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1875 | extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1876 | page_ordinal, |
| 1877 | install_parameter); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1878 | delayed_installs_.Insert(extension); |
| 1879 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1880 | } else { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1881 | AddNewOrUpdatedExtension(extension, |
| 1882 | initial_state, |
| 1883 | blacklist_state, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1884 | is_ephemeral, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1885 | page_ordinal, |
| 1886 | install_parameter); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1887 | } |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | void ExtensionService::AddNewOrUpdatedExtension( |
| 1891 | const Extension* extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1892 | Extension::State initial_state, |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 1893 | extensions::BlacklistState blacklist_state, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1894 | bool is_ephemeral, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1895 | const syncer::StringOrdinal& page_ordinal, |
| 1896 | const std::string& install_parameter) { |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 1897 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 0f9e626 | 2013-11-05 23:49:19 | [diff] [blame] | 1898 | const bool blacklisted_for_malware = |
[email protected] | 8e289f0b | 2013-12-17 17:49:07 | [diff] [blame] | 1899 | blacklist_state == extensions::BLACKLISTED_MALWARE; |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1900 | bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 1901 | extension_prefs_->OnExtensionInstalled(extension, |
| 1902 | initial_state, |
[email protected] | 0f9e626 | 2013-11-05 23:49:19 | [diff] [blame] | 1903 | blacklisted_for_malware, |
[email protected] | 411f8ae | 2014-05-22 11:12:23 | [diff] [blame] | 1904 | is_ephemeral, |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 1905 | page_ordinal, |
| 1906 | install_parameter); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 1907 | delayed_installs_.Remove(extension->id()); |
[email protected] | 913ffca9 | 2014-03-27 15:26:16 | [diff] [blame] | 1908 | if (InstallVerifier::NeedsVerification(*extension)) |
| 1909 | system_->install_verifier()->VerifyExtension(extension->id()); |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1910 | FinishInstallation(extension, was_ephemeral); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | void ExtensionService::MaybeFinishDelayedInstallation( |
| 1914 | const std::string& extension_id) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1915 | // Check if the extension already got installed. |
| 1916 | if (!delayed_installs_.Contains(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1917 | return; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1918 | extensions::ExtensionPrefs::DelayReason reason = |
| 1919 | extension_prefs_->GetDelayedInstallReason(extension_id); |
| 1920 | |
| 1921 | // Check if the extension is idle. DELAY_REASON_NONE is used for older |
| 1922 | // preferences files that will not have set this field but it was previously |
| 1923 | // only used for idle updates. |
| 1924 | if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE || |
| 1925 | reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) && |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 1926 | is_ready() && !extensions::util::IsExtensionIdle(extension_id, profile_)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1927 | return; |
| 1928 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1929 | const Extension* extension = delayed_installs_.GetByID(extension_id); |
| 1930 | if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) { |
[email protected] | 90878c5 | 2014-04-04 18:21:02 | [diff] [blame] | 1931 | extensions::SharedModuleService::ImportStatus status = |
| 1932 | shared_module_service_->SatisfyImports(extension); |
| 1933 | if (status != SharedModuleService::IMPORT_STATUS_OK) { |
| 1934 | if (status == SharedModuleService::IMPORT_STATUS_UNRECOVERABLE) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1935 | delayed_installs_.Remove(extension_id); |
| 1936 | // Make sure no version of the extension is actually installed, (i.e., |
| 1937 | // that this delayed install was not an update). |
| 1938 | CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get()); |
| 1939 | extension_prefs_->DeleteExtensionPrefs(extension_id); |
| 1940 | } |
| 1941 | return; |
| 1942 | } |
| 1943 | } |
| 1944 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1945 | FinishDelayedInstallation(extension_id); |
| 1946 | } |
| 1947 | |
| 1948 | void ExtensionService::FinishDelayedInstallation( |
| 1949 | const std::string& extension_id) { |
| 1950 | scoped_refptr<const Extension> extension( |
| 1951 | GetPendingExtensionUpdate(extension_id)); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1952 | CHECK(extension.get()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 1953 | delayed_installs_.Remove(extension_id); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1954 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1955 | bool was_ephemeral = extension_prefs_->IsEphemeralApp(extension->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1956 | if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1957 | NOTREACHED(); |
| 1958 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1959 | FinishInstallation(extension.get(), was_ephemeral); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1960 | } |
| 1961 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1962 | void ExtensionService::FinishInstallation( |
| 1963 | const Extension* extension, bool was_ephemeral) { |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 1964 | const extensions::Extension* existing_extension = |
| 1965 | GetInstalledExtension(extension->id()); |
| 1966 | bool is_update = false; |
| 1967 | std::string old_name; |
| 1968 | if (existing_extension) { |
| 1969 | is_update = true; |
| 1970 | old_name = existing_extension->name(); |
| 1971 | } |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1972 | bool from_ephemeral = |
| 1973 | was_ephemeral && !extension_prefs_->IsEphemeralApp(extension->id()); |
| 1974 | extensions::InstalledExtensionInfo details( |
| 1975 | extension, is_update, from_ephemeral, old_name); |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1976 | content::NotificationService::current()->Notify( |
[email protected] | 0403d4e | 2014-05-23 07:56:36 | [diff] [blame] | 1977 | chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1978 | content::Source<Profile>(profile_), |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 1979 | content::Details<const extensions::InstalledExtensionInfo>(&details)); |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 1980 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 1981 | ExtensionRegistry::Get(profile_)->TriggerOnWillBeInstalled( |
| 1982 | extension, is_update, from_ephemeral, old_name); |
[email protected] | 17f0782 | 2014-05-22 08:45:15 | [diff] [blame] | 1983 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1984 | bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 1985 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1986 | // Unpacked extensions default to allowing file access, but if that has been |
| 1987 | // overridden, don't reset the value. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1988 | if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 1989 | !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
| 1990 | extension_prefs_->SetAllowFileAccess(extension->id(), true); |
| 1991 | } |
| 1992 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 1993 | AddExtension(extension); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1994 | |
| 1995 | // If this is a new external extension that was disabled, alert the user |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1996 | // so he can reenable it. We do this last so that it has already been |
| 1997 | // added to our list of extensions. |
[email protected] | 3e3fafbb | 2013-08-17 13:33:16 | [diff] [blame] | 1998 | if (unacknowledged_external && !is_update) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1999 | UpdateExternalExtensionAlert(); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 2000 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 2001 | EXTERNAL_EXTENSION_INSTALLED, |
| 2002 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 2003 | if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
| 2004 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
| 2005 | EXTERNAL_EXTENSION_INSTALLED, |
| 2006 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 2007 | } else { |
| 2008 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
| 2009 | EXTERNAL_EXTENSION_INSTALLED, |
| 2010 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 2011 | } |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 2012 | } |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2013 | |
| 2014 | // Check extensions that may have been delayed only because this shared module |
| 2015 | // was not available. |
| 2016 | if (SharedModuleInfo::IsSharedModule(extension)) { |
| 2017 | MaybeFinishDelayedInstallations(); |
| 2018 | } |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 2019 | } |
| 2020 | |
[email protected] | 760f743b | 2014-05-28 13:52:02 | [diff] [blame] | 2021 | void ExtensionService::PromoteEphemeralApp( |
| 2022 | const extensions::Extension* extension, bool is_from_sync) { |
| 2023 | DCHECK(GetInstalledExtension(extension->id()) && |
| 2024 | extension_prefs_->IsEphemeralApp(extension->id())); |
| 2025 | |
| 2026 | if (!is_from_sync) { |
| 2027 | if (extension->RequiresSortOrdinal()) { |
| 2028 | // Reset the sort ordinals of the app to ensure it is added to the default |
| 2029 | // position, like newly installed apps would. |
| 2030 | extension_prefs_->app_sorting()->ClearOrdinals(extension->id()); |
| 2031 | extension_prefs_->app_sorting()->EnsureValidOrdinals( |
| 2032 | extension->id(), syncer::StringOrdinal()); |
| 2033 | } |
| 2034 | |
| 2035 | if (extension_prefs_->IsExtensionDisabled(extension->id()) && |
| 2036 | !extension_prefs_->IsExtensionBlacklisted(extension->id())) { |
| 2037 | // If the extension is not blacklisted and was disabled due to permission |
| 2038 | // increase or user action only, we can enable it because the user was |
| 2039 | // prompted. |
| 2040 | extension_prefs_->RemoveDisableReason( |
| 2041 | extension->id(), |
| 2042 | Extension::DISABLE_PERMISSIONS_INCREASE); |
| 2043 | extension_prefs_->RemoveDisableReason( |
| 2044 | extension->id(), |
| 2045 | Extension::DISABLE_USER_ACTION); |
| 2046 | if (!extension_prefs_->GetDisableReasons(extension->id())) |
| 2047 | EnableExtension(extension->id()); |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | // Remove the ephemeral flags from the preferences. |
| 2052 | extension_prefs_->OnEphemeralAppPromoted(extension->id()); |
| 2053 | |
| 2054 | // Fire install-related events to allow observers to handle the promotion |
| 2055 | // of the ephemeral app. |
| 2056 | extensions::InstalledExtensionInfo details( |
| 2057 | extension, |
| 2058 | true /* is update */, |
| 2059 | true /* from ephemeral */, |
| 2060 | extension->name() /* old name */); |
| 2061 | content::NotificationService::current()->Notify( |
| 2062 | chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
| 2063 | content::Source<Profile>(profile_), |
| 2064 | content::Details<const extensions::InstalledExtensionInfo>(&details)); |
| 2065 | |
| 2066 | registry_->TriggerOnWillBeInstalled( |
| 2067 | extension, |
| 2068 | true /* is update */, |
| 2069 | true /* from ephemeral */, |
| 2070 | extension->name() /* old name */); |
| 2071 | |
| 2072 | if (registry_->enabled_extensions().Contains(extension->id())) { |
| 2073 | content::NotificationService::current()->Notify( |
| 2074 | chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 2075 | content::Source<Profile>(profile_), |
| 2076 | content::Details<const Extension>(extension)); |
| 2077 | |
| 2078 | registry_->TriggerOnLoaded(extension); |
| 2079 | } |
| 2080 | |
| 2081 | if (!is_from_sync && extension_sync_service_) |
| 2082 | extension_sync_service_->SyncExtensionChangeIfNeeded(*extension); |
| 2083 | } |
| 2084 | |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 2085 | const Extension* ExtensionService::GetPendingExtensionUpdate( |
| 2086 | const std::string& id) const { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2087 | return delayed_installs_.GetByID(id); |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 2088 | } |
| 2089 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2090 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2091 | // No need to check for duplicates; inserting a duplicate is a no-op. |
| 2092 | registry_->AddTerminated(make_scoped_refptr(extension)); |
[email protected] | 3964e57 | 2014-02-13 21:57:41 | [diff] [blame] | 2093 | extensions_being_terminated_.erase(extension->id()); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 2094 | UnloadExtension(extension->id(), UnloadedExtensionInfo::REASON_TERMINATE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2095 | } |
| 2096 | |
[email protected] | e9d7496e | 2014-04-18 01:25:46 | [diff] [blame] | 2097 | void ExtensionService::TerminateExtension(const std::string& extension_id) { |
| 2098 | const Extension* extension = GetInstalledExtension(extension_id); |
| 2099 | TrackTerminatedExtension(extension); |
| 2100 | } |
| 2101 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2102 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2103 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2104 | const Extension* extension = |
| 2105 | registry_->terminated_extensions().GetByID(lowercase_id); |
| 2106 | registry_->RemoveTerminated(lowercase_id); |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 2107 | if (extension) { |
| 2108 | content::NotificationService::current()->Notify( |
| 2109 | chrome::NOTIFICATION_EXTENSION_REMOVED, |
| 2110 | content::Source<Profile>(profile_), |
| 2111 | content::Details<const Extension>(extension)); |
| 2112 | } |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2113 | } |
| 2114 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2115 | const Extension* ExtensionService::GetInstalledExtension( |
| 2116 | const std::string& id) const { |
[email protected] | 59953980 | 2014-01-07 23:06:00 | [diff] [blame] | 2117 | return registry_->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2118 | } |
| 2119 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2120 | bool ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2121 | const std::string& id, |
[email protected] | c5e4a222 | 2014-01-03 16:06:13 | [diff] [blame] | 2122 | const Version* version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2123 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2124 | Manifest::Location location, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 2125 | int creation_flags, |
| 2126 | bool mark_acknowledged) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 2127 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2128 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 2129 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2130 | return false; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2131 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2132 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 2133 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2134 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2135 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2136 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2137 | if (existing) { |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2138 | // The default apps will have the location set as INTERNAL. Since older |
| 2139 | // default apps are installed as EXTERNAL, we override them. However, if the |
| 2140 | // app is already installed as internal, then do the version check. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2141 | // TODO(grv) : Remove after Q1-2013. |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2142 | bool is_default_apps_migration = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2143 | (location == Manifest::INTERNAL && |
| 2144 | Manifest::IsExternalLocation(existing->location())); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2145 | |
| 2146 | if (!is_default_apps_migration) { |
| 2147 | DCHECK(version); |
| 2148 | |
| 2149 | switch (existing->version()->CompareTo(*version)) { |
| 2150 | case -1: // existing version is older, we should upgrade |
| 2151 | break; |
| 2152 | case 0: // existing version is same, do nothing |
| 2153 | return false; |
| 2154 | case 1: // existing version is newer, uh-oh |
| 2155 | LOG(WARNING) << "Found external version of extension " << id |
| 2156 | << "that is older than current version. Current version " |
| 2157 | << "is: " << existing->VersionString() << ". New " |
| 2158 | << "version is: " << version->GetString() |
| 2159 | << ". Keeping current version."; |
| 2160 | return false; |
| 2161 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2162 | } |
| 2163 | } |
| 2164 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2165 | // If the extension is already pending, don't start an install. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 2166 | if (!pending_extension_manager()->AddFromExternalFile( |
[email protected] | 464213a | 2013-10-15 01:06:48 | [diff] [blame] | 2167 | id, location, *version, creation_flags, mark_acknowledged)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2168 | return false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 2169 | } |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 2170 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2171 | // no client (silent install) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 2172 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2173 | installer->set_install_source(location); |
| 2174 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 2175 | installer->set_expected_version(*version); |
| 2176 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 2177 | installer->set_creation_flags(creation_flags); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 2178 | #if defined(OS_CHROMEOS) |
| 2179 | extensions::InstallLimiter::Get(profile_)->Add(installer, path); |
| 2180 | #else |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2181 | installer->InstallCrx(path); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 2182 | #endif |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 2183 | |
| 2184 | // Depending on the source, a new external extension might not need a user |
| 2185 | // notification on installation. For such extensions, mark them acknowledged |
| 2186 | // now to suppress the notification. |
| 2187 | if (mark_acknowledged) |
| 2188 | AcknowledgeExternalExtension(id); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2189 | |
| 2190 | return true; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2191 | } |
| 2192 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2193 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 2194 | extensions::ExtensionHost* host) { |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2195 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2196 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2197 | if (iter == orphaned_dev_tools_.end()) |
| 2198 | return; |
| 2199 | |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 2200 | iter->second->ConnectRenderViewHost(host->render_view_host()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2201 | orphaned_dev_tools_.erase(iter); |
| 2202 | } |
| 2203 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2204 | void ExtensionService::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2205 | const content::NotificationSource& source, |
| 2206 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2207 | switch (type) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2208 | case chrome::NOTIFICATION_APP_TERMINATING: |
| 2209 | // Shutdown has started. Don't start any more extension installs. |
| 2210 | // (We cannot use ExtensionService::Shutdown() for this because it |
| 2211 | // happens too late in browser teardown.) |
| 2212 | browser_terminating_ = true; |
| 2213 | break; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2214 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2215 | if (profile_ != |
| 2216 | content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2217 | break; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2218 | } |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2219 | |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 2220 | extensions::ExtensionHost* host = |
| 2221 | content::Details<extensions::ExtensionHost>(details).ptr(); |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2222 | |
[email protected] | 3964e57 | 2014-02-13 21:57:41 | [diff] [blame] | 2223 | // If the extension is already being terminated, there is nothing left to |
| 2224 | // do. |
| 2225 | if (!extensions_being_terminated_.insert(host->extension_id()).second) |
| 2226 | break; |
| 2227 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2228 | // Mark the extension as terminated and Unload it. We want it to |
| 2229 | // be in a consistent state: either fully working or not loaded |
| 2230 | // at all, but never half-crashed. We do it in a PostTask so |
| 2231 | // that other handlers of this notification will still have |
| 2232 | // access to the Extension and ExtensionHost. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 2233 | base::MessageLoop::current()->PostTask( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2234 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 2235 | base::Bind( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2236 | &ExtensionService::TrackTerminatedExtension, |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2237 | AsWeakPtr(), |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2238 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2239 | break; |
| 2240 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2241 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2242 | content::RenderProcessHost* process = |
| 2243 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2244 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2245 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2246 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2247 | break; |
| 2248 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2249 | extensions::ProcessMap* process_map = |
| 2250 | extensions::ProcessMap::Get(profile_); |
| 2251 | if (process_map->Contains(process->GetID())) { |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 2252 | // An extension process was terminated, this might have resulted in an |
| 2253 | // app or extension becoming idle. |
| 2254 | std::set<std::string> extension_ids = |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2255 | process_map->GetExtensionsInProcess(process->GetID()); |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 2256 | for (std::set<std::string>::const_iterator it = extension_ids.begin(); |
| 2257 | it != extension_ids.end(); ++it) { |
| 2258 | if (delayed_installs_.Contains(*it)) { |
| 2259 | base::MessageLoop::current()->PostDelayedTask( |
| 2260 | FROM_HERE, |
| 2261 | base::Bind(&ExtensionService::MaybeFinishDelayedInstallation, |
| 2262 | AsWeakPtr(), *it), |
| 2263 | base::TimeDelta::FromSeconds(kUpdateIdleDelay)); |
| 2264 | } |
| 2265 | } |
| 2266 | } |
| 2267 | |
[email protected] | fafdc84 | 2014-01-17 18:09:08 | [diff] [blame] | 2268 | process_map->RemoveAllFromProcess(process->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 2269 | BrowserThread::PostTask( |
[email protected] | 38427a1 | 2013-11-09 17:34:20 | [diff] [blame] | 2270 | BrowserThread::IO, |
| 2271 | FROM_HERE, |
| 2272 | base::Bind(&extensions::InfoMap::UnregisterAllExtensionsInProcess, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 2273 | system_->info_map(), |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2274 | process->GetID())); |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2275 | break; |
| 2276 | } |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 2277 | case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2278 | // Notify observers that chrome update is available. |
| 2279 | FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
| 2280 | OnChromeUpdateAvailable()); |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 2281 | break; |
| 2282 | } |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 2283 | case chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED: { |
| 2284 | OnProfileDestructionStarted(); |
| 2285 | break; |
| 2286 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2287 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2288 | default: |
| 2289 | NOTREACHED() << "Unexpected notification type."; |
| 2290 | } |
| 2291 | } |
| 2292 | |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 2293 | void ExtensionService::OnExtensionInstallPrefChanged() { |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 2294 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 2295 | CheckManagementPolicy(); |
| 2296 | } |
| 2297 | |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2298 | bool ExtensionService::IsBeingReloaded( |
| 2299 | const std::string& extension_id) const { |
| 2300 | return ContainsKey(extensions_being_reloaded_, extension_id); |
| 2301 | } |
| 2302 | |
| 2303 | void ExtensionService::SetBeingReloaded(const std::string& extension_id, |
[email protected] | 5e7015c | 2013-07-23 23:29:43 | [diff] [blame] | 2304 | bool isBeingReloaded) { |
| 2305 | if (isBeingReloaded) |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2306 | extensions_being_reloaded_.insert(extension_id); |
[email protected] | 5e7015c | 2013-07-23 23:29:43 | [diff] [blame] | 2307 | else |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2308 | extensions_being_reloaded_.erase(extension_id); |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2309 | } |
| 2310 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2311 | bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { |
| 2312 | // Extensions installed by policy can't be disabled. So even if a previous |
| 2313 | // installation disabled the extension, make sure it is now enabled. |
[email protected] | 75181f6 | 2014-03-19 21:41:12 | [diff] [blame] | 2314 | // TODO(rlp): Clean up the special case for external components as noted |
| 2315 | // in crbug.com/353266. For now, EXTERNAL_COMPONENT apps should be |
| 2316 | // default enabled on install as before. |
| 2317 | if (system_->management_policy()->MustRemainEnabled(extension, NULL) || |
| 2318 | extension->location() == Manifest::EXTERNAL_COMPONENT) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2319 | return true; |
[email protected] | 75181f6 | 2014-03-19 21:41:12 | [diff] [blame] | 2320 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2321 | |
| 2322 | if (extension_prefs_->IsExtensionDisabled(extension->id())) |
| 2323 | return false; |
| 2324 | |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 2325 | if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2326 | // External extensions are initially disabled. We prompt the user before |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 2327 | // enabling them. Hosted apps are excepted because they are not dangerous |
| 2328 | // (they need to be launched by the user anyway). |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2329 | if (extension->GetType() != Manifest::TYPE_HOSTED_APP && |
| 2330 | Manifest::IsExternalLocation(extension->location()) && |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2331 | !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) { |
| 2332 | return false; |
| 2333 | } |
| 2334 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2335 | |
| 2336 | return true; |
| 2337 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2338 | |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2339 | bool ExtensionService::ShouldDelayExtensionUpdate( |
| 2340 | const std::string& extension_id, |
| 2341 | bool wait_for_idle) const { |
| 2342 | const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 2343 | |
| 2344 | // If delayed updates are globally disabled, or just for this extension, |
| 2345 | // don't delay. |
| 2346 | if (!install_updates_when_idle_ || !wait_for_idle) |
| 2347 | return false; |
| 2348 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2349 | const Extension* old = GetInstalledExtension(extension_id); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2350 | // If there is no old extension, this is not an update, so don't delay. |
| 2351 | if (!old) |
| 2352 | return false; |
| 2353 | |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2354 | if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) { |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2355 | // Delay installation if the extension listens for the onUpdateAvailable |
| 2356 | // event. |
| 2357 | return system_->event_router()->ExtensionHasEventListener( |
| 2358 | extension_id, kOnUpdateAvailableEvent); |
| 2359 | } else { |
| 2360 | // Delay installation if the extension is not idle. |
[email protected] | 1d5cf414 | 2014-01-24 18:25:22 | [diff] [blame] | 2361 | return !extensions::util::IsExtensionIdle(extension_id, profile_); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2362 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2363 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2364 | |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 2365 | void ExtensionService::OnGarbageCollectIsolatedStorageStart() { |
| 2366 | DCHECK(!installs_delayed_for_gc_); |
| 2367 | installs_delayed_for_gc_ = true; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | void ExtensionService::OnGarbageCollectIsolatedStorageFinished() { |
[email protected] | e5f8fffe | 2014-04-02 00:30:44 | [diff] [blame] | 2371 | DCHECK(installs_delayed_for_gc_); |
| 2372 | installs_delayed_for_gc_ = false; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2373 | MaybeFinishDelayedInstallations(); |
| 2374 | } |
| 2375 | |
| 2376 | void ExtensionService::MaybeFinishDelayedInstallations() { |
| 2377 | std::vector<std::string> to_be_installed; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2378 | for (ExtensionSet::const_iterator it = delayed_installs_.begin(); |
| 2379 | it != delayed_installs_.end(); |
| 2380 | ++it) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2381 | to_be_installed.push_back((*it)->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2382 | } |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2383 | for (std::vector<std::string>::const_iterator it = to_be_installed.begin(); |
| 2384 | it != to_be_installed.end(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2385 | ++it) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2386 | MaybeFinishDelayedInstallation(*it); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2387 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2388 | } |
| 2389 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2390 | void ExtensionService::OnBlacklistUpdated() { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2391 | blacklist_->GetBlacklistedIDs( |
[email protected] | f47f717 | 2014-03-19 19:27:10 | [diff] [blame] | 2392 | registry_->GenerateInstalledExtensionsSet()->GetIDs(), |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2393 | base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2394 | } |
| 2395 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2396 | void ExtensionService::ManageBlacklist( |
| 2397 | const extensions::Blacklist::BlacklistStateMap& state_map) { |
[email protected] | 54ee819 | 2014-03-29 17:37:24 | [diff] [blame] | 2398 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2399 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2400 | std::set<std::string> blocked; |
| 2401 | ExtensionIdSet greylist; |
| 2402 | ExtensionIdSet unchanged; |
| 2403 | for (extensions::Blacklist::BlacklistStateMap::const_iterator it = |
| 2404 | state_map.begin(); |
| 2405 | it != state_map.end(); |
| 2406 | ++it) { |
| 2407 | switch (it->second) { |
| 2408 | case extensions::NOT_BLACKLISTED: |
| 2409 | break; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2410 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2411 | case extensions::BLACKLISTED_MALWARE: |
| 2412 | blocked.insert(it->first); |
| 2413 | break; |
| 2414 | |
| 2415 | case extensions::BLACKLISTED_SECURITY_VULNERABILITY: |
| 2416 | case extensions::BLACKLISTED_CWS_POLICY_VIOLATION: |
| 2417 | case extensions::BLACKLISTED_POTENTIALLY_UNWANTED: |
| 2418 | greylist.insert(it->first); |
| 2419 | break; |
| 2420 | |
| 2421 | case extensions::BLACKLISTED_UNKNOWN: |
| 2422 | unchanged.insert(it->first); |
| 2423 | break; |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | UpdateBlockedExtensions(blocked, unchanged); |
| 2428 | UpdateGreylistedExtensions(greylist, unchanged, state_map); |
| 2429 | |
[email protected] | 373daf97 | 2014-04-10 01:50:44 | [diff] [blame] | 2430 | error_controller_->ShowErrorIfNeeded(); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | namespace { |
| 2434 | void Partition(const ExtensionIdSet& before, |
| 2435 | const ExtensionIdSet& after, |
| 2436 | const ExtensionIdSet& unchanged, |
| 2437 | ExtensionIdSet* no_longer, |
| 2438 | ExtensionIdSet* not_yet) { |
| 2439 | *not_yet = base::STLSetDifference<ExtensionIdSet>(after, before); |
| 2440 | *no_longer = base::STLSetDifference<ExtensionIdSet>(before, after); |
| 2441 | *no_longer = base::STLSetDifference<ExtensionIdSet>(*no_longer, unchanged); |
| 2442 | } |
| 2443 | } // namespace |
| 2444 | |
| 2445 | void ExtensionService::UpdateBlockedExtensions( |
| 2446 | const ExtensionIdSet& blocked, |
| 2447 | const ExtensionIdSet& unchanged) { |
| 2448 | ExtensionIdSet not_yet_blocked, no_longer_blocked; |
| 2449 | Partition(registry_->blacklisted_extensions().GetIDs(), |
| 2450 | blocked, unchanged, |
| 2451 | &no_longer_blocked, ¬_yet_blocked); |
| 2452 | |
| 2453 | for (ExtensionIdSet::iterator it = no_longer_blocked.begin(); |
| 2454 | it != no_longer_blocked.end(); ++it) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2455 | scoped_refptr<const Extension> extension = |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2456 | registry_->blacklisted_extensions().GetByID(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2457 | if (!extension.get()) { |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2458 | NOTREACHED() << "Extension " << *it << " no longer blocked, " |
| 2459 | << "but it was never blocked."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2460 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2461 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2462 | registry_->RemoveBlacklisted(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2463 | extension_prefs_->SetExtensionBlacklisted(extension->id(), false); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2464 | AddExtension(extension.get()); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2465 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled", |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2466 | extension->location(), |
| 2467 | Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2468 | } |
| 2469 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2470 | for (ExtensionIdSet::iterator it = not_yet_blocked.begin(); |
| 2471 | it != not_yet_blocked.end(); ++it) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2472 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2473 | if (!extension.get()) { |
| 2474 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 2475 | << "blacklisted, but it's not installed."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2476 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 2477 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2478 | registry_->AddBlacklisted(extension); |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2479 | extension_prefs_->SetExtensionBlacklistState( |
| 2480 | extension->id(), extensions::BLACKLISTED_MALWARE); |
[email protected] | b0af479 | 2013-10-23 09:12:13 | [diff] [blame] | 2481 | UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2482 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled", |
| 2483 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2484 | } |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2485 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2486 | |
[email protected] | 2d19eb6e | 2014-01-27 17:30:00 | [diff] [blame] | 2487 | // TODO(oleg): UMA logging |
| 2488 | void ExtensionService::UpdateGreylistedExtensions( |
| 2489 | const ExtensionIdSet& greylist, |
| 2490 | const ExtensionIdSet& unchanged, |
| 2491 | const extensions::Blacklist::BlacklistStateMap& state_map) { |
| 2492 | ExtensionIdSet not_yet_greylisted, no_longer_greylisted; |
| 2493 | Partition(greylist_.GetIDs(), |
| 2494 | greylist, unchanged, |
| 2495 | &no_longer_greylisted, ¬_yet_greylisted); |
| 2496 | |
| 2497 | for (ExtensionIdSet::iterator it = no_longer_greylisted.begin(); |
| 2498 | it != no_longer_greylisted.end(); ++it) { |
| 2499 | scoped_refptr<const Extension> extension = greylist_.GetByID(*it); |
| 2500 | if (!extension.get()) { |
| 2501 | NOTREACHED() << "Extension " << *it << " no longer greylisted, " |
| 2502 | << "but it was not marked as greylisted."; |
| 2503 | continue; |
| 2504 | } |
| 2505 | |
| 2506 | greylist_.Remove(*it); |
| 2507 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
| 2508 | extensions::NOT_BLACKLISTED); |
| 2509 | if (extension_prefs_->GetDisableReasons(extension->id()) & |
| 2510 | extensions::Extension::DISABLE_GREYLIST) |
| 2511 | EnableExtension(*it); |
| 2512 | } |
| 2513 | |
| 2514 | for (ExtensionIdSet::iterator it = not_yet_greylisted.begin(); |
| 2515 | it != not_yet_greylisted.end(); ++it) { |
| 2516 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
| 2517 | if (!extension.get()) { |
| 2518 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 2519 | << "disabled, but it's not installed."; |
| 2520 | continue; |
| 2521 | } |
| 2522 | greylist_.Insert(extension); |
| 2523 | extension_prefs_->SetExtensionBlacklistState(extension->id(), |
| 2524 | state_map.find(*it)->second); |
| 2525 | if (registry_->enabled_extensions().Contains(extension->id())) |
| 2526 | DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST); |
| 2527 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 2528 | } |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2529 | |
| 2530 | void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 2531 | update_observers_.AddObserver(observer); |
| 2532 | } |
| 2533 | |
| 2534 | void ExtensionService::RemoveUpdateObserver( |
| 2535 | extensions::UpdateObserver* observer) { |
| 2536 | update_observers_.RemoveObserver(observer); |
| 2537 | } |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2538 | |
| 2539 | // Used only by test code. |
| 2540 | void ExtensionService::UnloadAllExtensionsInternal() { |
| 2541 | profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
| 2542 | |
| 2543 | registry_->ClearAll(); |
[email protected] | 45f5b7d | 2014-01-22 23:47:13 | [diff] [blame] | 2544 | system_->runtime_data()->ClearAll(); |
[email protected] | bb1bc9b3 | 2013-12-21 03:09:14 | [diff] [blame] | 2545 | |
| 2546 | // TODO(erikkay) should there be a notification for this? We can't use |
| 2547 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2548 | // or uninstalled. |
| 2549 | } |
[email protected] | ebe0777 | 2014-05-22 04:16:06 | [diff] [blame] | 2550 | |
| 2551 | void ExtensionService::OnProfileDestructionStarted() { |
| 2552 | ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
| 2553 | for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
| 2554 | it != ids_to_unload.end(); |
| 2555 | ++it) { |
| 2556 | UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
| 2557 | } |
| 2558 | } |