| 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 "chrome/common/content_settings_pattern.h" | 5 #include "chrome/common/content_settings_pattern.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ContentSettingsPattern ContentSettingsPattern::Builder::Build() { | 149 ContentSettingsPattern ContentSettingsPattern::Builder::Build() { |
| 150 if (!is_valid_) | 150 if (!is_valid_) |
| 151 return ContentSettingsPattern(); | 151 return ContentSettingsPattern(); |
| 152 if (!Canonicalize(&parts_)) | 152 if (!Canonicalize(&parts_)) |
| 153 return ContentSettingsPattern(); | 153 return ContentSettingsPattern(); |
| 154 if (use_legacy_validate_) { | 154 if (use_legacy_validate_) { |
| 155 is_valid_ = LegacyValidate(parts_); | 155 is_valid_ = LegacyValidate(parts_); |
| 156 } else { | 156 } else { |
| 157 is_valid_ = Validate(parts_); | 157 is_valid_ = Validate(parts_); |
| 158 } | 158 } |
| 159 if (!is_valid_) |
| 160 return ContentSettingsPattern(); |
| 161 |
| 162 // A pattern is invalid if canonicalization is not idempotent. |
| 163 // This check is here because it should be checked no matter |
| 164 // use_legacy_validate_ is. |
| 165 PatternParts parts(parts_); |
| 166 if (!Canonicalize(&parts)) |
| 167 return ContentSettingsPattern(); |
| 168 if (ContentSettingsPattern(parts_, true) != |
| 169 ContentSettingsPattern(parts, true)) { |
| 170 return ContentSettingsPattern(); |
| 171 } |
| 172 |
| 159 return ContentSettingsPattern(parts_, is_valid_); | 173 return ContentSettingsPattern(parts_, is_valid_); |
| 160 } | 174 } |
| 161 | 175 |
| 162 // static | 176 // static |
| 163 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { | 177 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { |
| 164 // Canonicalize the scheme part. | 178 // Canonicalize the scheme part. |
| 165 const std::string scheme(StringToLowerASCII(parts->scheme)); | 179 const std::string scheme(StringToLowerASCII(parts->scheme)); |
| 166 parts->scheme = scheme; | 180 parts->scheme = scheme; |
| 167 | 181 |
| 168 if (parts->scheme == std::string(chrome::kFileScheme) && | 182 if (parts->scheme == std::string(chrome::kFileScheme) && |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 674 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
| 661 return ContentSettingsPattern::PREDECESSOR; | 675 return ContentSettingsPattern::PREDECESSOR; |
| 662 | 676 |
| 663 int result = parts.port.compare(other_parts.port); | 677 int result = parts.port.compare(other_parts.port); |
| 664 if (result == 0) | 678 if (result == 0) |
| 665 return ContentSettingsPattern::IDENTITY; | 679 return ContentSettingsPattern::IDENTITY; |
| 666 if (result > 0) | 680 if (result > 0) |
| 667 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 681 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 668 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 682 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 669 } | 683 } |
| OLD | NEW |