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