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

Unified Diff: content/browser/host_zoom_map_impl.cc

Issue 1804023002: Fix page zoom to be frame-centric for out-of-process frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments, exclude part of test since not supported on Android. Created 4 years, 8 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: content/browser/host_zoom_map_impl.cc
diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc
index cda61f938b931d1f515cfdb1ec174683579efed3..1ed7bd881cec568d03c9eeefed6e7546e4c0825a 100644
--- a/content/browser/host_zoom_map_impl.cc
+++ b/content/browser/host_zoom_map_impl.cc
@@ -278,7 +278,66 @@ double HostZoomMapImpl::GetDefaultZoomLevel() const {
void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ if (ZoomValuesEqual(level, default_zoom_level_))
+ return;
+
default_zoom_level_ = level;
+
+ // First, remove all entries that match the new default zoom level.
+ {
+ base::AutoLock auto_lock(lock_);
+ for (auto it = host_zoom_levels_.begin(); it != host_zoom_levels_.end(); ) {
+ if (ZoomValuesEqual(it->second, default_zoom_level_))
+ it = host_zoom_levels_.erase(it);
+ else
+ it++;
+ }
+ }
+
+ // Second, update zoom levels for all pages that do not have an overriding
+ // entry.
+ for (auto web_contents : WebContentsImpl::GetAllWebContents()) {
+ if (GetForWebContents(web_contents) != this)
+ continue;
+
+ int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+ int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+
+ // Get the url from the navigation controller directly, as calling
+ // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that
+ // is different than the one stored in the map.
+ GURL url;
+ std::string host;
+ std::string scheme;
+
+ NavigationEntry* entry =
+ web_contents->GetController().GetLastCommittedEntry();
+ // It is possible for a WebContent's zoom level to be queried before
+ // a navigation has occurred.
+ if (entry) {
+ url = GetURLFromEntry(entry);
+ scheme = url.scheme();
+ host = net::GetHostOrSpecFromURL(url);
+ }
+
+ bool uses_default_zoom =
+ !HasZoomLevel(scheme, host) &&
+ !UsesTemporaryZoomLevel(render_process_id, render_view_id);
+
+ // Only change zoom for WebContents tied to the StoragePartition this
+ // HostZoomMap serves.
alexmos 2016/04/27 23:39:51 Should this comment be moved up to the "GetForWebC
wjmaclean 2016/04/28 13:20:11 Done.
+ if (uses_default_zoom) {
+ web_contents->UpdateZoom(level);
+
+ HostZoomMap::ZoomLevelChange change;
+ change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST;
+ change.host = host;
+ change.zoom_level = level;
+
+ zoom_level_changed_callbacks_.Notify(change);
+ }
+ }
}
std::unique_ptr<HostZoomMap::Subscription>
@@ -405,9 +464,10 @@ void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id,
temporary_zoom_levels_[key] = level;
}
- RenderViewHost* host =
- RenderViewHost::FromID(render_process_id, render_view_id);
- host->Send(new ViewMsg_SetZoomLevelForView(render_view_id, true, level));
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
+ RenderViewHost::FromID(render_process_id, render_view_id)));
+ web_contents->SetTemporaryZoomLevel(level, true);
HostZoomMap::ZoomLevelChange change;
change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM;
@@ -457,30 +517,31 @@ void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id,
return;
temporary_zoom_levels_.erase(it);
}
- RenderViewHost* host =
- RenderViewHost::FromID(render_process_id, render_view_id);
- DCHECK(host);
- // Send a new zoom level, host-specific if one exists.
- host->Send(new ViewMsg_SetZoomLevelForView(
- render_view_id,
- false,
- GetZoomLevelForHost(
- GetHostFromProcessView(render_process_id, render_view_id))));
+ WebContentsImpl* web_contents =
+ static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(
+ RenderViewHost::FromID(render_process_id, render_view_id)));
+ web_contents->SetTemporaryZoomLevel(GetZoomLevelForHost(
+ GetHostFromProcessView(render_process_id, render_view_id)), false);
}
void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme,
const std::string& host,
double level) {
- for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
- !i.IsAtEnd(); i.Advance()) {
- RenderProcessHost* render_process_host = i.GetCurrentValue();
- // TODO(wjmaclean) This will need to be cleaned up when
- // RenderProcessHost::GetStoragePartition() goes away. Perhaps have
- // RenderProcessHost expose a GetHostZoomMap() function?
- if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) {
- render_process_host->Send(
- new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level));
- }
+ // We'll only send to WebContents not using temporary zoom levels. The one
+ // other case of interest is where the renderer is hosting a plugin document;
+ // that should be reflected in our temporary zoom level map, but we will
+ // double check on the renderer side to avoid the possibility of any races.
+ for (auto web_contents : WebContentsImpl::GetAllWebContents()) {
+ if (GetForWebContents(web_contents) != this)
+ continue;
+
+ // Only send zoom level changes to WebContents that are using this
+ // HostZoomMap.
alexmos 2016/04/27 23:39:51 Should this comment also be on the GetForWebConten
wjmaclean 2016/04/28 13:20:11 Done.
+ int render_process_id = web_contents->GetRenderProcessHost()->GetID();
+ int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID();
+
+ if (!UsesTemporaryZoomLevel(render_process_id, render_view_id))
+ web_contents->UpdateZoomIfNecessary(scheme, host, level);
}
}

Powered by Google App Engine
This is Rietveld 408576698