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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "chrome/browser/extensions/extension_error_reporter.h" | 15 #include "chrome/browser/extensions/extension_error_reporter.h" |
16 #include "chrome/browser/extensions/extension_install_checker.h" | |
17 #include "chrome/browser/extensions/extension_install_prompt.h" | 16 #include "chrome/browser/extensions/extension_install_prompt.h" |
18 #include "chrome/browser/extensions/extension_management.h" | 17 #include "chrome/browser/extensions/extension_management.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/permissions_updater.h" | 19 #include "chrome/browser/extensions/permissions_updater.h" |
21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" | 21 #include "chrome/browser/ui/extensions/extension_install_ui_factory.h" |
23 #include "components/crx_file/id_util.h" | 22 #include "components/crx_file/id_util.h" |
24 #include "components/sync/model/string_ordinal.h" | 23 #include "components/sync/model/string_ordinal.h" |
25 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
26 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
27 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
28 #include "extensions/browser/install/extension_install_ui.h" | 27 #include "extensions/browser/install/extension_install_ui.h" |
29 #include "extensions/browser/install_flag.h" | 28 #include "extensions/browser/install_flag.h" |
| 29 #include "extensions/browser/policy_check.h" |
| 30 #include "extensions/browser/preload_check_group.h" |
| 31 #include "extensions/browser/requirements_checker.h" |
30 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
31 #include "extensions/common/extension_l10n_util.h" | 33 #include "extensions/common/extension_l10n_util.h" |
32 #include "extensions/common/file_util.h" | 34 #include "extensions/common/file_util.h" |
33 #include "extensions/common/manifest.h" | 35 #include "extensions/common/manifest.h" |
34 #include "extensions/common/manifest_handlers/plugins_handler.h" | 36 #include "extensions/common/manifest_handlers/plugins_handler.h" |
35 #include "extensions/common/manifest_handlers/shared_module_info.h" | 37 #include "extensions/common/manifest_handlers/shared_module_info.h" |
36 #include "extensions/common/permissions/permissions_data.h" | 38 #include "extensions/common/permissions/permissions_data.h" |
37 | 39 |
38 using content::BrowserThread; | 40 using content::BrowserThread; |
39 using extensions::Extension; | 41 using extensions::Extension; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } else if (imported_module && (version_required.IsValid() && | 238 } else if (imported_module && (version_required.IsValid() && |
237 imported_module->version()->CompareTo( | 239 imported_module->version()->CompareTo( |
238 version_required) < 0)) { | 240 version_required) < 0)) { |
239 ReportExtensionLoadError(kImportMinVersionNewer); | 241 ReportExtensionLoadError(kImportMinVersionNewer); |
240 return; | 242 return; |
241 } | 243 } |
242 } | 244 } |
243 } | 245 } |
244 } | 246 } |
245 | 247 |
246 install_checker_ = base::MakeUnique<ExtensionInstallChecker>( | 248 policy_check_ = base::MakeUnique<PolicyCheck>(profile_, extension_); |
247 profile_, extension_, | 249 requirements_check_ = base::MakeUnique<RequirementsChecker>(extension_); |
248 ExtensionInstallChecker::CHECK_REQUIREMENTS | | 250 |
249 ExtensionInstallChecker::CHECK_MANAGEMENT_POLICY, | 251 check_group_ = base::MakeUnique<PreloadCheckGroup>(); |
250 true /* fail fast */); | 252 check_group_->set_stop_on_first_error(true); |
251 install_checker_->Start( | 253 |
252 base::Bind(&UnpackedInstaller::OnInstallChecksComplete, this)); | 254 check_group_->AddCheck(policy_check_.get()); |
| 255 check_group_->AddCheck(requirements_check_.get()); |
| 256 check_group_->Start( |
| 257 base::BindOnce(&UnpackedInstaller::OnInstallChecksComplete, this)); |
253 } | 258 } |
254 | 259 |
255 void UnpackedInstaller::OnInstallChecksComplete(int failed_checks) { | 260 void UnpackedInstaller::OnInstallChecksComplete(PreloadCheck::Errors errors) { |
256 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 261 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
257 | 262 |
258 base::string16 error_message = install_checker_->policy_error(); | 263 if (errors.empty()) { |
259 if (error_message.empty()) | 264 InstallExtension(); |
260 error_message = install_checker_->requirements_error_message(); | |
261 | |
262 if (!error_message.empty()) { | |
263 ReportExtensionLoadError(base::UTF16ToUTF8(error_message)); | |
264 return; | 265 return; |
265 } | 266 } |
266 | 267 |
267 InstallExtension(); | 268 base::string16 error_message; |
| 269 if (errors.count(PreloadCheck::DISALLOWED_BY_POLICY)) |
| 270 error_message = policy_check_->GetErrorMessage(); |
| 271 else |
| 272 error_message = requirements_check_->GetErrorMessage(); |
| 273 |
| 274 DCHECK(!error_message.empty()); |
| 275 ReportExtensionLoadError(base::UTF16ToUTF8(error_message)); |
268 } | 276 } |
269 | 277 |
270 int UnpackedInstaller::GetFlags() { | 278 int UnpackedInstaller::GetFlags() { |
271 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_); | 279 std::string id = crx_file::id_util::GenerateIdForPath(extension_path_); |
272 bool allow_file_access = | 280 bool allow_file_access = |
273 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); | 281 Manifest::ShouldAlwaysAllowFileAccess(Manifest::UNPACKED); |
274 ExtensionPrefs* prefs = ExtensionPrefs::Get(service_weak_->profile()); | 282 ExtensionPrefs* prefs = ExtensionPrefs::Get(service_weak_->profile()); |
275 if (prefs->HasAllowFileAccessSetting(id)) | 283 if (prefs->HasAllowFileAccessSetting(id)) |
276 allow_file_access = prefs->AllowFileAccess(id); | 284 allow_file_access = prefs->AllowFileAccess(id); |
277 | 285 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 service_weak_->OnExtensionInstalled( | 390 service_weak_->OnExtensionInstalled( |
383 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); | 391 extension(), syncer::StringOrdinal(), kInstallFlagInstallImmediately); |
384 | 392 |
385 if (!callback_.is_null()) { | 393 if (!callback_.is_null()) { |
386 callback_.Run(extension(), extension_path_, std::string()); | 394 callback_.Run(extension(), extension_path_, std::string()); |
387 callback_.Reset(); | 395 callback_.Reset(); |
388 } | 396 } |
389 } | 397 } |
390 | 398 |
391 } // namespace extensions | 399 } // namespace extensions |
OLD | NEW |