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

Side by Side Diff: components/content_settings/core/common/content_settings_pattern.cc

Issue 2728503003: Update permission warning for contentSettings API
Patch Set: chrome.contentSettings API: Do not allow wildcard patterns that match extension URLs Created 3 years, 9 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
« no previous file with comments | « components/content_settings/core/common/content_settings_pattern.h ('k') | no next file » | 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 "components/content_settings/core/common/content_settings_pattern.h" 5 #include "components/content_settings/core/common/content_settings_pattern.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "components/content_settings/core/common/content_settings_pattern_parse r.h" 15 #include "components/content_settings/core/common/content_settings_pattern_parse r.h"
16 #include "net/base/url_util.h" 16 #include "net/base/url_util.h"
17 #include "third_party/re2/src/re2/re2.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace { 20 namespace {
20 21
21 // The component supports only one scheme for simplicity. 22 // The component supports only one scheme for simplicity.
22 const char* non_port_non_domain_wildcard_scheme = NULL; 23 const char* non_port_non_domain_wildcard_scheme = NULL;
23 24
24 // Keep it consistent with enum SchemeType in content_settings_pattern.h. 25 // Keep it consistent with enum SchemeType in content_settings_pattern.h.
25 const char* const kSchemeNames[] = { 26 const char* const kSchemeNames[] = {
26 "wildcard", 27 "wildcard",
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 : is_valid_(false) { 527 : is_valid_(false) {
527 } 528 }
528 529
529 ContentSettingsPattern::ContentSettingsPattern( 530 ContentSettingsPattern::ContentSettingsPattern(
530 const PatternParts& parts, 531 const PatternParts& parts,
531 bool valid) 532 bool valid)
532 : parts_(parts), 533 : parts_(parts),
533 is_valid_(valid) { 534 is_valid_(valid) {
534 } 535 }
535 536
537 bool ContentSettingsPattern::IsExtensionUrlWildcard() const {
538 if (!parts_.is_scheme_wildcard && parts_.scheme != "chrome-extension")
539 return false;
540 const char kExtensionIdRegex[] = "[a-zA-Z]{32}";
541
542 return parts_.has_domain_wildcard ||
543 RE2::FullMatch(parts_.host, kExtensionIdRegex);
544 }
545
536 bool ContentSettingsPattern::Matches( 546 bool ContentSettingsPattern::Matches(
537 const GURL& url) const { 547 const GURL& url) const {
538 // An invalid pattern matches nothing. 548 // An invalid pattern matches nothing.
539 if (!is_valid_) 549 if (!is_valid_)
540 return false; 550 return false;
541 551
542 const GURL* local_url = &url; 552 const GURL* local_url = &url;
543 if (url.SchemeIsFileSystem() && url.inner_url()) { 553 if (url.SchemeIsFileSystem() && url.inner_url()) {
544 local_url = url.inner_url(); 554 local_url = url.inner_url();
545 } 555 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) 831 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
822 return ContentSettingsPattern::PREDECESSOR; 832 return ContentSettingsPattern::PREDECESSOR;
823 833
824 int result = parts.path.compare(other_parts.path); 834 int result = parts.path.compare(other_parts.path);
825 if (result == 0) 835 if (result == 0)
826 return ContentSettingsPattern::IDENTITY; 836 return ContentSettingsPattern::IDENTITY;
827 if (result > 0) 837 if (result > 0)
828 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 838 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
829 return ContentSettingsPattern::DISJOINT_ORDER_POST; 839 return ContentSettingsPattern::DISJOINT_ORDER_POST;
830 } 840 }
OLDNEW
« no previous file with comments | « components/content_settings/core/common/content_settings_pattern.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698