| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/unpacked_installer.h" | 5 #include "chrome/browser/extensions/unpacked_installer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
| 12 #include "chrome/browser/extensions/extension_error_reporter.h" | 12 #include "chrome/browser/extensions/extension_error_reporter.h" |
| 13 #include "chrome/browser/extensions/extension_install_prompt.h" | 13 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 14 #include "chrome/browser/extensions/extension_management.h" | 14 #include "chrome/browser/extensions/extension_management.h" |
| 15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/permissions_updater.h" | 16 #include "chrome/browser/extensions/permissions_updater.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" | 18 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
| 19 #include "chrome/common/extensions/api/plugins/plugins_handler.h" | 19 #include "chrome/common/extensions/api/plugins/plugins_handler.h" |
| 20 #include "components/crx_file/id_util.h" | 20 #include "components/crx_file/id_util.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 base::ThreadRestrictions::ScopedAllowIO allow_io; | 142 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 143 | 143 |
| 144 extension_path_ = base::MakeAbsoluteFilePath(path_in); | 144 extension_path_ = base::MakeAbsoluteFilePath(path_in); |
| 145 | 145 |
| 146 if (!IsLoadingUnpackedAllowed()) { | 146 if (!IsLoadingUnpackedAllowed()) { |
| 147 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); | 147 ReportExtensionLoadError(kUnpackedExtensionsBlacklistedError); |
| 148 return false; | 148 return false; |
| 149 } | 149 } |
| 150 | 150 |
| 151 std::string error; | 151 std::string error; |
| 152 install_checker_.set_extension( | 152 extension_ = |
| 153 file_util::LoadExtension( | 153 file_util::LoadExtension( |
| 154 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error).get()); | 154 extension_path_, Manifest::COMMAND_LINE, GetFlags(), &error); |
| 155 | 155 |
| 156 if (!extension() || | 156 if (!extension_ || |
| 157 !extension_l10n_util::ValidateExtensionLocales( | 157 !extension_l10n_util::ValidateExtensionLocales( |
| 158 extension_path_, extension()->manifest()->value(), &error)) { | 158 extension_path_, extension_->manifest()->value(), &error)) { |
| 159 ReportExtensionLoadError(error); | 159 ReportExtensionLoadError(error); |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (only_allow_apps && !extension()->is_platform_app()) { | 163 if (only_allow_apps && !extension_->is_platform_app()) { |
| 164 #if defined(GOOGLE_CHROME_BUILD) | 164 #if defined(GOOGLE_CHROME_BUILD) |
| 165 // Avoid crashing for users with hijacked shortcuts. | 165 // Avoid crashing for users with hijacked shortcuts. |
| 166 return true; | 166 return true; |
| 167 #else | 167 #else |
| 168 // Defined here to avoid unused variable errors in official builds. | 168 // Defined here to avoid unused variable errors in official builds. |
| 169 const char extension_instead_of_app_error[] = | 169 const char extension_instead_of_app_error[] = |
| 170 "App loading flags cannot be used to load extensions. Please use " | 170 "App loading flags cannot be used to load extensions. Please use " |
| 171 "--load-extension instead."; | 171 "--load-extension instead."; |
| 172 ReportExtensionLoadError(extension_instead_of_app_error); | 172 ReportExtensionLoadError(extension_instead_of_app_error); |
| 173 return false; | 173 return false; |
| 174 #endif | 174 #endif |
| 175 } | 175 } |
| 176 | 176 |
| 177 extension()->permissions_data()->BindToCurrentThread(); | 177 extension_->permissions_data()->BindToCurrentThread(); |
| 178 PermissionsUpdater( | 178 PermissionsUpdater( |
| 179 service_weak_->profile(), PermissionsUpdater::INIT_FLAG_TRANSIENT) | 179 service_weak_->profile(), PermissionsUpdater::INIT_FLAG_TRANSIENT) |
| 180 .InitializePermissions(extension()); | 180 .InitializePermissions(extension_.get()); |
| 181 ShowInstallPrompt(); | 181 ShowInstallPrompt(); |
| 182 | 182 |
| 183 *extension_id = extension()->id(); | 183 *extension_id = extension_->id(); |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 void UnpackedInstaller::ShowInstallPrompt() { | 187 void UnpackedInstaller::ShowInstallPrompt() { |
| 188 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 188 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 189 if (!service_weak_.get()) | 189 if (!service_weak_.get()) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 const ExtensionSet& disabled_extensions = | 192 const ExtensionSet& disabled_extensions = |
| 193 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); | 193 ExtensionRegistry::Get(service_weak_->profile())->disabled_extensions(); |
| 194 if (prompt_for_plugins_ && | 194 if (prompt_for_plugins_ && |
| 195 PluginInfo::HasPlugins(extension()) && | 195 PluginInfo::HasPlugins(extension_.get()) && |
| 196 !disabled_extensions.Contains(extension()->id())) { | 196 !disabled_extensions.Contains(extension_->id())) { |
| 197 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( | 197 SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt( |
| 198 extension(), | 198 extension_.get(), |
| 199 install_checker_.profile(), | 199 install_checker_.profile(), |
| 200 base::Bind(&UnpackedInstaller::StartInstallChecks, this)); | 200 base::Bind(&UnpackedInstaller::StartInstallChecks, this)); |
| 201 prompt->ShowPrompt(); | 201 prompt->ShowPrompt(); |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 StartInstallChecks(); | 204 StartInstallChecks(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void UnpackedInstaller::StartInstallChecks() { | 207 void UnpackedInstaller::StartInstallChecks() { |
| 208 // TODO(crbug.com/421128): Enable these checks all the time. The reason | 208 // TODO(crbug.com/421128): Enable these checks all the time. The reason |
| 209 // they are disabled for extensions loaded from the command-line is that | 209 // they are disabled for extensions loaded from the command-line is that |
| 210 // installing unpacked extensions is asynchronous, but there can be | 210 // installing unpacked extensions is asynchronous, but there can be |
| 211 // dependencies between the extensions loaded by the command line. | 211 // dependencies between the extensions loaded by the command line. |
| 212 if (extension()->manifest()->location() != Manifest::COMMAND_LINE) { | 212 if (extension_->manifest()->location() != Manifest::COMMAND_LINE) { |
| 213 ExtensionService* service = service_weak_.get(); | 213 ExtensionService* service = service_weak_.get(); |
| 214 if (!service || service->browser_terminating()) | 214 if (!service || service->browser_terminating()) |
| 215 return; | 215 return; |
| 216 | 216 |
| 217 // TODO(crbug.com/420147): Move this code to a utility class to avoid | 217 // TODO(crbug.com/420147): Move this code to a utility class to avoid |
| 218 // duplication of SharedModuleService::CheckImports code. | 218 // duplication of SharedModuleService::CheckImports code. |
| 219 if (SharedModuleInfo::ImportsModules(extension())) { | 219 if (SharedModuleInfo::ImportsModules(extension_.get())) { |
| 220 const std::vector<SharedModuleInfo::ImportInfo>& imports = | 220 const std::vector<SharedModuleInfo::ImportInfo>& imports = |
| 221 SharedModuleInfo::GetImports(extension()); | 221 SharedModuleInfo::GetImports(extension_.get()); |
| 222 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i; | 222 std::vector<SharedModuleInfo::ImportInfo>::const_iterator i; |
| 223 for (i = imports.begin(); i != imports.end(); ++i) { | 223 for (i = imports.begin(); i != imports.end(); ++i) { |
| 224 base::Version version_required(i->minimum_version); | 224 base::Version version_required(i->minimum_version); |
| 225 const Extension* imported_module = | 225 const Extension* imported_module = |
| 226 service->GetExtensionById(i->extension_id, true); | 226 service->GetExtensionById(i->extension_id, true); |
| 227 if (!imported_module) { | 227 if (!imported_module) { |
| 228 ReportExtensionLoadError(kImportMissing); | 228 ReportExtensionLoadError(kImportMissing); |
| 229 return; | 229 return; |
| 230 } else if (imported_module && | 230 } else if (imported_module && |
| 231 !SharedModuleInfo::IsSharedModule(imported_module)) { | 231 !SharedModuleInfo::IsSharedModule(imported_module)) { |
| 232 ReportExtensionLoadError(kImportNotSharedModule); | 232 ReportExtensionLoadError(kImportNotSharedModule); |
| 233 return; | 233 return; |
| 234 } else if (imported_module && (version_required.IsValid() && | 234 } else if (imported_module && (version_required.IsValid() && |
| 235 imported_module->version()->CompareTo( | 235 imported_module->version()->CompareTo( |
| 236 version_required) < 0)) { | 236 version_required) < 0)) { |
| 237 ReportExtensionLoadError(kImportMinVersionNewer); | 237 ReportExtensionLoadError(kImportMinVersionNewer); |
| 238 return; | 238 return; |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 install_checker_.Start( | 244 install_checker_.Start( |
| 245 extension_, |
| 245 ExtensionInstallChecker::CHECK_REQUIREMENTS | | 246 ExtensionInstallChecker::CHECK_REQUIREMENTS | |
| 246 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | 247 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, |
| 247 true /* fail fast */, | 248 true /* fail fast */, |
| 248 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this)); | 249 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this)); |
| 249 } | 250 } |
| 250 | 251 |
| 251 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) { | 252 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) { |
| 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 253 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 253 | 254 |
| 254 if (!install_checker_.policy_error().empty()) { | 255 if (!install_checker_.policy_error().empty()) { |
| 255 ReportExtensionLoadError(install_checker_.policy_error()); | 256 ReportExtensionLoadError( |
| 257 base::UTF16ToUTF8(install_checker_.policy_error())); |
| 256 return; | 258 return; |
| 257 } | 259 } |
| 258 | 260 |
| 259 if (!install_checker_.requirement_errors().empty()) { | 261 if (!install_checker_.requirement_error_message().empty()) { |
| 260 ReportExtensionLoadError( | 262 ReportExtensionLoadError( |
| 261 base::JoinString(install_checker_.requirement_errors(), " ")); | 263 base::UTF16ToUTF8(install_checker_.requirement_error_message())); |
| 262 return; | 264 return; |
| 263 } | 265 } |
| 264 | 266 |
| 265 InstallExtension(); | 267 InstallExtension(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 int UnpackedInstaller::GetFlags() { | 270 int UnpackedInstaller::GetFlags() { |
| 269 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_); | 271 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_); |
| 270 bool allow_file_access = | 272 bool allow_file_access = |
| 271 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); | 273 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 BrowserThread::PostTask( | 324 BrowserThread::PostTask( |
| 323 BrowserThread::FILE, | 325 BrowserThread::FILE, |
| 324 FROM_HERE, | 326 FROM_HERE, |
| 325 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); | 327 base::Bind(&UnpackedInstaller::LoadWithFileAccess, this, GetFlags())); |
| 326 } | 328 } |
| 327 | 329 |
| 328 void UnpackedInstaller::LoadWithFileAccess(int flags) { | 330 void UnpackedInstaller::LoadWithFileAccess(int flags) { |
| 329 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 331 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 330 | 332 |
| 331 std::string error; | 333 std::string error; |
| 332 install_checker_.set_extension( | 334 extension_ = |
| 333 file_util::LoadExtension( | 335 file_util::LoadExtension( |
| 334 extension_path_, Manifest::UNPACKED, flags, &error).get()); | 336 extension_path_, Manifest::UNPACKED, flags, &error); |
| 335 | 337 |
| 336 if (!extension() || | 338 if (!extension_ || |
| 337 !extension_l10n_util::ValidateExtensionLocales( | 339 !extension_l10n_util::ValidateExtensionLocales( |
| 338 extension_path_, extension()->manifest()->value(), &error)) { | 340 extension_path_, extension_->manifest()->value(), &error)) { |
| 339 BrowserThread::PostTask( | 341 BrowserThread::PostTask( |
| 340 BrowserThread::UI, | 342 BrowserThread::UI, |
| 341 FROM_HERE, | 343 FROM_HERE, |
| 342 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); | 344 base::Bind(&UnpackedInstaller::ReportExtensionLoadError, this, error)); |
| 343 return; | 345 return; |
| 344 } | 346 } |
| 345 | 347 |
| 346 BrowserThread::PostTask( | 348 BrowserThread::PostTask( |
| 347 BrowserThread::UI, | 349 BrowserThread::UI, |
| 348 FROM_HERE, | 350 FROM_HERE, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 368 | 370 |
| 369 void UnpackedInstaller::InstallExtension() { | 371 void UnpackedInstaller::InstallExtension() { |
| 370 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 372 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 371 | 373 |
| 372 if (!service_weak_.get()) { | 374 if (!service_weak_.get()) { |
| 373 callback_.Reset(); | 375 callback_.Reset(); |
| 374 return; | 376 return; |
| 375 } | 377 } |
| 376 | 378 |
| 377 PermissionsUpdater perms_updater(service_weak_->profile()); | 379 PermissionsUpdater perms_updater(service_weak_->profile()); |
| 378 perms_updater.InitializePermissions(extension()); | 380 perms_updater.InitializePermissions(extension_.get()); |
| 379 perms_updater.GrantActivePermissions(extension()); | 381 perms_updater.GrantActivePermissions(extension_.get()); |
| 380 | 382 |
| 381 service_weak_->OnExtensionInstalled( | 383 service_weak_->OnExtensionInstalled( |
| 382 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 384 extension_.get(), syncer::StringOrdinal(), kInstallFlagInstallImmediately)
; |
| 383 | 385 |
| 384 if (!callback_.is_null()) { | 386 if (!callback_.is_null()) { |
| 385 callback_.Run(extension(), extension_path_, std::string()); | 387 callback_.Run(extension_.get(), extension_path_, std::string()); |
| 386 callback_.Reset(); | 388 callback_.Reset(); |
| 387 } | 389 } |
| 388 } | 390 } |
| 389 | 391 |
| 390 } // namespace extensions | 392 } // namespace extensions |
| OLD | NEW |