| 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 const url::Origin real_origin = url::Origin(origin); |
| 157 DCHECK(real_origin.IsSameOriginWith(url::Origin(origin.GetOrigin()))); |
| 156 URLPattern origin_pattern(valid_schemes); | 158 URLPattern origin_pattern(valid_schemes); |
| 157 // Origin adding could fail if |origin| does not match |valid_schemes|. | 159 // Origin adding could fail if |origin| does not match |valid_schemes|. |
| 158 if (origin_pattern.Parse(origin.GetOrigin().spec()) != | 160 if (origin_pattern.Parse(real_origin.Serialize()) != |
| 159 URLPattern::PARSE_SUCCESS) { | 161 URLPattern::PARSE_SUCCESS) { |
| 160 return false; | 162 return false; |
| 161 } | 163 } |
| 162 origin_pattern.SetPath("/*"); | 164 origin_pattern.SetPath("/*"); |
| 163 return AddPattern(origin_pattern); | 165 return AddPattern(origin_pattern); |
| 164 } | 166 } |
| 165 | 167 |
| 166 bool URLPatternSet::Contains(const URLPatternSet& other) const { | 168 bool URLPatternSet::Contains(const URLPatternSet& other) const { |
| 167 for (URLPatternSet::const_iterator it = other.begin(); | 169 for (URLPatternSet::const_iterator it = other.begin(); |
| 168 it != other.end(); ++it) { | 170 it != other.end(); ++it) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 for (size_t i = 0; i < value.GetSize(); ++i) { | 279 for (size_t i = 0; i < value.GetSize(); ++i) { |
| 278 std::string item; | 280 std::string item; |
| 279 if (!value.GetString(i, &item)) | 281 if (!value.GetString(i, &item)) |
| 280 return false; | 282 return false; |
| 281 patterns.push_back(item); | 283 patterns.push_back(item); |
| 282 } | 284 } |
| 283 return Populate(patterns, valid_schemes, allow_file_access, error); | 285 return Populate(patterns, valid_schemes, allow_file_access, error); |
| 284 } | 286 } |
| 285 | 287 |
| 286 } // namespace extensions | 288 } // namespace extensions |
| OLD | NEW |