| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 84 |
| 85 // Helper function for setting/getting zoom levels for WebContents without | 85 // Helper function for setting/getting zoom levels for WebContents without |
| 86 // having to import HostZoomMapImpl everywhere. | 86 // having to import HostZoomMapImpl everywhere. |
| 87 double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { | 87 double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { |
| 88 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( | 88 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 89 HostZoomMap::GetForWebContents(web_contents)); | 89 HostZoomMap::GetForWebContents(web_contents)); |
| 90 return host_zoom_map->GetZoomLevelForWebContents( | 90 return host_zoom_map->GetZoomLevelForWebContents( |
| 91 *static_cast<const WebContentsImpl*>(web_contents)); | 91 *static_cast<const WebContentsImpl*>(web_contents)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool HostZoomMap::PageScaleFactorIsOne(const WebContents* web_contents) { |
| 95 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 96 HostZoomMap::GetForWebContents(web_contents)); |
| 97 return host_zoom_map->PageScaleFactorIsOneForWebContents( |
| 98 *static_cast<const WebContentsImpl*>(web_contents)); |
| 99 } |
| 100 |
| 94 void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { | 101 void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { |
| 95 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( | 102 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 96 HostZoomMap::GetForWebContents(web_contents)); | 103 HostZoomMap::GetForWebContents(web_contents)); |
| 97 host_zoom_map->SetZoomLevelForWebContents( | 104 host_zoom_map->SetZoomLevelForWebContents( |
| 98 *static_cast<const WebContentsImpl*>(web_contents), level); | 105 *static_cast<const WebContentsImpl*>(web_contents), level); |
| 99 } | 106 } |
| 100 | 107 |
| 101 void HostZoomMap::SendErrorPageZoomLevelRefresh( | 108 void HostZoomMap::SendErrorPageZoomLevelRefresh( |
| 102 const WebContents* web_contents) { | 109 const WebContents* web_contents) { |
| 103 HostZoomMapImpl* host_zoom_map = | 110 HostZoomMapImpl* host_zoom_map = |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 void HostZoomMapImpl::SetZoomLevelForView(int render_process_id, | 334 void HostZoomMapImpl::SetZoomLevelForView(int render_process_id, |
| 328 int render_view_id, | 335 int render_view_id, |
| 329 double level, | 336 double level, |
| 330 const std::string& host) { | 337 const std::string& host) { |
| 331 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) | 338 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) |
| 332 SetTemporaryZoomLevel(render_process_id, render_view_id, level); | 339 SetTemporaryZoomLevel(render_process_id, render_view_id, level); |
| 333 else | 340 else |
| 334 SetZoomLevelForHost(host, level); | 341 SetZoomLevelForHost(host, level); |
| 335 } | 342 } |
| 336 | 343 |
| 344 void HostZoomMapImpl::SetPageScaleFactorIsOneForView(int render_process_id, |
| 345 int render_view_id, |
| 346 bool is_one) { |
| 347 { |
| 348 base::AutoLock auto_lock(lock_); |
| 349 view_page_scale_factors_are_one_[RenderViewKey(render_process_id, |
| 350 render_view_id)] = is_one; |
| 351 } |
| 352 HostZoomMap::ZoomLevelChange change; |
| 353 change.mode = HostZoomMap::PAGE_SCALE_IS_ONE_CHANGED; |
| 354 zoom_level_changed_callbacks_.Notify(change); |
| 355 } |
| 356 |
| 357 bool HostZoomMapImpl::PageScaleFactorIsOneForWebContents( |
| 358 const WebContentsImpl& web_contents_impl) const { |
| 359 if (!web_contents_impl.GetRenderProcessHost()) |
| 360 return true; |
| 361 base::AutoLock auto_lock(lock_); |
| 362 auto found = view_page_scale_factors_are_one_.find( |
| 363 RenderViewKey(web_contents_impl.GetRenderProcessHost()->GetID(), |
| 364 web_contents_impl.GetRoutingID())); |
| 365 if (found == view_page_scale_factors_are_one_.end()) |
| 366 return true; |
| 367 return found->second; |
| 368 } |
| 369 |
| 370 void HostZoomMapImpl::ClearPageScaleFactorIsOneForView(int render_process_id, |
| 371 int render_view_id) { |
| 372 base::AutoLock auto_lock(lock_); |
| 373 view_page_scale_factors_are_one_.erase( |
| 374 RenderViewKey(render_process_id, render_view_id)); |
| 375 } |
| 376 |
| 337 bool HostZoomMapImpl::UsesTemporaryZoomLevel(int render_process_id, | 377 bool HostZoomMapImpl::UsesTemporaryZoomLevel(int render_process_id, |
| 338 int render_view_id) const { | 378 int render_view_id) const { |
| 339 RenderViewKey key(render_process_id, render_view_id); | 379 RenderViewKey key(render_process_id, render_view_id); |
| 340 | 380 |
| 341 base::AutoLock auto_lock(lock_); | 381 base::AutoLock auto_lock(lock_); |
| 342 return ContainsKey(temporary_zoom_levels_, key); | 382 return ContainsKey(temporary_zoom_levels_, key); |
| 343 } | 383 } |
| 344 | 384 |
| 345 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, | 385 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, |
| 346 int render_view_id) const { | 386 int render_view_id) const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 430 |
| 391 void HostZoomMapImpl::Observe(int type, | 431 void HostZoomMapImpl::Observe(int type, |
| 392 const NotificationSource& source, | 432 const NotificationSource& source, |
| 393 const NotificationDetails& details) { | 433 const NotificationDetails& details) { |
| 394 switch (type) { | 434 switch (type) { |
| 395 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { | 435 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { |
| 396 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); | 436 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); |
| 397 int render_process_id = | 437 int render_process_id = |
| 398 Source<RenderViewHost>(source)->GetProcess()->GetID(); | 438 Source<RenderViewHost>(source)->GetProcess()->GetID(); |
| 399 ClearTemporaryZoomLevel(render_process_id, render_view_id); | 439 ClearTemporaryZoomLevel(render_process_id, render_view_id); |
| 440 ClearPageScaleFactorIsOneForView(render_process_id, render_view_id); |
| 400 break; | 441 break; |
| 401 } | 442 } |
| 402 default: | 443 default: |
| 403 NOTREACHED() << "Unexpected preference observed."; | 444 NOTREACHED() << "Unexpected preference observed."; |
| 404 } | 445 } |
| 405 } | 446 } |
| 406 | 447 |
| 407 void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id, | 448 void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id, |
| 408 int render_view_id) { | 449 int render_view_id) { |
| 409 { | 450 { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 double error_page_zoom_level = GetZoomLevelForHost(host); | 488 double error_page_zoom_level = GetZoomLevelForHost(host); |
| 448 | 489 |
| 449 SendZoomLevelChange(std::string(), host, error_page_zoom_level); | 490 SendZoomLevelChange(std::string(), host, error_page_zoom_level); |
| 450 } | 491 } |
| 451 | 492 |
| 452 HostZoomMapImpl::~HostZoomMapImpl() { | 493 HostZoomMapImpl::~HostZoomMapImpl() { |
| 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 454 } | 495 } |
| 455 | 496 |
| 456 } // namespace content | 497 } // namespace content |
| OLD | NEW |