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

Unified Diff: chrome/browser/extensions/unpacked_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, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/unpacked_installer.cc
diff --git a/chrome/browser/extensions/unpacked_installer.cc b/chrome/browser/extensions/unpacked_installer.cc
index 9ea11a1c2ad2ad848d51c218951296716250ad77..6ade8d134c863a7b08d3b8a7c5e77577786ecd91 100644
--- a/chrome/browser/extensions/unpacked_installer.cc
+++ b/chrome/browser/extensions/unpacked_installer.cc
@@ -7,11 +7,13 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/file_util.h"
+#include "base/string_util.h"
#include "chrome/browser/extensions/extension_install_prompt.h"
#include "chrome/browser/extensions/extension_install_ui.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/permissions_updater.h"
+#include "chrome/browser/extensions/requirements_checker.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/string_ordinal.h"
@@ -66,7 +68,10 @@ void SimpleExtensionLoadPrompt::InstallUIProceed() {
extensions::PermissionsUpdater perms_updater(service_weak_->profile());
perms_updater.GrantActivePermissions(extension_, false);
service_weak_->OnExtensionInstalled(
- extension_, false, StringOrdinal()); // Not from web store.
+ extension_,
+ false, // Not from web store.
+ StringOrdinal(),
+ std::vector<std::string>());
}
delete this;
}
@@ -88,7 +93,8 @@ scoped_refptr<UnpackedInstaller> UnpackedInstaller::Create(
UnpackedInstaller::UnpackedInstaller(ExtensionService* extension_service)
: service_weak_(extension_service->AsWeakPtr()),
- prompt_for_plugins_(true) {
+ prompt_for_plugins_(true),
+ requirements_checker_(new RequirementsChecker()) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -104,6 +110,8 @@ void UnpackedInstaller::Load(const FilePath& path_in) {
}
void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
if (!service_weak_.get())
return;
// Load extensions from the command line synchronously to avoid a race
@@ -129,18 +137,38 @@ void UnpackedInstaller::LoadFromCommandLine(const FilePath& path_in) {
flags |= Extension::ALLOW_FILE_ACCESS;
std::string error;
- scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
+ extension_ = extension_file_util::LoadExtension(
extension_path_,
Extension::LOAD,
flags | Extension::FOLLOW_SYMLINKS_ANYWHERE,
- &error));
+ &error);
- if (!extension) {
+ if (!extension_.get()) {
ReportExtensionLoadError(error);
return;
}
- OnLoaded(extension);
+ RunRequirementsChecker();
+}
+
+void UnpackedInstaller::RunRequirementsChecker() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ requirements_checker_->Check(
+ extension_,
+ base::Bind(&UnpackedInstaller::RequirementsChecked,
+ this),
+ BrowserThread::UI);
+}
+
+void UnpackedInstaller::RequirementsChecked(std::vector<std::string> errors) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (!errors.empty()) {
+ ReportExtensionLoadError(JoinString(errors, ' '));
+ return;
+ }
+
+ OnLoaded();
}
bool UnpackedInstaller::IsLoadingUnpackedAllowed() const {
@@ -190,13 +218,13 @@ void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) {
if (allow_file_access)
flags |= Extension::ALLOW_FILE_ACCESS;
std::string error;
- scoped_refptr<const Extension> extension(extension_file_util::LoadExtension(
+ extension_ = extension_file_util::LoadExtension(
extension_path_,
Extension::LOAD,
flags | Extension::FOLLOW_SYMLINKS_ANYWHERE,
- &error));
+ &error);
- if (!extension) {
+ if (!extension_.get()) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(
&UnpackedInstaller::ReportExtensionLoadError,
@@ -205,9 +233,7 @@ void UnpackedInstaller::LoadWithFileAccess(bool allow_file_access) {
}
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(
- &UnpackedInstaller::OnLoaded,
- this, extension));
+ base::Bind(&UnpackedInstaller::RunRequirementsChecker, this));
}
void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) {
@@ -217,8 +243,7 @@ void UnpackedInstaller::ReportExtensionLoadError(const std::string &error) {
service_weak_->ReportExtensionLoadError(extension_path_, error, true);
}
-void UnpackedInstaller::OnLoaded(
- const scoped_refptr<const Extension>& extension) {
+void UnpackedInstaller::OnLoaded() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!service_weak_.get())
return;
@@ -226,21 +251,22 @@ void UnpackedInstaller::OnLoaded(
service_weak_->disabled_extensions();
if (service_weak_->show_extensions_prompts() &&
prompt_for_plugins_ &&
- !extension->plugins().empty() &&
- !disabled_extensions->Contains(extension->id())) {
+ !extension_->plugins().empty() &&
+ !disabled_extensions->Contains(extension_->id())) {
SimpleExtensionLoadPrompt* prompt = new SimpleExtensionLoadPrompt(
service_weak_->profile(),
service_weak_,
- extension);
+ extension_);
prompt->ShowPrompt();
return; // continues in SimpleExtensionLoadPrompt::InstallPrompt*
}
PermissionsUpdater perms_updater(service_weak_->profile());
- perms_updater.GrantActivePermissions(extension, false);
- service_weak_->OnExtensionInstalled(extension,
+ perms_updater.GrantActivePermissions(extension_, false);
+ service_weak_->OnExtensionInstalled(extension_,
false, // Not from web store.
- StringOrdinal());
+ StringOrdinal(),
+ std::vector<std::string>());
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698