Chromium Code Reviews| 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(parts_, is_valid_); | |
|
jochen (gone - plz use gerrit)
2013/04/05 11:23:47
nit. just return ContentSettingsPattern()
yhirano
2013/04/08 00:37:45
Done.
| |
| 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(); | |
|
jochen (gone - plz use gerrit)
2013/04/05 11:23:47
nit { } around body since the if condition is mult
yhirano
2013/04/08 00:37:45
Done.
| |
| 171 | |
| 159 return ContentSettingsPattern(parts_, is_valid_); | 172 return ContentSettingsPattern(parts_, is_valid_); |
| 160 } | 173 } |
| 161 | 174 |
| 162 // static | 175 // static |
| 163 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { | 176 bool ContentSettingsPattern::Builder::Canonicalize(PatternParts* parts) { |
| 164 // Canonicalize the scheme part. | 177 // Canonicalize the scheme part. |
| 165 const std::string scheme(StringToLowerASCII(parts->scheme)); | 178 const std::string scheme(StringToLowerASCII(parts->scheme)); |
| 166 parts->scheme = scheme; | 179 parts->scheme = scheme; |
| 167 | 180 |
| 168 if (parts->scheme == std::string(chrome::kFileScheme) && | 181 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) | 673 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
| 661 return ContentSettingsPattern::PREDECESSOR; | 674 return ContentSettingsPattern::PREDECESSOR; |
| 662 | 675 |
| 663 int result = parts.port.compare(other_parts.port); | 676 int result = parts.port.compare(other_parts.port); |
| 664 if (result == 0) | 677 if (result == 0) |
| 665 return ContentSettingsPattern::IDENTITY; | 678 return ContentSettingsPattern::IDENTITY; |
| 666 if (result > 0) | 679 if (result > 0) |
| 667 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 680 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 668 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 681 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 669 } | 682 } |
| OLD | NEW |