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