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