OLD | NEW |
---|---|
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 Loading... | |
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(origin); | |
159 DCHECK(real_origin.IsSameOriginWith(url::Origin(origin.GetOrigin()))); | |
Devlin
2016/02/03 21:01:25
Can we not use the static IsSameOriginWith() here?
palmer
2016/02/03 21:03:08
No, I actually want to maintain the check on GURL:
Devlin
2016/02/03 21:10:11
I'm sure that's right. Can you tell me why? :) (F
| |
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 Loading... | |
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 |
OLD | NEW |