[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [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 | |
| 5 | #include "chrome/browser/extensions/crx_installer.h" |
| 6 | |
[email protected] | 5349ac6d | 2011-04-05 22:20:17 | [diff] [blame] | 7 | #include <map> |
[email protected] | b1f04cc | 2010-11-10 22:59:30 | [diff] [blame] | 8 | #include <set> |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 9 | |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 11 | #include "base/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 12 | #include "base/files/scoped_temp_dir.h" |
[email protected] | fee46a8 | 2010-12-09 16:42:15 | [diff] [blame] | 13 | #include "base/lazy_instance.h" |
[email protected] | 394dc47 | 2011-04-14 15:57:19 | [diff] [blame] | 14 | #include "base/metrics/histogram.h" |
[email protected] | b0b3abd9 | 2010-04-30 17:00:09 | [diff] [blame] | 15 | #include "base/path_service.h" |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 16 | #include "base/sequenced_task_runner.h" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 17 | #include "base/string_util.h" |
[email protected] | 18d4b6c | 2010-09-21 03:21:04 | [diff] [blame] | 18 | #include "base/stringprintf.h" |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 19 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 20 | #include "base/threading/thread_restrictions.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 21 | #include "base/time.h" |
[email protected] | 4bf4135 | 2010-03-08 21:21:36 | [diff] [blame] | 22 | #include "base/utf_string_conversions.h" |
[email protected] | daf66aa | 2010-08-06 06:24:28 | [diff] [blame] | 23 | #include "base/version.h" |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 24 | #include "chrome/browser/extensions/convert_user_script.h" |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 25 | #include "chrome/browser/extensions/convert_web_app.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 26 | #include "chrome/browser/extensions/crx_installer_error.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_error_reporter.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_install_ui.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_system.h" |
[email protected] | fdd679b | 2012-11-15 20:49:39 | [diff] [blame] | 31 | #include "chrome/browser/extensions/management_policy.h" |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 32 | #include "chrome/browser/extensions/permissions_updater.h" |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 33 | #include "chrome/browser/extensions/requirements_checker.h" |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 34 | #include "chrome/browser/extensions/webstore_installer.h" |
| 35 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 92bcd16 | 2010-01-15 08:47:48 | [diff] [blame] | 36 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 37 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | b0b3abd9 | 2010-04-30 17:00:09 | [diff] [blame] | 38 | #include "chrome/common/chrome_paths.h" |
[email protected] | a0cf04a | 2010-06-23 03:29:55 | [diff] [blame] | 39 | #include "chrome/common/extensions/extension_constants.h" |
[email protected] | f20d733 | 2011-03-08 21:11:53 | [diff] [blame] | 40 | #include "chrome/common/extensions/extension_file_util.h" |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 41 | #include "chrome/common/extensions/extension_icon_set.h" |
[email protected] | 544471a | 2012-10-13 05:27:09 | [diff] [blame] | 42 | #include "chrome/common/extensions/feature_switch.h" |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 43 | #include "chrome/common/extensions/manifest.h" |
[email protected] | abe720c0 | 2013-04-12 04:00:10 | [diff] [blame] | 44 | #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 45 | #include "content/public/browser/browser_thread.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 46 | #include "content/public/browser/notification_service.h" |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 47 | #include "content/public/browser/resource_dispatcher_host.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 48 | #include "content/public/browser/user_metrics.h" |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 49 | #include "grit/chromium_strings.h" |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 50 | #include "grit/generated_resources.h" |
[email protected] | 969894ab | 2010-08-29 00:35:01 | [diff] [blame] | 51 | #include "grit/theme_resources.h" |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 52 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 53 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 42ce29d | 2011-01-20 23:19:46 | [diff] [blame] | 54 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 55 | |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 56 | #if defined(ENABLE_MANAGED_USERS) |
| 57 | #include "chrome/browser/managed_mode/managed_user_service.h" |
| 58 | #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 59 | #endif |
| 60 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 61 | using content::BrowserThread; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 62 | using content::UserMetricsAction; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 63 | |
| 64 | namespace extensions { |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 65 | |
[email protected] | aa9fc86 | 2012-05-30 21:47:47 | [diff] [blame] | 66 | namespace { |
| 67 | |
| 68 | // Used in histograms; do not change order. |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 69 | enum OffStoreInstallDecision { |
| 70 | OnStoreInstall, |
| 71 | OffStoreInstallAllowed, |
| 72 | OffStoreInstallDisallowed, |
| 73 | NumOffStoreInstallDecision |
[email protected] | aa9fc86 | 2012-05-30 21:47:47 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | } // namespace |
| 77 | |
[email protected] | dd9d627 | 2010-09-09 17:33:18 | [diff] [blame] | 78 | // static |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 79 | scoped_refptr<CrxInstaller> CrxInstaller::Create( |
| 80 | ExtensionService* frontend, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 81 | ExtensionInstallPrompt* client) { |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 82 | return new CrxInstaller(frontend->AsWeakPtr(), client, NULL); |
[email protected] | d8c8f25f | 2011-11-02 18:18:01 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | // static |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 86 | scoped_refptr<CrxInstaller> CrxInstaller::Create( |
| 87 | ExtensionService* frontend, |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 88 | ExtensionInstallPrompt* client, |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 89 | const WebstoreInstaller::Approval* approval) { |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 90 | return new CrxInstaller(frontend->AsWeakPtr(), client, approval); |
[email protected] | 5349ac6d | 2011-04-05 22:20:17 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | 3d61a7f | 2012-07-12 19:11:25 | [diff] [blame] | 93 | CrxInstaller::CrxInstaller( |
| 94 | base::WeakPtr<ExtensionService> frontend_weak, |
| 95 | ExtensionInstallPrompt* client, |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 96 | const WebstoreInstaller::Approval* approval) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 97 | : install_directory_(frontend_weak->install_directory()), |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 98 | install_source_(Manifest::INTERNAL), |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 99 | approved_(false), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 100 | extensions_enabled_(frontend_weak->extensions_enabled()), |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 101 | delete_source_(false), |
[email protected] | 6451e33 | 2010-10-05 00:14:53 | [diff] [blame] | 102 | create_app_shortcut_(false), |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 103 | frontend_weak_(frontend_weak), |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 104 | profile_(frontend_weak->profile()), |
[email protected] | d4a7188 | 2010-06-25 16:36:41 | [diff] [blame] | 105 | client_(client), |
[email protected] | dd9d627 | 2010-09-09 17:33:18 | [diff] [blame] | 106 | apps_require_extension_mime_type_(false), |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 107 | allow_silent_install_(false), |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 108 | bypass_blacklist_for_test_(false), |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 109 | install_cause_(extension_misc::INSTALL_CAUSE_UNSET), |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 110 | creation_flags_(Extension::NO_FLAGS), |
[email protected] | 86a9911 | 2012-06-19 01:18:07 | [diff] [blame] | 111 | off_store_install_allow_reason_(OffStoreInstallDisallowed), |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 112 | did_handle_successfully_(true), |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 113 | error_on_unsupported_requirements_(false), |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 114 | requirements_checker_(new RequirementsChecker()), |
[email protected] | 0db124b0 | 2012-11-07 04:55:05 | [diff] [blame] | 115 | has_requirement_errors_(false), |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 116 | install_wait_for_idle_(true), |
| 117 | update_from_settings_page_(false) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 118 | installer_task_runner_ = frontend_weak->GetFileTaskRunner(); |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 119 | if (!approval) |
| 120 | return; |
| 121 | |
| 122 | CHECK(profile_->IsSameProfile(approval->profile)); |
[email protected] | d2a639e | 2012-09-17 07:41:21 | [diff] [blame] | 123 | if (client_) { |
| 124 | client_->install_ui()->SetUseAppInstalledBubble( |
| 125 | approval->use_app_installed_bubble); |
| 126 | client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui); |
| 127 | } |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 128 | |
[email protected] | 89019d6 | 2012-05-17 18:47:09 | [diff] [blame] | 129 | if (approval->skip_install_dialog) { |
| 130 | // Mark the extension as approved, but save the expected manifest and ID |
| 131 | // so we can check that they match the CRX's. |
| 132 | approved_ = true; |
[email protected] | 21c0104 | 2013-03-10 23:41:14 | [diff] [blame] | 133 | expected_manifest_.reset(approval->manifest->DeepCopy()); |
[email protected] | 89019d6 | 2012-05-17 18:47:09 | [diff] [blame] | 134 | expected_id_ = approval->extension_id; |
| 135 | } |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 136 | |
| 137 | show_dialog_callback_ = approval->show_dialog_callback; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 138 | } |
| 139 | |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 140 | CrxInstaller::~CrxInstaller() { |
[email protected] | 765b7ea5 | 2010-03-30 03:40:34 | [diff] [blame] | 141 | // Make sure the UI is deleted on the ui thread. |
[email protected] | d2a639e | 2012-09-17 07:41:21 | [diff] [blame] | 142 | if (client_) { |
| 143 | BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, client_); |
| 144 | client_ = NULL; |
| 145 | } |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 148 | void CrxInstaller::InstallCrx(const base::FilePath& source_file) { |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 149 | source_file_ = source_file; |
| 150 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 151 | scoped_refptr<SandboxedUnpacker> unpacker( |
| 152 | new SandboxedUnpacker( |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 153 | source_file, |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 154 | content::ResourceDispatcherHost::Get() != NULL, |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 155 | install_source_, |
[email protected] | 1bf73cc | 2011-10-26 22:38:31 | [diff] [blame] | 156 | creation_flags_, |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 157 | install_directory_, |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 158 | installer_task_runner_, |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 159 | this)); |
| 160 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 161 | if (!installer_task_runner_->PostTask( |
| 162 | FROM_HERE, |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 163 | base::Bind(&SandboxedUnpacker::Start, unpacker.get()))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 164 | NOTREACHED(); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 165 | } |
| 166 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 167 | void CrxInstaller::InstallUserScript(const base::FilePath& source_file, |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 168 | const GURL& download_url) { |
| 169 | DCHECK(!download_url.is_empty()); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 170 | |
| 171 | source_file_ = source_file; |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 172 | download_url_ = download_url; |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 173 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 174 | if (!installer_task_runner_->PostTask( |
| 175 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 176 | base::Bind(&CrxInstaller::ConvertUserScriptOnFileThread, this))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 177 | NOTREACHED(); |
[email protected] | 6dfbbf8 | 2010-03-12 23:09:16 | [diff] [blame] | 178 | } |
| 179 | |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 180 | void CrxInstaller::ConvertUserScriptOnFileThread() { |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 181 | string16 error; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 182 | scoped_refptr<Extension> extension = ConvertUserScriptToExtension( |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 183 | source_file_, download_url_, install_directory_, &error); |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 184 | if (!extension) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 185 | ReportFailureFromFileThread(CrxInstallerError(error)); |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 186 | return; |
| 187 | } |
| 188 | |
[email protected] | ad93c6ba | 2011-05-26 04:48:33 | [diff] [blame] | 189 | OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); |
[email protected] | 6657afa6 | 2009-11-04 02:15:20 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 192 | void CrxInstaller::InstallWebApp(const WebApplicationInfo& web_app) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 193 | if (!installer_task_runner_->PostTask( |
| 194 | FROM_HERE, |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 195 | base::Bind(&CrxInstaller::ConvertWebAppOnFileThread, |
| 196 | this, |
| 197 | web_app, |
| 198 | install_directory_))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 199 | NOTREACHED(); |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void CrxInstaller::ConvertWebAppOnFileThread( |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 203 | const WebApplicationInfo& web_app, |
| 204 | const base::FilePath& install_directory) { |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 205 | string16 error; |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 206 | scoped_refptr<Extension> extension( |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 207 | ConvertWebAppToExtension(web_app, base::Time::Now(), install_directory)); |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 208 | if (!extension) { |
| 209 | // Validation should have stopped any potential errors before getting here. |
| 210 | NOTREACHED() << "Could not convert web app to extension."; |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | // TODO(aa): conversion data gets lost here :( |
| 215 | |
[email protected] | ad93c6ba | 2011-05-26 04:48:33 | [diff] [blame] | 216 | OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); |
[email protected] | bb46153 | 2010-11-26 21:50:23 | [diff] [blame] | 217 | } |
| 218 | |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 219 | CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 220 | DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 221 | |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 222 | // Make sure the expected ID matches if one was supplied or if we want to |
| 223 | // bypass the prompt. |
| 224 | if ((approved_ || !expected_id_.empty()) && |
| 225 | expected_id_ != extension->id()) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 226 | return CrxInstallerError( |
| 227 | l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALL_UNEXPECTED_ID, |
| 228 | ASCIIToUTF16(expected_id_), |
| 229 | ASCIIToUTF16(extension->id()))); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | if (expected_version_.get() && |
| 233 | !expected_version_->Equals(*extension->version())) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 234 | return CrxInstallerError( |
| 235 | l10n_util::GetStringFUTF16( |
| 236 | IDS_EXTENSION_INSTALL_UNEXPECTED_VERSION, |
| 237 | ASCIIToUTF16(expected_version_->GetString()), |
| 238 | ASCIIToUTF16(extension->version()->GetString()))); |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 241 | // Make sure the manifests match if we want to bypass the prompt. |
| 242 | if (approved_ && |
| 243 | (!expected_manifest_.get() || |
| 244 | !expected_manifest_->Equals(original_manifest_.get()))) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 245 | return CrxInstallerError( |
| 246 | l10n_util::GetStringUTF16(IDS_EXTENSION_MANIFEST_INVALID)); |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 247 | } |
| 248 | |
[email protected] | 604322d | 2011-03-22 16:51:56 | [diff] [blame] | 249 | // The checks below are skipped for themes and external installs. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 250 | // TODO(pamg): After ManagementPolicy refactoring is complete, remove this |
| 251 | // and other uses of install_source_ that are no longer needed now that the |
[email protected] | f5ac274 | 2012-07-02 17:50:58 | [diff] [blame] | 252 | // SandboxedUnpacker sets extension->location. |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 253 | if (extension->is_theme() || Manifest::IsExternalLocation(install_source_)) |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 254 | return CrxInstallerError(); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 255 | |
| 256 | if (!extensions_enabled_) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 257 | return CrxInstallerError( |
| 258 | l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALL_NOT_ENABLED)); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 261 | if (install_cause_ == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) { |
[email protected] | 544471a | 2012-10-13 05:27:09 | [diff] [blame] | 262 | if (FeatureSwitch::easy_off_store_install()->IsEnabled()) { |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 263 | const char* kHistogramName = "Extensions.OffStoreInstallDecisionEasy"; |
| 264 | if (is_gallery_install()) { |
| 265 | UMA_HISTOGRAM_ENUMERATION(kHistogramName, OnStoreInstall, |
| 266 | NumOffStoreInstallDecision); |
| 267 | } else { |
| 268 | UMA_HISTOGRAM_ENUMERATION(kHistogramName, OffStoreInstallAllowed, |
| 269 | NumOffStoreInstallDecision); |
| 270 | } |
| 271 | } else { |
| 272 | const char* kHistogramName = "Extensions.OffStoreInstallDecisionHard"; |
| 273 | if (is_gallery_install()) { |
| 274 | UMA_HISTOGRAM_ENUMERATION(kHistogramName, OnStoreInstall, |
| 275 | NumOffStoreInstallDecision); |
[email protected] | d903981 | 2012-06-09 06:05:48 | [diff] [blame] | 276 | } else if (off_store_install_allow_reason_ != OffStoreInstallDisallowed) { |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 277 | UMA_HISTOGRAM_ENUMERATION(kHistogramName, OffStoreInstallAllowed, |
| 278 | NumOffStoreInstallDecision); |
[email protected] | d903981 | 2012-06-09 06:05:48 | [diff] [blame] | 279 | UMA_HISTOGRAM_ENUMERATION("Extensions.OffStoreInstallAllowReason", |
| 280 | off_store_install_allow_reason_, |
| 281 | NumOffStoreInstallAllowReasons); |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 282 | } else { |
| 283 | UMA_HISTOGRAM_ENUMERATION(kHistogramName, OffStoreInstallDisallowed, |
| 284 | NumOffStoreInstallDecision); |
[email protected] | 86a9911 | 2012-06-19 01:18:07 | [diff] [blame] | 285 | // Don't delete source in this case so that the user can install |
| 286 | // manually if they want. |
| 287 | delete_source_ = false; |
| 288 | did_handle_successfully_ = false; |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 289 | |
| 290 | return CrxInstallerError( |
| 291 | CrxInstallerError::ERROR_OFF_STORE, |
| 292 | l10n_util::GetStringUTF16( |
| 293 | IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE)); |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 298 | if (extension_->is_app()) { |
| 299 | // If the app was downloaded, apps_require_extension_mime_type_ |
| 300 | // will be set. In this case, check that it was served with the |
| 301 | // right mime type. Make an exception for file URLs, which come |
| 302 | // from the users computer and have no headers. |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 303 | if (!download_url_.SchemeIsFile() && |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 304 | apps_require_extension_mime_type_ && |
| 305 | original_mime_type_ != Extension::kMimeType) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 306 | return CrxInstallerError( |
| 307 | l10n_util::GetStringFUTF16( |
| 308 | IDS_EXTENSION_INSTALL_INCORRECT_APP_CONTENT_TYPE, |
| 309 | ASCIIToUTF16(Extension::kMimeType))); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 310 | } |
| 311 | |
[email protected] | c08931b | 2010-10-08 22:30:47 | [diff] [blame] | 312 | // If the client_ is NULL, then the app is either being installed via |
| 313 | // an internal mechanism like sync, external_extensions, or default apps. |
| 314 | // In that case, we don't want to enforce things like the install origin. |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 315 | if (!is_gallery_install() && client_) { |
[email protected] | c08931b | 2010-10-08 22:30:47 | [diff] [blame] | 316 | // For apps with a gallery update URL, require that they be installed |
| 317 | // from the gallery. |
| 318 | // TODO(erikkay) Apply this rule for paid extensions and themes as well. |
[email protected] | a65882c | 2010-11-12 15:15:09 | [diff] [blame] | 319 | if (extension->UpdatesFromGallery()) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 320 | return CrxInstallerError( |
| 321 | l10n_util::GetStringFUTF16( |
| 322 | IDS_EXTENSION_DISALLOW_NON_DOWNLOADED_GALLERY_INSTALLS, |
| 323 | l10n_util::GetStringUTF16(IDS_EXTENSION_WEB_STORE_TITLE))); |
[email protected] | c08931b | 2010-10-08 22:30:47 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // For self-hosted apps, verify that the entire extent is on the same |
| 327 | // host (or a subdomain of the host) the download happened from. There's |
| 328 | // no way for us to verify that the app controls any other hosts. |
[email protected] | ac2e2acd | 2013-03-21 12:57:29 | [diff] [blame] | 329 | URLPattern pattern(UserScript::ValidUserScriptSchemes()); |
[email protected] | 655b2b1a | 2011-10-13 17:13:06 | [diff] [blame] | 330 | pattern.SetHost(download_url_.host()); |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 331 | pattern.SetMatchSubdomains(true); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 332 | |
[email protected] | 06e8b8ff | 2011-07-13 15:03:47 | [diff] [blame] | 333 | URLPatternSet patterns = extension_->web_extent(); |
| 334 | for (URLPatternSet::const_iterator i = patterns.begin(); |
| 335 | i != patterns.end(); ++i) { |
| 336 | if (!pattern.MatchesHost(i->host())) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 337 | return CrxInstallerError( |
| 338 | l10n_util::GetStringUTF16( |
| 339 | IDS_EXTENSION_INSTALL_INCORRECT_INSTALL_HOST)); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 340 | } |
| 341 | } |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 345 | return CrxInstallerError(); |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 346 | } |
| 347 | |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 348 | void CrxInstaller::OnUnpackFailure(const string16& error_message) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 349 | DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 350 | |
| 351 | UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackFailureInstallSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 352 | install_source(), Manifest::NUM_LOCATIONS); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 353 | |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 354 | UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackFailureInstallCause", |
| 355 | install_cause(), |
| 356 | extension_misc::NUM_INSTALL_CAUSES); |
| 357 | |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 358 | ReportFailureFromFileThread(CrxInstallerError(error_message)); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 361 | void CrxInstaller::OnUnpackSuccess(const base::FilePath& temp_dir, |
| 362 | const base::FilePath& extension_dir, |
[email protected] | ad93c6ba | 2011-05-26 04:48:33 | [diff] [blame] | 363 | const DictionaryValue* original_manifest, |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 364 | const Extension* extension) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 365 | DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 366 | |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 367 | UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackSuccessInstallSource", |
[email protected] | 1d5e58b | 2013-01-31 08:41:40 | [diff] [blame] | 368 | install_source(), Manifest::NUM_LOCATIONS); |
[email protected] | cb0e5031 | 2011-05-09 15:03:07 | [diff] [blame] | 369 | |
| 370 | |
| 371 | UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackSuccessInstallCause", |
| 372 | install_cause(), |
| 373 | extension_misc::NUM_INSTALL_CAUSES); |
| 374 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 375 | // Note: We take ownership of |extension| and |temp_dir|. |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 376 | extension_ = extension; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 377 | temp_dir_ = temp_dir; |
| 378 | |
[email protected] | ad93c6ba | 2011-05-26 04:48:33 | [diff] [blame] | 379 | if (original_manifest) |
[email protected] | 21c0104 | 2013-03-10 23:41:14 | [diff] [blame] | 380 | original_manifest_.reset(new Manifest( |
| 381 | Manifest::INVALID_LOCATION, |
| 382 | scoped_ptr<DictionaryValue>(original_manifest->DeepCopy()))); |
[email protected] | ad93c6ba | 2011-05-26 04:48:33 | [diff] [blame] | 383 | |
[email protected] | 8ef78fd | 2010-08-19 17:14:32 | [diff] [blame] | 384 | // We don't have to delete the unpack dir explicity since it is a child of |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 385 | // the temp dir. |
| 386 | unpacked_extension_root_ = extension_dir; |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 387 | |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 388 | CrxInstallerError error = AllowInstall(extension); |
| 389 | if (error.type() != CrxInstallerError::ERROR_NONE) { |
[email protected] | da8479bf | 2010-10-08 15:19:45 | [diff] [blame] | 390 | ReportFailureFromFileThread(error); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 391 | return; |
| 392 | } |
| 393 | |
[email protected] | 7a5452f | 2010-12-13 23:03:19 | [diff] [blame] | 394 | if (client_) { |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 395 | IconsInfo::DecodeIcon(extension_.get(), |
[email protected] | faf8719 | 2012-08-17 00:07:59 | [diff] [blame] | 396 | extension_misc::EXTENSION_ICON_LARGE, |
[email protected] | e3c0bc2 | 2012-02-24 01:34:15 | [diff] [blame] | 397 | ExtensionIconSet::MATCH_BIGGER, |
[email protected] | c690a981 | 2009-12-17 05:55:32 | [diff] [blame] | 398 | &install_icon_); |
[email protected] | 86693068 | 2009-08-18 22:53:47 | [diff] [blame] | 399 | } |
[email protected] | 92bcd16 | 2010-01-15 08:47:48 | [diff] [blame] | 400 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 401 | if (!BrowserThread::PostTask( |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 402 | BrowserThread::UI, FROM_HERE, |
| 403 | base::Bind(&CrxInstaller::CheckRequirements, this))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 404 | NOTREACHED(); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 405 | } |
| 406 | |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 407 | void CrxInstaller::CheckRequirements() { |
| 408 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b80ec46 | 2012-10-30 18:53:00 | [diff] [blame] | 409 | if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
[email protected] | 3c4abc8 | 2012-10-22 22:25:54 | [diff] [blame] | 410 | return; |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 411 | AddRef(); // Balanced in OnRequirementsChecked(). |
| 412 | requirements_checker_->Check(extension_, |
| 413 | base::Bind(&CrxInstaller::OnRequirementsChecked, |
| 414 | this)); |
| 415 | } |
| 416 | |
| 417 | void CrxInstaller::OnRequirementsChecked( |
| 418 | std::vector<std::string> requirement_errors) { |
| 419 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 420 | Release(); // Balanced in CheckRequirements(). |
| 421 | if (!requirement_errors.empty()) { |
| 422 | if (error_on_unsupported_requirements_) { |
| 423 | ReportFailureFromUIThread(CrxInstallerError( |
| 424 | UTF8ToUTF16(JoinString(requirement_errors, ' ')))); |
| 425 | return; |
| 426 | } |
| 427 | has_requirement_errors_ = true; |
| 428 | } |
| 429 | |
[email protected] | 9cbd591 | 2013-04-18 11:27:54 | [diff] [blame] | 430 | #if defined(ENABLE_MANAGED_USERS) && !defined(OS_CHROMEOS) |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 431 | // Check whether the profile is managed. |
| 432 | ManagedUserService* service = |
| 433 | ManagedUserServiceFactory::GetForProfile(profile_); |
| 434 | if (service->ProfileIsManaged()) { |
[email protected] | a9bc63e | 2013-03-21 14:54:43 | [diff] [blame] | 435 | // Extensions which should be installed by policy are installed without |
| 436 | // using the ExtensionInstallPrompt. In that case, |client_| is NULL. |
| 437 | if (client_ == NULL) { |
| 438 | // Automatically set authorization |
| 439 | OnAuthorizationResult(true); |
| 440 | return; |
| 441 | } |
[email protected] | 509ad1a9 | 2013-03-19 21:41:06 | [diff] [blame] | 442 | // parent_web_contents could be NULL when the client is instantiated from |
| 443 | // ExtensionEnableFlow, but that code path does not lead to here. |
[email protected] | a9bc63e | 2013-03-21 14:54:43 | [diff] [blame] | 444 | CHECK(client_->parent_web_contents()); |
[email protected] | 509ad1a9 | 2013-03-19 21:41:06 | [diff] [blame] | 445 | service->RequestAuthorization( |
| 446 | client_->parent_web_contents(), |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 447 | base::Bind(&CrxInstaller::OnAuthorizationResult, |
| 448 | this)); |
| 449 | return; |
| 450 | } |
| 451 | #endif |
[email protected] | 9827043 | 2012-09-11 20:51:24 | [diff] [blame] | 452 | ConfirmInstall(); |
| 453 | } |
| 454 | |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 455 | #if defined(ENABLE_MANAGED_USERS) |
| 456 | void CrxInstaller::OnAuthorizationResult(bool success) { |
| 457 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 458 | if (success) { |
| 459 | ManagedUserService* service = |
| 460 | ManagedUserServiceFactory::GetForProfile(profile_); |
| 461 | DCHECK(service); |
| 462 | service->AddElevationForExtension(extension_->id()); |
| 463 | } |
| 464 | // In case the authorization was not successful, ConfirmInstall will give an |
| 465 | // appropriate error to the user. |
| 466 | ConfirmInstall(); |
| 467 | } |
| 468 | #endif |
| 469 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 470 | void CrxInstaller::ConfirmInstall() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 471 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | b80ec46 | 2012-10-30 18:53:00 | [diff] [blame] | 472 | if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 473 | return; |
| 474 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 475 | // Check whether this install is initiated from the settings page to |
| 476 | // update an existing extension or app. |
| 477 | CheckUpdateFromSettingsPage(); |
| 478 | |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 479 | // For managed users the call UserMayLoad returns false if the profile is not |
| 480 | // elevated. |
[email protected] | 6518715 | 2012-06-02 13:14:14 | [diff] [blame] | 481 | string16 error; |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 482 | if (!ExtensionSystem::Get(profile_)->management_policy()-> |
[email protected] | bd30672 | 2012-07-11 20:43:59 | [diff] [blame] | 483 | UserMayLoad(extension_, &error)) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 484 | ReportFailureFromUIThread(CrxInstallerError(error)); |
[email protected] | 306a2bd | 2010-08-11 14:56:36 | [diff] [blame] | 485 | return; |
| 486 | } |
| 487 | |
[email protected] | 0d9a1da8 | 2013-03-14 21:52:07 | [diff] [blame] | 488 | #if defined(ENABLE_MANAGED_USERS) |
| 489 | // Reset the elevation of managed users. |
| 490 | ManagedUserService* service = |
| 491 | ManagedUserServiceFactory::GetForProfile(profile_); |
| 492 | if (service->ProfileIsManaged()) |
| 493 | service->RemoveElevationForExtension(extension_->id()); |
| 494 | #endif |
| 495 | |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 496 | GURL overlapping_url; |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 497 | const Extension* overlapping_extension = |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 498 | frontend_weak_->extensions()-> |
| 499 | GetHostedAppByOverlappingWebExtent(extension_->web_extent()); |
[email protected] | 15300d9 | 2011-01-19 18:44:30 | [diff] [blame] | 500 | if (overlapping_extension && |
| 501 | overlapping_extension->id() != extension_->id()) { |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 502 | ReportFailureFromUIThread( |
| 503 | CrxInstallerError( |
| 504 | l10n_util::GetStringFUTF16( |
| 505 | IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, |
| 506 | UTF8ToUTF16(overlapping_extension->name())))); |
[email protected] | 6d2e60bd | 2010-06-03 22:37:39 | [diff] [blame] | 507 | return; |
| 508 | } |
| 509 | |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 510 | current_version_ = |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 511 | frontend_weak_->extension_prefs()->GetVersionString(extension_->id()); |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 512 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 513 | if (client_ && |
| 514 | (!allow_silent_install_ || !approved_) && |
| 515 | !update_from_settings_page_) { |
| 516 | AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
[email protected] | af6efb2 | 2012-10-12 02:23:05 | [diff] [blame] | 517 | client_->ConfirmInstall(this, extension_.get(), show_dialog_callback_); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 518 | } else { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 519 | if (!installer_task_runner_->PostTask( |
| 520 | FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 521 | base::Bind(&CrxInstaller::CompleteInstall, this))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 522 | NOTREACHED(); |
[email protected] | 6b75ec3 | 2009-08-14 06:37:18 | [diff] [blame] | 523 | } |
| 524 | return; |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 525 | } |
| 526 | |
[email protected] | ba9c96c6 | 2010-09-14 02:38:02 | [diff] [blame] | 527 | void CrxInstaller::InstallUIProceed() { |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 528 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 529 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 530 | if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
| 531 | return; |
| 532 | |
| 533 | // If update_from_settings_page_ boolean is true, this functions is |
| 534 | // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() |
| 535 | // and if it is false, this function is called in response to |
| 536 | // ExtensionInstallPrompt::ConfirmInstall(). |
| 537 | if (update_from_settings_page_) { |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 538 | frontend_weak_->GrantPermissionsAndEnableExtension(extension_.get()); |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 539 | } else { |
| 540 | if (!installer_task_runner_->PostTask( |
| 541 | FROM_HERE, |
| 542 | base::Bind(&CrxInstaller::CompleteInstall, this))) |
| 543 | NOTREACHED(); |
| 544 | } |
| 545 | |
| 546 | Release(); // balanced in ConfirmInstall() or ConfirmReEnable(). |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 547 | } |
| 548 | |
[email protected] | d828fac | 2011-06-28 05:43:04 | [diff] [blame] | 549 | void CrxInstaller::InstallUIAbort(bool user_initiated) { |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 550 | // If update_from_settings_page_ boolean is true, this functions is |
| 551 | // getting called in response to ExtensionInstallPrompt::ConfirmReEnable() |
| 552 | // and if it is false, this function is called in response to |
| 553 | // ExtensionInstallPrompt::ConfirmInstall(). |
| 554 | if (!update_from_settings_page_) { |
| 555 | std::string histogram_name = user_initiated ? |
| 556 | "Extensions.Permissions_InstallCancel" : |
| 557 | "Extensions.Permissions_InstallAbort"; |
| 558 | ExtensionService::RecordPermissionMessagesHistogram( |
| 559 | extension_, histogram_name.c_str()); |
[email protected] | fe2dd774 | 2011-04-19 22:52:49 | [diff] [blame] | 560 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 561 | // Kill the theme loading bubble. |
| 562 | content::NotificationService* service = |
| 563 | content::NotificationService::current(); |
| 564 | service->Notify(chrome::NOTIFICATION_NO_THEME_DETECTED, |
| 565 | content::Source<CrxInstaller>(this), |
| 566 | content::NotificationService::NoDetails()); |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 567 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 568 | NotifyCrxInstallComplete(false); |
| 569 | } |
[email protected] | 052ec1a3e | 2011-06-06 14:12:48 | [diff] [blame] | 570 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 571 | Release(); // balanced in ConfirmInstall() or ConfirmReEnable(). |
[email protected] | c544be5 | 2012-07-17 01:08:37 | [diff] [blame] | 572 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 573 | // We're done. Since we don't post any more tasks to ourself, our ref count |
| 574 | // should go to zero and we die. The destructor will clean up the temp dir. |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | void CrxInstaller::CompleteInstall() { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 578 | DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 579 | |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 580 | if (!current_version_.empty()) { |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 581 | Version current_version(current_version_); |
| 582 | if (current_version.CompareTo(*(extension_->version())) > 0) { |
[email protected] | 30e10d88 | 2011-04-22 19:36:29 | [diff] [blame] | 583 | ReportFailureFromFileThread( |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 584 | CrxInstallerError( |
[email protected] | bf71eb7 | 2012-09-13 20:29:28 | [diff] [blame] | 585 | l10n_util::GetStringUTF16(extension_->is_app() ? |
| 586 | IDS_APP_CANT_DOWNGRADE_VERSION : |
| 587 | IDS_EXTENSION_CANT_DOWNGRADE_VERSION))); |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 588 | return; |
| 589 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 590 | } |
| 591 | |
[email protected] | 394dc47 | 2011-04-14 15:57:19 | [diff] [blame] | 592 | // See how long extension install paths are. This is important on |
| 593 | // windows, because file operations may fail if the path to a file |
| 594 | // exceeds a small constant. See crbug.com/69693 . |
| 595 | UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 596 | "Extensions.CrxInstallDirPathLength", |
| 597 | install_directory_.value().length(), 0, 500, 100); |
| 598 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 599 | base::FilePath version_dir = extension_file_util::InstallExtension( |
[email protected] | ca3dbf5 | 2010-05-19 22:27:06 | [diff] [blame] | 600 | unpacked_extension_root_, |
| 601 | extension_->id(), |
| 602 | extension_->VersionString(), |
| 603 | install_directory_); |
| 604 | if (version_dir.empty()) { |
| 605 | ReportFailureFromFileThread( |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 606 | CrxInstallerError( |
| 607 | l10n_util::GetStringUTF16( |
| 608 | IDS_EXTENSION_MOVE_DIRECTORY_TO_PROFILE_FAILED))); |
[email protected] | b6ab96d | 2009-08-20 18:58:19 | [diff] [blame] | 609 | return; |
| 610 | } |
| 611 | |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 612 | // This is lame, but we must reload the extension because absolute paths |
| 613 | // inside the content scripts are established inside InitFromValue() and we |
| 614 | // just moved the extension. |
| 615 | // TODO(aa): All paths to resources inside extensions should be created |
| 616 | // lazily and based on the Extension's root path at that moment. |
[email protected] | fc67082 | 2011-12-17 09:33:49 | [diff] [blame] | 617 | // TODO(rdevlin.cronin): Continue removing std::string errors and replacing |
| 618 | // with string16 |
[email protected] | 7c6de19b | 2012-08-28 04:07:13 | [diff] [blame] | 619 | std::string extension_id = extension_->id(); |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 620 | std::string error; |
[email protected] | 66e4eb3 | 2010-10-27 20:37:41 | [diff] [blame] | 621 | extension_ = extension_file_util::LoadExtension( |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 622 | version_dir, |
| 623 | install_source_, |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 624 | extension_->creation_flags() | Extension::REQUIRE_KEY, |
[email protected] | 542258c | 2011-03-04 21:25:31 | [diff] [blame] | 625 | &error); |
[email protected] | 7c6de19b | 2012-08-28 04:07:13 | [diff] [blame] | 626 | |
[email protected] | 6d8c388 | 2012-09-05 02:19:44 | [diff] [blame] | 627 | if (extension_) { |
| 628 | ReportSuccessFromFileThread(); |
| 629 | } else { |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 630 | LOG(ERROR) << error << " " << extension_id << " " << download_url_; |
[email protected] | 6d8c388 | 2012-09-05 02:19:44 | [diff] [blame] | 631 | ReportFailureFromFileThread(CrxInstallerError(UTF8ToUTF16(error))); |
| 632 | } |
[email protected] | d281701 | 2009-08-04 06:46:21 | [diff] [blame] | 633 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 636 | void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 637 | DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 638 | if (!BrowserThread::PostTask( |
| 639 | BrowserThread::UI, FROM_HERE, |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 640 | base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 641 | NOTREACHED(); |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 642 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 643 | } |
| 644 | |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 645 | void CrxInstaller::ReportFailureFromUIThread(const CrxInstallerError& error) { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 646 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 647 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 648 | content::NotificationService* service = |
| 649 | content::NotificationService::current(); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 650 | service->Notify(chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 651 | content::Source<CrxInstaller>(this), |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 652 | content::Details<const string16>(&error.message())); |
[email protected] | 9f3a59f | 2009-09-03 23:13:07 | [diff] [blame] | 653 | |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 654 | // This isn't really necessary, it is only used because unit tests expect to |
| 655 | // see errors get reported via this interface. |
| 656 | // |
| 657 | // TODO(aa): Need to go through unit tests and clean them up too, probably get |
| 658 | // rid of this line. |
[email protected] | 4eaf0b3 | 2012-06-19 06:33:28 | [diff] [blame] | 659 | ExtensionErrorReporter::GetInstance()->ReportError( |
| 660 | error.message(), false); // quiet |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 661 | |
[email protected] | 765b7ea5 | 2010-03-30 03:40:34 | [diff] [blame] | 662 | if (client_) |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 663 | client_->OnInstallFailure(error); |
[email protected] | f9725c2 | 2011-05-25 14:40:33 | [diff] [blame] | 664 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 665 | NotifyCrxInstallComplete(false); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 666 | |
| 667 | // Delete temporary files. |
| 668 | CleanupTempFiles(); |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 669 | } |
| 670 | |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 671 | void CrxInstaller::ReportSuccessFromFileThread() { |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 672 | DCHECK(installer_task_runner_->RunsTasksOnCurrentThread()); |
[email protected] | 333b1de | 2011-09-12 18:28:50 | [diff] [blame] | 673 | |
| 674 | // Tracking number of extensions installed by users |
[email protected] | 754bc6e | 2012-10-22 22:26:13 | [diff] [blame] | 675 | if (install_cause() == extension_misc::INSTALL_CAUSE_USER_DOWNLOAD) |
[email protected] | 49098f70 | 2011-10-13 03:47:18 | [diff] [blame] | 676 | UMA_HISTOGRAM_ENUMERATION("Extensions.ExtensionInstalled", 1, 2); |
| 677 | |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 678 | if (!BrowserThread::PostTask( |
| 679 | BrowserThread::UI, FROM_HERE, |
[email protected] | 53612e8 | 2011-10-18 18:00:36 | [diff] [blame] | 680 | base::Bind(&CrxInstaller::ReportSuccessFromUIThread, this))) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 681 | NOTREACHED(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 682 | |
| 683 | // Delete temporary files. |
| 684 | CleanupTempFiles(); |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | void CrxInstaller::ReportSuccessFromUIThread() { |
[email protected] | ca4b5fa3 | 2010-10-09 12:42:18 | [diff] [blame] | 688 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 689 | |
[email protected] | b80ec46 | 2012-10-30 18:53:00 | [diff] [blame] | 690 | if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
[email protected] | 14908b7 | 2011-04-20 06:54:36 | [diff] [blame] | 691 | return; |
| 692 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 693 | if (!update_from_settings_page_) { |
| 694 | // If there is a client, tell the client about installation. |
| 695 | if (client_) |
| 696 | client_->OnInstallSuccess(extension_.get(), install_icon_.get()); |
[email protected] | 2a464a9 | 2009-08-01 17:58:35 | [diff] [blame] | 697 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 698 | // We update the extension's granted permissions if the user already |
| 699 | // approved the install (client_ is non NULL), or we are allowed to install |
| 700 | // this silently. |
| 701 | if (client_ || allow_silent_install_) { |
| 702 | PermissionsUpdater perms_updater(profile()); |
[email protected] | 009633c | 2013-03-07 22:08:28 | [diff] [blame] | 703 | perms_updater.GrantActivePermissions(extension_); |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 704 | } |
[email protected] | c333e79 | 2012-01-06 16:57:39 | [diff] [blame] | 705 | } |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 706 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 707 | // Install the extension if it's not blacklisted, but notify either way. |
| 708 | base::Closure on_success = |
| 709 | base::Bind(&ExtensionService::OnExtensionInstalled, |
| 710 | frontend_weak_, |
| 711 | extension_, |
| 712 | page_ordinal_, |
| 713 | has_requirement_errors_, |
| 714 | install_wait_for_idle_); |
| 715 | if (bypass_blacklist_for_test_) { |
| 716 | HandleIsBlacklistedResponse(on_success, false); |
| 717 | } else { |
| 718 | ExtensionSystem::Get(profile_)->blacklist()->IsBlacklisted( |
| 719 | extension_->id(), |
| 720 | base::Bind(&CrxInstaller::HandleIsBlacklistedResponse, |
| 721 | this, |
| 722 | on_success)); |
| 723 | } |
[email protected] | 7577a5c5 | 2009-07-30 06:21:58 | [diff] [blame] | 724 | } |
[email protected] | f9725c2 | 2011-05-25 14:40:33 | [diff] [blame] | 725 | |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 726 | void CrxInstaller::HandleIsBlacklistedResponse( |
| 727 | const base::Closure& on_success, |
| 728 | bool is_blacklisted) { |
| 729 | if (is_blacklisted) { |
| 730 | string16 error = |
| 731 | l10n_util::GetStringFUTF16(IDS_EXTENSION_IS_BLACKLISTED, |
| 732 | UTF8ToUTF16(extension_->name())); |
| 733 | make_scoped_ptr(ExtensionInstallUI::Create(profile()))->OnInstallFailure( |
| 734 | extensions::CrxInstallerError(error)); |
| 735 | // Show error via reporter to make tests happy. |
| 736 | ExtensionErrorReporter::GetInstance()->ReportError(error, false); // quiet |
[email protected] | ac87537 | 2013-02-28 04:36:09 | [diff] [blame] | 737 | UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlockCRX", |
| 738 | extension_->location(), Manifest::NUM_LOCATIONS); |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 739 | } else { |
| 740 | on_success.Run(); |
| 741 | } |
| 742 | NotifyCrxInstallComplete(!is_blacklisted); |
| 743 | } |
| 744 | |
| 745 | void CrxInstaller::NotifyCrxInstallComplete(bool success) { |
[email protected] | f9725c2 | 2011-05-25 14:40:33 | [diff] [blame] | 746 | // Some users (such as the download shelf) need to know when a |
| 747 | // CRXInstaller is done. Listening for the EXTENSION_* events |
| 748 | // is problematic because they don't know anything about the |
[email protected] | 84f4dc0 | 2011-11-29 21:58:26 | [diff] [blame] | 749 | // extension before it is unpacked, so they cannot filter based |
[email protected] | f9725c2 | 2011-05-25 14:40:33 | [diff] [blame] | 750 | // on the extension. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 751 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 752 | chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 753 | content::Source<CrxInstaller>(this), |
[email protected] | bc151cf9 | 2013-02-12 04:57:26 | [diff] [blame] | 754 | content::Details<const Extension>(success ? extension_.get() : NULL)); |
| 755 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 756 | if (success) |
| 757 | ConfirmReEnable(); |
| 758 | |
[email protected] | f9725c2 | 2011-05-25 14:40:33 | [diff] [blame] | 759 | } |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 760 | |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 761 | void CrxInstaller::CleanupTempFiles() { |
| 762 | if (!installer_task_runner_->RunsTasksOnCurrentThread()) { |
| 763 | if (!installer_task_runner_->PostTask( |
| 764 | FROM_HERE, |
| 765 | base::Bind(&CrxInstaller::CleanupTempFiles, this))) { |
| 766 | NOTREACHED(); |
| 767 | } |
| 768 | return; |
| 769 | } |
| 770 | |
| 771 | // Delete the temp directory and crx file as necessary. |
| 772 | if (!temp_dir_.value().empty()) { |
| 773 | extension_file_util::DeleteFile(temp_dir_, true); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 774 | temp_dir_ = base::FilePath(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | if (delete_source_ && !source_file_.value().empty()) { |
| 778 | extension_file_util::DeleteFile(source_file_, false); |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 779 | source_file_ = base::FilePath(); |
[email protected] | 7f8f24f | 2012-11-15 19:40:14 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
[email protected] | b86b9ee | 2013-03-01 01:58:29 | [diff] [blame] | 783 | void CrxInstaller::CheckUpdateFromSettingsPage() { |
| 784 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 785 | |
| 786 | if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
| 787 | return; |
| 788 | |
| 789 | if (off_store_install_allow_reason_ != OffStoreInstallAllowedFromSettingsPage) |
| 790 | return; |
| 791 | |
| 792 | const Extension* installed_extension = |
| 793 | frontend_weak_->GetInstalledExtension(extension_->id()); |
| 794 | if (installed_extension) { |
| 795 | // Previous version of the extension exists. |
| 796 | update_from_settings_page_ = true; |
| 797 | expected_id_ = installed_extension->id(); |
| 798 | install_source_ = installed_extension->location(); |
| 799 | install_cause_ = extension_misc::INSTALL_CAUSE_UPDATE; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | void CrxInstaller::ConfirmReEnable() { |
| 804 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 805 | |
| 806 | if (!frontend_weak_.get() || frontend_weak_->browser_terminating()) |
| 807 | return; |
| 808 | |
| 809 | if (!update_from_settings_page_) |
| 810 | return; |
| 811 | |
| 812 | extensions::ExtensionPrefs* prefs = frontend_weak_->extension_prefs(); |
| 813 | if (!prefs->DidExtensionEscalatePermissions(extension_->id())) |
| 814 | return; |
| 815 | |
| 816 | if (client_) { |
| 817 | AddRef(); // Balanced in InstallUIProceed() and InstallUIAbort(). |
| 818 | client_->ConfirmReEnable(this, extension_.get()); |
| 819 | } |
| 820 | } |
| 821 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 822 | } // namespace extensions |