| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_split.h" | 10 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "chrome/common/content_settings_pattern_parser.h" | 12 #include "chrome/common/content_settings_pattern_parser.h" |
| 13 #include "chrome/common/render_messages.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "net/base/dns_util.h" | 15 #include "net/base/dns_util.h" |
| 15 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "googleurl/src/url_canon.h" | 18 #include "googleurl/src/url_canon.h" |
| 19 #include "ipc/ipc_message_utils.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 std::string GetDefaultPort(const std::string& scheme) { | 23 std::string GetDefaultPort(const std::string& scheme) { |
| 22 if (scheme == chrome::kHttpScheme) | 24 if (scheme == chrome::kHttpScheme) |
| 23 return "80"; | 25 return "80"; |
| 24 if (scheme == chrome::kHttpsScheme) | 26 if (scheme == chrome::kHttpsScheme) |
| 25 return "443"; | 27 return "443"; |
| 26 return ""; | 28 return ""; |
| 27 } | 29 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 : is_valid_(false) { | 363 : is_valid_(false) { |
| 362 } | 364 } |
| 363 | 365 |
| 364 ContentSettingsPattern::ContentSettingsPattern( | 366 ContentSettingsPattern::ContentSettingsPattern( |
| 365 const PatternParts& parts, | 367 const PatternParts& parts, |
| 366 bool valid) | 368 bool valid) |
| 367 : parts_(parts), | 369 : parts_(parts), |
| 368 is_valid_(valid) { | 370 is_valid_(valid) { |
| 369 } | 371 } |
| 370 | 372 |
| 373 void ContentSettingsPattern::WriteToMessage(IPC::Message* m) const { |
| 374 IPC::WriteParam(m, is_valid_); |
| 375 IPC::WriteParam(m, parts_); |
| 376 } |
| 377 |
| 378 bool ContentSettingsPattern::ReadFromMessage(const IPC::Message* m, |
| 379 void** iter) { |
| 380 return IPC::ReadParam(m, iter, &is_valid_) && |
| 381 IPC::ReadParam(m, iter, &parts_); |
| 382 } |
| 383 |
| 371 bool ContentSettingsPattern::Matches( | 384 bool ContentSettingsPattern::Matches( |
| 372 const GURL& url) const { | 385 const GURL& url) const { |
| 373 // An invalid pattern matches nothing. | 386 // An invalid pattern matches nothing. |
| 374 if (!is_valid_) | 387 if (!is_valid_) |
| 375 return false; | 388 return false; |
| 376 | 389 |
| 377 // Match the scheme part. | 390 // Match the scheme part. |
| 378 const std::string scheme(url.scheme()); | 391 const std::string scheme(url.scheme()); |
| 379 if (!parts_.is_scheme_wildcard && | 392 if (!parts_.is_scheme_wildcard && |
| 380 parts_.scheme != scheme) { | 393 parts_.scheme != scheme) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 614 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
| 602 return ContentSettingsPattern::PREDECESSOR; | 615 return ContentSettingsPattern::PREDECESSOR; |
| 603 | 616 |
| 604 int result = parts.port.compare(other_parts.port); | 617 int result = parts.port.compare(other_parts.port); |
| 605 if (result == 0) | 618 if (result == 0) |
| 606 return ContentSettingsPattern::IDENTITY; | 619 return ContentSettingsPattern::IDENTITY; |
| 607 if (result > 0) | 620 if (result > 0) |
| 608 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 621 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 609 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 622 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 610 } | 623 } |
| OLD | NEW |