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

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: Created 8 years, 4 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/stl_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/string_util.h"
19 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
20 #include "base/time.h" 21 #include "base/time.h"
21 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
22 #include "base/version.h" 23 #include "base/version.h"
23 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/extensions/convert_user_script.h" 25 #include "chrome/browser/extensions/convert_user_script.h"
25 #include "chrome/browser/extensions/convert_web_app.h" 26 #include "chrome/browser/extensions/convert_web_app.h"
26 #include "chrome/browser/extensions/default_apps_trial.h" 27 #include "chrome/browser/extensions/default_apps_trial.h"
27 #include "chrome/browser/extensions/extension_error_reporter.h" 28 #include "chrome/browser/extensions/extension_error_reporter.h"
28 #include "chrome/browser/extensions/extension_install_ui.h" 29 #include "chrome/browser/extensions/extension_install_ui.h"
29 #include "chrome/browser/extensions/extension_service.h" 30 #include "chrome/browser/extensions/extension_service.h"
30 #include "chrome/browser/extensions/extension_system.h" 31 #include "chrome/browser/extensions/extension_system.h"
31 #include "chrome/browser/extensions/permissions_updater.h" 32 #include "chrome/browser/extensions/permissions_updater.h"
33 #include "chrome/browser/extensions/requirements_checker.h"
32 #include "chrome/browser/extensions/webstore_installer.h" 34 #include "chrome/browser/extensions/webstore_installer.h"
33 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/shell_integration.h" 36 #include "chrome/browser/shell_integration.h"
35 #include "chrome/browser/web_applications/web_app.h" 37 #include "chrome/browser/web_applications/web_app.h"
36 #include "chrome/common/chrome_notification_types.h" 38 #include "chrome/common/chrome_notification_types.h"
37 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/extensions/extension_constants.h" 40 #include "chrome/common/extensions/extension_constants.h"
39 #include "chrome/common/extensions/extension_file_util.h" 41 #include "chrome/common/extensions/extension_file_util.h"
40 #include "chrome/common/extensions/extension_icon_set.h" 42 #include "chrome/common/extensions/extension_icon_set.h"
41 #include "chrome/common/extensions/extension_switch_utils.h" 43 #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), 96 create_app_shortcut_(false),
95 frontend_weak_(frontend_weak), 97 frontend_weak_(frontend_weak),
96 profile_(frontend_weak->profile()), 98 profile_(frontend_weak->profile()),
97 client_(client), 99 client_(client),
98 apps_require_extension_mime_type_(false), 100 apps_require_extension_mime_type_(false),
99 allow_silent_install_(false), 101 allow_silent_install_(false),
100 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), 102 install_cause_(extension_misc::INSTALL_CAUSE_UNSET),
101 creation_flags_(Extension::NO_FLAGS), 103 creation_flags_(Extension::NO_FLAGS),
102 off_store_install_allow_reason_(OffStoreInstallDisallowed), 104 off_store_install_allow_reason_(OffStoreInstallDisallowed),
103 did_handle_successfully_(true), 105 did_handle_successfully_(true),
104 record_oauth2_grant_(false) { 106 record_oauth2_grant_(false),
107 error_on_unsupported_requirements_(false),
108 requirements_checker_(new extensions::RequirementsChecker()) {
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Validation should have stopped any potential errors before getting here. 201 // Validation should have stopped any potential errors before getting here.
198 NOTREACHED() << "Could not convert web app to extension."; 202 NOTREACHED() << "Could not convert web app to extension.";
199 return; 203 return;
200 } 204 }
201 205
202 // TODO(aa): conversion data gets lost here :( 206 // TODO(aa): conversion data gets lost here :(
203 207
204 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension); 208 OnUnpackSuccess(extension->path(), extension->path(), NULL, extension);
205 } 209 }
206 210
207 CrxInstallerError CrxInstaller::AllowInstall(const Extension* extension) { 211 CrxInstallerError CrxInstaller::AllowInstall(Extension* extension) {
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
209 213
210 // Make sure the expected ID matches if one was supplied or if we want to 214 // Make sure the expected ID matches if one was supplied or if we want to
211 // bypass the prompt. 215 // bypass the prompt.
212 if ((approved_ || !expected_id_.empty()) && 216 if ((approved_ || !expected_id_.empty()) &&
213 expected_id_ != extension->id()) { 217 expected_id_ != extension->id()) {
214 return CrxInstallerError( 218 return CrxInstallerError(
215 l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALL_UNEXPECTED_ID, 219 l10n_util::GetStringFUTF16(IDS_EXTENSION_INSTALL_UNEXPECTED_ID,
216 ASCIIToUTF16(expected_id_), 220 ASCIIToUTF16(expected_id_),
217 ASCIIToUTF16(extension->id()))); 221 ASCIIToUTF16(extension->id())));
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackFailureInstallCause", 346 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackFailureInstallCause",
343 install_cause(), 347 install_cause(),
344 extension_misc::NUM_INSTALL_CAUSES); 348 extension_misc::NUM_INSTALL_CAUSES);
345 349
346 ReportFailureFromFileThread(CrxInstallerError(error_message)); 350 ReportFailureFromFileThread(CrxInstallerError(error_message));
347 } 351 }
348 352
349 void CrxInstaller::OnUnpackSuccess(const FilePath& temp_dir, 353 void CrxInstaller::OnUnpackSuccess(const FilePath& temp_dir,
350 const FilePath& extension_dir, 354 const FilePath& extension_dir,
351 const DictionaryValue* original_manifest, 355 const DictionaryValue* original_manifest,
352 const Extension* extension) { 356 Extension* extension) {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
354 358
355 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackSuccessInstallSource", 359 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackSuccessInstallSource",
356 install_source(), Extension::NUM_LOCATIONS); 360 install_source(), Extension::NUM_LOCATIONS);
357 361
358 362
359 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackSuccessInstallCause", 363 UMA_HISTOGRAM_ENUMERATION("Extensions.UnpackSuccessInstallCause",
360 install_cause(), 364 install_cause(),
361 extension_misc::NUM_INSTALL_CAUSES); 365 extension_misc::NUM_INSTALL_CAUSES);
362 366
(...skipping 14 matching lines...) Expand all
377 return; 381 return;
378 } 382 }
379 383
380 if (client_) { 384 if (client_) {
381 Extension::DecodeIcon(extension_.get(), 385 Extension::DecodeIcon(extension_.get(),
382 ExtensionIconSet::EXTENSION_ICON_LARGE, 386 ExtensionIconSet::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 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
388 BrowserThread::UI, FROM_HERE, 392 base::Bind(&CrxInstaller::CheckRequirements, this));
389 base::Bind(&CrxInstaller::ConfirmInstall, this))) 393 }
390 NOTREACHED(); 394
395 void CrxInstaller::CheckRequirements() {
396 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
397 requirements_checker_->Check(extension_,
398 base::Bind(&CrxInstaller::RequirementsChecked,
399 this));
400 }
401
402 void CrxInstaller::RequirementsChecked(std::vector<std::string> errors) {
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
404
405 if (!errors.empty()) {
406 if (error_on_unsupported_requirements_) {
407 ReportFailureFromUIThread(CrxInstallerError(
408 UTF8ToUTF16(JoinString(errors, ' '))));
409 return;
410 }
411 requirement_errors_.swap(errors);
412 }
413
414 ConfirmInstall();
391 } 415 }
392 416
393 void CrxInstaller::ConfirmInstall() { 417 void CrxInstaller::ConfirmInstall() {
394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
395 if (!frontend_weak_.get()) 419 if (!frontend_weak_.get())
396 return; 420 return;
397 421
398 if (frontend_weak_->extension_prefs() 422 if (frontend_weak_->extension_prefs()
399 ->IsExtensionBlacklisted(extension_->id())) { 423 ->IsExtensionBlacklisted(extension_->id())) {
400 VLOG(1) << "This extension: " << extension_->id() 424 VLOG(1) << "This extension: " << extension_->id()
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing 537 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing
514 // with string16 538 // with string16
515 std::string error; 539 std::string error;
516 extension_ = extension_file_util::LoadExtension( 540 extension_ = extension_file_util::LoadExtension(
517 version_dir, 541 version_dir,
518 install_source_, 542 install_source_,
519 extension_->creation_flags() | Extension::REQUIRE_KEY, 543 extension_->creation_flags() | Extension::REQUIRE_KEY,
520 &error); 544 &error);
521 CHECK(error.empty()) << error; 545 CHECK(error.empty()) << error;
522 546
547 if (!requirement_errors_.empty()) {
548 extensions::Extension::InstallWarningVector install_warnings;
549 for (std::vector<std::string>::iterator it = requirement_errors_.begin();
550 it != requirement_errors_.end();
551 ++it) {
552 install_warnings.push_back(Extension::InstallWarning(
553 Extension::InstallWarning::FORMAT_TEXT, *it));
554 }
555 extension_->AddInstallWarnings(install_warnings);
556 }
557
523 ReportSuccessFromFileThread(); 558 ReportSuccessFromFileThread();
524 } 559 }
525 560
526 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) { 561 void CrxInstaller::ReportFailureFromFileThread(const CrxInstallerError& error) {
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
528 if (!BrowserThread::PostTask( 563 if (!BrowserThread::PostTask(
529 BrowserThread::UI, FROM_HERE, 564 BrowserThread::UI, FROM_HERE,
530 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) { 565 base::Bind(&CrxInstaller::ReportFailureFromUIThread, this, error))) {
531 NOTREACHED(); 566 NOTREACHED();
532 } 567 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // We update the extension's granted permissions if the user already approved 630 // We update the extension's granted permissions if the user already approved
596 // the install (client_ is non NULL), or we are allowed to install this 631 // the install (client_ is non NULL), or we are allowed to install this
597 // silently. 632 // silently.
598 if (client_ || allow_silent_install_) { 633 if (client_ || allow_silent_install_) {
599 PermissionsUpdater perms_updater(profile()); 634 PermissionsUpdater perms_updater(profile());
600 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_); 635 perms_updater.GrantActivePermissions(extension_, record_oauth2_grant_);
601 } 636 }
602 637
603 // Tell the frontend about the installation and hand off ownership of 638 // Tell the frontend about the installation and hand off ownership of
604 // extension_ to it. 639 // extension_ to it.
605 frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install(), 640 frontend_weak_->OnExtensionInstalled(extension_,
606 page_ordinal_); 641 is_gallery_install(),
642 page_ordinal_,
643 requirement_errors_);
607 644
608 NotifyCrxInstallComplete(extension_.get()); 645 NotifyCrxInstallComplete(extension_.get());
609 646
610 extension_ = NULL; 647 extension_ = NULL;
611 648
612 // We're done. We don't post any more tasks to ourselves so we are deleted 649 // We're done. We don't post any more tasks to ourselves so we are deleted
613 // soon. 650 // soon.
614 } 651 }
615 652
616 void CrxInstaller::NotifyCrxInstallComplete(const Extension* extension) { 653 void CrxInstaller::NotifyCrxInstallComplete(Extension* extension) {
617 // Some users (such as the download shelf) need to know when a 654 // Some users (such as the download shelf) need to know when a
618 // CRXInstaller is done. Listening for the EXTENSION_* events 655 // CRXInstaller is done. Listening for the EXTENSION_* events
619 // is problematic because they don't know anything about the 656 // is problematic because they don't know anything about the
620 // extension before it is unpacked, so they cannot filter based 657 // extension before it is unpacked, so they cannot filter based
621 // on the extension. 658 // on the extension.
622 content::NotificationService::current()->Notify( 659 content::NotificationService::current()->Notify(
623 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 660 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
624 content::Source<CrxInstaller>(this), 661 content::Source<CrxInstaller>(this),
625 content::Details<const Extension>(extension)); 662 content::Details<const Extension>(extension));
626 } 663 }
627 664
628 } // namespace extensions 665 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698