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