| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/common/chrome_version_info.h" | 27 #include "chrome/common/chrome_version_info.h" |
| 28 #include "chrome/common/extensions/csp_validator.h" | 28 #include "chrome/common/extensions/csp_validator.h" |
| 29 #include "chrome/common/extensions/extension_action.h" | 29 #include "chrome/common/extensions/extension_action.h" |
| 30 #include "chrome/common/extensions/extension_constants.h" | 30 #include "chrome/common/extensions/extension_constants.h" |
| 31 #include "chrome/common/extensions/extension_error_utils.h" | 31 #include "chrome/common/extensions/extension_error_utils.h" |
| 32 #include "chrome/common/extensions/extension_l10n_util.h" | 32 #include "chrome/common/extensions/extension_l10n_util.h" |
| 33 #include "chrome/common/extensions/extension_resource.h" | 33 #include "chrome/common/extensions/extension_resource.h" |
| 34 #include "chrome/common/extensions/extension_sidebar_defaults.h" | 34 #include "chrome/common/extensions/extension_sidebar_defaults.h" |
| 35 #include "chrome/common/extensions/extension_sidebar_utils.h" | 35 #include "chrome/common/extensions/extension_sidebar_utils.h" |
| 36 #include "chrome/common/extensions/file_browser_handler.h" | 36 #include "chrome/common/extensions/file_browser_handler.h" |
| 37 #include "chrome/common/extensions/manifest.h" | |
| 38 #include "chrome/common/extensions/user_script.h" | 37 #include "chrome/common/extensions/user_script.h" |
| 39 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 40 #include "googleurl/src/url_util.h" | 39 #include "googleurl/src/url_util.h" |
| 41 #include "grit/chromium_strings.h" | 40 #include "grit/chromium_strings.h" |
| 42 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| 43 #include "grit/theme_resources.h" | 42 #include "grit/theme_resources.h" |
| 44 #include "net/base/registry_controlled_domain.h" | 43 #include "net/base/registry_controlled_domain.h" |
| 45 #include "third_party/skia/include/core/SkBitmap.h" | 44 #include "third_party/skia/include/core/SkBitmap.h" |
| 46 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 47 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 static void ConvertHexadecimalToIDAlphabet(std::string* id) { | 78 static void ConvertHexadecimalToIDAlphabet(std::string* id) { |
| 80 for (size_t i = 0; i < id->size(); ++i) { | 79 for (size_t i = 0; i < id->size(); ++i) { |
| 81 int val; | 80 int val; |
| 82 if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val)) | 81 if (base::HexStringToInt(id->begin() + i, id->begin() + i + 1, &val)) |
| 83 (*id)[i] = val + 'a'; | 82 (*id)[i] = val + 'a'; |
| 84 else | 83 else |
| 85 (*id)[i] = 'a'; | 84 (*id)[i] = 'a'; |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 88 // These keys are allowed by all crx files (apps, extensions, themes, etc). |
| 89 static const char* kBaseCrxKeys[] = { |
| 90 keys::kCurrentLocale, |
| 91 keys::kDefaultLocale, |
| 92 keys::kDescription, |
| 93 keys::kIcons, |
| 94 keys::kManifestVersion, |
| 95 keys::kName, |
| 96 keys::kPublicKey, |
| 97 keys::kSignature, |
| 98 keys::kUpdateURL, |
| 99 keys::kVersion, |
| 100 }; |
| 101 |
| 102 bool IsBaseCrxKey(const std::string& key) { |
| 103 for (size_t i = 0; i < arraysize(kBaseCrxKeys); ++i) { |
| 104 if (key == kBaseCrxKeys[i]) |
| 105 return true; |
| 106 } |
| 107 |
| 108 return false; |
| 109 } |
| 110 |
| 89 // A singleton object containing global data needed by the extension objects. | 111 // A singleton object containing global data needed by the extension objects. |
| 90 class ExtensionConfig { | 112 class ExtensionConfig { |
| 91 public: | 113 public: |
| 92 static ExtensionConfig* GetInstance() { | 114 static ExtensionConfig* GetInstance() { |
| 93 return Singleton<ExtensionConfig>::get(); | 115 return Singleton<ExtensionConfig>::get(); |
| 94 } | 116 } |
| 95 | 117 |
| 96 Extension::ScriptingWhitelist* whitelist() { return &scripting_whitelist_; } | 118 Extension::ScriptingWhitelist* whitelist() { return &scripting_whitelist_; } |
| 97 | 119 |
| 98 private: | 120 private: |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 246 |
| 225 // static | 247 // static |
| 226 scoped_refptr<Extension> Extension::Create(const FilePath& path, | 248 scoped_refptr<Extension> Extension::Create(const FilePath& path, |
| 227 Location location, | 249 Location location, |
| 228 const DictionaryValue& value, | 250 const DictionaryValue& value, |
| 229 int flags, | 251 int flags, |
| 230 std::string* error) { | 252 std::string* error) { |
| 231 DCHECK(error); | 253 DCHECK(error); |
| 232 scoped_refptr<Extension> extension = new Extension(path, location); | 254 scoped_refptr<Extension> extension = new Extension(path, location); |
| 233 | 255 |
| 234 if (!extension->InitFromValue(new extensions::Manifest(value.DeepCopy()), | 256 if (!extension->InitFromValue(value, flags, error)) |
| 235 flags, error)) | |
| 236 return NULL; | 257 return NULL; |
| 237 return extension; | 258 return extension; |
| 238 } | 259 } |
| 239 | 260 |
| 240 scoped_refptr<Extension> Extension::CreateWithId(const FilePath& path, | 261 scoped_refptr<Extension> Extension::CreateWithId(const FilePath& path, |
| 241 Location location, | 262 Location location, |
| 242 const DictionaryValue& value, | 263 const DictionaryValue& value, |
| 243 int flags, | 264 int flags, |
| 244 const std::string& explicit_id, | 265 const std::string& explicit_id, |
| 245 std::string* error) { | 266 std::string* error) { |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 GURL url = extension_sidebar_utils::ResolveRelativePath( | 893 GURL url = extension_sidebar_utils::ResolveRelativePath( |
| 873 default_page, this, error); | 894 default_page, this, error); |
| 874 if (!url.is_valid()) | 895 if (!url.is_valid()) |
| 875 return NULL; | 896 return NULL; |
| 876 result->set_default_page(url); | 897 result->set_default_page(url); |
| 877 } | 898 } |
| 878 | 899 |
| 879 return result.release(); | 900 return result.release(); |
| 880 } | 901 } |
| 881 | 902 |
| 882 bool Extension::LoadExtent(const extensions::Manifest* manifest, | 903 bool Extension::ContainsNonThemeKeys(const DictionaryValue& source) const { |
| 904 for (DictionaryValue::key_iterator key = source.begin_keys(); |
| 905 key != source.end_keys(); ++key) { |
| 906 if (!IsBaseCrxKey(*key) && *key != keys::kTheme) |
| 907 return true; |
| 908 } |
| 909 return false; |
| 910 } |
| 911 |
| 912 bool Extension::LoadIsApp(const DictionaryValue* manifest, |
| 913 std::string* error) { |
| 914 if (manifest->HasKey(keys::kApp)) |
| 915 is_app_ = true; |
| 916 |
| 917 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 918 switches::kEnablePlatformApps)) { |
| 919 if (manifest->HasKey(keys::kPlatformApp)) { |
| 920 manifest->GetBoolean(keys::kPlatformApp, &is_platform_app_); |
| 921 } |
| 922 } |
| 923 |
| 924 return true; |
| 925 } |
| 926 |
| 927 bool Extension::LoadExtent(const DictionaryValue* manifest, |
| 883 const char* key, | 928 const char* key, |
| 884 URLPatternSet* extent, | 929 URLPatternSet* extent, |
| 885 const char* list_error, | 930 const char* list_error, |
| 886 const char* value_error, | 931 const char* value_error, |
| 887 URLPattern::ParseOption parse_strictness, | 932 URLPattern::ParseOption parse_strictness, |
| 888 std::string* error) { | 933 std::string* error) { |
| 889 Value* temp = NULL; | 934 Value* temp = NULL; |
| 890 if (!manifest->Get(key, &temp)) | 935 if (!manifest->Get(key, &temp)) |
| 891 return true; | 936 return true; |
| 892 | 937 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 return false; | 994 return false; |
| 950 } | 995 } |
| 951 pattern.SetPath(pattern.path() + '*'); | 996 pattern.SetPath(pattern.path() + '*'); |
| 952 | 997 |
| 953 extent->AddPattern(pattern); | 998 extent->AddPattern(pattern); |
| 954 } | 999 } |
| 955 | 1000 |
| 956 return true; | 1001 return true; |
| 957 } | 1002 } |
| 958 | 1003 |
| 959 bool Extension::LoadLaunchURL(const extensions::Manifest* manifest, | 1004 bool Extension::LoadLaunchURL(const DictionaryValue* manifest, |
| 960 std::string* error) { | 1005 std::string* error) { |
| 961 Value* temp = NULL; | 1006 Value* temp = NULL; |
| 962 | 1007 |
| 963 // launch URL can be either local (to chrome-extension:// root) or an absolute | 1008 // launch URL can be either local (to chrome-extension:// root) or an absolute |
| 964 // web URL. | 1009 // web URL. |
| 965 if (manifest->Get(keys::kLaunchLocalPath, &temp)) { | 1010 if (manifest->Get(keys::kLaunchLocalPath, &temp)) { |
| 966 if (manifest->Get(keys::kLaunchWebURL, NULL)) { | 1011 if (manifest->Get(keys::kLaunchWebURL, NULL)) { |
| 967 *error = errors::kLaunchPathAndURLAreExclusive; | 1012 *error = errors::kLaunchPathAndURLAreExclusive; |
| 968 return false; | 1013 return false; |
| 969 } | 1014 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 GURL::Replacements replacements; | 1092 GURL::Replacements replacements; |
| 1048 replacements.SetPathStr(path); | 1093 replacements.SetPathStr(path); |
| 1049 GURL cloud_print_enable_connector_url = | 1094 GURL cloud_print_enable_connector_url = |
| 1050 cloud_print_service_url.ReplaceComponents(replacements); | 1095 cloud_print_service_url.ReplaceComponents(replacements); |
| 1051 OverrideLaunchUrl(cloud_print_enable_connector_url); | 1096 OverrideLaunchUrl(cloud_print_enable_connector_url); |
| 1052 } | 1097 } |
| 1053 } | 1098 } |
| 1054 return true; | 1099 return true; |
| 1055 } | 1100 } |
| 1056 | 1101 |
| 1057 bool Extension::LoadLaunchContainer(const extensions::Manifest* manifest, | 1102 bool Extension::LoadLaunchContainer(const DictionaryValue* manifest, |
| 1058 std::string* error) { | 1103 std::string* error) { |
| 1059 Value* temp = NULL; | 1104 Value* temp = NULL; |
| 1060 if (!manifest->Get(keys::kLaunchContainer, &temp)) | 1105 if (!manifest->Get(keys::kLaunchContainer, &temp)) |
| 1061 return true; | 1106 return true; |
| 1062 | 1107 |
| 1063 std::string launch_container_string; | 1108 std::string launch_container_string; |
| 1064 if (!temp->GetAsString(&launch_container_string)) { | 1109 if (!temp->GetAsString(&launch_container_string)) { |
| 1065 *error = errors::kInvalidLaunchContainer; | 1110 *error = errors::kInvalidLaunchContainer; |
| 1066 return false; | 1111 return false; |
| 1067 } | 1112 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 if (!temp->GetAsInteger(&launch_height_) || launch_height_ < 0) { | 1147 if (!temp->GetAsInteger(&launch_height_) || launch_height_ < 0) { |
| 1103 launch_height_ = 0; | 1148 launch_height_ = 0; |
| 1104 *error = errors::kInvalidLaunchHeight; | 1149 *error = errors::kInvalidLaunchHeight; |
| 1105 return false; | 1150 return false; |
| 1106 } | 1151 } |
| 1107 } | 1152 } |
| 1108 | 1153 |
| 1109 return true; | 1154 return true; |
| 1110 } | 1155 } |
| 1111 | 1156 |
| 1112 bool Extension::LoadAppIsolation(const extensions::Manifest* manifest, | 1157 bool Extension::LoadAppIsolation(const DictionaryValue* manifest, |
| 1113 std::string* error) { | 1158 std::string* error) { |
| 1114 Value* temp = NULL; | 1159 Value* temp = NULL; |
| 1115 if (!manifest->Get(keys::kIsolation, &temp)) | 1160 if (!manifest->Get(keys::kIsolation, &temp)) |
| 1116 return true; | 1161 return true; |
| 1117 | 1162 |
| 1118 if (temp->GetType() != Value::TYPE_LIST) { | 1163 if (temp->GetType() != Value::TYPE_LIST) { |
| 1119 *error = errors::kInvalidIsolation; | 1164 *error = errors::kInvalidIsolation; |
| 1120 return false; | 1165 return false; |
| 1121 } | 1166 } |
| 1122 | 1167 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1134 if (isolation_string == values::kIsolatedStorage) { | 1179 if (isolation_string == values::kIsolatedStorage) { |
| 1135 is_storage_isolated_ = true; | 1180 is_storage_isolated_ = true; |
| 1136 } else { | 1181 } else { |
| 1137 DLOG(WARNING) << "Did not recognize isolation type: " | 1182 DLOG(WARNING) << "Did not recognize isolation type: " |
| 1138 << isolation_string; | 1183 << isolation_string; |
| 1139 } | 1184 } |
| 1140 } | 1185 } |
| 1141 return true; | 1186 return true; |
| 1142 } | 1187 } |
| 1143 | 1188 |
| 1144 bool Extension::LoadWebIntentServices(const extensions::Manifest* manifest, | 1189 bool Extension::LoadWebIntentServices(const base::DictionaryValue& manifest, |
| 1145 std::string* error) { | 1190 std::string* error) { |
| 1146 DCHECK(error); | 1191 DCHECK(error); |
| 1147 | 1192 |
| 1148 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) | 1193 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
| 1149 return true; | 1194 return true; |
| 1150 | 1195 |
| 1151 if (!manifest->HasKey(keys::kIntents)) | 1196 if (!manifest.HasKey(keys::kIntents)) |
| 1152 return true; | 1197 return true; |
| 1153 | 1198 |
| 1154 DictionaryValue* all_services = NULL; | 1199 DictionaryValue* all_services = NULL; |
| 1155 if (!manifest->GetDictionary(keys::kIntents, &all_services)) { | 1200 if (!manifest.GetDictionary(keys::kIntents, &all_services)) { |
| 1156 *error = errors::kInvalidIntents; | 1201 *error = errors::kInvalidIntents; |
| 1157 return false; | 1202 return false; |
| 1158 } | 1203 } |
| 1159 | 1204 |
| 1160 std::string value; | 1205 std::string value; |
| 1161 for (DictionaryValue::key_iterator iter(all_services->begin_keys()); | 1206 for (DictionaryValue::key_iterator iter(all_services->begin_keys()); |
| 1162 iter != all_services->end_keys(); ++iter) { | 1207 iter != all_services->end_keys(); ++iter) { |
| 1163 webkit_glue::WebIntentServiceData service; | 1208 webkit_glue::WebIntentServiceData service; |
| 1164 | 1209 |
| 1165 DictionaryValue* one_service = NULL; | 1210 DictionaryValue* one_service = NULL; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1204 service.disposition = | 1249 service.disposition = |
| 1205 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; | 1250 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; |
| 1206 } | 1251 } |
| 1207 } | 1252 } |
| 1208 | 1253 |
| 1209 intents_services_.push_back(service); | 1254 intents_services_.push_back(service); |
| 1210 } | 1255 } |
| 1211 return true; | 1256 return true; |
| 1212 } | 1257 } |
| 1213 | 1258 |
| 1259 |
| 1260 bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest, |
| 1261 std::string* error) { |
| 1262 if (web_extent().is_empty()) |
| 1263 return true; |
| 1264 |
| 1265 for (DictionaryValue::key_iterator key = manifest->begin_keys(); |
| 1266 key != manifest->end_keys(); ++key) { |
| 1267 if (!IsBaseCrxKey(*key) && |
| 1268 *key != keys::kApp && |
| 1269 *key != keys::kPermissions && |
| 1270 *key != keys::kOptionalPermissions && |
| 1271 *key != keys::kOptionsPage && |
| 1272 *key != keys::kBackground && |
| 1273 *key != keys::kOfflineEnabled && |
| 1274 *key != keys::kMinimumChromeVersion && |
| 1275 *key != keys::kRequirements) { |
| 1276 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1277 errors::kHostedAppsCannotIncludeExtensionFeatures, *key); |
| 1278 return false; |
| 1279 } |
| 1280 } |
| 1281 |
| 1282 return true; |
| 1283 } |
| 1284 |
| 1214 // static | 1285 // static |
| 1215 bool Extension::IsTrustedId(const std::string& id) { | 1286 bool Extension::IsTrustedId(const std::string& id) { |
| 1216 // See http://b/4946060 for more details. | 1287 // See http://b/4946060 for more details. |
| 1217 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); | 1288 return id == std::string("nckgahadagoaajjgafhacjanaoiihapd"); |
| 1218 } | 1289 } |
| 1219 | 1290 |
| 1220 Extension::Extension(const FilePath& path, Location location) | 1291 Extension::Extension(const FilePath& path, Location location) |
| 1221 : manifest_version_(0), | 1292 : manifest_version_(0), |
| 1222 incognito_split_mode_(false), | 1293 incognito_split_mode_(false), |
| 1223 offline_enabled_(false), | 1294 offline_enabled_(false), |
| 1224 location_(location), | 1295 location_(location), |
| 1225 converted_from_user_script_(false), | 1296 converted_from_user_script_(false), |
| 1297 is_theme_(false), |
| 1298 is_app_(false), |
| 1299 is_platform_app_(false), |
| 1226 is_storage_isolated_(false), | 1300 is_storage_isolated_(false), |
| 1227 launch_container_(extension_misc::LAUNCH_TAB), | 1301 launch_container_(extension_misc::LAUNCH_TAB), |
| 1228 launch_width_(0), | 1302 launch_width_(0), |
| 1229 launch_height_(0), | 1303 launch_height_(0), |
| 1230 wants_file_access_(false), | 1304 wants_file_access_(false), |
| 1231 creation_flags_(0) { | 1305 creation_flags_(0) { |
| 1232 DCHECK(path.empty() || path.IsAbsolute()); | 1306 DCHECK(path.empty() || path.IsAbsolute()); |
| 1233 path_ = MaybeNormalizePath(path); | 1307 path_ = MaybeNormalizePath(path); |
| 1234 } | 1308 } |
| 1235 | 1309 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 return *ResourceBundle::GetSharedInstance().GetBitmapNamed( | 1448 return *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 1375 IDR_EXTENSION_DEFAULT_ICON); | 1449 IDR_EXTENSION_DEFAULT_ICON); |
| 1376 } | 1450 } |
| 1377 } | 1451 } |
| 1378 | 1452 |
| 1379 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { | 1453 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) { |
| 1380 return GURL(std::string(chrome::kExtensionScheme) + | 1454 return GURL(std::string(chrome::kExtensionScheme) + |
| 1381 chrome::kStandardSchemeSeparator + extension_id + "/"); | 1455 chrome::kStandardSchemeSeparator + extension_id + "/"); |
| 1382 } | 1456 } |
| 1383 | 1457 |
| 1384 bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, | 1458 bool Extension::InitFromValue(const DictionaryValue& source, int flags, |
| 1385 std::string* error) { | 1459 std::string* error) { |
| 1386 DCHECK(error); | 1460 DCHECK(error); |
| 1387 base::AutoLock auto_lock(runtime_data_lock_); | 1461 base::AutoLock auto_lock(runtime_data_lock_); |
| 1388 | |
| 1389 if (!manifest->ValidateManifest(error)) | |
| 1390 return false; | |
| 1391 | |
| 1392 // When strict error checks are enabled, make URL pattern parsing strict. | 1462 // When strict error checks are enabled, make URL pattern parsing strict. |
| 1393 URLPattern::ParseOption parse_strictness = | 1463 URLPattern::ParseOption parse_strictness = |
| 1394 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 1464 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
| 1395 : URLPattern::IGNORE_PORTS); | 1465 : URLPattern::IGNORE_PORTS); |
| 1396 | 1466 |
| 1397 // Initialize permissions with an empty, default permission set. | 1467 // Initialize permissions with an empty, default permission set. |
| 1398 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); | 1468 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); |
| 1399 optional_permission_set_ = new ExtensionPermissionSet(); | 1469 optional_permission_set_ = new ExtensionPermissionSet(); |
| 1400 required_permission_set_ = new ExtensionPermissionSet(); | 1470 required_permission_set_ = new ExtensionPermissionSet(); |
| 1401 | 1471 |
| 1402 if (manifest->HasKey(keys::kManifestVersion)) { | 1472 if (source.HasKey(keys::kManifestVersion)) { |
| 1403 int manifest_version = 0; | 1473 int manifest_version = 0; |
| 1404 if (!manifest->GetInteger(keys::kManifestVersion, &manifest_version) || | 1474 if (!source.GetInteger(keys::kManifestVersion, &manifest_version) || |
| 1405 manifest_version < 1) { | 1475 manifest_version < 1) { |
| 1406 *error = errors::kInvalidManifestVersion; | 1476 *error = errors::kInvalidManifestVersion; |
| 1407 return false; | 1477 return false; |
| 1408 } | 1478 } |
| 1409 manifest_version_ = manifest_version; | 1479 manifest_version_ = manifest_version; |
| 1410 } else { | 1480 } else { |
| 1411 // Version 1 was the original version, which lacked a version indicator. | 1481 // Version 1 was the original version, which lacked a version indicator. |
| 1412 manifest_version_ = 1; | 1482 manifest_version_ = 1; |
| 1413 } | 1483 } |
| 1414 | 1484 |
| 1415 if (flags & REQUIRE_MODERN_MANIFEST_VERSION && | 1485 if (flags & REQUIRE_MODERN_MANIFEST_VERSION && |
| 1416 manifest_version() < kModernManifestVersion && | 1486 manifest_version() < kModernManifestVersion && |
| 1417 !CommandLine::ForCurrentProcess()->HasSwitch( | 1487 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 1418 switches::kAllowLegacyExtensionManifests)) { | 1488 switches::kAllowLegacyExtensionManifests)) { |
| 1419 *error = errors::kInvalidManifestVersion; | 1489 *error = errors::kInvalidManifestVersion; |
| 1420 return false; | 1490 return false; |
| 1421 } | 1491 } |
| 1422 | 1492 |
| 1423 if (manifest->HasKey(keys::kPublicKey)) { | 1493 if (source.HasKey(keys::kPublicKey)) { |
| 1424 std::string public_key_bytes; | 1494 std::string public_key_bytes; |
| 1425 if (!manifest->GetString(keys::kPublicKey, | 1495 if (!source.GetString(keys::kPublicKey, |
| 1426 &public_key_) || | 1496 &public_key_) || |
| 1427 !ParsePEMKeyBytes(public_key_, | 1497 !ParsePEMKeyBytes(public_key_, |
| 1428 &public_key_bytes) || | 1498 &public_key_bytes) || |
| 1429 !GenerateId(public_key_bytes, &id_)) { | 1499 !GenerateId(public_key_bytes, &id_)) { |
| 1430 *error = errors::kInvalidKey; | 1500 *error = errors::kInvalidKey; |
| 1431 return false; | 1501 return false; |
| 1432 } | 1502 } |
| 1433 } else if (flags & REQUIRE_KEY) { | 1503 } else if (flags & REQUIRE_KEY) { |
| 1434 *error = errors::kInvalidKey; | 1504 *error = errors::kInvalidKey; |
| 1435 return false; | 1505 return false; |
| 1436 } else { | 1506 } else { |
| 1437 // If there is a path, we generate the ID from it. This is useful for | 1507 // If there is a path, we generate the ID from it. This is useful for |
| 1438 // development mode, because it keeps the ID stable across restarts and | 1508 // development mode, because it keeps the ID stable across restarts and |
| 1439 // reloading the extension. | 1509 // reloading the extension. |
| 1440 id_ = Extension::GenerateIdForPath(path()); | 1510 id_ = Extension::GenerateIdForPath(path()); |
| 1441 if (id_.empty()) { | 1511 if (id_.empty()) { |
| 1442 NOTREACHED() << "Could not create ID from path."; | 1512 NOTREACHED() << "Could not create ID from path."; |
| 1443 return false; | 1513 return false; |
| 1444 } | 1514 } |
| 1445 } | 1515 } |
| 1446 | 1516 |
| 1447 creation_flags_ = flags; | 1517 creation_flags_ = flags; |
| 1448 | 1518 |
| 1449 manifest_.reset(manifest); | 1519 // Make a copy of the manifest so we can store it in prefs. |
| 1520 manifest_value_.reset(source.DeepCopy()); |
| 1450 | 1521 |
| 1451 // Initialize the URL. | 1522 // Initialize the URL. |
| 1452 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); | 1523 extension_url_ = Extension::GetBaseURLFromExtensionId(id()); |
| 1453 | 1524 |
| 1454 // Initialize version. | 1525 // Initialize version. |
| 1455 std::string version_str; | 1526 std::string version_str; |
| 1456 if (!manifest->GetString(keys::kVersion, &version_str)) { | 1527 if (!source.GetString(keys::kVersion, &version_str)) { |
| 1457 *error = errors::kInvalidVersion; | 1528 *error = errors::kInvalidVersion; |
| 1458 return false; | 1529 return false; |
| 1459 } | 1530 } |
| 1460 version_.reset(Version::GetVersionFromString(version_str)); | 1531 version_.reset(Version::GetVersionFromString(version_str)); |
| 1461 if (!version_.get() || | 1532 if (!version_.get() || |
| 1462 version_->components().size() > 4) { | 1533 version_->components().size() > 4) { |
| 1463 *error = errors::kInvalidVersion; | 1534 *error = errors::kInvalidVersion; |
| 1464 return false; | 1535 return false; |
| 1465 } | 1536 } |
| 1466 | 1537 |
| 1467 // Initialize name. | 1538 // Initialize name. |
| 1468 string16 localized_name; | 1539 string16 localized_name; |
| 1469 if (!manifest->GetString(keys::kName, &localized_name)) { | 1540 if (!source.GetString(keys::kName, &localized_name)) { |
| 1470 *error = errors::kInvalidName; | 1541 *error = errors::kInvalidName; |
| 1471 return false; | 1542 return false; |
| 1472 } | 1543 } |
| 1473 base::i18n::AdjustStringForLocaleDirection(&localized_name); | 1544 base::i18n::AdjustStringForLocaleDirection(&localized_name); |
| 1474 name_ = UTF16ToUTF8(localized_name); | 1545 name_ = UTF16ToUTF8(localized_name); |
| 1475 | 1546 |
| 1476 // Load App settings. LoadExtent at least has to be done before | 1547 // Load App settings. LoadExtent at least has to be done before |
| 1477 // ParsePermissions(), because the valid permissions depend on what type of | 1548 // ParsePermissions(), because the valid permissions depend on what type of |
| 1478 // package this is. | 1549 // package this is. |
| 1479 if (is_app() && | 1550 if (!LoadIsApp(manifest_value_.get(), error) || |
| 1480 (!LoadExtent(manifest_.get(), keys::kWebURLs, | 1551 !LoadExtent(manifest_value_.get(), keys::kWebURLs, |
| 1481 &extent_, | 1552 &extent_, |
| 1482 errors::kInvalidWebURLs, errors::kInvalidWebURL, | 1553 errors::kInvalidWebURLs, errors::kInvalidWebURL, |
| 1483 parse_strictness, error) || | 1554 parse_strictness, error) || |
| 1484 !LoadLaunchURL(manifest_.get(), error) || | 1555 !EnsureNotHybridApp(manifest_value_.get(), error) || |
| 1485 !LoadLaunchContainer(manifest_.get(), error))) { | 1556 !LoadLaunchURL(manifest_value_.get(), error) || |
| 1557 !LoadLaunchContainer(manifest_value_.get(), error)) { |
| 1486 return false; | 1558 return false; |
| 1487 } | 1559 } |
| 1488 | 1560 |
| 1489 if (is_platform_app()) { | 1561 if (is_platform_app_) { |
| 1490 if (launch_container() != extension_misc::LAUNCH_SHELL) { | 1562 if (launch_container() != extension_misc::LAUNCH_SHELL) { |
| 1491 *error = errors::kInvalidLaunchContainerForPlatform; | 1563 *error = errors::kInvalidLaunchContainerForPlatform; |
| 1492 return false; | 1564 return false; |
| 1493 } | 1565 } |
| 1494 } else if (launch_container() == extension_misc::LAUNCH_SHELL) { | 1566 } else if (launch_container() == extension_misc::LAUNCH_SHELL) { |
| 1495 *error = errors::kInvalidLaunchContainerForNonPlatform; | 1567 *error = errors::kInvalidLaunchContainerForNonPlatform; |
| 1496 return false; | 1568 return false; |
| 1497 } | 1569 } |
| 1498 | 1570 |
| 1499 // Initialize the permissions (optional). | 1571 // Initialize the permissions (optional). |
| 1500 ExtensionAPIPermissionSet api_permissions; | 1572 ExtensionAPIPermissionSet api_permissions; |
| 1501 URLPatternSet host_permissions; | 1573 URLPatternSet host_permissions; |
| 1502 if (!ParsePermissions(manifest_.get(), | 1574 if (!ParsePermissions(&source, |
| 1503 keys::kPermissions, | 1575 keys::kPermissions, |
| 1504 flags, | 1576 flags, |
| 1505 error, | 1577 error, |
| 1506 &api_permissions, | 1578 &api_permissions, |
| 1507 &host_permissions)) { | 1579 &host_permissions)) { |
| 1508 return false; | 1580 return false; |
| 1509 } | 1581 } |
| 1510 | 1582 |
| 1511 // Initialize the optional permissions (optional). | 1583 // Initialize the optional permissions (optional). |
| 1512 ExtensionAPIPermissionSet optional_api_permissions; | 1584 ExtensionAPIPermissionSet optional_api_permissions; |
| 1513 URLPatternSet optional_host_permissions; | 1585 URLPatternSet optional_host_permissions; |
| 1514 if (!ParsePermissions(manifest_.get(), | 1586 if (!ParsePermissions(&source, |
| 1515 keys::kOptionalPermissions, | 1587 keys::kOptionalPermissions, |
| 1516 flags, | 1588 flags, |
| 1517 error, | 1589 error, |
| 1518 &optional_api_permissions, | 1590 &optional_api_permissions, |
| 1519 &optional_host_permissions)) { | 1591 &optional_host_permissions)) { |
| 1520 return false; | 1592 return false; |
| 1521 } | 1593 } |
| 1522 | 1594 |
| 1523 // Initialize description (if present). | 1595 // Initialize description (if present). |
| 1524 if (manifest->HasKey(keys::kDescription)) { | 1596 if (source.HasKey(keys::kDescription)) { |
| 1525 if (!manifest->GetString(keys::kDescription, | 1597 if (!source.GetString(keys::kDescription, |
| 1526 &description_)) { | 1598 &description_)) { |
| 1527 *error = errors::kInvalidDescription; | 1599 *error = errors::kInvalidDescription; |
| 1528 return false; | 1600 return false; |
| 1529 } | 1601 } |
| 1530 } | 1602 } |
| 1531 | 1603 |
| 1532 // Initialize homepage url (if present). | 1604 // Initialize homepage url (if present). |
| 1533 if (manifest->HasKey(keys::kHomepageURL)) { | 1605 if (source.HasKey(keys::kHomepageURL)) { |
| 1534 std::string tmp; | 1606 std::string tmp; |
| 1535 if (!manifest->GetString(keys::kHomepageURL, &tmp)) { | 1607 if (!source.GetString(keys::kHomepageURL, &tmp)) { |
| 1536 *error = ExtensionErrorUtils::FormatErrorMessage( | 1608 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1537 errors::kInvalidHomepageURL, ""); | 1609 errors::kInvalidHomepageURL, ""); |
| 1538 return false; | 1610 return false; |
| 1539 } | 1611 } |
| 1540 homepage_url_ = GURL(tmp); | 1612 homepage_url_ = GURL(tmp); |
| 1541 if (!homepage_url_.is_valid() || | 1613 if (!homepage_url_.is_valid() || |
| 1542 (!homepage_url_.SchemeIs("http") && | 1614 (!homepage_url_.SchemeIs("http") && |
| 1543 !homepage_url_.SchemeIs("https"))) { | 1615 !homepage_url_.SchemeIs("https"))) { |
| 1544 *error = ExtensionErrorUtils::FormatErrorMessage( | 1616 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1545 errors::kInvalidHomepageURL, tmp); | 1617 errors::kInvalidHomepageURL, tmp); |
| 1546 return false; | 1618 return false; |
| 1547 } | 1619 } |
| 1548 } | 1620 } |
| 1549 | 1621 |
| 1550 // Initialize update url (if present). | 1622 // Initialize update url (if present). |
| 1551 if (manifest->HasKey(keys::kUpdateURL)) { | 1623 if (source.HasKey(keys::kUpdateURL)) { |
| 1552 std::string tmp; | 1624 std::string tmp; |
| 1553 if (!manifest->GetString(keys::kUpdateURL, &tmp)) { | 1625 if (!source.GetString(keys::kUpdateURL, &tmp)) { |
| 1554 *error = ExtensionErrorUtils::FormatErrorMessage( | 1626 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1555 errors::kInvalidUpdateURL, ""); | 1627 errors::kInvalidUpdateURL, ""); |
| 1556 return false; | 1628 return false; |
| 1557 } | 1629 } |
| 1558 update_url_ = GURL(tmp); | 1630 update_url_ = GURL(tmp); |
| 1559 if (!update_url_.is_valid() || | 1631 if (!update_url_.is_valid() || |
| 1560 update_url_.has_ref()) { | 1632 update_url_.has_ref()) { |
| 1561 *error = ExtensionErrorUtils::FormatErrorMessage( | 1633 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1562 errors::kInvalidUpdateURL, tmp); | 1634 errors::kInvalidUpdateURL, tmp); |
| 1563 return false; | 1635 return false; |
| 1564 } | 1636 } |
| 1565 } | 1637 } |
| 1566 | 1638 |
| 1567 // Validate minimum Chrome version (if present). We don't need to store this, | 1639 // Validate minimum Chrome version (if present). We don't need to store this, |
| 1568 // since the extension is not valid if it is incorrect. | 1640 // since the extension is not valid if it is incorrect. |
| 1569 if (manifest->HasKey(keys::kMinimumChromeVersion)) { | 1641 if (source.HasKey(keys::kMinimumChromeVersion)) { |
| 1570 std::string minimum_version_string; | 1642 std::string minimum_version_string; |
| 1571 if (!manifest->GetString(keys::kMinimumChromeVersion, | 1643 if (!source.GetString(keys::kMinimumChromeVersion, |
| 1572 &minimum_version_string)) { | 1644 &minimum_version_string)) { |
| 1573 *error = errors::kInvalidMinimumChromeVersion; | 1645 *error = errors::kInvalidMinimumChromeVersion; |
| 1574 return false; | 1646 return false; |
| 1575 } | 1647 } |
| 1576 | 1648 |
| 1577 scoped_ptr<Version> minimum_version( | 1649 scoped_ptr<Version> minimum_version( |
| 1578 Version::GetVersionFromString(minimum_version_string)); | 1650 Version::GetVersionFromString(minimum_version_string)); |
| 1579 if (!minimum_version.get()) { | 1651 if (!minimum_version.get()) { |
| 1580 *error = errors::kInvalidMinimumChromeVersion; | 1652 *error = errors::kInvalidMinimumChromeVersion; |
| 1581 return false; | 1653 return false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1597 if (current_version->CompareTo(*minimum_version) < 0) { | 1669 if (current_version->CompareTo(*minimum_version) < 0) { |
| 1598 *error = ExtensionErrorUtils::FormatErrorMessage( | 1670 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1599 errors::kChromeVersionTooLow, | 1671 errors::kChromeVersionTooLow, |
| 1600 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), | 1672 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), |
| 1601 minimum_version_string); | 1673 minimum_version_string); |
| 1602 return false; | 1674 return false; |
| 1603 } | 1675 } |
| 1604 } | 1676 } |
| 1605 | 1677 |
| 1606 // Initialize converted_from_user_script (if present) | 1678 // Initialize converted_from_user_script (if present) |
| 1607 if (manifest->HasKey(keys::kConvertedFromUserScript)) | 1679 source.GetBoolean(keys::kConvertedFromUserScript, |
| 1608 manifest->GetBoolean(keys::kConvertedFromUserScript, | 1680 &converted_from_user_script_); |
| 1609 &converted_from_user_script_); | |
| 1610 | 1681 |
| 1611 // Initialize icons (if present). | 1682 // Initialize icons (if present). |
| 1612 if (manifest->HasKey(keys::kIcons)) { | 1683 if (source.HasKey(keys::kIcons)) { |
| 1613 DictionaryValue* icons_value = NULL; | 1684 DictionaryValue* icons_value = NULL; |
| 1614 if (!manifest->GetDictionary(keys::kIcons, &icons_value)) { | 1685 if (!source.GetDictionary(keys::kIcons, &icons_value)) { |
| 1615 *error = errors::kInvalidIcons; | 1686 *error = errors::kInvalidIcons; |
| 1616 return false; | 1687 return false; |
| 1617 } | 1688 } |
| 1618 | 1689 |
| 1619 for (size_t i = 0; i < arraysize(kIconSizes); ++i) { | 1690 for (size_t i = 0; i < arraysize(kIconSizes); ++i) { |
| 1620 std::string key = base::IntToString(kIconSizes[i]); | 1691 std::string key = base::IntToString(kIconSizes[i]); |
| 1621 if (icons_value->HasKey(key)) { | 1692 if (icons_value->HasKey(key)) { |
| 1622 std::string icon_path; | 1693 std::string icon_path; |
| 1623 if (!icons_value->GetString(key, &icon_path)) { | 1694 if (!icons_value->GetString(key, &icon_path)) { |
| 1624 *error = ExtensionErrorUtils::FormatErrorMessage( | 1695 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1625 errors::kInvalidIconPath, key); | 1696 errors::kInvalidIconPath, key); |
| 1626 return false; | 1697 return false; |
| 1627 } | 1698 } |
| 1628 | 1699 |
| 1629 if (!icon_path.empty() && icon_path[0] == '/') | 1700 if (!icon_path.empty() && icon_path[0] == '/') |
| 1630 icon_path = icon_path.substr(1); | 1701 icon_path = icon_path.substr(1); |
| 1631 | 1702 |
| 1632 if (icon_path.empty()) { | 1703 if (icon_path.empty()) { |
| 1633 *error = ExtensionErrorUtils::FormatErrorMessage( | 1704 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1634 errors::kInvalidIconPath, key); | 1705 errors::kInvalidIconPath, key); |
| 1635 return false; | 1706 return false; |
| 1636 } | 1707 } |
| 1637 | 1708 |
| 1638 icons_.Add(kIconSizes[i], icon_path); | 1709 icons_.Add(kIconSizes[i], icon_path); |
| 1639 } | 1710 } |
| 1640 } | 1711 } |
| 1641 } | 1712 } |
| 1642 | 1713 |
| 1643 // Initialize themes (if present). | 1714 // Initialize themes (if present). |
| 1644 if (manifest->HasKey(keys::kTheme)) { | 1715 is_theme_ = false; |
| 1716 if (source.HasKey(keys::kTheme)) { |
| 1717 // Themes cannot contain extension keys. |
| 1718 if (ContainsNonThemeKeys(source)) { |
| 1719 *error = errors::kThemesCannotContainExtensions; |
| 1720 return false; |
| 1721 } |
| 1722 |
| 1645 DictionaryValue* theme_value = NULL; | 1723 DictionaryValue* theme_value = NULL; |
| 1646 if (!manifest->GetDictionary(keys::kTheme, &theme_value)) { | 1724 if (!source.GetDictionary(keys::kTheme, &theme_value)) { |
| 1647 *error = errors::kInvalidTheme; | 1725 *error = errors::kInvalidTheme; |
| 1648 return false; | 1726 return false; |
| 1649 } | 1727 } |
| 1728 is_theme_ = true; |
| 1650 | 1729 |
| 1651 DictionaryValue* images_value = NULL; | 1730 DictionaryValue* images_value = NULL; |
| 1652 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | 1731 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { |
| 1653 // Validate that the images are all strings | 1732 // Validate that the images are all strings |
| 1654 for (DictionaryValue::key_iterator iter = images_value->begin_keys(); | 1733 for (DictionaryValue::key_iterator iter = images_value->begin_keys(); |
| 1655 iter != images_value->end_keys(); ++iter) { | 1734 iter != images_value->end_keys(); ++iter) { |
| 1656 std::string val; | 1735 std::string val; |
| 1657 if (!images_value->GetString(*iter, &val)) { | 1736 if (!images_value->GetString(*iter, &val)) { |
| 1658 *error = errors::kInvalidThemeImages; | 1737 *error = errors::kInvalidThemeImages; |
| 1659 return false; | 1738 return false; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | 1791 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, |
| 1713 &display_properties_value)) { | 1792 &display_properties_value)) { |
| 1714 theme_display_properties_.reset( | 1793 theme_display_properties_.reset( |
| 1715 display_properties_value->DeepCopy()); | 1794 display_properties_value->DeepCopy()); |
| 1716 } | 1795 } |
| 1717 | 1796 |
| 1718 return true; | 1797 return true; |
| 1719 } | 1798 } |
| 1720 | 1799 |
| 1721 // Initialize plugins (optional). | 1800 // Initialize plugins (optional). |
| 1722 if (manifest->HasKey(keys::kPlugins)) { | 1801 if (source.HasKey(keys::kPlugins)) { |
| 1723 ListValue* list_value = NULL; | 1802 ListValue* list_value = NULL; |
| 1724 if (!manifest->GetList(keys::kPlugins, &list_value)) { | 1803 if (!source.GetList(keys::kPlugins, &list_value)) { |
| 1725 *error = errors::kInvalidPlugins; | 1804 *error = errors::kInvalidPlugins; |
| 1726 return false; | 1805 return false; |
| 1727 } | 1806 } |
| 1728 | 1807 |
| 1729 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1808 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 1730 DictionaryValue* plugin_value = NULL; | 1809 DictionaryValue* plugin_value = NULL; |
| 1731 std::string path_str; | 1810 std::string path_str; |
| 1732 bool is_public = false; | 1811 bool is_public = false; |
| 1733 | 1812 |
| 1734 if (!list_value->GetDictionary(i, &plugin_value)) { | 1813 if (!list_value->GetDictionary(i, &plugin_value)) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1756 // parse the manifest entry so that error messages are consistently | 1835 // parse the manifest entry so that error messages are consistently |
| 1757 // displayed across platforms. | 1836 // displayed across platforms. |
| 1758 #if !defined(OS_CHROMEOS) | 1837 #if !defined(OS_CHROMEOS) |
| 1759 plugins_.push_back(PluginInfo()); | 1838 plugins_.push_back(PluginInfo()); |
| 1760 plugins_.back().path = path().Append(FilePath::FromUTF8Unsafe(path_str)); | 1839 plugins_.back().path = path().Append(FilePath::FromUTF8Unsafe(path_str)); |
| 1761 plugins_.back().is_public = is_public; | 1840 plugins_.back().is_public = is_public; |
| 1762 #endif | 1841 #endif |
| 1763 } | 1842 } |
| 1764 } | 1843 } |
| 1765 | 1844 |
| 1766 if (manifest->HasKey(keys::kNaClModules)) { | 1845 if (source.HasKey(keys::kNaClModules)) { |
| 1767 ListValue* list_value = NULL; | 1846 ListValue* list_value = NULL; |
| 1768 if (!manifest->GetList(keys::kNaClModules, &list_value)) { | 1847 if (!source.GetList(keys::kNaClModules, &list_value)) { |
| 1769 *error = errors::kInvalidNaClModules; | 1848 *error = errors::kInvalidNaClModules; |
| 1770 return false; | 1849 return false; |
| 1771 } | 1850 } |
| 1772 | 1851 |
| 1773 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1852 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 1774 DictionaryValue* module_value = NULL; | 1853 DictionaryValue* module_value = NULL; |
| 1775 std::string path_str; | 1854 std::string path_str; |
| 1776 std::string mime_type; | 1855 std::string mime_type; |
| 1777 | 1856 |
| 1778 if (!list_value->GetDictionary(i, &module_value)) { | 1857 if (!list_value->GetDictionary(i, &module_value)) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1794 return false; | 1873 return false; |
| 1795 } | 1874 } |
| 1796 | 1875 |
| 1797 nacl_modules_.push_back(NaClModuleInfo()); | 1876 nacl_modules_.push_back(NaClModuleInfo()); |
| 1798 nacl_modules_.back().url = GetResourceURL(path_str); | 1877 nacl_modules_.back().url = GetResourceURL(path_str); |
| 1799 nacl_modules_.back().mime_type = mime_type; | 1878 nacl_modules_.back().mime_type = mime_type; |
| 1800 } | 1879 } |
| 1801 } | 1880 } |
| 1802 | 1881 |
| 1803 // Initialize content scripts (optional). | 1882 // Initialize content scripts (optional). |
| 1804 if (manifest->HasKey(keys::kContentScripts)) { | 1883 if (source.HasKey(keys::kContentScripts)) { |
| 1805 ListValue* list_value; | 1884 ListValue* list_value; |
| 1806 if (!manifest->GetList(keys::kContentScripts, &list_value)) { | 1885 if (!source.GetList(keys::kContentScripts, &list_value)) { |
| 1807 *error = errors::kInvalidContentScriptsList; | 1886 *error = errors::kInvalidContentScriptsList; |
| 1808 return false; | 1887 return false; |
| 1809 } | 1888 } |
| 1810 | 1889 |
| 1811 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1890 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 1812 DictionaryValue* content_script = NULL; | 1891 DictionaryValue* content_script = NULL; |
| 1813 if (!list_value->GetDictionary(i, &content_script)) { | 1892 if (!list_value->GetDictionary(i, &content_script)) { |
| 1814 *error = ExtensionErrorUtils::FormatErrorMessage( | 1893 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 1815 errors::kInvalidContentScript, base::IntToString(i)); | 1894 errors::kInvalidContentScript, base::IntToString(i)); |
| 1816 return false; | 1895 return false; |
| 1817 } | 1896 } |
| 1818 | 1897 |
| 1819 UserScript script; | 1898 UserScript script; |
| 1820 if (!LoadUserScriptHelper(content_script, i, flags, error, &script)) | 1899 if (!LoadUserScriptHelper(content_script, i, flags, error, &script)) |
| 1821 return false; // Failed to parse script context definition. | 1900 return false; // Failed to parse script context definition. |
| 1822 script.set_extension_id(id()); | 1901 script.set_extension_id(id()); |
| 1823 if (converted_from_user_script_) { | 1902 if (converted_from_user_script_) { |
| 1824 script.set_emulate_greasemonkey(true); | 1903 script.set_emulate_greasemonkey(true); |
| 1825 script.set_match_all_frames(true); // Greasemonkey matches all frames. | 1904 script.set_match_all_frames(true); // Greasemonkey matches all frames. |
| 1826 } | 1905 } |
| 1827 content_scripts_.push_back(script); | 1906 content_scripts_.push_back(script); |
| 1828 } | 1907 } |
| 1829 } | 1908 } |
| 1830 | 1909 |
| 1831 // Initialize page action (optional). | 1910 // Initialize page action (optional). |
| 1832 DictionaryValue* page_action_value = NULL; | 1911 DictionaryValue* page_action_value = NULL; |
| 1833 | 1912 |
| 1834 if (manifest->HasKey(keys::kPageActions)) { | 1913 if (source.HasKey(keys::kPageActions)) { |
| 1835 ListValue* list_value = NULL; | 1914 ListValue* list_value = NULL; |
| 1836 if (!manifest->GetList(keys::kPageActions, &list_value)) { | 1915 if (!source.GetList(keys::kPageActions, &list_value)) { |
| 1837 *error = errors::kInvalidPageActionsList; | 1916 *error = errors::kInvalidPageActionsList; |
| 1838 return false; | 1917 return false; |
| 1839 } | 1918 } |
| 1840 | 1919 |
| 1841 size_t list_value_length = list_value->GetSize(); | 1920 size_t list_value_length = list_value->GetSize(); |
| 1842 | 1921 |
| 1843 if (list_value_length == 0u) { | 1922 if (list_value_length == 0u) { |
| 1844 // A list with zero items is allowed, and is equivalent to not having | 1923 // A list with zero items is allowed, and is equivalent to not having |
| 1845 // a page_actions key in the manifest. Don't set |page_action_value|. | 1924 // a page_actions key in the manifest. Don't set |page_action_value|. |
| 1846 } else if (list_value_length == 1u) { | 1925 } else if (list_value_length == 1u) { |
| 1847 if (!list_value->GetDictionary(0, &page_action_value)) { | 1926 if (!list_value->GetDictionary(0, &page_action_value)) { |
| 1848 *error = errors::kInvalidPageAction; | 1927 *error = errors::kInvalidPageAction; |
| 1849 return false; | 1928 return false; |
| 1850 } | 1929 } |
| 1851 } else { // list_value_length > 1u. | 1930 } else { // list_value_length > 1u. |
| 1852 *error = errors::kInvalidPageActionsListSize; | 1931 *error = errors::kInvalidPageActionsListSize; |
| 1853 return false; | 1932 return false; |
| 1854 } | 1933 } |
| 1855 } else if (manifest->HasKey(keys::kPageAction)) { | 1934 } else if (source.HasKey(keys::kPageAction)) { |
| 1856 if (!manifest->GetDictionary(keys::kPageAction, &page_action_value)) { | 1935 if (!source.GetDictionary(keys::kPageAction, &page_action_value)) { |
| 1857 *error = errors::kInvalidPageAction; | 1936 *error = errors::kInvalidPageAction; |
| 1858 return false; | 1937 return false; |
| 1859 } | 1938 } |
| 1860 } | 1939 } |
| 1861 | 1940 |
| 1862 // If page_action_value is not NULL, then there was a valid page action. | 1941 // If page_action_value is not NULL, then there was a valid page action. |
| 1863 if (page_action_value) { | 1942 if (page_action_value) { |
| 1864 page_action_.reset( | 1943 page_action_.reset( |
| 1865 LoadExtensionActionHelper(page_action_value, error)); | 1944 LoadExtensionActionHelper(page_action_value, error)); |
| 1866 if (!page_action_.get()) | 1945 if (!page_action_.get()) |
| 1867 return false; // Failed to parse page action definition. | 1946 return false; // Failed to parse page action definition. |
| 1868 } | 1947 } |
| 1869 | 1948 |
| 1870 // Initialize browser action (optional). | 1949 // Initialize browser action (optional). |
| 1871 if (manifest->HasKey(keys::kBrowserAction)) { | 1950 if (source.HasKey(keys::kBrowserAction)) { |
| 1872 DictionaryValue* browser_action_value = NULL; | 1951 DictionaryValue* browser_action_value = NULL; |
| 1873 if (!manifest->GetDictionary(keys::kBrowserAction, &browser_action_value)) { | 1952 if (!source.GetDictionary(keys::kBrowserAction, &browser_action_value)) { |
| 1874 *error = errors::kInvalidBrowserAction; | 1953 *error = errors::kInvalidBrowserAction; |
| 1875 return false; | 1954 return false; |
| 1876 } | 1955 } |
| 1877 | 1956 |
| 1878 browser_action_.reset( | 1957 browser_action_.reset( |
| 1879 LoadExtensionActionHelper(browser_action_value, error)); | 1958 LoadExtensionActionHelper(browser_action_value, error)); |
| 1880 if (!browser_action_.get()) | 1959 if (!browser_action_.get()) |
| 1881 return false; // Failed to parse browser action definition. | 1960 return false; // Failed to parse browser action definition. |
| 1882 } | 1961 } |
| 1883 | 1962 |
| 1884 // Initialize file browser actions (optional). | 1963 // Initialize file browser actions (optional). |
| 1885 if (manifest->HasKey(keys::kFileBrowserHandlers)) { | 1964 if (source.HasKey(keys::kFileBrowserHandlers)) { |
| 1886 ListValue* file_browser_handlers_value = NULL; | 1965 ListValue* file_browser_handlers_value = NULL; |
| 1887 if (!manifest->GetList(keys::kFileBrowserHandlers, | 1966 if (!source.GetList(keys::kFileBrowserHandlers, |
| 1888 &file_browser_handlers_value)) { | 1967 &file_browser_handlers_value)) { |
| 1889 *error = errors::kInvalidFileBrowserHandler; | 1968 *error = errors::kInvalidFileBrowserHandler; |
| 1890 return false; | 1969 return false; |
| 1891 } | 1970 } |
| 1892 | 1971 |
| 1893 file_browser_handlers_.reset( | 1972 file_browser_handlers_.reset( |
| 1894 LoadFileBrowserHandlers(file_browser_handlers_value, error)); | 1973 LoadFileBrowserHandlers(file_browser_handlers_value, error)); |
| 1895 if (!file_browser_handlers_.get()) | 1974 if (!file_browser_handlers_.get()) |
| 1896 return false; // Failed to parse file browser actions definition. | 1975 return false; // Failed to parse file browser actions definition. |
| 1897 } | 1976 } |
| 1898 | 1977 |
| 1899 // App isolation. | 1978 // App isolation. |
| 1900 if (api_permissions.count(ExtensionAPIPermission::kExperimental)) { | 1979 if (api_permissions.count(ExtensionAPIPermission::kExperimental)) { |
| 1901 if (is_app() && !LoadAppIsolation(manifest_.get(), error)) | 1980 if (!LoadAppIsolation(manifest_value_.get(), error)) |
| 1902 return false; | 1981 return false; |
| 1903 } | 1982 } |
| 1904 | 1983 |
| 1905 // Initialize options page url (optional). | 1984 // Initialize options page url (optional). |
| 1906 if (manifest->HasKey(keys::kOptionsPage)) { | 1985 // Function LoadIsApp() set is_app_ above. |
| 1986 if (source.HasKey(keys::kOptionsPage)) { |
| 1907 std::string options_str; | 1987 std::string options_str; |
| 1908 if (!manifest->GetString(keys::kOptionsPage, &options_str)) { | 1988 if (!source.GetString(keys::kOptionsPage, &options_str)) { |
| 1909 *error = errors::kInvalidOptionsPage; | 1989 *error = errors::kInvalidOptionsPage; |
| 1910 return false; | 1990 return false; |
| 1911 } | 1991 } |
| 1912 | 1992 |
| 1913 if (is_hosted_app()) { | 1993 if (is_hosted_app()) { |
| 1914 // hosted apps require an absolute URL. | 1994 // hosted apps require an absolute URL. |
| 1915 GURL options_url(options_str); | 1995 GURL options_url(options_str); |
| 1916 if (!options_url.is_valid() || | 1996 if (!options_url.is_valid() || |
| 1917 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) { | 1997 !(options_url.SchemeIs("http") || options_url.SchemeIs("https"))) { |
| 1918 *error = errors::kInvalidOptionsPageInHostedApp; | 1998 *error = errors::kInvalidOptionsPageInHostedApp; |
| 1919 return false; | 1999 return false; |
| 1920 } | 2000 } |
| 1921 options_url_ = options_url; | 2001 options_url_ = options_url; |
| 1922 } else { | 2002 } else { |
| 1923 GURL absolute(options_str); | 2003 GURL absolute(options_str); |
| 1924 if (absolute.is_valid()) { | 2004 if (absolute.is_valid()) { |
| 1925 *error = errors::kInvalidOptionsPageExpectUrlInPackage; | 2005 *error = errors::kInvalidOptionsPageExpectUrlInPackage; |
| 1926 return false; | 2006 return false; |
| 1927 } | 2007 } |
| 1928 options_url_ = GetResourceURL(options_str); | 2008 options_url_ = GetResourceURL(options_str); |
| 1929 if (!options_url_.is_valid()) { | 2009 if (!options_url_.is_valid()) { |
| 1930 *error = errors::kInvalidOptionsPage; | 2010 *error = errors::kInvalidOptionsPage; |
| 1931 return false; | 2011 return false; |
| 1932 } | 2012 } |
| 1933 } | 2013 } |
| 1934 } | 2014 } |
| 1935 | 2015 |
| 1936 // Initialize background url (optional). | 2016 // Initialize background url (optional). |
| 1937 if (manifest->HasKey(keys::kBackground)) { | 2017 if (source.HasKey(keys::kBackground)) { |
| 1938 std::string background_str; | 2018 std::string background_str; |
| 1939 if (!manifest->GetString(keys::kBackground, &background_str)) { | 2019 if (!source.GetString(keys::kBackground, &background_str)) { |
| 1940 *error = errors::kInvalidBackground; | 2020 *error = errors::kInvalidBackground; |
| 1941 return false; | 2021 return false; |
| 1942 } | 2022 } |
| 1943 | 2023 |
| 1944 if (is_hosted_app()) { | 2024 if (is_hosted_app()) { |
| 1945 // Make sure "background" permission is set. | 2025 // Make sure "background" permission is set. |
| 1946 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { | 2026 if (!api_permissions.count(ExtensionAPIPermission::kBackground)) { |
| 1947 *error = errors::kBackgroundPermissionNeeded; | 2027 *error = errors::kBackgroundPermissionNeeded; |
| 1948 return false; | 2028 return false; |
| 1949 } | 2029 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1960 bg_page.SchemeIs("http")))) { | 2040 bg_page.SchemeIs("http")))) { |
| 1961 *error = errors::kInvalidBackgroundInHostedApp; | 2041 *error = errors::kInvalidBackgroundInHostedApp; |
| 1962 return false; | 2042 return false; |
| 1963 } | 2043 } |
| 1964 background_url_ = bg_page; | 2044 background_url_ = bg_page; |
| 1965 } else { | 2045 } else { |
| 1966 background_url_ = GetResourceURL(background_str); | 2046 background_url_ = GetResourceURL(background_str); |
| 1967 } | 2047 } |
| 1968 } | 2048 } |
| 1969 | 2049 |
| 1970 if (manifest->HasKey(keys::kDefaultLocale)) { | 2050 if (source.HasKey(keys::kDefaultLocale)) { |
| 1971 if (!manifest->GetString(keys::kDefaultLocale, &default_locale_) || | 2051 if (!source.GetString(keys::kDefaultLocale, &default_locale_) || |
| 1972 !l10n_util::IsValidLocaleSyntax(default_locale_)) { | 2052 !l10n_util::IsValidLocaleSyntax(default_locale_)) { |
| 1973 *error = errors::kInvalidDefaultLocale; | 2053 *error = errors::kInvalidDefaultLocale; |
| 1974 return false; | 2054 return false; |
| 1975 } | 2055 } |
| 1976 } | 2056 } |
| 1977 | 2057 |
| 1978 // Chrome URL overrides (optional) | 2058 // Chrome URL overrides (optional) |
| 1979 if (manifest->HasKey(keys::kChromeURLOverrides)) { | 2059 if (source.HasKey(keys::kChromeURLOverrides)) { |
| 1980 DictionaryValue* overrides = NULL; | 2060 DictionaryValue* overrides = NULL; |
| 1981 if (!manifest->GetDictionary(keys::kChromeURLOverrides, &overrides)) { | 2061 if (!source.GetDictionary(keys::kChromeURLOverrides, &overrides)) { |
| 1982 *error = errors::kInvalidChromeURLOverrides; | 2062 *error = errors::kInvalidChromeURLOverrides; |
| 1983 return false; | 2063 return false; |
| 1984 } | 2064 } |
| 1985 | 2065 |
| 1986 // Validate that the overrides are all strings | 2066 // Validate that the overrides are all strings |
| 1987 for (DictionaryValue::key_iterator iter = overrides->begin_keys(); | 2067 for (DictionaryValue::key_iterator iter = overrides->begin_keys(); |
| 1988 iter != overrides->end_keys(); ++iter) { | 2068 iter != overrides->end_keys(); ++iter) { |
| 1989 std::string page = *iter; | 2069 std::string page = *iter; |
| 1990 std::string val; | 2070 std::string val; |
| 1991 // Restrict override pages to a list of supported URLs. | 2071 // Restrict override pages to a list of supported URLs. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2013 } | 2093 } |
| 2014 | 2094 |
| 2015 // An extension may override at most one page. | 2095 // An extension may override at most one page. |
| 2016 if (overrides->size() > 1) { | 2096 if (overrides->size() > 1) { |
| 2017 *error = errors::kMultipleOverrides; | 2097 *error = errors::kMultipleOverrides; |
| 2018 return false; | 2098 return false; |
| 2019 } | 2099 } |
| 2020 } | 2100 } |
| 2021 | 2101 |
| 2022 if (api_permissions.count(ExtensionAPIPermission::kExperimental) && | 2102 if (api_permissions.count(ExtensionAPIPermission::kExperimental) && |
| 2023 manifest->HasKey(keys::kInputComponents)) { | 2103 source.HasKey(keys::kInputComponents)) { |
| 2024 ListValue* list_value = NULL; | 2104 ListValue* list_value = NULL; |
| 2025 if (!manifest->GetList(keys::kInputComponents, &list_value)) { | 2105 if (!source.GetList(keys::kInputComponents, &list_value)) { |
| 2026 *error = errors::kInvalidInputComponents; | 2106 *error = errors::kInvalidInputComponents; |
| 2027 return false; | 2107 return false; |
| 2028 } | 2108 } |
| 2029 | 2109 |
| 2030 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2110 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
| 2031 DictionaryValue* module_value = NULL; | 2111 DictionaryValue* module_value = NULL; |
| 2032 std::string name_str; | 2112 std::string name_str; |
| 2033 InputComponentType type; | 2113 InputComponentType type; |
| 2034 std::string id_str; | 2114 std::string id_str; |
| 2035 std::string description_str; | 2115 std::string description_str; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2144 input_components_.back().description = description_str; | 2224 input_components_.back().description = description_str; |
| 2145 input_components_.back().language = language_str; | 2225 input_components_.back().language = language_str; |
| 2146 input_components_.back().layouts.insert(layouts.begin(), layouts.end()); | 2226 input_components_.back().layouts.insert(layouts.begin(), layouts.end()); |
| 2147 input_components_.back().shortcut_keycode = shortcut_keycode_str; | 2227 input_components_.back().shortcut_keycode = shortcut_keycode_str; |
| 2148 input_components_.back().shortcut_alt = shortcut_alt; | 2228 input_components_.back().shortcut_alt = shortcut_alt; |
| 2149 input_components_.back().shortcut_ctrl = shortcut_ctrl; | 2229 input_components_.back().shortcut_ctrl = shortcut_ctrl; |
| 2150 input_components_.back().shortcut_shift = shortcut_shift; | 2230 input_components_.back().shortcut_shift = shortcut_shift; |
| 2151 } | 2231 } |
| 2152 } | 2232 } |
| 2153 | 2233 |
| 2154 if (manifest->HasKey(keys::kOmnibox)) { | 2234 if (source.HasKey(keys::kOmnibox)) { |
| 2155 if (!manifest->GetString(keys::kOmniboxKeyword, &omnibox_keyword_) || | 2235 if (!source.GetString(keys::kOmniboxKeyword, &omnibox_keyword_) || |
| 2156 omnibox_keyword_.empty()) { | 2236 omnibox_keyword_.empty()) { |
| 2157 *error = errors::kInvalidOmniboxKeyword; | 2237 *error = errors::kInvalidOmniboxKeyword; |
| 2158 return false; | 2238 return false; |
| 2159 } | 2239 } |
| 2160 } | 2240 } |
| 2161 | 2241 |
| 2162 if (manifest->HasKey(keys::kContentSecurityPolicy)) { | 2242 if (source.HasKey(keys::kContentSecurityPolicy)) { |
| 2163 std::string content_security_policy; | 2243 std::string content_security_policy; |
| 2164 if (!manifest->GetString(keys::kContentSecurityPolicy, | 2244 if (!source.GetString(keys::kContentSecurityPolicy, |
| 2165 &content_security_policy)) { | 2245 &content_security_policy)) { |
| 2166 *error = errors::kInvalidContentSecurityPolicy; | 2246 *error = errors::kInvalidContentSecurityPolicy; |
| 2167 return false; | 2247 return false; |
| 2168 } | 2248 } |
| 2169 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { | 2249 if (!ContentSecurityPolicyIsLegal(content_security_policy)) { |
| 2170 *error = errors::kInvalidContentSecurityPolicy; | 2250 *error = errors::kInvalidContentSecurityPolicy; |
| 2171 return false; | 2251 return false; |
| 2172 } | 2252 } |
| 2173 if (manifest_version_ >= 2 && | 2253 if (manifest_version_ >= 2 && |
| 2174 !ContentSecurityPolicyIsSecure(content_security_policy)) { | 2254 !ContentSecurityPolicyIsSecure(content_security_policy)) { |
| 2175 *error = errors::kInvalidContentSecurityPolicy; | 2255 *error = errors::kInvalidContentSecurityPolicy; |
| 2176 return false; | 2256 return false; |
| 2177 } | 2257 } |
| 2178 | 2258 |
| 2179 content_security_policy_ = content_security_policy; | 2259 content_security_policy_ = content_security_policy; |
| 2180 } else if (manifest_version_ >= 2) { | 2260 } else if (manifest_version_ >= 2) { |
| 2181 // Manifest version 2 introduced a default Content-Security-Policy. | 2261 // Manifest version 2 introduced a default Content-Security-Policy. |
| 2182 // TODO(abarth): Should we continue to let extensions override the | 2262 // TODO(abarth): Should we continue to let extensions override the |
| 2183 // default Content-Security-Policy? | 2263 // default Content-Security-Policy? |
| 2184 content_security_policy_ = kDefaultContentSecurityPolicy; | 2264 content_security_policy_ = kDefaultContentSecurityPolicy; |
| 2185 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); | 2265 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_)); |
| 2186 } | 2266 } |
| 2187 | 2267 |
| 2188 // Initialize devtools page url (optional). | 2268 // Initialize devtools page url (optional). |
| 2189 if (manifest->HasKey(keys::kDevToolsPage)) { | 2269 if (source.HasKey(keys::kDevToolsPage)) { |
| 2190 std::string devtools_str; | 2270 std::string devtools_str; |
| 2191 if (!manifest->GetString(keys::kDevToolsPage, &devtools_str)) { | 2271 if (!source.GetString(keys::kDevToolsPage, &devtools_str)) { |
| 2192 *error = errors::kInvalidDevToolsPage; | 2272 *error = errors::kInvalidDevToolsPage; |
| 2193 return false; | 2273 return false; |
| 2194 } | 2274 } |
| 2195 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { | 2275 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { |
| 2196 *error = errors::kDevToolsExperimental; | 2276 *error = errors::kDevToolsExperimental; |
| 2197 return false; | 2277 return false; |
| 2198 } | 2278 } |
| 2199 devtools_url_ = GetResourceURL(devtools_str); | 2279 devtools_url_ = GetResourceURL(devtools_str); |
| 2200 } | 2280 } |
| 2201 | 2281 |
| 2202 // Initialize sidebar action (optional). | 2282 // Initialize sidebar action (optional). |
| 2203 if (manifest->HasKey(keys::kSidebar)) { | 2283 if (source.HasKey(keys::kSidebar)) { |
| 2204 DictionaryValue* sidebar_value = NULL; | 2284 DictionaryValue* sidebar_value = NULL; |
| 2205 if (!manifest->GetDictionary(keys::kSidebar, &sidebar_value)) { | 2285 if (!source.GetDictionary(keys::kSidebar, &sidebar_value)) { |
| 2206 *error = errors::kInvalidSidebar; | 2286 *error = errors::kInvalidSidebar; |
| 2207 return false; | 2287 return false; |
| 2208 } | 2288 } |
| 2209 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { | 2289 if (!api_permissions.count(ExtensionAPIPermission::kExperimental)) { |
| 2210 *error = errors::kSidebarExperimental; | 2290 *error = errors::kSidebarExperimental; |
| 2211 return false; | 2291 return false; |
| 2212 } | 2292 } |
| 2213 sidebar_defaults_.reset(LoadExtensionSidebarDefaults(sidebar_value, error)); | 2293 sidebar_defaults_.reset(LoadExtensionSidebarDefaults(sidebar_value, error)); |
| 2214 if (!sidebar_defaults_.get()) | 2294 if (!sidebar_defaults_.get()) |
| 2215 return false; // Failed to parse sidebar definition. | 2295 return false; // Failed to parse sidebar definition. |
| 2216 } | 2296 } |
| 2217 | 2297 |
| 2218 // Initialize text-to-speech voices (optional). | 2298 // Initialize text-to-speech voices (optional). |
| 2219 if (manifest->HasKey(keys::kTtsEngine)) { | 2299 if (source.HasKey(keys::kTtsEngine)) { |
| 2220 DictionaryValue* tts_dict = NULL; | 2300 DictionaryValue* tts_dict = NULL; |
| 2221 if (!manifest->GetDictionary(keys::kTtsEngine, &tts_dict)) { | 2301 if (!source.GetDictionary(keys::kTtsEngine, &tts_dict)) { |
| 2222 *error = errors::kInvalidTts; | 2302 *error = errors::kInvalidTts; |
| 2223 return false; | 2303 return false; |
| 2224 } | 2304 } |
| 2225 | 2305 |
| 2226 if (tts_dict->HasKey(keys::kTtsVoices)) { | 2306 if (tts_dict->HasKey(keys::kTtsVoices)) { |
| 2227 ListValue* tts_voices = NULL; | 2307 ListValue* tts_voices = NULL; |
| 2228 if (!tts_dict->GetList(keys::kTtsVoices, &tts_voices)) { | 2308 if (!tts_dict->GetList(keys::kTtsVoices, &tts_voices)) { |
| 2229 *error = errors::kInvalidTtsVoices; | 2309 *error = errors::kInvalidTtsVoices; |
| 2230 return false; | 2310 return false; |
| 2231 } | 2311 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2292 voice_data.event_types.insert(event_type); | 2372 voice_data.event_types.insert(event_type); |
| 2293 } | 2373 } |
| 2294 } | 2374 } |
| 2295 | 2375 |
| 2296 tts_voices_.push_back(voice_data); | 2376 tts_voices_.push_back(voice_data); |
| 2297 } | 2377 } |
| 2298 } | 2378 } |
| 2299 } | 2379 } |
| 2300 | 2380 |
| 2301 // Initialize web intents (optional). | 2381 // Initialize web intents (optional). |
| 2302 if (!LoadWebIntentServices(manifest, error)) | 2382 if (!LoadWebIntentServices(source, error)) |
| 2303 return false; | 2383 return false; |
| 2304 | 2384 |
| 2305 // Initialize incognito behavior. Apps default to split mode, extensions | 2385 // Initialize incognito behavior. Apps default to split mode, extensions |
| 2306 // default to spanning. | 2386 // default to spanning. |
| 2307 incognito_split_mode_ = is_app(); | 2387 incognito_split_mode_ = is_app(); |
| 2308 if (manifest->HasKey(keys::kIncognito)) { | 2388 if (source.HasKey(keys::kIncognito)) { |
| 2309 std::string value; | 2389 std::string value; |
| 2310 if (!manifest->GetString(keys::kIncognito, &value)) { | 2390 if (!source.GetString(keys::kIncognito, &value)) { |
| 2311 *error = errors::kInvalidIncognitoBehavior; | 2391 *error = errors::kInvalidIncognitoBehavior; |
| 2312 return false; | 2392 return false; |
| 2313 } | 2393 } |
| 2314 if (value == values::kIncognitoSpanning) { | 2394 if (value == values::kIncognitoSpanning) { |
| 2315 incognito_split_mode_ = false; | 2395 incognito_split_mode_ = false; |
| 2316 } else if (value == values::kIncognitoSplit) { | 2396 } else if (value == values::kIncognitoSplit) { |
| 2317 incognito_split_mode_ = true; | 2397 incognito_split_mode_ = true; |
| 2318 } else { | 2398 } else { |
| 2319 *error = errors::kInvalidIncognitoBehavior; | 2399 *error = errors::kInvalidIncognitoBehavior; |
| 2320 return false; | 2400 return false; |
| 2321 } | 2401 } |
| 2322 } | 2402 } |
| 2323 | 2403 |
| 2324 // Initialize offline-enabled status. Defaults to false. | 2404 // Initialize offline-enabled status. Defaults to false. |
| 2325 if (manifest->HasKey(keys::kOfflineEnabled)) { | 2405 if (source.HasKey(keys::kOfflineEnabled)) { |
| 2326 if (!manifest->GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { | 2406 if (!source.GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) { |
| 2327 *error = errors::kInvalidOfflineEnabled; | 2407 *error = errors::kInvalidOfflineEnabled; |
| 2328 return false; | 2408 return false; |
| 2329 } | 2409 } |
| 2330 } | 2410 } |
| 2331 | 2411 |
| 2332 // Initialize requirements (optional). Not actually persisted (they're only | 2412 // Initialize requirements (optional). Not actually persisted (they're only |
| 2333 // used by the store), but still validated. | 2413 // used by the store), but still validated. |
| 2334 if (manifest->HasKey(keys::kRequirements)) { | 2414 if (source.HasKey(keys::kRequirements)) { |
| 2335 DictionaryValue* requirements_value = NULL; | 2415 DictionaryValue* requirements_value = NULL; |
| 2336 if (!manifest->GetDictionary(keys::kRequirements, &requirements_value)) { | 2416 if (!source.GetDictionary(keys::kRequirements, &requirements_value)) { |
| 2337 *error = errors::kInvalidRequirements; | 2417 *error = errors::kInvalidRequirements; |
| 2338 return false; | 2418 return false; |
| 2339 } | 2419 } |
| 2340 | 2420 |
| 2341 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); | 2421 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); |
| 2342 it != requirements_value->end_keys(); ++it) { | 2422 it != requirements_value->end_keys(); ++it) { |
| 2343 DictionaryValue* requirement_value; | 2423 DictionaryValue* requirement_value; |
| 2344 if (!requirements_value->GetDictionaryWithoutPathExpansion( | 2424 if (!requirements_value->GetDictionaryWithoutPathExpansion( |
| 2345 *it, &requirement_value)) { | 2425 *it, &requirement_value)) { |
| 2346 *error = ExtensionErrorUtils::FormatErrorMessage( | 2426 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 2347 errors::kInvalidRequirement, *it); | 2427 errors::kInvalidRequirement, *it); |
| 2348 return false; | 2428 return false; |
| 2349 } | 2429 } |
| 2350 } | 2430 } |
| 2351 } | 2431 } |
| 2352 | 2432 |
| 2353 if (HasMultipleUISurfaces()) { | 2433 if (HasMultipleUISurfaces()) { |
| 2354 *error = errors::kOneUISurfaceOnly; | 2434 *error = errors::kOneUISurfaceOnly; |
| 2355 return false; | 2435 return false; |
| 2356 } | 2436 } |
| 2357 | 2437 |
| 2358 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( | 2438 runtime_data_.SetActivePermissions(new ExtensionPermissionSet( |
| 2359 this, api_permissions, host_permissions)); | 2439 this, api_permissions, host_permissions)); |
| 2360 required_permission_set_ = new ExtensionPermissionSet( | 2440 required_permission_set_ = new ExtensionPermissionSet( |
| 2361 this, api_permissions, host_permissions); | 2441 this, api_permissions, host_permissions); |
| 2362 optional_permission_set_ = new ExtensionPermissionSet( | 2442 optional_permission_set_ = new ExtensionPermissionSet( |
| 2363 optional_api_permissions, optional_host_permissions, URLPatternSet()); | 2443 optional_api_permissions, optional_host_permissions, URLPatternSet()); |
| 2364 | 2444 |
| 2445 // Although |source| is passed in as a const, it's still possible to modify |
| 2446 // it. This is dangerous since the utility process re-uses |source| after |
| 2447 // it calls InitFromValue, passing it up to the browser process which calls |
| 2448 // InitFromValue again. As a result, we need to make sure that nobody |
| 2449 // accidentally modifies it. |
| 2450 DCHECK(source.Equals(manifest_value_.get())); |
| 2451 |
| 2365 return true; | 2452 return true; |
| 2366 } | 2453 } |
| 2367 | 2454 |
| 2368 GURL Extension::GetHomepageURL() const { | 2455 GURL Extension::GetHomepageURL() const { |
| 2369 if (homepage_url_.is_valid()) | 2456 if (homepage_url_.is_valid()) |
| 2370 return homepage_url_; | 2457 return homepage_url_; |
| 2371 | 2458 |
| 2372 if (!UpdatesFromGallery()) | 2459 if (!UpdatesFromGallery()) |
| 2373 return GURL(); | 2460 return GURL(); |
| 2374 | 2461 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2510 | 2597 |
| 2511 GURL Extension::GetIconURL(int size, | 2598 GURL Extension::GetIconURL(int size, |
| 2512 ExtensionIconSet::MatchType match_type) const { | 2599 ExtensionIconSet::MatchType match_type) const { |
| 2513 std::string path = icons().Get(size, match_type); | 2600 std::string path = icons().Get(size, match_type); |
| 2514 if (path.empty()) | 2601 if (path.empty()) |
| 2515 return GURL(); | 2602 return GURL(); |
| 2516 else | 2603 else |
| 2517 return GetResourceURL(path); | 2604 return GetResourceURL(path); |
| 2518 } | 2605 } |
| 2519 | 2606 |
| 2520 bool Extension::ParsePermissions(const extensions::Manifest* source, | 2607 bool Extension::ParsePermissions(const DictionaryValue* source, |
| 2521 const char* key, | 2608 const char* key, |
| 2522 int flags, | 2609 int flags, |
| 2523 std::string* error, | 2610 std::string* error, |
| 2524 ExtensionAPIPermissionSet* api_permissions, | 2611 ExtensionAPIPermissionSet* api_permissions, |
| 2525 URLPatternSet* host_permissions) { | 2612 URLPatternSet* host_permissions) { |
| 2526 if (source->HasKey(key)) { | 2613 if (source->HasKey(key)) { |
| 2527 // When strict error checks are enabled, make URL pattern parsing strict. | 2614 // When strict error checks are enabled, make URL pattern parsing strict. |
| 2528 URLPattern::ParseOption parse_strictness = | 2615 URLPattern::ParseOption parse_strictness = |
| 2529 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 2616 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
| 2530 : URLPattern::IGNORE_PORTS); | 2617 : URLPattern::IGNORE_PORTS); |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3000 already_disabled(false), | 3087 already_disabled(false), |
| 3001 extension(extension) {} | 3088 extension(extension) {} |
| 3002 | 3089 |
| 3003 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3090 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 3004 const Extension* extension, | 3091 const Extension* extension, |
| 3005 const ExtensionPermissionSet* permissions, | 3092 const ExtensionPermissionSet* permissions, |
| 3006 Reason reason) | 3093 Reason reason) |
| 3007 : reason(reason), | 3094 : reason(reason), |
| 3008 extension(extension), | 3095 extension(extension), |
| 3009 permissions(permissions) {} | 3096 permissions(permissions) {} |
| OLD | NEW |