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

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

Issue 1658913002: Make extensions use a correct same-origin check. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't break the tests — we shouldn't have been adding null origins anyway. Created 4 years, 10 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 "extensions/common/url_pattern_set.h" 5 #include "extensions/common/url_pattern_set.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <ostream> 8 #include <ostream>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "extensions/common/error_utils.h" 14 #include "extensions/common/error_utils.h"
15 #include "extensions/common/url_pattern.h" 15 #include "extensions/common/url_pattern.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 #include "url/origin.h"
17 #include "url/url_constants.h" 18 #include "url/url_constants.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
21 namespace { 22 namespace {
22 23
23 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; 24 const char kInvalidURLPatternError[] = "Invalid url pattern '*'";
24 25
25 } // namespace 26 } // namespace
26 27
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void URLPatternSet::AddPatterns(const URLPatternSet& set) { 146 void URLPatternSet::AddPatterns(const URLPatternSet& set) {
146 patterns_.insert(set.patterns().begin(), 147 patterns_.insert(set.patterns().begin(),
147 set.patterns().end()); 148 set.patterns().end());
148 } 149 }
149 150
150 void URLPatternSet::ClearPatterns() { 151 void URLPatternSet::ClearPatterns() {
151 patterns_.clear(); 152 patterns_.clear();
152 } 153 }
153 154
154 bool URLPatternSet::AddOrigin(int valid_schemes, const GURL& origin) { 155 bool URLPatternSet::AddOrigin(int valid_schemes, const GURL& origin) {
155 DCHECK_EQ(origin.GetOrigin(), origin); 156 if (origin.is_empty())
157 return false;
158 const url::Origin real_origin = url::Origin(origin);
brettw 2016/02/03 19:12:38 This would be better as: const url::Origin(origi
palmer 2016/02/03 20:47:57 Done.
159 DCHECK(real_origin.IsSameOriginWith(url::Origin(origin.GetOrigin())));
156 URLPattern origin_pattern(valid_schemes); 160 URLPattern origin_pattern(valid_schemes);
157 // Origin adding could fail if |origin| does not match |valid_schemes|. 161 // Origin adding could fail if |origin| does not match |valid_schemes|.
158 if (origin_pattern.Parse(origin.GetOrigin().spec()) != 162 if (origin_pattern.Parse(origin.spec()) != URLPattern::PARSE_SUCCESS) {
159 URLPattern::PARSE_SUCCESS) {
160 return false; 163 return false;
161 } 164 }
162 origin_pattern.SetPath("/*"); 165 origin_pattern.SetPath("/*");
163 return AddPattern(origin_pattern); 166 return AddPattern(origin_pattern);
164 } 167 }
165 168
166 bool URLPatternSet::Contains(const URLPatternSet& other) const { 169 bool URLPatternSet::Contains(const URLPatternSet& other) const {
167 for (URLPatternSet::const_iterator it = other.begin(); 170 for (URLPatternSet::const_iterator it = other.begin();
168 it != other.end(); ++it) { 171 it != other.end(); ++it) {
169 if (!ContainsPattern(*it)) 172 if (!ContainsPattern(*it))
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 for (size_t i = 0; i < value.GetSize(); ++i) { 280 for (size_t i = 0; i < value.GetSize(); ++i) {
278 std::string item; 281 std::string item;
279 if (!value.GetString(i, &item)) 282 if (!value.GetString(i, &item))
280 return false; 283 return false;
281 patterns.push_back(item); 284 patterns.push_back(item);
282 } 285 }
283 return Populate(patterns, valid_schemes, allow_file_access, error); 286 return Populate(patterns, valid_schemes, allow_file_access, error);
284 } 287 }
285 288
286 } // namespace extensions 289 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698