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

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: Better content_settings_pattern.cc changes. Created 9 years 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 | « chrome/browser/web_applications/web_app.cc ('k') | chrome/common/extensions/url_pattern.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/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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 bool validate) { 296 bool validate) {
297 return new Builder(validate); 297 return new Builder(validate);
298 } 298 }
299 299
300 // static 300 // static
301 ContentSettingsPattern ContentSettingsPattern::FromURL( 301 ContentSettingsPattern ContentSettingsPattern::FromURL(
302 const GURL& url) { 302 const GURL& url) {
303 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( 303 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
304 ContentSettingsPattern::CreateBuilder(false)); 304 ContentSettingsPattern::CreateBuilder(false));
305 305
306 if (url.SchemeIsFile()) { 306 const GURL* local_url = &url;
307 builder->WithScheme(url.scheme())->WithPath(url.path()); 307 if (url.SchemeIsFileSystem() && url.inner_url()) {
308 local_url = url.inner_url();
309 }
310 if (local_url->SchemeIsFile()) {
311 builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
308 } else { 312 } else {
309 // Please keep the order of the ifs below as URLs with an IP as host can 313 // Please keep the order of the ifs below as URLs with an IP as host can
310 // also have a "http" scheme. 314 // also have a "http" scheme.
311 if (url.HostIsIPAddress()) { 315 if (local_url->HostIsIPAddress()) {
312 builder->WithScheme(url.scheme())->WithHost(url.host()); 316 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
313 } else if (url.SchemeIs(chrome::kHttpScheme)) { 317 } else if (local_url->SchemeIs(chrome::kHttpScheme)) {
314 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(url.host()); 318 builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(
315 } else if (url.SchemeIs(chrome::kHttpsScheme)) { 319 local_url->host());
316 builder->WithScheme(url.scheme())->WithDomainWildcard()->WithHost( 320 } else if (local_url->SchemeIs(chrome::kHttpsScheme)) {
317 url.host()); 321 builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost(
322 local_url->host());
318 } else { 323 } else {
319 // Unsupported scheme 324 // Unsupported scheme
320 } 325 }
321 if (url.port().empty()) { 326 if (local_url->port().empty()) {
322 if (url.SchemeIs(chrome::kHttpsScheme)) 327 if (local_url->SchemeIs(chrome::kHttpsScheme))
323 builder->WithPort(GetDefaultPort(chrome::kHttpsScheme)); 328 builder->WithPort(GetDefaultPort(chrome::kHttpsScheme));
324 else 329 else
325 builder->WithPortWildcard(); 330 builder->WithPortWildcard();
326 } else { 331 } else {
327 builder->WithPort(url.port()); 332 builder->WithPort(local_url->port());
328 } 333 }
329 } 334 }
330 return builder->Build(); 335 return builder->Build();
331 } 336 }
332 337
333 // static 338 // static
334 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard( 339 ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard(
335 const GURL& url) { 340 const GURL& url) {
336 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( 341 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
337 ContentSettingsPattern::CreateBuilder(false)); 342 ContentSettingsPattern::CreateBuilder(false));
338 343
339 if (url.SchemeIsFile()) { 344 const GURL* local_url = &url;
340 builder->WithScheme(url.scheme())->WithPath(url.path()); 345 if (url.SchemeIsFileSystem() && url.inner_url()) {
346 local_url = url.inner_url();
347 }
348 if (local_url->SchemeIsFile()) {
349 builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
341 } else { 350 } else {
342 builder->WithScheme(url.scheme())->WithHost(url.host()); 351 builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
343 if (url.port().empty()) { 352 if (local_url->port().empty()) {
344 builder->WithPort(GetDefaultPort(url.scheme())); 353 builder->WithPort(GetDefaultPort(local_url->scheme()));
345 } else { 354 } else {
346 builder->WithPort(url.port()); 355 builder->WithPort(local_url->port());
347 } 356 }
348 } 357 }
349 return builder->Build(); 358 return builder->Build();
350 } 359 }
351 360
352 // static 361 // static
353 ContentSettingsPattern ContentSettingsPattern::FromString( 362 ContentSettingsPattern ContentSettingsPattern::FromString(
354 const std::string& pattern_spec) { 363 const std::string& pattern_spec) {
355 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder( 364 scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
356 ContentSettingsPattern::CreateBuilder(false)); 365 ContentSettingsPattern::CreateBuilder(false));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 return IPC::ReadParam(m, iter, &is_valid_) && 405 return IPC::ReadParam(m, iter, &is_valid_) &&
397 IPC::ReadParam(m, iter, &parts_); 406 IPC::ReadParam(m, iter, &parts_);
398 } 407 }
399 408
400 bool ContentSettingsPattern::Matches( 409 bool ContentSettingsPattern::Matches(
401 const GURL& url) const { 410 const GURL& url) const {
402 // An invalid pattern matches nothing. 411 // An invalid pattern matches nothing.
403 if (!is_valid_) 412 if (!is_valid_)
404 return false; 413 return false;
405 414
415 const GURL* local_url = &url;
416 if (url.SchemeIsFileSystem() && url.inner_url()) {
417 local_url = url.inner_url();
418 }
419
406 // Match the scheme part. 420 // Match the scheme part.
407 const std::string scheme(url.scheme()); 421 const std::string scheme(local_url->scheme());
408 if (!parts_.is_scheme_wildcard && 422 if (!parts_.is_scheme_wildcard &&
409 parts_.scheme != scheme) { 423 parts_.scheme != scheme) {
410 return false; 424 return false;
411 } 425 }
412 426
413 // File URLs have no host. For file URLs check if the url path matches the 427 // File URLs have no host. For file URLs check if the url path matches the
414 // path in the pattern. 428 // path in the pattern.
415 // TODO(markusheintz): This should change in the future. There should be only 429 // TODO(markusheintz): This should change in the future. There should be only
416 // one setting for all file URLs. So the path should be ignored. 430 // one setting for all file URLs. So the path should be ignored. It's wrong
431 // for filesystem:file URLs too--those paths are in different namespaces
432 // than those of file:// URLs.
markusheintz_ 2011/12/21 10:36:44 I don't understand this comment. What exactly is w
417 if (!parts_.is_scheme_wildcard && 433 if (!parts_.is_scheme_wildcard &&
418 scheme == std::string(chrome::kFileScheme)) { 434 scheme == std::string(chrome::kFileScheme)) {
419 if (parts_.path == std::string(url.path())) 435 if (parts_.path == std::string(local_url->path()))
420 return true; 436 return true;
421 return false; 437 return false;
422 } 438 }
423 439
424 // Match the host part. 440 // Match the host part.
425 const std::string host(net::TrimEndingDot(url.host())); 441 const std::string host(net::TrimEndingDot(local_url->host()));
426 if (!parts_.has_domain_wildcard) { 442 if (!parts_.has_domain_wildcard) {
427 if (parts_.host != host) 443 if (parts_.host != host)
428 return false; 444 return false;
429 } else { 445 } else {
430 if (!IsSubDomainOrEqual(host, parts_.host)) 446 if (!IsSubDomainOrEqual(host, parts_.host))
431 return false; 447 return false;
432 } 448 }
433 449
434 // For chrome extensions URLs ignore the port. 450 // For chrome extensions URLs ignore the port.
435 if (parts_.scheme == std::string(chrome::kExtensionScheme)) 451 if (parts_.scheme == std::string(chrome::kExtensionScheme))
436 return true; 452 return true;
437 453
438 // Match the port part. 454 // Match the port part.
439 std::string port(url.port()); 455 std::string port(local_url->port());
440 456
441 // Use the default port if the port string is empty. GURL returns an empty 457 // Use the default port if the port string is empty. GURL returns an empty
442 // string if no port at all was specified or if the default port was 458 // string if no port at all was specified or if the default port was
443 // specified. 459 // specified.
444 if (port.empty()) { 460 if (port.empty()) {
445 port = GetDefaultPort(scheme); 461 port = GetDefaultPort(scheme);
446 } 462 }
447 463
448 if (!parts_.is_port_wildcard && 464 if (!parts_.is_port_wildcard &&
449 parts_.port != port ) { 465 parts_.port != port ) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) 646 if (!parts.is_port_wildcard && other_parts.is_port_wildcard)
631 return ContentSettingsPattern::PREDECESSOR; 647 return ContentSettingsPattern::PREDECESSOR;
632 648
633 int result = parts.port.compare(other_parts.port); 649 int result = parts.port.compare(other_parts.port);
634 if (result == 0) 650 if (result == 0)
635 return ContentSettingsPattern::IDENTITY; 651 return ContentSettingsPattern::IDENTITY;
636 if (result > 0) 652 if (result > 0)
637 return ContentSettingsPattern::DISJOINT_ORDER_PRE; 653 return ContentSettingsPattern::DISJOINT_ORDER_PRE;
638 return ContentSettingsPattern::DISJOINT_ORDER_POST; 654 return ContentSettingsPattern::DISJOINT_ORDER_POST;
639 } 655 }
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app.cc ('k') | chrome/common/extensions/url_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698