summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/host_content_settings_map.cc12
-rw-r--r--chrome/browser/host_zoom_map.cc10
-rw-r--r--chrome/browser/host_zoom_map.h15
-rw-r--r--chrome/browser/host_zoom_map_unittest.cc45
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.cc11
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc14
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h4
-rw-r--r--chrome/common/render_messages_internal.h34
-rw-r--r--chrome/renderer/render_thread.cc19
-rw-r--r--chrome/renderer/render_thread.h2
-rw-r--r--chrome/renderer/render_view.cc33
-rw-r--r--chrome/renderer/render_view.h10
-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
15 files changed, 131 insertions, 101 deletions
diff --git a/chrome/browser/host_content_settings_map.cc b/chrome/browser/host_content_settings_map.cc
index dfcdfad..11a080e 100644
--- a/chrome/browser/host_content_settings_map.cc
+++ b/chrome/browser/host_content_settings_map.cc
@@ -28,6 +28,7 @@ namespace {
// - host (matches an exact hostname)
// - a.b.c.d (matches an exact IPv4 ip)
// - [a:b:c:d:e:f:g:h] (matches an exact IPv6 ip)
+// - file:///tmp/test.html (a complete URL without a host)
const int kContentSettingsPatternVersion = 1;
// The format of a domain wildcard.
@@ -36,17 +37,14 @@ const char kDomainWildcard[] = "[*.]";
// The length of kDomainWildcard (without the trailing '\0')
const size_t kDomainWildcardLength = arraysize(kDomainWildcard) - 1;
-// Returns the host part of an URL, or the spec, if no host is present.
-std::string HostFromURL(const GURL& url) {
- return url.has_host() ? net::TrimEndingDot(url.host()) : url.spec();
-}
} // namespace
// static
HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL(
const GURL& url) {
return Pattern(!url.has_host() || url.HostIsIPAddress() ?
- HostFromURL(url) : std::string(kDomainWildcard) + url.host());
+ net::GetHostOrSpecFromURL(url) :
+ std::string(kDomainWildcard) + url.host());
}
bool HostContentSettingsMap::Pattern::IsValid() const {
@@ -66,7 +64,7 @@ bool HostContentSettingsMap::Pattern::Matches(const GURL& url) const {
if (!IsValid())
return false;
- const std::string host(HostFromURL(url));
+ const std::string host(net::GetHostOrSpecFromURL(url));
if (pattern_.length() < kDomainWildcardLength ||
!StartsWithASCII(pattern_, kDomainWildcard, false))
return pattern_ == host;
@@ -227,7 +225,7 @@ ContentSettings HostContentSettingsMap::GetContentSettings(
AutoLock auto_lock(lock_);
- const std::string host(HostFromURL(url));
+ const std::string host(net::GetHostOrSpecFromURL(url));
// Check for exact matches first.
HostContentSettings::const_iterator i(host_content_settings_.find(host));
diff --git a/chrome/browser/host_zoom_map.cc b/chrome/browser/host_zoom_map.cc
index f83d6f6..c646b0d 100644
--- a/chrome/browser/host_zoom_map.cc
+++ b/chrome/browser/host_zoom_map.cc
@@ -13,6 +13,8 @@
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
+#include "googleurl/src/gurl.h"
+#include "net/base/net_util.h"
HostZoomMap::HostZoomMap(Profile* profile)
: profile_(profile),
@@ -50,19 +52,19 @@ void HostZoomMap::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterDictionaryPref(prefs::kPerHostZoomLevels);
}
-int HostZoomMap::GetZoomLevel(const std::string& host) const {
+int HostZoomMap::GetZoomLevel(const GURL& url) const {
+ std::string host(net::GetHostOrSpecFromURL(url));
AutoLock auto_lock(lock_);
HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
return (i == host_zoom_levels_.end()) ? 0 : i->second;
}
-void HostZoomMap::SetZoomLevel(const std::string& host, int level) {
+void HostZoomMap::SetZoomLevel(const GURL& url, int level) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
if (!profile_)
return;
- if (host.empty())
- return;
+ std::string host(net::GetHostOrSpecFromURL(url));
{
AutoLock auto_lock(lock_);
diff --git a/chrome/browser/host_zoom_map.h b/chrome/browser/host_zoom_map.h
index 87dee2c..648162c 100644
--- a/chrome/browser/host_zoom_map.h
+++ b/chrome/browser/host_zoom_map.h
@@ -17,6 +17,7 @@
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
+class GURL;
class PrefService;
class Profile;
@@ -27,19 +28,21 @@ class HostZoomMap : public NotificationObserver,
static void RegisterUserPrefs(PrefService* prefs);
- // Returns the zoom level for a given hostname. In most cases, there is no
- // custom zoom level, and this returns 0. Otherwise, returns the saved zoom
- // level, which may be positive (to zoom in) or negative (to zoom out).
+ // Returns the zoom level for a given url. The zoom level is determined by
+ // the host portion of the URL, or (in the absence of a host) the complete
+ // spec of the URL. In most cases, there is no custom zoom level, and this
+ // returns 0. Otherwise, returns the saved zoom level, which may be positive
+ // (to zoom in) or negative (to zoom out).
//
// This may be called on any thread.
- int GetZoomLevel(const std::string& host) const;
+ int GetZoomLevel(const GURL& url) const;
- // Sets the zoom level for a given hostname to |level|. If the level is 0,
+ // Sets the zoom level for a given url to |level|. If the level is 0,
// the host is erased from the saved preferences; otherwise the new value is
// written out.
//
// This should only be called on the UI thread.
- void SetZoomLevel(const std::string& host, int level);
+ void SetZoomLevel(const GURL& url, int level);
// Resets all zoom levels.
//
diff --git a/chrome/browser/host_zoom_map_unittest.cc b/chrome/browser/host_zoom_map_unittest.cc
index fb7b52d..a59a142 100644
--- a/chrome/browser/host_zoom_map_unittest.cc
+++ b/chrome/browser/host_zoom_map_unittest.cc
@@ -16,6 +16,7 @@
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/testing_profile.h"
+#include "googleurl/src/gurl.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -30,7 +31,8 @@ class HostZoomMapTest : public testing::Test {
: ui_thread_(ChromeThread::UI, &message_loop_),
prefs_(profile_.GetPrefs()),
per_host_zoom_levels_pref_(prefs::kPerHostZoomLevels),
- host_name_("http://example/com/") {}
+ url_("http://example.com/test"),
+ host_("example.com") {}
protected:
void SetPrefObserverExpectation() {
@@ -47,64 +49,75 @@ class HostZoomMapTest : public testing::Test {
TestingProfile profile_;
PrefService* prefs_;
std::wstring per_host_zoom_levels_pref_; // For the observe matcher.
- std::string host_name_;
+ GURL url_;
+ std::string host_;
NotificationObserverMock pref_observer_;
};
const int HostZoomMapTest::kZoomLevel = 42;
TEST_F(HostZoomMapTest, LoadNoPrefs) {
scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
- EXPECT_EQ(0, map->GetZoomLevel(host_name_));
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
}
TEST_F(HostZoomMapTest, Load) {
DictionaryValue* dict =
prefs_->GetMutableDictionary(prefs::kPerHostZoomLevels);
- dict->SetWithoutPathExpansion(UTF8ToWide(host_name_),
+ dict->SetWithoutPathExpansion(UTF8ToWide(host_),
Value::CreateIntegerValue(kZoomLevel));
scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
- EXPECT_EQ(kZoomLevel, map->GetZoomLevel(host_name_));
+ EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
}
TEST_F(HostZoomMapTest, SetZoomLevel) {
scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
prefs_->AddPrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
SetPrefObserverExpectation();
- map->SetZoomLevel(host_name_, kZoomLevel);
- EXPECT_EQ(kZoomLevel, map->GetZoomLevel(host_name_));
+ map->SetZoomLevel(url_, kZoomLevel);
+ EXPECT_EQ(kZoomLevel, map->GetZoomLevel(url_));
const DictionaryValue* dict =
prefs_->GetDictionary(prefs::kPerHostZoomLevels);
int zoom_level = 0;
- EXPECT_TRUE(dict->GetIntegerWithoutPathExpansion(UTF8ToWide(host_name_),
+ EXPECT_TRUE(dict->GetIntegerWithoutPathExpansion(UTF8ToWide(host_),
&zoom_level));
EXPECT_EQ(kZoomLevel, zoom_level);
SetPrefObserverExpectation();
- map->SetZoomLevel(host_name_, 0);
- EXPECT_EQ(0, map->GetZoomLevel(host_name_));
- EXPECT_FALSE(dict->HasKey(UTF8ToWide(host_name_)));
+ map->SetZoomLevel(url_, 0);
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
+ EXPECT_FALSE(dict->HasKey(UTF8ToWide(host_)));
prefs_->RemovePrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
}
TEST_F(HostZoomMapTest, ResetToDefaults) {
scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
- map->SetZoomLevel(host_name_, kZoomLevel);
+ map->SetZoomLevel(url_, kZoomLevel);
prefs_->AddPrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
SetPrefObserverExpectation();
map->ResetToDefaults();
- EXPECT_EQ(0, map->GetZoomLevel(host_name_));
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
EXPECT_EQ(NULL, prefs_->GetDictionary(prefs::kPerHostZoomLevels));
prefs_->RemovePrefObserver(prefs::kPerHostZoomLevels, &pref_observer_);
}
TEST_F(HostZoomMapTest, ReloadOnPrefChange) {
scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
- map->SetZoomLevel(host_name_, kZoomLevel);
+ map->SetZoomLevel(url_, kZoomLevel);
DictionaryValue dict;
- dict.SetWithoutPathExpansion(UTF8ToWide(host_name_),
+ dict.SetWithoutPathExpansion(UTF8ToWide(host_),
Value::CreateIntegerValue(0));
prefs_->Set(prefs::kPerHostZoomLevels, dict);
- EXPECT_EQ(0, map->GetZoomLevel(host_name_));
+ EXPECT_EQ(0, map->GetZoomLevel(url_));
+}
+
+TEST_F(HostZoomMapTest, NoHost) {
+ scoped_refptr<HostZoomMap> map(new HostZoomMap(&profile_));
+ GURL file_url1_("file:///tmp/test.html");
+ GURL file_url2_("file:///tmp/other.html");
+ map->SetZoomLevel(file_url1_, kZoomLevel);
+
+ EXPECT_EQ(kZoomLevel, map->GetZoomLevel(file_url1_));
+ EXPECT_EQ(0, map->GetZoomLevel(file_url2_));
}
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc
index 4cc35bb..a4a3494 100644
--- a/chrome/browser/renderer_host/async_resource_handler.cc
+++ b/chrome/browser/renderer_host/async_resource_handler.cc
@@ -110,16 +110,15 @@ bool AsyncResourceHandler::OnResponseStarted(int request_id,
ResourceDispatcherHostRequestInfo* info = rdh_->InfoForRequest(request);
if (info->resource_type() == ResourceType::MAIN_FRAME) {
GURL request_url(request->url());
- std::string host(request_url.host());
ChromeURLRequestContext* context =
static_cast<ChromeURLRequestContext*>(request->context());
- if (!host.empty() && context) {
- receiver_->Send(new ViewMsg_SetContentSettingsForLoadingHost(
- info->route_id(), host,
+ if (context) {
+ receiver_->Send(new ViewMsg_SetContentSettingsForLoadingURL(
+ info->route_id(), request_url,
context->host_content_settings_map()->GetContentSettings(
request_url)));
- receiver_->Send(new ViewMsg_SetZoomLevelForLoadingHost(info->route_id(),
- host, context->host_zoom_map()->GetZoomLevel(host)));
+ receiver_->Send(new ViewMsg_SetZoomLevelForLoadingURL(info->route_id(),
+ request_url, context->host_zoom_map()->GetZoomLevel(request_url)));
}
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 6119c18..7ef3f8e 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -514,7 +514,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) {
#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats)
IPC_MESSAGE_HANDLER(ViewHostMsg_V8HeapStats, OnV8HeapStats)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomHost, OnDidZoomHost)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings,
OnGetDefaultPrintSettings)
@@ -1039,26 +1039,26 @@ void ResourceMessageFilter::OnV8HeapStatsOnUIThread(
static_cast<size_t>(v8_memory_used));
}
-void ResourceMessageFilter::OnDidZoomHost(const std::string& host,
- int zoom_level) {
+void ResourceMessageFilter::OnDidZoomURL(const GURL& url,
+ int zoom_level) {
ChromeThread::PostTask(ChromeThread::UI, FROM_HERE,
NewRunnableMethod(this,
&ResourceMessageFilter::UpdateHostZoomLevelsOnUIThread,
- host, zoom_level));
+ url, zoom_level));
}
void ResourceMessageFilter::UpdateHostZoomLevelsOnUIThread(
- const std::string& host,
+ const GURL& url,
int zoom_level) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
- host_zoom_map_->SetZoomLevel(host, zoom_level);
+ host_zoom_map_->SetZoomLevel(url, zoom_level);
// Notify renderers.
for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
RenderProcessHost* render_process_host = i.GetCurrentValue();
render_process_host->Send(
- new ViewMsg_SetZoomLevelForCurrentHost(host, zoom_level));
+ new ViewMsg_SetZoomLevelForCurrentURL(url, zoom_level));
}
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 549110a..5013257 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -269,8 +269,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
int v8_memory_used,
base::ProcessId renderer_id);
- void OnDidZoomHost(const std::string& host, int zoom_level);
- void UpdateHostZoomLevelsOnUIThread(const std::string& host, int zoom_level);
+ void OnDidZoomURL(const GURL& url, int zoom_level);
+ void UpdateHostZoomLevelsOnUIThread(const GURL& url, int zoom_level);
void OnResolveProxy(const GURL& url, IPC::Message* reply_msg);
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 4d2b185..2396360 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -345,29 +345,29 @@ IPC_BEGIN_MESSAGES(View)
IPC_MESSAGE_ROUTED0(ViewMsg_SetupDevToolsClient)
// Change the zoom level for the current main frame. If the level actually
- // changes, a ViewHostMsg_DidZoomHost message will be sent back to the browser
- // telling it what host got zoomed and what its current zoom level is.
+ // changes, a ViewHostMsg_DidZoomURL message will be sent back to the browser
+ // telling it what url got zoomed and what its current zoom level is.
IPC_MESSAGE_ROUTED1(ViewMsg_Zoom,
PageZoom::Function /* function */)
- // Set the zoom level for a particular hostname that the renderer is in the
+ // Set the zoom level for a particular url that the renderer is in the
// process of loading. This will be stored, to be used if the load commits
// and ignored otherwise.
- IPC_MESSAGE_ROUTED2(ViewMsg_SetZoomLevelForLoadingHost,
- std::string /* host */,
+ IPC_MESSAGE_ROUTED2(ViewMsg_SetZoomLevelForLoadingURL,
+ GURL /* url */,
int /* zoom_level */)
- // Set the zoom level for a particular hostname, so all render views
- // displaying this host can update their zoom levels to match.
- IPC_MESSAGE_CONTROL2(ViewMsg_SetZoomLevelForCurrentHost,
- std::string /* host */,
+ // Set the zoom level for a particular url, so all render views
+ // displaying this url can update their zoom levels to match.
+ IPC_MESSAGE_CONTROL2(ViewMsg_SetZoomLevelForCurrentURL,
+ GURL /* url */,
int /* zoom_level */)
- // Set the content settings for a particular hostname that the renderer is in
- // the process of loading. This will be stored, to be used if the load
- // commits and ignored otherwise.
- IPC_MESSAGE_ROUTED2(ViewMsg_SetContentSettingsForLoadingHost,
- std::string /* host */,
+ // Set the content settings for a particular url that the renderer is in the
+ // process of loading. This will be stored, to be used if the load commits
+ // and ignored otherwise.
+ IPC_MESSAGE_ROUTED2(ViewMsg_SetContentSettingsForLoadingURL,
+ GURL /* url */,
ContentSettings /* content_settings */)
// Set the content settings for a particular url, so all render views
@@ -1682,10 +1682,10 @@ IPC_BEGIN_MESSAGES(ViewHost)
IPC_MESSAGE_ROUTED1(ViewHostMsg_UploadProgress_ACK,
int /* request_id */)
- // Sent when the renderer changes the zoom level for a particular host, so the
+ // Sent when the renderer changes the zoom level for a particular url, so the
// browser can update its records.
- IPC_MESSAGE_CONTROL2(ViewHostMsg_DidZoomHost,
- std::string /* host */,
+ IPC_MESSAGE_CONTROL2(ViewHostMsg_DidZoomURL,
+ GURL /* url */,
int /* zoom_level */)
#if defined(OS_WIN)
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index b7fb2af..ce746e4 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -61,6 +61,7 @@
#include "chrome/renderer/user_script_slave.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_platform_file.h"
+#include "net/base/net_util.h"
#include "third_party/tcmalloc/chromium/src/google/malloc_extension.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
#include "third_party/WebKit/WebKit/chromium/public/WebColor.h"
@@ -171,14 +172,14 @@ class RenderViewContentSettingsSetter : public RenderViewVisitor {
class RenderViewZoomer : public RenderViewVisitor {
public:
- RenderViewZoomer(const std::string& host, int zoom_level)
- : host_(host),
- zoom_level_(zoom_level) {
+ RenderViewZoomer(const GURL& url, int zoom_level)
+ : zoom_level_(zoom_level) {
+ host_ = net::GetHostOrSpecFromURL(url);
}
virtual bool Visit(RenderView* render_view) {
WebView* webview = render_view->webview(); // Guaranteed non-NULL.
- if (GURL(webview->mainFrame()->url()).host() == host_)
+ if (net::GetHostOrSpecFromURL(GURL(webview->mainFrame()->url())) == host_)
webview->setZoomLevel(false, zoom_level_);
return true;
}
@@ -457,9 +458,9 @@ void RenderThread::OnSetContentSettingsForCurrentURL(
RenderView::ForEach(&setter);
}
-void RenderThread::OnSetZoomLevelForCurrentHost(const std::string& host,
- int zoom_level) {
- RenderViewZoomer zoomer(host, zoom_level);
+void RenderThread::OnSetZoomLevelForCurrentURL(const GURL& url,
+ int zoom_level) {
+ RenderViewZoomer zoomer(url, zoom_level);
RenderView::ForEach(&zoomer);
}
@@ -531,8 +532,8 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(ViewMsg_VisitedLink_Reset, OnResetVisitedLinks)
IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForCurrentURL,
OnSetContentSettingsForCurrentURL)
- IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentHost,
- OnSetZoomLevelForCurrentHost)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForCurrentURL,
+ OnSetZoomLevelForCurrentURL)
IPC_MESSAGE_HANDLER(ViewMsg_SetIsIncognitoProcess, OnSetIsIncognitoProcess)
IPC_MESSAGE_HANDLER(ViewMsg_SetNextPageID, OnSetNextPageID)
IPC_MESSAGE_HANDLER(ViewMsg_SetCSSColors, OnSetCSSColors)
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index ba5c849..680668c 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -209,7 +209,7 @@ class RenderThread : public RenderThreadBase,
void OnUpdateVisitedLinks(base::SharedMemoryHandle table);
void OnAddVisitedLinks(const VisitedLinkSlave::Fingerprints& fingerprints);
void OnResetVisitedLinks();
- void OnSetZoomLevelForCurrentHost(const std::string& host, int zoom_level);
+ void OnSetZoomLevelForCurrentURL(const GURL& url, int zoom_level);
void OnSetContentSettingsForCurrentURL(
const GURL& url, const ContentSettings& content_settings);
void OnUpdateUserScripts(base::SharedMemoryHandle table);
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 3364d16..9c3d1bd 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -594,10 +594,10 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
- IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingHost,
- OnSetContentSettingsForLoadingHost)
- IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingHost,
- OnSetZoomLevelForLoadingHost)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetContentSettingsForLoadingURL,
+ OnSetContentSettingsForLoadingURL)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
+ OnSetZoomLevelForLoadingURL)
IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
IPC_MESSAGE_HANDLER(ViewMsg_ResetPageEncodingToDefault,
OnResetPageEncodingToDefault)
@@ -1235,7 +1235,7 @@ void RenderView::UpdateURL(WebFrame* frame) {
// Set content settings. Default them from the parent window if one exists.
// This makes sure about:blank windows work as expected.
HostContentSettings::iterator host_content_settings =
- host_content_settings_.find(GURL(request.url()).host());
+ host_content_settings_.find(GURL(request.url()));
if (host_content_settings != host_content_settings_.end()) {
SetContentSettings(host_content_settings->second);
@@ -1251,7 +1251,7 @@ void RenderView::UpdateURL(WebFrame* frame) {
// Set zoom level.
HostZoomLevels::iterator host_zoom =
- host_zoom_levels_.find(GURL(request.url()).host());
+ host_zoom_levels_.find(GURL(request.url()));
if (host_zoom != host_zoom_levels_.end()) {
webview()->setZoomLevel(false, host_zoom->second);
// This zoom level was merely recorded transiently for this load. We can
@@ -3596,23 +3596,20 @@ void RenderView::OnZoom(PageZoom::Function function) {
int new_zoom_level = webview()->setZoomLevel(false,
(function == PageZoom::RESET) ? 0 : (zoom_level + function));
- // Tell the browser which host got zoomed so it can update the saved values.
- // Pages like the safe browsing interstitial can have empty hosts; don't
- // record those.
- std::string host(GURL(webview()->mainFrame()->url()).host());
- if (!host.empty())
- Send(new ViewHostMsg_DidZoomHost(host, new_zoom_level));
+ // Tell the browser which url got zoomed so it can update the saved values.
+ Send(new ViewHostMsg_DidZoomURL(
+ GURL(webview()->mainFrame()->url()), new_zoom_level));
}
-void RenderView::OnSetContentSettingsForLoadingHost(
- std::string host,
+void RenderView::OnSetContentSettingsForLoadingURL(
+ const GURL& url,
const ContentSettings& content_settings) {
- host_content_settings_[host] = content_settings;
+ host_content_settings_[url] = content_settings;
}
-void RenderView::OnSetZoomLevelForLoadingHost(std::string host,
- int zoom_level) {
- host_zoom_levels_[host] = zoom_level;
+void RenderView::OnSetZoomLevelForLoadingURL(const GURL& url,
+ int zoom_level) {
+ host_zoom_levels_[url] = zoom_level;
}
void RenderView::OnSetPageEncoding(const std::string& encoding_name) {
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 837c617..3a0b497 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -549,8 +549,8 @@ class RenderView : public RenderWidget,
#endif
FRIEND_TEST(RenderViewTest, JSBlockSentAfterPageLoad);
- typedef std::map<std::string, ContentSettings> HostContentSettings;
- typedef std::map<std::string, int> HostZoomLevels;
+ typedef std::map<GURL, ContentSettings> HostContentSettings;
+ typedef std::map<GURL, int> HostZoomLevels;
explicit RenderView(RenderThreadBase* render_thread,
const WebPreferences& webkit_preferences,
@@ -653,10 +653,10 @@ class RenderView : public RenderWidget,
void OnStopFinding(const ViewMsg_StopFinding_Params& params);
void OnFindReplyAck();
void OnDeterminePageLanguage();
- void OnSetContentSettingsForLoadingHost(
- std::string host, const ContentSettings& content_settings);
+ void OnSetContentSettingsForLoadingURL(
+ const GURL& url, const ContentSettings& content_settings);
void OnZoom(PageZoom::Function function);
- void OnSetZoomLevelForLoadingHost(std::string host, int zoom_level);
+ void OnSetZoomLevelForLoadingURL(const GURL& url, int zoom_level);
void OnSetPageEncoding(const std::string& encoding_name);
void OnResetPageEncodingToDefault();
void OnGetAllSavableResourceLinksForCurrentPage(const GURL& page_url);
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")));
+}