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