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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 DLOG(WARNING) << "Override URL passed for " << name() | 276 DLOG(WARNING) << "Override URL passed for " << name() |
277 << " should not contain a port. Removing it."; | 277 << " should not contain a port. Removing it."; |
278 | 278 |
279 GURL::Replacements remove_port; | 279 GURL::Replacements remove_port; |
280 remove_port.ClearPort(); | 280 remove_port.ClearPort(); |
281 new_url = new_url.ReplaceComponents(remove_port); | 281 new_url = new_url.ReplaceComponents(remove_port); |
282 } | 282 } |
283 | 283 |
284 launch_web_url_ = new_url.spec(); | 284 launch_web_url_ = new_url.spec(); |
285 | 285 |
286 URLPattern pattern(kValidWebExtentSchemes); | 286 URLPattern pattern(URLPattern::ERROR_ON_PORTS, kValidWebExtentSchemes); |
287 pattern.Parse(new_url.spec(), URLPattern::ERROR_ON_PORTS); | 287 pattern.Parse(new_url.spec()); |
288 pattern.SetPath(pattern.path() + '*'); | 288 pattern.SetPath(pattern.path() + '*'); |
289 extent_.AddPattern(pattern); | 289 extent_.AddPattern(pattern); |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 FilePath Extension::MaybeNormalizePath(const FilePath& path) { | 293 FilePath Extension::MaybeNormalizePath(const FilePath& path) { |
294 #if defined(OS_WIN) | 294 #if defined(OS_WIN) |
295 // Normalize any drive letter to upper-case. We do this for consistency with | 295 // Normalize any drive letter to upper-case. We do this for consistency with |
296 // net_utils::FilePathToFileURL(), which does the same thing, to make string | 296 // net_utils::FilePathToFileURL(), which does the same thing, to make string |
297 // comparisons simpler. | 297 // comparisons simpler. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 380 } |
381 | 381 |
382 // Helper method that loads a UserScript object from a dictionary in the | 382 // Helper method that loads a UserScript object from a dictionary in the |
383 // content_script list of the manifest. | 383 // content_script list of the manifest. |
384 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, | 384 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
385 int definition_index, | 385 int definition_index, |
386 int flags, | 386 int flags, |
387 std::string* error, | 387 std::string* error, |
388 UserScript* result) { | 388 UserScript* result) { |
389 // When strict error checks are enabled, make URL pattern parsing strict. | 389 // When strict error checks are enabled, make URL pattern parsing strict. |
390 URLPattern::ParseOption parse_strictness = | 390 URLPattern::ParseOption parse_option = |
391 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 391 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
392 : URLPattern::IGNORE_PORTS); | 392 : URLPattern::IGNORE_PORTS); |
393 | 393 |
394 // run_at | 394 // run_at |
395 if (content_script->HasKey(keys::kRunAt)) { | 395 if (content_script->HasKey(keys::kRunAt)) { |
396 std::string run_location; | 396 std::string run_location; |
397 if (!content_script->GetString(keys::kRunAt, &run_location)) { | 397 if (!content_script->GetString(keys::kRunAt, &run_location)) { |
398 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, | 398 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kInvalidRunAt, |
399 base::IntToString(definition_index)); | 399 base::IntToString(definition_index)); |
400 return false; | 400 return false; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 std::string match_str; | 441 std::string match_str; |
442 if (!matches->GetString(j, &match_str)) { | 442 if (!matches->GetString(j, &match_str)) { |
443 *error = ExtensionErrorUtils::FormatErrorMessage( | 443 *error = ExtensionErrorUtils::FormatErrorMessage( |
444 errors::kInvalidMatch, | 444 errors::kInvalidMatch, |
445 base::IntToString(definition_index), | 445 base::IntToString(definition_index), |
446 base::IntToString(j), | 446 base::IntToString(j), |
447 errors::kExpectString); | 447 errors::kExpectString); |
448 return false; | 448 return false; |
449 } | 449 } |
450 | 450 |
451 URLPattern pattern(UserScript::kValidUserScriptSchemes); | 451 URLPattern pattern(parse_option, UserScript::kValidUserScriptSchemes); |
452 if (CanExecuteScriptEverywhere()) | 452 if (CanExecuteScriptEverywhere()) |
453 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); | 453 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); |
454 | 454 |
455 URLPattern::ParseResult parse_result = pattern.Parse(match_str, | 455 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
456 parse_strictness); | |
457 if (parse_result != URLPattern::PARSE_SUCCESS) { | 456 if (parse_result != URLPattern::PARSE_SUCCESS) { |
458 *error = ExtensionErrorUtils::FormatErrorMessage( | 457 *error = ExtensionErrorUtils::FormatErrorMessage( |
459 errors::kInvalidMatch, | 458 errors::kInvalidMatch, |
460 base::IntToString(definition_index), | 459 base::IntToString(definition_index), |
461 base::IntToString(j), | 460 base::IntToString(j), |
462 URLPattern::GetParseResultString(parse_result)); | 461 URLPattern::GetParseResultString(parse_result)); |
463 return false; | 462 return false; |
464 } | 463 } |
465 | 464 |
466 if (pattern.MatchesScheme(chrome::kFileScheme) && | 465 if (pattern.MatchesScheme(chrome::kFileScheme) && |
(...skipping 21 matching lines...) Expand all Loading... |
488 std::string match_str; | 487 std::string match_str; |
489 if (!exclude_matches->GetString(j, &match_str)) { | 488 if (!exclude_matches->GetString(j, &match_str)) { |
490 *error = ExtensionErrorUtils::FormatErrorMessage( | 489 *error = ExtensionErrorUtils::FormatErrorMessage( |
491 errors::kInvalidExcludeMatch, | 490 errors::kInvalidExcludeMatch, |
492 base::IntToString(definition_index), | 491 base::IntToString(definition_index), |
493 base::IntToString(j), | 492 base::IntToString(j), |
494 errors::kExpectString); | 493 errors::kExpectString); |
495 return false; | 494 return false; |
496 } | 495 } |
497 | 496 |
498 URLPattern pattern(UserScript::kValidUserScriptSchemes); | 497 URLPattern pattern(parse_option, UserScript::kValidUserScriptSchemes); |
499 if (CanExecuteScriptEverywhere()) | 498 if (CanExecuteScriptEverywhere()) |
500 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); | 499 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); |
501 URLPattern::ParseResult parse_result = pattern.Parse(match_str, | 500 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
502 parse_strictness); | |
503 if (parse_result != URLPattern::PARSE_SUCCESS) { | 501 if (parse_result != URLPattern::PARSE_SUCCESS) { |
504 *error = ExtensionErrorUtils::FormatErrorMessage( | 502 *error = ExtensionErrorUtils::FormatErrorMessage( |
505 errors::kInvalidExcludeMatch, | 503 errors::kInvalidExcludeMatch, |
506 base::IntToString(definition_index), base::IntToString(j), | 504 base::IntToString(definition_index), base::IntToString(j), |
507 URLPattern::GetParseResultString(parse_result)); | 505 URLPattern::GetParseResultString(parse_result)); |
508 return false; | 506 return false; |
509 } | 507 } |
510 | 508 |
511 result->add_exclude_url_pattern(pattern); | 509 result->add_exclude_url_pattern(pattern); |
512 } | 510 } |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 return NULL; | 790 return NULL; |
793 } | 791 } |
794 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 792 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
795 std::string filter; | 793 std::string filter; |
796 if (!list_value->GetString(i, &filter)) { | 794 if (!list_value->GetString(i, &filter)) { |
797 *error = ExtensionErrorUtils::FormatErrorMessage( | 795 *error = ExtensionErrorUtils::FormatErrorMessage( |
798 errors::kInvalidFileFilterValue, base::IntToString(i)); | 796 errors::kInvalidFileFilterValue, base::IntToString(i)); |
799 return NULL; | 797 return NULL; |
800 } | 798 } |
801 StringToLowerASCII(&filter); | 799 StringToLowerASCII(&filter); |
802 URLPattern pattern(URLPattern::SCHEME_FILESYSTEM); | 800 URLPattern pattern(URLPattern::ERROR_ON_PORTS, |
803 if (pattern.Parse(filter, URLPattern::ERROR_ON_PORTS) != | 801 URLPattern::SCHEME_FILESYSTEM); |
804 URLPattern::PARSE_SUCCESS) { | 802 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { |
805 *error = ExtensionErrorUtils::FormatErrorMessage( | 803 *error = ExtensionErrorUtils::FormatErrorMessage( |
806 errors::kInvalidURLPatternError, filter); | 804 errors::kInvalidURLPatternError, filter); |
807 return NULL; | 805 return NULL; |
808 } | 806 } |
809 std::string path = pattern.path(); | 807 std::string path = pattern.path(); |
810 bool allowed = path == "*" || path == "*.*" || | 808 bool allowed = path == "*" || path == "*.*" || |
811 (path.compare(0, 2, "*.") == 0 && | 809 (path.compare(0, 2, "*.") == 0 && |
812 path.find_first_of('*', 2) == std::string::npos); | 810 path.find_first_of('*', 2) == std::string::npos); |
813 if (!allowed) { | 811 if (!allowed) { |
814 *error = ExtensionErrorUtils::FormatErrorMessage( | 812 *error = ExtensionErrorUtils::FormatErrorMessage( |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 } | 875 } |
878 | 876 |
879 return result.release(); | 877 return result.release(); |
880 } | 878 } |
881 | 879 |
882 bool Extension::LoadExtent(const extensions::Manifest* manifest, | 880 bool Extension::LoadExtent(const extensions::Manifest* manifest, |
883 const char* key, | 881 const char* key, |
884 URLPatternSet* extent, | 882 URLPatternSet* extent, |
885 const char* list_error, | 883 const char* list_error, |
886 const char* value_error, | 884 const char* value_error, |
887 URLPattern::ParseOption parse_strictness, | 885 URLPattern::ParseOption parse_option, |
888 std::string* error) { | 886 std::string* error) { |
889 Value* temp = NULL; | 887 Value* temp = NULL; |
890 if (!manifest->Get(key, &temp)) | 888 if (!manifest->Get(key, &temp)) |
891 return true; | 889 return true; |
892 | 890 |
893 if (temp->GetType() != Value::TYPE_LIST) { | 891 if (temp->GetType() != Value::TYPE_LIST) { |
894 *error = list_error; | 892 *error = list_error; |
895 return false; | 893 return false; |
896 } | 894 } |
897 | 895 |
898 ListValue* pattern_list = static_cast<ListValue*>(temp); | 896 ListValue* pattern_list = static_cast<ListValue*>(temp); |
899 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { | 897 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { |
900 std::string pattern_string; | 898 std::string pattern_string; |
901 if (!pattern_list->GetString(i, &pattern_string)) { | 899 if (!pattern_list->GetString(i, &pattern_string)) { |
902 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, | 900 *error = ExtensionErrorUtils::FormatErrorMessage(value_error, |
903 base::UintToString(i), | 901 base::UintToString(i), |
904 errors::kExpectString); | 902 errors::kExpectString); |
905 return false; | 903 return false; |
906 } | 904 } |
907 | 905 |
908 URLPattern pattern(kValidWebExtentSchemes); | 906 URLPattern pattern(parse_option, kValidWebExtentSchemes); |
909 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string, | 907 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string); |
910 parse_strictness); | |
911 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) { | 908 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) { |
912 pattern_string += "/"; | 909 pattern_string += "/"; |
913 parse_result = pattern.Parse(pattern_string, parse_strictness); | 910 parse_result = pattern.Parse(pattern_string); |
914 } | 911 } |
915 | 912 |
916 if (parse_result != URLPattern::PARSE_SUCCESS) { | 913 if (parse_result != URLPattern::PARSE_SUCCESS) { |
917 *error = ExtensionErrorUtils::FormatErrorMessage( | 914 *error = ExtensionErrorUtils::FormatErrorMessage( |
918 value_error, | 915 value_error, |
919 base::UintToString(i), | 916 base::UintToString(i), |
920 URLPattern::GetParseResultString(parse_result)); | 917 URLPattern::GetParseResultString(parse_result)); |
921 return false; | 918 return false; |
922 } | 919 } |
923 | 920 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 launch_local_path_ = launch_path; | 986 launch_local_path_ = launch_path; |
990 } else if (manifest->Get(keys::kLaunchWebURL, &temp)) { | 987 } else if (manifest->Get(keys::kLaunchWebURL, &temp)) { |
991 std::string launch_url; | 988 std::string launch_url; |
992 if (!temp->GetAsString(&launch_url)) { | 989 if (!temp->GetAsString(&launch_url)) { |
993 *error = errors::kInvalidLaunchWebURL; | 990 *error = errors::kInvalidLaunchWebURL; |
994 return false; | 991 return false; |
995 } | 992 } |
996 | 993 |
997 // Ensure the launch URL is a valid absolute URL and web extent scheme. | 994 // Ensure the launch URL is a valid absolute URL and web extent scheme. |
998 GURL url(launch_url); | 995 GURL url(launch_url); |
999 URLPattern pattern(kValidWebExtentSchemes); | 996 URLPattern pattern(URLPattern::ERROR_ON_PORTS, kValidWebExtentSchemes); |
1000 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { | 997 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { |
1001 *error = errors::kInvalidLaunchWebURL; | 998 *error = errors::kInvalidLaunchWebURL; |
1002 return false; | 999 return false; |
1003 } | 1000 } |
1004 | 1001 |
1005 launch_web_url_ = launch_url; | 1002 launch_web_url_ = launch_url; |
1006 } else if (is_app()) { | 1003 } else if (is_app()) { |
1007 *error = errors::kLaunchURLRequired; | 1004 *error = errors::kLaunchURLRequired; |
1008 return false; | 1005 return false; |
1009 } | 1006 } |
1010 | 1007 |
1011 // If there is no extent, we default the extent based on the launch URL. | 1008 // If there is no extent, we default the extent based on the launch URL. |
1012 if (web_extent().is_empty() && !launch_web_url().empty()) { | 1009 if (web_extent().is_empty() && !launch_web_url().empty()) { |
1013 GURL launch_url(launch_web_url()); | 1010 GURL launch_url(launch_web_url()); |
1014 URLPattern pattern(kValidWebExtentSchemes); | 1011 URLPattern pattern(URLPattern::ERROR_ON_PORTS, kValidWebExtentSchemes); |
1015 if (!pattern.SetScheme("*")) { | 1012 if (!pattern.SetScheme("*")) { |
1016 *error = errors::kInvalidLaunchWebURL; | 1013 *error = errors::kInvalidLaunchWebURL; |
1017 return false; | 1014 return false; |
1018 } | 1015 } |
1019 pattern.SetHost(launch_url.host()); | 1016 pattern.SetHost(launch_url.host()); |
1020 pattern.SetPath("/*"); | 1017 pattern.SetPath("/*"); |
1021 extent_.AddPattern(pattern); | 1018 extent_.AddPattern(pattern); |
1022 } | 1019 } |
1023 | 1020 |
1024 // In order for the --apps-gallery-url switch to work with the gallery | 1021 // In order for the --apps-gallery-url switch to work with the gallery |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, | 1381 bool Extension::InitFromValue(extensions::Manifest* manifest, int flags, |
1385 std::string* error) { | 1382 std::string* error) { |
1386 DCHECK(error); | 1383 DCHECK(error); |
1387 base::AutoLock auto_lock(runtime_data_lock_); | 1384 base::AutoLock auto_lock(runtime_data_lock_); |
1388 manifest_.reset(manifest); | 1385 manifest_.reset(manifest); |
1389 | 1386 |
1390 if (!manifest->ValidateManifest(error)) | 1387 if (!manifest->ValidateManifest(error)) |
1391 return false; | 1388 return false; |
1392 | 1389 |
1393 // When strict error checks are enabled, make URL pattern parsing strict. | 1390 // When strict error checks are enabled, make URL pattern parsing strict. |
1394 URLPattern::ParseOption parse_strictness = | 1391 URLPattern::ParseOption parse_option = |
1395 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 1392 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
1396 : URLPattern::IGNORE_PORTS); | 1393 : URLPattern::IGNORE_PORTS); |
1397 | 1394 |
1398 // Initialize permissions with an empty, default permission set. | 1395 // Initialize permissions with an empty, default permission set. |
1399 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); | 1396 runtime_data_.SetActivePermissions(new ExtensionPermissionSet()); |
1400 optional_permission_set_ = new ExtensionPermissionSet(); | 1397 optional_permission_set_ = new ExtensionPermissionSet(); |
1401 required_permission_set_ = new ExtensionPermissionSet(); | 1398 required_permission_set_ = new ExtensionPermissionSet(); |
1402 | 1399 |
1403 if (manifest->HasKey(keys::kManifestVersion)) { | 1400 if (manifest->HasKey(keys::kManifestVersion)) { |
1404 int manifest_version = 0; | 1401 int manifest_version = 0; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 base::i18n::AdjustStringForLocaleDirection(&localized_name); | 1469 base::i18n::AdjustStringForLocaleDirection(&localized_name); |
1473 name_ = UTF16ToUTF8(localized_name); | 1470 name_ = UTF16ToUTF8(localized_name); |
1474 | 1471 |
1475 // Load App settings. LoadExtent at least has to be done before | 1472 // Load App settings. LoadExtent at least has to be done before |
1476 // ParsePermissions(), because the valid permissions depend on what type of | 1473 // ParsePermissions(), because the valid permissions depend on what type of |
1477 // package this is. | 1474 // package this is. |
1478 if (is_app() && | 1475 if (is_app() && |
1479 (!LoadExtent(manifest_.get(), keys::kWebURLs, | 1476 (!LoadExtent(manifest_.get(), keys::kWebURLs, |
1480 &extent_, | 1477 &extent_, |
1481 errors::kInvalidWebURLs, errors::kInvalidWebURL, | 1478 errors::kInvalidWebURLs, errors::kInvalidWebURL, |
1482 parse_strictness, error) || | 1479 parse_option, error) || |
1483 !LoadLaunchURL(manifest_.get(), error) || | 1480 !LoadLaunchURL(manifest_.get(), error) || |
1484 !LoadLaunchContainer(manifest_.get(), error))) { | 1481 !LoadLaunchContainer(manifest_.get(), error))) { |
1485 return false; | 1482 return false; |
1486 } | 1483 } |
1487 | 1484 |
1488 if (is_platform_app()) { | 1485 if (is_platform_app()) { |
1489 if (launch_container() != extension_misc::LAUNCH_SHELL) { | 1486 if (launch_container() != extension_misc::LAUNCH_SHELL) { |
1490 *error = errors::kInvalidLaunchContainerForPlatform; | 1487 *error = errors::kInvalidLaunchContainerForPlatform; |
1491 return false; | 1488 return false; |
1492 } | 1489 } |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2517 } | 2514 } |
2518 | 2515 |
2519 bool Extension::ParsePermissions(const extensions::Manifest* source, | 2516 bool Extension::ParsePermissions(const extensions::Manifest* source, |
2520 const char* key, | 2517 const char* key, |
2521 int flags, | 2518 int flags, |
2522 std::string* error, | 2519 std::string* error, |
2523 ExtensionAPIPermissionSet* api_permissions, | 2520 ExtensionAPIPermissionSet* api_permissions, |
2524 URLPatternSet* host_permissions) { | 2521 URLPatternSet* host_permissions) { |
2525 if (source->HasKey(key)) { | 2522 if (source->HasKey(key)) { |
2526 // When strict error checks are enabled, make URL pattern parsing strict. | 2523 // When strict error checks are enabled, make URL pattern parsing strict. |
2527 URLPattern::ParseOption parse_strictness = | 2524 URLPattern::ParseOption parse_option = |
2528 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS | 2525 (flags & STRICT_ERROR_CHECKS ? URLPattern::ERROR_ON_PORTS |
2529 : URLPattern::IGNORE_PORTS); | 2526 : URLPattern::IGNORE_PORTS); |
2530 ListValue* permissions = NULL; | 2527 ListValue* permissions = NULL; |
2531 if (!source->GetList(key, &permissions)) { | 2528 if (!source->GetList(key, &permissions)) { |
2532 *error = ExtensionErrorUtils::FormatErrorMessage( | 2529 *error = ExtensionErrorUtils::FormatErrorMessage( |
2533 errors::kInvalidPermissions, ""); | 2530 errors::kInvalidPermissions, ""); |
2534 return false; | 2531 return false; |
2535 } | 2532 } |
2536 | 2533 |
2537 for (size_t i = 0; i < permissions->GetSize(); ++i) { | 2534 for (size_t i = 0; i < permissions->GetSize(); ++i) { |
2538 std::string permission_str; | 2535 std::string permission_str; |
2539 if (!permissions->GetString(i, &permission_str)) { | 2536 if (!permissions->GetString(i, &permission_str)) { |
2540 *error = ExtensionErrorUtils::FormatErrorMessage( | 2537 *error = ExtensionErrorUtils::FormatErrorMessage( |
2541 errors::kInvalidPermission, base::IntToString(i)); | 2538 errors::kInvalidPermission, base::IntToString(i)); |
2542 return false; | 2539 return false; |
2543 } | 2540 } |
2544 | 2541 |
2545 ExtensionAPIPermission* permission = | 2542 ExtensionAPIPermission* permission = |
2546 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str); | 2543 ExtensionPermissionsInfo::GetInstance()->GetByName(permission_str); |
2547 | 2544 |
2548 if (permission != NULL) { | 2545 if (permission != NULL) { |
2549 if (CanSpecifyAPIPermission(permission, error)) | 2546 if (CanSpecifyAPIPermission(permission, error)) |
2550 api_permissions->insert(permission->id()); | 2547 api_permissions->insert(permission->id()); |
2551 if (!error->empty()) | 2548 if (!error->empty()) |
2552 return false; | 2549 return false; |
2553 continue; | 2550 continue; |
2554 } | 2551 } |
2555 | 2552 |
2556 // Check if it's a host pattern permission. | 2553 // Check if it's a host pattern permission. |
2557 URLPattern pattern = URLPattern(CanExecuteScriptEverywhere() ? | 2554 const int kAllowedSchemes = CanExecuteScriptEverywhere() ? |
2558 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes); | 2555 URLPattern::SCHEME_ALL : kValidHostPermissionSchemes; |
2559 | 2556 |
2560 URLPattern::ParseResult parse_result = pattern.Parse(permission_str, | 2557 URLPattern pattern = URLPattern(parse_option, kAllowedSchemes); |
2561 parse_strictness); | 2558 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); |
2562 if (parse_result == URLPattern::PARSE_SUCCESS) { | 2559 if (parse_result == URLPattern::PARSE_SUCCESS) { |
2563 if (!CanSpecifyHostPermission(pattern, *api_permissions)) { | 2560 if (!CanSpecifyHostPermission(pattern, *api_permissions)) { |
2564 *error = ExtensionErrorUtils::FormatErrorMessage( | 2561 *error = ExtensionErrorUtils::FormatErrorMessage( |
2565 errors::kInvalidPermissionScheme, base::IntToString(i)); | 2562 errors::kInvalidPermissionScheme, base::IntToString(i)); |
2566 return false; | 2563 return false; |
2567 } | 2564 } |
2568 | 2565 |
2569 // The path component is not used for host permissions, so we force it | 2566 // The path component is not used for host permissions, so we force it |
2570 // to match all paths. | 2567 // to match all paths. |
2571 pattern.SetPath("/*"); | 2568 pattern.SetPath("/*"); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2899 } | 2896 } |
2900 | 2897 |
2901 bool Extension::OverlapsWithOrigin(const GURL& origin) const { | 2898 bool Extension::OverlapsWithOrigin(const GURL& origin) const { |
2902 if (url() == origin) | 2899 if (url() == origin) |
2903 return true; | 2900 return true; |
2904 | 2901 |
2905 if (web_extent().is_empty()) | 2902 if (web_extent().is_empty()) |
2906 return false; | 2903 return false; |
2907 | 2904 |
2908 // Note: patterns and extents ignore port numbers. | 2905 // Note: patterns and extents ignore port numbers. |
2909 URLPattern origin_only_pattern(kValidWebExtentSchemes); | 2906 URLPattern origin_only_pattern(URLPattern::ERROR_ON_PORTS, |
| 2907 kValidWebExtentSchemes); |
2910 if (!origin_only_pattern.SetScheme(origin.scheme())) | 2908 if (!origin_only_pattern.SetScheme(origin.scheme())) |
2911 return false; | 2909 return false; |
2912 origin_only_pattern.SetHost(origin.host()); | 2910 origin_only_pattern.SetHost(origin.host()); |
2913 origin_only_pattern.SetPath("/*"); | 2911 origin_only_pattern.SetPath("/*"); |
2914 | 2912 |
2915 URLPatternSet origin_only_pattern_list; | 2913 URLPatternSet origin_only_pattern_list; |
2916 origin_only_pattern_list.AddPattern(origin_only_pattern); | 2914 origin_only_pattern_list.AddPattern(origin_only_pattern); |
2917 | 2915 |
2918 return web_extent().OverlapsWith(origin_only_pattern_list); | 2916 return web_extent().OverlapsWith(origin_only_pattern_list); |
2919 } | 2917 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2999 already_disabled(false), | 2997 already_disabled(false), |
3000 extension(extension) {} | 2998 extension(extension) {} |
3001 | 2999 |
3002 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3000 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3003 const Extension* extension, | 3001 const Extension* extension, |
3004 const ExtensionPermissionSet* permissions, | 3002 const ExtensionPermissionSet* permissions, |
3005 Reason reason) | 3003 Reason reason) |
3006 : reason(reason), | 3004 : reason(reason), |
3007 extension(extension), | 3005 extension(extension), |
3008 permissions(permissions) {} | 3006 permissions(permissions) {} |
OLD | NEW |