Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/browser/extensions/crx_installer.cc

Issue 10689097: Enforce the 'requirements' field in manifests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: recheck on enable Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/scoped_temp_dir.h" 16 #include "base/scoped_temp_dir.h"
17 #include "base/stl_util.h" 17 #include "base/string_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/version.h" 22 #include "base/version.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/extensions/convert_user_script.h" 24 #include "chrome/browser/extensions/convert_user_script.h"
25 #include "chrome/browser/extensions/convert_web_app.h" 25 #include "chrome/browser/extensions/convert_web_app.h"
26 #include "chrome/browser/extensions/default_apps_trial.h" 26 #include "chrome/browser/extensions/default_apps_trial.h"
27 #include "chrome/browser/extensions/extension_error_reporter.h" 27 #include "chrome/browser/extensions/extension_error_reporter.h"
28 #include "chrome/browser/extensions/extension_install_ui.h" 28 #include "chrome/browser/extensions/extension_install_ui.h"
29 #include "chrome/browser/extensions/extension_service.h" 29 #include "chrome/browser/extensions/extension_service.h"
30 #include "chrome/browser/extensions/extension_system.h" 30 #include "chrome/browser/extensions/extension_system.h"
31 #include "chrome/browser/extensions/permissions_updater.h" 31 #include "chrome/browser/extensions/permissions_updater.h"
32 #include "chrome/browser/extensions/requirements_checker.h"
32 #include "chrome/browser/extensions/webstore_installer.h" 33 #include "chrome/browser/extensions/webstore_installer.h"
33 #include "chrome/browser/profiles/profile.h" 34 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/shell_integration.h" 35 #include "chrome/browser/shell_integration.h"
35 #include "chrome/browser/web_applications/web_app.h" 36 #include "chrome/browser/web_applications/web_app.h"
36 #include "chrome/common/chrome_notification_types.h" 37 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/extensions/extension_constants.h" 39 #include "chrome/common/extensions/extension_constants.h"
39 #include "chrome/common/extensions/extension_file_util.h" 40 #include "chrome/common/extensions/extension_file_util.h"
40 #include "chrome/common/extensions/extension_icon_set.h" 41 #include "chrome/common/extensions/extension_icon_set.h"
41 #include "chrome/common/extensions/extension_switch_utils.h" 42 #include "chrome/common/extensions/extension_switch_utils.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 create_app_shortcut_(false), 95 create_app_shortcut_(false),
95 frontend_weak_(frontend_weak), 96 frontend_weak_(frontend_weak),
96 profile_(frontend_weak->profile()), 97 profile_(frontend_weak->profile()),
97 client_(client), 98 client_(client),
98 apps_require_extension_mime_type_(false), 99 apps_require_extension_mime_type_(false),
99 allow_silent_install_(false), 100 allow_silent_install_(false),
100 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), 101 install_cause_(extension_misc::INSTALL_CAUSE_UNSET),
101 creation_flags_(Extension::NO_FLAGS), 102 creation_flags_(Extension::NO_FLAGS),
102 off_store_install_allow_reason_(OffStoreInstallDisallowed), 103 off_store_install_allow_reason_(OffStoreInstallDisallowed),
103 did_handle_successfully_(true), 104 did_handle_successfully_(true),
104 record_oauth2_grant_(false) { 105 record_oauth2_grant_(false),
106 error_on_unsupported_requirements_(false),
107 requirements_checker_(new extensions::RequirementsChecker()),
108 has_requirement_errors_(false) {
105 if (!approval) 109 if (!approval)
106 return; 110 return;
107 111
108 CHECK(profile_->IsSameProfile(approval->profile)); 112 CHECK(profile_->IsSameProfile(approval->profile));
109 client_->install_ui()->SetUseAppInstalledBubble( 113 client_->install_ui()->SetUseAppInstalledBubble(
110 approval->use_app_installed_bubble); 114 approval->use_app_installed_bubble);
111 client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui); 115 client_->install_ui()->SetSkipPostInstallUI(approval->skip_post_install_ui);
112 116
113 if (approval->skip_install_dialog) { 117 if (approval->skip_install_dialog) {
114 // Mark the extension as approved, but save the expected manifest and ID 118 // Mark the extension as approved, but save the expected manifest and ID
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 382 }
379 383
380 if (client_) { 384 if (client_) {
381 Extension::DecodeIcon(extension_.get(), 385 Extension::DecodeIcon(extension_.get(),
382 extension_misc::EXTENSION_ICON_LARGE, 386 extension_misc::EXTENSION_ICON_LARGE,
383 ExtensionIconSet::MATCH_BIGGER, 387 ExtensionIconSet::MATCH_BIGGER,
384 &install_icon_); 388 &install_icon_);
385 } 389 }
386 390
387 if (!BrowserThread::PostTask( 391 if (!BrowserThread::PostTask(
388 BrowserThread::UI, FROM_HERE, 392 BrowserThread::UI, FROM_HERE,
389 base::Bind(&CrxInstaller::ConfirmInstall, this))) 393 base::Bind(&CrxInstaller::CheckRequirements, this)))
390 NOTREACHED(); 394 NOTREACHED();
391 } 395 }
392 396
397 void CrxInstaller::CheckRequirements() {
398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
399 AddRef(); // Balanced in OnRequirementsChecked().
400 requirements_checker_->Check(extension_,
401 base::Bind(&CrxInstaller::OnRequirementsChecked,
402 this));
403 }
404
405 void CrxInstaller::OnRequirementsChecked(
406 std::vector<std::string> requirement_errors) {
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
408 Release(); // Balanced in CheckRequirements().
409 if (!requirement_errors.empty()) {
410 if (error_on_unsupported_requirements_) {
411 ReportFailureFromUIThread(CrxInstallerError(
412 UTF8ToUTF16(JoinString(requirement_errors, ' '))));
413 return;
414 }
415 has_requirement_errors_ = true;
416 }
417
418 ConfirmInstall();
419 }
420
393 void CrxInstaller::ConfirmInstall() { 421 void CrxInstaller::ConfirmInstall() {
394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
395 if (!frontend_weak_.get()) 423 if (!frontend_weak_.get())
396 return; 424 return;
397 425
398 string16 error; 426 string16 error;
399 if (!ExtensionSystem::Get(profile_)->management_policy()-> 427 if (!ExtensionSystem::Get(profile_)->management_policy()->
400 UserMayLoad(extension_, &error)) { 428 UserMayLoad(extension_, &error)) {
401 ReportFailureFromUIThread(CrxInstallerError(error)); 429 ReportFailureFromUIThread(CrxInstallerError(error));
402 return; 430 return;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // We update the extension's granted permissions if the user already approved 613 // We update the extension's granted permissions if the user already approved
586 // the install (client_ is non NULL), or we are allowed to install this 614 // the install (client_ is non NULL), or we are allowed to install this
587 // silently. 615 // silently.
588 if (client_ || allow_silent_install_) { 616 if (client_ || allow_silent_install_) {
589 PermissionsUpdater perms_updater(profile()); 617 PermissionsUpdater perms_updater(profile());
590 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); 618 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_);
591 } 619 }
592 620
593 // Tell the frontend about the installation and hand off ownership of 621 // Tell the frontend about the installation and hand off ownership of
594 // extension_ to it. 622 // extension_ to it.
595 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), 623 frontend_weak_->OnExtensionInstalled(extension_,
596 page_ordinal_); 624 is_gallery_install(),
625 page_ordinal_,
626 has_requirement_errors_);
597 627
598 NotifyCrxInstallComplete(extension_.get()); 628 NotifyCrxInstallComplete(extension_.get());
599 629
600 extension_ = NULL; 630 extension_ = NULL;
601 631
602 // We're done. We don't post any more tasks to ourselves so we are deleted 632 // We're done. We don't post any more tasks to ourselves so we are deleted
603 // soon. 633 // soon.
604 } 634 }
605 635
606 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { 636 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) {
607 // Some users (such as the download shelf) need to know when a 637 // Some users (such as the download shelf) need to know when a
608 // CRXInstaller is done. Listening for the EXTENSION_* events 638 // CRXInstaller is done. Listening for the EXTENSION_* events
609 // is problematic because they don't know anything about the 639 // is problematic because they don't know anything about the
610 // extension before it is unpacked, so they cannot filter based 640 // extension before it is unpacked, so they cannot filter based
611 // on the extension. 641 // on the extension.
612 content::NotificationService::current()->Notify( 642 content::NotificationService::current()->Notify(
613 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 643 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
614 content::Source<CrxInstaller>(this), 644 content::Source<CrxInstaller>(this),
615 content::Details<const Extension>(extension)); 645 content::Details<const Extension>(extension));
616 } 646 }
617 647
618 } // namespace extensions 648 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698