Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: chrome/browser/content_settings/content_settings_pattern.cc

Issue 7059016: Content settings pattern trim trailing dots from hostnames before matching a URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add one more test Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/content_settings/content_settings_pattern_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/browser/content_settings/content_settings_pattern.h" 5 #include "chrome/browser/content_settings/content_settings_pattern.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "chrome/browser/content_settings/content_settings_pattern_parser.h" 9 #include "chrome/browser/content_settings/content_settings_pattern_parser.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "net/base/dns_util.h"
11 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
12 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
13 #include "googleurl/src/url_canon.h" 14 #include "googleurl/src/url_canon.h"
14 15
15 namespace { 16 namespace {
16 17
17 std::string GetDefaultPort(const std::string& scheme) { 18 std::string GetDefaultPort(const std::string& scheme) {
18 if (scheme == chrome::kHttpScheme) 19 if (scheme == chrome::kHttpScheme)
19 return "80"; 20 return "80";
20 if (scheme == chrome::kHttpsScheme) 21 if (scheme == chrome::kHttpsScheme)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 116
116 if (parts->scheme == std::string(chrome::kFileScheme)) { 117 if (parts->scheme == std::string(chrome::kFileScheme)) {
117 GURL url(std::string(chrome::kFileScheme) + 118 GURL url(std::string(chrome::kFileScheme) +
118 std::string(chrome::kStandardSchemeSeparator) + parts->path); 119 std::string(chrome::kStandardSchemeSeparator) + parts->path);
119 parts->path = url.path(); 120 parts->path = url.path();
120 } 121 }
121 122
122 // Canonicalize the host part. 123 // Canonicalize the host part.
123 const std::string host(parts->host); 124 const std::string host(parts->host);
124 url_canon::CanonHostInfo host_info; 125 url_canon::CanonHostInfo host_info;
125 const std::string canonicalized_host(net::CanonicalizeHost(host, &host_info)); 126 std::string canonicalized_host(net::CanonicalizeHost(host, &host_info));
127 canonicalized_host = net::TrimEndingDot(canonicalized_host);
126 128
127 parts->host = ""; 129 parts->host = "";
128 if ((host.find('*') == std::string::npos) && 130 if ((host.find('*') == std::string::npos) &&
129 !canonicalized_host.empty()) { 131 !canonicalized_host.empty()) {
130 // Valid host. 132 // Valid host.
131 parts->host += canonicalized_host; 133 parts->host += canonicalized_host;
132 } 134 }
133 } 135 }
134 136
135 // //////////////////////////////////////////////////////////////////////////// 137 // ////////////////////////////////////////////////////////////////////////////
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 // TODO(markusheintz): This should change in the future. There should be only 296 // TODO(markusheintz): This should change in the future. There should be only
295 // one setting for all file URLs. So the path should be ignored. 297 // one setting for all file URLs. So the path should be ignored.
296 if (!parts_.is_scheme_wildcard && 298 if (!parts_.is_scheme_wildcard &&
297 scheme == std::string(chrome::kFileScheme)) { 299 scheme == std::string(chrome::kFileScheme)) {
298 if (parts_.path == std::string(url.path())) 300 if (parts_.path == std::string(url.path()))
299 return true; 301 return true;
300 return false; 302 return false;
301 } 303 }
302 304
303 // Match the host part. 305 // Match the host part.
304 const std::string host(url.host()); 306 const std::string host(net::TrimEndingDot(url.host()));
305 if (!parts_.has_domain_wildcard) { 307 if (!parts_.has_domain_wildcard) {
306 if (parts_.host != host) 308 if (parts_.host != host)
307 return false; 309 return false;
308 } else { 310 } else {
309 if (!IsSubDomainOrEqual(host, parts_.host)) 311 if (!IsSubDomainOrEqual(host, parts_.host))
310 return false; 312 return false;
311 } 313 }
312 314
313 // For chrome extensions URLs ignore the port. 315 // For chrome extensions URLs ignore the port.
314 if (parts_.scheme == std::string(chrome::kExtensionScheme)) 316 if (parts_.scheme == std::string(chrome::kExtensionScheme))
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 const ContentSettingsPattern::PatternParts& parts, 467 const ContentSettingsPattern::PatternParts& parts,
466 const ContentSettingsPattern::PatternParts& other_parts) { 468 const ContentSettingsPattern::PatternParts& other_parts) {
467 if (parts.is_port_wildcard && !other_parts.is_port_wildcard) 469 if (parts.is_port_wildcard && !other_parts.is_port_wildcard)
468 return ContentSettingsPattern::SUCCESSOR; 470 return ContentSettingsPattern::SUCCESSOR;
469 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) 471 if (!parts.is_port_wildcard && other_parts.is_port_wildcard)
470 return ContentSettingsPattern::PREDECESSOR; 472 return ContentSettingsPattern::PREDECESSOR;
471 if (parts.port != other_parts.port) 473 if (parts.port != other_parts.port)
472 return ContentSettingsPattern::DISJOINT; 474 return ContentSettingsPattern::DISJOINT;
473 return ContentSettingsPattern::IDENTITY; 475 return ContentSettingsPattern::IDENTITY;
474 } 476 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/content_settings/content_settings_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698