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