| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 bool URLPatternSet::MatchesURL(const GURL& url) const { | 142 bool URLPatternSet::MatchesURL(const GURL& url) const { |
| 143 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 143 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
| 144 pattern != patterns_.end(); ++pattern) { | 144 pattern != patterns_.end(); ++pattern) { |
| 145 if (pattern->MatchesURL(url)) | 145 if (pattern->MatchesURL(url)) |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 return false; | 149 return false; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool URLPatternSet::MatchesAllURLs() const { |
| 153 for (URLPatternSet::const_iterator host = begin(); host != end(); ++host) { |
| 154 if (host->match_all_urls() || |
| 155 (host->match_subdomains() && host->host().empty())) |
| 156 return true; |
| 157 } |
| 158 return false; |
| 159 } |
| 160 |
| 152 bool URLPatternSet::MatchesSecurityOrigin(const GURL& origin) const { | 161 bool URLPatternSet::MatchesSecurityOrigin(const GURL& origin) const { |
| 153 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 162 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
| 154 pattern != patterns_.end(); ++pattern) { | 163 pattern != patterns_.end(); ++pattern) { |
| 155 if (pattern->MatchesSecurityOrigin(origin)) | 164 if (pattern->MatchesSecurityOrigin(origin)) |
| 156 return true; | 165 return true; |
| 157 } | 166 } |
| 158 | 167 |
| 159 return false; | 168 return false; |
| 160 } | 169 } |
| 161 | 170 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 209 } |
| 201 if (!allow_file_access && pattern.MatchesScheme(url::kFileScheme)) { | 210 if (!allow_file_access && pattern.MatchesScheme(url::kFileScheme)) { |
| 202 pattern.SetValidSchemes( | 211 pattern.SetValidSchemes( |
| 203 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 212 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 204 } | 213 } |
| 205 AddPattern(pattern); | 214 AddPattern(pattern); |
| 206 } | 215 } |
| 207 return true; | 216 return true; |
| 208 } | 217 } |
| 209 | 218 |
| 219 scoped_ptr<std::vector<std::string> > URLPatternSet::ToStringVector() const { |
| 220 scoped_ptr<std::vector<std::string> > value(new std::vector<std::string>); |
| 221 for (URLPatternSet::const_iterator i = patterns_.begin(); |
| 222 i != patterns_.end(); |
| 223 ++i) { |
| 224 value->push_back(i->GetAsString()); |
| 225 } |
| 226 std::unique(value->begin(), value->end()); |
| 227 return value.Pass(); |
| 228 } |
| 229 |
| 210 bool URLPatternSet::Populate(const base::ListValue& value, | 230 bool URLPatternSet::Populate(const base::ListValue& value, |
| 211 int valid_schemes, | 231 int valid_schemes, |
| 212 bool allow_file_access, | 232 bool allow_file_access, |
| 213 std::string* error) { | 233 std::string* error) { |
| 214 std::vector<std::string> patterns; | 234 std::vector<std::string> patterns; |
| 215 for (size_t i = 0; i < value.GetSize(); ++i) { | 235 for (size_t i = 0; i < value.GetSize(); ++i) { |
| 216 std::string item; | 236 std::string item; |
| 217 if (!value.GetString(i, &item)) | 237 if (!value.GetString(i, &item)) |
| 218 return false; | 238 return false; |
| 219 patterns.push_back(item); | 239 patterns.push_back(item); |
| 220 } | 240 } |
| 221 return Populate(patterns, valid_schemes, allow_file_access, error); | 241 return Populate(patterns, valid_schemes, allow_file_access, error); |
| 222 } | 242 } |
| 223 | 243 |
| 224 } // namespace extensions | 244 } // namespace extensions |
| OLD | NEW |