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