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

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

Powered by Google App Engine
This is Rietveld 408576698