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

Unified Diff: chrome/common/extensions/extension.cc

Issue 8598022: Restrict access to permissions based on extension types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_manifests_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/extension.cc
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 7a3c8ec45b2e893a879a6c6f0ac67809e4ca4499..8e25332bde4369f450da1d9e4ba17fecf7745532 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -365,6 +365,8 @@ Extension::Type Extension::GetType() const {
return TYPE_THEME;
if (converted_from_user_script())
return TYPE_USER_SCRIPT;
+ if (is_platform_app())
+ return TYPE_PLATFORM_APP;
if (is_hosted_app())
return TYPE_HOSTED_APP;
if (is_packaged_app())
@@ -2860,29 +2862,43 @@ bool Extension::CanSpecifyAPIPermission(
}
}
- if (is_hosted_app()) {
- if (!CanSpecifyPermissionForHostedApp(permission)) {
- // Some old versions of Chrome did not return errors here and we ended up
- // with extensions in the store containing bad data: crbug.com/101993.
- //
- // TODO(aa): Consider just being a lot looser when loading and installing
- // extensions. We can be strict when packing and in development mode. Then
- // we won't have to maintain all these tricky backward compat issues:
- // crbug.com/102328.
- if (creation_flags_ & STRICT_ERROR_CHECKS) {
- *error = ExtensionErrorUtils::FormatErrorMessage(
- errors::kPermissionNotAllowed, permission->name());
- }
- return false;
- }
+ if (location_ == Extension::COMPONENT)
+ return true;
+
+ bool supports_type = false;
+ switch (GetType()) {
+ case TYPE_USER_SCRIPT: // Pass through.
+ case TYPE_EXTENSION:
+ supports_type = permission->supports_extensions();
+ break;
+ case TYPE_HOSTED_APP:
+ supports_type = permission->supports_hosted_apps();
+ break;
+ case TYPE_PACKAGED_APP:
+ supports_type = permission->supports_packaged_apps();
+ break;
+ case TYPE_PLATFORM_APP:
+ supports_type = permission->supports_platform_apps();
+ break;
+ default:
+ supports_type = false;
+ break;
}
- if (permission->is_platform_app_only()) {
- if (!is_platform_app()) {
+ if (!supports_type) {
+ // We special case hosted apps because some old versions of Chrome did not
+ // return errors here and we ended up with extensions in the store
+ // containing bad data: crbug.com/101993.
+ //
+ // TODO(aa): Consider just being a lot looser when loading and installing
+ // extensions. We can be strict when packing and in development mode. Then
+ // we won't have to maintain all these tricky backward compat issues:
+ // crbug.com/102328.
+ if (!is_hosted_app() || creation_flags_ & STRICT_ERROR_CHECKS) {
*error = ExtensionErrorUtils::FormatErrorMessage(
errors::kPermissionNotAllowed, permission->name());
- return false;
}
+ return false;
}
return true;
@@ -2923,17 +2939,6 @@ bool Extension::CanSpecifyExperimentalPermission() const {
return false;
}
-bool Extension::CanSpecifyPermissionForHostedApp(
- const ExtensionAPIPermission* permission) const {
- if (location_ == Extension::COMPONENT)
- return true;
-
- if (permission->is_hosted_app())
- return true;
-
- return false;
-}
-
bool Extension::CanExecuteScriptEverywhere() const {
if (location() == Extension::COMPONENT
#ifndef NDEBUG
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_manifests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698