[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 12 | #include "base/file_util.h" |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 13 | #include "base/logging.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 14 | #include "base/metrics/histogram.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 15 | #include "base/path_service.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 16 | #include "base/stl_util.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 17 | #include "base/string16.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 18 | #include "base/string_number_conversions.h" |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 19 | #include "base/string_util.h" |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 20 | #include "base/stringprintf.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 21 | #include "base/threading/thread_restrictions.h" |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 22 | #include "base/time.h" |
[email protected] | ce7f62e3 | 2010-08-10 23:43:59 | [diff] [blame] | 23 | #include "base/utf_string_conversions.h" |
[email protected] | cc65591 | 2009-01-29 23:19:19 | [diff] [blame] | 24 | #include "base/values.h" |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 25 | #include "base/version.h" |
[email protected] | 15730c4 | 2009-09-03 00:03:20 | [diff] [blame] | 26 | #include "chrome/browser/browser_process.h" |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 27 | #include "chrome/browser/extensions/apps_promo.h" |
[email protected] | e078590 | 2011-05-19 23:34:17 | [diff] [blame] | 28 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_accessibility_api.h" |
[email protected] | 840b0db | 2009-11-20 03:00:38 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 32 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 33 | #include "chrome/browser/extensions/extension_data_deleter.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 34 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_history_api.h" |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | 7596ce7 | 2010-08-30 05:10:46 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_management_api.h" |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_preference_api.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_processes_api.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_updater.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 784688a6 | 2010-09-13 07:06:52 | [diff] [blame] | 47 | #include "chrome/browser/extensions/extension_webnavigation_api.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 48 | #include "chrome/browser/extensions/external_extension_provider_impl.h" |
[email protected] | 42b79565 | 2011-02-22 23:32:38 | [diff] [blame] | 49 | #include "chrome/browser/extensions/external_extension_provider_interface.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 50 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 51 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 52 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 53 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 54 | #include "chrome/browser/search_engines/template_url_service.h" |
| 55 | #include "chrome/browser/search_engines/template_url_service_factory.h" |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 56 | #include "chrome/browser/sync/api/sync_change.h" |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 57 | #include "chrome/browser/themes/theme_service.h" |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 58 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 59 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 60 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 7c5c6f3a | 2011-04-28 19:56:49 | [diff] [blame] | 61 | #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 62 | #include "chrome/common/child_process_logging.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 63 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 64 | #include "chrome/common/chrome_paths.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 65 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 66 | #include "chrome/common/extensions/extension.h" |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 67 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 68 | #include "chrome/common/extensions/extension_error_utils.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 69 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 70 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 71 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 72 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 73 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 74 | #include "chrome/common/url_constants.h" |
[email protected] | 5f945a0e | 2011-03-01 17:47:53 | [diff] [blame] | 75 | #include "content/browser/browser_thread.h" |
[email protected] | b46442d7e | 2011-06-29 02:16:06 | [diff] [blame] | 76 | #include "content/browser/debugger/devtools_manager.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 77 | #include "content/browser/plugin_process_host.h" |
| 78 | #include "content/browser/plugin_service.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 79 | #include "content/browser/renderer_host/render_process_host.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 80 | #include "content/common/content_notification_types.h" |
[email protected] | c311302 | 2011-04-16 03:26:30 | [diff] [blame] | 81 | #include "content/common/json_value_serializer.h" |
[email protected] | b3841c50 | 2011-03-09 01:21:31 | [diff] [blame] | 82 | #include "content/common/notification_service.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 83 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 84 | #include "googleurl/src/gurl.h" |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 85 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 86 | #include "webkit/database/database_tracker.h" |
| 87 | #include "webkit/database/database_util.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 88 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 89 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 90 | #if defined(OS_CHROMEOS) |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 91 | #include "chrome/browser/chromeos/cros/cros_library.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 92 | #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 93 | #include "chrome/browser/chromeos/extensions/input_method_event_router.h" |
[email protected] | ce980204 | 2011-05-27 10:11:40 | [diff] [blame] | 94 | #include "chrome/browser/chromeos/extensions/media_player_event_router.h" |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 95 | #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
| 96 | #include "chrome/browser/extensions/extension_input_ime_api.h" |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 97 | #include "webkit/fileapi/file_system_context.h" |
| 98 | #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 99 | #include "webkit/fileapi/file_system_path_manager.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 100 | #endif |
| 101 | |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 102 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 103 | #include "chrome/browser/extensions/extension_input_ui_api.h" |
| 104 | #endif |
| 105 | |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 106 | using base::Time; |
| 107 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 108 | namespace errors = extension_manifest_errors; |
| 109 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 110 | namespace { |
| 111 | |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 112 | #if defined(OS_LINUX) |
| 113 | static const int kOmniboxIconPaddingLeft = 2; |
| 114 | static const int kOmniboxIconPaddingRight = 2; |
| 115 | #elif defined(OS_MACOSX) |
| 116 | static const int kOmniboxIconPaddingLeft = 0; |
| 117 | static const int kOmniboxIconPaddingRight = 2; |
| 118 | #else |
| 119 | static const int kOmniboxIconPaddingLeft = 0; |
| 120 | static const int kOmniboxIconPaddingRight = 0; |
| 121 | #endif |
| 122 | |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 123 | const char* kNaClPluginMimeType = "application/x-nacl"; |
| 124 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 125 | // The following enumeration is used in histograms matching |
| 126 | // Extensions.ManifestReload* . Values may be added, as long |
| 127 | // as existing values are not changed. |
| 128 | enum ManifestReloadReason { |
| 129 | NOT_NEEDED = 0, // Reload not needed. |
| 130 | UNPACKED_DIR, // Unpacked directory |
| 131 | NEEDS_RELOCALIZATION, // The local has changed since we read this extension. |
| 132 | NUM_MANIFEST_RELOAD_REASONS |
| 133 | }; |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 134 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 135 | ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) { |
| 136 | // Always reload manifests of unpacked extensions, because they can change |
| 137 | // on disk independent of the manifest in our prefs. |
| 138 | if (info.extension_location == Extension::LOAD) |
| 139 | return UNPACKED_DIR; |
| 140 | |
| 141 | // Reload the manifest if it needs to be relocalized. |
| 142 | if (extension_l10n_util::ShouldRelocalizeManifest(info)) |
| 143 | return NEEDS_RELOCALIZATION; |
| 144 | |
| 145 | return NOT_NEEDED; |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 148 | static void ForceShutdownPlugin(const FilePath& plugin_path) { |
| 149 | PluginProcessHost* plugin = |
| 150 | PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path); |
| 151 | if (plugin) |
| 152 | plugin->ForceShutdown(); |
| 153 | } |
| 154 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 155 | static bool IsSyncableExtension(const Extension& extension) { |
| 156 | return extension.GetSyncType() == Extension::SYNC_TYPE_EXTENSION; |
| 157 | } |
| 158 | |
| 159 | static bool IsSyncableApp(const Extension& extension) { |
| 160 | return extension.GetSyncType() == Extension::SYNC_TYPE_APP; |
| 161 | } |
| 162 | |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 163 | // Manages an ExtensionInstallUI for a particular extension. |
| 164 | class SimpleExtensionLoadPrompt : public ExtensionInstallUI::Delegate { |
| 165 | public: |
| 166 | SimpleExtensionLoadPrompt(Profile* profile, |
| 167 | base::WeakPtr<ExtensionService> extension_service, |
| 168 | const Extension* extension); |
| 169 | ~SimpleExtensionLoadPrompt(); |
| 170 | |
| 171 | void ShowPrompt(); |
| 172 | |
| 173 | // ExtensionInstallUI::Delegate |
| 174 | virtual void InstallUIProceed(); |
[email protected] | d828fac | 2011-06-28 05:43:04 | [diff] [blame] | 175 | virtual void InstallUIAbort(bool user_initiated); |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 176 | |
| 177 | private: |
| 178 | base::WeakPtr<ExtensionService> extension_service_; |
| 179 | scoped_ptr<ExtensionInstallUI> install_ui_; |
| 180 | scoped_refptr<const Extension> extension_; |
| 181 | }; |
| 182 | |
| 183 | SimpleExtensionLoadPrompt::SimpleExtensionLoadPrompt( |
| 184 | Profile* profile, |
| 185 | base::WeakPtr<ExtensionService> extension_service, |
| 186 | const Extension* extension) |
| 187 | : extension_service_(extension_service), |
| 188 | install_ui_(new ExtensionInstallUI(profile)), |
| 189 | extension_(extension) { |
| 190 | } |
| 191 | |
| 192 | SimpleExtensionLoadPrompt::~SimpleExtensionLoadPrompt() { |
| 193 | } |
| 194 | |
| 195 | void SimpleExtensionLoadPrompt::ShowPrompt() { |
| 196 | install_ui_->ConfirmInstall(this, extension_); |
| 197 | } |
| 198 | |
| 199 | void SimpleExtensionLoadPrompt::InstallUIProceed() { |
| 200 | if (extension_service_.get()) |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 201 | extension_service_->OnExtensionInstalled( |
[email protected] | f1b6665 | 2011-08-25 23:30:58 | [diff] [blame] | 202 | extension_, false, -1); // Not from web store. |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 203 | delete this; |
| 204 | } |
| 205 | |
[email protected] | d828fac | 2011-06-28 05:43:04 | [diff] [blame] | 206 | void SimpleExtensionLoadPrompt::InstallUIAbort(bool user_initiated) { |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 207 | delete this; |
| 208 | } |
| 209 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 210 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 211 | |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 212 | bool ExtensionService::ComponentExtensionInfo::Equals( |
| 213 | const ComponentExtensionInfo& other) const { |
| 214 | return other.manifest == manifest && other.root_directory == root_directory; |
| 215 | } |
| 216 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 217 | ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 218 | : background_page_ready(false), |
| 219 | being_upgraded(false) { |
| 220 | } |
| 221 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 222 | ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 225 | ExtensionService::NaClModuleInfo::NaClModuleInfo() { |
| 226 | } |
| 227 | |
| 228 | ExtensionService::NaClModuleInfo::~NaClModuleInfo() { |
| 229 | } |
| 230 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 231 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 232 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 233 | const char* ExtensionService::kInstallDirectoryName = "Extensions"; |
| 234 | const char* ExtensionService::kCurrentVersionFileName = "Current Version"; |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 235 | const char* ExtensionService::kSettingsDirectoryName = "Extension Settings"; |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 236 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 237 | // Implements IO for the ExtensionService. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 238 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 239 | class ExtensionServiceBackend |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 240 | : public base::RefCountedThreadSafe<ExtensionServiceBackend> { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 241 | public: |
[email protected] | 1f830eb | 2010-09-28 08:25:14 | [diff] [blame] | 242 | // |install_directory| is a path where to look for extensions to load. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 243 | ExtensionServiceBackend( |
| 244 | base::WeakPtr<ExtensionService> frontend, |
| 245 | const FilePath& install_directory); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 246 | |
| 247 | // Loads a single extension from |path| where |path| is the top directory of |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 248 | // a specific extension where its manifest file lives. If |prompt_for_plugins| |
| 249 | // is true and the extension contains plugins, we prompt the user before |
| 250 | // loading. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 251 | // Errors are reported through ExtensionErrorReporter. On success, |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 252 | // AddExtension() is called. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 253 | // TODO(erikkay): It might be useful to be able to load a packed extension |
| 254 | // (presumably into memory) without installing it. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 255 | void LoadSingleExtension(const FilePath &path, bool prompt_for_plugins); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 256 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 257 | private: |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 258 | friend class base::RefCountedThreadSafe<ExtensionServiceBackend>; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 259 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 260 | virtual ~ExtensionServiceBackend(); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 261 | |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 262 | // LoadSingleExtension needs to check the file access preference, which needs |
| 263 | // to happen back on the UI thread, so it posts CheckExtensionFileAccess on |
| 264 | // the UI thread. In turn, once that gets the pref, it goes back to the |
| 265 | // file thread with LoadSingleExtensionWithFileAccess. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 266 | void CheckExtensionFileAccess(const FilePath& extension_path, |
| 267 | bool prompt_for_plugins); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 268 | void LoadSingleExtensionWithFileAccess( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 269 | const FilePath &path, bool allow_file_access, bool prompt_for_plugins); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 270 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 271 | // Notify the frontend that there was an error loading an extension. |
| 272 | void ReportExtensionLoadError(const FilePath& extension_path, |
| 273 | const std::string& error); |
| 274 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 275 | // Notify the frontend that an extension was installed. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 276 | void OnLoadSingleExtension(const scoped_refptr<const Extension>& extension, |
| 277 | bool prompt_for_plugins); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 278 | |
| 279 | base::WeakPtr<ExtensionService> frontend_; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 280 | |
| 281 | // The top-level extensions directory being installed to. |
| 282 | FilePath install_directory_; |
| 283 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 284 | DISALLOW_COPY_AND_ASSIGN(ExtensionServiceBackend); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 285 | }; |
| 286 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 287 | ExtensionServiceBackend::ExtensionServiceBackend( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 288 | base::WeakPtr<ExtensionService> frontend, |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 289 | const FilePath& install_directory) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 290 | : frontend_(frontend), |
| 291 | install_directory_(install_directory) { |
| 292 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 293 | } |
| 294 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 295 | ExtensionServiceBackend::~ExtensionServiceBackend() { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 296 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 297 | BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 298 | } |
| 299 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 300 | void ExtensionServiceBackend::LoadSingleExtension(const FilePath& path_in, |
| 301 | bool prompt_for_plugins) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 302 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 303 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 304 | FilePath extension_path = path_in; |
| 305 | file_util::AbsolutePath(&extension_path); |
| 306 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 307 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 308 | NewRunnableMethod(this, |
| 309 | &ExtensionServiceBackend::CheckExtensionFileAccess, |
| 310 | extension_path, prompt_for_plugins)); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | void ExtensionServiceBackend::CheckExtensionFileAccess( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 314 | const FilePath& extension_path, bool prompt_for_plugins) { |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 315 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 316 | std::string id = Extension::GenerateIdForPath(extension_path); |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 317 | // Unpacked extensions default to allowing file access, but if that has been |
| 318 | // overridden, don't reset the value. |
| 319 | bool allow_file_access = |
| 320 | Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); |
| 321 | if (frontend_->extension_prefs()->HasAllowFileAccessSetting(id)) |
| 322 | allow_file_access = frontend_->extension_prefs()->AllowFileAccess(id); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 323 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 324 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 325 | NewRunnableMethod( |
| 326 | this, |
| 327 | &ExtensionServiceBackend::LoadSingleExtensionWithFileAccess, |
| 328 | extension_path, allow_file_access, prompt_for_plugins)); |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 331 | void ExtensionServiceBackend::LoadSingleExtensionWithFileAccess( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 332 | const FilePath& extension_path, |
| 333 | bool allow_file_access, |
| 334 | bool prompt_for_plugins) { |
[email protected] | d10f460 | 2011-06-16 15:44:50 | [diff] [blame] | 335 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 336 | int flags = allow_file_access ? |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 337 | Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS; |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 338 | if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
| 339 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 340 | std::string error; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 341 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 342 | extension_path, |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 343 | Extension::LOAD, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 344 | flags, |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 345 | &error)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 346 | |
| 347 | if (!extension) { |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 348 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 349 | NewRunnableMethod( |
| 350 | this, |
| 351 | &ExtensionServiceBackend::ReportExtensionLoadError, |
| 352 | extension_path, error)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 356 | // Report this as an installed extension so that it gets remembered in the |
| 357 | // prefs. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 358 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 359 | NewRunnableMethod( |
| 360 | this, |
| 361 | &ExtensionServiceBackend::OnLoadSingleExtension, |
| 362 | extension, prompt_for_plugins)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 363 | } |
| 364 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 365 | void ExtensionServiceBackend::ReportExtensionLoadError( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 366 | const FilePath& extension_path, const std::string &error) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 367 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 368 | if (frontend_.get()) |
| 369 | frontend_->ReportExtensionLoadError( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 370 | extension_path, error, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 371 | true /* alert_on_error */); |
| 372 | } |
| 373 | |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 374 | void ExtensionServiceBackend::OnLoadSingleExtension( |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 375 | const scoped_refptr<const Extension>& extension, bool prompt_for_plugins) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 376 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 377 | if (frontend_.get()) |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 378 | frontend_->OnLoadSingleExtension(extension, prompt_for_plugins); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 381 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 382 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 383 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 384 | // Check if the providers know about this extension. |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 385 | ProviderCollection::const_iterator i; |
| 386 | for (i = external_extension_providers_.begin(); |
| 387 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 388 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 389 | if (i->get()->HasExtension(id)) |
| 390 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 391 | } |
| 392 | |
[email protected] | 0f48fca | 2011-05-19 18:46:35 | [diff] [blame] | 393 | // We get the list of external extensions to check from preferences. |
| 394 | // It is possible that an extension has preferences but is not loaded. |
| 395 | // For example, an extension that requires experimental permissions |
| 396 | // will not be loaded if the experimental command line flag is not used. |
| 397 | // In this case, do not uninstall. |
| 398 | const Extension* extension = GetInstalledExtension(id); |
| 399 | if (!extension) { |
| 400 | // We can't call UninstallExtension with an unloaded/invalid |
| 401 | // extension ID. |
| 402 | LOG(WARNING) << "Attempted uninstallation of unloaded/invalid extension " |
| 403 | << "with id: " << id; |
| 404 | return; |
| 405 | } |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 406 | UninstallExtension(id, true, NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 407 | } |
| 408 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 409 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 410 | external_extension_providers_.clear(); |
| 411 | } |
| 412 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 413 | void ExtensionService::AddProviderForTesting( |
| 414 | ExternalExtensionProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 415 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 416 | external_extension_providers_.push_back( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 417 | linked_ptr<ExternalExtensionProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 420 | void ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 421 | const std::string& id, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 422 | const GURL& update_url, |
| 423 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 424 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 425 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 426 | |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 427 | const Extension* extension = GetExtensionById(id, true); |
| 428 | if (extension) { |
| 429 | // Already installed. Skip this install if the current location has |
| 430 | // higher priority than |location|. |
| 431 | Extension::Location current = extension->location(); |
| 432 | if (current == Extension::GetHigherPriorityLocation(current, location)) |
| 433 | return; |
| 434 | // Otherwise, overwrite the current installation. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 435 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 436 | pending_extension_manager()->AddFromExternalUpdateUrl( |
| 437 | id, update_url, location); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 438 | external_extension_url_added_ |= true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 439 | } |
| 440 | |
[email protected] | 454434f | 2011-08-24 04:00:00 | [diff] [blame] | 441 | // If a download url matches one of these patterns and has a referrer of the |
| 442 | // webstore, then we're willing to treat that as a gallery download. |
| 443 | static const char* kAllowedDownloadURLPatterns[] = { |
| 444 | "https://clients2.google.com/service/update2*", |
| 445 | "https://clients2.googleusercontent.com/crx/*" |
| 446 | }; |
| 447 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 448 | bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 449 | const GURL& referrer_url) { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 450 | // Special-case the themes mini-gallery. |
| 451 | // TODO(erikkay) When that gallery goes away, remove this code. |
| 452 | if (IsDownloadFromMiniGallery(download_url) && |
| 453 | StartsWithASCII(referrer_url.spec(), |
| 454 | extension_urls::kMiniGalleryBrowsePrefix, false)) { |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 455 | return true; |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 456 | } |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 457 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 458 | const Extension* download_extension = GetExtensionByWebExtent(download_url); |
| 459 | const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url); |
| 460 | const Extension* webstore_app = GetWebStoreApp(); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 461 | |
| 462 | bool referrer_valid = (referrer_extension == webstore_app); |
| 463 | bool download_valid = (download_extension == webstore_app); |
| 464 | |
[email protected] | 454434f | 2011-08-24 04:00:00 | [diff] [blame] | 465 | // We also allow the download to be from a small set of trusted paths. |
| 466 | if (!download_valid) { |
| 467 | for (size_t i = 0; i < arraysize(kAllowedDownloadURLPatterns); i++) { |
| 468 | URLPattern pattern(URLPattern::SCHEME_HTTPS, |
| 469 | kAllowedDownloadURLPatterns[i]); |
| 470 | if (pattern.MatchesURL(download_url)) { |
| 471 | download_valid = true; |
| 472 | break; |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 477 | // If the command-line gallery URL is set, then be a bit more lenient. |
| 478 | GURL store_url = |
| 479 | GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 480 | switches::kAppsGalleryURL)); |
| 481 | if (!store_url.is_empty()) { |
| 482 | std::string store_tld = |
| 483 | net::RegistryControlledDomainService::GetDomainAndRegistry(store_url); |
| 484 | if (!referrer_valid) { |
| 485 | std::string referrer_tld = |
| 486 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
| 487 | referrer_url); |
| 488 | // The referrer gets stripped when transitioning from https to http, |
| 489 | // or when hitting an unknown test cert and that commonly happens in |
| 490 | // testing environments. Given this, we allow an empty referrer when |
| 491 | // the command-line flag is set. |
| 492 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 493 | referrer_valid = referrer_url.is_empty() || (referrer_tld == store_tld); |
| 494 | } |
| 495 | |
| 496 | if (!download_valid) { |
| 497 | std::string download_tld = |
| 498 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 499 | download_url); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 500 | |
| 501 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 502 | download_valid = (download_tld == store_tld); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | return (referrer_valid && download_valid); |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 507 | } |
| 508 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 509 | bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) { |
[email protected] | ac02528 | 2009-12-16 19:16:38 | [diff] [blame] | 510 | return StartsWithASCII(download_url.spec(), |
| 511 | extension_urls::kMiniGalleryDownloadPrefix, |
| 512 | false); // case_sensitive |
| 513 | } |
| 514 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 515 | const Extension* ExtensionService::GetInstalledApp(const GURL& url) { |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 516 | // Check for hosted app. |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 517 | const Extension* app = GetExtensionByWebExtent(url); |
| 518 | if (app) |
| 519 | return app; |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 520 | |
| 521 | // Check for packaged app. |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 522 | app = GetExtensionByURL(url); |
| 523 | if (app && app->is_app()) |
| 524 | return app; |
| 525 | |
| 526 | return NULL; |
| 527 | } |
| 528 | |
| 529 | bool ExtensionService::IsInstalledApp(const GURL& url) { |
| 530 | return !!GetInstalledApp(url); |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 531 | } |
| 532 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 533 | void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, |
| 534 | const Extension* app) { |
| 535 | installed_app_hosts_[renderer_child_id] = app; |
| 536 | } |
| 537 | |
| 538 | const Extension* ExtensionService::GetInstalledAppForRenderer( |
| 539 | int renderer_child_id) { |
| 540 | InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); |
| 541 | if (i == installed_app_hosts_.end()) |
| 542 | return NULL; |
| 543 | return i->second; |
| 544 | } |
| 545 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 546 | // static |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 547 | // This function is used to implement the command-line switch |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 548 | // --uninstall-extension, and to uninstall an extension via sync. The LOG |
| 549 | // statements within this function are used to inform the user if the uninstall |
| 550 | // cannot be done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 551 | bool ExtensionService::UninstallExtensionHelper( |
| 552 | ExtensionService* extensions_service, |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 553 | const std::string& extension_id) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 554 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 555 | const Extension* extension = |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 556 | extensions_service->GetInstalledExtension(extension_id); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 557 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 558 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 559 | if (!extension) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 560 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 561 | << "id: " << extension_id; |
| 562 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 563 | } |
| 564 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 565 | // The following call to UninstallExtension will not allow an uninstall of a |
| 566 | // policy-controlled extension. |
| 567 | std::string error; |
| 568 | if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 569 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 570 | << ": " << error; |
| 571 | return false; |
| 572 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 573 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 574 | return true; |
| 575 | } |
| 576 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 577 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 578 | const CommandLine* command_line, |
| 579 | const FilePath& install_directory, |
| 580 | ExtensionPrefs* extension_prefs, |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 581 | ExtensionSettings* extension_settings, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 582 | bool autoupdate_enabled, |
| 583 | bool extensions_enabled) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 584 | : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 585 | method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 586 | profile_(profile), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 587 | extension_prefs_(extension_prefs), |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 588 | extension_settings_(extension_settings), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 589 | pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 590 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 591 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 592 | show_extensions_prompts_(true), |
[email protected] | 3ecda25 | 2010-11-18 19:50:55 | [diff] [blame] | 593 | ready_(false), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 594 | toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 595 | permissions_manager_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 596 | apps_promo_(profile->GetPrefs()), |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 597 | event_routers_initialized_(false) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 598 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 599 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 600 | // Figure out if extension installation should be enabled. |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 601 | if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 602 | extensions_enabled_ = false; |
| 603 | } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 604 | extensions_enabled_ = false; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 605 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 606 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 607 | registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 608 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 609 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 610 | NotificationService::AllSources()); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 611 | registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 612 | NotificationService::AllSources()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 613 | pref_change_registrar_.Init(profile->GetPrefs()); |
| 614 | pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); |
| 615 | pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 616 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 617 | // Set up the ExtensionUpdater |
| 618 | if (autoupdate_enabled) { |
| 619 | int update_frequency = kDefaultUpdateFrequencySeconds; |
| 620 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 621 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 622 | switches::kExtensionsUpdateFrequency), |
| 623 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 624 | } |
[email protected] | 82b6e51 | 2011-04-12 20:33:27 | [diff] [blame] | 625 | updater_.reset(new ExtensionUpdater(this, |
| 626 | extension_prefs, |
| 627 | profile->GetPrefs(), |
| 628 | profile, |
| 629 | update_frequency)); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 632 | backend_ = |
| 633 | new ExtensionServiceBackend(weak_ptr_factory_.GetWeakPtr(), |
| 634 | install_directory_); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 635 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 636 | if (extensions_enabled_) { |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 637 | ExternalExtensionProviderImpl::CreateExternalProviders( |
| 638 | this, profile_, &external_extension_providers_); |
| 639 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 640 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 641 | // Use monochrome icons for Omnibox icons. |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 642 | omnibox_popup_icon_manager_.set_monochrome(true); |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 643 | omnibox_icon_manager_.set_monochrome(true); |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 644 | omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
| 645 | 0, kOmniboxIconPaddingRight)); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 646 | |
| 647 | // How long is the path to the Extensions directory? |
| 648 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 649 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 650 | } |
| 651 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 652 | const ExtensionList* ExtensionService::extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 653 | return &extensions_; |
| 654 | } |
| 655 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 656 | const ExtensionList* ExtensionService::disabled_extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 657 | return &disabled_extensions_; |
| 658 | } |
| 659 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 660 | const ExtensionList* ExtensionService::terminated_extensions() const { |
| 661 | return &terminated_extensions_; |
| 662 | } |
| 663 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 664 | PendingExtensionManager* ExtensionService::pending_extension_manager() { |
| 665 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 668 | void ExtensionService::UnregisterComponentExtension( |
| 669 | const ComponentExtensionInfo& info) { |
| 670 | RegisteredComponentExtensions new_component_extension_manifests; |
| 671 | for (RegisteredComponentExtensions::iterator it = |
| 672 | component_extension_manifests_.begin(); |
| 673 | it != component_extension_manifests_.end(); ++it) { |
| 674 | if (!it->Equals(info)) |
| 675 | new_component_extension_manifests.push_back(*it); |
| 676 | } |
| 677 | component_extension_manifests_.swap(new_component_extension_manifests); |
| 678 | } |
| 679 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 680 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 681 | // No need to unload extensions here because they are profile-scoped, and the |
| 682 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 683 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 684 | ProviderCollection::const_iterator i; |
| 685 | for (i = external_extension_providers_.begin(); |
| 686 | i != external_extension_providers_.end(); ++i) { |
| 687 | ExternalExtensionProviderInterface* provider = i->get(); |
| 688 | provider->ServiceShutdown(); |
| 689 | } |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 690 | } |
| 691 | |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame^] | 692 | void ExtensionService::InitEventRoutersAfterImport() { |
| 693 | registrar_.Add(this, chrome::NOTIFICATION_IMPORT_FINISHED, |
| 694 | Source<Profile>(profile_)); |
| 695 | } |
| 696 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 697 | void ExtensionService::InitEventRouters() { |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 698 | if (event_routers_initialized_) |
| 699 | return; |
| 700 | |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 701 | history_event_router_.reset(new ExtensionHistoryEventRouter()); |
| 702 | history_event_router_->ObserveProfile(profile_); |
[email protected] | 7da9a823 | 2011-05-27 21:07:11 | [diff] [blame] | 703 | ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 704 | browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_)); |
| 705 | browser_event_router_->Init(); |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 706 | preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_)); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 707 | bookmark_event_router_.reset(new ExtensionBookmarkEventRouter( |
| 708 | profile_->GetBookmarkModel())); |
| 709 | bookmark_event_router_->Init(); |
| 710 | cookies_event_router_.reset(new ExtensionCookiesEventRouter(profile_)); |
| 711 | cookies_event_router_->Init(); |
| 712 | management_event_router_.reset(new ExtensionManagementEventRouter(profile_)); |
| 713 | management_event_router_->Init(); |
[email protected] | 7da9a823 | 2011-05-27 21:07:11 | [diff] [blame] | 714 | ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | f825df2 | 2011-06-28 17:36:10 | [diff] [blame] | 715 | web_navigation_event_router_.reset( |
| 716 | new ExtensionWebNavigationEventRouter(profile_)); |
| 717 | web_navigation_event_router_->Init(); |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 718 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 719 | #if defined(OS_CHROMEOS) |
[email protected] | b16fc2e | 2011-07-21 21:32:58 | [diff] [blame] | 720 | file_browser_event_router_.reset( |
| 721 | new ExtensionFileBrowserEventRouter(profile_)); |
| 722 | file_browser_event_router_->ObserveFileSystemEvents(); |
[email protected] | be5bd574 | 2011-07-14 07:21:01 | [diff] [blame] | 723 | // Lazy initialization. |
| 724 | chromeos::ExtensionInputMethodEventRouter::GetInstance(); |
| 725 | |
[email protected] | c8bf09be | 2011-06-25 03:22:27 | [diff] [blame] | 726 | ExtensionMediaPlayerEventRouter::GetInstance()->Init(profile_); |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 727 | ExtensionInputImeEventRouter::GetInstance()->Init(); |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 728 | #endif |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame] | 729 | |
| 730 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
| 731 | ExtensionInputUiEventRouter::GetInstance()->Init(); |
| 732 | #endif |
| 733 | |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 734 | event_routers_initialized_ = true; |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 735 | } |
| 736 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 737 | const Extension* ExtensionService::GetExtensionById( |
| 738 | const std::string& id, bool include_disabled) const { |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 739 | return GetExtensionByIdInternal(id, true, include_disabled, false); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 740 | } |
| 741 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 742 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 743 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 744 | |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 745 | DCHECK(!ready_); // Can't redo init. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 746 | DCHECK_EQ(extensions_.size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 747 | |
[email protected] | 95dd38f | 2009-10-20 20:09:15 | [diff] [blame] | 748 | // Hack: we need to ensure the ResourceDispatcherHost is ready before we load |
| 749 | // the first extension, because its members listen for loaded notifications. |
| 750 | g_browser_process->resource_dispatcher_host(); |
| 751 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 752 | LoadAllExtensions(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 753 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 754 | // TODO(erikkay) this should probably be deferred to a future point |
| 755 | // rather than running immediately at startup. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 756 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 757 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 758 | // TODO(erikkay) this should probably be deferred as well. |
| 759 | GarbageCollectExtensions(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 762 | bool ExtensionService::UpdateExtension( |
| 763 | const std::string& id, |
| 764 | const FilePath& extension_path, |
| 765 | const GURL& download_url, |
| 766 | CrxInstaller** out_crx_installer) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 767 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 768 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 769 | PendingExtensionInfo pending_extension_info; |
| 770 | bool is_pending_extension = pending_extension_manager_.GetById( |
| 771 | id, &pending_extension_info); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 772 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 773 | const Extension* extension = |
| 774 | GetExtensionByIdInternal(id, true, true, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 775 | if (!is_pending_extension && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 776 | LOG(WARNING) << "Will not update extension " << id |
| 777 | << " because it is not installed or pending"; |
| 778 | // Delete extension_path since we're not creating a CrxInstaller |
| 779 | // that would do it for us. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 780 | if (!BrowserThread::PostTask( |
| 781 | BrowserThread::FILE, FROM_HERE, |
| 782 | NewRunnableFunction( |
| 783 | extension_file_util::DeleteFile, extension_path, false))) |
| 784 | NOTREACHED(); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 785 | |
| 786 | return false; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 789 | // We want a silent install only for non-pending extensions and |
| 790 | // pending extensions that have install_silently set. |
| 791 | ExtensionInstallUI* client = |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 792 | (!is_pending_extension || pending_extension_info.install_silently()) ? |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 793 | NULL : new ExtensionInstallUI(profile_); |
| 794 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 795 | scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 796 | installer->set_expected_id(id); |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 797 | if (is_pending_extension) |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 798 | installer->set_install_source(pending_extension_info.install_source()); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 799 | else if (extension) |
| 800 | installer->set_install_source(extension->location()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 801 | if (pending_extension_info.install_silently()) |
| 802 | installer->set_allow_silent_install(true); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 803 | installer->set_delete_source(true); |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 804 | installer->set_original_url(download_url); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 805 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 806 | installer->InstallCrx(extension_path); |
[email protected] | 420a0ec | 2011-06-01 01:07:03 | [diff] [blame] | 807 | |
| 808 | if (out_crx_installer) |
| 809 | *out_crx_installer = installer; |
| 810 | |
| 811 | return true; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 812 | } |
| 813 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 814 | void ExtensionService::ReloadExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 815 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 816 | FilePath path; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 817 | const Extension* current_extension = GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 818 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 819 | // 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] | 820 | if (current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 821 | // If the extension has an inspector open for its background page, detach |
| 822 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 823 | // later. |
| 824 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 825 | ExtensionHost* host = manager->GetBackgroundHostForExtension( |
| 826 | current_extension); |
| 827 | if (host) { |
| 828 | // Look for an open inspector for the background page. |
| 829 | int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost( |
| 830 | host->render_view_host()); |
| 831 | if (devtools_cookie >= 0) |
| 832 | orphaned_dev_tools_[extension_id] = devtools_cookie; |
| 833 | } |
| 834 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 835 | path = current_extension->path(); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 836 | DisableExtension(extension_id); |
| 837 | disabled_extension_paths_[extension_id] = path; |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 838 | } else { |
| 839 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 840 | } |
| 841 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 842 | // Check the installed extensions to see if what we're reloading was already |
| 843 | // installed. |
| 844 | scoped_ptr<ExtensionInfo> installed_extension( |
| 845 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 846 | if (installed_extension.get() && |
| 847 | installed_extension->extension_manifest.get()) { |
| 848 | LoadInstalledExtension(*installed_extension, false); |
| 849 | } else { |
| 850 | // We should always be able to remember the extension's path. If it's not in |
| 851 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 852 | CHECK(!path.empty()); |
| 853 | LoadExtension(path); |
| 854 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 855 | } |
| 856 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 857 | bool ExtensionService::UninstallExtension( |
| 858 | const std::string& extension_id_unsafe, |
| 859 | bool external_uninstall, |
| 860 | std::string* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 861 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 862 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 863 | // Copy the extension identifier since the reference might have been |
| 864 | // obtained via Extension::id() and the extension may be deleted in |
| 865 | // this function. |
| 866 | std::string extension_id(extension_id_unsafe); |
| 867 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 868 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 869 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 870 | // Callers should not send us nonexistent extensions. |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 871 | CHECK(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 872 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 873 | // Get hold of information we need after unloading, since the extension |
| 874 | // pointer will be invalid then. |
| 875 | GURL extension_url(extension->url()); |
| 876 | Extension::Location location(extension->location()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 877 | |
| 878 | // Policy change which triggers an uninstall will always set |
| 879 | // |external_uninstall| to true so this is the only way to uninstall |
| 880 | // managed extensions. |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 881 | if (!Extension::UserMayDisable(location) && !external_uninstall) { |
| 882 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 883 | chrome::NOTIFICATION_EXTENSION_UNINSTALL_NOT_ALLOWED, |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 884 | Source<Profile>(profile_), |
| 885 | Details<const Extension>(extension)); |
| 886 | if (error != NULL) { |
| 887 | *error = errors::kCannotUninstallManagedExtension; |
| 888 | } |
| 889 | return false; |
| 890 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 891 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 892 | // Extract the data we need for sync now, but don't actually sync until we've |
| 893 | // completed the uninstallation. |
| 894 | SyncBundle* sync_bundle = GetSyncBundleForExtension(*extension); |
| 895 | |
| 896 | SyncChange sync_change; |
| 897 | if (sync_bundle) { |
| 898 | ExtensionSyncData extension_sync_data(*extension, |
| 899 | IsExtensionEnabled(extension_id), |
| 900 | IsIncognitoEnabled(extension_id)); |
| 901 | sync_change = extension_sync_data.GetSyncChange(SyncChange::ACTION_DELETE); |
| 902 | } |
| 903 | |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 904 | UninstalledExtensionInfo uninstalled_extension_info(*extension); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 905 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 906 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 907 | extension->GetType(), 100); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 908 | RecordPermissionMessagesHistogram( |
| 909 | extension, "Extensions.Permissions_Uninstall"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 910 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 911 | TemplateURLService* url_service = |
| 912 | TemplateURLServiceFactory::GetForProfile(profile_); |
| 913 | if (url_service) |
| 914 | url_service->UnregisterExtensionKeyword(extension); |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 915 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 916 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 917 | // any of these resources. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 918 | UnloadExtension(extension_id, extension_misc::UNLOAD_REASON_UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 919 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 920 | extension_prefs_->OnExtensionUninstalled(extension_id, location, |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 921 | external_uninstall); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 922 | |
| 923 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 924 | if (Extension::LOAD != location) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 925 | if (!BrowserThread::PostTask( |
| 926 | BrowserThread::FILE, FROM_HERE, |
| 927 | NewRunnableFunction( |
| 928 | &extension_file_util::UninstallExtension, |
| 929 | install_directory_, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 930 | extension_id))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 931 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 932 | } |
| 933 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 934 | ClearExtensionData(extension_url); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 935 | UntrackTerminatedExtension(extension_id); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 936 | |
| 937 | // Notify interested parties that we've uninstalled this extension. |
| 938 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 939 | chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 940 | Source<Profile>(profile_), |
| 941 | Details<UninstalledExtensionInfo>(&uninstalled_extension_info)); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 942 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 943 | if (sync_bundle && sync_bundle->HasExtensionId(extension_id)) { |
| 944 | sync_bundle->sync_processor->ProcessSyncChanges( |
| 945 | FROM_HERE, SyncChangeList(1, sync_change)); |
| 946 | sync_bundle->synced_extensions.erase(extension_id); |
| 947 | } |
| 948 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 949 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 950 | } |
| 951 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 952 | void ExtensionService::ClearExtensionData(const GURL& extension_url) { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 953 | scoped_refptr<ExtensionDataDeleter> deleter( |
| 954 | new ExtensionDataDeleter(profile_, extension_url)); |
| 955 | deleter->StartDeleting(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 956 | } |
| 957 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 958 | bool ExtensionService::IsExtensionEnabled( |
| 959 | const std::string& extension_id) const { |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 960 | const Extension* extension = |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 961 | GetExtensionByIdInternal(extension_id, true, false, true); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 962 | if (extension) |
| 963 | return true; |
| 964 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 965 | extension = |
| 966 | GetExtensionByIdInternal(extension_id, false, true, false); |
| 967 | if (extension) |
| 968 | return false; |
| 969 | |
| 970 | // If the extension hasn't been loaded yet, check the prefs for it. Assume |
| 971 | // enabled unless otherwise noted. |
| 972 | return !extension_prefs_->IsExtensionDisabled(extension_id) && |
| 973 | !extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | bool ExtensionService::IsExternalExtensionUninstalled( |
| 977 | const std::string& extension_id) const { |
| 978 | return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 979 | } |
| 980 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 981 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 982 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 983 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 984 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 985 | return; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 986 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 987 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 988 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 989 | const Extension* extension = |
| 990 | GetExtensionByIdInternal(extension_id, false, true, false); |
| 991 | // This can happen if sync enables an extension that is not |
| 992 | // installed yet. |
| 993 | if (!extension) |
| 994 | return; |
| 995 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 996 | // Move it over to the enabled list. |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 997 | extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 998 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 999 | disabled_extensions_.end(), |
| 1000 | extension); |
| 1001 | disabled_extensions_.erase(iter); |
| 1002 | |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 1003 | // Make sure any browser action contained within it is not hidden. |
| 1004 | extension_prefs_->SetBrowserActionVisibility(extension, true); |
| 1005 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1006 | NotifyExtensionLoaded(extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1007 | |
| 1008 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1009 | } |
| 1010 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1011 | void ExtensionService::DisableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1012 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1013 | |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 1014 | // The extension may have been disabled already. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1015 | if (!IsExtensionEnabled(extension_id)) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1016 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1017 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1018 | const Extension* extension = GetInstalledExtension(extension_id); |
| 1019 | // |extension| can be NULL if sync disables an extension that is not |
| 1020 | // installed yet. |
| 1021 | if (extension && !Extension::UserMayDisable(extension->location())) |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 1022 | return; |
| 1023 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 1024 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1025 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1026 | extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 1027 | if (!extension) |
| 1028 | return; |
| 1029 | |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1030 | // Move it over to the disabled list. |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 1031 | disabled_extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1032 | ExtensionList::iterator iter = std::find(extensions_.begin(), |
| 1033 | extensions_.end(), |
| 1034 | extension); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1035 | if (iter != extensions_.end()) { |
| 1036 | extensions_.erase(iter); |
| 1037 | } else { |
| 1038 | iter = std::find(terminated_extensions_.begin(), |
| 1039 | terminated_extensions_.end(), |
| 1040 | extension); |
| 1041 | terminated_extensions_.erase(iter); |
| 1042 | } |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1043 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1044 | NotifyExtensionUnloaded(extension, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1045 | |
| 1046 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 1047 | } |
| 1048 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1049 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1050 | CHECK(extension); |
| 1051 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1052 | // We only maintain the granted permissions prefs for extensions that can't |
| 1053 | // silently increase their permissions. |
| 1054 | if (extension->CanSilentlyIncreasePermissions()) |
| 1055 | return; |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1056 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1057 | extension_prefs_->AddGrantedPermissions(extension->id(), |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1058 | extension->GetActivePermissions()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1059 | } |
| 1060 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1061 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1062 | const Extension* extension) { |
| 1063 | CHECK(extension); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1064 | RecordPermissionMessagesHistogram( |
| 1065 | extension, "Extensions.Permissions_ReEnable"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1066 | GrantPermissions(extension); |
| 1067 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 1068 | EnableExtension(extension->id()); |
| 1069 | } |
| 1070 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 1071 | void ExtensionService::UpdateActivePermissions( |
| 1072 | const Extension* extension, |
| 1073 | const ExtensionPermissionSet* permissions) { |
| 1074 | extension_prefs()->SetActivePermissions(extension->id(), permissions); |
| 1075 | extension->SetActivePermissions(permissions); |
| 1076 | } |
| 1077 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1078 | void ExtensionService::LoadExtension(const FilePath& extension_path) { |
[email protected] | 71eb1e6d | 2011-08-02 22:57:40 | [diff] [blame] | 1079 | LoadExtension(extension_path, true); |
| 1080 | } |
| 1081 | |
| 1082 | void ExtensionService::LoadExtension(const FilePath& extension_path, |
| 1083 | bool prompt_for_plugins) { |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 1084 | BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 1085 | NewRunnableMethod(backend_.get(), |
| 1086 | &ExtensionServiceBackend::LoadSingleExtension, |
[email protected] | 71eb1e6d | 2011-08-02 22:57:40 | [diff] [blame] | 1087 | extension_path, prompt_for_plugins)); |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | void ExtensionService::LoadExtensionFromCommandLine( |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1091 | const FilePath& path_in) { |
| 1092 | |
| 1093 | // Load extensions from the command line synchronously to avoid a race |
| 1094 | // between extension loading and loading an URL from the command line. |
| 1095 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1096 | |
| 1097 | FilePath extension_path = path_in; |
| 1098 | file_util::AbsolutePath(&extension_path); |
| 1099 | |
| 1100 | std::string id = Extension::GenerateIdForPath(extension_path); |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 1101 | bool allow_file_access = |
| 1102 | Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD); |
| 1103 | if (extension_prefs()->HasAllowFileAccessSetting(id)) |
| 1104 | allow_file_access = extension_prefs()->AllowFileAccess(id); |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1105 | |
| 1106 | int flags = Extension::NO_FLAGS; |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 1107 | if (allow_file_access) |
[email protected] | 67d2d80 | 2011-07-21 02:54:28 | [diff] [blame] | 1108 | flags |= Extension::ALLOW_FILE_ACCESS; |
| 1109 | if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
| 1110 | flags |= Extension::STRICT_ERROR_CHECKS; |
| 1111 | |
| 1112 | std::string error; |
| 1113 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
| 1114 | extension_path, |
| 1115 | Extension::LOAD, |
| 1116 | flags, |
| 1117 | &error)); |
| 1118 | |
| 1119 | if (!extension) { |
| 1120 | ReportExtensionLoadError( |
| 1121 | extension_path, |
| 1122 | error, |
| 1123 | chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| 1124 | true); |
| 1125 | return; |
| 1126 | } |
| 1127 | |
| 1128 | OnLoadSingleExtension(extension, false); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1129 | } |
| 1130 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1131 | void ExtensionService::LoadComponentExtensions() { |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1132 | for (RegisteredComponentExtensions::iterator it = |
| 1133 | component_extension_manifests_.begin(); |
| 1134 | it != component_extension_manifests_.end(); ++it) { |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1135 | LoadComponentExtension(*it); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1139 | const Extension* ExtensionService::LoadComponentExtension( |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1140 | const ComponentExtensionInfo &info) { |
| 1141 | JSONStringValueSerializer serializer(info.manifest); |
| 1142 | scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
| 1143 | if (!manifest.get()) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1144 | LOG(ERROR) << "Failed to parse manifest for extension"; |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1145 | return NULL; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1146 | } |
| 1147 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1148 | int flags = Extension::REQUIRE_KEY; |
| 1149 | if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) |
| 1150 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1151 | std::string error; |
| 1152 | scoped_refptr<const Extension> extension(Extension::Create( |
| 1153 | info.root_directory, |
| 1154 | Extension::COMPONENT, |
| 1155 | *static_cast<DictionaryValue*>(manifest.get()), |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1156 | flags, |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1157 | &error)); |
| 1158 | if (!extension.get()) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1159 | LOG(ERROR) << error; |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1160 | return NULL; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1161 | } |
| 1162 | AddExtension(extension); |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 1163 | return extension; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 1164 | } |
| 1165 | |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1166 | void ExtensionService::UnloadComponentExtension( |
| 1167 | const ComponentExtensionInfo& info) { |
| 1168 | JSONStringValueSerializer serializer(info.manifest); |
| 1169 | scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
| 1170 | if (!manifest.get()) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1171 | LOG(ERROR) << "Failed to parse manifest for extension"; |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1172 | return; |
| 1173 | } |
| 1174 | std::string public_key; |
| 1175 | std::string public_key_bytes; |
| 1176 | std::string id; |
| 1177 | if (!static_cast<DictionaryValue*>(manifest.get())-> |
| 1178 | GetString(extension_manifest_keys::kPublicKey, &public_key) || |
| 1179 | !Extension::ParsePEMKeyBytes(public_key, &public_key_bytes) || |
| 1180 | !Extension::GenerateId(public_key_bytes, &id)) { |
[email protected] | 0b05c26 | 2011-08-11 01:42:21 | [diff] [blame] | 1181 | LOG(ERROR) << "Failed to get extension id"; |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1182 | return; |
| 1183 | } |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1184 | UnloadExtension(id, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | ad63a79 | 2011-06-16 06:41:11 | [diff] [blame] | 1185 | } |
| 1186 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1187 | void ExtensionService::LoadAllExtensions() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1188 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1189 | |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1190 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 1191 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1192 | // Load any component extensions. |
| 1193 | LoadComponentExtensions(); |
| 1194 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1195 | // Load the previously installed extensions. |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1196 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 1197 | extension_prefs_->GetInstalledExtensionsInfo()); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1198 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1199 | std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0); |
| 1200 | bool should_write_prefs = false; |
| 1201 | |
| 1202 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1203 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 1204 | |
| 1205 | ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info); |
| 1206 | ++reload_reason_counts[reload_reason]; |
| 1207 | UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue", |
| 1208 | reload_reason, 100); |
| 1209 | |
| 1210 | if (reload_reason != NOT_NEEDED) { |
| 1211 | // Reloading and extension reads files from disk. We do this on the |
| 1212 | // UI thread because reloads should be very rare, and the complexity |
| 1213 | // added by delaying the time when the extensions service knows about |
| 1214 | // all extensions is significant. See crbug.com/37548 for details. |
| 1215 | // |allow_io| disables tests that file operations run on the file |
| 1216 | // thread. |
| 1217 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1218 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1219 | int flags = Extension::NO_FLAGS; |
| 1220 | if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) |
| 1221 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1222 | if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 1223 | flags |= Extension::ALLOW_FILE_ACCESS; |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 1224 | if (extension_prefs_->IsFromWebStore(info->extension_id)) |
| 1225 | flags |= Extension::FROM_WEBSTORE; |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 1226 | if (extension_prefs_->IsFromBookmark(info->extension_id)) |
| 1227 | flags |= Extension::FROM_BOOKMARK; |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1228 | std::string error; |
| 1229 | scoped_refptr<const Extension> extension( |
| 1230 | extension_file_util::LoadExtension( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1231 | info->extension_path, |
| 1232 | info->extension_location, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1233 | flags, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1234 | &error)); |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1235 | |
| 1236 | if (extension.get()) { |
| 1237 | extensions_info->at(i)->extension_manifest.reset( |
| 1238 | static_cast<DictionaryValue*>( |
| 1239 | extension->manifest_value()->DeepCopy())); |
| 1240 | should_write_prefs = true; |
| 1241 | } |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1245 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1246 | LoadInstalledExtension(*extensions_info->at(i), should_write_prefs); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1247 | } |
| 1248 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1249 | OnLoadedInstalledExtensions(); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1250 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1251 | // The histograms Extensions.ManifestReload* allow us to validate |
| 1252 | // the assumption that reloading manifest is a rare event. |
| 1253 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", |
| 1254 | reload_reason_counts[NOT_NEEDED]); |
| 1255 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", |
| 1256 | reload_reason_counts[UNPACKED_DIR]); |
| 1257 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", |
| 1258 | reload_reason_counts[NEEDS_RELOCALIZATION]); |
| 1259 | |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1260 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", extensions_.size()); |
| 1261 | UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled_extensions_.size()); |
| 1262 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1263 | UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", |
| 1264 | base::TimeTicks::Now() - start_time); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1265 | |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1266 | int app_user_count = 0; |
| 1267 | int app_external_count = 0; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1268 | int hosted_app_count = 0; |
| 1269 | int packaged_app_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1270 | int user_script_count = 0; |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1271 | int extension_user_count = 0; |
| 1272 | int extension_external_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1273 | int theme_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1274 | int page_action_count = 0; |
| 1275 | int browser_action_count = 0; |
| 1276 | ExtensionList::iterator ex; |
| 1277 | for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) { |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1278 | Extension::Location location = (*ex)->location(); |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 1279 | Extension::Type type = (*ex)->GetType(); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1280 | if ((*ex)->is_app()) { |
| 1281 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", |
| 1282 | location, 100); |
| 1283 | } else if (type == Extension::TYPE_EXTENSION) { |
| 1284 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation", |
| 1285 | location, 100); |
| 1286 | } |
| 1287 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1288 | // Don't count component extensions, since they are only extensions as an |
| 1289 | // implementation detail. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1290 | if (location == Extension::COMPONENT) |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1291 | continue; |
| 1292 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 1293 | // Don't count unpacked extensions, since they're a developer-specific |
| 1294 | // feature. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1295 | if (location == Extension::LOAD) |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 1296 | continue; |
| 1297 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1298 | // Using an enumeration shows us the total installed ratio across all users. |
| 1299 | // Using the totals per user at each startup tells us the distribution of |
| 1300 | // usage for each user (e.g. 40% of users have at least one app installed). |
| 1301 | UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); |
| 1302 | switch (type) { |
| 1303 | case Extension::TYPE_THEME: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1304 | ++theme_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1305 | break; |
| 1306 | case Extension::TYPE_USER_SCRIPT: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1307 | ++user_script_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1308 | break; |
| 1309 | case Extension::TYPE_HOSTED_APP: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1310 | ++hosted_app_count; |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1311 | if (Extension::IsExternalLocation(location)) { |
| 1312 | ++app_external_count; |
| 1313 | } else { |
| 1314 | ++app_user_count; |
| 1315 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1316 | break; |
| 1317 | case Extension::TYPE_PACKAGED_APP: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1318 | ++packaged_app_count; |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1319 | if (Extension::IsExternalLocation(location)) { |
| 1320 | ++app_external_count; |
| 1321 | } else { |
| 1322 | ++app_user_count; |
| 1323 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1324 | break; |
| 1325 | case Extension::TYPE_EXTENSION: |
| 1326 | default: |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1327 | if (Extension::IsExternalLocation(location)) { |
| 1328 | ++extension_external_count; |
| 1329 | } else { |
| 1330 | ++extension_user_count; |
| 1331 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1332 | break; |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1333 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1334 | if ((*ex)->page_action() != NULL) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1335 | ++page_action_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1336 | if ((*ex)->browser_action() != NULL) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1337 | ++browser_action_count; |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1338 | |
| 1339 | RecordPermissionMessagesHistogram( |
| 1340 | ex->get(), "Extensions.Permissions_Load"); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1341 | } |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1342 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp", |
| 1343 | app_user_count + app_external_count); |
| 1344 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppUser", app_user_count); |
| 1345 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAppExternal", app_external_count); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1346 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count); |
| 1347 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp", packaged_app_count); |
[email protected] | d101c4a | 2011-07-22 22:51:36 | [diff] [blame] | 1348 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", |
| 1349 | extension_user_count + extension_external_count); |
| 1350 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtensionUser", |
| 1351 | extension_user_count); |
| 1352 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtensionExternal", |
| 1353 | extension_external_count); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1354 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadUserScript", user_script_count); |
| 1355 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadTheme", theme_count); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1356 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count); |
| 1357 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction", |
| 1358 | browser_action_count); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1359 | } |
| 1360 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1361 | // static |
| 1362 | void ExtensionService::RecordPermissionMessagesHistogram( |
| 1363 | const Extension* e, const char* histogram) { |
| 1364 | // Since this is called from multiple sources, and since the Histogram macros |
| 1365 | // use statics, we need to manually lookup the Histogram ourselves. |
| 1366 | base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 1367 | histogram, |
| 1368 | 1, |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1369 | ExtensionPermissionMessage::kEnumBoundary, |
| 1370 | ExtensionPermissionMessage::kEnumBoundary + 1, |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1371 | base::Histogram::kUmaTargetedHistogramFlag); |
| 1372 | |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1373 | ExtensionPermissionMessages permissions = e->GetPermissionMessages(); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1374 | if (permissions.empty()) { |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1375 | counter->Add(ExtensionPermissionMessage::kNone); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1376 | } else { |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 1377 | for (ExtensionPermissionMessages::iterator it = permissions.begin(); |
| 1378 | it != permissions.end(); ++it) |
| 1379 | counter->Add(it->id()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1383 | void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1384 | bool write_to_prefs) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1385 | std::string error; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1386 | scoped_refptr<const Extension> extension(NULL); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 1387 | if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
| 1388 | error = errors::kDisabledByPolicy; |
| 1389 | } else if (info.extension_manifest.get()) { |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1390 | int flags = Extension::NO_FLAGS; |
| 1391 | if (info.extension_location != Extension::LOAD) |
| 1392 | flags |= Extension::REQUIRE_KEY; |
| 1393 | if (Extension::ShouldDoStrictErrorChecking(info.extension_location)) |
| 1394 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1395 | if (extension_prefs_->AllowFileAccess(info.extension_id)) |
| 1396 | flags |= Extension::ALLOW_FILE_ACCESS; |
[email protected] | 620db176 | 2011-07-15 21:57:34 | [diff] [blame] | 1397 | if (extension_prefs_->IsFromWebStore(info.extension_id)) |
| 1398 | flags |= Extension::FROM_WEBSTORE; |
[email protected] | e805baf | 2011-07-26 18:23:05 | [diff] [blame] | 1399 | if (extension_prefs_->IsFromBookmark(info.extension_id)) |
| 1400 | flags |= Extension::FROM_BOOKMARK; |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 1401 | extension = Extension::Create( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1402 | info.extension_path, |
| 1403 | info.extension_location, |
| 1404 | *info.extension_manifest, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1405 | flags, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1406 | &error); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1407 | } else { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1408 | error = errors::kManifestUnreadable; |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | if (!extension) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1412 | ReportExtensionLoadError(info.extension_path, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1413 | error, |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1414 | chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1415 | false); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1416 | return; |
| 1417 | } |
| 1418 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1419 | if (write_to_prefs) |
| 1420 | extension_prefs_->UpdateManifest(extension); |
| 1421 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 1422 | AddExtension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1423 | } |
| 1424 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1425 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 1426 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1427 | // was loaded, otherwise a race can arise where a renderer that is created |
| 1428 | // 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] | 1429 | // that the request context doesn't yet know about. The profile is responsible |
| 1430 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 1431 | // extension. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1432 | profile_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1433 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1434 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 1435 | // extension. |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1436 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1437 | chrome::NOTIFICATION_EXTENSION_LOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1438 | Source<Profile>(profile_), |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1439 | Details<const Extension>(extension)); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1440 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1441 | // Tell renderers about the new extension. |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1442 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1443 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1444 | RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1445 | Profile* host_profile = |
| 1446 | Profile::FromBrowserContext(host->browser_context()); |
| 1447 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1448 | host->Send( |
[email protected] | 1537964 | 2011-08-11 22:22:05 | [diff] [blame] | 1449 | new ExtensionMsg_Loaded(ExtensionMsg_Loaded_Params(extension))); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1450 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1451 | } |
| 1452 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1453 | // Tell a random-ass collection of other subsystems about the new extension. |
| 1454 | // TODO(aa): What should we do with all this goop? Can it move into the |
| 1455 | // relevant objects via EXTENSION_LOADED? |
| 1456 | |
| 1457 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1458 | GrantRightsForExtension(extension); |
| 1459 | |
| 1460 | UpdateActiveExtensionsInCrashReporter(); |
| 1461 | |
| 1462 | ExtensionWebUI::RegisterChromeURLOverrides( |
| 1463 | profile_, extension->GetChromeURLOverrides()); |
| 1464 | |
[email protected] | 8e5c89a | 2011-06-07 18:13:33 | [diff] [blame] | 1465 | TemplateURLService* url_service = |
| 1466 | TemplateURLServiceFactory::GetForProfile(profile_); |
| 1467 | if (url_service) |
| 1468 | url_service->RegisterExtensionKeyword(extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1469 | |
| 1470 | // Load the icon for omnibox-enabled extensions so it will be ready to display |
| 1471 | // in the URL bar. |
| 1472 | if (!extension->omnibox_keyword().empty()) { |
| 1473 | omnibox_popup_icon_manager_.LoadIcon(extension); |
| 1474 | omnibox_icon_manager_.LoadIcon(extension); |
| 1475 | } |
| 1476 | |
| 1477 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1478 | // to make sure that the FaviconSource is registered with the |
| 1479 | // ChromeURLDataManager. |
| 1480 | if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
| 1481 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1482 | FaviconSource::FAVICON); |
| 1483 | profile_->GetChromeURLDataManager()->AddDataSource(favicon_source); |
| 1484 | } |
| 1485 | |
| 1486 | // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757. |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1487 | bool plugins_changed = false; |
| 1488 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1489 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
| 1490 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 1491 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path); |
| 1492 | plugins_changed = true; |
| 1493 | if (!plugin.is_public) { |
| 1494 | PluginService::GetInstance()->RestrictPluginToUrl( |
| 1495 | plugin.path, extension->url()); |
| 1496 | } |
| 1497 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1498 | |
| 1499 | bool nacl_modules_changed = false; |
| 1500 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1501 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1502 | RegisterNaClModule(module.url, module.mime_type); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1503 | nacl_modules_changed = true; |
| 1504 | } |
| 1505 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 1506 | if (nacl_modules_changed) |
| 1507 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1508 | |
| 1509 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1510 | PluginService::GetInstance()->PurgePluginListCache(false); |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1511 | |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1512 | #if defined(OS_CHROMEOS) |
| 1513 | #if defined(TOUCH_UI) |
[email protected] | c8d4e946 | 2011-06-29 23:18:57 | [diff] [blame] | 1514 | chromeos::input_method::InputMethodManager* input_method_manager = |
| 1515 | chromeos::input_method::InputMethodManager::GetInstance(); |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1516 | #endif |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1517 | for (std::vector<Extension::InputComponentInfo>::const_iterator component = |
| 1518 | extension->input_components().begin(); |
| 1519 | component != extension->input_components().end(); |
| 1520 | ++component) { |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1521 | if (component->type == Extension::INPUT_COMPONENT_TYPE_IME) { |
| 1522 | ExtensionInputImeEventRouter::GetInstance()->RegisterIme( |
| 1523 | profile_, extension->id(), *component); |
| 1524 | } |
| 1525 | #if defined(TOUCH_UI) |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1526 | if (component->type == Extension::INPUT_COMPONENT_TYPE_VIRTUAL_KEYBOARD && |
| 1527 | !component->layouts.empty()) { |
| 1528 | const bool is_system = |
| 1529 | !Extension::IsExternalLocation(extension->location()); |
[email protected] | cbd4c04 | 2011-08-13 18:22:19 | [diff] [blame] | 1530 | input_method_manager->RegisterVirtualKeyboard( |
| 1531 | extension->url(), |
| 1532 | component->name, // human-readable name of the keyboard extension. |
| 1533 | component->layouts, |
| 1534 | is_system); |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1535 | } |
[email protected] | 14da67b0 | 2011-08-02 05:49:13 | [diff] [blame] | 1536 | #endif |
[email protected] | b4d9d12 | 2011-06-17 01:58:54 | [diff] [blame] | 1537 | } |
| 1538 | #endif |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1539 | } |
| 1540 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1541 | void ExtensionService::NotifyExtensionUnloaded( |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1542 | const Extension* extension, |
| 1543 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1544 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1545 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1546 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1547 | Source<Profile>(profile_), |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1548 | Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1549 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1550 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1551 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1552 | RenderProcessHost* host = i.GetCurrentValue(); |
[email protected] | 9b62ecf | 2011-07-27 20:23:08 | [diff] [blame] | 1553 | Profile* host_profile = |
| 1554 | Profile::FromBrowserContext(host->browser_context()); |
| 1555 | if (host_profile->GetOriginalProfile() == profile_->GetOriginalProfile()) |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1556 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1557 | } |
| 1558 | |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1559 | profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1560 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1561 | RevokeRightsForExtension(extension); |
| 1562 | |
| 1563 | ExtensionWebUI::UnregisterChromeURLOverrides( |
| 1564 | profile_, extension->GetChromeURLOverrides()); |
| 1565 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1566 | #if defined(OS_CHROMEOS) |
| 1567 | // Revoke external file access to |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1568 | if (profile_->GetFileSystemContext() && |
| 1569 | profile_->GetFileSystemContext()->path_manager() && |
| 1570 | profile_->GetFileSystemContext()->path_manager()->external_provider()) { |
| 1571 | profile_->GetFileSystemContext()->path_manager()->external_provider()-> |
| 1572 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1573 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1574 | #endif |
| 1575 | |
| 1576 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1577 | |
| 1578 | bool plugins_changed = false; |
| 1579 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1580 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1581 | if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 1582 | NewRunnableFunction(&ForceShutdownPlugin, |
| 1583 | plugin.path))) |
| 1584 | NOTREACHED(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1585 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 1586 | webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath( |
| 1587 | plugin.path); |
| 1588 | plugins_changed = true; |
| 1589 | if (!plugin.is_public) |
| 1590 | PluginService::GetInstance()->RestrictPluginToUrl(plugin.path, GURL()); |
| 1591 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1592 | |
| 1593 | bool nacl_modules_changed = false; |
| 1594 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1595 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1596 | UnregisterNaClModule(module.url); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1597 | nacl_modules_changed = true; |
| 1598 | } |
| 1599 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 1600 | if (nacl_modules_changed) |
| 1601 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1602 | |
| 1603 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1604 | PluginService::GetInstance()->PurgePluginListCache(false); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1605 | } |
| 1606 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1607 | void ExtensionService::UpdateExtensionBlacklist( |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1608 | const std::vector<std::string>& blacklist) { |
| 1609 | // Use this set to indicate if an extension in the blacklist has been used. |
| 1610 | std::set<std::string> blacklist_set; |
| 1611 | for (unsigned int i = 0; i < blacklist.size(); ++i) { |
| 1612 | if (Extension::IdIsValid(blacklist[i])) { |
| 1613 | blacklist_set.insert(blacklist[i]); |
| 1614 | } |
| 1615 | } |
| 1616 | extension_prefs_->UpdateBlacklist(blacklist_set); |
| 1617 | std::vector<std::string> to_be_removed; |
| 1618 | // Loop current extensions, unload installed extensions. |
| 1619 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1620 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1621 | const Extension* extension = (*iter); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1622 | if (blacklist_set.find(extension->id()) != blacklist_set.end()) { |
| 1623 | to_be_removed.push_back(extension->id()); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | // UnloadExtension will change the extensions_ list. So, we should |
| 1628 | // call it outside the iterator loop. |
| 1629 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1630 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | |
[email protected] | 0a071a3 | 2011-02-08 00:18:24 | [diff] [blame] | 1634 | Profile* ExtensionService::profile() { |
| 1635 | return profile_; |
| 1636 | } |
| 1637 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1638 | ExtensionPrefs* ExtensionService::extension_prefs() { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 1639 | return extension_prefs_; |
| 1640 | } |
| 1641 | |
[email protected] | b7f853e28 | 2011-08-10 09:24:20 | [diff] [blame] | 1642 | ExtensionSettings* ExtensionService::extension_settings() { |
| 1643 | return extension_settings_; |
| 1644 | } |
| 1645 | |
[email protected] | b790b07 | 2011-05-20 09:46:44 | [diff] [blame] | 1646 | ExtensionContentSettingsStore* |
| 1647 | ExtensionService::GetExtensionContentSettingsStore() { |
| 1648 | return extension_prefs()->content_settings_store(); |
| 1649 | } |
| 1650 | |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 1651 | ExtensionUpdater* ExtensionService::updater() { |
| 1652 | return updater_.get(); |
| 1653 | } |
| 1654 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1655 | void ExtensionService::CheckAdminBlacklist() { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1656 | std::vector<std::string> to_be_removed; |
| 1657 | // Loop through extensions list, unload installed extensions. |
| 1658 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1659 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1660 | const Extension* extension = (*iter); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1661 | if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) |
| 1662 | to_be_removed.push_back(extension->id()); |
| 1663 | } |
| 1664 | |
| 1665 | // UnloadExtension will change the extensions_ list. So, we should |
| 1666 | // call it outside the iterator loop. |
| 1667 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1668 | UnloadExtension(to_be_removed[i], extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1669 | } |
| 1670 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1671 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1672 | if (updater()) { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1673 | updater()->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1674 | } else { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1675 | LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1676 | } |
| 1677 | } |
| 1678 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1679 | namespace { |
| 1680 | bool IsSyncableNone(const Extension& extension) { return false; } |
| 1681 | } // namespace |
| 1682 | |
| 1683 | ExtensionService::SyncBundle::SyncBundle() |
| 1684 | : filter(IsSyncableNone), |
| 1685 | sync_processor(NULL) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1686 | } |
| 1687 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1688 | ExtensionService::SyncBundle::~SyncBundle() { |
| 1689 | } |
| 1690 | |
| 1691 | bool ExtensionService::SyncBundle::HasExtensionId(const std::string& id) const { |
| 1692 | return synced_extensions.find(id) != synced_extensions.end(); |
| 1693 | } |
| 1694 | |
| 1695 | bool ExtensionService::SyncBundle::HasPendingExtensionId(const std::string& id) |
| 1696 | const { |
| 1697 | return pending_sync_data.find(id) != pending_sync_data.end(); |
| 1698 | } |
| 1699 | |
| 1700 | void ExtensionService::SyncExtensionChangeIfNeeded(const Extension& extension) { |
| 1701 | SyncBundle* sync_bundle = GetSyncBundleForExtension(extension); |
| 1702 | if (sync_bundle) { |
| 1703 | ExtensionSyncData extension_sync_data(extension, |
| 1704 | IsExtensionEnabled(extension.id()), |
| 1705 | IsIncognitoEnabled(extension.id())); |
| 1706 | |
| 1707 | SyncChangeList sync_change_list(1, extension_sync_data.GetSyncChange( |
| 1708 | sync_bundle->HasExtensionId(extension.id()) ? |
| 1709 | SyncChange::ACTION_UPDATE : SyncChange::ACTION_ADD)); |
| 1710 | sync_bundle->sync_processor->ProcessSyncChanges( |
| 1711 | FROM_HERE, sync_change_list); |
| 1712 | sync_bundle->synced_extensions.insert(extension.id()); |
| 1713 | sync_bundle->pending_sync_data.erase(extension.id()); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1714 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForExtension( |
| 1718 | const Extension& extension) { |
| 1719 | if (app_sync_bundle_.filter(extension)) |
| 1720 | return &app_sync_bundle_; |
| 1721 | else if (extension_sync_bundle_.filter(extension)) |
| 1722 | return &extension_sync_bundle_; |
| 1723 | else |
| 1724 | return NULL; |
| 1725 | } |
| 1726 | |
| 1727 | ExtensionService::SyncBundle* |
| 1728 | ExtensionService::GetSyncBundleForExtensionSyncData( |
| 1729 | const ExtensionSyncData& extension_sync_data) { |
| 1730 | switch (extension_sync_data.type()) { |
| 1731 | case Extension::SYNC_TYPE_APP: |
| 1732 | return &app_sync_bundle_; |
| 1733 | case Extension::SYNC_TYPE_EXTENSION: |
| 1734 | return &extension_sync_bundle_; |
| 1735 | default: |
| 1736 | NOTREACHED(); |
| 1737 | return NULL; |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | #define GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY() \ |
| 1742 | do { \ |
| 1743 | switch (type) { \ |
| 1744 | case syncable::APPS: \ |
| 1745 | return &app_sync_bundle_; \ |
| 1746 | case syncable::EXTENSIONS: \ |
| 1747 | return &extension_sync_bundle_; \ |
| 1748 | default: \ |
| 1749 | NOTREACHED(); \ |
| 1750 | return NULL; \ |
| 1751 | } \ |
| 1752 | } while (0) |
| 1753 | |
| 1754 | const ExtensionService::SyncBundle* |
| 1755 | ExtensionService::GetSyncBundleForModelTypeConst( |
| 1756 | syncable::ModelType type) const { |
| 1757 | GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); |
| 1758 | } |
| 1759 | |
| 1760 | ExtensionService::SyncBundle* ExtensionService::GetSyncBundleForModelType( |
| 1761 | syncable::ModelType type) { |
| 1762 | GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY(); |
| 1763 | } |
| 1764 | |
| 1765 | #undef GET_SYNC_BUNDLE_FOR_MODEL_TYPE_BODY |
| 1766 | |
| 1767 | SyncError ExtensionService::MergeDataAndStartSyncing( |
| 1768 | syncable::ModelType type, |
| 1769 | const SyncDataList& initial_sync_data, |
| 1770 | SyncChangeProcessor* sync_processor) { |
| 1771 | CHECK(sync_processor); |
| 1772 | |
| 1773 | SyncBundle* bundle = NULL; |
| 1774 | |
| 1775 | switch (type) { |
| 1776 | case syncable::EXTENSIONS: |
| 1777 | bundle = &extension_sync_bundle_; |
| 1778 | bundle->filter = IsSyncableExtension; |
| 1779 | break; |
| 1780 | |
| 1781 | case syncable::APPS: |
| 1782 | bundle = &app_sync_bundle_; |
| 1783 | bundle->filter = IsSyncableApp; |
| 1784 | break; |
| 1785 | |
| 1786 | default: |
| 1787 | LOG(FATAL) << "Got " << type << " ModelType"; |
| 1788 | } |
| 1789 | |
| 1790 | bundle->sync_processor = sync_processor; |
| 1791 | |
| 1792 | for (SyncDataList::const_iterator i = initial_sync_data.begin(); |
| 1793 | i != initial_sync_data.end(); |
| 1794 | ++i) { |
| 1795 | ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); |
| 1796 | bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1797 | ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1798 | } |
| 1799 | |
| 1800 | SyncDataList sync_data_list = GetAllSyncData(type); |
| 1801 | SyncChangeList sync_change_list; |
| 1802 | for (SyncDataList::const_iterator i = sync_data_list.begin(); |
| 1803 | i != sync_data_list.end(); |
| 1804 | ++i) { |
| 1805 | if (bundle->HasExtensionId(i->GetTag())) |
| 1806 | sync_change_list.push_back(SyncChange(SyncChange::ACTION_UPDATE, *i)); |
| 1807 | else |
| 1808 | sync_change_list.push_back(SyncChange(SyncChange::ACTION_ADD, *i)); |
| 1809 | } |
| 1810 | bundle->sync_processor->ProcessSyncChanges(FROM_HERE, sync_change_list); |
| 1811 | |
| 1812 | return SyncError(); |
| 1813 | } |
| 1814 | |
| 1815 | void ExtensionService::StopSyncing(syncable::ModelType type) { |
| 1816 | SyncBundle* bundle = GetSyncBundleForModelType(type); |
| 1817 | CHECK(bundle); |
| 1818 | // This is the simplest way to clear out the bundle. |
| 1819 | *bundle = SyncBundle(); |
| 1820 | } |
| 1821 | |
| 1822 | SyncDataList ExtensionService::GetAllSyncData(syncable::ModelType type) const { |
| 1823 | const SyncBundle* bundle = GetSyncBundleForModelTypeConst(type); |
| 1824 | CHECK(bundle); |
| 1825 | std::vector<ExtensionSyncData> extension_sync_data = GetSyncDataList(*bundle); |
| 1826 | SyncDataList result(extension_sync_data.size()); |
| 1827 | for (int i = 0; i < static_cast<int>(extension_sync_data.size()); ++i) { |
| 1828 | result[i] = extension_sync_data[i].GetSyncData(); |
| 1829 | } |
| 1830 | return result; |
| 1831 | } |
| 1832 | |
| 1833 | SyncError ExtensionService::ProcessSyncChanges( |
| 1834 | const tracked_objects::Location& from_here, |
| 1835 | const SyncChangeList& change_list) { |
| 1836 | for (SyncChangeList::const_iterator i = change_list.begin(); |
| 1837 | i != change_list.end(); |
| 1838 | ++i) { |
| 1839 | ExtensionSyncData extension_sync_data = ExtensionSyncData(*i); |
| 1840 | SyncBundle* bundle = GetSyncBundleForExtensionSyncData(extension_sync_data); |
| 1841 | CHECK(bundle); |
| 1842 | |
| 1843 | if (extension_sync_data.uninstalled()) |
| 1844 | bundle->synced_extensions.erase(extension_sync_data.id()); |
| 1845 | else |
| 1846 | bundle->synced_extensions.insert(extension_sync_data.id()); |
| 1847 | ProcessExtensionSyncData(extension_sync_data, *bundle); |
| 1848 | } |
| 1849 | |
| 1850 | return SyncError(); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | void ExtensionService::GetSyncDataListHelper( |
| 1854 | const ExtensionList& extensions, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1855 | const SyncBundle& bundle, |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1856 | std::vector<ExtensionSyncData>* sync_data_list) const { |
| 1857 | for (ExtensionList::const_iterator it = extensions.begin(); |
| 1858 | it != extensions.end(); ++it) { |
| 1859 | const Extension& extension = **it; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1860 | if (bundle.filter(extension) && |
| 1861 | // If we have pending extension data for this extension, then this |
| 1862 | // version is out of date. We'll sync back the version we got from |
| 1863 | // sync. |
| 1864 | !bundle.HasPendingExtensionId(extension.id())) { |
| 1865 | sync_data_list->push_back( |
| 1866 | ExtensionSyncData(extension, |
| 1867 | IsExtensionEnabled(extension.id()), |
| 1868 | IsIncognitoEnabled(extension.id()))); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1869 | } |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1874 | const SyncBundle& bundle) const { |
| 1875 | std::vector<ExtensionSyncData> extension_sync_list; |
| 1876 | GetSyncDataListHelper(extensions_, bundle, &extension_sync_list); |
| 1877 | GetSyncDataListHelper(disabled_extensions_, bundle, &extension_sync_list); |
| 1878 | GetSyncDataListHelper(terminated_extensions_, bundle, &extension_sync_list); |
| 1879 | |
| 1880 | for (std::map<std::string, ExtensionSyncData>::const_iterator i = |
| 1881 | bundle.pending_sync_data.begin(); |
| 1882 | i != bundle.pending_sync_data.end(); |
| 1883 | ++i) { |
| 1884 | extension_sync_list.push_back(i->second); |
| 1885 | } |
| 1886 | |
| 1887 | return extension_sync_list; |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1888 | } |
| 1889 | |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1890 | void ExtensionService::ProcessExtensionSyncData( |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1891 | const ExtensionSyncData& extension_sync_data, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1892 | SyncBundle& bundle) { |
| 1893 | const std::string& id = extension_sync_data.id(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1894 | |
| 1895 | // Handle uninstalls first. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1896 | if (extension_sync_data.uninstalled()) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1897 | std::string error; |
| 1898 | if (!UninstallExtensionHelper(this, id)) { |
| 1899 | LOG(WARNING) << "Could not uninstall extension " << id |
| 1900 | << " for sync"; |
| 1901 | } |
| 1902 | return; |
| 1903 | } |
| 1904 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1905 | // Set user settings. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1906 | if (extension_sync_data.enabled()) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1907 | EnableExtension(id); |
| 1908 | } else { |
| 1909 | DisableExtension(id); |
| 1910 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1911 | SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled()); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1912 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1913 | const Extension* extension = GetInstalledExtension(id); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1914 | if (extension) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1915 | // If the extension is already installed, check if it's outdated. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1916 | int result = extension->version()->CompareTo(extension_sync_data.version()); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1917 | if (result < 0) { |
| 1918 | // Extension is outdated. |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1919 | bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1920 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1921 | } |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1922 | } else { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1923 | // TODO(akalin): Replace silent update with a list of enabled |
| 1924 | // permissions. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1925 | const bool kInstallSilently = true; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1926 | if (!pending_extension_manager()->AddFromSync( |
| 1927 | id, |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1928 | extension_sync_data.update_url(), |
| 1929 | bundle.filter, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1930 | kInstallSilently)) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1931 | LOG(WARNING) << "Could not add pending extension for " << id; |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1932 | // This means that the extension is already pending installation, with a |
| 1933 | // non-INTERNAL location. Add to pending_sync_data, even though it will |
| 1934 | // never be removed (we'll never install a syncable version of the |
| 1935 | // extension), so that GetAllSyncData() continues to send it. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1936 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1937 | // Track pending extensions so that we can return them in GetAllSyncData(). |
| 1938 | bundle.pending_sync_data[extension_sync_data.id()] = extension_sync_data; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1939 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1940 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1941 | } |
| 1942 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1943 | bool ExtensionService::IsIncognitoEnabled( |
| 1944 | const std::string& extension_id) const { |
| 1945 | // If this is an existing component extension we always allow it to |
| 1946 | // work in incognito mode. |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1947 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1948 | if (extension && extension->location() == Extension::COMPONENT) |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 1949 | return true; |
| 1950 | |
| 1951 | // Check the prefs. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1952 | return extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 1953 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1954 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1955 | void ExtensionService::SetIsIncognitoEnabled( |
| 1956 | const std::string& extension_id, bool enabled) { |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1957 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1958 | if (extension && extension->location() == Extension::COMPONENT) { |
| 1959 | // This shouldn't be called for component extensions. |
| 1960 | NOTREACHED(); |
| 1961 | return; |
| 1962 | } |
| 1963 | |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1964 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 1965 | // if the value changed and the extension is actually enabled, since there is |
| 1966 | // no UI otherwise. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1967 | bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1968 | if (enabled == old_enabled) |
| 1969 | return; |
| 1970 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1971 | extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1972 | |
| 1973 | // If the extension is enabled (and not terminated), unload and |
| 1974 | // reload it to update UI. |
| 1975 | const Extension* enabled_extension = GetExtensionById(extension_id, false); |
| 1976 | if (enabled_extension) { |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 1977 | NotifyExtensionUnloaded( |
| 1978 | enabled_extension, extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1979 | NotifyExtensionLoaded(enabled_extension); |
[email protected] | 568f33d | 2010-08-04 17:06:41 | [diff] [blame] | 1980 | } |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 1981 | |
| 1982 | if (extension) |
| 1983 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1984 | } |
| 1985 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1986 | bool ExtensionService::CanCrossIncognito(const Extension* extension) { |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1987 | // We allow the extension to see events and data from another profile iff it |
| 1988 | // uses "spanning" behavior and it has incognito access. "split" mode |
| 1989 | // extensions only see events for a matching profile. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1990 | return IsIncognitoEnabled(extension->id()) && |
| 1991 | !extension->incognito_split_mode(); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1992 | } |
| 1993 | |
[email protected] | 5ef7b00 | 2011-05-12 23:16:20 | [diff] [blame] | 1994 | bool ExtensionService::CanLoadInIncognito(const Extension* extension) const { |
| 1995 | if (extension->is_hosted_app()) |
| 1996 | return true; |
| 1997 | // Packaged apps and regular extensions need to be enabled specifically for |
| 1998 | // incognito (and split mode should be set). |
| 1999 | return extension->incognito_split_mode() && |
| 2000 | IsIncognitoEnabled(extension->id()); |
| 2001 | } |
| 2002 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2003 | bool ExtensionService::AllowFileAccess(const Extension* extension) { |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2004 | return (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 2005 | switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2006 | extension_prefs_->AllowFileAccess(extension->id())); |
| 2007 | } |
| 2008 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2009 | void ExtensionService::SetAllowFileAccess(const Extension* extension, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 2010 | bool allow) { |
| 2011 | // Reload to update browser state. Only bother if the value changed and the |
| 2012 | // extension is actually enabled, since there is no UI otherwise. |
| 2013 | bool old_allow = AllowFileAccess(extension); |
| 2014 | if (allow == old_allow) |
| 2015 | return; |
| 2016 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2017 | extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 2018 | |
| 2019 | bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), |
| 2020 | extension) != extensions_.end(); |
| 2021 | if (extension_is_enabled) |
| 2022 | ReloadExtension(extension->id()); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 2023 | } |
| 2024 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2025 | bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 2026 | return extension_prefs_->GetBrowserActionVisibility(extension); |
| 2027 | } |
| 2028 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2029 | void ExtensionService::SetBrowserActionVisibility(const Extension* extension, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2030 | bool visible) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 2031 | extension_prefs_->SetBrowserActionVisibility(extension, visible); |
| 2032 | } |
| 2033 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2034 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 2035 | // are typically part of some larger client application package. To support |
| 2036 | // these, the extension will register its location in the the preferences file |
| 2037 | // (and also, on Windows, in the registry) and this code will periodically |
| 2038 | // check that location for a .crx file, which it will then install locally if |
| 2039 | // a new version is available. |
| 2040 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 2041 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2042 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2043 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2044 | |
| 2045 | // Note that this installation is intentionally silent (since it didn't |
| 2046 | // go through the front-end). Extensions that are registered in this |
| 2047 | // way are effectively considered 'pre-bundled', and so implicitly |
| 2048 | // trusted. In general, if something has HKLM or filesystem access, |
| 2049 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2050 | |
| 2051 | // If any external extension records give a URL, a provider will set |
| 2052 | // this to true. Used by OnExternalProviderReady() to see if we need |
| 2053 | // to start an update check to fetch a new external extension. |
| 2054 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2055 | |
| 2056 | // Ask each external extension provider to give us a call back for each |
| 2057 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
| 2058 | ProviderCollection::const_iterator i; |
| 2059 | for (i = external_extension_providers_.begin(); |
| 2060 | i != external_extension_providers_.end(); ++i) { |
| 2061 | ExternalExtensionProviderInterface* provider = i->get(); |
| 2062 | provider->VisitRegisteredExtension(); |
| 2063 | } |
| 2064 | |
| 2065 | // Uninstall of unclaimed extensions will happen after all the providers |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2066 | // had reported ready. Every provider calls OnExternalProviderReady() |
| 2067 | // when it finishes, and OnExternalProviderReady() only acts when all |
| 2068 | // providers are ready. In case there are no providers, we call it |
| 2069 | // to trigger removal of extensions that used to have an external source. |
| 2070 | if (external_extension_providers_.empty()) |
| 2071 | OnExternalProviderReady(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2074 | void ExtensionService::OnExternalProviderReady() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2075 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2076 | |
| 2077 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2078 | // if all of them are finished. So we check them first. |
| 2079 | ProviderCollection::const_iterator i; |
| 2080 | for (i = external_extension_providers_.begin(); |
| 2081 | i != external_extension_providers_.end(); ++i) { |
| 2082 | ExternalExtensionProviderInterface* provider = i->get(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2083 | if (!provider->IsReady()) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2084 | return; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2085 | } |
| 2086 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2087 | // All the providers are ready. Install any pending extensions. |
| 2088 | if (external_extension_url_added_ && updater()) { |
| 2089 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2090 | updater()->CheckNow(); |
| 2091 | } |
| 2092 | |
| 2093 | // Uninstall all the unclaimed extensions. |
| 2094 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 2095 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 2096 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 2097 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 2098 | if (Extension::IsExternalLocation(info->extension_location)) |
| 2099 | CheckExternalUninstall(info->extension_id); |
| 2100 | } |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2101 | } |
| 2102 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2103 | void ExtensionService::UnloadExtension( |
| 2104 | const std::string& extension_id, |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2105 | extension_misc::UnloadedExtensionReason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 2106 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2107 | scoped_refptr<const Extension> extension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2108 | GetExtensionByIdInternal(extension_id, true, true, false)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 2109 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 2110 | // This method can be called via PostTask, so the extension may have been |
| 2111 | // unloaded by the time this runs. |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 2112 | if (!extension) { |
| 2113 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 2114 | // clean up its RequestContexts. |
| 2115 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 2116 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 2117 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2118 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 2119 | // Keep information about the extension so that we can reload it later |
| 2120 | // even if it's not permanently installed. |
| 2121 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 2122 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 2123 | // Clean up if the extension is meant to be enabled after a reload. |
| 2124 | disabled_extension_paths_.erase(extension->id()); |
| 2125 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2126 | // Clean up runtime data. |
| 2127 | extension_runtime_data_.erase(extension_id); |
| 2128 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2129 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 2130 | disabled_extensions_.end(), |
| 2131 | extension.get()); |
| 2132 | if (iter != disabled_extensions_.end()) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2133 | UnloadedExtensionInfo details(extension, reason); |
| 2134 | details.already_disabled = true; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2135 | disabled_extensions_.erase(iter); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 2136 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2137 | chrome::NOTIFICATION_EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2138 | Source<Profile>(profile_), |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2139 | Details<UnloadedExtensionInfo>(&details)); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 2140 | // Make sure the profile cleans up its RequestContexts when an already |
| 2141 | // disabled extension is unloaded (since they are also tracking the disabled |
| 2142 | // extensions). |
| 2143 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2144 | return; |
| 2145 | } |
| 2146 | |
| 2147 | iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 2148 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 2149 | // Remove the extension from our list. |
| 2150 | extensions_.erase(iter); |
| 2151 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 2152 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 2153 | } |
| 2154 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2155 | void ExtensionService::UnloadAllExtensions() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2156 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 2157 | RevokeRightsForAllExtensions(); |
| 2158 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2159 | extensions_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 2160 | disabled_extensions_.clear(); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2161 | terminated_extension_ids_.clear(); |
| 2162 | terminated_extensions_.clear(); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2163 | extension_runtime_data_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 2164 | |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 2165 | // TODO(erikkay) should there be a notification for this? We can't use |
| 2166 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 2167 | // or uninstalled, and UnloadAll is just part of shutdown. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2168 | } |
| 2169 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2170 | void ExtensionService::ReloadExtensions() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2171 | UnloadAllExtensions(); |
| 2172 | LoadAllExtensions(); |
| 2173 | } |
| 2174 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2175 | void ExtensionService::GarbageCollectExtensions() { |
[email protected] | 39d9f62c | 2010-12-03 10:48:50 | [diff] [blame] | 2176 | if (extension_prefs_->pref_service()->ReadOnly()) |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 2177 | return; |
| 2178 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 2179 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 2180 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 2181 | |
| 2182 | std::map<std::string, FilePath> extension_paths; |
| 2183 | for (size_t i = 0; i < info->size(); ++i) |
| 2184 | extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path; |
| 2185 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2186 | if (!BrowserThread::PostTask( |
| 2187 | BrowserThread::FILE, FROM_HERE, |
| 2188 | NewRunnableFunction( |
| 2189 | &extension_file_util::GarbageCollectExtensions, |
| 2190 | install_directory_, |
| 2191 | extension_paths))) |
| 2192 | NOTREACHED(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 2193 | |
| 2194 | // Also garbage-collect themes. We check |profile_| to be |
| 2195 | // defensive; in the future, we may call GarbageCollectExtensions() |
| 2196 | // from somewhere other than Init() (e.g., in a timer). |
| 2197 | if (profile_) { |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 2198 | ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 2199 | } |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 2200 | } |
| 2201 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2202 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 2203 | if (updater_.get()) { |
| 2204 | updater_->Start(); |
| 2205 | } |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 2206 | |
| 2207 | ready_ = true; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2208 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2209 | chrome::NOTIFICATION_EXTENSIONS_READY, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2210 | Source<Profile>(profile_), |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2211 | NotificationService::NoDetails()); |
| 2212 | } |
| 2213 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 2214 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 2215 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2216 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2217 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2218 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 2219 | // default extension state to DISABLED when the --disable-extensions flag |
| 2220 | // is set (http://crbug.com/29067). |
| 2221 | if (!extensions_enabled() && |
| 2222 | !extension->is_theme() && |
| 2223 | extension->location() != Extension::COMPONENT && |
| 2224 | !Extension::IsExternalLocation(extension->location())) |
| 2225 | return; |
| 2226 | |
| 2227 | SetBeingUpgraded(extension, false); |
| 2228 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 2229 | // The extension is now loaded, remove its data from unloaded extension map. |
| 2230 | unloaded_extension_paths_.erase(extension->id()); |
| 2231 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2232 | // If a terminated extension is loaded, remove it from the terminated list. |
| 2233 | UntrackTerminatedExtension(extension->id()); |
| 2234 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 2235 | // If the extension was disabled for a reload, then enable it. |
| 2236 | if (disabled_extension_paths_.erase(extension->id()) > 0) |
| 2237 | EnableExtension(extension->id()); |
| 2238 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 2239 | // Check if the extension's privileges have changed and disable the |
| 2240 | // extension if necessary. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2241 | InitializePermissions(extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2242 | |
[email protected] | ad83ca24 | 2011-07-29 01:32:25 | [diff] [blame] | 2243 | bool disabled = extension_prefs_->IsExtensionDisabled(extension->id()); |
[email protected] | 36429da | 2011-07-11 20:25:18 | [diff] [blame] | 2244 | if (disabled) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2245 | disabled_extensions_.push_back(scoped_extension); |
| 2246 | // TODO(aa): This seems dodgy. It seems that AddExtension() could get called |
| 2247 | // with a disabled extension for other reasons other than that an update was |
| 2248 | // disabled. |
| 2249 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2250 | chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2251 | Source<Profile>(profile_), |
| 2252 | Details<const Extension>(extension)); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2253 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2254 | return; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 2255 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2256 | |
[email protected] | f1b6665 | 2011-08-25 23:30:58 | [diff] [blame] | 2257 | // Unfortunately, we used to set app launcher indices for non-apps. If this |
| 2258 | // extension has an index (page or in-page), set it to -1. |
| 2259 | if (!extension->is_app()) { |
| 2260 | if (extension_prefs_->GetAppLaunchIndex(extension->id()) != -1) |
| 2261 | extension_prefs_->SetAppLaunchIndex(extension->id(), -1); |
| 2262 | if (extension_prefs_->GetPageIndex(extension->id()) != -1) |
| 2263 | extension_prefs_->SetPageIndex(extension->id(), -1); |
| 2264 | } |
| 2265 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2266 | extensions_.push_back(scoped_extension); |
[email protected] | 3bdba0d | 2011-08-23 07:17:30 | [diff] [blame] | 2267 | SyncExtensionChangeIfNeeded(*extension); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 2268 | NotifyExtensionLoaded(extension); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2269 | } |
| 2270 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2271 | void ExtensionService::InitializePermissions(const Extension* extension) { |
| 2272 | // If the extension has used the optional permissions API, it will have a |
| 2273 | // custom set of active permissions defined in the extension prefs. Here, |
| 2274 | // we update the extension's active permissions based on the prefs. |
| 2275 | scoped_refptr<ExtensionPermissionSet> active_permissions = |
| 2276 | extension_prefs()->GetActivePermissions(extension->id()); |
| 2277 | |
| 2278 | if (active_permissions.get()) { |
| 2279 | // We restrict the active permissions to be within the bounds defined in the |
| 2280 | // extension's manifest. |
| 2281 | // a) active permissions must be a subset of optional + default permissions |
| 2282 | // b) active permissions must contains all default permissions |
| 2283 | scoped_refptr<ExtensionPermissionSet> total_permissions = |
| 2284 | ExtensionPermissionSet::CreateUnion( |
| 2285 | extension->required_permission_set(), |
| 2286 | extension->optional_permission_set()); |
| 2287 | |
| 2288 | // Make sure the active permissions contain no more than optional + default. |
| 2289 | scoped_refptr<ExtensionPermissionSet> adjusted_active = |
| 2290 | ExtensionPermissionSet::CreateIntersection( |
| 2291 | total_permissions.get(), active_permissions.get()); |
| 2292 | |
| 2293 | // Make sure the active permissions contain the default permissions. |
| 2294 | adjusted_active = ExtensionPermissionSet::CreateUnion( |
| 2295 | extension->required_permission_set(), adjusted_active.get()); |
| 2296 | |
| 2297 | UpdateActivePermissions(extension, adjusted_active); |
| 2298 | } |
| 2299 | |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2300 | // We keep track of all permissions the user has granted each extension. |
| 2301 | // This allows extensions to gracefully support backwards compatibility |
| 2302 | // by including unknown permissions in their manifests. When the user |
| 2303 | // installs the extension, only the recognized permissions are recorded. |
| 2304 | // When the unknown permissions become recognized (e.g., through browser |
| 2305 | // upgrade), we can prompt the user to accept these new permissions. |
| 2306 | // Extensions can also silently upgrade to less permissions, and then |
| 2307 | // silently upgrade to a version that adds these permissions back. |
| 2308 | // |
| 2309 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 2310 | // for an API that adds suggestions to the omnibox. An extension can |
| 2311 | // maintain backwards compatibility while still having "omnibox" in the |
| 2312 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 2313 | // will record the permissions it recognized, not including "omnibox." |
| 2314 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 2315 | // will disable the extension and prompt the user to approve the increase |
| 2316 | // in privileges. The extension could then release a new version that |
| 2317 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 2318 | // still remember that "omnibox" had been granted, so that if the |
| 2319 | // extension once again includes "omnibox" in an upgrade, the extension |
| 2320 | // can upgrade without requiring this user's approval. |
| 2321 | const Extension* old = GetExtensionByIdInternal(extension->id(), |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2322 | true, true, false); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2323 | bool is_extension_upgrade = old != NULL; |
| 2324 | bool is_privilege_increase = false; |
| 2325 | |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2326 | // We only need to compare the granted permissions to the current permissions |
| 2327 | // if the extension is not allowed to silently increase its permissions. |
| 2328 | if (!extension->CanSilentlyIncreasePermissions()) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2329 | // Add all the recognized permissions if the granted permissions list |
| 2330 | // hasn't been initialized yet. |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2331 | scoped_refptr<ExtensionPermissionSet> granted_permissions = |
| 2332 | extension_prefs_->GetGrantedPermissions(extension->id()); |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2333 | CHECK(granted_permissions.get()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2334 | |
| 2335 | // Here, we check if an extension's privileges have increased in a manner |
| 2336 | // that requires the user's approval. This could occur because the browser |
| 2337 | // upgraded and recognized additional privileges, or an extension upgrades |
| 2338 | // to a version that requires additional privileges. |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 2339 | is_privilege_increase = |
[email protected] | 902fd7b | 2011-07-27 18:42:31 | [diff] [blame] | 2340 | granted_permissions->HasLessPrivilegesThan( |
| 2341 | extension->GetActivePermissions()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | if (is_extension_upgrade) { |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 2345 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 2346 | // that we aren't downgrading. |
| 2347 | if (extension->location() != Extension::LOAD) |
| 2348 | CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2349 | |
| 2350 | // Extensions get upgraded if the privileges are allowed to increase or |
| 2351 | // the privileges haven't increased. |
| 2352 | if (!is_privilege_increase) { |
| 2353 | SetBeingUpgraded(old, true); |
| 2354 | SetBeingUpgraded(extension, true); |
| 2355 | } |
| 2356 | |
| 2357 | // To upgrade an extension in place, unload the old one and |
| 2358 | // then load the new one. |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2359 | UnloadExtension(old->id(), extension_misc::UNLOAD_REASON_UPDATE); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2360 | old = NULL; |
| 2361 | } |
| 2362 | |
| 2363 | // Extension has changed permissions significantly. Disable it. A |
| 2364 | // notification should be sent by the caller. |
| 2365 | if (is_privilege_increase) { |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 2366 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 2367 | RecordPermissionMessagesHistogram( |
| 2368 | extension, "Extensions.Permissions_AutoDisable"); |
| 2369 | } |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 2370 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 2371 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 2372 | } |
| 2373 | } |
| 2374 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2375 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 2376 | std::set<std::string> extension_ids; |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2377 | for (size_t i = 0; i < extensions_.size(); ++i) { |
[email protected] | 2a500c1b | 2010-11-05 15:27:34 | [diff] [blame] | 2378 | if (!extensions_[i]->is_theme() && |
| 2379 | extensions_[i]->location() != Extension::COMPONENT) |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 2380 | extension_ids.insert(extensions_[i]->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | child_process_logging::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 2384 | } |
| 2385 | |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 2386 | void ExtensionService::OnLoadSingleExtension(const Extension* extension, |
| 2387 | bool prompt_for_plugins) { |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 2388 | // If this is a new install of an extension with plugins, prompt the user |
| 2389 | // first. |
[email protected] | e49002a | 2011-07-13 03:40:44 | [diff] [blame] | 2390 | if (show_extensions_prompts_ && prompt_for_plugins && |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 2391 | !extension->plugins().empty() && |
| 2392 | disabled_extension_paths_.find(extension->id()) == |
| 2393 | disabled_extension_paths_.end()) { |
| 2394 | SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
| 2395 | profile_, weak_ptr_factory_.GetWeakPtr(), extension); |
| 2396 | prompt->ShowPrompt(); |
| 2397 | return; // continues in SimpleExtensionLoadPrompt::InstallUI* |
| 2398 | } |
[email protected] | f1b6665 | 2011-08-25 23:30:58 | [diff] [blame] | 2399 | OnExtensionInstalled(extension, false, -1); // Not from web store. |
[email protected] | 5fb88938 | 2011-06-03 00:29:20 | [diff] [blame] | 2400 | } |
| 2401 | |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2402 | void ExtensionService::OnExtensionInstalled( |
[email protected] | cc829cf | 2011-08-22 21:01:35 | [diff] [blame] | 2403 | const Extension* extension, bool from_webstore, int page_index) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 2404 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2405 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2406 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2407 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2408 | const std::string& id = extension->id(); |
[email protected] | 8a87a533 | 2011-08-11 17:54:59 | [diff] [blame] | 2409 | // Extensions installed by policy can't be disabled. So even if a previous |
| 2410 | // installation disabled the extension, make sure it is now enabled. |
| 2411 | bool initial_enable = |
| 2412 | !extension_prefs_->IsExtensionDisabled(id) || |
| 2413 | !Extension::UserMayDisable(extension->location()); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2414 | PendingExtensionInfo pending_extension_info; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2415 | if (pending_extension_manager()->GetById(id, &pending_extension_info)) { |
| 2416 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2417 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 2418 | if (!pending_extension_info.ShouldAllowInstall(*extension)) { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2419 | LOG(WARNING) |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2420 | << "ShouldAllowInstall() returned false for " |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2421 | << id << " of type " << extension->GetType() |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 2422 | << " and update URL " << extension->update_url().spec() |
| 2423 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2424 | |
| 2425 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2426 | chrome::NOTIFICATION_EXTENSION_INSTALL_NOT_ALLOWED, |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 2427 | Source<Profile>(profile_), |
| 2428 | Details<const Extension>(extension)); |
| 2429 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2430 | // Delete the extension directory since we're not going to |
| 2431 | // load it. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2432 | if (!BrowserThread::PostTask( |
| 2433 | BrowserThread::FILE, FROM_HERE, |
| 2434 | NewRunnableFunction(&extension_file_util::DeleteFile, |
| 2435 | extension->path(), true))) |
| 2436 | NOTREACHED(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2437 | return; |
| 2438 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2439 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 2440 | // We explicitly want to re-enable an uninstalled external |
| 2441 | // extension; if we're here, that means the user is manually |
| 2442 | // installing the extension. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 2443 | if (IsExternalExtensionUninstalled(id)) { |
| 2444 | initial_enable = true; |
| 2445 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 2446 | } |
| 2447 | |
[email protected] | 0753302 | 2011-06-27 20:42:55 | [diff] [blame] | 2448 | // Do not record the install histograms for upgrades. |
| 2449 | if (!GetExtensionByIdInternal(extension->id(), true, true, false)) { |
| 2450 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
| 2451 | extension->GetType(), 100); |
| 2452 | RecordPermissionMessagesHistogram( |
| 2453 | extension, "Extensions.Permissions_Install"); |
| 2454 | } |
| 2455 | |
[email protected] | eda3c36 | 2010-11-12 08:08:23 | [diff] [blame] | 2456 | ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 2457 | extension_prefs_->OnExtensionInstalled( |
[email protected] | 8266d66 | 2011-07-12 21:53:26 | [diff] [blame] | 2458 | extension, |
| 2459 | initial_enable ? Extension::ENABLED : Extension::DISABLED, |
[email protected] | cc829cf | 2011-08-22 21:01:35 | [diff] [blame] | 2460 | from_webstore, |
| 2461 | page_index); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 2462 | |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 2463 | // Unpacked extensions default to allowing file access, but if that has been |
| 2464 | // overridden, don't reset the value. |
[email protected] | b6e64fd | 2011-08-09 19:49:19 | [diff] [blame] | 2465 | if (Extension::ShouldAlwaysAllowFileAccess(extension->location()) && |
[email protected] | cdfca970 | 2011-08-08 16:07:01 | [diff] [blame] | 2466 | !extension_prefs_->HasAllowFileAccessSetting(id)) { |
| 2467 | extension_prefs_->SetAllowFileAccess(id, true); |
| 2468 | } |
| 2469 | |
[email protected] | a3e61e8 | 2011-04-15 20:32:08 | [diff] [blame] | 2470 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2471 | chrome::NOTIFICATION_EXTENSION_INSTALLED, |
[email protected] | a3e61e8 | 2011-04-15 20:32:08 | [diff] [blame] | 2472 | Source<Profile>(profile_), |
| 2473 | Details<const Extension>(extension)); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2474 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 2475 | // Transfer ownership of |extension| to AddExtension. |
| 2476 | AddExtension(scoped_extension); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 2477 | } |
| 2478 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2479 | const Extension* ExtensionService::GetExtensionByIdInternal( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2480 | const std::string& id, bool include_enabled, bool include_disabled, |
| 2481 | bool include_terminated) const { |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 2482 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 2483 | if (include_enabled) { |
| 2484 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 2485 | iter != extensions_.end(); ++iter) { |
| 2486 | if ((*iter)->id() == lowercase_id) |
| 2487 | return *iter; |
| 2488 | } |
| 2489 | } |
| 2490 | if (include_disabled) { |
| 2491 | for (ExtensionList::const_iterator iter = disabled_extensions_.begin(); |
| 2492 | iter != disabled_extensions_.end(); ++iter) { |
| 2493 | if ((*iter)->id() == lowercase_id) |
| 2494 | return *iter; |
| 2495 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2496 | } |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2497 | if (include_terminated) { |
| 2498 | for (ExtensionList::const_iterator iter = terminated_extensions_.begin(); |
| 2499 | iter != terminated_extensions_.end(); ++iter) { |
| 2500 | if ((*iter)->id() == lowercase_id) |
| 2501 | return *iter; |
| 2502 | } |
| 2503 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2504 | return NULL; |
| 2505 | } |
| 2506 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2507 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
| 2508 | if (terminated_extension_ids_.insert(extension->id()).second) |
| 2509 | terminated_extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2510 | |
[email protected] | 814a7bf0f | 2011-08-13 05:30:59 | [diff] [blame] | 2511 | UnloadExtension(extension->id(), extension_misc::UNLOAD_REASON_DISABLE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2515 | std::string lowercase_id = StringToLowerASCII(id); |
| 2516 | if (terminated_extension_ids_.erase(lowercase_id) <= 0) |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2517 | return; |
| 2518 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 2519 | for (ExtensionList::iterator iter = terminated_extensions_.begin(); |
| 2520 | iter != terminated_extensions_.end(); ++iter) { |
| 2521 | if ((*iter)->id() == lowercase_id) { |
| 2522 | terminated_extensions_.erase(iter); |
| 2523 | return; |
| 2524 | } |
| 2525 | } |
| 2526 | } |
| 2527 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2528 | const Extension* ExtensionService::GetTerminatedExtension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 2529 | const std::string& id) const { |
| 2530 | return GetExtensionByIdInternal(id, false, false, true); |
| 2531 | } |
| 2532 | |
| 2533 | const Extension* ExtensionService::GetInstalledExtension( |
| 2534 | const std::string& id) const { |
| 2535 | return GetExtensionByIdInternal(id, true, true, true); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 2536 | } |
| 2537 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2538 | const Extension* ExtensionService::GetWebStoreApp() { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 2539 | return GetExtensionById(extension_misc::kWebStoreAppId, false); |
| 2540 | } |
| 2541 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2542 | const Extension* ExtensionService::GetExtensionByURL(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 2543 | return url.scheme() != chrome::kExtensionScheme ? NULL : |
| 2544 | GetExtensionById(url.host(), false); |
| 2545 | } |
| 2546 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2547 | const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 2548 | for (size_t i = 0; i < extensions_.size(); ++i) { |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2549 | if (extensions_[i]->web_extent().MatchesURL(url)) |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 2550 | return extensions_[i]; |
| 2551 | } |
| 2552 | return NULL; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 2553 | } |
| 2554 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2555 | bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 2556 | // Allow bindings for all packaged extensions. |
| 2557 | // Note that GetExtensionByURL may return an Extension for hosted apps |
| 2558 | // if the URL came from GetEffectiveURL. |
| 2559 | const Extension* extension = GetExtensionByURL(url); |
| 2560 | if (extension && extension->GetType() != Extension::TYPE_HOSTED_APP) |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 2561 | return true; |
| 2562 | |
| 2563 | // Allow bindings for all component, hosted apps. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 2564 | if (!extension) |
| 2565 | extension = GetExtensionByWebExtent(url); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 2566 | return (extension && extension->location() == Extension::COMPONENT); |
| 2567 | } |
| 2568 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2569 | const Extension* ExtensionService::GetExtensionByOverlappingWebExtent( |
[email protected] | cced75a | 2011-05-20 08:31:12 | [diff] [blame] | 2570 | const URLPatternSet& extent) { |
[email protected] | 22c966c | 2010-06-26 06:35:02 | [diff] [blame] | 2571 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 2572 | if (extensions_[i]->web_extent().OverlapsWith(extent)) |
| 2573 | return extensions_[i]; |
| 2574 | } |
| 2575 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 2576 | return NULL; |
| 2577 | } |
| 2578 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2579 | const SkBitmap& ExtensionService::GetOmniboxIcon( |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 2580 | const std::string& extension_id) { |
| 2581 | return omnibox_icon_manager_.GetIcon(extension_id); |
| 2582 | } |
| 2583 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2584 | const SkBitmap& ExtensionService::GetOmniboxPopupIcon( |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 2585 | const std::string& extension_id) { |
| 2586 | return omnibox_popup_icon_manager_.GetIcon(extension_id); |
| 2587 | } |
| 2588 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2589 | void ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2590 | const std::string& id, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2591 | const Version* version, |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2592 | const FilePath& path, |
| 2593 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 2594 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2595 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 2596 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 2597 | return; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2598 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2599 | DCHECK(version); |
| 2600 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2601 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 2602 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2603 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2604 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2605 | if (existing) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2606 | switch (existing->version()->CompareTo(*version)) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2607 | case -1: // existing version is older, we should upgrade |
| 2608 | break; |
| 2609 | case 0: // existing version is same, do nothing |
| 2610 | return; |
| 2611 | case 1: // existing version is newer, uh-oh |
| 2612 | LOG(WARNING) << "Found external version of extension " << id |
| 2613 | << "that is older than current version. Current version " |
| 2614 | << "is: " << existing->VersionString() << ". New version " |
| 2615 | << "is: " << version << ". Keeping current version."; |
| 2616 | return; |
| 2617 | } |
| 2618 | } |
| 2619 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2620 | pending_extension_manager()->AddFromExternalFile(id, location); |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 2621 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2622 | // no client (silent install) |
| 2623 | scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(NULL)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2624 | installer->set_install_source(location); |
| 2625 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 2626 | installer->set_expected_version(*version); |
| 2627 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2628 | installer->InstallCrx(path); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2629 | } |
| 2630 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2631 | void ExtensionService::ReportExtensionLoadError( |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2632 | const FilePath& extension_path, |
| 2633 | const std::string &error, |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2634 | int type, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2635 | bool be_noisy) { |
| 2636 | NotificationService* service = NotificationService::current(); |
| 2637 | service->Notify(type, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2638 | Source<Profile>(profile_), |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2639 | Details<const std::string>(&error)); |
| 2640 | |
[email protected] | 8a205c0 | 2011-02-04 20:41:33 | [diff] [blame] | 2641 | std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 2642 | std::string message = base::StringPrintf( |
| 2643 | "Could not load extension from '%s'. %s", |
| 2644 | path_str.c_str(), error.c_str()); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2645 | ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
| 2646 | } |
| 2647 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2648 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2649 | ExtensionHost* host) { |
| 2650 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2651 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2652 | if (iter == orphaned_dev_tools_.end()) |
| 2653 | return; |
| 2654 | |
| 2655 | DevToolsManager::GetInstance()->AttachClientHost( |
| 2656 | iter->second, host->render_view_host()); |
| 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] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2661 | const NotificationSource& source, |
| 2662 | const NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2663 | switch (type) { |
| 2664 | case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2665 | if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile()) |
| 2666 | break; |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2667 | |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2668 | ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
| 2669 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2670 | // Mark the extension as terminated and Unload it. We want it to |
| 2671 | // be in a consistent state: either fully working or not loaded |
| 2672 | // at all, but never half-crashed. We do it in a PostTask so |
| 2673 | // that other handlers of this notification will still have |
| 2674 | // access to the Extension and ExtensionHost. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2675 | MessageLoop::current()->PostTask( |
| 2676 | FROM_HERE, |
| 2677 | method_factory_.NewRunnableMethod( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2678 | &ExtensionService::TrackTerminatedExtension, |
| 2679 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2680 | break; |
| 2681 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2682 | case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2683 | RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2684 | Profile* host_profile = |
| 2685 | Profile::FromBrowserContext(process->browser_context()); |
| 2686 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2687 | break; |
| 2688 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2689 | // Valid extension function names, used to setup bindings in renderer. |
| 2690 | std::vector<std::string> function_names; |
| 2691 | ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); |
| 2692 | process->Send(new ExtensionMsg_SetFunctionNames(function_names)); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2693 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2694 | // Scripting whitelist. This is modified by tests and must be communicated |
| 2695 | // to renderers. |
| 2696 | process->Send(new ExtensionMsg_SetScriptingWhitelist( |
| 2697 | *Extension::GetScriptingWhitelist())); |
| 2698 | |
| 2699 | // Loaded extensions. |
| 2700 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 2701 | process->Send(new ExtensionMsg_Loaded( |
[email protected] | 1537964 | 2011-08-11 22:22:05 | [diff] [blame] | 2702 | ExtensionMsg_Loaded_Params(extensions_[i]))); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2703 | } |
| 2704 | break; |
| 2705 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2706 | case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2707 | RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
[email protected] | fc30ef08 | 2011-08-18 04:07:19 | [diff] [blame] | 2708 | Profile* host_profile = |
| 2709 | Profile::FromBrowserContext(process->browser_context()); |
| 2710 | if (!profile_->IsSameProfile(host_profile->GetOriginalProfile())) |
| 2711 | break; |
| 2712 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2713 | installed_app_hosts_.erase(process->id()); |
| 2714 | break; |
| 2715 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2716 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2717 | std::string* pref_name = Details<std::string>(details).ptr(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2718 | if (*pref_name == prefs::kExtensionInstallAllowList || |
| 2719 | *pref_name == prefs::kExtensionInstallDenyList) { |
| 2720 | CheckAdminBlacklist(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2721 | } else { |
| 2722 | NOTREACHED() << "Unexpected preference name."; |
| 2723 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2724 | break; |
| 2725 | } |
[email protected] | d9126802 | 2011-08-26 13:17:37 | [diff] [blame^] | 2726 | case chrome::NOTIFICATION_IMPORT_FINISHED: { |
| 2727 | registrar_.Remove(this, chrome::NOTIFICATION_IMPORT_FINISHED, |
| 2728 | Source<Profile>(profile_)); |
| 2729 | InitEventRouters(); |
| 2730 | break; |
| 2731 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2732 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2733 | default: |
| 2734 | NOTREACHED() << "Unexpected notification type."; |
| 2735 | } |
| 2736 | } |
| 2737 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2738 | bool ExtensionService::HasApps() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2739 | return !GetAppIds().empty(); |
| 2740 | } |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2741 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2742 | ExtensionIdSet ExtensionService::GetAppIds() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2743 | ExtensionIdSet result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2744 | for (ExtensionList::const_iterator it = extensions_.begin(); |
| 2745 | it != extensions_.end(); ++it) { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2746 | if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) |
| 2747 | result.insert((*it)->id()); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2748 | } |
| 2749 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2750 | return result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2751 | } |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2752 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2753 | scoped_refptr<CrxInstaller> ExtensionService::MakeCrxInstaller( |
| 2754 | ExtensionInstallUI* client) { |
| 2755 | return new CrxInstaller(weak_ptr_factory_.GetWeakPtr(), client); |
| 2756 | } |
| 2757 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2758 | bool ExtensionService::IsBackgroundPageReady(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2759 | return (extension->background_url().is_empty() || |
| 2760 | extension_runtime_data_[extension->id()].background_page_ready); |
| 2761 | } |
| 2762 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2763 | void ExtensionService::SetBackgroundPageReady(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2764 | DCHECK(!extension->background_url().is_empty()); |
| 2765 | extension_runtime_data_[extension->id()].background_page_ready = true; |
| 2766 | NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2767 | chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2768 | Source<const Extension>(extension), |
| 2769 | NotificationService::NoDetails()); |
| 2770 | } |
| 2771 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2772 | bool ExtensionService::IsBeingUpgraded(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2773 | return extension_runtime_data_[extension->id()].being_upgraded; |
| 2774 | } |
| 2775 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2776 | void ExtensionService::SetBeingUpgraded(const Extension* extension, |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2777 | bool value) { |
| 2778 | extension_runtime_data_[extension->id()].being_upgraded = value; |
| 2779 | } |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2780 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2781 | PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2782 | return &extension_runtime_data_[extension->id()].property_bag; |
| 2783 | } |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 2784 | |
| 2785 | void ExtensionService::RegisterNaClModule(const GURL& url, |
| 2786 | const std::string& mime_type) { |
| 2787 | NaClModuleInfo info; |
| 2788 | info.url = url; |
| 2789 | info.mime_type = mime_type; |
| 2790 | |
| 2791 | DCHECK(FindNaClModule(url) == nacl_module_list_.end()); |
| 2792 | nacl_module_list_.push_front(info); |
| 2793 | } |
| 2794 | |
| 2795 | void ExtensionService::UnregisterNaClModule(const GURL& url) { |
| 2796 | NaClModuleInfoList::iterator iter = FindNaClModule(url); |
| 2797 | DCHECK(iter != nacl_module_list_.end()); |
| 2798 | nacl_module_list_.erase(iter); |
| 2799 | } |
| 2800 | |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2801 | void ExtensionService::UpdatePluginListWithNaClModules() { |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2802 | // An extension has been added which has a nacl_module component, which means |
| 2803 | // there is a MIME type that module wants to handle, so we need to add that |
| 2804 | // MIME type to plugins which handle NaCl modules in order to allow the |
| 2805 | // individual modules to handle these types. |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2806 | const PepperPluginInfo* pepper_info = NULL; |
| 2807 | std::vector<PepperPluginInfo> plugins; |
| 2808 | PepperPluginRegistry::ComputeList(&plugins); |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2809 | |
| 2810 | // Search the entire plugin list for plugins that handle the NaCl MIME type. |
| 2811 | // There can be multiple plugins like this, for instance the internal NaCl |
| 2812 | // plugin and a plugin registered by --register-pepper-plugins during tests. |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2813 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2814 | pepper_info = &plugins[i]; |
| 2815 | CHECK(pepper_info); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 2816 | std::vector<webkit::WebPluginMimeType>::const_iterator mime_iter; |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2817 | // Check each MIME type the plugins handle for the NaCl MIME type. |
| 2818 | for (mime_iter = pepper_info->mime_types.begin(); |
| 2819 | mime_iter != pepper_info->mime_types.end(); ++mime_iter) { |
| 2820 | if (mime_iter->mime_type == kNaClPluginMimeType) { |
| 2821 | // This plugin handles "application/x-nacl". |
| 2822 | |
| 2823 | webkit::npapi::PluginList::Singleton()-> |
| 2824 | UnregisterInternalPlugin(pepper_info->path); |
| 2825 | |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 2826 | webkit::WebPluginInfo info = pepper_info->ToWebPluginInfo(); |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2827 | |
| 2828 | for (ExtensionService::NaClModuleInfoList::const_iterator iter = |
| 2829 | nacl_module_list_.begin(); |
| 2830 | iter != nacl_module_list_.end(); ++iter) { |
| 2831 | // Add the MIME type specified in the extension to this NaCl plugin, |
| 2832 | // With an extra "nacl" argument to specify the location of the NaCl |
| 2833 | // manifest file. |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 2834 | webkit::WebPluginMimeType mime_type_info; |
[email protected] | 300c0ea | 2011-07-15 23:04:33 | [diff] [blame] | 2835 | mime_type_info.mime_type = iter->mime_type; |
| 2836 | mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| 2837 | mime_type_info.additional_param_values.push_back( |
| 2838 | UTF8ToUTF16(iter->url.spec())); |
| 2839 | info.mime_types.push_back(mime_type_info); |
| 2840 | } |
| 2841 | |
| 2842 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 2843 | webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 2844 | // This plugin has been modified, no need to check the rest of its |
| 2845 | // types, but continue checking other plugins. |
| 2846 | break; |
| 2847 | } |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2848 | } |
| 2849 | } |
[email protected] | ed0ba00 | 2011-05-26 16:55:13 | [diff] [blame] | 2850 | } |
| 2851 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 2852 | ExtensionService::NaClModuleInfoList::iterator |
| 2853 | ExtensionService::FindNaClModule(const GURL& url) { |
| 2854 | for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2855 | iter != nacl_module_list_.end(); ++iter) { |
| 2856 | if (iter->url == url) |
| 2857 | return iter; |
| 2858 | } |
| 2859 | return nacl_module_list_.end(); |
| 2860 | } |