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

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

Issue 2730533002: chrome.contentSettings API: Block patterns that match extension URLs for mic and video
Patch Set: More tests 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
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::MatchesExtensionUrls() const {
msramek 2017/03/02 09:50:40 This is a layering violation. It's not the first e
Devlin 2017/03/02 21:55:02 For this, we should just be able to use crx_file::
meacer 2017/03/07 20:50:38 Thanks! I searched a lot for an existing function
538 const char kExtensionIdRegex[] = "^[a-zA-Z]{32}";
msramek 2017/03/02 09:50:40 It's actually [a-p]{32}. https://cs.chromium.org/
meacer 2017/03/07 20:50:38 Not sure why I put a-z. But removed in favor of Is
539 return (parts_.is_scheme_wildcard || parts_.scheme == "chrome-extension") &&
msramek 2017/03/02 09:50:40 "*://[*.]google.com" is a valid scheme that both i
meacer 2017/03/07 20:50:38 Thanks for pointing this out, I though has_domain_
msramek 2017/03/13 22:05:25 Well, that's not exactly true. There's no way in t
meacer 2017/04/11 18:30:47 I'm explicitly avoiding querying for installed ext
msramek 2017/04/12 09:53:13 Acknowledged. Can you please explain that reasonin
540 (parts_.has_domain_wildcard ||
541 RE2::FullMatch(parts_.host, kExtensionIdRegex));
542 }
543
536 bool ContentSettingsPattern::Matches( 544 bool ContentSettingsPattern::Matches(
537 const GURL& url) const { 545 const GURL& url) const {
538 // An invalid pattern matches nothing. 546 // An invalid pattern matches nothing.
539 if (!is_valid_) 547 if (!is_valid_)
540 return false; 548 return false;
541 549
542 const GURL* local_url = &url; 550 const GURL* local_url = &url;
543 if (url.SchemeIsFileSystem() && url.inner_url()) { 551 if (url.SchemeIsFileSystem() && url.inner_url()) {
544 local_url = url.inner_url(); 552 local_url = url.inner_url();
545 } 553 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 if (!parts.is_path_wildcard && other_parts.is_path_wildcard) 829 if (!parts.is_path_wildcard && other_parts.is_path_wildcard)
822 return ContentSettingsPattern::PREDECESSOR; 830 return ContentSettingsPattern::PREDECESSOR;
823 831
824 int result = parts.path.compare(other_parts.path); 832 int result = parts.path.compare(other_parts.path);
825 if (result == 0) 833 if (result == 0)
826 return ContentSettingsPattern::IDENTITY; 834 return ContentSettingsPattern::IDENTITY;
827 if (result > 0) 835 if (result > 0)
828 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 836 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
829 return ContentSettingsPattern::DISJOINT_ORDER_POST; 837 return ContentSettingsPattern::DISJOINT_ORDER_POST;
830 } 838 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698