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

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 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (!GenerateId(path_bytes, &id)) 358 if (!GenerateId(path_bytes, &id))
359 return ""; 359 return "";
360 return id; 360 return id;
361 } 361 }
362 362
363 Extension::Type Extension::GetType() const { 363 Extension::Type Extension::GetType() const {
364 if (is_theme()) 364 if (is_theme())
365 return TYPE_THEME; 365 return TYPE_THEME;
366 if (converted_from_user_script()) 366 if (converted_from_user_script())
367 return TYPE_USER_SCRIPT; 367 return TYPE_USER_SCRIPT;
368 if (is_platform_app())
369 return TYPE_PLATFORM_APP;
368 if (is_hosted_app()) 370 if (is_hosted_app())
369 return TYPE_HOSTED_APP; 371 return TYPE_HOSTED_APP;
370 if (is_packaged_app()) 372 if (is_packaged_app())
371 return TYPE_PACKAGED_APP; 373 return TYPE_PACKAGED_APP;
372 return TYPE_EXTENSION; 374 return TYPE_EXTENSION;
373 } 375 }
374 376
375 // static 377 // static
376 GURL Extension::GetResourceURL(const GURL& extension_url, 378 GURL Extension::GetResourceURL(const GURL& extension_url,
377 const std::string& relative_path) { 379 const std::string& relative_path) {
(...skipping 2475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2853 } 2855 }
2854 } 2856 }
2855 2857
2856 if (permission->id() == ExtensionAPIPermission::kExperimental) { 2858 if (permission->id() == ExtensionAPIPermission::kExperimental) {
2857 if (!CanSpecifyExperimentalPermission()) { 2859 if (!CanSpecifyExperimentalPermission()) {
2858 *error = errors::kExperimentalFlagRequired; 2860 *error = errors::kExperimentalFlagRequired;
2859 return false; 2861 return false;
2860 } 2862 }
2861 } 2863 }
2862 2864
2863 if (is_hosted_app()) { 2865 if (location_ == Extension::COMPONENT)
2864 if (!CanSpecifyPermissionForHostedApp(permission)) { 2866 return true;
2865 // Some old versions of Chrome did not return errors here and we ended up 2867
2866 // with extensions in the store containing bad data: crbug.com/101993. 2868 bool supports_type = false;
2867 // 2869 switch (GetType()) {
2868 // TODO(aa): Consider just being a lot looser when loading and installing 2870 case TYPE_USER_SCRIPT: // Pass through.
2869 // extensions. We can be strict when packing and in development mode. Then 2871 case TYPE_EXTENSION:
2870 // we won't have to maintain all these tricky backward compat issues: 2872 supports_type = permission->supports_extensions();
2871 // crbug.com/102328. 2873 break;
2872 if (creation_flags_ & STRICT_ERROR_CHECKS) { 2874 case TYPE_HOSTED_APP:
2873 *error = ExtensionErrorUtils::FormatErrorMessage( 2875 supports_type = permission->supports_hosted_apps();
2874 errors::kPermissionNotAllowed, permission->name()); 2876 break;
2875 } 2877 case TYPE_PACKAGED_APP:
2876 return false; 2878 supports_type = permission->supports_packaged_apps();
2877 } 2879 break;
2880 case TYPE_PLATFORM_APP:
2881 supports_type = permission->supports_platform_apps();
2882 break;
2883 default:
2884 supports_type = false;
2885 break;
2878 } 2886 }
2879 2887
2880 if (permission->is_platform_app_only()) { 2888 if (!supports_type) {
2881 if (!is_platform_app()) { 2889 // We special case hosted apps because some old versions of Chrome did not
2890 // return errors here and we ended up with extensions in the store
2891 // containing bad data: crbug.com/101993.
2892 //
2893 // TODO(aa): Consider just being a lot looser when loading and installing
2894 // extensions. We can be strict when packing and in development mode. Then
2895 // we won't have to maintain all these tricky backward compat issues:
2896 // crbug.com/102328.
2897 if (!is_hosted_app() || creation_flags_ & STRICT_ERROR_CHECKS) {
2882 *error = ExtensionErrorUtils::FormatErrorMessage( 2898 *error = ExtensionErrorUtils::FormatErrorMessage(
2883 errors::kPermissionNotAllowed, permission->name()); 2899 errors::kPermissionNotAllowed, permission->name());
2884 return false;
2885 } 2900 }
2901 return false;
2886 } 2902 }
2887 2903
2888 return true; 2904 return true;
2889 } 2905 }
2890 2906
2891 bool Extension::CanSpecifyComponentOnlyPermission() const { 2907 bool Extension::CanSpecifyComponentOnlyPermission() const {
2892 // Only COMPONENT extensions can use private APIs. 2908 // Only COMPONENT extensions can use private APIs.
2893 // TODO(asargent) - We want a more general purpose mechanism for this, 2909 // TODO(asargent) - We want a more general purpose mechanism for this,
2894 // and better error messages. (http://crbug.com/54013) 2910 // and better error messages. (http://crbug.com/54013)
2895 if (location_ == Extension::COMPONENT) 2911 if (location_ == Extension::COMPONENT)
(...skipping 20 matching lines...) Expand all
2916 2932
2917 // We rely on the webstore to check access to experimental. This way we can 2933 // We rely on the webstore to check access to experimental. This way we can
2918 // whitelist extensions to have access to experimental in just the store, and 2934 // whitelist extensions to have access to experimental in just the store, and
2919 // not have to push a new version of the client. 2935 // not have to push a new version of the client.
2920 if (from_webstore()) 2936 if (from_webstore())
2921 return true; 2937 return true;
2922 2938
2923 return false; 2939 return false;
2924 } 2940 }
2925 2941
2926 bool Extension::CanSpecifyPermissionForHostedApp(
2927 const ExtensionAPIPermission* permission) const {
2928 if (location_ == Extension::COMPONENT)
2929 return true;
2930
2931 if (permission->is_hosted_app())
2932 return true;
2933
2934 return false;
2935 }
2936
2937 bool Extension::CanExecuteScriptEverywhere() const { 2942 bool Extension::CanExecuteScriptEverywhere() const {
2938 if (location() == Extension::COMPONENT 2943 if (location() == Extension::COMPONENT
2939 #ifndef NDEBUG 2944 #ifndef NDEBUG
2940 || CommandLine::ForCurrentProcess()->HasSwitch( 2945 || CommandLine::ForCurrentProcess()->HasSwitch(
2941 switches::kExposePrivateExtensionApi) 2946 switches::kExposePrivateExtensionApi)
2942 #endif 2947 #endif
2943 ) 2948 )
2944 return true; 2949 return true;
2945 2950
2946 ScriptingWhitelist* whitelist = 2951 ScriptingWhitelist* whitelist =
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 already_disabled(false), 3079 already_disabled(false),
3075 extension(extension) {} 3080 extension(extension) {}
3076 3081
3077 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( 3082 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
3078 const Extension* extension, 3083 const Extension* extension,
3079 const ExtensionPermissionSet* permissions, 3084 const ExtensionPermissionSet* permissions,
3080 Reason reason) 3085 Reason reason)
3081 : reason(reason), 3086 : reason(reason),
3082 extension(extension), 3087 extension(extension),
3083 permissions(permissions) {} 3088 permissions(permissions) {}
OLDNEW
« 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