[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] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 27 | #include "base/values.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 28 | #include "base/version.h" |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 29 | #include "chrome/browser/app_mode/app_mode_utils.h" |
[email protected] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 30 | #include "chrome/browser/browser_process.h" |
[email protected] | 9ea0cd3 | 2013-07-12 01:50:36 | [diff] [blame] | 31 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 32b36c6 | 2012-10-24 05:37:41 | [diff] [blame] | 32 | #include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h" |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 33 | #include "chrome/browser/extensions/api/declarative/rules_registry_service.h" |
[email protected] | ad44576 | 2013-01-23 00:47:44 | [diff] [blame] | 34 | #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
[email protected] | c39df1a | 2013-01-08 18:22:07 | [diff] [blame] | 35 | #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 36 | #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
[email protected] | 4636c83 | 2013-01-11 02:10:11 | [diff] [blame] | 37 | #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 38 | #include "chrome/browser/extensions/app_sync_data.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 39 | #include "chrome/browser/extensions/component_loader.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 40 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame] | 41 | #include "chrome/browser/extensions/data_deleter.h" |
[email protected] | ebc8d93 | 2013-09-11 23:47:29 | [diff] [blame] | 42 | #include "chrome/browser/extensions/event_router.h" |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_disabled_ui.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_error_ui.h" |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 00b3824 | 2012-07-18 18:43:22 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 48 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame] | 49 | #include "chrome/browser/extensions/extension_sorting.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 50 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 51 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 52 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 53 | #include "chrome/browser/extensions/external_install_ui.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 54 | #include "chrome/browser/extensions/external_provider_impl.h" |
| 55 | #include "chrome/browser/extensions/external_provider_interface.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 56 | #include "chrome/browser/extensions/installed_loader.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 57 | #include "chrome/browser/extensions/management_policy.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 58 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 59 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 60 | #include "chrome/browser/extensions/unpacked_installer.h" |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 61 | #include "chrome/browser/extensions/update_observer.h" |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 62 | #include "chrome/browser/extensions/updater/extension_updater.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 63 | #include "chrome/browser/profiles/profile.h" |
[email protected] | cf593af | 2011-12-30 05:44:39 | [diff] [blame] | 64 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 65 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 66 | #include "chrome/browser/ui/webui/ntp/thumbnail_source.h" |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 67 | #include "chrome/browser/ui/webui/theme_source.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 68 | #include "chrome/common/chrome_switches.h" |
[email protected] | 15397b4 | 2012-05-16 23:56:06 | [diff] [blame] | 69 | #include "chrome/common/chrome_version_info.h" |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 70 | #include "chrome/common/crash_keys.h" |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 71 | #include "chrome/common/extensions/background_info.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 72 | #include "chrome/common/extensions/extension.h" |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 73 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 74 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 75 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 76 | #include "chrome/common/extensions/feature_switch.h" |
[email protected] | 15d4d2d | 2013-08-09 06:49:03 | [diff] [blame] | 77 | #include "chrome/common/extensions/features/feature_channel.h" |
[email protected] | 06492ed | 2013-03-24 22:13:14 | [diff] [blame] | 78 | #include "chrome/common/extensions/incognito_handler.h" |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 79 | #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 80 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 81 | #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 82 | #include "chrome/common/extensions/manifest_url_handler.h" |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 83 | #include "chrome/common/extensions/permissions/permissions_data.h" |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 84 | #include "chrome/common/extensions/sync_helper.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 85 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 86 | #include "chrome/common/url_constants.h" |
[email protected] | 7a83dd07 | 2013-09-03 12:09:17 | [diff] [blame] | 87 | #include "components/startup_metric_utils/startup_metric_utils.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 88 | #include "content/public/browser/browser_thread.h" |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 89 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | 05aad2da | 2011-10-28 10:12:37 | [diff] [blame] | 90 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 91 | #include "content/public/browser/notification_types.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 92 | #include "content/public/browser/render_process_host.h" |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 93 | #include "content/public/browser/site_instance.h" |
| 94 | #include "content/public/browser/storage_partition.h" |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 95 | #include "content/public/browser/url_data_source.h" |
[email protected] | 836e298 | 2013-05-16 08:07:42 | [diff] [blame] | 96 | #include "extensions/common/constants.h" |
[email protected] | e9f541a | 2012-11-19 21:52:31 | [diff] [blame] | 97 | #include "extensions/common/error_utils.h" |
[email protected] | d42c1115 | 2013-08-22 19:36:32 | [diff] [blame] | 98 | #include "extensions/common/manifest.h" |
[email protected] | 0c3c973 | 2013-09-16 08:53:41 | [diff] [blame] | 99 | #include "extensions/common/manifest_constants.h" |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 100 | #include "grit/generated_resources.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 101 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 895a1e5 | 2012-05-15 02:50:12 | [diff] [blame] | 102 | #include "sync/api/sync_change.h" |
| 103 | #include "sync/api/sync_error_factory.h" |
[email protected] | 4941fe9 | 2013-06-13 23:21:01 | [diff] [blame] | 104 | #include "ui/webui/web_ui_util.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 105 | #include "url/gurl.h" |
[email protected] | 08b1f75f | 2013-05-22 22:02:38 | [diff] [blame] | 106 | #include "webkit/browser/database/database_tracker.h" |
| 107 | #include "webkit/browser/database/database_util.h" |
[email protected] | 79a6064 | 2012-10-20 21:03:18 | [diff] [blame] | 108 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 109 | #if defined(OS_CHROMEOS) |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 110 | #include "chrome/browser/chromeos/extensions/install_limiter.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 111 | #include "webkit/browser/fileapi/file_system_backend.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 112 | #include "webkit/browser/fileapi/file_system_context.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 113 | #endif |
| 114 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 115 | using content::BrowserContext; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 116 | using content::BrowserThread; |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 117 | using content::DevToolsAgentHost; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 118 | using extensions::CrxInstaller; |
[email protected] | 1c321ee5 | 2012-05-21 03:02:34 | [diff] [blame] | 119 | using extensions::Extension; |
| 120 | using extensions::ExtensionIdSet; |
| 121 | using extensions::ExtensionInfo; |
[email protected] | 215a7be | 2012-10-22 19:53:42 | [diff] [blame] | 122 | using extensions::FeatureSwitch; |
[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, |
| 175 | string16* error) const OVERRIDE { |
| 176 | return !IsCWSSharedModule(extension); |
| 177 | } |
| 178 | |
| 179 | virtual bool MustRemainEnabled(const Extension* extension, |
| 180 | string16* error) const OVERRIDE { |
| 181 | return IsCWSSharedModule(extension); |
| 182 | } |
| 183 | |
| 184 | private: |
| 185 | DISALLOW_COPY_AND_ASSIGN(SharedModuleProvider); |
| 186 | }; |
| 187 | |
| 188 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 189 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 190 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 191 | ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 192 | : background_page_ready(false), |
[email protected] | f8bf599 | 2011-10-24 22:38:57 | [diff] [blame] | 193 | being_upgraded(false), |
| 194 | has_used_webrequest(false) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 197 | ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 198 | } |
| 199 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 200 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 201 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 202 | const char ExtensionService::kLocalAppSettingsDirectoryName[] = |
[email protected] | 15d5b47 | 2011-11-24 04:17:24 | [diff] [blame] | 203 | "Local App Settings"; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 204 | const char ExtensionService::kLocalExtensionSettingsDirectoryName[] = |
[email protected] | 15d5b47 | 2011-11-24 04:17:24 | [diff] [blame] | 205 | "Local Extension Settings"; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 206 | const char ExtensionService::kSyncAppSettingsDirectoryName[] = |
[email protected] | 15d5b47 | 2011-11-24 04:17:24 | [diff] [blame] | 207 | "Sync App Settings"; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 208 | const char ExtensionService::kSyncExtensionSettingsDirectoryName[] = |
[email protected] | 15d5b47 | 2011-11-24 04:17:24 | [diff] [blame] | 209 | "Sync Extension Settings"; |
[email protected] | 675bb0101 | 2012-12-14 22:03:29 | [diff] [blame] | 210 | const char ExtensionService::kManagedSettingsDirectoryName[] = |
| 211 | "Managed Extension Settings"; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 212 | const char ExtensionService::kStateStoreName[] = "Extension State"; |
[email protected] | a690e29 | 2012-12-19 19:22:49 | [diff] [blame] | 213 | const char ExtensionService::kRulesStoreName[] = "Extension Rules"; |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 214 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 215 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 216 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 217 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 218 | // Check if the providers know about this extension. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 219 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 220 | for (i = external_extension_providers_.begin(); |
| 221 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 222 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 223 | if (i->get()->HasExtension(id)) |
| 224 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 225 | } |
| 226 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 227 | // We get the list of external extensions to check from preferences. |
| 228 | // It is possible that an extension has preferences but is not loaded. |
| 229 | // For example, an extension that requires experimental permissions |
| 230 | // will not be loaded if the experimental command line flag is not used. |
| 231 | // In this case, do not uninstall. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 232 | if (!GetInstalledExtension(id)) { |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 233 | // We can't call UninstallExtension with an unloaded/invalid |
| 234 | // extension ID. |
| 235 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 236 | << "with id: " << id; |
| 237 | return; |
| 238 | } |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 239 | UninstallExtension(id, true, NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 242 | void ExtensionService::SetFileTaskRunnerForTesting( |
| 243 | base::SequencedTaskRunner* task_runner) { |
| 244 | file_task_runner_ = task_runner; |
| 245 | } |
| 246 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 247 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 248 | external_extension_providers_.clear(); |
| 249 | } |
| 250 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 251 | void ExtensionService::AddProviderForTesting( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 252 | extensions::ExternalProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 253 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 254 | external_extension_providers_.push_back( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 255 | linked_ptr<extensions::ExternalProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 256 | } |
| 257 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 258 | bool ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 259 | const std::string& id, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 260 | const GURL& update_url, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 261 | Manifest::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 262 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 263 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 264 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 265 | const Extension* extension = GetExtensionById(id, true); |
| 266 | if (extension) { |
| 267 | // Already installed. Skip this install if the current location has |
| 268 | // higher priority than |location|. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 269 | Manifest::Location current = extension->location(); |
| 270 | if (current == Manifest::GetHigherPriorityLocation(current, location)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 271 | return false; |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 272 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 273 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 274 | |
| 275 | // Add |id| to the set of pending extensions. If it can not be added, |
| 276 | // then there is already a pending record from a higher-priority install |
| 277 | // source. In this case, signal that this extension will not be |
| 278 | // installed by returning false. |
| 279 | if (!pending_extension_manager()->AddFromExternalUpdateUrl( |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 280 | id, update_url, location)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 281 | return false; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 282 | } |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 283 | |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 284 | update_once_all_providers_are_ready_ = true; |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 285 | return true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 286 | } |
| 287 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 288 | const Extension* ExtensionService::GetInstalledApp(const GURL& url) const { |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 289 | const Extension* extension = extensions_.GetExtensionOrAppByURL(url); |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 290 | return (extension && extension->is_app()) ? extension : NULL; |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 291 | } |
| 292 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 293 | bool ExtensionService::IsInstalledApp(const GURL& url) const { |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 294 | return !!GetInstalledApp(url); |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 404fb00 | 2012-10-02 21:06:17 | [diff] [blame] | 297 | const Extension* ExtensionService::GetIsolatedAppForRenderer( |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 298 | int renderer_child_id) const { |
[email protected] | 404fb00 | 2012-10-02 21:06:17 | [diff] [blame] | 299 | std::set<std::string> extension_ids = |
| 300 | process_map_.GetExtensionsInProcess(renderer_child_id); |
| 301 | // All apps in one process share the same partition. |
| 302 | // It is only possible for the app to have isolated storage |
| 303 | // if there is only 1 app in the process. |
| 304 | if (extension_ids.size() != 1) |
| 305 | return NULL; |
| 306 | |
| 307 | const extensions::Extension* extension = |
| 308 | extensions_.GetByID(*(extension_ids.begin())); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 309 | // We still need to check if the extension has isolated storage, |
[email protected] | 404fb00 | 2012-10-02 21:06:17 | [diff] [blame] | 310 | // because it's common for there to be one extension in a process |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 311 | // without isolated storage. |
| 312 | if (extension && |
| 313 | extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
[email protected] | 404fb00 | 2012-10-02 21:06:17 | [diff] [blame] | 314 | return extension; |
| 315 | |
| 316 | return NULL; |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 317 | } |
| 318 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 319 | // static |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 320 | // This function is used to implement the command-line switch |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 321 | // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 322 | // statements within this function are used to inform the user if the uninstall |
| 323 | // cannot be done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 324 | bool ExtensionService::UninstallExtensionHelper( |
| 325 | ExtensionService* extensions_service, |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 326 | const std::string& extension_id) { |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 327 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 328 | if (!extensions_service->GetInstalledExtension(extension_id)) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 329 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 330 | << "id: " << extension_id; |
| 331 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 332 | } |
| 333 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 334 | // The following call to UninstallExtension will not allow an uninstall of a |
| 335 | // policy-controlled extension. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 336 | string16 error; |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 337 | if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 338 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 339 | << ": " << error; |
| 340 | return false; |
| 341 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 342 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 343 | return true; |
| 344 | } |
| 345 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 346 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 347 | const CommandLine* command_line, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 348 | const base::FilePath& install_directory, |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 349 | extensions::ExtensionPrefs* extension_prefs, |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 350 | extensions::Blacklist* blacklist, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 351 | bool autoupdate_enabled, |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 352 | bool extensions_enabled, |
| 353 | extensions::OneShotEvent* ready) |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 354 | : extensions::Blacklist::Observer(blacklist), |
| 355 | profile_(profile), |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 356 | system_(extensions::ExtensionSystem::Get(profile)), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 357 | extension_prefs_(extension_prefs), |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 358 | blacklist_(blacklist), |
[email protected] | cccdf0aa | 2011-11-11 03:43:38 | [diff] [blame] | 359 | settings_frontend_(extensions::SettingsFrontend::Create(profile)), |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 360 | pending_extension_manager_(*this), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 361 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 362 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 363 | show_extensions_prompts_(true), |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 364 | install_updates_when_idle_(true), |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 365 | ready_(ready), |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 366 | toolbar_model_(this), |
[email protected] | 8b28030 | 2011-10-13 22:22:23 | [diff] [blame] | 367 | menu_manager_(profile), |
[email protected] | dff1e04 | 2012-04-27 10:59:18 | [diff] [blame] | 368 | update_once_all_providers_are_ready_(false), |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 369 | browser_terminating_(false), |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 370 | installs_delayed_for_gc_(false), |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 371 | is_first_run_(false), |
[email protected] | 9c00909 | 2013-05-01 03:14:09 | [diff] [blame] | 372 | app_sync_bundle_(this), |
| 373 | extension_sync_bundle_(this) { |
[email protected] | c04fd3dd | 2013-09-05 08:20:10 | [diff] [blame] | 374 | #if defined(OS_CHROMEOS) |
| 375 | disable_garbage_collection_ = false; |
| 376 | #endif |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 377 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 378 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 379 | // Figure out if extension installation should be enabled. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 380 | if (command_line->HasSwitch(switches::kDisableExtensions) || |
| 381 | profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 382 | extensions_enabled_ = false; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 383 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 384 | |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 385 | registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
| 386 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 387 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 388 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 389 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 390 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 391 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 392 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 393 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 394 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 395 | registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
| 396 | content::NotificationService::AllBrowserContextsAndSources()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 397 | pref_change_registrar_.Init(profile->GetPrefs()); |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 398 | base::Closure callback = |
| 399 | base::Bind(&ExtensionService::OnExtensionInstallPrefChanged, |
| 400 | base::Unretained(this)); |
| 401 | pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, callback); |
| 402 | pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, callback); |
[email protected] | e410b5f | 2012-12-14 14:02:24 | [diff] [blame] | 403 | pref_change_registrar_.Add(prefs::kExtensionAllowedTypes, callback); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 404 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 405 | // Set up the ExtensionUpdater |
| 406 | if (autoupdate_enabled) { |
| 407 | int update_frequency = kDefaultUpdateFrequencySeconds; |
| 408 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 409 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 410 | switches::kExtensionsUpdateFrequency), |
| 411 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 412 | } |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 413 | updater_.reset(new extensions::ExtensionUpdater(this, |
| 414 | extension_prefs, |
| 415 | profile->GetPrefs(), |
| 416 | profile, |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 417 | update_frequency)); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 420 | component_loader_.reset( |
| 421 | new extensions::ComponentLoader(this, |
| 422 | profile->GetPrefs(), |
| 423 | g_browser_process->local_state())); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 424 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 425 | if (extensions_enabled_) { |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 426 | extensions::ExternalProviderImpl::CreateExternalProviders( |
| 427 | this, profile_, &external_extension_providers_); |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 428 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 429 | |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 430 | // Set this as the ExtensionService for extension sorting to ensure it |
| 431 | // cause syncs if required. |
| 432 | extension_prefs_->extension_sorting()->SetExtensionService(this); |
| 433 | |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 434 | is_first_run_ = !extension_prefs_->SetAlertSystemFirstRun(); |
| 435 | |
[email protected] | 9ce11d2 | 2012-08-08 23:20:13 | [diff] [blame] | 436 | #if defined(ENABLE_EXTENSIONS) |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 437 | extension_action_storage_manager_.reset( |
| 438 | new extensions::ExtensionActionStorageManager(profile_)); |
[email protected] | 9ce11d2 | 2012-08-08 23:20:13 | [diff] [blame] | 439 | #endif |
[email protected] | c77f235 | 2012-08-08 22:07:58 | [diff] [blame] | 440 | |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 441 | shared_module_policy_provider_.reset(new SharedModuleProvider); |
| 442 | |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 443 | // How long is the path to the Extensions directory? |
| 444 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 445 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 446 | } |
| 447 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 448 | const ExtensionSet* ExtensionService::extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 449 | return &extensions_; |
| 450 | } |
| 451 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 452 | const ExtensionSet* ExtensionService::disabled_extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 453 | return &disabled_extensions_; |
| 454 | } |
| 455 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 456 | const ExtensionSet* ExtensionService::terminated_extensions() const { |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 457 | return &terminated_extensions_; |
| 458 | } |
| 459 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 460 | const ExtensionSet* ExtensionService::blacklisted_extensions() const { |
| 461 | return &blacklisted_extensions_; |
| 462 | } |
| 463 | |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 464 | const ExtensionSet* ExtensionService::delayed_installs() const { |
| 465 | return &delayed_installs_; |
| 466 | } |
| 467 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 468 | scoped_ptr<const ExtensionSet> |
| 469 | ExtensionService::GenerateInstalledExtensionsSet() const { |
| 470 | scoped_ptr<ExtensionSet> installed_extensions(new ExtensionSet()); |
[email protected] | 7f4308d | 2012-01-18 07:43:01 | [diff] [blame] | 471 | installed_extensions->InsertAll(extensions_); |
| 472 | installed_extensions->InsertAll(disabled_extensions_); |
| 473 | installed_extensions->InsertAll(terminated_extensions_); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 474 | installed_extensions->InsertAll(blacklisted_extensions_); |
| 475 | return installed_extensions.PassAs<const ExtensionSet>(); |
[email protected] | 7f4308d | 2012-01-18 07:43:01 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 478 | extensions::PendingExtensionManager* |
| 479 | ExtensionService::pending_extension_manager() { |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 480 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 481 | } |
| 482 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 483 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 484 | // No need to unload extensions here because they are profile-scoped, and the |
| 485 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 486 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 487 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 488 | for (i = external_extension_providers_.begin(); |
| 489 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 490 | extensions::ExternalProviderInterface* provider = i->get(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 491 | provider->ServiceShutdown(); |
| 492 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 495 | void ExtensionService::SetSyncStartFlare( |
| 496 | const syncer::SyncableService::StartSyncFlare& flare) { |
| 497 | flare_ = flare; |
| 498 | } |
| 499 | |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 500 | void ExtensionService::Shutdown() { |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 501 | system_->management_policy()->UnregisterProvider( |
| 502 | shared_module_policy_provider_.get()); |
[email protected] | 037228a | 2012-10-05 01:36:16 | [diff] [blame] | 503 | } |
| 504 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 505 | const Extension* ExtensionService::GetExtensionById( |
| 506 | const std::string& id, bool include_disabled) const { |
[email protected] | 81f0d16 | 2012-08-15 04:21:47 | [diff] [blame] | 507 | int include_mask = INCLUDE_ENABLED; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 508 | if (include_disabled) { |
| 509 | // Include blacklisted extensions here because there are hundreds of |
| 510 | // callers of this function, and many might assume that this includes those |
| 511 | // that have been disabled due to blacklisting. |
| 512 | include_mask |= INCLUDE_DISABLED | INCLUDE_BLACKLISTED; |
| 513 | } |
| 514 | return GetExtensionById(id, include_mask); |
| 515 | } |
| 516 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 517 | GURL ExtensionService::GetSiteForExtensionId(const std::string& extension_id) { |
| 518 | return content::SiteInstance::GetSiteForURL( |
| 519 | profile_, |
| 520 | Extension::GetBaseURLFromExtensionId(extension_id)); |
| 521 | } |
| 522 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 523 | const Extension* ExtensionService::GetExtensionById( |
| 524 | const std::string& id, int include_mask) const { |
| 525 | std::string lowercase_id = StringToLowerASCII(id); |
| 526 | if (include_mask & INCLUDE_ENABLED) { |
| 527 | const Extension* extension = extensions_.GetByID(lowercase_id); |
| 528 | if (extension) |
| 529 | return extension; |
| 530 | } |
| 531 | if (include_mask & INCLUDE_DISABLED) { |
| 532 | const Extension* extension = disabled_extensions_.GetByID(lowercase_id); |
| 533 | if (extension) |
| 534 | return extension; |
| 535 | } |
| 536 | if (include_mask & INCLUDE_TERMINATED) { |
| 537 | const Extension* extension = terminated_extensions_.GetByID(lowercase_id); |
| 538 | if (extension) |
| 539 | return extension; |
| 540 | } |
| 541 | if (include_mask & INCLUDE_BLACKLISTED) { |
| 542 | const Extension* extension = blacklisted_extensions_.GetByID(lowercase_id); |
| 543 | if (extension) |
| 544 | return extension; |
| 545 | } |
| 546 | return NULL; |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 547 | } |
| 548 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 549 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 550 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 551 | |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 552 | DCHECK(!is_ready()); // Can't redo init. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 553 | DCHECK_EQ(extensions_.size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 554 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 555 | const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 556 | if (cmd_line->HasSwitch(switches::kInstallFromWebstore) || |
| 557 | cmd_line->HasSwitch(switches::kLimitedInstallFromWebstore)) { |
| 558 | // The sole purpose of this launch is to install a new extension from CWS |
| 559 | // and immediately terminate: loading already installed extensions is |
| 560 | // unnecessary and may interfere with the inline install dialog (e.g. if an |
| 561 | // extension listens to onStartup and opens a window). |
| 562 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 563 | } else { |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 564 | // LoadAllExtensions() calls OnLoadedInstalledExtensions(). |
| 565 | component_loader_->LoadAll(); |
| 566 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 567 | |
[email protected] | 2edd5785 | 2013-08-14 22:07:40 | [diff] [blame] | 568 | // Attempt to re-enable extensions whose only disable reason is reloading. |
| 569 | std::vector<std::string> extensions_to_enable; |
| 570 | for (ExtensionSet::const_iterator iter = disabled_extensions_.begin(); |
| 571 | iter != disabled_extensions_.end(); ++iter) { |
| 572 | const Extension* e = iter->get(); |
| 573 | if (extension_prefs_->GetDisableReasons(e->id()) == |
| 574 | Extension::DISABLE_RELOAD) { |
| 575 | extensions_to_enable.push_back(e->id()); |
| 576 | } |
| 577 | } |
| 578 | for (std::vector<std::string>::iterator it = extensions_to_enable.begin(); |
| 579 | it != extensions_to_enable.end(); ++it) { |
| 580 | EnableExtension(*it); |
| 581 | } |
| 582 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 583 | // Finish install (if possible) of extensions that were still delayed while |
| 584 | // the browser was shut down. |
| 585 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info( |
| 586 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 587 | for (size_t i = 0; i < delayed_info->size(); ++i) { |
| 588 | ExtensionInfo* info = delayed_info->at(i).get(); |
| 589 | scoped_refptr<const Extension> extension(NULL); |
| 590 | if (info->extension_manifest) { |
| 591 | std::string error; |
| 592 | extension = Extension::Create( |
| 593 | info->extension_path, |
| 594 | info->extension_location, |
| 595 | *info->extension_manifest, |
| 596 | extension_prefs_->GetDelayedInstallCreationFlags( |
| 597 | info->extension_id), |
| 598 | info->extension_id, |
| 599 | &error); |
| 600 | if (extension.get()) |
| 601 | delayed_installs_.Insert(extension); |
| 602 | } |
| 603 | } |
| 604 | MaybeFinishDelayedInstallations(); |
| 605 | |
| 606 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> delayed_info2( |
| 607 | extension_prefs_->GetAllDelayedInstallInfo()); |
| 608 | UMA_HISTOGRAM_COUNTS_100("Extensions.UpdateOnLoad", |
| 609 | delayed_info2->size() - delayed_info->size()); |
| 610 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 611 | SetReadyAndNotifyListeners(); |
[email protected] | ae4c37e | 2012-12-21 01:16:25 | [diff] [blame] | 612 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 613 | // TODO(erikkay) this should probably be deferred to a future point |
| 614 | // rather than running immediately at startup. |
| 615 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 616 | |
[email protected] | 47b6007 | 2013-06-20 10:35:56 | [diff] [blame] | 617 | base::MessageLoop::current()->PostDelayedTask( |
| 618 | FROM_HERE, |
| 619 | base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), |
| 620 | base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); |
[email protected] | 215a7be | 2012-10-22 19:53:42 | [diff] [blame] | 621 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 622 | if (extension_prefs_->NeedsStorageGarbageCollection()) { |
| 623 | GarbageCollectIsolatedStorage(); |
| 624 | extension_prefs_->SetNeedsStorageGarbageCollection(false); |
| 625 | } |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 626 | system_->management_policy()->RegisterProvider( |
| 627 | shared_module_policy_provider_.get()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 628 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 631 | bool ExtensionService::UpdateExtension(const std::string& id, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 632 | const base::FilePath& extension_path, |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 633 | const GURL& download_url, |
| 634 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 635 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 636 | if (browser_terminating_) { |
| 637 | LOG(WARNING) << "Skipping UpdateExtension due to browser shutdown"; |
| 638 | // Leak the temp file at extension_path. We don't want to add to the disk |
| 639 | // I/O burden at shutdown, we can't rely on the I/O completing anyway, and |
| 640 | // the file is in the OS temp directory which should be cleaned up for us. |
| 641 | return false; |
| 642 | } |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 643 | |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 644 | const extensions::PendingExtensionInfo* pending_extension_info = |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 645 | pending_extension_manager()->GetById(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 646 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 647 | const Extension* extension = GetInstalledExtension(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 648 | if (!pending_extension_info && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 649 | LOG(WARNING) << "Will not update extension " << id |
| 650 | << " because it is not installed or pending"; |
| 651 | // Delete extension_path since we're not creating a CrxInstaller |
| 652 | // that would do it for us. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 653 | if (!GetFileTaskRunner()->PostTask( |
| 654 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 655 | base::Bind( |
[email protected] | 7296f276 | 2011-11-21 19:23:44 | [diff] [blame] | 656 | &extension_file_util::DeleteFile, extension_path, false))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 657 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 658 | |
| 659 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 662 | // We want a silent install only for non-pending extensions and |
| 663 | // pending extensions that have install_silently set. |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 664 | scoped_ptr<ExtensionInstallPrompt> client; |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 665 | if (pending_extension_info && !pending_extension_info->install_silently()) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 666 | client.reset(ExtensionInstallUI::CreateInstallPromptWithProfile(profile_)); |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 667 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 668 | scoped_refptr<CrxInstaller> installer( |
| 669 | CrxInstaller::Create(this, client.Pass())); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 670 | installer->set_expected_id(id); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 671 | if (pending_extension_info) { |
| 672 | installer->set_install_source(pending_extension_info->install_source()); |
| 673 | if (pending_extension_info->install_silently()) |
| 674 | installer->set_allow_silent_install(true); |
| 675 | } else if (extension) { |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 676 | installer->set_install_source(extension->location()); |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 677 | } |
[email protected] | 7d8b707 | 2012-04-07 01:07:46 | [diff] [blame] | 678 | // If the extension was installed from or has migrated to the webstore, or |
[email protected] | fcb2c2c | 2012-10-17 21:08:45 | [diff] [blame] | 679 | // its auto-update URL is from the webstore, treat it as a webstore install. |
| 680 | // Note that we ignore some older extensions with blank auto-update URLs |
| 681 | // because we are mostly concerned with restrictions on NaCl extensions, |
| 682 | // which are newer. |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 683 | int creation_flags = Extension::NO_FLAGS; |
[email protected] | 7576451 | 2011-12-19 19:54:28 | [diff] [blame] | 684 | if ((extension && extension->from_webstore()) || |
[email protected] | 4a5fe3e2 | 2013-06-04 07:06:38 | [diff] [blame] | 685 | (extension && extensions::ManifestURL::UpdatesFromGallery(extension)) || |
[email protected] | 963d13c | 2012-09-29 17:13:35 | [diff] [blame] | 686 | (!extension && extension_urls::IsWebstoreUpdateUrl( |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 687 | pending_extension_info->update_url()))) { |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 688 | creation_flags |= Extension::FROM_WEBSTORE; |
| 689 | } |
| 690 | |
| 691 | // Bookmark apps being updated is kind of a contradiction, but that's because |
| 692 | // we mark the default apps as bookmark apps, and they're hosted in the web |
| 693 | // store, thus they can get updated. See http://crbug.com/101605 for more |
| 694 | // details. |
| 695 | if (extension && extension->from_bookmark()) |
| 696 | creation_flags |= Extension::FROM_BOOKMARK; |
| 697 | |
[email protected] | e33bbc2 | 2012-08-27 22:05:46 | [diff] [blame] | 698 | if (extension && extension->was_installed_by_default()) |
| 699 | creation_flags |= Extension::WAS_INSTALLED_BY_DEFAULT; |
| 700 | |
[email protected] | a12ce8b2 | 2012-01-17 18:40:53 | [diff] [blame] | 701 | installer->set_creation_flags(creation_flags); |
| 702 | |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 703 | installer->set_delete_source(true); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 704 | installer->set_download_url(download_url); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 705 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 706 | installer->InstallCrx(extension_path); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 707 | |
| 708 | if (out_crx_installer) |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 709 | *out_crx_installer = installer.get(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 710 | |
| 711 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 714 | void ExtensionService::ReloadExtension(const std::string extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 715 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2a94720 | 2013-03-06 04:58:05 | [diff] [blame] | 716 | |
| 717 | // If the extension is already reloading, don't reload again. |
| 718 | if (extension_prefs_->GetDisableReasons(extension_id) & |
| 719 | Extension::DISABLE_RELOAD) { |
| 720 | return; |
| 721 | } |
| 722 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 723 | base::FilePath path; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 724 | const Extension* current_extension = GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 725 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 726 | // 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] | 727 | if (current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 728 | // If the extension has an inspector open for its background page, detach |
| 729 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 730 | // later. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 731 | // TODO(yoz): this is not incognito-safe! |
| 732 | ExtensionProcessManager* manager = system_->process_manager(); |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 733 | extensions::ExtensionHost* host = |
| 734 | manager->GetBackgroundHostForExtension(extension_id); |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 735 | if (host && DevToolsAgentHost::HasFor(host->render_view_host())) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 736 | // Look for an open inspector for the background page. |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 737 | scoped_refptr<DevToolsAgentHost> agent_host = |
| 738 | DevToolsAgentHost::GetOrCreateFor(host->render_view_host()); |
| 739 | agent_host->DisconnectRenderViewHost(); |
| 740 | orphaned_dev_tools_[extension_id] = agent_host; |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 741 | } |
| 742 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 743 | path = current_extension->path(); |
[email protected] | 5807619 | 2013-07-19 19:43:50 | [diff] [blame] | 744 | // BeingUpgraded is set back to false when the extension is added. |
| 745 | SetBeingUpgraded(current_extension, true); |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 746 | DisableExtension(extension_id, Extension::DISABLE_RELOAD); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 747 | reloading_extensions_.insert(extension_id); |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 748 | } else { |
| 749 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 750 | } |
| 751 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 752 | if (delayed_installs_.Contains(extension_id)) { |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 753 | FinishDelayedInstallation(extension_id); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 754 | return; |
| 755 | } |
| 756 | |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 757 | // If we're reloading a component extension, use the component extension |
| 758 | // loader's reloader. |
| 759 | if (component_loader_->Exists(extension_id)) { |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 760 | SetBeingReloaded(extension_id, true); |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 761 | component_loader_->Reload(extension_id); |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 762 | SetBeingReloaded(extension_id, false); |
[email protected] | 43ceb00 | 2012-02-10 23:19:15 | [diff] [blame] | 763 | return; |
| 764 | } |
| 765 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 766 | // Check the installed extensions to see if what we're reloading was already |
| 767 | // installed. |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 768 | SetBeingReloaded(extension_id, true); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 769 | scoped_ptr<ExtensionInfo> installed_extension( |
| 770 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 771 | if (installed_extension.get() && |
| 772 | installed_extension->extension_manifest.get()) { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 773 | extensions::InstalledLoader(this).Load(*installed_extension, false); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 774 | } else { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 775 | // Otherwise, the extension is unpacked (location LOAD). |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 776 | // We should always be able to remember the extension's path. If it's not in |
| 777 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 778 | CHECK(!path.empty()); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 779 | extensions::UnpackedInstaller::Create(this)->Load(path); |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 780 | } |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 781 | // When reloading is done, mark this extension as done reloading. |
| 782 | SetBeingReloaded(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 783 | } |
| 784 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 785 | bool ExtensionService::UninstallExtension( |
[email protected] | a12c706e | 2011-12-01 00:58:08 | [diff] [blame] | 786 | std::string extension_id, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 787 | bool external_uninstall, |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 788 | string16* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 789 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 790 | |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 791 | scoped_refptr<const Extension> extension(GetInstalledExtension(extension_id)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 792 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 793 | // Callers should not send us nonexistent extensions. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 794 | CHECK(extension.get()); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 795 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 796 | // Policy change which triggers an uninstall will always set |
| 797 | // |external_uninstall| to true so this is the only way to uninstall |
| 798 | // managed extensions. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 799 | if (!external_uninstall && |
| 800 | !system_->management_policy()->UserMayModifySettings( |
| 801 | extension.get(), error)) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 802 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 803 | chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 804 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 805 | content::Details<const Extension>(extension.get())); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 806 | return false; |
| 807 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 808 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 809 | // Extract the data we need for sync now, but don't actually sync until we've |
| 810 | // completed the uninstallation. |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 811 | // TODO(tim): If we get here and IsSyncing is false, this will cause |
| 812 | // "back from the dead" style bugs, because sync will add-back the extension |
| 813 | // that was uninstalled here when MergeDataAndStartSyncing is called. |
| 814 | // See crbug.com/256795. |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 815 | syncer::SyncChange sync_change; |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 816 | if (extensions::sync_helper::IsSyncableApp(extension.get())) { |
| 817 | if (app_sync_bundle_.IsSyncing()) |
| 818 | sync_change = app_sync_bundle_.CreateSyncChangeToDelete(extension.get()); |
| 819 | else if (is_ready() && !flare_.is_null()) |
| 820 | flare_.Run(syncer::APPS); // Tell sync to start ASAP. |
| 821 | } else if (extensions::sync_helper::IsSyncableExtension(extension.get())) { |
| 822 | if (extension_sync_bundle_.IsSyncing()) |
| 823 | sync_change = extension_sync_bundle_.CreateSyncChangeToDelete(extension); |
| 824 | else if (is_ready() && !flare_.is_null()) |
| 825 | flare_.Run(syncer::EXTENSIONS); // Tell sync to start ASAP. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 826 | } |
| 827 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 828 | if (IsUnacknowledgedExternalExtension(extension.get())) { |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 829 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 830 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 831 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 832 | if (extensions::ManifestURL::UpdatesFromGallery(extension.get())) { |
| 833 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
| 834 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 835 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 836 | } else { |
| 837 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
| 838 | EXTERNAL_EXTENSION_UNINSTALLED, |
| 839 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 840 | } |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 841 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 842 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 843 | extension->GetType(), 100); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 844 | RecordPermissionMessagesHistogram(extension.get(), |
| 845 | "Extensions.Permissions_Uninstall"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 846 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 847 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 848 | // any of these resources. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 849 | UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 850 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 851 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 12075d1 | 2013-02-27 05:38:05 | [diff] [blame] | 852 | if (!Manifest::IsUnpackedLocation(extension->location())) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 853 | if (!GetFileTaskRunner()->PostTask( |
| 854 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 855 | base::Bind( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 856 | &extension_file_util::UninstallExtension, |
| 857 | install_directory_, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 858 | extension_id))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 859 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 860 | } |
| 861 | |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 862 | GURL launch_web_url_origin( |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 863 | extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin()); |
[email protected] | 561e33d5 | 2013-04-03 06:58:43 | [diff] [blame] | 864 | bool is_storage_isolated = |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 865 | extensions::AppIsolationInfo::HasIsolatedStorage(extension.get()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 866 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 867 | if (is_storage_isolated) { |
| 868 | BrowserContext::AsyncObliterateStoragePartition( |
| 869 | profile_, |
| 870 | GetSiteForExtensionId(extension_id), |
| 871 | base::Bind(&ExtensionService::OnNeedsToGarbageCollectIsolatedStorage, |
| 872 | AsWeakPtr())); |
| 873 | } else { |
| 874 | if (extension->is_hosted_app() && |
| 875 | !profile_->GetExtensionSpecialStoragePolicy()-> |
| 876 | IsStorageProtected(launch_web_url_origin)) { |
| 877 | extensions::DataDeleter::StartDeleting( |
| 878 | profile_, extension_id, launch_web_url_origin); |
| 879 | } |
| 880 | extensions::DataDeleter::StartDeleting(profile_, extension_id, |
| 881 | extension->url()); |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 882 | } |
[email protected] | 0d6ec3a7 | 2011-09-02 02:09:43 | [diff] [blame] | 883 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 884 | UntrackTerminatedExtension(extension_id); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 885 | |
| 886 | // Notify interested parties that we've uninstalled this extension. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 887 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 888 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 889 | content::Source<Profile>(profile_), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 890 | content::Details<const Extension>(extension.get())); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 891 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 892 | if (app_sync_bundle_.HasExtensionId(extension_id) && |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 893 | sync_change.sync_data().GetDataType() == syncer::APPS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 894 | app_sync_bundle_.ProcessDeletion(extension_id, sync_change); |
| 895 | } else if (extension_sync_bundle_.HasExtensionId(extension_id) && |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 896 | sync_change.sync_data().GetDataType() == syncer::EXTENSIONS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 897 | extension_sync_bundle_.ProcessDeletion(extension_id, sync_change); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 898 | } |
| 899 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 900 | delayed_installs_.Remove(extension_id); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 901 | |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 902 | PruneSharedModulesOnUninstall(extension.get()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 903 | |
[email protected] | d4eda59 | 2013-09-18 03:37:57 | [diff] [blame] | 904 | extension_prefs_->OnExtensionUninstalled(extension_id, extension->location(), |
| 905 | external_uninstall); |
| 906 | |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 907 | // Track the uninstallation. |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 908 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionUninstalled", 1, 2); |
| 909 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 910 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 911 | } |
| 912 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 913 | bool ExtensionService::IsExtensionEnabled( |
| 914 | const std::string& extension_id) const { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 915 | if (extensions_.Contains(extension_id) || |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 916 | terminated_extensions_.Contains(extension_id)) { |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 917 | return true; |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 918 | } |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 919 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 920 | if (disabled_extensions_.Contains(extension_id) || |
| 921 | blacklisted_extensions_.Contains(extension_id)) { |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 922 | return false; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 923 | } |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 924 | |
| 925 | // If the extension hasn't been loaded yet, check the prefs for it. Assume |
| 926 | // enabled unless otherwise noted. |
| 927 | return !extension_prefs_->IsExtensionDisabled(extension_id) && |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 928 | !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | bool ExtensionService::IsExternalExtensionUninstalled( |
| 932 | const std::string& extension_id) const { |
| 933 | return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 934 | } |
| 935 | |
[email protected] | e237703 | 2013-01-18 17:53:22 | [diff] [blame] | 936 | bool ExtensionService::IsExtensionEnabledForLauncher( |
| 937 | const std::string& extension_id) const { |
| 938 | return IsExtensionEnabled(extension_id) && |
| 939 | !GetTerminatedExtension(extension_id); |
| 940 | } |
| 941 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 942 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 943 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 944 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 945 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 946 | return; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 947 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 948 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 949 | extension_prefs_->ClearDisableReasons(extension_id); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 950 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 951 | const Extension* extension = disabled_extensions_.GetByID(extension_id); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 952 | // This can happen if sync enables an extension that is not |
| 953 | // installed yet. |
| 954 | if (!extension) |
| 955 | return; |
| 956 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 957 | if (IsUnacknowledgedExternalExtension(extension)) { |
| 958 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 959 | EXTERNAL_EXTENSION_REENABLED, |
| 960 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 961 | if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
| 962 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
| 963 | EXTERNAL_EXTENSION_REENABLED, |
| 964 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 965 | } else { |
| 966 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
| 967 | EXTERNAL_EXTENSION_REENABLED, |
| 968 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 969 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 970 | AcknowledgeExternalExtension(extension->id()); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 971 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 972 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 973 | // Move it over to the enabled list. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 974 | extensions_.Insert(make_scoped_refptr(extension)); |
| 975 | disabled_extensions_.Remove(extension->id()); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 976 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 977 | NotifyExtensionLoaded(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 978 | |
[email protected] | f74d7f3 | 2012-06-19 19:22:51 | [diff] [blame] | 979 | // Notify listeners that the extension was enabled. |
| 980 | content::NotificationService::current()->Notify( |
| 981 | chrome::NOTIFICATION_EXTENSION_ENABLED, |
| 982 | content::Source<Profile>(profile_), |
| 983 | content::Details<const Extension>(extension)); |
| 984 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 985 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 986 | } |
| 987 | |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 988 | void ExtensionService::DisableExtension( |
| 989 | const std::string& extension_id, |
| 990 | Extension::DisableReason disable_reason) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 991 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 992 | |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 993 | // The extension may have been disabled already. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 994 | if (!IsExtensionEnabled(extension_id)) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 995 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 996 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 997 | const Extension* extension = GetInstalledExtension(extension_id); |
| 998 | // |extension| can be NULL if sync disables an extension that is not |
| 999 | // installed yet. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 1000 | if (extension && |
[email protected] | 505ccdc | 2013-06-20 20:15:35 | [diff] [blame] | 1001 | disable_reason != Extension::DISABLE_RELOAD && |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 1002 | !system_->management_policy()->UserMayModifySettings(extension, NULL)) { |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 1003 | return; |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 1004 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 1005 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 1006 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 1007 | extension_prefs_->AddDisableReason(extension_id, disable_reason); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1008 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1009 | int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_DISABLED; |
| 1010 | extension = GetExtensionById(extension_id, include_mask); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1011 | if (!extension) |
| 1012 | return; |
| 1013 | |
[email protected] | 64742de3 | 2013-04-22 08:44:34 | [diff] [blame] | 1014 | // Reset the background_page_ready flag |
| 1015 | if (extensions::BackgroundInfo::HasBackgroundPage(extension)) |
| 1016 | extension_runtime_data_[extension->id()].background_page_ready = false; |
| 1017 | |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 1018 | // Move it over to the disabled list. Don't send a second unload notification |
| 1019 | // for terminated extensions being disabled. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1020 | disabled_extensions_.Insert(make_scoped_refptr(extension)); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 1021 | if (extensions_.Contains(extension->id())) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1022 | extensions_.Remove(extension->id()); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 1023 | NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); |
| 1024 | } else { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1025 | terminated_extensions_.Remove(extension->id()); |
[email protected] | 5c09479 | 2012-09-07 19:44:53 | [diff] [blame] | 1026 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1027 | |
| 1028 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1029 | } |
| 1030 | |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 1031 | void ExtensionService::DisableUserExtensions( |
| 1032 | const std::vector<std::string>& except_ids) { |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 1033 | extensions::ManagementPolicy* management_policy = |
| 1034 | system_->management_policy(); |
| 1035 | extensions::ExtensionList to_disable; |
| 1036 | |
| 1037 | for (ExtensionSet::const_iterator extension = extensions_.begin(); |
| 1038 | extension != extensions_.end(); ++extension) { |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 1039 | if (management_policy->UserMayModifySettings(extension->get(), NULL)) |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 1040 | to_disable.push_back(*extension); |
| 1041 | } |
| 1042 | for (ExtensionSet::const_iterator extension = terminated_extensions_.begin(); |
| 1043 | extension != terminated_extensions_.end(); ++extension) { |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 1044 | if (management_policy->UserMayModifySettings(extension->get(), NULL)) |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 1045 | to_disable.push_back(*extension); |
| 1046 | } |
| 1047 | |
| 1048 | for (extensions::ExtensionList::const_iterator extension = to_disable.begin(); |
| 1049 | extension != to_disable.end(); ++extension) { |
[email protected] | 3082fe3 | 2013-08-06 11:12:38 | [diff] [blame] | 1050 | if ((*extension)->was_installed_by_default() && |
| 1051 | extension_urls::IsWebstoreUpdateUrl( |
| 1052 | extensions::ManifestURL::GetUpdateURL(*extension))) |
| 1053 | continue; |
[email protected] | 1abf05e | 2013-07-09 17:04:36 | [diff] [blame] | 1054 | const std::string& id = (*extension)->id(); |
| 1055 | if (except_ids.end() == std::find(except_ids.begin(), except_ids.end(), id)) |
| 1056 | DisableExtension(id, extensions::Extension::DISABLE_USER_ACTION); |
[email protected] | e516e4c | 2013-06-12 17:41:14 | [diff] [blame] | 1057 | } |
| 1058 | } |
| 1059 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1060 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 1061 | const Extension* extension) { |
| 1062 | GrantPermissions(extension); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1063 | RecordPermissionMessagesHistogram( |
| 1064 | extension, "Extensions.Permissions_ReEnable"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1065 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 1066 | EnableExtension(extension->id()); |
| 1067 | } |
| 1068 | |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 1069 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1070 | CHECK(extension); |
| 1071 | extensions::PermissionsUpdater perms_updater(profile()); |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 1072 | perms_updater.GrantActivePermissions(extension); |
[email protected] | be08386 | 2012-09-01 03:53:45 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1075 | // static |
| 1076 | void ExtensionService::RecordPermissionMessagesHistogram( |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1077 | const Extension* extension, const char* histogram) { |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 1078 | // Since this is called from multiple sources, and since the histogram macros |
| 1079 | // use statics, we need to manually lookup the histogram ourselves. |
| 1080 | base::HistogramBase* counter = base::LinearHistogram::FactoryGet( |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1081 | histogram, |
| 1082 | 1, |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1083 | PermissionMessage::kEnumBoundary, |
| 1084 | PermissionMessage::kEnumBoundary + 1, |
[email protected] | de41555 | 2013-01-23 04:12:17 | [diff] [blame] | 1085 | base::HistogramBase::kUmaTargetedHistogramFlag); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1086 | |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1087 | PermissionMessages permissions = |
| 1088 | extensions::PermissionsData::GetPermissionMessages(extension); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1089 | if (permissions.empty()) { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1090 | counter->Add(PermissionMessage::kNone); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1091 | } else { |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 1092 | for (PermissionMessages::iterator it = permissions.begin(); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1093 | it != permissions.end(); ++it) |
| 1094 | counter->Add(it->id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1095 | } |
| 1096 | } |
| 1097 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1098 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 1099 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1100 | // was loaded, otherwise a race can arise where a renderer that is created |
| 1101 | // 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] | 1102 | // that the request context doesn't yet know about. The profile is responsible |
| 1103 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 1104 | // extension. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1105 | system_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1106 | |
[email protected] | d594931 | 2012-12-03 22:13:30 | [diff] [blame] | 1107 | // Tell renderers about the new extension, unless it's a theme (renderers |
| 1108 | // don't need to know about themes). |
[email protected] | a58f599c | 2012-12-01 03:08:19 | [diff] [blame] | 1109 | if (!extension->is_theme()) { |
[email protected] | 1964726 | 2011-12-16 09:57:49 | [diff] [blame] | 1110 | for (content::RenderProcessHost::iterator i( |
| 1111 | content::RenderProcessHost::AllHostsIterator()); |
| 1112 | !i.IsAtEnd(); i.Advance()) { |
| 1113 | content::RenderProcessHost* host = i.GetCurrentValue(); |
| 1114 | Profile* host_profile = |
| 1115 | Profile::FromBrowserContext(host->GetBrowserContext()); |
| 1116 | if (host_profile->GetOriginalProfile() == |
| 1117 | profile_->GetOriginalProfile()) { |
| 1118 | std::vector<ExtensionMsg_Loaded_Params> loaded_extensions( |
| 1119 | 1, ExtensionMsg_Loaded_Params(extension)); |
| 1120 | host->Send( |
| 1121 | new ExtensionMsg_Loaded(loaded_extensions)); |
| 1122 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1123 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1124 | } |
| 1125 | |
[email protected] | 3442a66 | 2012-01-12 08:06:17 | [diff] [blame] | 1126 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 1127 | // extension. |
| 1128 | // |
| 1129 | // NOTE: It is important that this happen after notifying the renderers about |
| 1130 | // the new extensions so that if we navigate to an extension URL in |
| 1131 | // NOTIFICATION_EXTENSION_LOADED, the renderer is guaranteed to know about it. |
| 1132 | content::NotificationService::current()->Notify( |
| 1133 | chrome::NOTIFICATION_EXTENSION_LOADED, |
| 1134 | content::Source<Profile>(profile_), |
| 1135 | content::Details<const Extension>(extension)); |
| 1136 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1137 | // Tell a random-ass collection of other subsystems about the new extension. |
| 1138 | // TODO(aa): What should we do with all this goop? Can it move into the |
| 1139 | // relevant objects via EXTENSION_LOADED? |
| 1140 | |
| 1141 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1142 | GrantRightsForExtension(extension); |
| 1143 | |
| 1144 | UpdateActiveExtensionsInCrashReporter(); |
| 1145 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1146 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1147 | // to make sure that the FaviconSource is registered with the |
| 1148 | // ChromeURLDataManager. |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1149 | if (extensions::PermissionsData::HasHostPermission( |
| 1150 | extension, GURL(chrome::kChromeUIFaviconURL))) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1151 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1152 | FaviconSource::FAVICON); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1153 | content::URLDataSource::Add(profile_, favicon_source); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1154 | } |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1155 | |
| 1156 | #if !defined(OS_ANDROID) |
| 1157 | // Same for chrome://theme/ resources. |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1158 | if (extensions::PermissionsData::HasHostPermission( |
| 1159 | extension, GURL(chrome::kChromeUIThemeURL))) { |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1160 | ThemeSource* theme_source = new ThemeSource(profile_); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1161 | content::URLDataSource::Add(profile_, theme_source); |
[email protected] | b07e606e | 2012-09-15 20:16:15 | [diff] [blame] | 1162 | } |
| 1163 | #endif |
| 1164 | |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1165 | // Same for chrome://thumb/ resources. |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 1166 | if (extensions::PermissionsData::HasHostPermission( |
| 1167 | extension, GURL(chrome::kChromeUIThumbnailURL))) { |
[email protected] | 420e6d9 | 2013-09-17 01:48:51 | [diff] [blame] | 1168 | ThumbnailSource* thumbnail_source = new ThumbnailSource(profile_, false); |
[email protected] | 24ea7a1 | 2013-01-27 23:54:53 | [diff] [blame] | 1169 | content::URLDataSource::Add(profile_, thumbnail_source); |
[email protected] | 5eddc3e | 2011-10-26 04:33:31 | [diff] [blame] | 1170 | } |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1171 | } |
| 1172 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1173 | void ExtensionService::NotifyExtensionUnloaded( |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1174 | const Extension* extension, |
| 1175 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1176 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1177 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1178 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1179 | content::Source<Profile>(profile_), |
| 1180 | content::Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1181 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1182 | for (content::RenderProcessHost::iterator i( |
| 1183 | content::RenderProcessHost::AllHostsIterator()); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1184 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1185 | content::RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1186 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1187 | Profile::FromBrowserContext(host->GetBrowserContext()); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1188 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1189 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1192 | system_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1193 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1194 | RevokeRightsForExtension(extension); |
| 1195 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1196 | #if defined(OS_CHROMEOS) |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 1197 | // Revoke external file access for the extension from its file system context. |
| 1198 | // It is safe to access the extension's storage partition at this point. The |
| 1199 | // storage partition may get destroyed only after the extension gets unloaded. |
| 1200 | GURL site = extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 1201 | GetSiteForExtensionId(extension->id()); |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 1202 | fileapi::FileSystemContext* filesystem_context = |
[email protected] | ac66e45 | 2013-01-11 09:21:23 | [diff] [blame] | 1203 | BrowserContext::GetStoragePartitionForSite(profile_, site)-> |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 1204 | GetFileSystemContext(); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 1205 | if (filesystem_context && filesystem_context->external_backend()) { |
| 1206 | filesystem_context->external_backend()-> |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1207 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1208 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1209 | #endif |
| 1210 | |
| 1211 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1212 | } |
| 1213 | |
[email protected] | 0a071a3 | 2011-02-08 00:18:24 | [diff] [blame] | 1214 | Profile* ExtensionService::profile() { |
| 1215 | return profile_; |
| 1216 | } |
| 1217 | |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 1218 | extensions::ExtensionPrefs* ExtensionService::extension_prefs() { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 1219 | return extension_prefs_; |
| 1220 | } |
| 1221 | |
[email protected] | 0d9a220 | 2011-11-09 13:48:41 | [diff] [blame] | 1222 | extensions::SettingsFrontend* ExtensionService::settings_frontend() { |
[email protected] | cccdf0aa | 2011-11-11 03:43:38 | [diff] [blame] | 1223 | return settings_frontend_.get(); |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 1224 | } |
| 1225 | |
[email protected] | e2d720aa | 2012-05-17 00:11:35 | [diff] [blame] | 1226 | extensions::ContentSettingsStore* ExtensionService::GetContentSettingsStore() { |
[email protected] | b790b07 | 2011-05-20 09:46:44 | [diff] [blame] | 1227 | return extension_prefs()->content_settings_store(); |
| 1228 | } |
| 1229 | |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1230 | bool ExtensionService::is_ready() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1231 | return ready_->is_signaled(); |
[email protected] | 25ae015 | 2011-11-18 14:40:02 | [diff] [blame] | 1232 | } |
| 1233 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1234 | base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() { |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1235 | if (file_task_runner_.get()) |
| 1236 | return file_task_runner_.get(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1237 | |
| 1238 | // We should be able to interrupt any part of extension install process during |
| 1239 | // shutdown. SKIP_ON_SHUTDOWN ensures that not started extension install tasks |
| 1240 | // will be ignored/deleted while we will block on started tasks. |
| 1241 | std::string token("ext_install-"); |
| 1242 | token.append(profile_->GetPath().AsUTF8Unsafe()); |
| 1243 | file_task_runner_ = BrowserThread::GetBlockingPool()-> |
| 1244 | GetSequencedTaskRunnerWithShutdownBehavior( |
| 1245 | BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), |
| 1246 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1247 | return file_task_runner_.get(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 1248 | } |
| 1249 | |
[email protected] | 42a0816 | 2012-03-16 18:09:11 | [diff] [blame] | 1250 | extensions::ExtensionUpdater* ExtensionService::updater() { |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 1251 | return updater_.get(); |
| 1252 | } |
| 1253 | |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 1254 | void ExtensionService::CheckManagementPolicy() { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1255 | std::vector<std::string> to_be_removed; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1256 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1257 | // Loop through extensions list, unload installed extensions. |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1258 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1259 | iter != extensions_.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1260 | const Extension* extension = (iter->get()); |
[email protected] | 4ee07c6 | 2012-08-21 12:40:42 | [diff] [blame] | 1261 | if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1262 | to_be_removed.push_back(extension->id()); |
| 1263 | } |
| 1264 | |
| 1265 | // UnloadExtension will change the extensions_ list. So, we should |
| 1266 | // call it outside the iterator loop. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1267 | for (size_t i = 0; i < to_be_removed.size(); ++i) |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1268 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1269 | } |
| 1270 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1271 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1272 | if (updater()) { |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1273 | if (AreAllExternalProvidersReady()) { |
| 1274 | updater()->CheckSoon(); |
| 1275 | } else { |
| 1276 | // Sync can start updating before all the external providers are ready |
| 1277 | // during startup. Start the update as soon as those providers are ready, |
| 1278 | // but not before. |
| 1279 | update_once_all_providers_are_ready_ = true; |
| 1280 | } |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1281 | } else { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1282 | LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1283 | } |
| 1284 | } |
| 1285 | |
[email protected] | 3f98fd9 | 2012-11-17 15:54:29 | [diff] [blame] | 1286 | syncer::SyncMergeResult ExtensionService::MergeDataAndStartSyncing( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1287 | syncer::ModelType type, |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1288 | const syncer::SyncDataList& initial_sync_data, |
| 1289 | scoped_ptr<syncer::SyncChangeProcessor> sync_processor, |
| 1290 | scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1291 | CHECK(sync_processor.get()); |
[email protected] | 5d36e05 | 2012-04-20 20:12:28 | [diff] [blame] | 1292 | CHECK(sync_error_factory.get()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1293 | |
| 1294 | switch (type) { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1295 | case syncer::EXTENSIONS: |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1296 | extension_sync_bundle_.SetupSync(sync_processor.release(), |
[email protected] | 5d36e05 | 2012-04-20 20:12:28 | [diff] [blame] | 1297 | sync_error_factory.release(), |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1298 | initial_sync_data); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1299 | break; |
| 1300 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1301 | case syncer::APPS: |
[email protected] | 5d36e05 | 2012-04-20 20:12:28 | [diff] [blame] | 1302 | app_sync_bundle_.SetupSync(sync_processor.release(), |
| 1303 | sync_error_factory.release(), |
| 1304 | initial_sync_data); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1305 | break; |
| 1306 | |
| 1307 | default: |
| 1308 | LOG(FATAL) << "Got " << type << " ModelType"; |
| 1309 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1310 | |
[email protected] | b1417ab | 2011-12-15 17:09:11 | [diff] [blame] | 1311 | // Process local extensions. |
| 1312 | // TODO(yoz): Determine whether pending extensions should be considered too. |
| 1313 | // See crbug.com/104399. |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1314 | syncer::SyncDataList sync_data_list = GetAllSyncData(type); |
| 1315 | syncer::SyncChangeList sync_change_list; |
| 1316 | for (syncer::SyncDataList::const_iterator i = sync_data_list.begin(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1317 | i != sync_data_list.end(); |
| 1318 | ++i) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1319 | switch (type) { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1320 | case syncer::EXTENSIONS: |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1321 | sync_change_list.push_back( |
| 1322 | extension_sync_bundle_.CreateSyncChange(*i)); |
| 1323 | break; |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1324 | case syncer::APPS: |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1325 | sync_change_list.push_back(app_sync_bundle_.CreateSyncChange(*i)); |
| 1326 | break; |
| 1327 | default: |
| 1328 | LOG(FATAL) << "Got " << type << " ModelType"; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1329 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1330 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1331 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1332 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1333 | if (type == syncer::EXTENSIONS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1334 | extension_sync_bundle_.ProcessSyncChangeList(sync_change_list); |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1335 | } else if (type == syncer::APPS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1336 | app_sync_bundle_.ProcessSyncChangeList(sync_change_list); |
| 1337 | } |
[email protected] | 0ffd9e5 | 2012-01-26 21:44:34 | [diff] [blame] | 1338 | |
[email protected] | 3f98fd9 | 2012-11-17 15:54:29 | [diff] [blame] | 1339 | return syncer::SyncMergeResult(type); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1340 | } |
| 1341 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1342 | void ExtensionService::StopSyncing(syncer::ModelType type) { |
| 1343 | if (type == syncer::APPS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1344 | app_sync_bundle_.Reset(); |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1345 | } else if (type == syncer::EXTENSIONS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1346 | extension_sync_bundle_.Reset(); |
| 1347 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1348 | } |
| 1349 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1350 | syncer::SyncDataList ExtensionService::GetAllSyncData( |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1351 | syncer::ModelType type) const { |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1352 | if (type == syncer::EXTENSIONS) |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1353 | return extension_sync_bundle_.GetAllSyncData(); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1354 | if (type == syncer::APPS) |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1355 | return app_sync_bundle_.GetAllSyncData(); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1356 | |
| 1357 | // We should only get sync data for extensions and apps. |
| 1358 | NOTREACHED(); |
| 1359 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1360 | return syncer::SyncDataList(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1361 | } |
| 1362 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1363 | syncer::SyncError ExtensionService::ProcessSyncChanges( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1364 | const tracked_objects::Location& from_here, |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1365 | const syncer::SyncChangeList& change_list) { |
| 1366 | for (syncer::SyncChangeList::const_iterator i = change_list.begin(); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1367 | i != change_list.end(); |
| 1368 | ++i) { |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1369 | syncer::ModelType type = i->sync_data().GetDataType(); |
| 1370 | if (type == syncer::EXTENSIONS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1371 | extension_sync_bundle_.ProcessSyncChange( |
| 1372 | extensions::ExtensionSyncData(*i)); |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1373 | } else if (type == syncer::APPS) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1374 | app_sync_bundle_.ProcessSyncChange(extensions::AppSyncData(*i)); |
| 1375 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1376 | } |
| 1377 | |
[email protected] | 0ffd9e5 | 2012-01-26 21:44:34 | [diff] [blame] | 1378 | extension_prefs()->extension_sorting()->FixNTPOrdinalCollisions(); |
| 1379 | |
[email protected] | 65f17355 | 2012-06-28 22:43:58 | [diff] [blame] | 1380 | return syncer::SyncError(); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1381 | } |
| 1382 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1383 | extensions::ExtensionSyncData ExtensionService::GetExtensionSyncData( |
| 1384 | const Extension& extension) const { |
| 1385 | return extensions::ExtensionSyncData(extension, |
| 1386 | IsExtensionEnabled(extension.id()), |
| 1387 | IsIncognitoEnabled(extension.id())); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1390 | extensions::AppSyncData ExtensionService::GetAppSyncData( |
| 1391 | const Extension& extension) const { |
| 1392 | return extensions::AppSyncData( |
| 1393 | extension, |
| 1394 | IsExtensionEnabled(extension.id()), |
| 1395 | IsIncognitoEnabled(extension.id()), |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1396 | extension_prefs_->extension_sorting()->GetAppLaunchOrdinal( |
| 1397 | extension.id()), |
| 1398 | extension_prefs_->extension_sorting()->GetPageOrdinal(extension.id())); |
| 1399 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1400 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1401 | std::vector<extensions::ExtensionSyncData> |
| 1402 | ExtensionService::GetExtensionSyncDataList() const { |
| 1403 | std::vector<extensions::ExtensionSyncData> extension_sync_list; |
| 1404 | extension_sync_bundle_.GetExtensionSyncDataListHelper(extensions_, |
| 1405 | &extension_sync_list); |
| 1406 | extension_sync_bundle_.GetExtensionSyncDataListHelper(disabled_extensions_, |
| 1407 | &extension_sync_list); |
| 1408 | extension_sync_bundle_.GetExtensionSyncDataListHelper(terminated_extensions_, |
| 1409 | &extension_sync_list); |
| 1410 | |
| 1411 | std::vector<extensions::ExtensionSyncData> pending_extensions = |
| 1412 | extension_sync_bundle_.GetPendingData(); |
| 1413 | extension_sync_list.insert(extension_sync_list.begin(), |
| 1414 | pending_extensions.begin(), |
| 1415 | pending_extensions.end()); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1416 | |
| 1417 | return extension_sync_list; |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1418 | } |
| 1419 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1420 | std::vector<extensions::AppSyncData> ExtensionService::GetAppSyncDataList() |
| 1421 | const { |
| 1422 | std::vector<extensions::AppSyncData> app_sync_list; |
| 1423 | app_sync_bundle_.GetAppSyncDataListHelper(extensions_, &app_sync_list); |
| 1424 | app_sync_bundle_.GetAppSyncDataListHelper(disabled_extensions_, |
| 1425 | &app_sync_list); |
| 1426 | app_sync_bundle_.GetAppSyncDataListHelper(terminated_extensions_, |
| 1427 | &app_sync_list); |
| 1428 | |
| 1429 | std::vector<extensions::AppSyncData> pending_apps = |
| 1430 | app_sync_bundle_.GetPendingData(); |
| 1431 | app_sync_list.insert(app_sync_list.begin(), |
| 1432 | pending_apps.begin(), |
| 1433 | pending_apps.end()); |
| 1434 | |
| 1435 | return app_sync_list; |
| 1436 | } |
| 1437 | |
| 1438 | bool ExtensionService::ProcessExtensionSyncData( |
| 1439 | const extensions::ExtensionSyncData& extension_sync_data) { |
| 1440 | if (!ProcessExtensionSyncDataHelper(extension_sync_data, |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1441 | syncer::EXTENSIONS)) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1442 | extension_sync_bundle_.AddPendingExtension(extension_sync_data.id(), |
| 1443 | extension_sync_data); |
| 1444 | CheckForUpdatesSoon(); |
| 1445 | return false; |
| 1446 | } |
| 1447 | |
| 1448 | return true; |
| 1449 | } |
| 1450 | |
| 1451 | bool ExtensionService::ProcessAppSyncData( |
| 1452 | const extensions::AppSyncData& app_sync_data) { |
| 1453 | const std::string& id = app_sync_data.id(); |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1454 | |
| 1455 | if (app_sync_data.app_launch_ordinal().IsValid() && |
| 1456 | app_sync_data.page_ordinal().IsValid()) { |
| 1457 | extension_prefs_->extension_sorting()->SetAppLaunchOrdinal( |
| 1458 | id, |
| 1459 | app_sync_data.app_launch_ordinal()); |
| 1460 | extension_prefs_->extension_sorting()->SetPageOrdinal( |
| 1461 | id, |
| 1462 | app_sync_data.page_ordinal()); |
| 1463 | } |
| 1464 | |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1465 | if (!ProcessExtensionSyncDataHelper(app_sync_data.extension_sync_data(), |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1466 | syncer::APPS)) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1467 | app_sync_bundle_.AddPendingApp(id, app_sync_data); |
| 1468 | CheckForUpdatesSoon(); |
| 1469 | return false; |
| 1470 | } |
| 1471 | |
| 1472 | return true; |
| 1473 | } |
| 1474 | |
| 1475 | bool ExtensionService::IsCorrectSyncType(const Extension& extension, |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1476 | syncer::ModelType type) const { |
| 1477 | if (type == syncer::EXTENSIONS && |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1478 | extensions::sync_helper::IsSyncableExtension(&extension)) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1479 | return true; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1480 | } |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1481 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1482 | if (type == syncer::APPS && |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1483 | extensions::sync_helper::IsSyncableApp(&extension)) { |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1484 | return true; |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1485 | } |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1486 | |
| 1487 | return false; |
| 1488 | } |
| 1489 | |
| 1490 | bool ExtensionService::ProcessExtensionSyncDataHelper( |
| 1491 | const extensions::ExtensionSyncData& extension_sync_data, |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1492 | syncer::ModelType type) { |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1493 | const std::string& id = extension_sync_data.id(); |
[email protected] | 96e989b | 2011-08-30 19:35:06 | [diff] [blame] | 1494 | const Extension* extension = GetInstalledExtension(id); |
| 1495 | |
| 1496 | // TODO(bolms): we should really handle this better. The particularly bad |
| 1497 | // case is where an app becomes an extension or vice versa, and we end up with |
| 1498 | // a zombie extension that won't go away. |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1499 | if (extension && !IsCorrectSyncType(*extension, type)) |
| 1500 | return true; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1501 | |
| 1502 | // Handle uninstalls first. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1503 | if (extension_sync_data.uninstalled()) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1504 | if (!UninstallExtensionHelper(this, id)) { |
| 1505 | LOG(WARNING) << "Could not uninstall extension " << id |
| 1506 | << " for sync"; |
| 1507 | } |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1508 | return true; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1509 | } |
| 1510 | |
[email protected] | caf2d44 | 2012-05-04 10:00:50 | [diff] [blame] | 1511 | // Extension from sync was uninstalled by the user as external extensions. |
| 1512 | // Honor user choice and skip installation/enabling. |
| 1513 | if (IsExternalExtensionUninstalled(id)) { |
| 1514 | LOG(WARNING) << "Extension with id " << id |
| 1515 | << " from sync was uninstalled as external extension"; |
| 1516 | return true; |
| 1517 | } |
| 1518 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1519 | // Set user settings. |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1520 | // If the extension has been disabled from sync, it may not have |
| 1521 | // been installed yet, so we don't know if the disable reason was a |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1522 | // permissions increase. That will be updated once CheckPermissionsIncrease |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1523 | // is called for it. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1524 | if (extension_sync_data.enabled()) |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1525 | EnableExtension(id); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1526 | else |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 1527 | DisableExtension(id, Extension::DISABLE_UNKNOWN_FROM_SYNC); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1528 | |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1529 | // We need to cache some version information here because setting the |
| 1530 | // incognito flag invalidates the |extension| pointer (it reloads the |
| 1531 | // extension). |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 1532 | bool extension_installed = (extension != NULL); |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1533 | int result = extension ? |
| 1534 | extension->version()->CompareTo(extension_sync_data.version()) : 0; |
| 1535 | SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); |
| 1536 | extension = NULL; // No longer safe to use. |
| 1537 | |
| 1538 | if (extension_installed) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1539 | // If the extension is already installed, check if it's outdated. |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1540 | if (result < 0) { |
| 1541 | // Extension is outdated. |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1542 | return false; |
[email protected] | b020dc1 | 2011-12-06 04:35:42 | [diff] [blame] | 1543 | } |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1544 | } else { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1545 | // TODO(akalin): Replace silent update with a list of enabled |
| 1546 | // permissions. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1547 | const bool kInstallSilently = true; |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1548 | |
[email protected] | a4a14765 | 2012-07-03 23:41:32 | [diff] [blame] | 1549 | CHECK(type == syncer::EXTENSIONS || type == syncer::APPS); |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1550 | extensions::PendingExtensionInfo::ShouldAllowInstallPredicate filter = |
| 1551 | (type == syncer::APPS) ? extensions::sync_helper::IsSyncableApp : |
| 1552 | extensions::sync_helper::IsSyncableExtension; |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1553 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1554 | if (!pending_extension_manager()->AddFromSync( |
| 1555 | id, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1556 | extension_sync_data.update_url(), |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1557 | filter, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1558 | kInstallSilently)) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1559 | LOG(WARNING) << "Could not add pending extension for " << id; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1560 | // This means that the extension is already pending installation, with a |
| 1561 | // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 1562 | // never be removed (we'll never install a syncable version of the |
| 1563 | // extension), so that GetAllSyncData() continues to send it. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1564 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1565 | // Track pending extensions so that we can return them in GetAllSyncData(). |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1566 | return false; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1567 | } |
[email protected] | 5db9ada | 2012-04-11 13:48:20 | [diff] [blame] | 1568 | |
| 1569 | return true; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1570 | } |
| 1571 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1572 | bool ExtensionService::IsIncognitoEnabled( |
| 1573 | const std::string& extension_id) const { |
[email protected] | cdc7b1f4 | 2012-12-07 19:39:48 | [diff] [blame] | 1574 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1575 | if (extension && !extension->can_be_incognito_enabled()) |
| 1576 | return false; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1577 | // If this is an existing component extension we always allow it to |
| 1578 | // work in incognito mode. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1579 | if (extension && extension->location() == Manifest::COMPONENT) |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 1580 | return true; |
[email protected] | fc05749a | 2013-07-10 06:59:11 | [diff] [blame] | 1581 | if (extension && extension->force_incognito_enabled()) |
| 1582 | return true; |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 1583 | |
| 1584 | // Check the prefs. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1585 | return extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 1586 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1587 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1588 | void ExtensionService::SetIsIncognitoEnabled( |
| 1589 | const std::string& extension_id, bool enabled) { |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1590 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | cdc7b1f4 | 2012-12-07 19:39:48 | [diff] [blame] | 1591 | if (extension && !extension->can_be_incognito_enabled()) |
| 1592 | return; |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1593 | if (extension && extension->location() == Manifest::COMPONENT) { |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 1594 | // This shouldn't be called for component extensions unless they are |
| 1595 | // syncable. |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 1596 | DCHECK(extensions::sync_helper::IsSyncable(extension)); |
[email protected] | b873cd9 | 2012-02-09 21:51:48 | [diff] [blame] | 1597 | |
| 1598 | // If we are here, make sure the we aren't trying to change the value. |
| 1599 | DCHECK_EQ(enabled, IsIncognitoEnabled(extension_id)); |
| 1600 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1601 | return; |
| 1602 | } |
| 1603 | |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1604 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 1605 | // if the value changed and the extension is actually enabled, since there is |
| 1606 | // no UI otherwise. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1607 | bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1608 | if (enabled == old_enabled) |
| 1609 | return; |
| 1610 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1611 | extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1612 | |
[email protected] | ffbf3f1 | 2011-12-09 22:10:33 | [diff] [blame] | 1613 | bool extension_is_enabled = extensions_.Contains(extension_id); |
[email protected] | bd9892eb | 2011-11-11 19:41:34 | [diff] [blame] | 1614 | |
| 1615 | // When we reload the extension the ID may be invalidated if we've passed it |
| 1616 | // by const ref everywhere. Make a copy to be safe. |
| 1617 | std::string id = extension_id; |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1618 | if (extension_is_enabled) |
[email protected] | ffbf3f1 | 2011-12-09 22:10:33 | [diff] [blame] | 1619 | ReloadExtension(id); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1620 | |
[email protected] | 406b5a9 | 2011-11-08 11:58:26 | [diff] [blame] | 1621 | // Reloading the extension invalidates the |extension| pointer. |
[email protected] | bd9892eb | 2011-11-11 19:41:34 | [diff] [blame] | 1622 | extension = GetInstalledExtension(id); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1623 | if (extension) |
| 1624 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1625 | } |
| 1626 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 1627 | bool ExtensionService::CanCrossIncognito(const Extension* extension) const { |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1628 | // We allow the extension to see events and data from another profile iff it |
| 1629 | // uses "spanning" behavior and it has incognito access. "split" mode |
| 1630 | // extensions only see events for a matching profile. |
[email protected] | 0c41298f | 2011-09-13 21:17:22 | [diff] [blame] | 1631 | CHECK(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1632 | return IsIncognitoEnabled(extension->id()) && |
[email protected] | 06492ed | 2013-03-24 22:13:14 | [diff] [blame] | 1633 | !extensions::IncognitoInfo::IsSplitMode(extension); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1634 | } |
| 1635 | |
[email protected] | 5ef7b00 | 2011-05-12 23:16:20 | [diff] [blame] | 1636 | bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
| 1637 | if (extension->is_hosted_app()) |
| 1638 | return true; |
| 1639 | // Packaged apps and regular extensions need to be enabled specifically for |
| 1640 | // incognito (and split mode should be set). |
[email protected] | 06492ed | 2013-03-24 22:13:14 | [diff] [blame] | 1641 | return extensions::IncognitoInfo::IsSplitMode(extension) && |
[email protected] | 5ef7b00 | 2011-05-12 23:16:20 | [diff] [blame] | 1642 | IsIncognitoEnabled(extension->id()); |
| 1643 | } |
| 1644 | |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1645 | void ExtensionService::OnExtensionMoved( |
| 1646 | const std::string& moved_extension_id, |
| 1647 | const std::string& predecessor_extension_id, |
| 1648 | const std::string& successor_extension_id) { |
[email protected] | 3569b50 | 2012-01-12 20:08:23 | [diff] [blame] | 1649 | extension_prefs_->extension_sorting()->OnExtensionMoved( |
| 1650 | moved_extension_id, |
| 1651 | predecessor_extension_id, |
| 1652 | successor_extension_id); |
[email protected] | 168389f | 2011-12-20 17:12:48 | [diff] [blame] | 1653 | |
| 1654 | const Extension* extension = GetInstalledExtension(moved_extension_id); |
| 1655 | if (extension) |
| 1656 | SyncExtensionChangeIfNeeded(*extension); |
| 1657 | } |
| 1658 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 1659 | bool ExtensionService::AllowFileAccess(const Extension* extension) const { |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1660 | return (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 1661 | switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1662 | extension_prefs_->AllowFileAccess(extension->id())); |
| 1663 | } |
| 1664 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1665 | void ExtensionService::SetAllowFileAccess(const Extension* extension, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1666 | bool allow) { |
| 1667 | // Reload to update browser state. Only bother if the value changed and the |
| 1668 | // extension is actually enabled, since there is no UI otherwise. |
| 1669 | bool old_allow = AllowFileAccess(extension); |
| 1670 | if (allow == old_allow) |
| 1671 | return; |
| 1672 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1673 | extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1674 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1675 | bool extension_is_enabled = extensions_.Contains(extension->id()); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1676 | if (extension_is_enabled) |
| 1677 | ReloadExtension(extension->id()); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1678 | } |
| 1679 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1680 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 1681 | // are typically part of some larger client application package. To support |
| 1682 | // these, the extension will register its location in the the preferences file |
| 1683 | // (and also, on Windows, in the registry) and this code will periodically |
| 1684 | // check that location for a .crx file, which it will then install locally if |
| 1685 | // a new version is available. |
| 1686 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 1687 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1688 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1689 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1690 | |
| 1691 | // Note that this installation is intentionally silent (since it didn't |
| 1692 | // go through the front-end). Extensions that are registered in this |
| 1693 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1694 | // trusted. In general, if something has HKLM or filesystem access, |
| 1695 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1696 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1697 | // Ask each external extension provider to give us a call back for each |
| 1698 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1699 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1700 | for (i = external_extension_providers_.begin(); |
| 1701 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1702 | extensions::ExternalProviderInterface* provider = i->get(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1703 | provider->VisitRegisteredExtension(); |
| 1704 | } |
| 1705 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1706 | // Do any required work that we would have done after completion of all |
| 1707 | // providers. |
| 1708 | if (external_extension_providers_.empty()) { |
| 1709 | OnAllExternalProvidersReady(); |
| 1710 | } |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1711 | } |
| 1712 | |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1713 | void ExtensionService::OnExternalProviderReady( |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1714 | const extensions::ExternalProviderInterface* provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1715 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1716 | CHECK(provider->IsReady()); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1717 | |
| 1718 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1719 | // if all of them are finished. So we check them first. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1720 | if (AreAllExternalProvidersReady()) |
| 1721 | OnAllExternalProvidersReady(); |
| 1722 | } |
| 1723 | |
| 1724 | bool ExtensionService::AreAllExternalProvidersReady() const { |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 1725 | extensions::ProviderCollection::const_iterator i; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1726 | for (i = external_extension_providers_.begin(); |
| 1727 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1728 | if (!i->get()->IsReady()) |
| 1729 | return false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1730 | } |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1731 | return true; |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | void ExtensionService::OnAllExternalProvidersReady() { |
| 1735 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1736 | base::TimeDelta elapsed = base::Time::Now() - profile_->GetStartTime(); |
| 1737 | UMA_HISTOGRAM_TIMES("Extension.ExternalProvidersReadyAfter", elapsed); |
[email protected] | 50067e5 | 2011-10-20 23:17:07 | [diff] [blame] | 1738 | |
| 1739 | // Install any pending extensions. |
[email protected] | 94fde23 | 2012-04-27 10:22:30 | [diff] [blame] | 1740 | if (update_once_all_providers_are_ready_ && updater()) { |
| 1741 | update_once_all_providers_are_ready_ = false; |
[email protected] | 42774e4 | 2012-11-14 21:01:06 | [diff] [blame] | 1742 | updater()->CheckNow(extensions::ExtensionUpdater::CheckParams()); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | // Uninstall all the unclaimed extensions. |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 1746 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1747 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1748 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1749 | ExtensionInfo* info = extensions_info->at(i).get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1750 | if (Manifest::IsExternalLocation(info->extension_location)) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1751 | CheckExternalUninstall(info->extension_id); |
| 1752 | } |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1753 | IdentifyAlertableExtensions(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void ExtensionService::IdentifyAlertableExtensions() { |
| 1757 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1758 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1759 | // Build up the lists of extensions that require acknowledgment. If this is |
| 1760 | // the first time, grandfather extensions that would have caused |
| 1761 | // notification. |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1762 | extension_error_ui_.reset(ExtensionErrorUI::Create(this)); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1763 | |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1764 | bool did_show_alert = false; |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1765 | if (PopulateExtensionErrorUI(extension_error_ui_.get())) { |
[email protected] | 460c671 | 2013-04-24 07:20:01 | [diff] [blame] | 1766 | if (!is_first_run_) { |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1767 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1768 | did_show_alert = extension_error_ui_->ShowErrorInBubbleView(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1769 | } else { |
| 1770 | // First run. Just acknowledge all the extensions, silently, by |
| 1771 | // shortcutting the display of the UI and going straight to the |
| 1772 | // callback for pressing the Accept button. |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1773 | HandleExtensionAlertAccept(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1774 | } |
| 1775 | } |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1776 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1777 | UpdateExternalExtensionAlert(); |
| 1778 | |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1779 | if (!did_show_alert) |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1780 | extension_error_ui_.reset(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1781 | } |
| 1782 | |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1783 | bool ExtensionService::PopulateExtensionErrorUI( |
| 1784 | ExtensionErrorUI* extension_error_ui) { |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1785 | bool needs_alert = false; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1786 | |
| 1787 | // Extensions that are blacklisted. |
| 1788 | for (ExtensionSet::const_iterator it = blacklisted_extensions_.begin(); |
| 1789 | it != blacklisted_extensions_.end(); ++it) { |
| 1790 | std::string id = (*it)->id(); |
| 1791 | if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(id)) { |
| 1792 | extension_error_ui->AddBlacklistedExtension(id); |
| 1793 | needs_alert = true; |
| 1794 | } |
| 1795 | } |
| 1796 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1797 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 1798 | iter != extensions_.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1799 | const Extension* e = iter->get(); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1800 | |
| 1801 | // Extensions disabled by policy. Note: this no longer includes blacklisted |
| 1802 | // extensions, though we still show the same UI. |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 1803 | if (!system_->management_policy()->UserMayLoad(e, NULL)) { |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1804 | if (!extension_prefs_->IsBlacklistedExtensionAcknowledged(e->id())) { |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1805 | extension_error_ui->AddBlacklistedExtension(e->id()); |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1806 | needs_alert = true; |
| 1807 | } |
| 1808 | } |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1809 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1810 | |
[email protected] | 07c9f2f4 | 2012-02-29 18:45:22 | [diff] [blame] | 1811 | return needs_alert; |
| 1812 | } |
| 1813 | |
[email protected] | a9aa593 | 2012-01-25 08:27:40 | [diff] [blame] | 1814 | void ExtensionService::HandleExtensionAlertClosed() { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1815 | const ExtensionIdSet* extension_ids = |
| 1816 | extension_error_ui_->get_blacklisted_extension_ids(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1817 | for (ExtensionIdSet::const_iterator iter = extension_ids->begin(); |
| 1818 | iter != extension_ids->end(); ++iter) { |
| 1819 | extension_prefs_->AcknowledgeBlacklistedExtension(*iter); |
| 1820 | } |
[email protected] | 879a609 | 2013-03-06 04:12:50 | [diff] [blame] | 1821 | extension_error_ui_.reset(); |
| 1822 | } |
| 1823 | |
| 1824 | void ExtensionService::HandleExtensionAlertAccept() { |
[email protected] | 73a85e01 | 2013-04-04 10:45:30 | [diff] [blame] | 1825 | extension_error_ui_->Close(); |
[email protected] | e5af875f | 2011-10-10 21:09:14 | [diff] [blame] | 1826 | } |
| 1827 | |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1828 | void ExtensionService::AcknowledgeExternalExtension(const std::string& id) { |
| 1829 | extension_prefs_->AcknowledgeExternalExtension(id); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1830 | UpdateExternalExtensionAlert(); |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 1831 | } |
| 1832 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1833 | bool ExtensionService::IsUnacknowledgedExternalExtension( |
| 1834 | const Extension* extension) { |
[email protected] | b82d18da | 2012-11-09 00:11:32 | [diff] [blame] | 1835 | if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
| 1836 | return false; |
| 1837 | |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 1838 | return (Manifest::IsExternalLocation(extension->location()) && |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1839 | !extension_prefs_->IsExternalExtensionAcknowledged(extension->id()) && |
| 1840 | !(extension_prefs_->GetDisableReasons(extension->id()) & |
| 1841 | Extension::DISABLE_SIDELOAD_WIPEOUT)); |
| 1842 | } |
| 1843 | |
[email protected] | 8922698 | 2012-07-16 20:09:18 | [diff] [blame] | 1844 | void ExtensionService::HandleExtensionAlertDetails() { |
| 1845 | extension_error_ui_->ShowExtensions(); |
[email protected] | 73a85e01 | 2013-04-04 10:45:30 | [diff] [blame] | 1846 | // ShowExtensions may cause the error UI to close synchronously, e.g. if it |
| 1847 | // causes a navigation. |
| 1848 | if (extension_error_ui_) |
| 1849 | extension_error_ui_->Close(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 1850 | } |
| 1851 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1852 | void ExtensionService::UpdateExternalExtensionAlert() { |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 1853 | if (!FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1854 | return; |
| 1855 | |
| 1856 | const Extension* extension = NULL; |
| 1857 | for (ExtensionSet::const_iterator iter = disabled_extensions_.begin(); |
| 1858 | iter != disabled_extensions_.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1859 | const Extension* e = iter->get(); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1860 | if (IsUnacknowledgedExternalExtension(e)) { |
| 1861 | extension = e; |
| 1862 | break; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | if (extension) { |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1867 | if (!extensions::HasExternalInstallError(this)) { |
| 1868 | if (extension_prefs_->IncrementAcknowledgePromptCount(extension->id()) > |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1869 | kMaxExtensionAcknowledgePromptCount) { |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1870 | // Stop prompting for this extension, and check if there's another |
| 1871 | // one that needs prompting. |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1872 | extension_prefs_->AcknowledgeExternalExtension(extension->id()); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1873 | UpdateExternalExtensionAlert(); |
| 1874 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 1875 | EXTERNAL_EXTENSION_IGNORED, |
| 1876 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 1877 | if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
| 1878 | UMA_HISTOGRAM_ENUMERATION( |
| 1879 | "Extensions.ExternalExtensionEventWebstore", |
| 1880 | EXTERNAL_EXTENSION_IGNORED, |
| 1881 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 1882 | } else { |
| 1883 | UMA_HISTOGRAM_ENUMERATION( |
| 1884 | "Extensions.ExternalExtensionEventNonWebstore", |
| 1885 | EXTERNAL_EXTENSION_IGNORED, |
| 1886 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 1887 | } |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 1888 | return; |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1889 | } |
[email protected] | b3aa718 | 2013-04-25 04:45:23 | [diff] [blame] | 1890 | if (is_first_run_) |
| 1891 | extension_prefs_->SetExternalInstallFirstRun(extension->id()); |
| 1892 | // first_run is true if the extension was installed during a first run |
| 1893 | // (even if it's post-first run now). |
| 1894 | bool first_run = extension_prefs_->IsExternalInstallFirstRun( |
| 1895 | extension->id()); |
| 1896 | extensions::AddExternalInstallError(this, extension, first_run); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1897 | } |
| 1898 | } else { |
| 1899 | extensions::RemoveExternalInstallError(this); |
| 1900 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 1901 | } |
| 1902 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1903 | void ExtensionService::UnloadExtension( |
| 1904 | const std::string& extension_id, |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1905 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 1906 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1907 | int include_mask = INCLUDE_EVERYTHING & ~INCLUDE_TERMINATED; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1908 | scoped_refptr<const Extension> extension( |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 1909 | GetExtensionById(extension_id, include_mask)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1910 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1911 | // This method can be called via PostTask, so the extension may have been |
| 1912 | // unloaded by the time this runs. |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 1913 | if (!extension.get()) { |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1914 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 1915 | // clean up its RequestContexts. |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1916 | system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1917 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1918 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1919 | |
[email protected] | 20c8b94 | 2013-05-26 02:03:40 | [diff] [blame] | 1920 | // If uninstalling let RuntimeEventRouter know. |
| 1921 | if (reason == extension_misc::UNLOAD_REASON_UNINSTALL) |
| 1922 | extensions::RuntimeEventRouter::OnExtensionUninstalled( |
| 1923 | profile_, extension_id); |
| 1924 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1925 | // Keep information about the extension so that we can reload it later |
| 1926 | // even if it's not permanently installed. |
| 1927 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1928 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1929 | // Clean up if the extension is meant to be enabled after a reload. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 1930 | reloading_extensions_.erase(extension->id()); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1931 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 1932 | // Clean up runtime data. |
| 1933 | extension_runtime_data_.erase(extension_id); |
| 1934 | |
[email protected] | 060d497 | 2012-07-19 17:22:39 | [diff] [blame] | 1935 | if (disabled_extensions_.Contains(extension->id())) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1936 | disabled_extensions_.Remove(extension->id()); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1937 | // Make sure the profile cleans up its RequestContexts when an already |
| 1938 | // disabled extension is unloaded (since they are also tracking the disabled |
| 1939 | // extensions). |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 1940 | system_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 60a174a | 2013-08-02 20:29:28 | [diff] [blame] | 1941 | } else { |
| 1942 | // Remove the extension from our list. |
| 1943 | extensions_.Remove(extension->id()); |
| 1944 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1945 | } |
| 1946 | |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 1947 | content::NotificationService::current()->Notify( |
| 1948 | chrome::NOTIFICATION_EXTENSION_REMOVED, |
| 1949 | content::Source<Profile>(profile_), |
| 1950 | content::Details<const Extension>(extension.get())); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1951 | } |
| 1952 | |
[email protected] | 8b1ec20 | 2013-09-05 02:09:50 | [diff] [blame] | 1953 | void ExtensionService::RemoveComponentExtension( |
| 1954 | const std::string& extension_id) { |
| 1955 | scoped_refptr<const Extension> extension( |
| 1956 | GetExtensionById(extension_id, false)); |
| 1957 | UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); |
| 1958 | content::NotificationService::current()->Notify( |
| 1959 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 1960 | content::Source<Profile>(profile_), |
| 1961 | content::Details<const Extension>(extension.get())); |
| 1962 | } |
| 1963 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1964 | void ExtensionService::UnloadAllExtensions() { |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 1965 | profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1966 | |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 1967 | extensions_.Clear(); |
| 1968 | disabled_extensions_.Clear(); |
| 1969 | terminated_extensions_.Clear(); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 1970 | extension_runtime_data_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 1971 | |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 1972 | // TODO(erikkay) should there be a notification for this? We can't use |
| 1973 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 1974 | // or uninstalled, and UnloadAll is just part of shutdown. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1975 | } |
| 1976 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1977 | void ExtensionService::ReloadExtensions() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1978 | UnloadAllExtensions(); |
[email protected] | eac8833 | 2012-12-26 17:57:45 | [diff] [blame] | 1979 | component_loader_->LoadAll(); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 1980 | extensions::InstalledLoader(this).LoadAllExtensions(); |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 1981 | // Don't call SetReadyAndNotifyListeners() since tests call this multiple |
| 1982 | // times. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1983 | } |
| 1984 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1985 | void ExtensionService::GarbageCollectExtensions() { |
[email protected] | c04fd3dd | 2013-09-05 08:20:10 | [diff] [blame] | 1986 | #if defined(OS_CHROMEOS) |
| 1987 | if (disable_garbage_collection_) |
| 1988 | return; |
| 1989 | #endif |
| 1990 | |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 1991 | if (extension_prefs_->pref_service()->ReadOnly()) |
| 1992 | return; |
| 1993 | |
[email protected] | 9bd9a686 | 2012-11-29 09:24:22 | [diff] [blame] | 1994 | if (pending_extension_manager()->HasPendingExtensions()) { |
| 1995 | // Don't garbage collect while there are pending installations, which may |
| 1996 | // be using the temporary installation directory. Try to garbage collect |
| 1997 | // again later. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 1998 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 9bd9a686 | 2012-11-29 09:24:22 | [diff] [blame] | 1999 | FROM_HERE, |
| 2000 | base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), |
| 2001 | base::TimeDelta::FromSeconds(kGarbageCollectRetryDelay)); |
| 2002 | return; |
| 2003 | } |
| 2004 | |
[email protected] | 4575961 | 2012-07-10 17:21:23 | [diff] [blame] | 2005 | scoped_ptr<extensions::ExtensionPrefs::ExtensionsInfo> info( |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 2006 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 2007 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2008 | std::multimap<std::string, base::FilePath> extension_paths; |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 2009 | for (size_t i = 0; i < info->size(); ++i) |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2010 | extension_paths.insert(std::make_pair(info->at(i)->extension_id, |
| 2011 | info->at(i)->extension_path)); |
| 2012 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2013 | info = extension_prefs_->GetAllDelayedInstallInfo(); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2014 | for (size_t i = 0; i < info->size(); ++i) |
| 2015 | extension_paths.insert(std::make_pair(info->at(i)->extension_id, |
| 2016 | info->at(i)->extension_path)); |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 2017 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 2018 | if (!GetFileTaskRunner()->PostTask( |
| 2019 | FROM_HERE, |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 2020 | base::Bind( |
| 2021 | &extension_file_util::GarbageCollectExtensions, |
| 2022 | install_directory_, |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2023 | extension_paths))) { |
[email protected] | 2f8757c3 | 2012-06-19 19:17:47 | [diff] [blame] | 2024 | NOTREACHED(); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2025 | } |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 2026 | } |
| 2027 | |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 2028 | void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
[email protected] | 6d14791 | 2013-07-09 08:02:14 | [diff] [blame] | 2029 | if (extensions::sync_helper::IsSyncableApp(&extension)) { |
| 2030 | if (app_sync_bundle_.IsSyncing()) |
| 2031 | app_sync_bundle_.SyncChangeIfNeeded(extension); |
| 2032 | else if (is_ready() && !flare_.is_null()) |
| 2033 | flare_.Run(syncer::APPS); |
| 2034 | } else if (extensions::sync_helper::IsSyncableExtension(&extension)) { |
| 2035 | if (extension_sync_bundle_.IsSyncing()) |
| 2036 | extension_sync_bundle_.SyncChangeIfNeeded(extension); |
| 2037 | else if (is_ready() && !flare_.is_null()) |
| 2038 | flare_.Run(syncer::EXTENSIONS); |
[email protected] | fb82dcd | 2012-03-21 14:15:46 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 2042 | void ExtensionService::SetReadyAndNotifyListeners() { |
[email protected] | 4a10006a | 2013-05-17 23:18:35 | [diff] [blame] | 2043 | ready_->Signal(); |
[email protected] | 820d9bd | 2013-04-03 03:46:03 | [diff] [blame] | 2044 | content::NotificationService::current()->Notify( |
| 2045 | chrome::NOTIFICATION_EXTENSIONS_READY, |
| 2046 | content::Source<Profile>(profile_), |
| 2047 | content::NotificationService::NoDetails()); |
| 2048 | } |
| 2049 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2050 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 3eeddd89 | 2013-04-17 17:00:11 | [diff] [blame] | 2051 | if (updater_) |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 2052 | updater_->Start(); |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 2053 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 2054 | OnBlacklistUpdated(); |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2055 | } |
| 2056 | |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 2057 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2058 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 2059 | // default extension state to DISABLED when the --disable-extensions flag |
| 2060 | // is set (http://crbug.com/29067). |
| 2061 | if (!extensions_enabled() && |
| 2062 | !extension->is_theme() && |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2063 | extension->location() != Manifest::COMPONENT && |
| 2064 | !Manifest::IsExternalLocation(extension->location())) { |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 2065 | return; |
[email protected] | 330840c | 2012-08-29 22:21:01 | [diff] [blame] | 2066 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2067 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2068 | bool is_extension_upgrade = false; |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2069 | bool is_extension_installed = false; |
| 2070 | const Extension* old = GetInstalledExtension(extension->id()); |
| 2071 | if (old) { |
| 2072 | is_extension_installed = true; |
| 2073 | int version_compare_result = |
| 2074 | extension->version()->CompareTo(*(old->version())); |
| 2075 | is_extension_upgrade = version_compare_result > 0; |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2076 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 2077 | // that we aren't downgrading. |
| 2078 | if (!Manifest::IsUnpackedLocation(extension->location())) |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2079 | CHECK_GE(version_compare_result, 0); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2080 | } |
| 2081 | SetBeingUpgraded(extension, is_extension_upgrade); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2082 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 2083 | // The extension is now loaded, remove its data from unloaded extension map. |
| 2084 | unloaded_extension_paths_.erase(extension->id()); |
| 2085 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2086 | // If a terminated extension is loaded, remove it from the terminated list. |
| 2087 | UntrackTerminatedExtension(extension->id()); |
| 2088 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 2089 | // If the extension was disabled for a reload, then enable it. |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 2090 | bool reloading = reloading_extensions_.erase(extension->id()) > 0; |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 2091 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2092 | // Check if the extension's privileges have changed and mark the |
| 2093 | // extension disabled if necessary. |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2094 | CheckPermissionsIncrease(extension, is_extension_installed); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2095 | |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2096 | if (is_extension_installed && !reloading) { |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 2097 | // To upgrade an extension in place, unload the old one and then load the |
| 2098 | // new one. ReloadExtension disables the extension, which is sufficient. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2099 | UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_UPDATE); |
| 2100 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2101 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2102 | if (extension_prefs_->IsExtensionBlacklisted(extension->id())) { |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 2103 | // Only prefs is checked for the blacklist. We rely on callers to check the |
| 2104 | // blacklist before calling into here, e.g. CrxInstaller checks before |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2105 | // installation then threads through the install and pending install flow |
| 2106 | // of this class, and we check when loading installed extensions. |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2107 | blacklisted_extensions_.Insert(extension); |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 2108 | } else if (!reloading && |
| 2109 | extension_prefs_->IsExtensionDisabled(extension->id())) { |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2110 | disabled_extensions_.Insert(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2111 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 2112 | content::NotificationService::current()->Notify( |
| 2113 | chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
| 2114 | content::Source<Profile>(profile_), |
| 2115 | content::Details<const Extension>(extension)); |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 2116 | |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 2117 | // Show the extension disabled error if a permissions increase was the |
| 2118 | // only reason it was disabled. |
| 2119 | if (extension_prefs_->GetDisableReasons(extension->id()) == |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 2120 | Extension::DISABLE_PERMISSIONS_INCREASE) { |
[email protected] | 62f051c | 2012-03-29 17:04:44 | [diff] [blame] | 2121 | extensions::AddExtensionDisabledError(this, extension); |
| 2122 | } |
[email protected] | ca2e8202 | 2013-04-29 16:48:41 | [diff] [blame] | 2123 | } else if (reloading) { |
| 2124 | // Replace the old extension with the new version. |
| 2125 | CHECK(!disabled_extensions_.Insert(extension)); |
| 2126 | EnableExtension(extension->id()); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2127 | } else { |
| 2128 | // All apps that are displayed in the launcher are ordered by their ordinals |
| 2129 | // so we must ensure they have valid ordinals. |
| 2130 | if (extension->RequiresSortOrdinal()) { |
[email protected] | bd36b65 | 2013-02-27 02:13:25 | [diff] [blame] | 2131 | if (!extension->ShouldDisplayInNewTabPage()) { |
| 2132 | extension_prefs_->extension_sorting()->MarkExtensionAsHidden( |
| 2133 | extension->id()); |
| 2134 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2135 | extension_prefs_->extension_sorting()->EnsureValidOrdinals( |
| 2136 | extension->id(), syncer::StringOrdinal()); |
| 2137 | } |
| 2138 | |
| 2139 | extensions_.Insert(extension); |
| 2140 | SyncExtensionChangeIfNeeded(*extension); |
| 2141 | NotifyExtensionLoaded(extension); |
[email protected] | f574c40 | 2012-12-04 23:20:31 | [diff] [blame] | 2142 | } |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2143 | SetBeingUpgraded(extension, false); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2144 | } |
| 2145 | |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 2146 | void ExtensionService::AddComponentExtension(const Extension* extension) { |
| 2147 | const std::string old_version_string( |
| 2148 | extension_prefs_->GetVersionString(extension->id())); |
| 2149 | const Version old_version(old_version_string); |
| 2150 | |
| 2151 | if (!old_version.IsValid() || !old_version.Equals(*extension->version())) { |
| 2152 | VLOG(1) << "Component extension " << extension->name() << " (" |
| 2153 | << extension->id() << ") installing/upgrading from '" |
| 2154 | << old_version_string << "' to " << extension->version()->GetString(); |
| 2155 | |
| 2156 | AddNewOrUpdatedExtension(extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2157 | Extension::ENABLED_COMPONENT, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2158 | extensions::Blacklist::NOT_BLACKLISTED, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2159 | syncer::StringOrdinal()); |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 2160 | return; |
| 2161 | } |
| 2162 | |
| 2163 | AddExtension(extension); |
| 2164 | } |
| 2165 | |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2166 | void ExtensionService::UpdateActivePermissions(const Extension* extension) { |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2167 | // If the extension has used the optional permissions API, it will have a |
| 2168 | // custom set of active permissions defined in the extension prefs. Here, |
| 2169 | // we update the extension's active permissions based on the prefs. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2170 | scoped_refptr<PermissionSet> active_permissions = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2171 | extension_prefs()->GetActivePermissions(extension->id()); |
| 2172 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2173 | if (active_permissions.get()) { |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2174 | // We restrict the active permissions to be within the bounds defined in the |
| 2175 | // extension's manifest. |
| 2176 | // a) active permissions must be a subset of optional + default permissions |
| 2177 | // b) active permissions must contains all default permissions |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2178 | scoped_refptr<PermissionSet> total_permissions = |
| 2179 | PermissionSet::CreateUnion( |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 2180 | extensions::PermissionsData::GetRequiredPermissions(extension), |
| 2181 | extensions::PermissionsData::GetOptionalPermissions(extension)); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2182 | |
| 2183 | // Make sure the active permissions contain no more than optional + default. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2184 | scoped_refptr<PermissionSet> adjusted_active = |
| 2185 | PermissionSet::CreateIntersection( |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2186 | total_permissions.get(), active_permissions.get()); |
| 2187 | |
| 2188 | // Make sure the active permissions contain the default permissions. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2189 | adjusted_active = PermissionSet::CreateUnion( |
[email protected] | 2cb5e30 | 2013-05-09 05:00:06 | [diff] [blame] | 2190 | extensions::PermissionsData::GetRequiredPermissions(extension), |
| 2191 | adjusted_active.get()); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2192 | |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 2193 | extensions::PermissionsUpdater perms_updater(profile()); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2194 | perms_updater.UpdateActivePermissions(extension, adjusted_active.get()); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2195 | } |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | void ExtensionService::CheckPermissionsIncrease(const Extension* extension, |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2199 | bool is_extension_installed) { |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2200 | UpdateActivePermissions(extension); |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2201 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2202 | // We keep track of all permissions the user has granted each extension. |
| 2203 | // This allows extensions to gracefully support backwards compatibility |
| 2204 | // by including unknown permissions in their manifests. When the user |
| 2205 | // installs the extension, only the recognized permissions are recorded. |
| 2206 | // When the unknown permissions become recognized (e.g., through browser |
| 2207 | // upgrade), we can prompt the user to accept these new permissions. |
| 2208 | // Extensions can also silently upgrade to less permissions, and then |
| 2209 | // silently upgrade to a version that adds these permissions back. |
| 2210 | // |
| 2211 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 2212 | // for an API that adds suggestions to the omnibox. An extension can |
| 2213 | // maintain backwards compatibility while still having "omnibox" in the |
| 2214 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 2215 | // will record the permissions it recognized, not including "omnibox." |
| 2216 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 2217 | // will disable the extension and prompt the user to approve the increase |
| 2218 | // in privileges. The extension could then release a new version that |
| 2219 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 2220 | // still remember that "omnibox" had been granted, so that if the |
| 2221 | // extension once again includes "omnibox" in an upgrade, the extension |
| 2222 | // can upgrade without requiring this user's approval. |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 2223 | int disable_reasons = extension_prefs_->GetDisableReasons(extension->id()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2224 | |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 2225 | bool auto_grant_permission = |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2226 | (!is_extension_installed && extension->was_installed_by_default()) || |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 2227 | chrome::IsRunningInForcedAppMode(); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2228 | // Silently grant all active permissions to default apps only on install. |
| 2229 | // After install they should behave like other apps. |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 2230 | // Silently grant all active permissions to apps install in kiosk mode on both |
| 2231 | // install and update. |
| 2232 | if (auto_grant_permission) |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2233 | GrantPermissions(extension); |
| 2234 | |
| 2235 | bool is_privilege_increase = false; |
| 2236 | // We only need to compare the granted permissions to the current permissions |
| 2237 | // if the extension is not allowed to silently increase its permissions. |
[email protected] | 13c68b6 | 2013-05-17 11:29:05 | [diff] [blame] | 2238 | if (!extensions::PermissionsData::CanSilentlyIncreasePermissions(extension) && |
[email protected] | 211a3f3 | 2013-05-28 21:48:18 | [diff] [blame] | 2239 | !auto_grant_permission) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2240 | // Add all the recognized permissions if the granted permissions list |
| 2241 | // hasn't been initialized yet. |
[email protected] | c2e66e1 | 2012-06-27 06:27:06 | [diff] [blame] | 2242 | scoped_refptr<PermissionSet> granted_permissions = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2243 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2244 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2245 | |
| 2246 | // Here, we check if an extension's privileges have increased in a manner |
| 2247 | // that requires the user's approval. This could occur because the browser |
| 2248 | // upgraded and recognized additional privileges, or an extension upgrades |
| 2249 | // to a version that requires additional privileges. |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 2250 | is_privilege_increase = granted_permissions->HasLessPrivilegesThan( |
[email protected] | a0a7305 | 2013-07-10 01:42:43 | [diff] [blame] | 2251 | extension->GetActivePermissions().get(), extension->GetType()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2252 | } |
| 2253 | |
[email protected] | 116d40e | 2013-08-08 17:23:17 | [diff] [blame] | 2254 | if (is_extension_installed) { |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 2255 | // If the extension was already disabled, suppress any alerts for becoming |
| 2256 | // disabled on permissions increase. |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2257 | bool previously_disabled = |
| 2258 | extension_prefs_->IsExtensionDisabled(extension->id()); |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 2259 | // Legacy disabled extensions do not have a disable reason. Infer that if |
| 2260 | // there was no permission increase, it was likely disabled by the user. |
| 2261 | if (previously_disabled && disable_reasons == Extension::DISABLE_NONE && |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2262 | !extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 2263 | disable_reasons |= Extension::DISABLE_USER_ACTION; |
[email protected] | 44d62b6 | 2012-04-11 00:06:03 | [diff] [blame] | 2264 | } |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 2265 | // Extensions that came to us disabled from sync need a similar inference, |
| 2266 | // except based on the new version's permissions. |
| 2267 | if (previously_disabled && |
| 2268 | disable_reasons == Extension::DISABLE_UNKNOWN_FROM_SYNC) { |
| 2269 | // Remove the DISABLE_UNKNOWN_FROM_SYNC reason. |
| 2270 | extension_prefs_->ClearDisableReasons(extension->id()); |
| 2271 | if (!is_privilege_increase) |
| 2272 | disable_reasons |= Extension::DISABLE_USER_ACTION; |
| 2273 | } |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2274 | disable_reasons &= ~Extension::DISABLE_UNKNOWN_FROM_SYNC; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | // Extension has changed permissions significantly. Disable it. A |
| 2278 | // notification should be sent by the caller. |
| 2279 | if (is_privilege_increase) { |
[email protected] | 7e9e242 | 2012-12-13 19:54:19 | [diff] [blame] | 2280 | disable_reasons |= Extension::DISABLE_PERMISSIONS_INCREASE; |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 2281 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 2282 | RecordPermissionMessagesHistogram( |
| 2283 | extension, "Extensions.Permissions_AutoDisable"); |
| 2284 | } |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 2285 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2286 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2287 | } |
| 2288 | if (disable_reasons != Extension::DISABLE_NONE) { |
[email protected] | eb5e4f9 | 2012-08-15 23:33:28 | [diff] [blame] | 2289 | extension_prefs_->AddDisableReason( |
| 2290 | extension->id(), |
| 2291 | static_cast<Extension::DisableReason>(disable_reasons)); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2292 | } |
| 2293 | } |
| 2294 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2295 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 2296 | std::set<std::string> extension_ids; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2297 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2298 | iter != extensions_.end(); ++iter) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 2299 | const Extension* extension = iter->get(); |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2300 | if (!extension->is_theme() && extension->location() != Manifest::COMPONENT) |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2301 | extension_ids.insert(extension->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2302 | } |
| 2303 | |
[email protected] | f6431be8 | 2013-09-07 02:53:45 | [diff] [blame] | 2304 | crash_keys::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2305 | } |
| 2306 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2307 | ExtensionService::ImportStatus ExtensionService::SatisfyImports( |
| 2308 | const Extension* extension) { |
| 2309 | ImportStatus status = IMPORT_STATUS_OK; |
| 2310 | std::vector<std::string> pending; |
| 2311 | // TODO(elijahtaylor): Message the user if there is a failure that is |
| 2312 | // unrecoverable. |
| 2313 | if (SharedModuleInfo::ImportsModules(extension)) { |
| 2314 | const std::vector<SharedModuleInfo::ImportInfo>& imports = |
| 2315 | SharedModuleInfo::GetImports(extension); |
| 2316 | std::vector<SharedModuleInfo::ImportInfo>::const_iterator i; |
| 2317 | for (i = imports.begin(); i != imports.end(); ++i) { |
| 2318 | Version version_required(i->minimum_version); |
| 2319 | const Extension* imported_module = |
| 2320 | GetExtensionById(i->extension_id, true); |
| 2321 | if (!imported_module) { |
| 2322 | if (extension->from_webstore()) { |
| 2323 | status = IMPORT_STATUS_UNSATISFIED; |
| 2324 | pending.push_back(i->extension_id); |
| 2325 | } else { |
| 2326 | return IMPORT_STATUS_UNRECOVERABLE; |
| 2327 | } |
| 2328 | } else if (!SharedModuleInfo::IsSharedModule(imported_module)) { |
| 2329 | return IMPORT_STATUS_UNRECOVERABLE; |
| 2330 | } else if (version_required.IsValid() && |
| 2331 | imported_module->version()->CompareTo(version_required) < 0) { |
| 2332 | if (imported_module->from_webstore()) { |
| 2333 | status = IMPORT_STATUS_UNSATISFIED; |
| 2334 | } else { |
| 2335 | return IMPORT_STATUS_UNRECOVERABLE; |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | } |
| 2340 | if (status == IMPORT_STATUS_UNSATISFIED) { |
| 2341 | for (std::vector<std::string>::const_iterator iter = pending.begin(); |
| 2342 | iter != pending.end(); |
| 2343 | ++iter) { |
| 2344 | pending_extension_manager()->AddFromExtensionImport( |
| 2345 | *iter, |
| 2346 | extension_urls::GetWebstoreUpdateUrl(), |
| 2347 | IsSharedModule); |
| 2348 | } |
| 2349 | CheckForUpdatesSoon(); |
| 2350 | } |
| 2351 | return status; |
| 2352 | } |
| 2353 | |
| 2354 | scoped_ptr<const ExtensionSet> |
| 2355 | ExtensionService::GetDependentExtensions(const Extension* extension) { |
| 2356 | scoped_ptr<ExtensionSet> dependents(new ExtensionSet()); |
| 2357 | scoped_ptr<ExtensionSet> set_to_check(new ExtensionSet()); |
| 2358 | if (SharedModuleInfo::IsSharedModule(extension)) { |
| 2359 | set_to_check->InsertAll(disabled_extensions_); |
| 2360 | set_to_check->InsertAll(delayed_installs_); |
| 2361 | set_to_check->InsertAll(extensions_); |
| 2362 | for (ExtensionSet::const_iterator iter = set_to_check->begin(); |
| 2363 | iter != set_to_check->end(); ++iter) { |
[email protected] | 198b590 | 2013-06-27 10:36:11 | [diff] [blame] | 2364 | if (SharedModuleInfo::ImportsExtensionById(iter->get(), |
| 2365 | extension->id())) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2366 | dependents->Insert(*iter); |
| 2367 | } |
| 2368 | } |
| 2369 | } |
| 2370 | return dependents.PassAs<const ExtensionSet>(); |
| 2371 | } |
| 2372 | |
| 2373 | void ExtensionService::PruneSharedModulesOnUninstall( |
| 2374 | const Extension* extension) { |
| 2375 | if (SharedModuleInfo::ImportsModules(extension)) { |
| 2376 | const std::vector<SharedModuleInfo::ImportInfo>& imports = |
| 2377 | SharedModuleInfo::GetImports(extension); |
| 2378 | std::vector<SharedModuleInfo::ImportInfo>::const_iterator i; |
| 2379 | for (i = imports.begin(); i != imports.end(); ++i) { |
| 2380 | const Extension* imported_module = |
| 2381 | GetExtensionById(i->extension_id, true); |
| 2382 | if (imported_module && imported_module->from_webstore()) { |
| 2383 | scoped_ptr<const ExtensionSet> dependents = |
| 2384 | GetDependentExtensions(imported_module); |
| 2385 | if (dependents->size() == 0) { |
[email protected] | 4c9201c4 | 2013-08-16 04:56:21 | [diff] [blame] | 2386 | UninstallExtension(i->extension_id, true, NULL); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2393 | void ExtensionService::OnExtensionInstalled( |
[email protected] | 36a5c4c | 2011-12-14 16:34:50 | [diff] [blame] | 2394 | const Extension* extension, |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 2395 | const syncer::StringOrdinal& page_ordinal, |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2396 | bool has_requirement_errors, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2397 | extensions::Blacklist::BlacklistState blacklist_state, |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2398 | bool wait_for_idle) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2399 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2400 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2401 | const std::string& id = extension->id(); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2402 | bool initial_enable = ShouldEnableOnInstall(extension); |
[email protected] | 3f213ad | 2012-07-26 23:39:41 | [diff] [blame] | 2403 | const extensions::PendingExtensionInfo* pending_extension_info = NULL; |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2404 | if ((pending_extension_info = pending_extension_manager()->GetById(id))) { |
[email protected] | 8f3bcbd | 2013-06-05 08:42:40 | [diff] [blame] | 2405 | if (!pending_extension_info->ShouldAllowInstall(extension)) { |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2406 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2407 | |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2408 | LOG(WARNING) << "ShouldAllowInstall() returned false for " |
| 2409 | << id << " of type " << extension->GetType() |
[email protected] | 6534806 | 2013-01-15 07:27:22 | [diff] [blame] | 2410 | << " and update URL " |
| 2411 | << extensions::ManifestURL::GetUpdateURL(extension).spec() |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2412 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2413 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2414 | // Delete the extension directory since we're not going to |
| 2415 | // load it. |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 2416 | if (!GetFileTaskRunner()->PostTask( |
| 2417 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 2418 | base::Bind(&extension_file_util::DeleteFile, |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2419 | extension->path(), true))) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2420 | NOTREACHED(); |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2421 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2422 | return; |
| 2423 | } |
[email protected] | 51a3bf8b | 2012-06-08 22:53:06 | [diff] [blame] | 2424 | |
| 2425 | pending_extension_manager()->Remove(id); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2426 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2427 | // We explicitly want to re-enable an uninstalled external |
| 2428 | // extension; if we're here, that means the user is manually |
| 2429 | // installing the extension. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2430 | if (IsExternalExtensionUninstalled(id)) { |
| 2431 | initial_enable = true; |
| 2432 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2433 | } |
| 2434 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 2435 | // Unsupported requirements overrides the management policy. |
| 2436 | if (has_requirement_errors) { |
| 2437 | initial_enable = false; |
| 2438 | extension_prefs_->AddDisableReason( |
| 2439 | id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| 2440 | // If the extension was disabled because of unsupported requirements but |
| 2441 | // now supports all requirements after an update and there are not other |
| 2442 | // disable reasons, enable it. |
| 2443 | } else if (extension_prefs_->GetDisableReasons(id) == |
| 2444 | Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
| 2445 | initial_enable = true; |
| 2446 | extension_prefs_->ClearDisableReasons(id); |
| 2447 | } |
| 2448 | |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2449 | if (blacklist_state == extensions::Blacklist::BLACKLISTED) { |
| 2450 | // Installation of a blacklisted extension can happen from sync, policy, |
| 2451 | // etc, where to maintain consistency we need to install it, just never |
| 2452 | // load it (see AddExtension). Usually it should be the job of callers to |
| 2453 | // incercept blacklisted extension earlier (e.g. CrxInstaller, before even |
| 2454 | // showing the install dialogue). |
| 2455 | extension_prefs()->AcknowledgeBlacklistedExtension(id); |
| 2456 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
| 2457 | extension->location(), |
| 2458 | Manifest::NUM_LOCATIONS); |
| 2459 | } |
| 2460 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2461 | if (!GetInstalledExtension(extension->id())) { |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 2462 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 2463 | extension->GetType(), 100); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 2464 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2465 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 2466 | RecordPermissionMessagesHistogram( |
| 2467 | extension, "Extensions.Permissions_Install"); |
[email protected] | 69084dc | 2012-11-17 07:39:30 | [diff] [blame] | 2468 | } else { |
| 2469 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateType", |
| 2470 | extension->GetType(), 100); |
| 2471 | UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2472 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 2473 | } |
| 2474 | |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 2475 | // Certain extension locations are specific enough that we can |
| 2476 | // auto-acknowledge any extension that came from one of them. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2477 | if (extension->location() == Manifest::EXTERNAL_POLICY_DOWNLOAD) |
[email protected] | a39921b4 | 2012-02-28 03:42:54 | [diff] [blame] | 2478 | AcknowledgeExternalExtension(extension->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2479 | const Extension::State initial_state = |
| 2480 | initial_enable ? Extension::ENABLED : Extension::DISABLED; |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2481 | if (ShouldDelayExtensionUpdate(id, wait_for_idle)) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2482 | extension_prefs_->SetDelayedInstallInfo( |
| 2483 | extension, |
| 2484 | initial_state, |
| 2485 | blacklist_state, |
| 2486 | extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, |
| 2487 | page_ordinal); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2488 | |
| 2489 | // Transfer ownership of |extension|. |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2490 | delayed_installs_.Insert(extension); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2491 | |
| 2492 | // Notify extension of available update. |
| 2493 | extensions::RuntimeEventRouter::DispatchOnUpdateAvailableEvent( |
| 2494 | profile_, id, extension->manifest()->value()); |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2495 | |
| 2496 | // Notify observers that app update is available. |
| 2497 | FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
| 2498 | OnAppUpdateAvailable(extension->id())); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2499 | return; |
| 2500 | } |
| 2501 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2502 | ImportStatus status = SatisfyImports(extension); |
| 2503 | if (installs_delayed_for_gc()) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2504 | extension_prefs_->SetDelayedInstallInfo( |
| 2505 | extension, |
| 2506 | initial_state, |
| 2507 | blacklist_state, |
| 2508 | extensions::ExtensionPrefs::DELAY_REASON_GC, |
| 2509 | page_ordinal); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2510 | delayed_installs_.Insert(extension); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2511 | } else if (status != IMPORT_STATUS_OK) { |
| 2512 | if (status == IMPORT_STATUS_UNSATISFIED) { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2513 | extension_prefs_->SetDelayedInstallInfo( |
| 2514 | extension, |
| 2515 | initial_state, |
| 2516 | blacklist_state, |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2517 | extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS, |
| 2518 | page_ordinal); |
| 2519 | delayed_installs_.Insert(extension); |
| 2520 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2521 | } else { |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2522 | AddNewOrUpdatedExtension(extension, |
| 2523 | initial_state, |
| 2524 | blacklist_state, |
| 2525 | page_ordinal); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2526 | } |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | void ExtensionService::AddNewOrUpdatedExtension( |
| 2530 | const Extension* extension, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2531 | Extension::State initial_state, |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2532 | extensions::Blacklist::BlacklistState blacklist_state, |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2533 | const syncer::StringOrdinal& page_ordinal) { |
[email protected] | 8c484b74 | 2012-11-29 06:05:36 | [diff] [blame] | 2534 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 2535 | extension_prefs_->OnExtensionInstalled(extension, |
| 2536 | initial_state, |
| 2537 | blacklist_state, |
| 2538 | page_ordinal); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 2539 | delayed_installs_.Remove(extension->id()); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2540 | FinishInstallation(extension); |
| 2541 | } |
| 2542 | |
| 2543 | void ExtensionService::MaybeFinishDelayedInstallation( |
| 2544 | const std::string& extension_id) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2545 | // Check if the extension already got installed. |
| 2546 | if (!delayed_installs_.Contains(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2547 | return; |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2548 | extensions::ExtensionPrefs::DelayReason reason = |
| 2549 | extension_prefs_->GetDelayedInstallReason(extension_id); |
| 2550 | |
| 2551 | // Check if the extension is idle. DELAY_REASON_NONE is used for older |
| 2552 | // preferences files that will not have set this field but it was previously |
| 2553 | // only used for idle updates. |
| 2554 | if ((reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE || |
| 2555 | reason == extensions::ExtensionPrefs::DELAY_REASON_NONE) && |
| 2556 | is_ready() && !IsExtensionIdle(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2557 | return; |
| 2558 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2559 | const Extension* extension = delayed_installs_.GetByID(extension_id); |
| 2560 | if (reason == extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IMPORTS) { |
| 2561 | ImportStatus status = SatisfyImports(extension); |
| 2562 | if (status != IMPORT_STATUS_OK) { |
| 2563 | if (status == IMPORT_STATUS_UNRECOVERABLE) { |
| 2564 | delayed_installs_.Remove(extension_id); |
| 2565 | // Make sure no version of the extension is actually installed, (i.e., |
| 2566 | // that this delayed install was not an update). |
| 2567 | CHECK(!extension_prefs_->GetInstalledExtensionInfo(extension_id).get()); |
| 2568 | extension_prefs_->DeleteExtensionPrefs(extension_id); |
| 2569 | } |
| 2570 | return; |
| 2571 | } |
| 2572 | } |
| 2573 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2574 | FinishDelayedInstallation(extension_id); |
| 2575 | } |
| 2576 | |
| 2577 | void ExtensionService::FinishDelayedInstallation( |
| 2578 | const std::string& extension_id) { |
| 2579 | scoped_refptr<const Extension> extension( |
| 2580 | GetPendingExtensionUpdate(extension_id)); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2581 | CHECK(extension.get()); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2582 | delayed_installs_.Remove(extension_id); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2583 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2584 | if (!extension_prefs_->FinishDelayedInstallInfo(extension_id)) |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2585 | NOTREACHED(); |
| 2586 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 2587 | FinishInstallation(extension.get()); |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | void ExtensionService::FinishInstallation(const Extension* extension) { |
[email protected] | e7554c3f | 2013-05-29 00:36:56 | [diff] [blame] | 2591 | const extensions::Extension* existing_extension = |
| 2592 | GetInstalledExtension(extension->id()); |
| 2593 | bool is_update = false; |
| 2594 | std::string old_name; |
| 2595 | if (existing_extension) { |
| 2596 | is_update = true; |
| 2597 | old_name = existing_extension->name(); |
| 2598 | } |
| 2599 | extensions::InstalledExtensionInfo details(extension, is_update, old_name); |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 2600 | content::NotificationService::current()->Notify( |
| 2601 | chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| 2602 | content::Source<Profile>(profile_), |
[email protected] | 41bb80bd | 2013-05-03 10:56:02 | [diff] [blame] | 2603 | content::Details<const extensions::InstalledExtensionInfo>(&details)); |
[email protected] | fcb58a86 | 2012-05-01 01:03:15 | [diff] [blame] | 2604 | |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 2605 | bool unacknowledged_external = IsUnacknowledgedExternalExtension(extension); |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 2606 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2607 | // Unpacked extensions default to allowing file access, but if that has been |
| 2608 | // overridden, don't reset the value. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2609 | if (Manifest::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 2610 | !extension_prefs_->HasAllowFileAccessSetting(extension->id())) { |
| 2611 | extension_prefs_->SetAllowFileAccess(extension->id(), true); |
| 2612 | } |
| 2613 | |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2614 | AddExtension(extension); |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2615 | |
| 2616 | // If this is a new external extension that was disabled, alert the user |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 2617 | // so he can reenable it. We do this last so that it has already been |
| 2618 | // added to our list of extensions. |
[email protected] | 3e3fafbb | 2013-08-17 13:33:16 | [diff] [blame] | 2619 | if (unacknowledged_external && !is_update) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2620 | UpdateExternalExtensionAlert(); |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 2621 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEvent", |
| 2622 | EXTERNAL_EXTENSION_INSTALLED, |
| 2623 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
[email protected] | 446e37e | 2013-08-07 00:30:02 | [diff] [blame] | 2624 | if (extensions::ManifestURL::UpdatesFromGallery(extension)) { |
| 2625 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventWebstore", |
| 2626 | EXTERNAL_EXTENSION_INSTALLED, |
| 2627 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 2628 | } else { |
| 2629 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExternalExtensionEventNonWebstore", |
| 2630 | EXTERNAL_EXTENSION_INSTALLED, |
| 2631 | EXTERNAL_EXTENSION_BUCKET_BOUNDARY); |
| 2632 | } |
[email protected] | d96eb51 | 2012-11-01 23:44:08 | [diff] [blame] | 2633 | } |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2634 | |
| 2635 | // Check extensions that may have been delayed only because this shared module |
| 2636 | // was not available. |
| 2637 | if (SharedModuleInfo::IsSharedModule(extension)) { |
| 2638 | MaybeFinishDelayedInstallations(); |
| 2639 | } |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 2640 | } |
| 2641 | |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 2642 | const Extension* ExtensionService::GetPendingExtensionUpdate( |
| 2643 | const std::string& id) const { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2644 | return delayed_installs_.GetByID(id); |
[email protected] | 76b6544 | 2012-11-17 14:11:48 | [diff] [blame] | 2645 | } |
| 2646 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2647 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2648 | if (!terminated_extensions_.Contains(extension->id())) |
| 2649 | terminated_extensions_.Insert(make_scoped_refptr(extension)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2650 | |
[email protected] | b3f7fe2 | 2011-11-11 19:27:56 | [diff] [blame] | 2651 | UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_TERMINATE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2655 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 60a174a | 2013-08-02 20:29:28 | [diff] [blame] | 2656 | const Extension* extension = terminated_extensions_.GetByID(lowercase_id); |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2657 | terminated_extensions_.Remove(lowercase_id); |
[email protected] | fb78953 | 2013-08-27 02:40:21 | [diff] [blame] | 2658 | if (extension) { |
| 2659 | content::NotificationService::current()->Notify( |
| 2660 | chrome::NOTIFICATION_EXTENSION_REMOVED, |
| 2661 | content::Source<Profile>(profile_), |
| 2662 | content::Details<const Extension>(extension)); |
| 2663 | } |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2664 | } |
| 2665 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2666 | const Extension* ExtensionService::GetTerminatedExtension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2667 | const std::string& id) const { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2668 | return GetExtensionById(id, INCLUDE_TERMINATED); |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | const Extension* ExtensionService::GetInstalledExtension( |
| 2672 | const std::string& id) const { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 2673 | int include_mask = INCLUDE_ENABLED | |
| 2674 | INCLUDE_DISABLED | |
| 2675 | INCLUDE_TERMINATED | |
| 2676 | INCLUDE_BLACKLISTED; |
| 2677 | return GetExtensionById(id, include_mask); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2678 | } |
| 2679 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2680 | bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 2681 | // Allow bindings for all packaged extensions and component hosted apps. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2682 | const Extension* extension = extensions_.GetExtensionOrAppByURL(url); |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 2683 | return extension && (!extension->is_hosted_app() || |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2684 | extension->location() == Manifest::COMPONENT); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2685 | } |
| 2686 | |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame] | 2687 | bool ExtensionService::ShouldBlockUrlInBrowserTab(GURL* url) { |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2688 | const Extension* extension = extensions_.GetExtensionOrAppByURL(*url); |
[email protected] | 4d007b31 | 2012-10-17 03:00:48 | [diff] [blame] | 2689 | if (extension && extension->is_platform_app()) { |
| 2690 | *url = GURL(chrome::kExtensionInvalidRequestURL); |
| 2691 | return true; |
| 2692 | } |
| 2693 | |
| 2694 | return false; |
| 2695 | } |
| 2696 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2697 | bool ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2698 | const std::string& id, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2699 | const Version* version, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2700 | const base::FilePath& path, |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2701 | Manifest::Location location, |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 2702 | int creation_flags, |
| 2703 | bool mark_acknowledged) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 2704 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2705 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 2706 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2707 | return false; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2708 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2709 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 2710 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2711 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2712 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2713 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2714 | if (existing) { |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2715 | // The default apps will have the location set as INTERNAL. Since older |
| 2716 | // default apps are installed as EXTERNAL, we override them. However, if the |
| 2717 | // app is already installed as internal, then do the version check. |
[email protected] | 31bb5ee6 | 2012-09-12 22:58:40 | [diff] [blame] | 2718 | // TODO(grv) : Remove after Q1-2013. |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2719 | bool is_default_apps_migration = |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2720 | (location == Manifest::INTERNAL && |
| 2721 | Manifest::IsExternalLocation(existing->location())); |
[email protected] | 910f72ce | 2012-08-24 01:38:35 | [diff] [blame] | 2722 | |
| 2723 | if (!is_default_apps_migration) { |
| 2724 | DCHECK(version); |
| 2725 | |
| 2726 | switch (existing->version()->CompareTo(*version)) { |
| 2727 | case -1: // existing version is older, we should upgrade |
| 2728 | break; |
| 2729 | case 0: // existing version is same, do nothing |
| 2730 | return false; |
| 2731 | case 1: // existing version is newer, uh-oh |
| 2732 | LOG(WARNING) << "Found external version of extension " << id |
| 2733 | << "that is older than current version. Current version " |
| 2734 | << "is: " << existing->VersionString() << ". New " |
| 2735 | << "version is: " << version->GetString() |
| 2736 | << ". Keeping current version."; |
| 2737 | return false; |
| 2738 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2739 | } |
| 2740 | } |
| 2741 | |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2742 | // If the extension is already pending, don't start an install. |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 2743 | if (!pending_extension_manager()->AddFromExternalFile( |
| 2744 | id, location, *version)) { |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2745 | return false; |
[email protected] | e398785 | 2012-05-04 10:06:30 | [diff] [blame] | 2746 | } |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 2747 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2748 | // no client (silent install) |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 2749 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(this)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2750 | installer->set_install_source(location); |
| 2751 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 2752 | installer->set_expected_version(*version); |
| 2753 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 1bf73cc3 | 2011-10-26 22:38:31 | [diff] [blame] | 2754 | installer->set_creation_flags(creation_flags); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 2755 | #if defined(OS_CHROMEOS) |
| 2756 | extensions::InstallLimiter::Get(profile_)->Add(installer, path); |
| 2757 | #else |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2758 | installer->InstallCrx(path); |
[email protected] | 88e8ec915 | 2013-01-17 04:05:18 | [diff] [blame] | 2759 | #endif |
[email protected] | 47fc70c | 2011-12-06 07:29:51 | [diff] [blame] | 2760 | |
| 2761 | // Depending on the source, a new external extension might not need a user |
| 2762 | // notification on installation. For such extensions, mark them acknowledged |
| 2763 | // now to suppress the notification. |
| 2764 | if (mark_acknowledged) |
| 2765 | AcknowledgeExternalExtension(id); |
[email protected] | 9060d8b0 | 2012-01-13 02:14:30 | [diff] [blame] | 2766 | |
| 2767 | return true; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2768 | } |
| 2769 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2770 | void ExtensionService::ReportExtensionLoadError( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 2771 | const base::FilePath& extension_path, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2772 | const std::string &error, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2773 | bool be_noisy) { |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2774 | content::NotificationService::current()->Notify( |
| 2775 | chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
| 2776 | content::Source<Profile>(profile_), |
| 2777 | content::Details<const std::string>(&error)); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2778 | |
[email protected] | 8a205c0 | 2011-02-04 20:41:33 | [diff] [blame] | 2779 | std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); |
[email protected] | 438afb1 | 2012-07-05 03:18:21 | [diff] [blame] | 2780 | string16 message = UTF8ToUTF16(base::StringPrintf( |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 2781 | "Could not load extension from '%s'. %s", |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 2782 | path_str.c_str(), error.c_str())); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2783 | ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
| 2784 | } |
| 2785 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2786 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 2787 | extensions::ExtensionHost* host) { |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2788 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2789 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2790 | if (iter == orphaned_dev_tools_.end()) |
| 2791 | return; |
| 2792 | |
[email protected] | 04ea1bb | 2013-07-10 09:26:09 | [diff] [blame] | 2793 | iter->second->ConnectRenderViewHost(host->render_view_host()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2794 | orphaned_dev_tools_.erase(iter); |
| 2795 | } |
| 2796 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2797 | void ExtensionService::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2798 | const content::NotificationSource& source, |
| 2799 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2800 | switch (type) { |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 2801 | case chrome::NOTIFICATION_APP_TERMINATING: |
| 2802 | // Shutdown has started. Don't start any more extension installs. |
| 2803 | // (We cannot use ExtensionService::Shutdown() for this because it |
| 2804 | // happens too late in browser teardown.) |
| 2805 | browser_terminating_ = true; |
| 2806 | break; |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2807 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2808 | if (profile_ != |
| 2809 | content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2810 | break; |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2811 | } |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2812 | |
[email protected] | 3a1dc57 | 2012-07-31 22:25:13 | [diff] [blame] | 2813 | extensions::ExtensionHost* host = |
| 2814 | content::Details<extensions::ExtensionHost>(details).ptr(); |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2815 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2816 | // Mark the extension as terminated and Unload it. We want it to |
| 2817 | // be in a consistent state: either fully working or not loaded |
| 2818 | // at all, but never half-crashed. We do it in a PostTask so |
| 2819 | // that other handlers of this notification will still have |
| 2820 | // access to the Extension and ExtensionHost. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 2821 | base::MessageLoop::current()->PostTask( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2822 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 2823 | base::Bind( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2824 | &ExtensionService::TrackTerminatedExtension, |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 2825 | AsWeakPtr(), |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2826 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2827 | break; |
| 2828 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2829 | case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2830 | content::RenderProcessHost* process = |
| 2831 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2832 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2833 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2834 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2835 | break; |
| 2836 | |
[email protected] | 15397b4 | 2012-05-16 23:56:06 | [diff] [blame] | 2837 | // Extensions need to know the channel for API restrictions. |
| 2838 | process->Send(new ExtensionMsg_SetChannel( |
[email protected] | 15d4d2d | 2013-08-09 06:49:03 | [diff] [blame] | 2839 | extensions::GetCurrentChannel())); |
[email protected] | 15397b4 | 2012-05-16 23:56:06 | [diff] [blame] | 2840 | |
[email protected] | 4941fe9 | 2013-06-13 23:21:01 | [diff] [blame] | 2841 | // Platform apps need to know the system font. |
| 2842 | scoped_ptr<base::DictionaryValue> fonts(new base::DictionaryValue); |
| 2843 | webui::SetFontAndTextDirection(fonts.get()); |
| 2844 | std::string font_family, font_size; |
| 2845 | fonts->GetString("fontfamily", &font_family); |
| 2846 | fonts->GetString("fontsize", &font_size); |
| 2847 | process->Send(new ExtensionMsg_SetSystemFont( |
| 2848 | font_family, font_size)); |
| 2849 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2850 | // Valid extension function names, used to setup bindings in renderer. |
| 2851 | std::vector<std::string> function_names; |
| 2852 | ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); |
| 2853 | process->Send(new ExtensionMsg_SetFunctionNames(function_names)); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2854 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2855 | // Scripting whitelist. This is modified by tests and must be communicated |
| 2856 | // to renderers. |
| 2857 | process->Send(new ExtensionMsg_SetScriptingWhitelist( |
| 2858 | *Extension::GetScriptingWhitelist())); |
| 2859 | |
| 2860 | // Loaded extensions. |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 2861 | std::vector<ExtensionMsg_Loaded_Params> loaded_extensions; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2862 | for (ExtensionSet::const_iterator iter = extensions_.begin(); |
| 2863 | iter != extensions_.end(); ++iter) { |
[email protected] | 1964726 | 2011-12-16 09:57:49 | [diff] [blame] | 2864 | // Renderers don't need to know about themes. |
| 2865 | if (!(*iter)->is_theme()) |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 2866 | loaded_extensions.push_back(ExtensionMsg_Loaded_Params(iter->get())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2867 | } |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 2868 | process->Send(new ExtensionMsg_Loaded(loaded_extensions)); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2869 | break; |
| 2870 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2871 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2872 | content::RenderProcessHost* process = |
| 2873 | content::Source<content::RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2874 | Profile* host_profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2875 | Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2876 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2877 | break; |
| 2878 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 2879 | process_map_.RemoveAllFromProcess(process->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 2880 | BrowserThread::PostTask( |
| 2881 | BrowserThread::IO, FROM_HERE, |
| 2882 | base::Bind(&ExtensionInfoMap::UnregisterAllExtensionsInProcess, |
[email protected] | 31d8f5f2 | 2012-04-02 15:22:08 | [diff] [blame] | 2883 | system_->info_map(), |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 2884 | process->GetID())); |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2885 | break; |
| 2886 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2887 | case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 2888 | extensions::ExtensionHost* host = |
| 2889 | content::Details<extensions::ExtensionHost>(details).ptr(); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2890 | std::string extension_id = host->extension_id(); |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 2891 | if (delayed_installs_.Contains(extension_id)) { |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 2892 | // We were waiting for this extension to become idle, it now might have, |
| 2893 | // so maybe finish installation. |
[email protected] | b3a2509 | 2013-05-28 22:08:16 | [diff] [blame] | 2894 | base::MessageLoop::current()->PostDelayedTask( |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2895 | FROM_HERE, |
[email protected] | 6f610183 | 2012-11-27 22:10:48 | [diff] [blame] | 2896 | base::Bind(&ExtensionService::MaybeFinishDelayedInstallation, |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2897 | AsWeakPtr(), extension_id), |
| 2898 | base::TimeDelta::FromSeconds(kUpdateIdleDelay)); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 2899 | } |
| 2900 | break; |
| 2901 | } |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 2902 | case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: { |
| 2903 | // Notify extensions that chrome update is available. |
| 2904 | extensions::RuntimeEventRouter::DispatchOnBrowserUpdateAvailableEvent( |
| 2905 | profile_); |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 2906 | |
| 2907 | // Notify observers that chrome update is available. |
| 2908 | FOR_EACH_OBSERVER(extensions::UpdateObserver, update_observers_, |
| 2909 | OnChromeUpdateAvailable()); |
[email protected] | 92dd8d9 | 2013-02-26 00:41:08 | [diff] [blame] | 2910 | break; |
| 2911 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2912 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2913 | default: |
| 2914 | NOTREACHED() << "Unexpected notification type."; |
| 2915 | } |
| 2916 | } |
| 2917 | |
[email protected] | 90bb38d | 2012-11-14 18:36:03 | [diff] [blame] | 2918 | void ExtensionService::OnExtensionInstallPrefChanged() { |
[email protected] | a6a7ced | 2012-11-01 17:24:18 | [diff] [blame] | 2919 | IdentifyAlertableExtensions(); |
| 2920 | CheckManagementPolicy(); |
| 2921 | } |
| 2922 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2923 | bool ExtensionService::HasApps() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2924 | return !GetAppIds().empty(); |
| 2925 | } |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2926 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2927 | ExtensionIdSet ExtensionService::GetAppIds() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2928 | ExtensionIdSet result; |
[email protected] | 84df833 | 2011-12-06 18:22:46 | [diff] [blame] | 2929 | for (ExtensionSet::const_iterator it = extensions_.begin(); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2930 | it != extensions_.end(); ++it) { |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 2931 | if ((*it)->is_app() && (*it)->location() != Manifest::COMPONENT) |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2932 | result.insert((*it)->id()); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2933 | } |
| 2934 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2935 | return result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2936 | } |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2937 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 2938 | bool ExtensionService::IsBackgroundPageReady(const Extension* extension) const { |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2939 | if (!extensions::BackgroundInfo::HasPersistentBackgroundPage(extension)) |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 2940 | return true; |
| 2941 | ExtensionRuntimeDataMap::const_iterator it = |
| 2942 | extension_runtime_data_.find(extension->id()); |
| 2943 | return it == extension_runtime_data_.end() ? false : |
| 2944 | it->second.background_page_ready; |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2945 | } |
| 2946 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2947 | void ExtensionService::SetBackgroundPageReady(const Extension* extension) { |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2948 | DCHECK(extensions::BackgroundInfo::HasBackgroundPage(extension)); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2949 | extension_runtime_data_[extension->id()].background_page_ready = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2950 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2951 | chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2952 | content::Source<const Extension>(extension), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2953 | content::NotificationService::NoDetails()); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2954 | } |
| 2955 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 2956 | bool ExtensionService::IsBeingUpgraded(const Extension* extension) const { |
| 2957 | ExtensionRuntimeDataMap::const_iterator it = |
| 2958 | extension_runtime_data_.find(extension->id()); |
| 2959 | return it == extension_runtime_data_.end() ? false : |
| 2960 | it->second.being_upgraded; |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2961 | } |
| 2962 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2963 | void ExtensionService::SetBeingUpgraded(const Extension* extension, |
[email protected] | b914e295 | 2013-04-26 07:10:03 | [diff] [blame] | 2964 | bool value) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2965 | extension_runtime_data_[extension->id()].being_upgraded = value; |
| 2966 | } |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2967 | |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2968 | bool ExtensionService::IsBeingReloaded( |
| 2969 | const std::string& extension_id) const { |
| 2970 | return ContainsKey(extensions_being_reloaded_, extension_id); |
| 2971 | } |
| 2972 | |
| 2973 | void ExtensionService::SetBeingReloaded(const std::string& extension_id, |
[email protected] | 5e7015c | 2013-07-23 23:29:43 | [diff] [blame] | 2974 | bool isBeingReloaded) { |
| 2975 | if (isBeingReloaded) |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2976 | extensions_being_reloaded_.insert(extension_id); |
[email protected] | 5e7015c | 2013-07-23 23:29:43 | [diff] [blame] | 2977 | else |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2978 | extensions_being_reloaded_.erase(extension_id); |
[email protected] | e178ad9 | 2013-06-28 02:29:25 | [diff] [blame] | 2979 | } |
| 2980 | |
[email protected] | dc9a74f7 | 2012-08-17 18:07:21 | [diff] [blame] | 2981 | bool ExtensionService::HasUsedWebRequest(const Extension* extension) const { |
| 2982 | ExtensionRuntimeDataMap::const_iterator it = |
| 2983 | extension_runtime_data_.find(extension->id()); |
| 2984 | return it == extension_runtime_data_.end() ? false : |
| 2985 | it->second.has_used_webrequest; |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | void ExtensionService::SetHasUsedWebRequest(const Extension* extension, |
| 2989 | bool value) { |
| 2990 | extension_runtime_data_[extension->id()].has_used_webrequest = value; |
| 2991 | } |
| 2992 | |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 2993 | bool ExtensionService::ShouldEnableOnInstall(const Extension* extension) { |
| 2994 | // Extensions installed by policy can't be disabled. So even if a previous |
| 2995 | // installation disabled the extension, make sure it is now enabled. |
| 2996 | if (system_->management_policy()->MustRemainEnabled(extension, NULL)) |
| 2997 | return true; |
| 2998 | |
| 2999 | if (extension_prefs_->IsExtensionDisabled(extension->id())) |
| 3000 | return false; |
| 3001 | |
[email protected] | 41070e8d | 2012-10-24 01:34:36 | [diff] [blame] | 3002 | if (FeatureSwitch::prompt_for_external_extensions()->IsEnabled()) { |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 3003 | // External extensions are initially disabled. We prompt the user before |
[email protected] | 2c495c4 | 2013-01-04 21:49:54 | [diff] [blame] | 3004 | // enabling them. Hosted apps are excepted because they are not dangerous |
| 3005 | // (they need to be launched by the user anyway). |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 3006 | if (extension->GetType() != Manifest::TYPE_HOSTED_APP && |
| 3007 | Manifest::IsExternalLocation(extension->location()) && |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 3008 | !extension_prefs_->IsExternalExtensionAcknowledged(extension->id())) { |
| 3009 | return false; |
| 3010 | } |
| 3011 | } |
[email protected] | 612a1cb1 | 2012-10-17 13:18:03 | [diff] [blame] | 3012 | |
| 3013 | return true; |
| 3014 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 3015 | |
| 3016 | bool ExtensionService::IsExtensionIdle(const std::string& extension_id) const { |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3017 | ExtensionProcessManager* process_manager = system_->process_manager(); |
[email protected] | fc332ae | 2012-11-14 20:17:33 | [diff] [blame] | 3018 | DCHECK(process_manager); |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 3019 | extensions::ExtensionHost* host = |
[email protected] | d9a61e1 | 2012-11-14 02:43:47 | [diff] [blame] | 3020 | process_manager->GetBackgroundHostForExtension(extension_id); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 3021 | if (host) |
| 3022 | return false; |
| 3023 | return process_manager->GetRenderViewHostsForExtension(extension_id).empty(); |
| 3024 | } |
| 3025 | |
| 3026 | bool ExtensionService::ShouldDelayExtensionUpdate( |
| 3027 | const std::string& extension_id, |
| 3028 | bool wait_for_idle) const { |
| 3029 | const char kOnUpdateAvailableEvent[] = "runtime.onUpdateAvailable"; |
| 3030 | |
| 3031 | // If delayed updates are globally disabled, or just for this extension, |
| 3032 | // don't delay. |
| 3033 | if (!install_updates_when_idle_ || !wait_for_idle) |
| 3034 | return false; |
| 3035 | |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3036 | const Extension* old = GetInstalledExtension(extension_id); |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 3037 | // If there is no old extension, this is not an update, so don't delay. |
| 3038 | if (!old) |
| 3039 | return false; |
| 3040 | |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 3041 | if (extensions::BackgroundInfo::HasPersistentBackgroundPage(old)) { |
[email protected] | e7aa7b7e | 2012-11-27 04:51:22 | [diff] [blame] | 3042 | // Delay installation if the extension listens for the onUpdateAvailable |
| 3043 | // event. |
| 3044 | return system_->event_router()->ExtensionHasEventListener( |
| 3045 | extension_id, kOnUpdateAvailableEvent); |
| 3046 | } else { |
| 3047 | // Delay installation if the extension is not idle. |
| 3048 | return !IsExtensionIdle(extension_id); |
| 3049 | } |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 3050 | } |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3051 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3052 | void ExtensionService::GarbageCollectIsolatedStorage() { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3053 | scoped_ptr<base::hash_set<base::FilePath> > active_paths( |
| 3054 | new base::hash_set<base::FilePath>()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3055 | for (ExtensionSet::const_iterator it = extensions_.begin(); |
| 3056 | it != extensions_.end(); ++it) { |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3057 | if (extensions::AppIsolationInfo::HasIsolatedStorage(it->get())) { |
| 3058 | active_paths->insert(BrowserContext::GetStoragePartitionForSite( |
| 3059 | profile_, GetSiteForExtensionId((*it)->id()))->GetPath()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3060 | } |
| 3061 | } |
| 3062 | |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 3063 | DCHECK(!installs_delayed_for_gc()); |
| 3064 | set_installs_delayed_for_gc(true); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3065 | BrowserContext::GarbageCollectStoragePartitions( |
| 3066 | profile_, active_paths.Pass(), |
| 3067 | base::Bind(&ExtensionService::OnGarbageCollectIsolatedStorageFinished, |
| 3068 | AsWeakPtr())); |
| 3069 | } |
| 3070 | |
| 3071 | void ExtensionService::OnGarbageCollectIsolatedStorageFinished() { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 3072 | set_installs_delayed_for_gc(false); |
| 3073 | MaybeFinishDelayedInstallations(); |
| 3074 | } |
| 3075 | |
| 3076 | void ExtensionService::MaybeFinishDelayedInstallations() { |
| 3077 | std::vector<std::string> to_be_installed; |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3078 | for (ExtensionSet::const_iterator it = delayed_installs_.begin(); |
| 3079 | it != delayed_installs_.end(); |
| 3080 | ++it) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 3081 | to_be_installed.push_back((*it)->id()); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3082 | } |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 3083 | for (std::vector<std::string>::const_iterator it = to_be_installed.begin(); |
| 3084 | it != to_be_installed.end(); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3085 | ++it) { |
[email protected] | 9f4e4f08 | 2013-06-21 07:11:19 | [diff] [blame] | 3086 | MaybeFinishDelayedInstallation(*it); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3087 | } |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | void ExtensionService::OnNeedsToGarbageCollectIsolatedStorage() { |
| 3091 | extension_prefs_->SetNeedsStorageGarbageCollection(true); |
| 3092 | } |
| 3093 | |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3094 | void ExtensionService::OnBlacklistUpdated() { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3095 | blacklist_->GetBlacklistedIDs( |
| 3096 | GenerateInstalledExtensionsSet()->GetIDs(), |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3097 | base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3098 | } |
| 3099 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3100 | void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) { |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3101 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3102 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3103 | std::set<std::string> before = blacklisted_extensions_.GetIDs(); |
[email protected] | 16bf7ba7 | 2013-08-23 11:52:54 | [diff] [blame] | 3104 | std::set<std::string> no_longer_blacklisted = |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3105 | base::STLSetDifference<std::set<std::string> >(before, updated); |
[email protected] | 16bf7ba7 | 2013-08-23 11:52:54 | [diff] [blame] | 3106 | std::set<std::string> not_yet_blacklisted = |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3107 | base::STLSetDifference<std::set<std::string> >(updated, before); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3108 | |
| 3109 | for (std::set<std::string>::iterator it = no_longer_blacklisted.begin(); |
| 3110 | it != no_longer_blacklisted.end(); ++it) { |
| 3111 | scoped_refptr<const Extension> extension = |
| 3112 | blacklisted_extensions_.GetByID(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3113 | if (!extension.get()) { |
| 3114 | NOTREACHED() << "Extension " << *it << " no longer blacklisted, " |
| 3115 | << "but it was never blacklisted."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3116 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3117 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3118 | blacklisted_extensions_.Remove(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3119 | extension_prefs_->SetExtensionBlacklisted(extension->id(), false); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 3120 | AddExtension(extension.get()); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 3121 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled", |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 3122 | extension->location(), |
| 3123 | Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | for (std::set<std::string>::iterator it = not_yet_blacklisted.begin(); |
| 3127 | it != not_yet_blacklisted.end(); ++it) { |
| 3128 | scoped_refptr<const Extension> extension = GetInstalledExtension(*it); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3129 | if (!extension.get()) { |
| 3130 | NOTREACHED() << "Extension " << *it << " needs to be " |
| 3131 | << "blacklisted, but it's not installed."; |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3132 | continue; |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3133 | } |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3134 | blacklisted_extensions_.Insert(extension); |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame^] | 3135 | extension_prefs_->SetExtensionBlacklisted(extension->id(), true); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3136 | UnloadExtension(*it, extension_misc::UNLOAD_REASON_BLACKLIST); |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 3137 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled", |
| 3138 | extension->location(), Manifest::NUM_LOCATIONS); |
[email protected] | 695b571 | 2012-12-06 23:55:28 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | IdentifyAlertableExtensions(); |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 3142 | } |
[email protected] | 75bdcb87 | 2013-03-13 00:41:45 | [diff] [blame] | 3143 | |
| 3144 | void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { |
| 3145 | update_observers_.AddObserver(observer); |
| 3146 | } |
| 3147 | |
| 3148 | void ExtensionService::RemoveUpdateObserver( |
| 3149 | extensions::UpdateObserver* observer) { |
| 3150 | update_observers_.RemoveObserver(observer); |
| 3151 | } |