Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/host_zoom_map_impl.h" | 5 #include "content/browser/host_zoom_map_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 } | 214 } |
| 215 | 215 |
| 216 double HostZoomMapImpl::GetZoomLevelForWebContents( | 216 double HostZoomMapImpl::GetZoomLevelForWebContents( |
| 217 const WebContentsImpl& web_contents_impl) const { | 217 const WebContentsImpl& web_contents_impl) const { |
| 218 int render_process_id = web_contents_impl.GetRenderProcessHost()->GetID(); | 218 int render_process_id = web_contents_impl.GetRenderProcessHost()->GetID(); |
| 219 int routing_id = web_contents_impl.GetRenderViewHost()->GetRoutingID(); | 219 int routing_id = web_contents_impl.GetRenderViewHost()->GetRoutingID(); |
| 220 | 220 |
| 221 if (UsesTemporaryZoomLevel(render_process_id, routing_id)) | 221 if (UsesTemporaryZoomLevel(render_process_id, routing_id)) |
| 222 return GetTemporaryZoomLevel(render_process_id, routing_id); | 222 return GetTemporaryZoomLevel(render_process_id, routing_id); |
| 223 | 223 |
| 224 // Since zoom map is updated using the url as stored in the navigation | 224 // Get the url from the navigation controller directly, as calling |
| 225 // controller, we use that URL to get the zoom level. | 225 // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that |
| 226 // is different than is stored in the map. | |
| 226 GURL url; | 227 GURL url; |
| 227 NavigationEntry* entry = | 228 NavigationEntry* entry = |
| 228 web_contents_impl.GetController().GetLastCommittedEntry(); | 229 web_contents_impl.GetController().GetLastCommittedEntry(); |
| 230 // It is possible for a WebContent's zoom level to be queried before | |
| 231 // a navigation has occurred. | |
| 229 if (entry) | 232 if (entry) |
| 230 url = entry->GetURL(); | 233 url = entry->GetURL(); |
|
Peter Kasting
2014/06/04 20:03:40
Nit: You still have an extra space both here and i
| |
| 231 return GetZoomLevelForHostAndScheme(url.scheme(), | 234 return GetZoomLevelForHostAndScheme(url.scheme(), |
| 232 net::GetHostOrSpecFromURL(url)); | 235 net::GetHostOrSpecFromURL(url)); |
| 233 } | 236 } |
| 234 | 237 |
| 235 void HostZoomMapImpl::SetZoomLevelForWebContents( | 238 void HostZoomMapImpl::SetZoomLevelForWebContents( |
| 236 const WebContentsImpl& web_contents_impl, | 239 const WebContentsImpl& web_contents_impl, |
| 237 double level) { | 240 double level) { |
| 238 int render_process_id = web_contents_impl.GetRenderProcessHost()->GetID(); | 241 int render_process_id = web_contents_impl.GetRenderProcessHost()->GetID(); |
| 239 int render_view_id = web_contents_impl.GetRenderViewHost()->GetRoutingID(); | 242 int render_view_id = web_contents_impl.GetRenderViewHost()->GetRoutingID(); |
| 240 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) { | 243 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) { |
| 241 | |
| 242 SetTemporaryZoomLevel(render_process_id, render_view_id, level); | 244 SetTemporaryZoomLevel(render_process_id, render_view_id, level); |
| 243 } else { | 245 } else { |
| 244 SetZoomLevelForHost( | 246 // Get the url from the navigation controller directly, as calling |
| 245 net::GetHostOrSpecFromURL(web_contents_impl.GetLastCommittedURL()), | 247 // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that |
| 246 level); | 248 // is different than what the render view is using. If the two don't match, |
| 249 // the attempt to set the zoom will fail. | |
| 250 GURL url; | |
| 251 NavigationEntry* entry = | |
| 252 web_contents_impl.GetController().GetLastCommittedEntry(); | |
| 253 DCHECK(entry); | |
| 254 url = entry->GetURL(); | |
| 255 SetZoomLevelForHost(net::GetHostOrSpecFromURL(url), level); | |
| 247 } | 256 } |
| 248 } | 257 } |
| 249 | 258 |
| 250 void HostZoomMapImpl::SetZoomLevelForView(int render_process_id, | 259 void HostZoomMapImpl::SetZoomLevelForView(int render_process_id, |
| 251 int render_view_id, | 260 int render_view_id, |
| 252 double level, | 261 double level, |
| 253 const std::string& host) { | 262 const std::string& host) { |
| 254 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) | 263 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) |
| 255 SetTemporaryZoomLevel(render_process_id, render_view_id, level); | 264 SetTemporaryZoomLevel(render_process_id, render_view_id, level); |
| 256 else | 265 else |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 zoom_level(0.0) { | 384 zoom_level(0.0) { |
| 376 } | 385 } |
| 377 | 386 |
| 378 bool HostZoomMapImpl::TemporaryZoomLevel::operator==( | 387 bool HostZoomMapImpl::TemporaryZoomLevel::operator==( |
| 379 const TemporaryZoomLevel& other) const { | 388 const TemporaryZoomLevel& other) const { |
| 380 return other.render_process_id == render_process_id && | 389 return other.render_process_id == render_process_id && |
| 381 other.render_view_id == render_view_id; | 390 other.render_view_id == render_view_id; |
| 382 } | 391 } |
| 383 | 392 |
| 384 } // namespace content | 393 } // namespace content |
| OLD | NEW |