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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 zoom_level_changed_callbacks_.Notify(change); | 271 zoom_level_changed_callbacks_.Notify(change); |
272 } | 272 } |
273 | 273 |
274 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 274 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
276 return default_zoom_level_; | 276 return default_zoom_level_; |
277 } | 277 } |
278 | 278 |
279 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { | 279 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
280 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
281 | |
282 if (ZoomValuesEqual(level, default_zoom_level_)) | |
283 return; | |
284 | |
281 default_zoom_level_ = level; | 285 default_zoom_level_ = level; |
286 | |
287 // First, remove all entries that match the new default zoom level. | |
alexmos
2016/04/05 18:00:53
Does this need to be done for scheme_host_zoom_lev
wjmaclean
2016/04/05 20:21:59
In the old code-path this isn't done for scheme+ho
alexmos
2016/04/07 01:20:56
Where was this done in the old codepath? I saw th
wjmaclean
2016/04/07 12:55:36
As I mentioned before, the old codepath involved a
| |
288 { | |
289 base::AutoLock auto_lock(lock_); | |
290 for (auto it = host_zoom_levels_.begin(); it != host_zoom_levels_.end(); ) { | |
291 if (ZoomValuesEqual(it->second, default_zoom_level_)) | |
292 it = host_zoom_levels_.erase(it); | |
293 else | |
294 it++; | |
295 } | |
296 } | |
297 | |
298 // Second, update zoom levels for all pages that do not have an overriding | |
299 // entry. | |
300 for (auto web_contents : WebContentsImpl::GetAllWebContents()) { | |
301 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); | |
302 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); | |
303 | |
304 // Get the url from the navigation controller directly, as calling | |
305 // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that | |
306 // is different than is stored in the map. | |
alexmos
2016/04/05 18:00:53
nit: s/than is stored/than the one stored/
wjmaclean
2016/04/05 20:22:00
Done.
| |
307 GURL url; | |
308 NavigationEntry* entry = | |
309 web_contents->GetController().GetLastCommittedEntry(); | |
310 // It is possible for a WebContent's zoom level to be queried before | |
311 // a navigation has occurred. | |
312 if (entry) | |
313 url = GetURLFromEntry(entry); | |
314 | |
315 bool uses_default_zoom = | |
316 !HasZoomLevel(url.scheme(), net::GetHostOrSpecFromURL(url)) && | |
317 !UsesTemporaryZoomLevel(render_process_id, routing_id); | |
318 | |
319 if (GetForWebContents(web_contents) == this && uses_default_zoom) { | |
alexmos
2016/04/05 18:00:53
Help me understand: why do we want to filter this
wjmaclean
2016/04/05 20:22:00
I'll add a comment.
The answer is that HostZoomMa
alexmos
2016/04/07 01:20:56
Acknowledged.
| |
320 web_contents->UpdateZoom(level); | |
321 | |
322 NavigationEntry* entry = | |
323 web_contents->GetController().GetLastCommittedEntry(); | |
alexmos
2016/04/05 18:00:53
It seems |entry| is already set to last committed
wjmaclean
2016/04/05 20:22:00
Done.
| |
324 | |
325 HostZoomMap::ZoomLevelChange change; | |
326 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; | |
327 change.host = | |
328 entry ? net::GetHostOrSpecFromURL(HostZoomMap::GetURLFromEntry(entry)) | |
329 : std::string(); | |
330 change.zoom_level = level; | |
331 | |
332 zoom_level_changed_callbacks_.Notify(change); | |
alexmos
2016/04/05 18:00:53
I didn't see this notification used previously for
wjmaclean
2016/04/05 20:22:00
It was done previously, but via a rather roundabou
alexmos
2016/04/07 01:20:56
Ah, I see. Was this the one that went through Ren
| |
333 } | |
334 } | |
282 } | 335 } |
283 | 336 |
284 scoped_ptr<HostZoomMap::Subscription> | 337 scoped_ptr<HostZoomMap::Subscription> |
285 HostZoomMapImpl::AddZoomLevelChangedCallback( | 338 HostZoomMapImpl::AddZoomLevelChangedCallback( |
286 const ZoomLevelChangedCallback& callback) { | 339 const ZoomLevelChangedCallback& callback) { |
287 return zoom_level_changed_callbacks_.Add(callback); | 340 return zoom_level_changed_callbacks_.Add(callback); |
288 } | 341 } |
289 | 342 |
290 double HostZoomMapImpl::GetZoomLevelForWebContents( | 343 double HostZoomMapImpl::GetZoomLevelForWebContents( |
291 const WebContentsImpl& web_contents_impl) const { | 344 const WebContentsImpl& web_contents_impl) const { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 int render_view_id, | 451 int render_view_id, |
399 double level) { | 452 double level) { |
400 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 453 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
401 | 454 |
402 { | 455 { |
403 RenderViewKey key(render_process_id, render_view_id); | 456 RenderViewKey key(render_process_id, render_view_id); |
404 base::AutoLock auto_lock(lock_); | 457 base::AutoLock auto_lock(lock_); |
405 temporary_zoom_levels_[key] = level; | 458 temporary_zoom_levels_[key] = level; |
406 } | 459 } |
407 | 460 |
408 RenderViewHost* host = | 461 WebContentsImpl* web_contents = |
409 RenderViewHost::FromID(render_process_id, render_view_id); | 462 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( |
410 host->Send(new ViewMsg_SetZoomLevelForView(render_view_id, true, level)); | 463 RenderViewHost::FromID(render_process_id, render_view_id))); |
464 web_contents->SetTemporaryZoomLevel(level, true); | |
411 | 465 |
412 HostZoomMap::ZoomLevelChange change; | 466 HostZoomMap::ZoomLevelChange change; |
413 change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM; | 467 change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM; |
414 change.host = GetHostFromProcessView(render_process_id, render_view_id); | 468 change.host = GetHostFromProcessView(render_process_id, render_view_id); |
415 change.zoom_level = level; | 469 change.zoom_level = level; |
416 | 470 |
417 zoom_level_changed_callbacks_.Notify(change); | 471 zoom_level_changed_callbacks_.Notify(change); |
418 } | 472 } |
419 | 473 |
420 double HostZoomMapImpl::GetZoomLevelForView(const GURL& url, | 474 double HostZoomMapImpl::GetZoomLevelForView(const GURL& url, |
(...skipping 29 matching lines...) Expand all Loading... | |
450 void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id, | 504 void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id, |
451 int render_view_id) { | 505 int render_view_id) { |
452 { | 506 { |
453 base::AutoLock auto_lock(lock_); | 507 base::AutoLock auto_lock(lock_); |
454 RenderViewKey key(render_process_id, render_view_id); | 508 RenderViewKey key(render_process_id, render_view_id); |
455 TemporaryZoomLevels::iterator it = temporary_zoom_levels_.find(key); | 509 TemporaryZoomLevels::iterator it = temporary_zoom_levels_.find(key); |
456 if (it == temporary_zoom_levels_.end()) | 510 if (it == temporary_zoom_levels_.end()) |
457 return; | 511 return; |
458 temporary_zoom_levels_.erase(it); | 512 temporary_zoom_levels_.erase(it); |
459 } | 513 } |
460 RenderViewHost* host = | 514 WebContentsImpl* web_contents = |
461 RenderViewHost::FromID(render_process_id, render_view_id); | 515 static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( |
462 DCHECK(host); | 516 RenderViewHost::FromID(render_process_id, render_view_id))); |
463 // Send a new zoom level, host-specific if one exists. | 517 web_contents->SetTemporaryZoomLevel(GetZoomLevelForHost( |
464 host->Send(new ViewMsg_SetZoomLevelForView( | 518 GetHostFromProcessView(render_process_id, render_view_id)), false); |
465 render_view_id, | |
466 false, | |
467 GetZoomLevelForHost( | |
468 GetHostFromProcessView(render_process_id, render_view_id)))); | |
469 } | 519 } |
470 | 520 |
471 void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, | 521 void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
472 const std::string& host, | 522 const std::string& host, |
473 double level) { | 523 double level) { |
474 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 524 // We'll only send to WebContents not using temporary zoom levels. The one |
475 !i.IsAtEnd(); i.Advance()) { | 525 // other case of interest is where the renderer is hosting a plugin document; |
476 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 526 // that should be reflected in our temporary zoom level map, but we will |
477 // TODO(wjmaclean) This will need to be cleaned up when | 527 // double check on the renderer side to avoid the possibility of any races. |
478 // RenderProcessHost::GetStoragePartition() goes away. Perhaps have | 528 for (auto web_contents : WebContentsImpl::GetAllWebContents()) { |
479 // RenderProcessHost expose a GetHostZoomMap() function? | 529 // Only send zoom level changes to WebContents that are using this |
480 if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) { | 530 // HostZoomMap. |
481 render_process_host->Send( | 531 int render_process_id = web_contents->GetRenderProcessHost()->GetID(); |
482 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); | 532 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
alexmos
2016/04/05 18:00:53
nit: render_view_id or view_routing_id might be a
wjmaclean
2016/04/05 20:22:00
Done.
Note: routing_id is in use elsewhere in the
| |
533 | |
534 if (GetForWebContents(web_contents) == this && | |
535 !UsesTemporaryZoomLevel(render_process_id, routing_id)) { | |
536 web_contents->UpdateZoomIfNecessary(scheme, host, level); | |
483 } | 537 } |
484 } | 538 } |
485 } | 539 } |
486 | 540 |
487 void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { | 541 void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { |
488 GURL error_url(kUnreachableWebDataURL); | 542 GURL error_url(kUnreachableWebDataURL); |
489 std::string host = net::GetHostOrSpecFromURL(error_url); | 543 std::string host = net::GetHostOrSpecFromURL(error_url); |
490 double error_page_zoom_level = GetZoomLevelForHost(host); | 544 double error_page_zoom_level = GetZoomLevelForHost(host); |
491 | 545 |
492 SendZoomLevelChange(std::string(), host, error_page_zoom_level); | 546 SendZoomLevelChange(std::string(), host, error_page_zoom_level); |
493 } | 547 } |
494 | 548 |
495 HostZoomMapImpl::~HostZoomMapImpl() { | 549 HostZoomMapImpl::~HostZoomMapImpl() { |
496 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 550 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
497 } | 551 } |
498 | 552 |
499 } // namespace content | 553 } // namespace content |
OLD | NEW |