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

Side by Side Diff: extensions/common/url_pattern.cc

Issue 348313003: Create withheld permissions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest master Created 6 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
« no previous file with comments | « extensions/common/url_pattern.h ('k') | extensions/common/user_script.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/common/url_pattern.h" 5 #include "extensions/common/url_pattern.h"
6 6
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h"
11 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
12 #include "extensions/common/constants.h" 13 #include "extensions/common/constants.h"
14 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 #include "url/gurl.h" 15 #include "url/gurl.h"
14 #include "url/url_util.h" 16 #include "url/url_util.h"
15 17
16 const char URLPattern::kAllUrlsPattern[] = "<all_urls>"; 18 const char URLPattern::kAllUrlsPattern[] = "<all_urls>";
17 19
18 namespace { 20 namespace {
19 21
20 // TODO(aa): What about more obscure schemes like data: and javascript: ? 22 // TODO(aa): What about more obscure schemes like data: and javascript: ?
21 // Note: keep this array in sync with kValidSchemeMasks. 23 // Note: keep this array in sync with kValidSchemeMasks.
22 const char* kValidSchemes[] = { 24 const char* kValidSchemes[] = {
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 if (test.host().length() <= (host_.length() + 1)) 412 if (test.host().length() <= (host_.length() + 1))
411 return false; 413 return false;
412 414
413 if (test.host().compare(test.host().length() - host_.length(), 415 if (test.host().compare(test.host().length() - host_.length(),
414 host_.length(), host_) != 0) 416 host_.length(), host_) != 0)
415 return false; 417 return false;
416 418
417 return test.host()[test.host().length() - host_.length() - 1] == '.'; 419 return test.host()[test.host().length() - host_.length() - 1] == '.';
418 } 420 }
419 421
422 bool URLPattern::ImpliesAllHosts() const {
423 // Check if it matches all urls or is a pattern like http://*/*.
424 if (match_all_urls_ ||
425 (match_subdomains_ && host_.empty() && port_ == "*" && path_ == "/*")) {
426 return true;
427 }
428
429 // If this doesn't even match subdomains, it can't possibly imply all hosts.
430 if (!match_subdomains_)
431 return false;
432
433 // If |host_| is a recognized TLD, this will be 0. We don't include private
434 // TLDs, so that, e.g., *.appspot.com does not imply all hosts.
435 size_t registry_length = net::registry_controlled_domains::GetRegistryLength(
436 host_,
437 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
438 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
439 // If there was more than just a TLD in the host (e.g., *.foobar.com), it
440 // doesn't imply all hosts.
441 if (registry_length > 0)
442 return false;
443
444 // At this point the host could either be just a TLD ("com") or some unknown
445 // TLD-like string ("notatld"). To disambiguate between them construct a
446 // fake URL, and check the registry. This returns 0 if the TLD is
447 // unrecognized, or the length of the recognized TLD.
448 registry_length = net::registry_controlled_domains::GetRegistryLength(
449 base::StringPrintf("foo.%s", host_.c_str()),
450 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
451 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
452 // If we recognized this TLD, then this is a pattern like *.com, and it
453 // should imply all hosts. Otherwise, this doesn't imply all hosts.
454 return registry_length > 0;
455 }
456
420 bool URLPattern::MatchesPath(const std::string& test) const { 457 bool URLPattern::MatchesPath(const std::string& test) const {
421 // Make the behaviour of OverlapsWith consistent with MatchesURL, which is 458 // Make the behaviour of OverlapsWith consistent with MatchesURL, which is
422 // need to match hosted apps on e.g. 'google.com' also run on 'google.com/'. 459 // need to match hosted apps on e.g. 'google.com' also run on 'google.com/'.
423 if (test + "/*" == path_escaped_) 460 if (test + "/*" == path_escaped_)
424 return true; 461 return true;
425 462
426 return MatchPattern(test, path_escaped_); 463 return MatchPattern(test, path_escaped_);
427 } 464 }
428 465
429 const std::string& URLPattern::GetAsString() const { 466 const std::string& URLPattern::GetAsString() const {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 587 }
551 588
552 return result; 589 return result;
553 } 590 }
554 591
555 // static 592 // static
556 const char* URLPattern::GetParseResultString( 593 const char* URLPattern::GetParseResultString(
557 URLPattern::ParseResult parse_result) { 594 URLPattern::ParseResult parse_result) {
558 return kParseResultMessages[parse_result]; 595 return kParseResultMessages[parse_result];
559 } 596 }
OLDNEW
« no previous file with comments | « extensions/common/url_pattern.h ('k') | extensions/common/user_script.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698