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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 2828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 } 2839 }
2840 } 2840 }
2841 2841
2842 if (permission->id() == ExtensionAPIPermission::kExperimental) { 2842 if (permission->id() == ExtensionAPIPermission::kExperimental) {
2843 if (!CanSpecifyExperimentalPermission()) { 2843 if (!CanSpecifyExperimentalPermission()) {
2844 *error = errors::kExperimentalFlagRequired; 2844 *error = errors::kExperimentalFlagRequired;
2845 return false; 2845 return false;
2846 } 2846 }
2847 } 2847 }
2848 2848
2849 if (is_hosted_app()) { 2849 if (location_ != Extension::COMPONENT &&
2850 if (!CanSpecifyPermissionForHostedApp(permission)) { 2850 !CanSpecifyPermissionForType(permission)) {
2851 // Some old versions of Chrome did not return errors here and we ended up 2851 // Some old versions of Chrome did not return errors here and we ended up
2852 // with extensions in the store containing bad data: crbug.com/101993. 2852 // with extensions in the store containing bad data: crbug.com/101993.
2853 // 2853 //
2854 // TODO(aa): Consider just being a lot looser when loading and installing 2854 // TODO(aa): Consider just being a lot looser when loading and installing
2855 // extensions. We can be strict when packing and in development mode. Then 2855 // extensions. We can be strict when packing and in development mode. Then
2856 // we won't have to maintain all these tricky backward compat issues: 2856 // we won't have to maintain all these tricky backward compat issues:
2857 // crbug.com/102328. 2857 // crbug.com/102328.
2858 if (creation_flags_ & STRICT_ERROR_CHECKS) { 2858 if (creation_flags_ & STRICT_ERROR_CHECKS) {
Aaron Boodman 2011/11/22 09:40:32 I don't think we want to be lose with the errors f
Aaron Boodman 2011/11/22 09:41:17 sigh, *loose*
jstritar 2011/11/22 15:58:29 Won't we run into this again? http://b/issue?id=5
2859 *error = ExtensionErrorUtils::FormatErrorMessage( 2859 *error = ExtensionErrorUtils::FormatErrorMessage(
2860 errors::kPermissionNotAllowed, permission->name()); 2860 errors::kPermissionNotAllowed, permission->name());
2861 }
2862 return false;
2863 } 2861 }
2862 return false;
2864 } 2863 }
2865 2864
2866 return true; 2865 return true;
2867 } 2866 }
2868 2867
2869 bool Extension::CanSpecifyComponentOnlyPermission() const { 2868 bool Extension::CanSpecifyComponentOnlyPermission() const {
2870 // Only COMPONENT extensions can use private APIs. 2869 // Only COMPONENT extensions can use private APIs.
2871 // TODO(asargent) - We want a more general purpose mechanism for this, 2870 // TODO(asargent) - We want a more general purpose mechanism for this,
2872 // and better error messages. (http://crbug.com/54013) 2871 // and better error messages. (http://crbug.com/54013)
2873 if (location_ == Extension::COMPONENT) 2872 if (location_ == Extension::COMPONENT)
(...skipping 20 matching lines...) Expand all
2894 2893
2895 // We rely on the webstore to check access to experimental. This way we can 2894 // We rely on the webstore to check access to experimental. This way we can
2896 // whitelist extensions to have access to experimental in just the store, and 2895 // whitelist extensions to have access to experimental in just the store, and
2897 // not have to push a new version of the client. 2896 // not have to push a new version of the client.
2898 if (from_webstore()) 2897 if (from_webstore())
2899 return true; 2898 return true;
2900 2899
2901 return false; 2900 return false;
2902 } 2901 }
2903 2902
2904 bool Extension::CanSpecifyPermissionForHostedApp( 2903 bool Extension::CanSpecifyPermissionForType(
2905 const ExtensionAPIPermission* permission) const { 2904 const ExtensionAPIPermission* permission) const {
2906 if (location_ == Extension::COMPONENT) 2905 switch (GetType()) {
Aaron Boodman 2011/11/22 09:40:32 This is so short, you could just fold it into CanS
jstritar 2011/11/22 15:58:29 Done.
2907 return true; 2906 case TYPE_USER_SCRIPT: // Pass through.
2908 2907 case TYPE_EXTENSION:
2909 if (permission->is_hosted_app()) 2908 return permission->supports_extensions();
2910 return true; 2909 case TYPE_HOSTED_APP:
2911 2910 return permission->supports_hosted_apps();
2912 return false; 2911 case TYPE_PACKAGED_APP:
2912 return permission->supports_packaged_apps();
2913 case TYPE_PLATFORM_APP:
2914 return permission->supports_platform_apps();
2915 default:
2916 return false;
2917 }
2913 } 2918 }
2914 2919
2915 bool Extension::CanExecuteScriptEverywhere() const { 2920 bool Extension::CanExecuteScriptEverywhere() const {
2916 if (location() == Extension::COMPONENT 2921 if (location() == Extension::COMPONENT
2917 #ifndef NDEBUG 2922 #ifndef NDEBUG
2918 || CommandLine::ForCurrentProcess()->HasSwitch( 2923 || CommandLine::ForCurrentProcess()->HasSwitch(
2919 switches::kExposePrivateExtensionApi) 2924 switches::kExposePrivateExtensionApi)
2920 #endif 2925 #endif
2921 ) 2926 )
2922 return true; 2927 return true;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3052 already_disabled(false), 3057 already_disabled(false),
3053 extension(extension) {} 3058 extension(extension) {}
3054 3059
3055 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3060 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3056 const Extension* extension, 3061 const Extension* extension,
3057 const ExtensionPermissionSet* permissions, 3062 const ExtensionPermissionSet* permissions,
3058 Reason reason) 3063 Reason reason)
3059 : reason(reason), 3064 : reason(reason),
3060 extension(extension), 3065 extension(extension),
3061 permissions(permissions) {} 3066 permissions(permissions) {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698