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