[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] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 16 | #include "base/stl_util-inl.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] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 27 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 28 | #include "chrome/browser/extensions/crx_installer.h" |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 29 | #include "chrome/browser/extensions/apps_promo.h" |
[email protected] | 5cbe1e2 | 2010-01-30 01:18:56 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_accessibility_api.h" |
[email protected] | 840b0db | 2009-11-20 03:00:38 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_bookmarks_module.h" |
[email protected] | b68d5ed | 2009-04-16 02:41:28 | [diff] [blame] | 32 | #include "chrome/browser/extensions/extension_browser_event_router.h" |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 33 | #include "chrome/browser/extensions/extension_cookies_api.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 34 | #include "chrome/browser/extensions/extension_data_deleter.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | de768a83 | 2009-10-30 05:25:01 | [diff] [blame] | 36 | #include "chrome/browser/extensions/extension_history_api.h" |
[email protected] | b1748b1d8 | 2009-11-30 20:32:56 | [diff] [blame] | 37 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 7596ce7 | 2010-08-30 05:10:46 | [diff] [blame] | 38 | #include "chrome/browser/extensions/extension_management_api.h" |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extension_preference_api.h" |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 40 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 41 | #include "chrome/browser/extensions/extension_processes_api.h" |
[email protected] | 19eb8015 | 2011-02-26 00:28:43 | [diff] [blame] | 42 | #include "chrome/browser/extensions/extension_special_storage_policy.h" |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 43 | #include "chrome/browser/extensions/extension_sync_data.h" |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 44 | #include "chrome/browser/extensions/extension_updater.h" |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 45 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 784688a6 | 2010-09-13 07:06:52 | [diff] [blame] | 46 | #include "chrome/browser/extensions/extension_webnavigation_api.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 47 | #include "chrome/browser/extensions/external_extension_provider_impl.h" |
[email protected] | 42b79565 | 2011-02-22 23:32:38 | [diff] [blame] | 48 | #include "chrome/browser/extensions/external_extension_provider_interface.h" |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 49 | #include "chrome/browser/extensions/pending_extension_manager.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 50 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 51 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 52 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 53 | #include "chrome/browser/search_engines/template_url_model.h" |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 54 | #include "chrome/browser/themes/theme_service.h" |
[email protected] | a0ea76c | 2011-03-23 17:36:42 | [diff] [blame] | 55 | #include "chrome/browser/themes/theme_service_factory.h" |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 56 | #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
| 57 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | 7c5c6f3a | 2011-04-28 19:56:49 | [diff] [blame] | 58 | #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 59 | #include "chrome/common/child_process_logging.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 60 | #include "chrome/common/chrome_paths.h" |
[email protected] | e2eb4311 | 2009-05-29 21:19:54 | [diff] [blame] | 61 | #include "chrome/common/chrome_switches.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 62 | #include "chrome/common/extensions/extension.h" |
[email protected] | d7b36dc | 2009-10-29 21:47:40 | [diff] [blame] | 63 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 64 | #include "chrome/common/extensions/extension_error_utils.h" |
[email protected] | 7c927b6 | 2010-02-24 09:54:13 | [diff] [blame] | 65 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 66 | #include "chrome/common/extensions/extension_l10n_util.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 67 | #include "chrome/common/extensions/extension_messages.h" |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 68 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 69 | #include "chrome/common/pref_names.h" |
[email protected] | a5720987 | 2009-05-04 22:53:14 | [diff] [blame] | 70 | #include "chrome/common/url_constants.h" |
[email protected] | 5f945a0e | 2011-03-01 17:47:53 | [diff] [blame] | 71 | #include "content/browser/browser_thread.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 72 | #include "content/browser/plugin_process_host.h" |
| 73 | #include "content/browser/plugin_service.h" |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 74 | #include "content/browser/renderer_host/render_process_host.h" |
[email protected] | c311302 | 2011-04-16 03:26:30 | [diff] [blame] | 75 | #include "content/common/json_value_serializer.h" |
[email protected] | b3841c50 | 2011-03-09 01:21:31 | [diff] [blame] | 76 | #include "content/common/notification_service.h" |
| 77 | #include "content/common/notification_type.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 78 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 79 | #include "googleurl/src/gurl.h" |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 80 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 24b538a | 2010-02-27 01:22:44 | [diff] [blame] | 81 | #include "webkit/database/database_tracker.h" |
| 82 | #include "webkit/database/database_util.h" |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 83 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | c6463165 | 2009-04-29 22:24:31 | [diff] [blame] | 84 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 85 | #if defined(OS_CHROMEOS) |
| 86 | #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 87 | #include "webkit/fileapi/file_system_context.h" |
| 88 | #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 89 | #include "webkit/fileapi/file_system_path_manager.h" |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 90 | #endif |
| 91 | |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame^] | 92 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
| 93 | #include "chrome/browser/extensions/extension_input_ui_api.h" |
| 94 | #endif |
| 95 | |
[email protected] | 5ef47ec | 2010-01-28 05:58:05 | [diff] [blame] | 96 | using base::Time; |
| 97 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 98 | namespace errors = extension_manifest_errors; |
| 99 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 100 | namespace { |
| 101 | |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 102 | #if defined(OS_LINUX) |
| 103 | static const int kOmniboxIconPaddingLeft = 2; |
| 104 | static const int kOmniboxIconPaddingRight = 2; |
| 105 | #elif defined(OS_MACOSX) |
| 106 | static const int kOmniboxIconPaddingLeft = 0; |
| 107 | static const int kOmniboxIconPaddingRight = 2; |
| 108 | #else |
| 109 | static const int kOmniboxIconPaddingLeft = 0; |
| 110 | static const int kOmniboxIconPaddingRight = 0; |
| 111 | #endif |
| 112 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 113 | // The following enumeration is used in histograms matching |
| 114 | // Extensions.ManifestReload* . Values may be added, as long |
| 115 | // as existing values are not changed. |
| 116 | enum ManifestReloadReason { |
| 117 | NOT_NEEDED = 0, // Reload not needed. |
| 118 | UNPACKED_DIR, // Unpacked directory |
| 119 | NEEDS_RELOCALIZATION, // The local has changed since we read this extension. |
| 120 | NUM_MANIFEST_RELOAD_REASONS |
| 121 | }; |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 122 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 123 | ManifestReloadReason ShouldReloadExtensionManifest(const ExtensionInfo& info) { |
| 124 | // Always reload manifests of unpacked extensions, because they can change |
| 125 | // on disk independent of the manifest in our prefs. |
| 126 | if (info.extension_location == Extension::LOAD) |
| 127 | return UNPACKED_DIR; |
| 128 | |
| 129 | // Reload the manifest if it needs to be relocalized. |
| 130 | if (extension_l10n_util::ShouldRelocalizeManifest(info)) |
| 131 | return NEEDS_RELOCALIZATION; |
| 132 | |
| 133 | return NOT_NEEDED; |
[email protected] | 2111b1a | 2010-03-12 18:12:44 | [diff] [blame] | 134 | } |
| 135 | |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 136 | static void ForceShutdownPlugin(const FilePath& plugin_path) { |
| 137 | PluginProcessHost* plugin = |
| 138 | PluginService::GetInstance()->FindNpapiPluginProcess(plugin_path); |
| 139 | if (plugin) |
| 140 | plugin->ForceShutdown(); |
| 141 | } |
| 142 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 143 | } // namespace |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 144 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 145 | ExtensionService::ExtensionRuntimeData::ExtensionRuntimeData() |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 146 | : background_page_ready(false), |
| 147 | being_upgraded(false) { |
| 148 | } |
| 149 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 150 | ExtensionService::ExtensionRuntimeData::~ExtensionRuntimeData() { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 153 | ExtensionService::NaClModuleInfo::NaClModuleInfo() { |
| 154 | } |
| 155 | |
| 156 | ExtensionService::NaClModuleInfo::~NaClModuleInfo() { |
| 157 | } |
| 158 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 159 | // ExtensionService. |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 160 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 161 | const char* ExtensionService::kInstallDirectoryName = "Extensions"; |
| 162 | const char* ExtensionService::kCurrentVersionFileName = "Current Version"; |
[email protected] | 494c06e | 2009-07-25 01:06:42 | [diff] [blame] | 163 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 164 | // Implements IO for the ExtensionService. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 165 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 166 | class ExtensionServiceBackend |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 167 | : public base::RefCountedThreadSafe<ExtensionServiceBackend> { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 168 | public: |
[email protected] | 1f830eb | 2010-09-28 08:25:14 | [diff] [blame] | 169 | // |install_directory| is a path where to look for extensions to load. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 170 | ExtensionServiceBackend( |
| 171 | base::WeakPtr<ExtensionService> frontend, |
| 172 | const FilePath& install_directory); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 173 | |
| 174 | // Loads a single extension from |path| where |path| is the top directory of |
| 175 | // a specific extension where its manifest file lives. |
| 176 | // Errors are reported through ExtensionErrorReporter. On success, |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 177 | // AddExtension() is called. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 178 | // TODO(erikkay): It might be useful to be able to load a packed extension |
| 179 | // (presumably into memory) without installing it. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 180 | void LoadSingleExtension(const FilePath &path); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 181 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 182 | private: |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 183 | friend class base::RefCountedThreadSafe<ExtensionServiceBackend>; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 184 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 185 | virtual ~ExtensionServiceBackend(); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 186 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 187 | // Notify the frontend that there was an error loading an extension. |
| 188 | void ReportExtensionLoadError(const FilePath& extension_path, |
| 189 | const std::string& error); |
| 190 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 191 | // Notify the frontend that an extension was installed. |
| 192 | void OnExtensionInstalled(const scoped_refptr<const Extension>& extension); |
| 193 | |
| 194 | base::WeakPtr<ExtensionService> frontend_; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 195 | |
| 196 | // The top-level extensions directory being installed to. |
| 197 | FilePath install_directory_; |
| 198 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 199 | DISALLOW_COPY_AND_ASSIGN(ExtensionServiceBackend); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 200 | }; |
| 201 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 202 | ExtensionServiceBackend::ExtensionServiceBackend( |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 203 | base::WeakPtr<ExtensionService> frontend, |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 204 | const FilePath& install_directory) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 205 | : frontend_(frontend), |
| 206 | install_directory_(install_directory) { |
| 207 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 210 | ExtensionServiceBackend::~ExtensionServiceBackend() { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 211 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 212 | BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 213 | } |
| 214 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 215 | void ExtensionServiceBackend::LoadSingleExtension(const FilePath& path_in) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 216 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 217 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 218 | FilePath extension_path = path_in; |
| 219 | file_util::AbsolutePath(&extension_path); |
| 220 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 221 | int flags = Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) ? |
| 222 | Extension::ALLOW_FILE_ACCESS : Extension::NO_FLAGS; |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 223 | if (Extension::ShouldDoStrictErrorChecking(Extension::LOAD)) |
| 224 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 225 | std::string error; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 226 | scoped_refptr<const Extension> extension(extension_file_util::LoadExtension( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 227 | extension_path, |
[email protected] | 9288808 | 2010-10-18 19:24:57 | [diff] [blame] | 228 | Extension::LOAD, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 229 | flags, |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 230 | &error)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 231 | |
| 232 | if (!extension) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 233 | if (!BrowserThread::PostTask( |
| 234 | BrowserThread::UI, FROM_HERE, |
| 235 | NewRunnableMethod( |
| 236 | this, |
| 237 | &ExtensionServiceBackend::ReportExtensionLoadError, |
| 238 | extension_path, error))) |
| 239 | NOTREACHED() << error; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 240 | return; |
| 241 | } |
| 242 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 243 | // Report this as an installed extension so that it gets remembered in the |
| 244 | // prefs. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 245 | if (!BrowserThread::PostTask( |
| 246 | BrowserThread::UI, FROM_HERE, |
| 247 | NewRunnableMethod( |
| 248 | this, |
| 249 | &ExtensionServiceBackend::OnExtensionInstalled, |
| 250 | extension))) |
| 251 | NOTREACHED(); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 254 | void ExtensionServiceBackend::ReportExtensionLoadError( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 255 | const FilePath& extension_path, const std::string &error) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 256 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 257 | if (frontend_.get()) |
| 258 | frontend_->ReportExtensionLoadError( |
| 259 | extension_path, error, NotificationType::EXTENSION_INSTALL_ERROR, |
| 260 | true /* alert_on_error */); |
| 261 | } |
| 262 | |
| 263 | void ExtensionServiceBackend::OnExtensionInstalled( |
| 264 | const scoped_refptr<const Extension>& extension) { |
| 265 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 | if (frontend_.get()) |
| 267 | frontend_->OnExtensionInstalled(extension); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 270 | void ExtensionService::CheckExternalUninstall(const std::string& id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 271 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 272 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 273 | // Check if the providers know about this extension. |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 274 | ProviderCollection::const_iterator i; |
| 275 | for (i = external_extension_providers_.begin(); |
| 276 | i != external_extension_providers_.end(); ++i) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 277 | DCHECK(i->get()->IsReady()); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 278 | if (i->get()->HasExtension(id)) |
| 279 | return; // Yup, known extension, don't uninstall. |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 280 | } |
| 281 | |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 282 | // This is an external extension that we don't have registered. Uninstall. |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 283 | UninstallExtension(id, true, NULL); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 286 | void ExtensionService::ClearProvidersForTesting() { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 287 | external_extension_providers_.clear(); |
| 288 | } |
| 289 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 290 | void ExtensionService::AddProviderForTesting( |
| 291 | ExternalExtensionProviderInterface* test_provider) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 292 | CHECK(test_provider); |
[email protected] | 0a60a2e | 2010-10-25 16:15:21 | [diff] [blame] | 293 | external_extension_providers_.push_back( |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 294 | linked_ptr<ExternalExtensionProviderInterface>(test_provider)); |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 297 | void ExtensionService::OnExternalExtensionUpdateUrlFound( |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 298 | const std::string& id, |
[email protected] | 21a5a67 | 2010-11-04 10:47:42 | [diff] [blame] | 299 | const GURL& update_url, |
| 300 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 301 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 302 | CHECK(Extension::IdIsValid(id)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 303 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 304 | if (GetExtensionById(id, true)) { |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 305 | // Already installed. Do not change the update URL that the extension set. |
| 306 | return; |
| 307 | } |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 308 | pending_extension_manager()->AddFromExternalUpdateUrl( |
| 309 | id, update_url, location); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 310 | external_extension_url_added_ |= true; |
[email protected] | 7a4c685 | 2010-09-16 03:44:22 | [diff] [blame] | 311 | } |
| 312 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 313 | bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 314 | const GURL& referrer_url) { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 315 | // Special-case the themes mini-gallery. |
| 316 | // TODO(erikkay) When that gallery goes away, remove this code. |
| 317 | if (IsDownloadFromMiniGallery(download_url) && |
| 318 | StartsWithASCII(referrer_url.spec(), |
| 319 | extension_urls::kMiniGalleryBrowsePrefix, false)) { |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 320 | return true; |
[email protected] | 1debbbb6 | 2010-10-06 17:23:44 | [diff] [blame] | 321 | } |
[email protected] | 473ff6e | 2010-05-12 15:31:55 | [diff] [blame] | 322 | |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 323 | const Extension* download_extension = GetExtensionByWebExtent(download_url); |
| 324 | const Extension* referrer_extension = GetExtensionByWebExtent(referrer_url); |
| 325 | const Extension* webstore_app = GetWebStoreApp(); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 326 | |
| 327 | bool referrer_valid = (referrer_extension == webstore_app); |
| 328 | bool download_valid = (download_extension == webstore_app); |
| 329 | |
| 330 | // If the command-line gallery URL is set, then be a bit more lenient. |
| 331 | GURL store_url = |
| 332 | GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 333 | switches::kAppsGalleryURL)); |
| 334 | if (!store_url.is_empty()) { |
| 335 | std::string store_tld = |
| 336 | net::RegistryControlledDomainService::GetDomainAndRegistry(store_url); |
| 337 | if (!referrer_valid) { |
| 338 | std::string referrer_tld = |
| 339 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
| 340 | referrer_url); |
| 341 | // The referrer gets stripped when transitioning from https to http, |
| 342 | // or when hitting an unknown test cert and that commonly happens in |
| 343 | // testing environments. Given this, we allow an empty referrer when |
| 344 | // the command-line flag is set. |
| 345 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 346 | referrer_valid = referrer_url.is_empty() || (referrer_tld == store_tld); |
| 347 | } |
| 348 | |
| 349 | if (!download_valid) { |
| 350 | std::string download_tld = |
| 351 | net::RegistryControlledDomainService::GetDomainAndRegistry( |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 352 | download_url); |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 353 | |
| 354 | // Otherwise, the TLD must match the TLD of the command-line url. |
| 355 | download_valid = (download_tld == store_tld); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | return (referrer_valid && download_valid); |
[email protected] | b7c2f25 | 2009-12-08 00:47:23 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 362 | bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) { |
[email protected] | ac02528 | 2009-12-16 19:16:38 | [diff] [blame] | 363 | return StartsWithASCII(download_url.spec(), |
| 364 | extension_urls::kMiniGalleryDownloadPrefix, |
| 365 | false); // case_sensitive |
| 366 | } |
| 367 | |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 368 | const Extension* ExtensionService::GetInstalledApp(const GURL& url) { |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 369 | // Check for hosted app. |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 370 | const Extension* app = GetExtensionByWebExtent(url); |
| 371 | if (app) |
| 372 | return app; |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 373 | |
| 374 | // Check for packaged app. |
[email protected] | d969667 | 2011-03-15 22:45:09 | [diff] [blame] | 375 | app = GetExtensionByURL(url); |
| 376 | if (app && app->is_app()) |
| 377 | return app; |
| 378 | |
| 379 | return NULL; |
| 380 | } |
| 381 | |
| 382 | bool ExtensionService::IsInstalledApp(const GURL& url) { |
| 383 | return !!GetInstalledApp(url); |
[email protected] | ffb204f2 | 2010-12-05 23:20:27 | [diff] [blame] | 384 | } |
| 385 | |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 386 | void ExtensionService::SetInstalledAppForRenderer(int renderer_child_id, |
| 387 | const Extension* app) { |
| 388 | installed_app_hosts_[renderer_child_id] = app; |
| 389 | } |
| 390 | |
| 391 | const Extension* ExtensionService::GetInstalledAppForRenderer( |
| 392 | int renderer_child_id) { |
| 393 | InstalledAppMap::iterator i = installed_app_hosts_.find(renderer_child_id); |
| 394 | if (i == installed_app_hosts_.end()) |
| 395 | return NULL; |
| 396 | return i->second; |
| 397 | } |
| 398 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 399 | // static |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 400 | // This function is used to implement the command-line switch |
| 401 | // --uninstall-extension. The LOG statements within this function are used to |
| 402 | // inform the user if the uninstall cannot be done. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 403 | bool ExtensionService::UninstallExtensionHelper( |
| 404 | ExtensionService* extensions_service, |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 405 | const std::string& extension_id) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 406 | |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 407 | const Extension* extension = |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 408 | extensions_service->GetInstalledExtension(extension_id); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 409 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 410 | // We can't call UninstallExtension with an invalid extension ID. |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 411 | if (!extension) { |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 412 | LOG(WARNING) << "Attempted uninstallation of non-existent extension with " |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 413 | << "id: " << extension_id; |
| 414 | return false; |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 417 | // The following call to UninstallExtension will not allow an uninstall of a |
| 418 | // policy-controlled extension. |
| 419 | std::string error; |
| 420 | if (!extensions_service->UninstallExtension(extension_id, false, &error)) { |
| 421 | LOG(WARNING) << "Cannot uninstall extension with id " << extension_id |
| 422 | << ": " << error; |
| 423 | return false; |
| 424 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 425 | |
[email protected] | 6aeac834 | 2010-10-01 20:21:18 | [diff] [blame] | 426 | return true; |
| 427 | } |
| 428 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 429 | ExtensionService::ExtensionService(Profile* profile, |
[email protected] | f0841cd | 2011-01-19 15:07:24 | [diff] [blame] | 430 | const CommandLine* command_line, |
| 431 | const FilePath& install_directory, |
| 432 | ExtensionPrefs* extension_prefs, |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 433 | bool autoupdate_enabled, |
| 434 | bool extensions_enabled) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 435 | : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 436 | method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 437 | profile_(profile), |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 438 | extension_prefs_(extension_prefs), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 439 | pending_extension_manager_(*ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | a9b00ac | 2009-06-25 21:03:23 | [diff] [blame] | 440 | install_directory_(install_directory), |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 441 | extensions_enabled_(extensions_enabled), |
[email protected] | e81dba3 | 2009-06-19 20:19:13 | [diff] [blame] | 442 | show_extensions_prompts_(true), |
[email protected] | 3ecda25 | 2010-11-18 19:50:55 | [diff] [blame] | 443 | ready_(false), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 444 | toolbar_model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
[email protected] | 18cc5a5 | 2011-04-15 16:03:38 | [diff] [blame] | 445 | apps_promo_(profile->GetPrefs()), |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 446 | event_routers_initialized_(false) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 447 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 448 | |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 449 | // Figure out if extension installation should be enabled. |
[email protected] | 6d60703b | 2009-08-29 01:29:23 | [diff] [blame] | 450 | if (command_line->HasSwitch(switches::kDisableExtensions)) { |
| 451 | extensions_enabled_ = false; |
| 452 | } else if (profile->GetPrefs()->GetBoolean(prefs::kDisableExtensions)) { |
| 453 | extensions_enabled_ = false; |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 454 | } |
[email protected] | 36a784c | 2009-06-23 06:21:08 | [diff] [blame] | 455 | |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 456 | registrar_.Add(this, NotificationType::EXTENSION_PROCESS_TERMINATED, |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 457 | NotificationService::AllSources()); |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 458 | registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, |
| 459 | NotificationService::AllSources()); |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 460 | registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, |
| 461 | NotificationService::AllSources()); |
[email protected] | 2fb7dc98 | 2010-09-29 12:24:28 | [diff] [blame] | 462 | pref_change_registrar_.Init(profile->GetPrefs()); |
| 463 | pref_change_registrar_.Add(prefs::kExtensionInstallAllowList, this); |
| 464 | pref_change_registrar_.Add(prefs::kExtensionInstallDenyList, this); |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 465 | |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 466 | // Set up the ExtensionUpdater |
| 467 | if (autoupdate_enabled) { |
| 468 | int update_frequency = kDefaultUpdateFrequencySeconds; |
| 469 | if (command_line->HasSwitch(switches::kExtensionsUpdateFrequency)) { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 470 | base::StringToInt(command_line->GetSwitchValueASCII( |
| 471 | switches::kExtensionsUpdateFrequency), |
| 472 | &update_frequency); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 473 | } |
[email protected] | 82b6e51 | 2011-04-12 20:33:27 | [diff] [blame] | 474 | updater_.reset(new ExtensionUpdater(this, |
| 475 | extension_prefs, |
| 476 | profile->GetPrefs(), |
| 477 | profile, |
| 478 | update_frequency)); |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 481 | backend_ = |
| 482 | new ExtensionServiceBackend(weak_ptr_factory_.GetWeakPtr(), |
| 483 | install_directory_); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 484 | |
[email protected] | 0436b10 | 2011-04-15 18:30:03 | [diff] [blame] | 485 | if (extensions_enabled_) { |
[email protected] | 87353134 | 2011-03-09 12:16:05 | [diff] [blame] | 486 | ExternalExtensionProviderImpl::CreateExternalProviders( |
| 487 | this, profile_, &external_extension_providers_); |
| 488 | } |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 489 | |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 490 | // Use monochrome icons for Omnibox icons. |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 491 | omnibox_popup_icon_manager_.set_monochrome(true); |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 492 | omnibox_icon_manager_.set_monochrome(true); |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 493 | omnibox_icon_manager_.set_padding(gfx::Insets(0, kOmniboxIconPaddingLeft, |
| 494 | 0, kOmniboxIconPaddingRight)); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 495 | |
| 496 | // How long is the path to the Extensions directory? |
| 497 | UMA_HISTOGRAM_CUSTOM_COUNTS("Extensions.ExtensionRootPathLength", |
| 498 | install_directory_.value().length(), 0, 500, 100); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 501 | const ExtensionList* ExtensionService::extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 502 | return &extensions_; |
| 503 | } |
| 504 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 505 | const ExtensionList* ExtensionService::disabled_extensions() const { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 506 | return &disabled_extensions_; |
| 507 | } |
| 508 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 509 | const ExtensionList* ExtensionService::terminated_extensions() const { |
| 510 | return &terminated_extensions_; |
| 511 | } |
| 512 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 513 | PendingExtensionManager* ExtensionService::pending_extension_manager() { |
| 514 | return &pending_extension_manager_; |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 515 | } |
| 516 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 517 | ExtensionService::~ExtensionService() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 518 | // No need to unload extensions here because they are profile-scoped, and the |
| 519 | // profile is in the process of being deleted. |
[email protected] | 94b4ffc | 2011-02-04 05:55:17 | [diff] [blame] | 520 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 521 | ProviderCollection::const_iterator i; |
| 522 | for (i = external_extension_providers_.begin(); |
| 523 | i != external_extension_providers_.end(); ++i) { |
| 524 | ExternalExtensionProviderInterface* provider = i->get(); |
| 525 | provider->ServiceShutdown(); |
| 526 | } |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 527 | |
| 528 | #if defined(OS_CHROMEOS) |
| 529 | if (event_routers_initialized_) { |
| 530 | ExtensionFileBrowserEventRouter::GetInstance()-> |
| 531 | StopObservingFileSystemEvents(); |
| 532 | } |
| 533 | #endif |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 534 | } |
| 535 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 536 | void ExtensionService::InitEventRouters() { |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 537 | if (event_routers_initialized_) |
| 538 | return; |
| 539 | |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 540 | ExtensionHistoryEventRouter::GetInstance()->ObserveProfile(profile_); |
| 541 | ExtensionAccessibilityEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | 97d2f1d | 2011-01-15 00:41:08 | [diff] [blame] | 542 | browser_event_router_.reset(new ExtensionBrowserEventRouter(profile_)); |
| 543 | browser_event_router_->Init(); |
[email protected] | 118de789 | 2011-03-16 13:31:40 | [diff] [blame] | 544 | preference_event_router_.reset(new ExtensionPreferenceEventRouter(profile_)); |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 545 | ExtensionBookmarkEventRouter::GetInstance()->Observe( |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 546 | profile_->GetBookmarkModel()); |
[email protected] | 2c5e1e1 | 2010-06-10 13:14:44 | [diff] [blame] | 547 | ExtensionCookiesEventRouter::GetInstance()->Init(); |
[email protected] | 7596ce7 | 2010-08-30 05:10:46 | [diff] [blame] | 548 | ExtensionManagementEventRouter::GetInstance()->Init(); |
[email protected] | 8a661f8 | 2010-10-19 21:47:11 | [diff] [blame] | 549 | ExtensionProcessesEventRouter::GetInstance()->ObserveProfile(profile_); |
[email protected] | 784688a6 | 2010-09-13 07:06:52 | [diff] [blame] | 550 | ExtensionWebNavigationEventRouter::GetInstance()->Init(); |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame^] | 551 | |
[email protected] | eed367e | 2011-04-12 03:43:31 | [diff] [blame] | 552 | #if defined(OS_CHROMEOS) |
| 553 | ExtensionFileBrowserEventRouter::GetInstance()->ObserveFileSystemEvents( |
| 554 | profile_); |
| 555 | #endif |
[email protected] | 27072cad | 2011-05-09 19:46:40 | [diff] [blame^] | 556 | |
| 557 | #if defined(OS_CHROMEOS) && defined(TOUCH_UI) |
| 558 | ExtensionInputUiEventRouter::GetInstance()->Init(); |
| 559 | #endif |
| 560 | |
[email protected] | b3d62312b1 | 2010-10-14 21:10:18 | [diff] [blame] | 561 | event_routers_initialized_ = true; |
[email protected] | c5ae74ab | 2010-04-15 18:14:37 | [diff] [blame] | 562 | } |
| 563 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 564 | const Extension* ExtensionService::GetExtensionById( |
| 565 | const std::string& id, bool include_disabled) const { |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 566 | return GetExtensionByIdInternal(id, true, include_disabled, false); |
[email protected] | 78994ab0 | 2010-12-08 18:06:44 | [diff] [blame] | 567 | } |
| 568 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 569 | void ExtensionService::Init() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 570 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 571 | |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 572 | DCHECK(!ready_); // Can't redo init. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 573 | DCHECK_EQ(extensions_.size(), 0u); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 574 | |
[email protected] | 95dd38f | 2009-10-20 20:09:15 | [diff] [blame] | 575 | // Hack: we need to ensure the ResourceDispatcherHost is ready before we load |
| 576 | // the first extension, because its members listen for loaded notifications. |
| 577 | g_browser_process->resource_dispatcher_host(); |
| 578 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 579 | LoadAllExtensions(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 580 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 581 | // TODO(erikkay) this should probably be deferred to a future point |
| 582 | // rather than running immediately at startup. |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 583 | CheckForExternalUpdates(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 584 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 585 | // TODO(erikkay) this should probably be deferred as well. |
| 586 | GarbageCollectExtensions(); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 587 | } |
| 588 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 589 | void ExtensionService::UpdateExtension(const std::string& id, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 590 | const FilePath& extension_path, |
| 591 | const GURL& download_url) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 592 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 593 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 594 | PendingExtensionInfo pending_extension_info; |
| 595 | bool is_pending_extension = pending_extension_manager_.GetById( |
| 596 | id, &pending_extension_info); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 597 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 598 | const Extension* extension = |
| 599 | GetExtensionByIdInternal(id, true, true, false); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 600 | if (!is_pending_extension && !extension) { |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 601 | LOG(WARNING) << "Will not update extension " << id |
| 602 | << " because it is not installed or pending"; |
| 603 | // Delete extension_path since we're not creating a CrxInstaller |
| 604 | // that would do it for us. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 605 | if (!BrowserThread::PostTask( |
| 606 | BrowserThread::FILE, FROM_HERE, |
| 607 | NewRunnableFunction( |
| 608 | extension_file_util::DeleteFile, extension_path, false))) |
| 609 | NOTREACHED(); |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 610 | return; |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 613 | // We want a silent install only for non-pending extensions and |
| 614 | // pending extensions that have install_silently set. |
| 615 | ExtensionInstallUI* client = |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 616 | (!is_pending_extension || pending_extension_info.install_silently()) ? |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 617 | NULL : new ExtensionInstallUI(profile_); |
| 618 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 619 | scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(client)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 620 | installer->set_expected_id(id); |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 621 | if (is_pending_extension) |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 622 | installer->set_install_source(pending_extension_info.install_source()); |
[email protected] | 5eb375e9 | 2010-11-26 07:50:41 | [diff] [blame] | 623 | else if (extension) |
| 624 | installer->set_install_source(extension->location()); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 625 | installer->set_delete_source(true); |
[email protected] | 5c851620 | 2010-03-18 21:43:34 | [diff] [blame] | 626 | installer->set_original_url(download_url); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 627 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_UPDATE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 628 | installer->InstallCrx(extension_path); |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 631 | void ExtensionService::ReloadExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 632 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 633 | FilePath path; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 634 | const Extension* current_extension = GetExtensionById(extension_id, false); |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 635 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 636 | // 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] | 637 | if (current_extension) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 638 | // If the extension has an inspector open for its background page, detach |
| 639 | // the inspector and hang onto a cookie for it, so that we can reattach |
| 640 | // later. |
| 641 | ExtensionProcessManager* manager = profile_->GetExtensionProcessManager(); |
| 642 | ExtensionHost* host = manager->GetBackgroundHostForExtension( |
| 643 | current_extension); |
| 644 | if (host) { |
| 645 | // Look for an open inspector for the background page. |
| 646 | int devtools_cookie = DevToolsManager::GetInstance()->DetachClientHost( |
| 647 | host->render_view_host()); |
| 648 | if (devtools_cookie >= 0) |
| 649 | orphaned_dev_tools_[extension_id] = devtools_cookie; |
| 650 | } |
| 651 | |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 652 | path = current_extension->path(); |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 653 | DisableExtension(extension_id); |
| 654 | disabled_extension_paths_[extension_id] = path; |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 655 | } else { |
| 656 | path = unloaded_extension_paths_[extension_id]; |
[email protected] | b65272f | 2009-08-31 15:47:06 | [diff] [blame] | 657 | } |
| 658 | |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 659 | // Check the installed extensions to see if what we're reloading was already |
| 660 | // installed. |
| 661 | scoped_ptr<ExtensionInfo> installed_extension( |
| 662 | extension_prefs_->GetInstalledExtensionInfo(extension_id)); |
| 663 | if (installed_extension.get() && |
| 664 | installed_extension->extension_manifest.get()) { |
| 665 | LoadInstalledExtension(*installed_extension, false); |
| 666 | } else { |
| 667 | // We should always be able to remember the extension's path. If it's not in |
| 668 | // the map, someone failed to update |unloaded_extension_paths_|. |
| 669 | CHECK(!path.empty()); |
| 670 | LoadExtension(path); |
| 671 | } |
[email protected] | 9cddd470 | 2009-07-27 22:09:40 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 674 | bool ExtensionService::UninstallExtension( |
| 675 | const std::string& extension_id_unsafe, |
| 676 | bool external_uninstall, |
| 677 | std::string* error) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 678 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 679 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 680 | // Copy the extension identifier since the reference might have been |
| 681 | // obtained via Extension::id() and the extension may be deleted in |
| 682 | // this function. |
| 683 | std::string extension_id(extension_id_unsafe); |
| 684 | |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 685 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 686 | |
[email protected] | e7afe245 | 2010-08-22 16:19:13 | [diff] [blame] | 687 | // Callers should not send us nonexistent extensions. |
[email protected] | aebe23a3 | 2010-12-10 22:15:48 | [diff] [blame] | 688 | CHECK(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 689 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 690 | // Get hold of information we need after unloading, since the extension |
| 691 | // pointer will be invalid then. |
| 692 | GURL extension_url(extension->url()); |
| 693 | Extension::Location location(extension->location()); |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 694 | |
| 695 | // Policy change which triggers an uninstall will always set |
| 696 | // |external_uninstall| to true so this is the only way to uninstall |
| 697 | // managed extensions. |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 698 | if (!Extension::UserMayDisable(location) && !external_uninstall) { |
| 699 | NotificationService::current()->Notify( |
| 700 | NotificationType::EXTENSION_UNINSTALL_NOT_ALLOWED, |
| 701 | Source<Profile>(profile_), |
| 702 | Details<const Extension>(extension)); |
| 703 | if (error != NULL) { |
| 704 | *error = errors::kCannotUninstallManagedExtension; |
| 705 | } |
| 706 | return false; |
| 707 | } |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 708 | |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 709 | UninstalledExtensionInfo uninstalled_extension_info(*extension); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 710 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 711 | UMA_HISTOGRAM_ENUMERATION("Extensions.UninstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 712 | extension->GetType(), 100); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 713 | RecordPermissionMessagesHistogram( |
| 714 | extension, "Extensions.Permissions_Uninstall"); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 715 | |
[email protected] | 56ad379 | 2010-05-28 17:45:33 | [diff] [blame] | 716 | if (profile_->GetTemplateURLModel()) |
| 717 | profile_->GetTemplateURLModel()->UnregisterExtensionKeyword(extension); |
| 718 | |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 719 | // Unload before doing more cleanup to ensure that nothing is hanging on to |
| 720 | // any of these resources. |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 721 | UnloadExtension(extension_id, UnloadedExtensionInfo::UNINSTALL); |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 722 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 723 | extension_prefs_->OnExtensionUninstalled(extension_id, location, |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 724 | external_uninstall); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 725 | |
| 726 | // Tell the backend to start deleting installed extensions on the file thread. |
[email protected] | 831aa21 | 2010-03-26 13:55:19 | [diff] [blame] | 727 | if (Extension::LOAD != location) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 728 | if (!BrowserThread::PostTask( |
| 729 | BrowserThread::FILE, FROM_HERE, |
| 730 | NewRunnableFunction( |
| 731 | &extension_file_util::UninstallExtension, |
| 732 | install_directory_, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 733 | extension_id))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 734 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 735 | } |
| 736 | |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 737 | ClearExtensionData(extension_url); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 738 | UntrackTerminatedExtension(extension_id); |
[email protected] | 21103034 | 2010-09-30 18:41:06 | [diff] [blame] | 739 | |
| 740 | // Notify interested parties that we've uninstalled this extension. |
| 741 | NotificationService::current()->Notify( |
| 742 | NotificationType::EXTENSION_UNINSTALLED, |
| 743 | Source<Profile>(profile_), |
| 744 | Details<UninstalledExtensionInfo>(&uninstalled_extension_info)); |
[email protected] | d6ebc979 | 2011-04-07 18:18:33 | [diff] [blame] | 745 | |
| 746 | return true; |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 747 | } |
| 748 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 749 | void ExtensionService::ClearExtensionData(const GURL& extension_url) { |
[email protected] | c10da4b0 | 2010-03-25 14:38:32 | [diff] [blame] | 750 | scoped_refptr<ExtensionDataDeleter> deleter( |
| 751 | new ExtensionDataDeleter(profile_, extension_url)); |
| 752 | deleter->StartDeleting(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 753 | } |
| 754 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 755 | bool ExtensionService::IsExtensionEnabled( |
| 756 | const std::string& extension_id) const { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 757 | return |
| 758 | extension_prefs_->GetExtensionState(extension_id) == Extension::ENABLED; |
| 759 | } |
| 760 | |
| 761 | bool ExtensionService::IsExternalExtensionUninstalled( |
| 762 | const std::string& extension_id) const { |
| 763 | return extension_prefs_->IsExternalExtensionUninstalled(extension_id); |
| 764 | } |
| 765 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 766 | void ExtensionService::EnableExtension(const std::string& extension_id) { |
[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] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 769 | if (IsExtensionEnabled(extension_id)) |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 770 | return; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 771 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 772 | extension_prefs_->SetExtensionState(extension_id, Extension::ENABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 773 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 774 | const Extension* extension = |
| 775 | GetExtensionByIdInternal(extension_id, false, true, false); |
| 776 | // This can happen if sync enables an extension that is not |
| 777 | // installed yet. |
| 778 | if (!extension) |
| 779 | return; |
| 780 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 781 | // Move it over to the enabled list. |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 782 | extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 783 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 784 | disabled_extensions_.end(), |
| 785 | extension); |
| 786 | disabled_extensions_.erase(iter); |
| 787 | |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 788 | // Make sure any browser action contained within it is not hidden. |
| 789 | extension_prefs_->SetBrowserActionVisibility(extension, true); |
| 790 | |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 791 | NotifyExtensionLoaded(extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 792 | } |
| 793 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 794 | void ExtensionService::DisableExtension(const std::string& extension_id) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 795 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 796 | |
[email protected] | b2ba996 | 2009-12-10 20:10:15 | [diff] [blame] | 797 | // The extension may have been disabled already. |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 798 | if (!IsExtensionEnabled(extension_id)) |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 799 | return; |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 800 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 801 | const Extension* extension = GetInstalledExtension(extension_id); |
| 802 | // |extension| can be NULL if sync disables an extension that is not |
| 803 | // installed yet. |
| 804 | if (extension && !Extension::UserMayDisable(extension->location())) |
[email protected] | 95da88c4 | 2011-03-31 10:07:33 | [diff] [blame] | 805 | return; |
| 806 | |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 807 | extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 808 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 809 | extension = GetExtensionByIdInternal(extension_id, true, false, true); |
| 810 | if (!extension) |
| 811 | return; |
| 812 | |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 813 | // Move it over to the disabled list. |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 814 | disabled_extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 815 | ExtensionList::iterator iter = std::find(extensions_.begin(), |
| 816 | extensions_.end(), |
| 817 | extension); |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 818 | if (iter != extensions_.end()) { |
| 819 | extensions_.erase(iter); |
| 820 | } else { |
| 821 | iter = std::find(terminated_extensions_.begin(), |
| 822 | terminated_extensions_.end(), |
| 823 | extension); |
| 824 | terminated_extensions_.erase(iter); |
| 825 | } |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 826 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 827 | NotifyExtensionUnloaded(extension, UnloadedExtensionInfo::DISABLE); |
[email protected] | 1784e83a | 2009-09-08 21:01:52 | [diff] [blame] | 828 | } |
| 829 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 830 | void ExtensionService::GrantPermissions(const Extension* extension) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 831 | CHECK(extension); |
| 832 | |
| 833 | // We only maintain the granted permissions prefs for INTERNAL extensions. |
[email protected] | 139e573 | 2011-03-16 19:29:51 | [diff] [blame] | 834 | CHECK_EQ(Extension::INTERNAL, extension->location()); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 835 | |
| 836 | ExtensionExtent effective_hosts = extension->GetEffectiveHostPermissions(); |
| 837 | extension_prefs_->AddGrantedPermissions(extension->id(), |
| 838 | extension->HasFullPermissions(), |
| 839 | extension->api_permissions(), |
| 840 | effective_hosts); |
| 841 | } |
| 842 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 843 | void ExtensionService::GrantPermissionsAndEnableExtension( |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 844 | const Extension* extension) { |
| 845 | CHECK(extension); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 846 | RecordPermissionMessagesHistogram( |
| 847 | extension, "Extensions.Permissions_ReEnable"); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 848 | GrantPermissions(extension); |
| 849 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, false); |
| 850 | EnableExtension(extension->id()); |
| 851 | } |
| 852 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 853 | void ExtensionService::LoadExtension(const FilePath& extension_path) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 854 | if (!BrowserThread::PostTask( |
| 855 | BrowserThread::FILE, FROM_HERE, |
| 856 | NewRunnableMethod( |
| 857 | backend_.get(), |
| 858 | &ExtensionServiceBackend::LoadSingleExtension, |
| 859 | extension_path))) |
| 860 | NOTREACHED(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 861 | } |
| 862 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 863 | void ExtensionService::LoadComponentExtensions() { |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 864 | for (RegisteredComponentExtensions::iterator it = |
| 865 | component_extension_manifests_.begin(); |
| 866 | it != component_extension_manifests_.end(); ++it) { |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 867 | LoadComponentExtension(*it); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 871 | const Extension* ExtensionService::LoadComponentExtension( |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 872 | const ComponentExtensionInfo &info) { |
| 873 | JSONStringValueSerializer serializer(info.manifest); |
| 874 | scoped_ptr<Value> manifest(serializer.Deserialize(NULL, NULL)); |
| 875 | if (!manifest.get()) { |
| 876 | DLOG(ERROR) << "Failed to parse manifest for extension"; |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 877 | return NULL; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 878 | } |
| 879 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 880 | int flags = Extension::REQUIRE_KEY; |
| 881 | if (Extension::ShouldDoStrictErrorChecking(Extension::COMPONENT)) |
| 882 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 883 | std::string error; |
| 884 | scoped_refptr<const Extension> extension(Extension::Create( |
| 885 | info.root_directory, |
| 886 | Extension::COMPONENT, |
| 887 | *static_cast<DictionaryValue*>(manifest.get()), |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 888 | flags, |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 889 | &error)); |
| 890 | if (!extension.get()) { |
| 891 | NOTREACHED() << error; |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 892 | return NULL; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 893 | } |
| 894 | AddExtension(extension); |
[email protected] | a964e11 | 2011-04-14 21:52:51 | [diff] [blame] | 895 | return extension; |
[email protected] | 61b55b6 | 2011-03-24 09:03:10 | [diff] [blame] | 896 | } |
| 897 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 898 | void ExtensionService::LoadAllExtensions() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 899 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 900 | |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 901 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 902 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 903 | // Load any component extensions. |
| 904 | LoadComponentExtensions(); |
| 905 | |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 906 | // Load the previously installed extensions. |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 907 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
[email protected] | e6090e4 | 2010-03-23 22:44:08 | [diff] [blame] | 908 | extension_prefs_->GetInstalledExtensionsInfo()); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 909 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 910 | std::vector<int> reload_reason_counts(NUM_MANIFEST_RELOAD_REASONS, 0); |
| 911 | bool should_write_prefs = false; |
| 912 | |
| 913 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 914 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 915 | |
| 916 | ManifestReloadReason reload_reason = ShouldReloadExtensionManifest(*info); |
| 917 | ++reload_reason_counts[reload_reason]; |
| 918 | UMA_HISTOGRAM_ENUMERATION("Extensions.ManifestReloadEnumValue", |
| 919 | reload_reason, 100); |
| 920 | |
| 921 | if (reload_reason != NOT_NEEDED) { |
| 922 | // Reloading and extension reads files from disk. We do this on the |
| 923 | // UI thread because reloads should be very rare, and the complexity |
| 924 | // added by delaying the time when the extensions service knows about |
| 925 | // all extensions is significant. See crbug.com/37548 for details. |
| 926 | // |allow_io| disables tests that file operations run on the file |
| 927 | // thread. |
| 928 | base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 929 | |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 930 | int flags = Extension::NO_FLAGS; |
| 931 | if (Extension::ShouldDoStrictErrorChecking(info->extension_location)) |
| 932 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 933 | if (extension_prefs_->AllowFileAccess(info->extension_id)) |
| 934 | flags |= Extension::ALLOW_FILE_ACCESS; |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 935 | std::string error; |
| 936 | scoped_refptr<const Extension> extension( |
| 937 | extension_file_util::LoadExtension( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 938 | info->extension_path, |
| 939 | info->extension_location, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 940 | flags, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 941 | &error)); |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 942 | |
| 943 | if (extension.get()) { |
| 944 | extensions_info->at(i)->extension_manifest.reset( |
| 945 | static_cast<DictionaryValue*>( |
| 946 | extension->manifest_value()->DeepCopy())); |
| 947 | should_write_prefs = true; |
| 948 | } |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 952 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 953 | LoadInstalledExtension(*extensions_info->at(i), should_write_prefs); |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 956 | OnLoadedInstalledExtensions(); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 957 | |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 958 | // The histograms Extensions.ManifestReload* allow us to validate |
| 959 | // the assumption that reloading manifest is a rare event. |
| 960 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNotNeeded", |
| 961 | reload_reason_counts[NOT_NEEDED]); |
| 962 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadUnpackedDir", |
| 963 | reload_reason_counts[UNPACKED_DIR]); |
| 964 | UMA_HISTOGRAM_COUNTS_100("Extensions.ManifestReloadNeedsRelocalization", |
| 965 | reload_reason_counts[NEEDS_RELOCALIZATION]); |
| 966 | |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 967 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadAll", extensions_.size()); |
| 968 | UMA_HISTOGRAM_COUNTS_100("Extensions.Disabled", disabled_extensions_.size()); |
| 969 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 970 | UMA_HISTOGRAM_TIMES("Extensions.LoadAllTime", |
| 971 | base::TimeTicks::Now() - start_time); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 972 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 973 | int app_count = 0; |
| 974 | int hosted_app_count = 0; |
| 975 | int packaged_app_count = 0; |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 976 | int user_script_count = 0; |
| 977 | int extension_count = 0; |
| 978 | int theme_count = 0; |
| 979 | int external_count = 0; |
| 980 | int page_action_count = 0; |
| 981 | int browser_action_count = 0; |
| 982 | ExtensionList::iterator ex; |
| 983 | for (ex = extensions_.begin(); ex != extensions_.end(); ++ex) { |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 984 | Extension::Location location = (*ex)->location(); |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 985 | Extension::Type type = (*ex)->GetType(); |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 986 | if ((*ex)->is_app()) { |
| 987 | UMA_HISTOGRAM_ENUMERATION("Extensions.AppLocation", |
| 988 | location, 100); |
| 989 | } else if (type == Extension::TYPE_EXTENSION) { |
| 990 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionLocation", |
| 991 | location, 100); |
| 992 | } |
| 993 | |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 994 | // Don't count component extensions, since they are only extensions as an |
| 995 | // implementation detail. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 996 | if (location == Extension::COMPONENT) |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 997 | continue; |
| 998 | |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 999 | // Don't count unpacked extensions, since they're a developer-specific |
| 1000 | // feature. |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1001 | if (location == Extension::LOAD) |
[email protected] | e8c729a | 2010-03-09 19:55:19 | [diff] [blame] | 1002 | continue; |
| 1003 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1004 | // Using an enumeration shows us the total installed ratio across all users. |
| 1005 | // Using the totals per user at each startup tells us the distribution of |
| 1006 | // usage for each user (e.g. 40% of users have at least one app installed). |
| 1007 | UMA_HISTOGRAM_ENUMERATION("Extensions.LoadType", type, 100); |
| 1008 | switch (type) { |
| 1009 | case Extension::TYPE_THEME: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1010 | ++theme_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1011 | break; |
| 1012 | case Extension::TYPE_USER_SCRIPT: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1013 | ++user_script_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1014 | break; |
| 1015 | case Extension::TYPE_HOSTED_APP: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1016 | ++app_count; |
| 1017 | ++hosted_app_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1018 | break; |
| 1019 | case Extension::TYPE_PACKAGED_APP: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1020 | ++app_count; |
| 1021 | ++packaged_app_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1022 | break; |
| 1023 | case Extension::TYPE_EXTENSION: |
| 1024 | default: |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1025 | ++extension_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1026 | break; |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1027 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1028 | if (Extension::IsExternalLocation(location)) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1029 | ++external_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1030 | if ((*ex)->page_action() != NULL) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1031 | ++page_action_count; |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1032 | if ((*ex)->browser_action() != NULL) |
[email protected] | a315ba9 | 2010-11-16 14:12:21 | [diff] [blame] | 1033 | ++browser_action_count; |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1034 | |
| 1035 | RecordPermissionMessagesHistogram( |
| 1036 | ex->get(), "Extensions.Permissions_Load"); |
[email protected] | cc2c343 | 2009-11-06 17:24:36 | [diff] [blame] | 1037 | } |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1038 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadApp", app_count); |
| 1039 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadHostedApp", hosted_app_count); |
| 1040 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPackagedApp", packaged_app_count); |
[email protected] | 1952c7d | 2010-03-04 23:48:34 | [diff] [blame] | 1041 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExtension", extension_count); |
| 1042 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadUserScript", user_script_count); |
| 1043 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadTheme", theme_count); |
| 1044 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadExternal", external_count); |
| 1045 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadPageAction", page_action_count); |
| 1046 | UMA_HISTOGRAM_COUNTS_100("Extensions.LoadBrowserAction", |
| 1047 | browser_action_count); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1048 | } |
| 1049 | |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1050 | // static |
| 1051 | void ExtensionService::RecordPermissionMessagesHistogram( |
| 1052 | const Extension* e, const char* histogram) { |
| 1053 | // Since this is called from multiple sources, and since the Histogram macros |
| 1054 | // use statics, we need to manually lookup the Histogram ourselves. |
| 1055 | base::Histogram* counter = base::LinearHistogram::FactoryGet( |
| 1056 | histogram, |
| 1057 | 1, |
| 1058 | Extension::PermissionMessage::ID_ENUM_BOUNDARY, |
| 1059 | Extension::PermissionMessage::ID_ENUM_BOUNDARY + 1, |
| 1060 | base::Histogram::kUmaTargetedHistogramFlag); |
| 1061 | |
| 1062 | std::vector<Extension::PermissionMessage> permissions = |
| 1063 | e->GetPermissionMessages(); |
| 1064 | if (permissions.empty()) { |
| 1065 | counter->Add(Extension::PermissionMessage::ID_NONE); |
| 1066 | } else { |
| 1067 | std::vector<Extension::PermissionMessage>::iterator it; |
| 1068 | for (it = permissions.begin(); it != permissions.end(); ++it) |
| 1069 | counter->Add(it->message_id()); |
| 1070 | } |
| 1071 | } |
| 1072 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1073 | void ExtensionService::LoadInstalledExtension(const ExtensionInfo& info, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1074 | bool write_to_prefs) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1075 | std::string error; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1076 | scoped_refptr<const Extension> extension(NULL); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 1077 | if (!extension_prefs_->IsExtensionAllowedByPolicy(info.extension_id)) { |
| 1078 | error = errors::kDisabledByPolicy; |
| 1079 | } else if (info.extension_manifest.get()) { |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1080 | int flags = Extension::NO_FLAGS; |
| 1081 | if (info.extension_location != Extension::LOAD) |
| 1082 | flags |= Extension::REQUIRE_KEY; |
| 1083 | if (Extension::ShouldDoStrictErrorChecking(info.extension_location)) |
| 1084 | flags |= Extension::STRICT_ERROR_CHECKS; |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1085 | if (extension_prefs_->AllowFileAccess(info.extension_id)) |
| 1086 | flags |= Extension::ALLOW_FILE_ACCESS; |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 1087 | extension = Extension::Create( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1088 | info.extension_path, |
| 1089 | info.extension_location, |
| 1090 | *info.extension_manifest, |
[email protected] | 83048a2 | 2011-03-29 00:14:13 | [diff] [blame] | 1091 | flags, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 1092 | &error); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1093 | } else { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1094 | error = errors::kManifestUnreadable; |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (!extension) { |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1098 | ReportExtensionLoadError(info.extension_path, |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 1099 | error, |
| 1100 | NotificationType::EXTENSION_INSTALL_ERROR, |
| 1101 | false); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1102 | return; |
| 1103 | } |
| 1104 | |
[email protected] | c6d474f8 | 2009-12-16 21:11:06 | [diff] [blame] | 1105 | if (write_to_prefs) |
| 1106 | extension_prefs_->UpdateManifest(extension); |
| 1107 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 1108 | AddExtension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1109 | } |
| 1110 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1111 | void ExtensionService::NotifyExtensionLoaded(const Extension* extension) { |
[email protected] | 57a777f7 | 2010-03-31 01:09:42 | [diff] [blame] | 1112 | // The ChromeURLRequestContexts need to be first to know that the extension |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1113 | // was loaded, otherwise a race can arise where a renderer that is created |
| 1114 | // 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] | 1115 | // that the request context doesn't yet know about. The profile is responsible |
| 1116 | // for ensuring its URLRequestContexts appropriately discover the loaded |
| 1117 | // extension. |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1118 | profile_->RegisterExtensionWithRequestContexts(extension); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1119 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1120 | // Tell subsystems that use the EXTENSION_LOADED notification about the new |
| 1121 | // extension. |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1122 | NotificationService::current()->Notify( |
| 1123 | NotificationType::EXTENSION_LOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1124 | Source<Profile>(profile_), |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1125 | Details<const Extension>(extension)); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1126 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1127 | // Tell renderers about the new extension. |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1128 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1129 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1130 | RenderProcessHost* host = i.GetCurrentValue(); |
| 1131 | if (host->profile()->GetOriginalProfile() == |
| 1132 | profile_->GetOriginalProfile()) { |
| 1133 | host->Send( |
| 1134 | new ExtensionMsg_Loaded(ExtensionMsg_Loaded_Params(extension))); |
| 1135 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1136 | } |
| 1137 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1138 | // Tell a random-ass collection of other subsystems about the new extension. |
| 1139 | // TODO(aa): What should we do with all this goop? Can it move into the |
| 1140 | // relevant objects via EXTENSION_LOADED? |
| 1141 | |
| 1142 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1143 | GrantRightsForExtension(extension); |
| 1144 | |
| 1145 | UpdateActiveExtensionsInCrashReporter(); |
| 1146 | |
| 1147 | ExtensionWebUI::RegisterChromeURLOverrides( |
| 1148 | profile_, extension->GetChromeURLOverrides()); |
| 1149 | |
| 1150 | if (profile_->GetTemplateURLModel()) |
| 1151 | profile_->GetTemplateURLModel()->RegisterExtensionKeyword(extension); |
| 1152 | |
| 1153 | // Load the icon for omnibox-enabled extensions so it will be ready to display |
| 1154 | // in the URL bar. |
| 1155 | if (!extension->omnibox_keyword().empty()) { |
| 1156 | omnibox_popup_icon_manager_.LoadIcon(extension); |
| 1157 | omnibox_icon_manager_.LoadIcon(extension); |
| 1158 | } |
| 1159 | |
| 1160 | // If the extension has permission to load chrome://favicon/ resources we need |
| 1161 | // to make sure that the FaviconSource is registered with the |
| 1162 | // ChromeURLDataManager. |
| 1163 | if (extension->HasHostPermission(GURL(chrome::kChromeUIFaviconURL))) { |
| 1164 | FaviconSource* favicon_source = new FaviconSource(profile_, |
| 1165 | FaviconSource::FAVICON); |
| 1166 | profile_->GetChromeURLDataManager()->AddDataSource(favicon_source); |
| 1167 | } |
| 1168 | |
| 1169 | // TODO(mpcomplete): This ends up affecting all profiles. See crbug.com/80757. |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1170 | bool plugins_changed = false; |
| 1171 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1172 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
| 1173 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 1174 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path); |
| 1175 | plugins_changed = true; |
| 1176 | if (!plugin.is_public) { |
| 1177 | PluginService::GetInstance()->RestrictPluginToUrl( |
| 1178 | plugin.path, extension->url()); |
| 1179 | } |
| 1180 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1181 | |
| 1182 | bool nacl_modules_changed = false; |
| 1183 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1184 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1185 | RegisterNaClModule(module.url, module.mime_type); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1186 | nacl_modules_changed = true; |
| 1187 | } |
| 1188 | |
| 1189 | if (nacl_modules_changed) |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1190 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1191 | |
| 1192 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1193 | PluginService::GetInstance()->PurgePluginListCache(false); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1194 | } |
| 1195 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1196 | void ExtensionService::NotifyExtensionUnloaded( |
| 1197 | const Extension* extension, UnloadedExtensionInfo::Reason reason) { |
| 1198 | UnloadedExtensionInfo details(extension, reason); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1199 | NotificationService::current()->Notify( |
| 1200 | NotificationType::EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1201 | Source<Profile>(profile_), |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1202 | Details<UnloadedExtensionInfo>(&details)); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1203 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1204 | for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 1205 | !i.IsAtEnd(); i.Advance()) { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1206 | RenderProcessHost* host = i.GetCurrentValue(); |
| 1207 | if (host->profile()->GetOriginalProfile() == |
| 1208 | profile_->GetOriginalProfile()) { |
| 1209 | host->Send(new ExtensionMsg_Unloaded(extension->id())); |
| 1210 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 1211 | } |
| 1212 | |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1213 | profile_->UnregisterExtensionWithRequestContexts(extension->id(), reason); |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1214 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1215 | RevokeRightsForExtension(extension); |
| 1216 | |
| 1217 | ExtensionWebUI::UnregisterChromeURLOverrides( |
| 1218 | profile_, extension->GetChromeURLOverrides()); |
| 1219 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 1220 | #if defined(OS_CHROMEOS) |
| 1221 | // Revoke external file access to |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1222 | if (profile_->GetFileSystemContext() && |
| 1223 | profile_->GetFileSystemContext()->path_manager() && |
| 1224 | profile_->GetFileSystemContext()->path_manager()->external_provider()) { |
| 1225 | profile_->GetFileSystemContext()->path_manager()->external_provider()-> |
| 1226 | RevokeAccessForExtension(extension->id()); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1227 | } |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1228 | #endif |
| 1229 | |
| 1230 | UpdateActiveExtensionsInCrashReporter(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1231 | |
| 1232 | bool plugins_changed = false; |
| 1233 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
| 1234 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1235 | if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 1236 | NewRunnableFunction(&ForceShutdownPlugin, |
| 1237 | plugin.path))) |
| 1238 | NOTREACHED(); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1239 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 1240 | webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath( |
| 1241 | plugin.path); |
| 1242 | plugins_changed = true; |
| 1243 | if (!plugin.is_public) |
| 1244 | PluginService::GetInstance()->RestrictPluginToUrl(plugin.path, GURL()); |
| 1245 | } |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1246 | |
| 1247 | bool nacl_modules_changed = false; |
| 1248 | for (size_t i = 0; i < extension->nacl_modules().size(); ++i) { |
| 1249 | const Extension::NaClModuleInfo& module = extension->nacl_modules()[i]; |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1250 | UnregisterNaClModule(module.url); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1251 | nacl_modules_changed = true; |
| 1252 | } |
| 1253 | |
| 1254 | if (nacl_modules_changed) |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 1255 | UpdatePluginListWithNaClModules(); |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 1256 | |
| 1257 | if (plugins_changed || nacl_modules_changed) |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 1258 | PluginService::GetInstance()->PurgePluginListCache(false); |
[email protected] | 62d30f4 | 2009-10-01 22:36:06 | [diff] [blame] | 1259 | } |
| 1260 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1261 | void ExtensionService::UpdateExtensionBlacklist( |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1262 | const std::vector<std::string>& blacklist) { |
| 1263 | // Use this set to indicate if an extension in the blacklist has been used. |
| 1264 | std::set<std::string> blacklist_set; |
| 1265 | for (unsigned int i = 0; i < blacklist.size(); ++i) { |
| 1266 | if (Extension::IdIsValid(blacklist[i])) { |
| 1267 | blacklist_set.insert(blacklist[i]); |
| 1268 | } |
| 1269 | } |
| 1270 | extension_prefs_->UpdateBlacklist(blacklist_set); |
| 1271 | std::vector<std::string> to_be_removed; |
| 1272 | // Loop current extensions, unload installed extensions. |
| 1273 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1274 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1275 | const Extension* extension = (*iter); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1276 | if (blacklist_set.find(extension->id()) != blacklist_set.end()) { |
| 1277 | to_be_removed.push_back(extension->id()); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | // UnloadExtension will change the extensions_ list. So, we should |
| 1282 | // call it outside the iterator loop. |
| 1283 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1284 | UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
[email protected] | 0a071a3 | 2011-02-08 00:18:24 | [diff] [blame] | 1288 | Profile* ExtensionService::profile() { |
| 1289 | return profile_; |
| 1290 | } |
| 1291 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1292 | ExtensionPrefs* ExtensionService::extension_prefs() { |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 1293 | return extension_prefs_; |
| 1294 | } |
| 1295 | |
[email protected] | 2859946f | 2011-04-04 18:18:06 | [diff] [blame] | 1296 | ExtensionUpdater* ExtensionService::updater() { |
| 1297 | return updater_.get(); |
| 1298 | } |
| 1299 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1300 | void ExtensionService::CheckAdminBlacklist() { |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1301 | std::vector<std::string> to_be_removed; |
| 1302 | // Loop through extensions list, unload installed extensions. |
| 1303 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1304 | iter != extensions_.end(); ++iter) { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1305 | const Extension* extension = (*iter); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1306 | if (!extension_prefs_->IsExtensionAllowedByPolicy(extension->id())) |
| 1307 | to_be_removed.push_back(extension->id()); |
| 1308 | } |
| 1309 | |
| 1310 | // UnloadExtension will change the extensions_ list. So, we should |
| 1311 | // call it outside the iterator loop. |
| 1312 | for (unsigned int i = 0; i < to_be_removed.size(); ++i) |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1313 | UnloadExtension(to_be_removed[i], UnloadedExtensionInfo::DISABLE); |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 1314 | } |
| 1315 | |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1316 | void ExtensionService::CheckForUpdatesSoon() { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1317 | if (updater()) { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1318 | updater()->CheckSoon(); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1319 | } else { |
[email protected] | 3120660 | 2011-04-13 23:07:32 | [diff] [blame] | 1320 | LOG(WARNING) << "CheckForUpdatesSoon() called with auto-update turned off"; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1324 | ExtensionSyncData ExtensionService::GetSyncDataHelper( |
| 1325 | const Extension& extension) const { |
| 1326 | const std::string& id = extension.id(); |
| 1327 | ExtensionSyncData data; |
| 1328 | data.id = id; |
| 1329 | data.uninstalled = false; |
| 1330 | data.enabled = IsExtensionEnabled(id); |
| 1331 | data.incognito_enabled = IsIncognitoEnabled(id); |
| 1332 | data.version = *extension.version(); |
| 1333 | data.update_url = extension.update_url(); |
| 1334 | data.name = extension.name(); |
| 1335 | return data; |
| 1336 | } |
| 1337 | |
| 1338 | bool ExtensionService::GetSyncData( |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 1339 | const Extension& extension, |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1340 | ExtensionFilter filter, |
| 1341 | ExtensionSyncData* extension_sync_data) const { |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 1342 | if (!(*filter)(extension)) { |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1343 | return false; |
| 1344 | } |
[email protected] | 85fc920 | 2011-05-05 00:04:59 | [diff] [blame] | 1345 | *extension_sync_data = GetSyncDataHelper(extension); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1346 | return true; |
| 1347 | } |
| 1348 | |
| 1349 | void ExtensionService::GetSyncDataListHelper( |
| 1350 | const ExtensionList& extensions, |
| 1351 | ExtensionFilter filter, |
| 1352 | std::vector<ExtensionSyncData>* sync_data_list) const { |
| 1353 | for (ExtensionList::const_iterator it = extensions.begin(); |
| 1354 | it != extensions.end(); ++it) { |
| 1355 | const Extension& extension = **it; |
| 1356 | if ((*filter)(extension)) { |
| 1357 | sync_data_list->push_back(GetSyncDataHelper(extension)); |
| 1358 | } |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | std::vector<ExtensionSyncData> ExtensionService::GetSyncDataList( |
| 1363 | ExtensionFilter filter) const { |
| 1364 | std::vector<ExtensionSyncData> sync_data_list; |
| 1365 | GetSyncDataListHelper(extensions_, filter, &sync_data_list); |
| 1366 | GetSyncDataListHelper(disabled_extensions_, filter, &sync_data_list); |
[email protected] | 45b6fee | 2011-05-03 09:41:31 | [diff] [blame] | 1367 | GetSyncDataListHelper(terminated_extensions_, filter, &sync_data_list); |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1368 | return sync_data_list; |
| 1369 | } |
| 1370 | |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1371 | void ExtensionService::ProcessSyncData( |
| 1372 | const ExtensionSyncData& extension_sync_data, |
[email protected] | b05fb9ff | 2011-04-23 00:07:56 | [diff] [blame] | 1373 | ExtensionFilter filter) { |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1374 | const std::string& id = extension_sync_data.id; |
| 1375 | |
| 1376 | // Handle uninstalls first. |
| 1377 | if (extension_sync_data.uninstalled) { |
| 1378 | std::string error; |
| 1379 | if (!UninstallExtensionHelper(this, id)) { |
| 1380 | LOG(WARNING) << "Could not uninstall extension " << id |
| 1381 | << " for sync"; |
| 1382 | } |
| 1383 | return; |
| 1384 | } |
| 1385 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1386 | // Set user settings. |
| 1387 | if (extension_sync_data.enabled) { |
| 1388 | EnableExtension(id); |
| 1389 | } else { |
| 1390 | DisableExtension(id); |
| 1391 | } |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1392 | SetIsIncognitoEnabled(id, extension_sync_data.incognito_enabled); |
| 1393 | |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1394 | const Extension* extension = GetInstalledExtension(id); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1395 | if (extension) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1396 | // If the extension is already installed, check if it's outdated. |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1397 | int result = extension->version()->CompareTo(extension_sync_data.version); |
| 1398 | if (result < 0) { |
| 1399 | // Extension is outdated. |
| 1400 | CheckForUpdatesSoon(); |
| 1401 | } else if (result > 0) { |
| 1402 | // Sync version is outdated. Do nothing for now, as sync code |
| 1403 | // in other places will eventually update the sync data. |
| 1404 | // |
| 1405 | // TODO(akalin): Move that code here. |
| 1406 | } |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1407 | } else { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1408 | // TODO(akalin): Replace silent update with a list of enabled |
| 1409 | // permissions. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1410 | const bool kInstallSilently = true; |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1411 | if (!pending_extension_manager()->AddFromSync( |
| 1412 | id, |
| 1413 | extension_sync_data.update_url, |
| 1414 | filter, |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1415 | kInstallSilently)) { |
[email protected] | 06f9256 | 2011-04-29 19:27:31 | [diff] [blame] | 1416 | LOG(WARNING) << "Could not add pending extension for " << id; |
| 1417 | return; |
| 1418 | } |
| 1419 | CheckForUpdatesSoon(); |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1420 | } |
[email protected] | 90310d9 | 2011-04-17 07:35:04 | [diff] [blame] | 1421 | } |
| 1422 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1423 | bool ExtensionService::IsIncognitoEnabled( |
| 1424 | const std::string& extension_id) const { |
| 1425 | // If this is an existing component extension we always allow it to |
| 1426 | // work in incognito mode. |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1427 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1428 | if (extension && extension->location() == Extension::COMPONENT) |
[email protected] | cb0ce1e02 | 2010-03-10 19:54:41 | [diff] [blame] | 1429 | return true; |
| 1430 | |
| 1431 | // Check the prefs. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1432 | return extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | db7331a | 2010-02-25 22:10:50 | [diff] [blame] | 1433 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1434 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1435 | void ExtensionService::SetIsIncognitoEnabled( |
| 1436 | const std::string& extension_id, bool enabled) { |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1437 | const Extension* extension = GetInstalledExtension(extension_id); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1438 | if (extension && extension->location() == Extension::COMPONENT) { |
| 1439 | // This shouldn't be called for component extensions. |
| 1440 | NOTREACHED(); |
| 1441 | return; |
| 1442 | } |
| 1443 | |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1444 | // Broadcast unloaded and loaded events to update browser state. Only bother |
| 1445 | // if the value changed and the extension is actually enabled, since there is |
| 1446 | // no UI otherwise. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1447 | bool old_enabled = extension_prefs_->IsIncognitoEnabled(extension_id); |
[email protected] | 8c6c8c2 | 2011-03-09 12:52:34 | [diff] [blame] | 1448 | if (enabled == old_enabled) |
| 1449 | return; |
| 1450 | |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1451 | extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled); |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1452 | |
| 1453 | // If the extension is enabled (and not terminated), unload and |
| 1454 | // reload it to update UI. |
| 1455 | const Extension* enabled_extension = GetExtensionById(extension_id, false); |
| 1456 | if (enabled_extension) { |
| 1457 | NotifyExtensionUnloaded(enabled_extension, UnloadedExtensionInfo::DISABLE); |
| 1458 | NotifyExtensionLoaded(enabled_extension); |
[email protected] | 568f33d | 2010-08-04 17:06:41 | [diff] [blame] | 1459 | } |
[email protected] | 55a3569 | 2010-02-11 23:25:21 | [diff] [blame] | 1460 | } |
| 1461 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1462 | bool ExtensionService::CanCrossIncognito(const Extension* extension) { |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1463 | // We allow the extension to see events and data from another profile iff it |
| 1464 | // uses "spanning" behavior and it has incognito access. "split" mode |
| 1465 | // extensions only see events for a matching profile. |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1466 | return IsIncognitoEnabled(extension->id()) && |
| 1467 | !extension->incognito_split_mode(); |
[email protected] | 2a8f24e | 2010-11-03 21:37:05 | [diff] [blame] | 1468 | } |
| 1469 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1470 | bool ExtensionService::AllowFileAccess(const Extension* extension) { |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1471 | return (CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 334e04a | 2010-06-24 23:34:44 | [diff] [blame] | 1472 | switches::kDisableExtensionsFileAccessCheck) || |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1473 | extension_prefs_->AllowFileAccess(extension->id())); |
| 1474 | } |
| 1475 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1476 | void ExtensionService::SetAllowFileAccess(const Extension* extension, |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1477 | bool allow) { |
| 1478 | // Reload to update browser state. Only bother if the value changed and the |
| 1479 | // extension is actually enabled, since there is no UI otherwise. |
| 1480 | bool old_allow = AllowFileAccess(extension); |
| 1481 | if (allow == old_allow) |
| 1482 | return; |
| 1483 | |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1484 | extension_prefs_->SetAllowFileAccess(extension->id(), allow); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1485 | |
| 1486 | bool extension_is_enabled = std::find(extensions_.begin(), extensions_.end(), |
| 1487 | extension) != extensions_.end(); |
| 1488 | if (extension_is_enabled) |
| 1489 | ReloadExtension(extension->id()); |
[email protected] | 05c8218 | 2010-06-24 17:49:08 | [diff] [blame] | 1490 | } |
| 1491 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1492 | bool ExtensionService::GetBrowserActionVisibility(const Extension* extension) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 1493 | return extension_prefs_->GetBrowserActionVisibility(extension); |
| 1494 | } |
| 1495 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1496 | void ExtensionService::SetBrowserActionVisibility(const Extension* extension, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1497 | bool visible) { |
[email protected] | f681c78 | 2010-11-19 11:19:39 | [diff] [blame] | 1498 | extension_prefs_->SetBrowserActionVisibility(extension, visible); |
| 1499 | } |
| 1500 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1501 | // Some extensions will autoupdate themselves externally from Chrome. These |
| 1502 | // are typically part of some larger client application package. To support |
| 1503 | // these, the extension will register its location in the the preferences file |
| 1504 | // (and also, on Windows, in the registry) and this code will periodically |
| 1505 | // check that location for a .crx file, which it will then install locally if |
| 1506 | // a new version is available. |
| 1507 | // Errors are reported through ExtensionErrorReporter. Succcess is not |
| 1508 | // reported. |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1509 | void ExtensionService::CheckForExternalUpdates() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1510 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1511 | |
| 1512 | // Note that this installation is intentionally silent (since it didn't |
| 1513 | // go through the front-end). Extensions that are registered in this |
| 1514 | // way are effectively considered 'pre-bundled', and so implicitly |
| 1515 | // trusted. In general, if something has HKLM or filesystem access, |
| 1516 | // they could install an extension manually themselves anyway. |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1517 | |
| 1518 | // If any external extension records give a URL, a provider will set |
| 1519 | // this to true. Used by OnExternalProviderReady() to see if we need |
| 1520 | // to start an update check to fetch a new external extension. |
| 1521 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1522 | |
| 1523 | // Ask each external extension provider to give us a call back for each |
| 1524 | // extension they know about. See OnExternalExtension(File|UpdateUrl)Found. |
| 1525 | ProviderCollection::const_iterator i; |
| 1526 | for (i = external_extension_providers_.begin(); |
| 1527 | i != external_extension_providers_.end(); ++i) { |
| 1528 | ExternalExtensionProviderInterface* provider = i->get(); |
| 1529 | provider->VisitRegisteredExtension(); |
| 1530 | } |
| 1531 | |
| 1532 | // Uninstall of unclaimed extensions will happen after all the providers |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1533 | // had reported ready. Every provider calls OnExternalProviderReady() |
| 1534 | // when it finishes, and OnExternalProviderReady() only acts when all |
| 1535 | // providers are ready. In case there are no providers, we call it |
| 1536 | // to trigger removal of extensions that used to have an external source. |
| 1537 | if (external_extension_providers_.empty()) |
| 1538 | OnExternalProviderReady(); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1539 | } |
| 1540 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1541 | void ExtensionService::OnExternalProviderReady() { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1542 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1543 | |
| 1544 | // An external provider has finished loading. We only take action |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1545 | // if all of them are finished. So we check them first. |
| 1546 | ProviderCollection::const_iterator i; |
| 1547 | for (i = external_extension_providers_.begin(); |
| 1548 | i != external_extension_providers_.end(); ++i) { |
| 1549 | ExternalExtensionProviderInterface* provider = i->get(); |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1550 | if (!provider->IsReady()) |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1551 | return; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1552 | } |
| 1553 | |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1554 | // All the providers are ready. Install any pending extensions. |
| 1555 | if (external_extension_url_added_ && updater()) { |
| 1556 | external_extension_url_added_ = false; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 1557 | updater()->CheckNow(); |
| 1558 | } |
| 1559 | |
| 1560 | // Uninstall all the unclaimed extensions. |
| 1561 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( |
| 1562 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1563 | for (size_t i = 0; i < extensions_info->size(); ++i) { |
| 1564 | ExtensionInfo* info = extensions_info->at(i).get(); |
| 1565 | if (Extension::IsExternalLocation(info->extension_location)) |
| 1566 | CheckExternalUninstall(info->extension_id); |
| 1567 | } |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 1568 | } |
| 1569 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1570 | void ExtensionService::UnloadExtension( |
| 1571 | const std::string& extension_id, |
| 1572 | UnloadedExtensionInfo::Reason reason) { |
[email protected] | 27e469a | 2010-01-11 20:35:09 | [diff] [blame] | 1573 | // Make sure the extension gets deleted after we return from this function. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1574 | scoped_refptr<const Extension> extension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1575 | GetExtensionByIdInternal(extension_id, true, true, false)); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1576 | |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1577 | // This method can be called via PostTask, so the extension may have been |
| 1578 | // unloaded by the time this runs. |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1579 | if (!extension) { |
| 1580 | // In case the extension may have crashed/uninstalled. Allow the profile to |
| 1581 | // clean up its RequestContexts. |
| 1582 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | fa0c9673 | 2010-11-17 00:14:23 | [diff] [blame] | 1583 | return; |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1584 | } |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1585 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1586 | // Keep information about the extension so that we can reload it later |
| 1587 | // even if it's not permanently installed. |
| 1588 | unloaded_extension_paths_[extension->id()] = extension->path(); |
| 1589 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1590 | // Clean up if the extension is meant to be enabled after a reload. |
| 1591 | disabled_extension_paths_.erase(extension->id()); |
| 1592 | |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 1593 | // Clean up runtime data. |
| 1594 | extension_runtime_data_.erase(extension_id); |
| 1595 | |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1596 | ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), |
| 1597 | disabled_extensions_.end(), |
| 1598 | extension.get()); |
| 1599 | if (iter != disabled_extensions_.end()) { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1600 | UnloadedExtensionInfo details(extension, reason); |
| 1601 | details.already_disabled = true; |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1602 | disabled_extensions_.erase(iter); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 1603 | NotificationService::current()->Notify( |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1604 | NotificationType::EXTENSION_UNLOADED, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1605 | Source<Profile>(profile_), |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1606 | Details<UnloadedExtensionInfo>(&details)); |
[email protected] | dd163fb0 | 2011-05-04 22:22:17 | [diff] [blame] | 1607 | // Make sure the profile cleans up its RequestContexts when an already |
| 1608 | // disabled extension is unloaded (since they are also tracking the disabled |
| 1609 | // extensions). |
| 1610 | profile_->UnregisterExtensionWithRequestContexts(extension_id, reason); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1611 | return; |
| 1612 | } |
| 1613 | |
| 1614 | iter = std::find(extensions_.begin(), extensions_.end(), extension.get()); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 1615 | |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1616 | // Remove the extension from our list. |
| 1617 | extensions_.erase(iter); |
| 1618 | |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1619 | NotifyExtensionUnloaded(extension.get(), reason); |
[email protected] | 631cf82 | 2009-05-15 07:01:25 | [diff] [blame] | 1620 | } |
| 1621 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1622 | void ExtensionService::UnloadAllExtensions() { |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1623 | profile_->GetExtensionSpecialStoragePolicy()-> |
| 1624 | RevokeRightsForAllExtensions(); |
| 1625 | |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1626 | extensions_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 1627 | disabled_extensions_.clear(); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1628 | terminated_extension_ids_.clear(); |
| 1629 | terminated_extensions_.clear(); |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 1630 | extension_runtime_data_.clear(); |
[email protected] | cd500f7 | 2010-06-25 23:44:32 | [diff] [blame] | 1631 | |
[email protected] | c6e4a341 | 2009-06-24 15:45:29 | [diff] [blame] | 1632 | // TODO(erikkay) should there be a notification for this? We can't use |
| 1633 | // EXTENSION_UNLOADED since that implies that the extension has been disabled |
| 1634 | // or uninstalled, and UnloadAll is just part of shutdown. |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1635 | } |
| 1636 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1637 | void ExtensionService::ReloadExtensions() { |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1638 | UnloadAllExtensions(); |
| 1639 | LoadAllExtensions(); |
| 1640 | } |
| 1641 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1642 | void ExtensionService::GarbageCollectExtensions() { |
[email protected] | 39d9f62c | 2010-12-03 10:48:50 | [diff] [blame] | 1643 | if (extension_prefs_->pref_service()->ReadOnly()) |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 1644 | return; |
| 1645 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 1646 | scoped_ptr<ExtensionPrefs::ExtensionsInfo> info( |
| 1647 | extension_prefs_->GetInstalledExtensionsInfo()); |
| 1648 | |
| 1649 | std::map<std::string, FilePath> extension_paths; |
| 1650 | for (size_t i = 0; i < info->size(); ++i) |
| 1651 | extension_paths[info->at(i)->extension_id] = info->at(i)->extension_path; |
| 1652 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1653 | if (!BrowserThread::PostTask( |
| 1654 | BrowserThread::FILE, FROM_HERE, |
| 1655 | NewRunnableFunction( |
| 1656 | &extension_file_util::GarbageCollectExtensions, |
| 1657 | install_directory_, |
| 1658 | extension_paths))) |
| 1659 | NOTREACHED(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 1660 | |
| 1661 | // Also garbage-collect themes. We check |profile_| to be |
| 1662 | // defensive; in the future, we may call GarbageCollectExtensions() |
| 1663 | // from somewhere other than Init() (e.g., in a timer). |
| 1664 | if (profile_) { |
[email protected] | 1828037 | 2011-03-22 18:05:22 | [diff] [blame] | 1665 | ThemeServiceFactory::GetForProfile(profile_)->RemoveUnusedThemes(); |
[email protected] | f6ccd65 | 2010-11-17 00:48:34 | [diff] [blame] | 1666 | } |
[email protected] | 3cf4f099 | 2009-02-03 23:00:30 | [diff] [blame] | 1667 | } |
| 1668 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1669 | void ExtensionService::OnLoadedInstalledExtensions() { |
[email protected] | 93fd78f4 | 2009-07-10 16:43:17 | [diff] [blame] | 1670 | if (updater_.get()) { |
| 1671 | updater_->Start(); |
| 1672 | } |
[email protected] | fa6a910 | 2010-11-22 15:38:50 | [diff] [blame] | 1673 | |
| 1674 | ready_ = true; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1675 | NotificationService::current()->Notify( |
| 1676 | NotificationType::EXTENSIONS_READY, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 1677 | Source<Profile>(profile_), |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1678 | NotificationService::NoDetails()); |
| 1679 | } |
| 1680 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 1681 | void ExtensionService::AddExtension(const Extension* extension) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 1682 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1683 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1684 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1685 | // TODO(jstritar): We may be able to get rid of this branch by overriding the |
| 1686 | // default extension state to DISABLED when the --disable-extensions flag |
| 1687 | // is set (http://crbug.com/29067). |
| 1688 | if (!extensions_enabled() && |
| 1689 | !extension->is_theme() && |
| 1690 | extension->location() != Extension::COMPONENT && |
| 1691 | !Extension::IsExternalLocation(extension->location())) |
| 1692 | return; |
| 1693 | |
| 1694 | SetBeingUpgraded(extension, false); |
| 1695 | |
[email protected] | 1eb17508 | 2010-02-10 09:26:16 | [diff] [blame] | 1696 | // The extension is now loaded, remove its data from unloaded extension map. |
| 1697 | unloaded_extension_paths_.erase(extension->id()); |
| 1698 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1699 | // If a terminated extension is loaded, remove it from the terminated list. |
| 1700 | UntrackTerminatedExtension(extension->id()); |
| 1701 | |
[email protected] | f17dbd4 | 2010-08-16 23:21:10 | [diff] [blame] | 1702 | // If the extension was disabled for a reload, then enable it. |
| 1703 | if (disabled_extension_paths_.erase(extension->id()) > 0) |
| 1704 | EnableExtension(extension->id()); |
| 1705 | |
[email protected] | d728e00 | 2010-12-08 04:46:23 | [diff] [blame] | 1706 | // Check if the extension's privileges have changed and disable the |
| 1707 | // extension if necessary. |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1708 | DisableIfPrivilegeIncrease(extension); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1709 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1710 | Extension::State state = extension_prefs_->GetExtensionState(extension->id()); |
| 1711 | if (state == Extension::DISABLED) { |
| 1712 | disabled_extensions_.push_back(scoped_extension); |
| 1713 | // TODO(aa): This seems dodgy. It seems that AddExtension() could get called |
| 1714 | // with a disabled extension for other reasons other than that an update was |
| 1715 | // disabled. |
| 1716 | NotificationService::current()->Notify( |
| 1717 | NotificationType::EXTENSION_UPDATE_DISABLED, |
| 1718 | Source<Profile>(profile_), |
| 1719 | Details<const Extension>(extension)); |
| 1720 | return; |
[email protected] | e72e8eb8 | 2009-06-18 17:21:51 | [diff] [blame] | 1721 | } |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1722 | |
[email protected] | c8d407e | 2011-04-28 21:27:17 | [diff] [blame] | 1723 | // It should not be possible to get here with EXTERNAL_EXTENSION_UNINSTALLED |
| 1724 | // because we would not have loaded the extension in that case. |
| 1725 | CHECK(state == Extension::ENABLED); |
| 1726 | extensions_.push_back(scoped_extension); |
| 1727 | NotifyExtensionLoaded(extension); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1728 | } |
| 1729 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1730 | void ExtensionService::DisableIfPrivilegeIncrease(const Extension* extension) { |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1731 | // We keep track of all permissions the user has granted each extension. |
| 1732 | // This allows extensions to gracefully support backwards compatibility |
| 1733 | // by including unknown permissions in their manifests. When the user |
| 1734 | // installs the extension, only the recognized permissions are recorded. |
| 1735 | // When the unknown permissions become recognized (e.g., through browser |
| 1736 | // upgrade), we can prompt the user to accept these new permissions. |
| 1737 | // Extensions can also silently upgrade to less permissions, and then |
| 1738 | // silently upgrade to a version that adds these permissions back. |
| 1739 | // |
| 1740 | // For example, pretend that Chrome 10 includes a permission "omnibox" |
| 1741 | // for an API that adds suggestions to the omnibox. An extension can |
| 1742 | // maintain backwards compatibility while still having "omnibox" in the |
| 1743 | // manifest. If a user installs the extension on Chrome 9, the browser |
| 1744 | // will record the permissions it recognized, not including "omnibox." |
| 1745 | // When upgrading to Chrome 10, "omnibox" will be recognized and Chrome |
| 1746 | // will disable the extension and prompt the user to approve the increase |
| 1747 | // in privileges. The extension could then release a new version that |
| 1748 | // removes the "omnibox" permission. When the user upgrades, Chrome will |
| 1749 | // still remember that "omnibox" had been granted, so that if the |
| 1750 | // extension once again includes "omnibox" in an upgrade, the extension |
| 1751 | // can upgrade without requiring this user's approval. |
| 1752 | const Extension* old = GetExtensionByIdInternal(extension->id(), |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1753 | true, true, false); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1754 | bool granted_full_access; |
| 1755 | std::set<std::string> granted_apis; |
| 1756 | ExtensionExtent granted_extent; |
| 1757 | |
| 1758 | bool is_extension_upgrade = old != NULL; |
| 1759 | bool is_privilege_increase = false; |
| 1760 | |
| 1761 | // We only record the granted permissions for INTERNAL extensions, since |
| 1762 | // they can't silently increase privileges. |
| 1763 | if (extension->location() == Extension::INTERNAL) { |
| 1764 | // Add all the recognized permissions if the granted permissions list |
| 1765 | // hasn't been initialized yet. |
| 1766 | if (!extension_prefs_->GetGrantedPermissions(extension->id(), |
| 1767 | &granted_full_access, |
| 1768 | &granted_apis, |
| 1769 | &granted_extent)) { |
| 1770 | GrantPermissions(extension); |
| 1771 | CHECK(extension_prefs_->GetGrantedPermissions(extension->id(), |
| 1772 | &granted_full_access, |
| 1773 | &granted_apis, |
| 1774 | &granted_extent)); |
| 1775 | } |
| 1776 | |
| 1777 | // Here, we check if an extension's privileges have increased in a manner |
| 1778 | // that requires the user's approval. This could occur because the browser |
| 1779 | // upgraded and recognized additional privileges, or an extension upgrades |
| 1780 | // to a version that requires additional privileges. |
| 1781 | is_privilege_increase = Extension::IsPrivilegeIncrease( |
| 1782 | granted_full_access, granted_apis, granted_extent, extension); |
| 1783 | } |
| 1784 | |
| 1785 | if (is_extension_upgrade) { |
[email protected] | 66e2687 | 2010-12-03 20:07:25 | [diff] [blame] | 1786 | // Other than for unpacked extensions, CrxInstaller should have guaranteed |
| 1787 | // that we aren't downgrading. |
| 1788 | if (extension->location() != Extension::LOAD) |
| 1789 | CHECK(extension->version()->CompareTo(*(old->version())) >= 0); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1790 | |
| 1791 | // Extensions get upgraded if the privileges are allowed to increase or |
| 1792 | // the privileges haven't increased. |
| 1793 | if (!is_privilege_increase) { |
| 1794 | SetBeingUpgraded(old, true); |
| 1795 | SetBeingUpgraded(extension, true); |
| 1796 | } |
| 1797 | |
| 1798 | // To upgrade an extension in place, unload the old one and |
| 1799 | // then load the new one. |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 1800 | UnloadExtension(old->id(), UnloadedExtensionInfo::UPDATE); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1801 | old = NULL; |
| 1802 | } |
| 1803 | |
| 1804 | // Extension has changed permissions significantly. Disable it. A |
| 1805 | // notification should be sent by the caller. |
| 1806 | if (is_privilege_increase) { |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1807 | if (!extension_prefs_->DidExtensionEscalatePermissions(extension->id())) { |
| 1808 | RecordPermissionMessagesHistogram( |
| 1809 | extension, "Extensions.Permissions_AutoDisable"); |
| 1810 | } |
[email protected] | b3317ad | 2011-04-28 23:46:00 | [diff] [blame] | 1811 | extension_prefs_->SetExtensionState(extension->id(), Extension::DISABLED); |
[email protected] | 8d888c1 | 2010-11-30 00:00:25 | [diff] [blame] | 1812 | extension_prefs_->SetDidExtensionEscalatePermissions(extension, true); |
| 1813 | } |
| 1814 | } |
| 1815 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1816 | void ExtensionService::UpdateActiveExtensionsInCrashReporter() { |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 1817 | std::set<std::string> extension_ids; |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1818 | for (size_t i = 0; i < extensions_.size(); ++i) { |
[email protected] | 2a500c1b | 2010-11-05 15:27:34 | [diff] [blame] | 1819 | if (!extensions_[i]->is_theme() && |
| 1820 | extensions_[i]->location() != Extension::COMPONENT) |
[email protected] | c886596 | 2009-12-16 07:47:39 | [diff] [blame] | 1821 | extension_ids.insert(extensions_[i]->id()); |
[email protected] | aab98a5 | 2009-12-02 03:22:35 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | child_process_logging::SetActiveExtensions(extension_ids); |
[email protected] | 6014d67 | 2008-12-05 00:38:25 | [diff] [blame] | 1825 | } |
| 1826 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1827 | void ExtensionService::OnExtensionInstalled(const Extension* extension) { |
[email protected] | a29a517a | 2011-01-21 21:11:12 | [diff] [blame] | 1828 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 1829 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1830 | // Ensure extension is deleted unless we transfer ownership. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1831 | scoped_refptr<const Extension> scoped_extension(extension); |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1832 | const std::string& id = extension->id(); |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1833 | bool initial_enable = IsExtensionEnabled(id); |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 1834 | |
| 1835 | PendingExtensionInfo pending_extension_info; |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1836 | if (pending_extension_manager()->GetById(id, &pending_extension_info)) { |
| 1837 | pending_extension_manager()->Remove(id); |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 1838 | |
[email protected] | 483d1ff | 2011-03-03 17:12:02 | [diff] [blame] | 1839 | if (!pending_extension_info.ShouldAllowInstall(*extension)) { |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1840 | LOG(WARNING) |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 1841 | << "ShouldAllowInstall() returned false for " |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1842 | << id << " of type " << extension->GetType() |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 1843 | << " and update URL " << extension->update_url().spec() |
| 1844 | << "; not installing"; |
[email protected] | ae6cb302 | 2011-04-04 20:11:54 | [diff] [blame] | 1845 | |
| 1846 | NotificationService::current()->Notify( |
| 1847 | NotificationType::EXTENSION_INSTALL_NOT_ALLOWED, |
| 1848 | Source<Profile>(profile_), |
| 1849 | Details<const Extension>(extension)); |
| 1850 | |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1851 | // Delete the extension directory since we're not going to |
| 1852 | // load it. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 1853 | if (!BrowserThread::PostTask( |
| 1854 | BrowserThread::FILE, FROM_HERE, |
| 1855 | NewRunnableFunction(&extension_file_util::DeleteFile, |
| 1856 | extension->path(), true))) |
| 1857 | NOTREACHED(); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1858 | return; |
| 1859 | } |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1860 | } else { |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1861 | // We explicitly want to re-enable an uninstalled external |
| 1862 | // extension; if we're here, that means the user is manually |
| 1863 | // installing the extension. |
[email protected] | 6cc7dbae | 2011-04-29 21:18:33 | [diff] [blame] | 1864 | if (IsExternalExtensionUninstalled(id)) { |
| 1865 | initial_enable = true; |
| 1866 | } |
[email protected] | aa14270 | 2010-03-26 01:26:33 | [diff] [blame] | 1867 | } |
| 1868 | |
[email protected] | 9b21765 | 2010-10-08 22:04:23 | [diff] [blame] | 1869 | UMA_HISTOGRAM_ENUMERATION("Extensions.InstallType", |
[email protected] | 7fa19f8 | 2010-12-21 19:40:08 | [diff] [blame] | 1870 | extension->GetType(), 100); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 1871 | RecordPermissionMessagesHistogram( |
| 1872 | extension, "Extensions.Permissions_Install"); |
[email protected] | eda3c36 | 2010-11-12 08:08:23 | [diff] [blame] | 1873 | ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); |
[email protected] | 4416c5a | 2010-06-26 01:28:57 | [diff] [blame] | 1874 | extension_prefs_->OnExtensionInstalled( |
[email protected] | 81b14cc | 2011-04-29 00:39:37 | [diff] [blame] | 1875 | extension, initial_enable ? Extension::ENABLED : Extension::DISABLED); |
[email protected] | 25b3433 | 2009-06-05 21:53:19 | [diff] [blame] | 1876 | |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1877 | // Unpacked extensions default to allowing file access, but if that has been |
| 1878 | // overridden, don't reset the value. |
| 1879 | if (Extension::ShouldAlwaysAllowFileAccess(Extension::LOAD) && |
[email protected] | c3cfb01 | 2011-04-06 22:07:35 | [diff] [blame] | 1880 | !extension_prefs_->HasAllowFileAccessSetting(id)) { |
| 1881 | extension_prefs_->SetAllowFileAccess(id, true); |
[email protected] | 3aff9ad | 2011-04-01 20:26:48 | [diff] [blame] | 1882 | } |
[email protected] | 92a5b1d | 2010-07-20 00:42:00 | [diff] [blame] | 1883 | |
[email protected] | a3e61e8 | 2011-04-15 20:32:08 | [diff] [blame] | 1884 | NotificationService::current()->Notify( |
| 1885 | NotificationType::EXTENSION_INSTALLED, |
| 1886 | Source<Profile>(profile_), |
| 1887 | Details<const Extension>(extension)); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 1888 | |
[email protected] | 49cd157 | 2011-02-08 21:38:45 | [diff] [blame] | 1889 | // Transfer ownership of |extension| to AddExtension. |
| 1890 | AddExtension(scoped_extension); |
[email protected] | 4a19063 | 2009-05-09 01:07:42 | [diff] [blame] | 1891 | } |
| 1892 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1893 | const Extension* ExtensionService::GetExtensionByIdInternal( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1894 | const std::string& id, bool include_enabled, bool include_disabled, |
| 1895 | bool include_terminated) const { |
[email protected] | e957fe5 | 2009-06-23 16:51:05 | [diff] [blame] | 1896 | std::string lowercase_id = StringToLowerASCII(id); |
[email protected] | 0c6da50 | 2009-08-14 22:32:39 | [diff] [blame] | 1897 | if (include_enabled) { |
| 1898 | for (ExtensionList::const_iterator iter = extensions_.begin(); |
| 1899 | iter != extensions_.end(); ++iter) { |
| 1900 | if ((*iter)->id() == lowercase_id) |
| 1901 | return *iter; |
| 1902 | } |
| 1903 | } |
| 1904 | if (include_disabled) { |
| 1905 | for (ExtensionList::const_iterator iter = disabled_extensions_.begin(); |
| 1906 | iter != disabled_extensions_.end(); ++iter) { |
| 1907 | if ((*iter)->id() == lowercase_id) |
| 1908 | return *iter; |
| 1909 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1910 | } |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1911 | if (include_terminated) { |
| 1912 | for (ExtensionList::const_iterator iter = terminated_extensions_.begin(); |
| 1913 | iter != terminated_extensions_.end(); ++iter) { |
| 1914 | if ((*iter)->id() == lowercase_id) |
| 1915 | return *iter; |
| 1916 | } |
| 1917 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1918 | return NULL; |
| 1919 | } |
| 1920 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1921 | void ExtensionService::TrackTerminatedExtension(const Extension* extension) { |
| 1922 | if (terminated_extension_ids_.insert(extension->id()).second) |
| 1923 | terminated_extensions_.push_back(make_scoped_refptr(extension)); |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1924 | |
| 1925 | UnloadExtension(extension->id(), UnloadedExtensionInfo::DISABLE); |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | void ExtensionService::UntrackTerminatedExtension(const std::string& id) { |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 1929 | std::string lowercase_id = StringToLowerASCII(id); |
| 1930 | if (terminated_extension_ids_.erase(lowercase_id) <= 0) |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1931 | return; |
| 1932 | |
[email protected] | bb7f4095 | 2011-01-13 00:21:20 | [diff] [blame] | 1933 | for (ExtensionList::iterator iter = terminated_extensions_.begin(); |
| 1934 | iter != terminated_extensions_.end(); ++iter) { |
| 1935 | if ((*iter)->id() == lowercase_id) { |
| 1936 | terminated_extensions_.erase(iter); |
| 1937 | return; |
| 1938 | } |
| 1939 | } |
| 1940 | } |
| 1941 | |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 1942 | const Extension* ExtensionService::GetTerminatedExtension( |
[email protected] | 8001df2 | 2011-04-28 19:59:47 | [diff] [blame] | 1943 | const std::string& id) const { |
| 1944 | return GetExtensionByIdInternal(id, false, false, true); |
| 1945 | } |
| 1946 | |
| 1947 | const Extension* ExtensionService::GetInstalledExtension( |
| 1948 | const std::string& id) const { |
| 1949 | return GetExtensionByIdInternal(id, true, true, true); |
[email protected] | 0dfe05c | 2011-02-23 23:03:36 | [diff] [blame] | 1950 | } |
| 1951 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1952 | const Extension* ExtensionService::GetWebStoreApp() { |
[email protected] | d307199 | 2010-10-08 15:24:07 | [diff] [blame] | 1953 | return GetExtensionById(extension_misc::kWebStoreAppId, false); |
| 1954 | } |
| 1955 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1956 | const Extension* ExtensionService::GetExtensionByURL(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 1957 | return url.scheme() != chrome::kExtensionScheme ? NULL : |
| 1958 | GetExtensionById(url.host(), false); |
| 1959 | } |
| 1960 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1961 | const Extension* ExtensionService::GetExtensionByWebExtent(const GURL& url) { |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 1962 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 1963 | if (extensions_[i]->web_extent().ContainsURL(url)) |
| 1964 | return extensions_[i]; |
| 1965 | } |
| 1966 | return NULL; |
[email protected] | 9f1087e | 2009-06-15 17:29:32 | [diff] [blame] | 1967 | } |
| 1968 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1969 | bool ExtensionService::ExtensionBindingsAllowed(const GURL& url) { |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 1970 | // Allow bindings for all packaged extension. |
| 1971 | if (GetExtensionByURL(url)) |
| 1972 | return true; |
| 1973 | |
| 1974 | // Allow bindings for all component, hosted apps. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 1975 | const Extension* extension = GetExtensionByWebExtent(url); |
[email protected] | 583d45c1 | 2010-08-31 02:48:12 | [diff] [blame] | 1976 | return (extension && extension->location() == Extension::COMPONENT); |
| 1977 | } |
| 1978 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1979 | const Extension* ExtensionService::GetExtensionByOverlappingWebExtent( |
[email protected] | 9f72aa0 | 2010-06-25 10:01:05 | [diff] [blame] | 1980 | const ExtensionExtent& extent) { |
[email protected] | 22c966c | 2010-06-26 06:35:02 | [diff] [blame] | 1981 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 1982 | if (extensions_[i]->web_extent().OverlapsWith(extent)) |
| 1983 | return extensions_[i]; |
| 1984 | } |
| 1985 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 1986 | return NULL; |
| 1987 | } |
| 1988 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1989 | const SkBitmap& ExtensionService::GetOmniboxIcon( |
[email protected] | b671760b | 2010-07-15 21:13:47 | [diff] [blame] | 1990 | const std::string& extension_id) { |
| 1991 | return omnibox_icon_manager_.GetIcon(extension_id); |
| 1992 | } |
| 1993 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1994 | const SkBitmap& ExtensionService::GetOmniboxPopupIcon( |
[email protected] | 29d0d4ac | 2010-09-08 21:10:31 | [diff] [blame] | 1995 | const std::string& extension_id) { |
| 1996 | return omnibox_popup_icon_manager_.GetIcon(extension_id); |
| 1997 | } |
| 1998 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 1999 | void ExtensionService::OnExternalExtensionFileFound( |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2000 | const std::string& id, |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2001 | const Version* version, |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 2002 | const FilePath& path, |
| 2003 | Extension::Location location) { |
[email protected] | ab22ba4 | 2011-01-14 16:36:38 | [diff] [blame] | 2004 | CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2005 | CHECK(Extension::IdIsValid(id)); |
[email protected] | 79c833b5 | 2011-04-05 18:31:01 | [diff] [blame] | 2006 | if (extension_prefs_->IsExternalExtensionUninstalled(id)) |
[email protected] | 683d070 | 2010-12-06 16:25:57 | [diff] [blame] | 2007 | return; |
[email protected] | a8af9fdb | 2010-10-28 21:52:20 | [diff] [blame] | 2008 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2009 | DCHECK(version); |
| 2010 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2011 | // Before even bothering to unpack, check and see if we already have this |
[email protected] | 4c96793 | 2009-07-31 01:15:49 | [diff] [blame] | 2012 | // version. This is important because these extensions are going to get |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2013 | // installed on every startup. |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 2014 | const Extension* existing = GetExtensionById(id, true); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2015 | if (existing) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2016 | switch (existing->version()->CompareTo(*version)) { |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2017 | case -1: // existing version is older, we should upgrade |
| 2018 | break; |
| 2019 | case 0: // existing version is same, do nothing |
| 2020 | return; |
| 2021 | case 1: // existing version is newer, uh-oh |
| 2022 | LOG(WARNING) << "Found external version of extension " << id |
| 2023 | << "that is older than current version. Current version " |
| 2024 | << "is: " << existing->VersionString() << ". New version " |
| 2025 | << "is: " << version << ". Keeping current version."; |
| 2026 | return; |
| 2027 | } |
| 2028 | } |
| 2029 | |
[email protected] | b2907fd | 2011-03-25 16:43:37 | [diff] [blame] | 2030 | pending_extension_manager()->AddFromExternalFile(id, location); |
[email protected] | 9c635f2 | 2010-12-02 09:36:36 | [diff] [blame] | 2031 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2032 | // no client (silent install) |
| 2033 | scoped_refptr<CrxInstaller> installer(MakeCrxInstaller(NULL)); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2034 | installer->set_install_source(location); |
| 2035 | installer->set_expected_id(id); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 2036 | installer->set_expected_version(*version); |
| 2037 | installer->set_install_cause(extension_misc::INSTALL_CAUSE_EXTERNAL_FILE); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 2038 | installer->InstallCrx(path); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 2039 | } |
| 2040 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2041 | void ExtensionService::ReportExtensionLoadError( |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2042 | const FilePath& extension_path, |
| 2043 | const std::string &error, |
| 2044 | NotificationType type, |
| 2045 | bool be_noisy) { |
| 2046 | NotificationService* service = NotificationService::current(); |
| 2047 | service->Notify(type, |
[email protected] | 24e7a9d | 2009-11-04 11:11:34 | [diff] [blame] | 2048 | Source<Profile>(profile_), |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2049 | Details<const std::string>(&error)); |
| 2050 | |
[email protected] | 8a205c0 | 2011-02-04 20:41:33 | [diff] [blame] | 2051 | std::string path_str = UTF16ToUTF8(extension_path.LossyDisplayName()); |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 2052 | std::string message = base::StringPrintf( |
| 2053 | "Could not load extension from '%s'. %s", |
| 2054 | path_str.c_str(), error.c_str()); |
[email protected] | d11c8e9 | 2009-10-20 23:26:40 | [diff] [blame] | 2055 | ExtensionErrorReporter::GetInstance()->ReportError(message, be_noisy); |
| 2056 | } |
| 2057 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2058 | void ExtensionService::DidCreateRenderViewForBackgroundPage( |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2059 | ExtensionHost* host) { |
| 2060 | OrphanedDevTools::iterator iter = |
[email protected] | 2d2f6cfc | 2011-05-06 21:09:33 | [diff] [blame] | 2061 | orphaned_dev_tools_.find(host->extension_id()); |
[email protected] | 406027c0 | 2010-09-27 08:03:18 | [diff] [blame] | 2062 | if (iter == orphaned_dev_tools_.end()) |
| 2063 | return; |
| 2064 | |
| 2065 | DevToolsManager::GetInstance()->AttachClientHost( |
| 2066 | iter->second, host->render_view_host()); |
| 2067 | orphaned_dev_tools_.erase(iter); |
| 2068 | } |
| 2069 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2070 | void ExtensionService::Observe(NotificationType type, |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2071 | const NotificationSource& source, |
| 2072 | const NotificationDetails& details) { |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2073 | switch (type.value) { |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2074 | case NotificationType::EXTENSION_PROCESS_TERMINATED: { |
[email protected] | bc535ee5 | 2010-08-31 18:40:32 | [diff] [blame] | 2075 | if (profile_ != Source<Profile>(source).ptr()->GetOriginalProfile()) |
| 2076 | break; |
[email protected] | a4ed628 | 2009-12-14 20:51:16 | [diff] [blame] | 2077 | |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2078 | ExtensionHost* host = Details<ExtensionHost>(details).ptr(); |
[email protected] | f128af4 | 2010-08-05 18:05:26 | [diff] [blame] | 2079 | |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2080 | // Mark the extension as terminated and Unload it. We want it to |
| 2081 | // be in a consistent state: either fully working or not loaded |
| 2082 | // at all, but never half-crashed. We do it in a PostTask so |
| 2083 | // that other handlers of this notification will still have |
| 2084 | // access to the Extension and ExtensionHost. |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2085 | MessageLoop::current()->PostTask( |
| 2086 | FROM_HERE, |
| 2087 | method_factory_.NewRunnableMethod( |
[email protected] | fa2416f | 2011-05-03 08:41:20 | [diff] [blame] | 2088 | &ExtensionService::TrackTerminatedExtension, |
| 2089 | host->extension())); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2090 | break; |
| 2091 | } |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2092 | case NotificationType::RENDERER_PROCESS_CREATED: { |
| 2093 | RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
| 2094 | // Valid extension function names, used to setup bindings in renderer. |
| 2095 | std::vector<std::string> function_names; |
| 2096 | ExtensionFunctionDispatcher::GetAllFunctionNames(&function_names); |
| 2097 | process->Send(new ExtensionMsg_SetFunctionNames(function_names)); |
[email protected] | 31f7726 | 2009-12-02 20:48:53 | [diff] [blame] | 2098 | |
[email protected] | 77a6970c | 2011-04-23 16:58:56 | [diff] [blame] | 2099 | // Scripting whitelist. This is modified by tests and must be communicated |
| 2100 | // to renderers. |
| 2101 | process->Send(new ExtensionMsg_SetScriptingWhitelist( |
| 2102 | *Extension::GetScriptingWhitelist())); |
| 2103 | |
| 2104 | // Loaded extensions. |
| 2105 | for (size_t i = 0; i < extensions_.size(); ++i) { |
| 2106 | process->Send(new ExtensionMsg_Loaded( |
| 2107 | ExtensionMsg_Loaded_Params(extensions_[i]))); |
| 2108 | } |
| 2109 | break; |
| 2110 | } |
[email protected] | da5683db | 2011-04-23 17:12:21 | [diff] [blame] | 2111 | case NotificationType::RENDERER_PROCESS_TERMINATED: { |
| 2112 | RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
| 2113 | installed_app_hosts_.erase(process->id()); |
| 2114 | break; |
| 2115 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2116 | case NotificationType::PREF_CHANGED: { |
| 2117 | std::string* pref_name = Details<std::string>(details).ptr(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2118 | if (*pref_name == prefs::kExtensionInstallAllowList || |
| 2119 | *pref_name == prefs::kExtensionInstallDenyList) { |
| 2120 | CheckAdminBlacklist(); |
[email protected] | 6c751e7 | 2010-11-23 10:11:10 | [diff] [blame] | 2121 | } else { |
| 2122 | NOTREACHED() << "Unexpected preference name."; |
| 2123 | } |
[email protected] | aa96d3a | 2010-08-21 08:45:25 | [diff] [blame] | 2124 | break; |
| 2125 | } |
| 2126 | |
[email protected] | 4814b51 | 2009-11-07 00:12:29 | [diff] [blame] | 2127 | default: |
| 2128 | NOTREACHED() << "Unexpected notification type."; |
| 2129 | } |
| 2130 | } |
| 2131 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2132 | bool ExtensionService::HasApps() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2133 | return !GetAppIds().empty(); |
| 2134 | } |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2135 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2136 | ExtensionIdSet ExtensionService::GetAppIds() const { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2137 | ExtensionIdSet result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2138 | for (ExtensionList::const_iterator it = extensions_.begin(); |
| 2139 | it != extensions_.end(); ++it) { |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2140 | if ((*it)->is_app() && (*it)->location() != Extension::COMPONENT) |
| 2141 | result.insert((*it)->id()); |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2142 | } |
| 2143 | |
[email protected] | ec5b50d | 2010-10-09 16:35:18 | [diff] [blame] | 2144 | return result; |
[email protected] | 377011d | 2010-07-20 04:18:50 | [diff] [blame] | 2145 | } |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2146 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 2147 | scoped_refptr<CrxInstaller> ExtensionService::MakeCrxInstaller( |
| 2148 | ExtensionInstallUI* client) { |
| 2149 | return new CrxInstaller(weak_ptr_factory_.GetWeakPtr(), client); |
| 2150 | } |
| 2151 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2152 | bool ExtensionService::IsBackgroundPageReady(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2153 | return (extension->background_url().is_empty() || |
| 2154 | extension_runtime_data_[extension->id()].background_page_ready); |
| 2155 | } |
| 2156 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2157 | void ExtensionService::SetBackgroundPageReady(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2158 | DCHECK(!extension->background_url().is_empty()); |
| 2159 | extension_runtime_data_[extension->id()].background_page_ready = true; |
| 2160 | NotificationService::current()->Notify( |
| 2161 | NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
| 2162 | Source<const Extension>(extension), |
| 2163 | NotificationService::NoDetails()); |
| 2164 | } |
| 2165 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2166 | bool ExtensionService::IsBeingUpgraded(const Extension* extension) { |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2167 | return extension_runtime_data_[extension->id()].being_upgraded; |
| 2168 | } |
| 2169 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2170 | void ExtensionService::SetBeingUpgraded(const Extension* extension, |
[email protected] | d7e9a86 | 2010-11-03 21:57:49 | [diff] [blame] | 2171 | bool value) { |
| 2172 | extension_runtime_data_[extension->id()].being_upgraded = value; |
| 2173 | } |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2174 | |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 2175 | PropertyBag* ExtensionService::GetPropertyBag(const Extension* extension) { |
[email protected] | 1bead071 | 2010-11-27 17:41:53 | [diff] [blame] | 2176 | return &extension_runtime_data_[extension->id()].property_bag; |
| 2177 | } |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 2178 | |
| 2179 | void ExtensionService::RegisterNaClModule(const GURL& url, |
| 2180 | const std::string& mime_type) { |
| 2181 | NaClModuleInfo info; |
| 2182 | info.url = url; |
| 2183 | info.mime_type = mime_type; |
| 2184 | |
| 2185 | DCHECK(FindNaClModule(url) == nacl_module_list_.end()); |
| 2186 | nacl_module_list_.push_front(info); |
| 2187 | } |
| 2188 | |
| 2189 | void ExtensionService::UnregisterNaClModule(const GURL& url) { |
| 2190 | NaClModuleInfoList::iterator iter = FindNaClModule(url); |
| 2191 | DCHECK(iter != nacl_module_list_.end()); |
| 2192 | nacl_module_list_.erase(iter); |
| 2193 | } |
| 2194 | |
| 2195 | void ExtensionService::UpdatePluginListWithNaClModules() { |
| 2196 | FilePath path; |
| 2197 | PathService::Get(chrome::FILE_NACL_PLUGIN, &path); |
| 2198 | |
| 2199 | webkit::npapi::PluginList::Singleton()->UnregisterInternalPlugin(path); |
| 2200 | |
| 2201 | const PepperPluginInfo* pepper_info = |
| 2202 | PepperPluginRegistry::GetInstance()->GetInfoForPlugin(path); |
| 2203 | webkit::npapi::WebPluginInfo info = pepper_info->ToWebPluginInfo(); |
| 2204 | |
| 2205 | DCHECK(nacl_module_list_.size() <= 1); |
| 2206 | for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2207 | iter != nacl_module_list_.end(); ++iter) { |
| 2208 | webkit::npapi::WebPluginMimeType mime_type_info; |
| 2209 | mime_type_info.mime_type = iter->mime_type; |
| 2210 | mime_type_info.additional_param_names.push_back(UTF8ToUTF16("nacl")); |
| 2211 | mime_type_info.additional_param_values.push_back( |
| 2212 | UTF8ToUTF16(iter->url.spec())); |
| 2213 | info.mime_types.push_back(mime_type_info); |
| 2214 | } |
| 2215 | |
| 2216 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 2217 | webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 2218 | } |
| 2219 | |
| 2220 | ExtensionService::NaClModuleInfoList::iterator |
| 2221 | ExtensionService::FindNaClModule(const GURL& url) { |
| 2222 | for (NaClModuleInfoList::iterator iter = nacl_module_list_.begin(); |
| 2223 | iter != nacl_module_list_.end(); ++iter) { |
| 2224 | if (iter->url == url) |
| 2225 | return iter; |
| 2226 | } |
| 2227 | return nacl_module_list_.end(); |
| 2228 | } |