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