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

Unified 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: Merged out; haven't built yet. Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/content_settings_pattern.cc
diff --git a/chrome/common/content_settings_pattern.cc b/chrome/common/content_settings_pattern.cc
index 16ec56f00b10bd7c027f891a30eb6cfd7ac02e6c..e8fc1dbb894a08d9625b1bc10f25f271653405b9 100644
--- a/chrome/common/content_settings_pattern.cc
+++ b/chrome/common/content_settings_pattern.cc
@@ -303,28 +303,33 @@ ContentSettingsPattern ContentSettingsPattern::FromURL(
scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
ContentSettingsPattern::CreateBuilder(false));
- if (url.SchemeIsFile()) {
- builder->WithScheme(url.scheme())->WithPath(url.path());
+ const GURL* local_url = &url;
+ if (url.SchemeIsFileSystem() && url.inner_url()) {
+ local_url = url.inner_url();
+ }
+ if (local_url->SchemeIsFile()) {
+ builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
} else {
// Please keep the order of the ifs below as URLs with an IP as host can
// also have a "http" scheme.
- if (url.HostIsIPAddress()) {
- builder->WithScheme(url.scheme())->WithHost(url.host());
- } else if (url.SchemeIs(chrome::kHttpScheme)) {
- builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(url.host());
- } else if (url.SchemeIs(chrome::kHttpsScheme)) {
- builder->WithScheme(url.scheme())->WithDomainWildcard()->WithHost(
- url.host());
+ if (local_url->HostIsIPAddress()) {
+ builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
+ } else if (local_url->SchemeIs(chrome::kHttpScheme)) {
+ builder->WithSchemeWildcard()->WithDomainWildcard()->WithHost(
+ local_url->host());
+ } else if (local_url->SchemeIs(chrome::kHttpsScheme)) {
+ builder->WithScheme(local_url->scheme())->WithDomainWildcard()->WithHost(
+ local_url->host());
} else {
// Unsupported scheme
}
- if (url.port().empty()) {
- if (url.SchemeIs(chrome::kHttpsScheme))
+ if (local_url->port().empty()) {
+ if (local_url->SchemeIs(chrome::kHttpsScheme))
builder->WithPort(GetDefaultPort(chrome::kHttpsScheme));
else
builder->WithPortWildcard();
} else {
- builder->WithPort(url.port());
+ builder->WithPort(local_url->port());
}
}
return builder->Build();
@@ -336,14 +341,18 @@ ContentSettingsPattern ContentSettingsPattern::FromURLNoWildcard(
scoped_ptr<ContentSettingsPattern::BuilderInterface> builder(
ContentSettingsPattern::CreateBuilder(false));
- if (url.SchemeIsFile()) {
- builder->WithScheme(url.scheme())->WithPath(url.path());
+ const GURL* local_url = &url;
+ if (url.SchemeIsFileSystem() && url.inner_url()) {
+ local_url = url.inner_url();
+ }
+ if (local_url->SchemeIsFile()) {
+ builder->WithScheme(local_url->scheme())->WithPath(local_url->path());
} else {
- builder->WithScheme(url.scheme())->WithHost(url.host());
- if (url.port().empty()) {
- builder->WithPort(GetDefaultPort(url.scheme()));
+ builder->WithScheme(local_url->scheme())->WithHost(local_url->host());
+ if (local_url->port().empty()) {
+ builder->WithPort(GetDefaultPort(local_url->scheme()));
} else {
- builder->WithPort(url.port());
+ builder->WithPort(local_url->port());
}
}
return builder->Build();
@@ -403,8 +412,13 @@ bool ContentSettingsPattern::Matches(
if (!is_valid_)
return false;
+ const GURL* local_url = &url;
+ if (url.SchemeIsFileSystem() && url.inner_url()) {
+ local_url = url.inner_url();
+ }
+
// Match the scheme part.
- const std::string scheme(url.scheme());
+ const std::string scheme(local_url->scheme());
if (!parts_.is_scheme_wildcard &&
parts_.scheme != scheme) {
return false;
@@ -413,16 +427,18 @@ bool ContentSettingsPattern::Matches(
// File URLs have no host. For file URLs check if the url path matches the
// path in the pattern.
// TODO(markusheintz): This should change in the future. There should be only
- // one setting for all file URLs. So the path should be ignored.
+ // one setting for all file URLs. So the path should be ignored. It's wrong
+ // for filesystem:file URLs too--those paths are in different namespaces
+ // than those of file:// URLs.
if (!parts_.is_scheme_wildcard &&
scheme == std::string(chrome::kFileScheme)) {
- if (parts_.path == std::string(url.path()))
+ if (parts_.path == std::string(local_url->path()))
return true;
return false;
}
// Match the host part.
- const std::string host(net::TrimEndingDot(url.host()));
+ const std::string host(net::TrimEndingDot(local_url->host()));
if (!parts_.has_domain_wildcard) {
if (parts_.host != host)
return false;
@@ -436,7 +452,7 @@ bool ContentSettingsPattern::Matches(
return true;
// Match the port part.
- std::string port(url.port());
+ std::string port(local_url->port());
// Use the default port if the port string is empty. GURL returns an empty
// string if no port at all was specified or if the default port was

Powered by Google App Engine
This is Rietveld 408576698