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

Side by Side Diff: chrome/common/content_settings_pattern.cc

Issue 254763005: Move some content url constants to /url. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and address some style nits. Created 6 years, 8 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
OLDNEW
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/strings/string_split.h" 10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/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/render_messages.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "extensions/common/constants.h" 15 #include "extensions/common/constants.h"
16 #include "ipc/ipc_message_utils.h" 16 #include "ipc/ipc_message_utils.h"
17 #include "net/base/dns_util.h" 17 #include "net/base/dns_util.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 #include "net/base/url_constants.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 #include "url/url_canon.h" 21 #include "url/url_canon.h"
21 22
22 namespace { 23 namespace {
23 24
24 std::string GetDefaultPort(const std::string& scheme) { 25 std::string GetDefaultPort(const std::string& scheme) {
25 if (scheme == content::kHttpScheme) 26 if (scheme == net::kHttpScheme)
26 return "80"; 27 return "80";
27 if (scheme == content::kHttpsScheme) 28 if (scheme == net::kHttpsScheme)
28 return "443"; 29 return "443";
29 return std::string(); 30 return std::string();
30 } 31 }
31 32
32 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g. 33 // Returns true if |sub_domain| is a sub domain or equls |domain|. E.g.
33 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a 34 // "mail.google.com" is a sub domain of "google.com" but "evilhost.com" is not a
34 // subdomain of "host.com". 35 // subdomain of "host.com".
35 bool IsSubDomainOrEqual(const std::string& sub_domain, 36 bool IsSubDomainOrEqual(const std::string& sub_domain,
36 const std::string& domain) { 37 const std::string& domain) {
37 // The empty string serves as wildcard. Each domain is a subdomain of the 38 // The empty string serves as wildcard. Each domain is a subdomain of the
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 (parts.host.empty() && !parts.has_domain_wildcard) || 237 (parts.host.empty() && !parts.has_domain_wildcard) ||
237 (parts.port.empty() && !parts.is_port_wildcard)) { 238 (parts.port.empty() && !parts.is_port_wildcard)) {
238 return false; 239 return false;
239 } 240 }
240 241
241 if (parts.host.find("*") != std::string::npos) 242 if (parts.host.find("*") != std::string::npos)
242 return false; 243 return false;
243 244
244 // Test if the scheme is supported or a wildcard. 245 // Test if the scheme is supported or a wildcard.
245 if (!parts.is_scheme_wildcard && 246 if (!parts.is_scheme_wildcard &&
246 parts.scheme != std::string(content::kHttpScheme) && 247 parts.scheme != std::string(net::kHttpScheme) &&
247 parts.scheme != std::string(content::kHttpsScheme)) { 248 parts.scheme != std::string(net::kHttpsScheme)) {
248 return false; 249 return false;
249 } 250 }
250 return true; 251 return true;
251 } 252 }
252 253
253 // static 254 // static
254 bool ContentSettingsPattern::Builder::LegacyValidate( 255 bool ContentSettingsPattern::Builder::LegacyValidate(
255 const PatternParts& parts) { 256 const PatternParts& parts) {
256 // If the pattern is for a "file-pattern" test if it is valid. 257 // If the pattern is for a "file-pattern" test if it is valid.
257 if (parts.scheme == std::string(content::kFileScheme) && 258 if (parts.scheme == std::string(content::kFileScheme) &&
(...skipping 13 matching lines...) Expand all
271 272
272 // Non-file patterns are invalid if either the scheme, host or port part is 273 // Non-file patterns are invalid if either the scheme, host or port part is
273 // empty. 274 // empty.
274 if ((!parts.is_scheme_wildcard) || 275 if ((!parts.is_scheme_wildcard) ||
275 (parts.host.empty() && !parts.has_domain_wildcard) || 276 (parts.host.empty() && !parts.has_domain_wildcard) ||
276 (!parts.is_port_wildcard)) 277 (!parts.is_port_wildcard))
277 return false; 278 return false;
278 279
279 // Test if the scheme is supported or a wildcard. 280 // Test if the scheme is supported or a wildcard.
280 if (!parts.is_scheme_wildcard && 281 if (!parts.is_scheme_wildcard &&
281 parts.scheme != std::string(content::kHttpScheme) && 282 parts.scheme != std::string(net::kHttpScheme) &&
282 parts.scheme != std::string(content::kHttpsScheme)) { 283 parts.scheme != std::string(net::kHttpsScheme)) {
283 return false; 284 return false;
284 } 285 }
285 return true; 286 return true;
286 } 287 }
287 288
288 // //////////////////////////////////////////////////////////////////////////// 289 // ////////////////////////////////////////////////////////////////////////////
289 // ContentSettingsPattern::PatternParts 290 // ContentSettingsPattern::PatternParts
290 // 291 //
291 ContentSettingsPattern::PatternParts::PatternParts() 292 ContentSettingsPattern::PatternParts::PatternParts()
292 : is_scheme_wildcard(false), 293 : is_scheme_wildcard(false),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (url.SchemeIsFileSystem() && url.inner_url()) { 333 if (url.SchemeIsFileSystem() && url.inner_url()) {
333 local_url = url.inner_url(); 334 local_url = url.inner_url();
334 } 335 }
335 if (local_url->SchemeIsFile()) { 336 if (local_url->SchemeIsFile()) {
336 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); 337 builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
337 } else { 338 } else {
338 // Please keep the order of the ifs below as URLs with an IP as host can 339 // Please keep the order of the ifs below as URLs with an IP as host can
339 // also have a "http" scheme. 340 // also have a "http" scheme.
340 if (local_url->HostIsIPAddress()) { 341 if (local_url->HostIsIPAddress()) {
341 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); 342 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
342 } else if (local_url->SchemeIs(content::kHttpScheme)) { 343 } else if (local_url->SchemeIs(net::kHttpScheme)) {
343 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( 344 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(
344 local_url->host()); 345 local_url->host());
345 } else if (local_url->SchemeIs(content::kHttpsScheme)) { 346 } else if (local_url->SchemeIs(net::kHttpsScheme)) {
346 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost( 347 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost(
347 local_url->host()); 348 local_url->host());
348 } else { 349 } else {
349 // Unsupported scheme 350 // Unsupported scheme
350 } 351 }
351 if (local_url->port().empty()) { 352 if (local_url->port().empty()) {
352 if (local_url->SchemeIs(content::kHttpsScheme)) 353 if (local_url->SchemeIs(net::kHttpsScheme))
353 builder->WithPort(GetDefaultPort(content::kHttpsScheme)); 354 builder->WithPort(GetDefaultPort(net::kHttpsScheme));
354 else 355 else
355 builder->WithPortWildcard(); 356 builder->WithPortWildcard();
356 } else { 357 } else {
357 builder->WithPort(local_url->port()); 358 builder->WithPort(local_url->port());
358 } 359 }
359 } 360 }
360 return builder->Build(); 361 return builder->Build();
361 } 362 }
362 363
363 // static 364 // static
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) 675 if (!parts.is_port_wildcard && other_parts.is_port_wildcard)
675 return ContentSettingsPattern::PREDECESSOR; 676 return ContentSettingsPattern::PREDECESSOR;
676 677
677 int result = parts.port.compare(other_parts.port); 678 int result = parts.port.compare(other_parts.port);
678 if (result == 0) 679 if (result == 0)
679 return ContentSettingsPattern::IDENTITY; 680 return ContentSettingsPattern::IDENTITY;
680 if (result > 0) 681 if (result > 0)
681 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 682 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
682 return ContentSettingsPattern::DISJOINT_ORDER_POST; 683 return ContentSettingsPattern::DISJOINT_ORDER_POST;
683 } 684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698