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_split.h" | 10 #include "base/string_split.h" |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 bool validate) { | 306 bool validate) { |
307 return new Builder(validate); | 307 return new Builder(validate); |
308 } | 308 } |
309 | 309 |
310 // static | 310 // static |
311 ContentSettingsPattern ContentSettingsPattern::FromURL( | 311 ContentSettingsPattern ContentSettingsPattern::FromURL( |
312 const GURL& url) { | 312 const GURL& url) { |
313 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 313 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
314 ContentSettingsPattern::CreateBuilder(false)); | 314 ContentSettingsPattern::CreateBuilder(false)); |
315 | 315 |
316 if (url.SchemeIsFile()) { | 316 const GURL* local_url = &url; |
317 builder->WithScheme(url.scheme())->WithPath(url.path()); | 317 if (url.SchemeIsFileSystem() && url.inner_url()) { |
| 318 local_url = url.inner_url(); |
| 319 } |
| 320 if (local_url->SchemeIsFile()) { |
| 321 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); |
318 } else { | 322 } else { |
319 // Please keep the order of the ifs below as URLs with an IP as host can | 323 // Please keep the order of the ifs below as URLs with an IP as host can |
320 // also have a "http" scheme. | 324 // also have a "http" scheme. |
321 if (url.HostIsIPAddress()) { | 325 if (local_url->HostIsIPAddress()) { |
322 builder->WithScheme(url.scheme())->WithHost(url.host()); | 326 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); |
323 } else if (url.SchemeIs(chrome::kHttpScheme)) { | 327 } else if (local_url->SchemeIs(chrome::kHttpScheme)) { |
324 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(url.host()); | 328 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost( |
325 } else if (url.SchemeIs(chrome::kHttpsScheme)) { | 329 local_url->host()); |
326 builder->WithScheme(url.scheme())->WithDomainWildcard()->WithHost( | 330 } else if (local_url->SchemeIs(chrome::kHttpsScheme)) { |
327 url.host()); | 331 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost( |
| 332 local_url->host()); |
328 } else { | 333 } else { |
329 // Unsupported scheme | 334 // Unsupported scheme |
330 } | 335 } |
331 if (url.port().empty()) { | 336 if (local_url->port().empty()) { |
332 if (url.SchemeIs(chrome::kHttpsScheme)) | 337 if (local_url->SchemeIs(chrome::kHttpsScheme)) |
333 builder->WithPort(GetDefaultPort(chrome::kHttpsScheme)); | 338 builder->WithPort(GetDefaultPort(chrome::kHttpsScheme)); |
334 else | 339 else |
335 builder->WithPortWildcard(); | 340 builder->WithPortWildcard(); |
336 } else { | 341 } else { |
337 builder->WithPort(url.port()); | 342 builder->WithPort(local_url->port()); |
338 } | 343 } |
339 } | 344 } |
340 return builder->Build(); | 345 return builder->Build(); |
341 } | 346 } |
342 | 347 |
343 // static | 348 // static |
344 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( | 349 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( |
345 const GURL& url) { | 350 const GURL& url) { |
346 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 351 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
347 ContentSettingsPattern::CreateBuilder(false)); | 352 ContentSettingsPattern::CreateBuilder(false)); |
348 | 353 |
349 if (url.SchemeIsFile()) { | 354 const GURL* local_url = &url; |
350 builder->WithScheme(url.scheme())->WithPath(url.path()); | 355 if (url.SchemeIsFileSystem() && url.inner_url()) { |
| 356 local_url = url.inner_url(); |
| 357 } |
| 358 if (local_url->SchemeIsFile()) { |
| 359 builder->WithScheme(local_url->scheme())->WithPath(local_url->path()); |
351 } else { | 360 } else { |
352 builder->WithScheme(url.scheme())->WithHost(url.host()); | 361 builder->WithScheme(local_url->scheme())->WithHost(local_url->host()); |
353 if (url.port().empty()) { | 362 if (local_url->port().empty()) { |
354 builder->WithPort(GetDefaultPort(url.scheme())); | 363 builder->WithPort(GetDefaultPort(local_url->scheme())); |
355 } else { | 364 } else { |
356 builder->WithPort(url.port()); | 365 builder->WithPort(local_url->port()); |
357 } | 366 } |
358 } | 367 } |
359 return builder->Build(); | 368 return builder->Build(); |
360 } | 369 } |
361 | 370 |
362 // static | 371 // static |
363 ContentSettingsPattern ContentSettingsPattern::FromString( | 372 ContentSettingsPattern ContentSettingsPattern::FromString( |
364 const std::string& pattern_spec) { | 373 const std::string& pattern_spec) { |
365 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( | 374 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( |
366 ContentSettingsPattern::CreateBuilder(false)); | 375 ContentSettingsPattern::CreateBuilder(false)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 return IPC::ReadParam(m, iter, &is_valid_) && | 416 return IPC::ReadParam(m, iter, &is_valid_) && |
408 IPC::ReadParam(m, iter, &parts_); | 417 IPC::ReadParam(m, iter, &parts_); |
409 } | 418 } |
410 | 419 |
411 bool ContentSettingsPattern::Matches( | 420 bool ContentSettingsPattern::Matches( |
412 const GURL& url) const { | 421 const GURL& url) const { |
413 // An invalid pattern matches nothing. | 422 // An invalid pattern matches nothing. |
414 if (!is_valid_) | 423 if (!is_valid_) |
415 return false; | 424 return false; |
416 | 425 |
| 426 const GURL* local_url = &url; |
| 427 if (url.SchemeIsFileSystem() && url.inner_url()) { |
| 428 local_url = url.inner_url(); |
| 429 } |
| 430 |
417 // Match the scheme part. | 431 // Match the scheme part. |
418 const std::string scheme(url.scheme()); | 432 const std::string scheme(local_url->scheme()); |
419 if (!parts_.is_scheme_wildcard && | 433 if (!parts_.is_scheme_wildcard && |
420 parts_.scheme != scheme) { | 434 parts_.scheme != scheme) { |
421 return false; | 435 return false; |
422 } | 436 } |
423 | 437 |
424 // File URLs have no host. Matches if the pattern has the path wildcard set, | 438 // File URLs have no host. Matches if the pattern has the path wildcard set, |
425 // or if the path in the URL is identical to the one in the pattern. | 439 // or if the path in the URL is identical to the one in the pattern. |
| 440 // For filesystem:file URLs, the path used is the filesystem type, so all |
| 441 // filesystem:file:///temporary/... are equivalent. |
| 442 // TODO(markusheintz): Content settings should be defined for all files on |
| 443 // a machine. Unless there is a good use case for supporting paths for file |
| 444 // patterns, stop supporting path for file patterns. |
426 if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) | 445 if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) |
427 return parts_.is_path_wildcard || parts_.path == std::string(url.path()); | 446 return parts_.is_path_wildcard || |
| 447 parts_.path == std::string(local_url->path()); |
428 | 448 |
429 // Match the host part. | 449 // Match the host part. |
430 const std::string host(net::TrimEndingDot(url.host())); | 450 const std::string host(net::TrimEndingDot(local_url->host())); |
431 if (!parts_.has_domain_wildcard) { | 451 if (!parts_.has_domain_wildcard) { |
432 if (parts_.host != host) | 452 if (parts_.host != host) |
433 return false; | 453 return false; |
434 } else { | 454 } else { |
435 if (!IsSubDomainOrEqual(host, parts_.host)) | 455 if (!IsSubDomainOrEqual(host, parts_.host)) |
436 return false; | 456 return false; |
437 } | 457 } |
438 | 458 |
439 // For chrome extensions URLs ignore the port. | 459 // For chrome extensions URLs ignore the port. |
440 if (parts_.scheme == std::string(chrome::kExtensionScheme)) | 460 if (parts_.scheme == std::string(chrome::kExtensionScheme)) |
441 return true; | 461 return true; |
442 | 462 |
443 // Match the port part. | 463 // Match the port part. |
444 std::string port(url.port()); | 464 std::string port(local_url->port()); |
445 | 465 |
446 // Use the default port if the port string is empty. GURL returns an empty | 466 // Use the default port if the port string is empty. GURL returns an empty |
447 // string if no port at all was specified or if the default port was | 467 // string if no port at all was specified or if the default port was |
448 // specified. | 468 // specified. |
449 if (port.empty()) { | 469 if (port.empty()) { |
450 port = GetDefaultPort(scheme); | 470 port = GetDefaultPort(scheme); |
451 } | 471 } |
452 | 472 |
453 if (!parts_.is_port_wildcard && | 473 if (!parts_.is_port_wildcard && |
454 parts_.port != port ) { | 474 parts_.port != port ) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 655 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
636 return ContentSettingsPattern::PREDECESSOR; | 656 return ContentSettingsPattern::PREDECESSOR; |
637 | 657 |
638 int result = parts.port.compare(other_parts.port); | 658 int result = parts.port.compare(other_parts.port); |
639 if (result == 0) | 659 if (result == 0) |
640 return ContentSettingsPattern::IDENTITY; | 660 return ContentSettingsPattern::IDENTITY; |
641 if (result > 0) | 661 if (result > 0) |
642 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 662 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
643 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 663 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
644 } | 664 } |
OLD | NEW |