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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 7347011: Update URLPatternSet to contain a std::set instead of std::vector. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows compile errors. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 *error = ExtensionErrorUtils::FormatErrorMessage( 451 *error = ExtensionErrorUtils::FormatErrorMessage(
452 errors::kInvalidMatch, 452 errors::kInvalidMatch,
453 base::IntToString(definition_index), 453 base::IntToString(definition_index),
454 base::IntToString(j), 454 base::IntToString(j),
455 errors::kExpectString); 455 errors::kExpectString);
456 return false; 456 return false;
457 } 457 }
458 458
459 URLPattern pattern(UserScript::kValidUserScriptSchemes); 459 URLPattern pattern(UserScript::kValidUserScriptSchemes);
460 if (CanExecuteScriptEverywhere()) 460 if (CanExecuteScriptEverywhere())
461 pattern.set_valid_schemes(URLPattern::SCHEME_ALL); 461 pattern.SetValidSchemes(URLPattern::SCHEME_ALL);
462 462
463 URLPattern::ParseResult parse_result = pattern.Parse(match_str, 463 URLPattern::ParseResult parse_result = pattern.Parse(match_str,
464 parse_strictness); 464 parse_strictness);
465 if (parse_result != URLPattern::PARSE_SUCCESS) { 465 if (parse_result != URLPattern::PARSE_SUCCESS) {
466 *error = ExtensionErrorUtils::FormatErrorMessage( 466 *error = ExtensionErrorUtils::FormatErrorMessage(
467 errors::kInvalidMatch, 467 errors::kInvalidMatch,
468 base::IntToString(definition_index), 468 base::IntToString(definition_index),
469 base::IntToString(j), 469 base::IntToString(j),
470 URLPattern::GetParseResultString(parse_result)); 470 URLPattern::GetParseResultString(parse_result));
471 return false; 471 return false;
472 } 472 }
473 473
474 if (pattern.MatchesScheme(chrome::kFileScheme) && 474 if (pattern.MatchesScheme(chrome::kFileScheme) &&
475 !CanExecuteScriptEverywhere()) { 475 !CanExecuteScriptEverywhere()) {
476 wants_file_access_ = true; 476 wants_file_access_ = true;
477 if (!(flags & ALLOW_FILE_ACCESS)) 477 if (!(flags & ALLOW_FILE_ACCESS))
478 pattern.set_valid_schemes( 478 pattern.SetValidSchemes(
479 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); 479 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
480 } 480 }
481 481
482 result->add_url_pattern(pattern); 482 result->add_url_pattern(pattern);
483 } 483 }
484 484
485 // exclude_matches 485 // exclude_matches
486 if (content_script->HasKey(keys::kExcludeMatches)) { // optional 486 if (content_script->HasKey(keys::kExcludeMatches)) { // optional
487 ListValue* exclude_matches = NULL; 487 ListValue* exclude_matches = NULL;
488 if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) { 488 if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) {
489 *error = ExtensionErrorUtils::FormatErrorMessage( 489 *error = ExtensionErrorUtils::FormatErrorMessage(
490 errors::kInvalidExcludeMatches, 490 errors::kInvalidExcludeMatches,
491 base::IntToString(definition_index)); 491 base::IntToString(definition_index));
492 return false; 492 return false;
493 } 493 }
494 494
495 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) { 495 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) {
496 std::string match_str; 496 std::string match_str;
497 if (!exclude_matches->GetString(j, &match_str)) { 497 if (!exclude_matches->GetString(j, &match_str)) {
498 *error = ExtensionErrorUtils::FormatErrorMessage( 498 *error = ExtensionErrorUtils::FormatErrorMessage(
499 errors::kInvalidExcludeMatch, 499 errors::kInvalidExcludeMatch,
500 base::IntToString(definition_index), 500 base::IntToString(definition_index),
501 base::IntToString(j), 501 base::IntToString(j),
502 errors::kExpectString); 502 errors::kExpectString);
503 return false; 503 return false;
504 } 504 }
505 505
506 URLPattern pattern(UserScript::kValidUserScriptSchemes); 506 URLPattern pattern(UserScript::kValidUserScriptSchemes);
507 if (CanExecuteScriptEverywhere()) 507 if (CanExecuteScriptEverywhere())
508 pattern.set_valid_schemes(URLPattern::SCHEME_ALL); 508 pattern.SetValidSchemes(URLPattern::SCHEME_ALL);
509 URLPattern::ParseResult parse_result = pattern.Parse(match_str, 509 URLPattern::ParseResult parse_result = pattern.Parse(match_str,
510 parse_strictness); 510 parse_strictness);
511 if (parse_result != URLPattern::PARSE_SUCCESS) { 511 if (parse_result != URLPattern::PARSE_SUCCESS) {
512 *error = ExtensionErrorUtils::FormatErrorMessage( 512 *error = ExtensionErrorUtils::FormatErrorMessage(
513 errors::kInvalidExcludeMatch, 513 errors::kInvalidExcludeMatch,
514 base::IntToString(definition_index), base::IntToString(j), 514 base::IntToString(definition_index), base::IntToString(j),
515 URLPattern::GetParseResultString(parse_result)); 515 URLPattern::GetParseResultString(parse_result));
516 return false; 516 return false;
517 } 517 }
518 518
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 } 1019 }
1020 1020
1021 // If there is no extent, we default the extent based on the launch URL. 1021 // If there is no extent, we default the extent based on the launch URL.
1022 if (web_extent().is_empty() && !launch_web_url().empty()) { 1022 if (web_extent().is_empty() && !launch_web_url().empty()) {
1023 GURL launch_url(launch_web_url()); 1023 GURL launch_url(launch_web_url());
1024 URLPattern pattern(kValidWebExtentSchemes); 1024 URLPattern pattern(kValidWebExtentSchemes);
1025 if (!pattern.SetScheme("*")) { 1025 if (!pattern.SetScheme("*")) {
1026 *error = errors::kInvalidLaunchWebURL; 1026 *error = errors::kInvalidLaunchWebURL;
1027 return false; 1027 return false;
1028 } 1028 }
1029 pattern.set_host(launch_url.host()); 1029 pattern.SetHost(launch_url.host());
1030 pattern.SetPath("/*"); 1030 pattern.SetPath("/*");
1031 extent_.AddPattern(pattern); 1031 extent_.AddPattern(pattern);
1032 } 1032 }
1033 1033
1034 // In order for the --apps-gallery-url switch to work with the gallery 1034 // In order for the --apps-gallery-url switch to work with the gallery
1035 // process isolation, we must insert any provided value into the component 1035 // process isolation, we must insert any provided value into the component
1036 // app's launch url and web extent. 1036 // app's launch url and web extent.
1037 if (id() == extension_misc::kWebStoreAppId) { 1037 if (id() == extension_misc::kWebStoreAppId) {
1038 std::string gallery_url_str = CommandLine::ForCurrentProcess()-> 1038 std::string gallery_url_str = CommandLine::ForCurrentProcess()->
1039 GetSwitchValueASCII(switches::kAppsGalleryURL); 1039 GetSwitchValueASCII(switches::kAppsGalleryURL);
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 } 1949 }
1950 1950
1951 // The path component is not used for host permissions, so we force it 1951 // The path component is not used for host permissions, so we force it
1952 // to match all paths. 1952 // to match all paths.
1953 pattern.SetPath("/*"); 1953 pattern.SetPath("/*");
1954 1954
1955 if (pattern.MatchesScheme(chrome::kFileScheme) && 1955 if (pattern.MatchesScheme(chrome::kFileScheme) &&
1956 !CanExecuteScriptEverywhere()) { 1956 !CanExecuteScriptEverywhere()) {
1957 wants_file_access_ = true; 1957 wants_file_access_ = true;
1958 if (!(flags & ALLOW_FILE_ACCESS)) 1958 if (!(flags & ALLOW_FILE_ACCESS))
1959 pattern.set_valid_schemes( 1959 pattern.SetValidSchemes(
1960 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); 1960 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE);
1961 } 1961 }
1962 1962
1963 host_permissions.AddPattern(pattern); 1963 host_permissions.AddPattern(pattern);
1964 } 1964 }
1965 1965
1966 // If it's not a host permission, then it's probably an unknown API 1966 // If it's not a host permission, then it's probably an unknown API
1967 // permission. Do not throw an error so extensions can retain 1967 // permission. Do not throw an error so extensions can retain
1968 // backwards compatability (http://crbug.com/42742). 1968 // backwards compatability (http://crbug.com/42742).
1969 // TODO(jstritar): We can improve error messages by adding better 1969 // TODO(jstritar): We can improve error messages by adding better
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 if (url() == origin) 2698 if (url() == origin)
2699 return true; 2699 return true;
2700 2700
2701 if (web_extent().is_empty()) 2701 if (web_extent().is_empty())
2702 return false; 2702 return false;
2703 2703
2704 // Note: patterns and extents ignore port numbers. 2704 // Note: patterns and extents ignore port numbers.
2705 URLPattern origin_only_pattern(kValidWebExtentSchemes); 2705 URLPattern origin_only_pattern(kValidWebExtentSchemes);
2706 if (!origin_only_pattern.SetScheme(origin.scheme())) 2706 if (!origin_only_pattern.SetScheme(origin.scheme()))
2707 return false; 2707 return false;
2708 origin_only_pattern.set_host(origin.host()); 2708 origin_only_pattern.SetHost(origin.host());
2709 origin_only_pattern.SetPath("/*"); 2709 origin_only_pattern.SetPath("/*");
2710 2710
2711 URLPatternSet origin_only_pattern_list; 2711 URLPatternSet origin_only_pattern_list;
2712 origin_only_pattern_list.AddPattern(origin_only_pattern); 2712 origin_only_pattern_list.AddPattern(origin_only_pattern);
2713 2713
2714 return web_extent().OverlapsWith(origin_only_pattern_list); 2714 return web_extent().OverlapsWith(origin_only_pattern_list);
2715 } 2715 }
2716 2716
2717 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest, 2717 ExtensionInfo::ExtensionInfo(const DictionaryValue* manifest,
2718 const std::string& id, 2718 const std::string& id,
(...skipping 18 matching lines...) Expand all
2737 2737
2738 UninstalledExtensionInfo::~UninstalledExtensionInfo() {} 2738 UninstalledExtensionInfo::~UninstalledExtensionInfo() {}
2739 2739
2740 2740
2741 UnloadedExtensionInfo::UnloadedExtensionInfo( 2741 UnloadedExtensionInfo::UnloadedExtensionInfo(
2742 const Extension* extension, 2742 const Extension* extension,
2743 Reason reason) 2743 Reason reason)
2744 : reason(reason), 2744 : reason(reason),
2745 already_disabled(false), 2745 already_disabled(false),
2746 extension(extension) {} 2746 extension(extension) {}
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | chrome/common/extensions/extension_manifests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698