Commit c6249049 authored by wjmaclean's avatar wjmaclean Committed by Commit bot

Check temporary zoom status when sending zoom level in navigation.

This CL causes the AsyncResourceHandler code to check for temporary zoom
levels for the current view before sending the new zoom level during
navigation. This will allow tabs with per-tab scope zoom settings to
retain their current (temporary) zoom levels during same-origin
navigations.

Review URL: https://codereview.chromium.org/809223006

Cr-Commit-Position: refs/heads/master@{#316301}
parent 67fa17a0
......@@ -136,6 +136,11 @@ void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) {
double HostZoomMapImpl::GetZoomLevelForHost(const std::string& host) const {
base::AutoLock auto_lock(lock_);
return GetZoomLevelForHostInternal(host);
}
double HostZoomMapImpl::GetZoomLevelForHostInternal(
const std::string& host) const {
HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second;
}
......@@ -156,20 +161,25 @@ bool HostZoomMapImpl::HasZoomLevel(const std::string& scheme,
return i != zoom_levels.end();
}
double HostZoomMapImpl::GetZoomLevelForHostAndScheme(
double HostZoomMapImpl::GetZoomLevelForHostAndSchemeInternal(
const std::string& scheme,
const std::string& host) const {
{
base::AutoLock auto_lock(lock_);
SchemeHostZoomLevels::const_iterator scheme_iterator(
scheme_host_zoom_levels_.find(scheme));
if (scheme_iterator != scheme_host_zoom_levels_.end()) {
HostZoomLevels::const_iterator i(scheme_iterator->second.find(host));
if (i != scheme_iterator->second.end())
return i->second;
}
SchemeHostZoomLevels::const_iterator scheme_iterator(
scheme_host_zoom_levels_.find(scheme));
if (scheme_iterator != scheme_host_zoom_levels_.end()) {
HostZoomLevels::const_iterator i(scheme_iterator->second.find(host));
if (i != scheme_iterator->second.end())
return i->second;
}
return GetZoomLevelForHost(host);
return GetZoomLevelForHostInternal(host);
}
double HostZoomMapImpl::GetZoomLevelForHostAndScheme(
const std::string& scheme,
const std::string& host) const {
base::AutoLock auto_lock(lock_);
return GetZoomLevelForHostAndSchemeInternal(scheme, host);
}
HostZoomMap::ZoomLevelVector HostZoomMapImpl::GetAllZoomLevels() const {
......@@ -365,6 +375,19 @@ void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id,
zoom_level_changed_callbacks_.Notify(change);
}
double HostZoomMapImpl::GetZoomLevelForView(const GURL& url,
int render_process_id,
int render_view_id) const {
RenderViewKey key(render_process_id, render_view_id);
base::AutoLock auto_lock(lock_);
if (ContainsKey(temporary_zoom_levels_, key))
return temporary_zoom_levels_.find(key)->second;
return GetZoomLevelForHostAndSchemeInternal(url.scheme(),
net::GetHostOrSpecFromURL(url));
}
void HostZoomMapImpl::Observe(int type,
const NotificationSource& source,
const NotificationDetails& details) {
......
......@@ -79,6 +79,14 @@ class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap),
double GetTemporaryZoomLevel(int render_process_id,
int render_view_id) const;
// Returns the zoom level regardless of whether it's temporary, host-keyed or
// scheme+host-keyed.
//
// This may be called on any thread.
double GetZoomLevelForView(const GURL& url,
int render_process_id,
int render_view_id) const;
// NotificationObserver implementation.
void Observe(int type,
const NotificationSource& source,
......@@ -107,6 +115,12 @@ class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap),
double GetZoomLevelForHost(const std::string& host) const;
// Non-locked versions for internal use. These should only be called within
// a scope where a lock has been acquired.
double GetZoomLevelForHostInternal(const std::string& host) const;
double GetZoomLevelForHostAndSchemeInternal(const std::string& scheme,
const std::string& host) const;
// Notifies the renderers from this browser context to change the zoom level
// for the specified host and scheme.
// TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
......
// Copyright 2015 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.
#include "content/browser/host_zoom_map_impl.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/content_browser_test.h"
#include "content/shell/browser/shell.h"
#include "url/gurl.h"
namespace content {
class HostZoomMapImplBrowserTest : public ContentBrowserTest {
};
void RunTestForURL(const GURL& url,
Shell* shell,
double host_zoom_level,
double temp_zoom_level) {
shell->LoadURL(url);
WebContents* web_contents = shell->web_contents();
HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
HostZoomMap::GetForWebContents(web_contents));
int view_id = web_contents->GetRoutingID();
int render_process_id = web_contents->GetRenderProcessHost()->GetID();
// Assume caller has set the zoom level to |host_zoom_level| using
// either a host or host+scheme entry in the HostZoomMap prior to
// calling this function.
EXPECT_DOUBLE_EQ(host_zoom_level, host_zoom_map->GetZoomLevelForView(
url, render_process_id, view_id));
// Make sure that GetZoomLevelForView() works for temporary zoom levels.
host_zoom_map->SetTemporaryZoomLevel(render_process_id, view_id,
temp_zoom_level);
EXPECT_DOUBLE_EQ(temp_zoom_level, host_zoom_map->GetZoomLevelForView(
url, render_process_id, view_id));
// Clear the temporary zoom level in case subsequent test calls use the same
// web_contents.
host_zoom_map->ClearTemporaryZoomLevel(render_process_id, view_id);
}
// Test to make sure that GetZoomForView() works properly for zoom levels
// stored by host value, and can distinguish temporary zoom levels from
// these.
IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest, GetZoomForView_Host) {
GURL url("http://abc.com");
HostZoomMap* host_zoom_map =
HostZoomMap::GetForWebContents(shell()->web_contents());
double default_zoom_level = host_zoom_map->GetDefaultZoomLevel();
double host_zoom_level = default_zoom_level + 1.0;
double temp_zoom_level = default_zoom_level + 2.0;
host_zoom_map->SetZoomLevelForHost(url.host(), host_zoom_level);
RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level);
}
// Test to make sure that GetZoomForView() works properly for zoom levels
// stored by host and scheme values, and can distinguish temporary zoom levels
// from these.
IN_PROC_BROWSER_TEST_F(HostZoomMapImplBrowserTest,
GetZoomForView_HostAndScheme) {
GURL url("http://abc.com");
HostZoomMap* host_zoom_map =
HostZoomMap::GetForWebContents(shell()->web_contents());
double default_zoom_level = host_zoom_map->GetDefaultZoomLevel();
double host_zoom_level = default_zoom_level + 1.0;
double temp_zoom_level = default_zoom_level + 2.0;
host_zoom_map->SetZoomLevelForHostAndScheme(url.scheme(), url.host(),
host_zoom_level);
RunTestForURL(url, shell(), host_zoom_level, temp_zoom_level);
}
} // namespace content
......@@ -193,15 +193,19 @@ bool AsyncResourceHandler::OnResponseStarted(ResourceResponse* response,
DevToolsNetLogObserver::PopulateResponseInfo(request(), response);
const HostZoomMap* host_zoom_map = info->filter()->GetHostZoomMap();
const HostZoomMapImpl* host_zoom_map =
static_cast<const HostZoomMapImpl*>(info->filter()->GetHostZoomMap());
if (info->GetResourceType() == RESOURCE_TYPE_MAIN_FRAME && host_zoom_map) {
const GURL& request_url = request()->url();
int render_process_id = info->GetChildID();
int render_view_id = info->GetRouteID();
double zoom_level = host_zoom_map->GetZoomLevelForView(
request_url, render_process_id, render_view_id);
info->filter()->Send(new ViewMsg_SetZoomLevelForLoadingURL(
info->GetRouteID(),
request_url, host_zoom_map->GetZoomLevelForHostAndScheme(
request_url.scheme(),
net::GetHostOrSpecFromURL(request_url))));
render_view_id, request_url, zoom_level));
}
// If the parent handler downloaded the resource to a file, grant the child
......
......@@ -209,6 +209,7 @@
'browser/frame_host/render_frame_host_impl_browsertest.cc',
'browser/frame_host/render_frame_host_manager_browsertest.cc',
'browser/gpu/gpu_ipc_browsertests.cc',
'browser/host_zoom_map_impl_browsertest.cc',
'browser/indexed_db/indexed_db_browsertest.cc',
'browser/indexed_db/mock_browsertest_indexed_db_class_factory.cc',
'browser/indexed_db/mock_browsertest_indexed_db_class_factory.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment