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

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

Issue 7811006: Add full support for filesystem URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace code deleted in botched merge. Created 8 years, 9 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
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/string_split.h" 10 #include "base/string_split.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 bool validate) { 308 bool validate) {
309 return new Builder(validate); 309 return new Builder(validate);
310 } 310 }
311 311
312 // static 312 // static
313 ContentSettingsPattern ContentSettingsPattern::FromURL( 313 ContentSettingsPattern ContentSettingsPattern::FromURL(
314 const GURL& url) { 314 const GURL& url) {
315 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( 315 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
316 ContentSettingsPattern::CreateBuilder(false)); 316 ContentSettingsPattern::CreateBuilder(false));
317 317
318 if (url.SchemeIsFile()) { 318 const GURL* local_url = &url;
319 builder->WithScheme(url.scheme())->WithPath(url.path()); 319 if (url.SchemeIsFileSystem() && url.inner_url()) {
320 local_url = url.inner_url();
321 }
322 if (local_url->SchemeIsFile()) {
323 builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
320 } else { 324 } else {
321 // Please keep the order of the ifs below as URLs with an IP as host can 325 // Please keep the order of the ifs below as URLs with an IP as host can
322 // also have a "http" scheme. 326 // also have a "http" scheme.
323 if (url.HostIsIPAddress()) { 327 if (local_url->HostIsIPAddress()) {
324 builder->WithScheme(url.scheme())->WithHost(url.host()); 328 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
325 } else if (url.SchemeIs(chrome::kHttpScheme)) { 329 } else if (local_url->SchemeIs(chrome::kHttpScheme)) {
326 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(url.host()); 330 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(
327 } else if (url.SchemeIs(chrome::kHttpsScheme)) { 331 local_url->host());
328 builder->WithScheme(url.scheme())->WithDomainWildcard()->WithHost( 332 } else if (local_url->SchemeIs(chrome::kHttpsScheme)) {
329 url.host()); 333 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost(
334 local_url->host());
330 } else { 335 } else {
331 // Unsupported scheme 336 // Unsupported scheme
332 } 337 }
333 if (url.port().empty()) { 338 if (local_url->port().empty()) {
334 if (url.SchemeIs(chrome::kHttpsScheme)) 339 if (local_url->SchemeIs(chrome::kHttpsScheme))
335 builder->WithPort(GetDefaultPort(chrome::kHttpsScheme)); 340 builder->WithPort(GetDefaultPort(chrome::kHttpsScheme));
336 else 341 else
337 builder->WithPortWildcard(); 342 builder->WithPortWildcard();
338 } else { 343 } else {
339 builder->WithPort(url.port()); 344 builder->WithPort(local_url->port());
340 } 345 }
341 } 346 }
342 return builder->Build(); 347 return builder->Build();
343 } 348 }
344 349
345 // static 350 // static
346 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( 351 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard(
347 const GURL& url) { 352 const GURL& url) {
348 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( 353 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
349 ContentSettingsPattern::CreateBuilder(false)); 354 ContentSettingsPattern::CreateBuilder(false));
350 355
351 if (url.SchemeIsFile()) { 356 const GURL* local_url = &url;
352 builder->WithScheme(url.scheme())->WithPath(url.path()); 357 if (url.SchemeIsFileSystem() && url.inner_url()) {
358 local_url = url.inner_url();
359 }
360 if (local_url->SchemeIsFile()) {
361 builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
353 } else { 362 } else {
354 builder->WithScheme(url.scheme())->WithHost(url.host()); 363 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
355 if (url.port().empty()) { 364 if (local_url->port().empty()) {
356 builder->WithPort(GetDefaultPort(url.scheme())); 365 builder->WithPort(GetDefaultPort(local_url->scheme()));
357 } else { 366 } else {
358 builder->WithPort(url.port()); 367 builder->WithPort(local_url->port());
359 } 368 }
360 } 369 }
361 return builder->Build(); 370 return builder->Build();
362 } 371 }
363 372
364 // static 373 // static
365 ContentSettingsPattern ContentSettingsPattern::FromString( 374 ContentSettingsPattern ContentSettingsPattern::FromString(
366 const std::string& pattern_spec) { 375 const std::string& pattern_spec) {
367 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( 376 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
368 ContentSettingsPattern::CreateBuilder(false)); 377 ContentSettingsPattern::CreateBuilder(false));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 return IPC::ReadParam(m, iter, &is_valid_) && 418 return IPC::ReadParam(m, iter, &is_valid_) &&
410 IPC::ReadParam(m, iter, &parts_); 419 IPC::ReadParam(m, iter, &parts_);
411 } 420 }
412 421
413 bool ContentSettingsPattern::Matches( 422 bool ContentSettingsPattern::Matches(
414 const GURL& url) const { 423 const GURL& url) const {
415 // An invalid pattern matches nothing. 424 // An invalid pattern matches nothing.
416 if (!is_valid_) 425 if (!is_valid_)
417 return false; 426 return false;
418 427
428 const GURL* local_url = &url;
429 if (url.SchemeIsFileSystem() && url.inner_url()) {
430 local_url = url.inner_url();
431 }
432
419 // Match the scheme part. 433 // Match the scheme part.
420 const std::string scheme(url.scheme()); 434 const std::string scheme(local_url->scheme());
421 if (!parts_.is_scheme_wildcard && 435 if (!parts_.is_scheme_wildcard &&
422 parts_.scheme != scheme) { 436 parts_.scheme != scheme) {
423 return false; 437 return false;
424 } 438 }
425 439
426 // File URLs have no host. Matches if the pattern has the path wildcard set, 440 // File URLs have no host. Matches if the pattern has the path wildcard set,
427 // or if the path in the URL is identical to the one in the pattern. 441 // or if the path in the URL is identical to the one in the pattern.
442 // For filesystem:file URLs, the path used is the filesystem type, so all
443 // filesystem:file:///temporary/... are equivalent.
markusheintz_ 2012/02/28 23:20:09 Please add a TODO for me here: TODO(markusheintz):
ericu 2012/02/28 23:27:15 Done, thanks.
428 if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme) 444 if (!parts_.is_scheme_wildcard && scheme == chrome::kFileScheme)
429 return parts_.is_path_wildcard || parts_.path == std::string(url.path()); 445 return parts_.is_path_wildcard ||
446 parts_.path == std::string(local_url->path());
430 447
431 // Match the host part. 448 // Match the host part.
432 const std::string host(net::TrimEndingDot(url.host())); 449 const std::string host(net::TrimEndingDot(local_url->host()));
433 if (!parts_.has_domain_wildcard) { 450 if (!parts_.has_domain_wildcard) {
434 if (parts_.host != host) 451 if (parts_.host != host)
435 return false; 452 return false;
436 } else { 453 } else {
437 if (!IsSubDomainOrEqual(host, parts_.host)) 454 if (!IsSubDomainOrEqual(host, parts_.host))
438 return false; 455 return false;
439 } 456 }
440 457
441 // For chrome extensions URLs ignore the port. 458 // For chrome extensions URLs ignore the port.
442 if (parts_.scheme == std::string(chrome::kExtensionScheme)) 459 if (parts_.scheme == std::string(chrome::kExtensionScheme))
443 return true; 460 return true;
444 461
445 // Match the port part. 462 // Match the port part.
446 std::string port(url.port()); 463 std::string port(local_url->port());
447 464
448 // Use the default port if the port string is empty. GURL returns an empty 465 // Use the default port if the port string is empty. GURL returns an empty
449 // string if no port at all was specified or if the default port was 466 // string if no port at all was specified or if the default port was
450 // specified. 467 // specified.
451 if (port.empty()) { 468 if (port.empty()) {
452 port = GetDefaultPort(scheme); 469 port = GetDefaultPort(scheme);
453 } 470 }
454 471
455 if (!parts_.is_port_wildcard && 472 if (!parts_.is_port_wildcard &&
456 parts_.port != port ) { 473 parts_.port != port ) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) 654 if (!parts.is_port_wildcard && other_parts.is_port_wildcard)
638 return ContentSettingsPattern::PREDECESSOR; 655 return ContentSettingsPattern::PREDECESSOR;
639 656
640 int result = parts.port.compare(other_parts.port); 657 int result = parts.port.compare(other_parts.port);
641 if (result == 0) 658 if (result == 0)
642 return ContentSettingsPattern::IDENTITY; 659 return ContentSettingsPattern::IDENTITY;
643 if (result > 0) 660 if (result > 0)
644 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 661 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
645 return ContentSettingsPattern::DISJOINT_ORDER_POST; 662 return ContentSettingsPattern::DISJOINT_ORDER_POST;
646 } 663 }
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app.cc ('k') | chrome/common/content_settings_pattern_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698