| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 2817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2828 | 2828 |
| 2829 bool Extension::ImplicitlyDelaysNetworkStartup() const { | 2829 bool Extension::ImplicitlyDelaysNetworkStartup() const { |
| 2830 // Network requests should be deferred until any extensions that might want | 2830 // Network requests should be deferred until any extensions that might want |
| 2831 // to observe and modify them are loaded. | 2831 // to observe and modify them are loaded. |
| 2832 return HasAPIPermission(ExtensionAPIPermission::kWebRequestBlocking); | 2832 return HasAPIPermission(ExtensionAPIPermission::kWebRequestBlocking); |
| 2833 } | 2833 } |
| 2834 | 2834 |
| 2835 bool Extension::CanSpecifyAPIPermission( | 2835 bool Extension::CanSpecifyAPIPermission( |
| 2836 const ExtensionAPIPermission* permission, | 2836 const ExtensionAPIPermission* permission, |
| 2837 string16* error) const { | 2837 string16* error) const { |
| 2838 if (permission->is_component_only()) { | 2838 if (location_ == Extension::COMPONENT) |
| 2839 if (!CanSpecifyComponentOnlyPermission()) { | 2839 return true; |
| 2840 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2840 |
| 2841 errors::kPermissionNotAllowed, permission->name()); | 2841 bool access_denied = false; |
| 2842 return false; | 2842 if (permission->HasWhitelist()) { |
| 2843 } | 2843 if (permission->IsWhitelisted(id_)) |
| 2844 return true; |
| 2845 else |
| 2846 access_denied = true; |
| 2847 } else if (permission->is_component_only()) { |
| 2848 access_denied = true; |
| 2849 } |
| 2850 |
| 2851 if (access_denied) { |
| 2852 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 2853 errors::kPermissionNotAllowed, permission->name()); |
| 2854 return false; |
| 2844 } | 2855 } |
| 2845 | 2856 |
| 2846 if (permission->id() == ExtensionAPIPermission::kExperimental) { | 2857 if (permission->id() == ExtensionAPIPermission::kExperimental) { |
| 2847 if (!CanSpecifyExperimentalPermission()) { | 2858 if (!CanSpecifyExperimentalPermission()) { |
| 2848 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); | 2859 *error = ASCIIToUTF16(errors::kExperimentalFlagRequired); |
| 2849 return false; | 2860 return false; |
| 2850 } | 2861 } |
| 2851 } | 2862 } |
| 2852 | 2863 |
| 2853 if (location_ == Extension::COMPONENT) | |
| 2854 return true; | |
| 2855 | |
| 2856 bool supports_type = false; | 2864 bool supports_type = false; |
| 2857 switch (GetType()) { | 2865 switch (GetType()) { |
| 2858 case TYPE_USER_SCRIPT: // Pass through. | 2866 case TYPE_USER_SCRIPT: // Pass through. |
| 2859 case TYPE_EXTENSION: | 2867 case TYPE_EXTENSION: |
| 2860 supports_type = permission->supports_extensions(); | 2868 supports_type = permission->supports_extensions(); |
| 2861 break; | 2869 break; |
| 2862 case TYPE_HOSTED_APP: | 2870 case TYPE_HOSTED_APP: |
| 2863 supports_type = permission->supports_hosted_apps(); | 2871 supports_type = permission->supports_hosted_apps(); |
| 2864 break; | 2872 break; |
| 2865 case TYPE_PACKAGED_APP: | 2873 case TYPE_PACKAGED_APP: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2885 if (!is_hosted_app() || creation_flags_ & STRICT_ERROR_CHECKS) { | 2893 if (!is_hosted_app() || creation_flags_ & STRICT_ERROR_CHECKS) { |
| 2886 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2894 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( |
| 2887 errors::kPermissionNotAllowed, permission->name()); | 2895 errors::kPermissionNotAllowed, permission->name()); |
| 2888 } | 2896 } |
| 2889 return false; | 2897 return false; |
| 2890 } | 2898 } |
| 2891 | 2899 |
| 2892 return true; | 2900 return true; |
| 2893 } | 2901 } |
| 2894 | 2902 |
| 2895 bool Extension::CanSpecifyComponentOnlyPermission() const { | |
| 2896 // Only COMPONENT extensions can use private APIs. | |
| 2897 // TODO(asargent) - We want a more general purpose mechanism for this, | |
| 2898 // and better error messages. (http://crbug.com/54013) | |
| 2899 return location_ == Extension::COMPONENT; | |
| 2900 } | |
| 2901 | |
| 2902 bool Extension::CanSpecifyExperimentalPermission() const { | 2903 bool Extension::CanSpecifyExperimentalPermission() const { |
| 2903 if (location_ == Extension::COMPONENT) | 2904 if (location_ == Extension::COMPONENT) |
| 2904 return true; | 2905 return true; |
| 2905 | 2906 |
| 2906 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2907 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2907 switches::kEnableExperimentalExtensionApis)) { | 2908 switches::kEnableExperimentalExtensionApis)) { |
| 2908 return true; | 2909 return true; |
| 2909 } | 2910 } |
| 2910 | 2911 |
| 2911 // We rely on the webstore to check access to experimental. This way we can | 2912 // We rely on the webstore to check access to experimental. This way we can |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3047 already_disabled(false), | 3048 already_disabled(false), |
| 3048 extension(extension) {} | 3049 extension(extension) {} |
| 3049 | 3050 |
| 3050 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3051 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3051 const Extension* extension, | 3052 const Extension* extension, |
| 3052 const ExtensionPermissionSet* permissions, | 3053 const ExtensionPermissionSet* permissions, |
| 3053 Reason reason) | 3054 Reason reason) |
| 3054 : reason(reason), | 3055 : reason(reason), |
| 3055 extension(extension), | 3056 extension(extension), |
| 3056 permissions(permissions) {} | 3057 permissions(permissions) {} |
| OLD | NEW |