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