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