summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 07:17:54 +0000
committerjochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 07:17:54 +0000
commit9d797f394f319b754ed91a981dab566d764d2c2e (patch)
treeaee695b1c2af9d540e3fe99d834de015f70665cf /net
parent97c9e77b34099c518f85571f6d36e178d7695b23 (diff)
downloadchromium_src-9d797f394f319b754ed91a981dab566d764d2c2e.zip
chromium_src-9d797f394f319b754ed91a981dab566d764d2c2e.tar.gz
chromium_src-9d797f394f319b754ed91a981dab566d764d2c2e.tar.bz2
Send content settings based on the URL to the renderer instead of just the host.
BUG=36025 TEST=manual Review URL: http://codereview.chromium.org/1744003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45424 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc7
-rw-r--r--net/base/net_util.h5
-rw-r--r--net/base/net_util_unittest.cc11
3 files changed, 20 insertions, 3 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index a66d27a..064de0d 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -53,6 +53,7 @@
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_canon.h"
#include "googleurl/src/url_parse.h"
+#include "net/base/dns_util.h"
#include "net/base/escape.h"
#include "net/base/net_module.h"
#if defined(OS_WIN)
@@ -1286,6 +1287,10 @@ void GetIdentityFromURL(const GURL& url,
flags, NULL));
}
+std::string GetHostOrSpecFromURL(const GURL& url) {
+ return url.has_host() ? net::TrimEndingDot(url.host()) : url.spec();
+}
+
void AppendFormattedHost(const GURL& url,
const std::wstring& languages,
std::wstring* output,
diff --git a/net/base/net_util.h b/net/base/net_util.h
index f614eb6..9251a4a 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -83,6 +83,9 @@ void GetIdentityFromURL(const GURL& url,
std::wstring* username,
std::wstring* password);
+// Returns either the host from |url|, or, if the host is empty, the full spec.
+std::string GetHostOrSpecFromURL(const GURL& url);
+
// Return the value of the HTTP response header with name 'name'. 'headers'
// should be in the format that URLRequest::GetResponseHeaders() returns.
// Returns the empty string if the header is not found.
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 833375c..0d10bb1 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -1631,3 +1631,12 @@ TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) {
EXPECT_EQ(i, net::explicitly_allowed_ports.size());
}
}
+
+TEST(NetUtilTest, GetHostOrSpecFromURL) {
+ EXPECT_EQ("example.com",
+ net::GetHostOrSpecFromURL(GURL("http://example.com/test")));
+ EXPECT_EQ("example.com",
+ net::GetHostOrSpecFromURL(GURL("http://example.com./test")));
+ EXPECT_EQ("file:///tmp/test.html",
+ net::GetHostOrSpecFromURL(GURL("file:///tmp/test.html")));
+}