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 30 matching lines...) Expand all Loading... |
41 NavigationEntry* entry = | 41 NavigationEntry* entry = |
42 web_contents->GetController().GetLastCommittedEntry(); | 42 web_contents->GetController().GetLastCommittedEntry(); |
43 if (!entry) | 43 if (!entry) |
44 return std::string(); | 44 return std::string(); |
45 | 45 |
46 return net::GetHostOrSpecFromURL(entry->GetURL()); | 46 return net::GetHostOrSpecFromURL(entry->GetURL()); |
47 } | 47 } |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 HostZoomMap* HostZoomMap::GetForBrowserContext(BrowserContext* context) { | 51 HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) { |
52 HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( | 52 HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( |
53 context->GetUserData(kHostZoomMapKeyName)); | 53 context->GetUserData(kHostZoomMapKeyName)); |
54 if (!rv) { | 54 if (!rv) { |
55 rv = new HostZoomMapImpl(); | 55 rv = new HostZoomMapImpl(); |
56 context->SetUserData(kHostZoomMapKeyName, rv); | 56 context->SetUserData(kHostZoomMapKeyName, rv); |
57 } | 57 } |
58 return rv; | 58 return rv; |
59 } | 59 } |
60 | 60 |
61 // Helper function for setting/getting zoom levels for WebContents without | 61 // Helper function for setting/getting zoom levels for WebContents without |
62 // having to import HostZoomMapImpl everywhere. | 62 // having to import HostZoomMapImpl everywhere. |
63 double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { | 63 double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { |
64 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( | 64 HostZoomMapImpl* host_zoom_map = |
65 HostZoomMap::GetForBrowserContext(web_contents->GetBrowserContext())); | 65 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( |
| 66 web_contents->GetBrowserContext())); |
66 return host_zoom_map->GetZoomLevelForWebContents( | 67 return host_zoom_map->GetZoomLevelForWebContents( |
67 *static_cast<const WebContentsImpl*>(web_contents)); | 68 *static_cast<const WebContentsImpl*>(web_contents)); |
68 } | 69 } |
69 | 70 |
70 void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { | 71 void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { |
71 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( | 72 HostZoomMapImpl* host_zoom_map = |
72 HostZoomMap::GetForBrowserContext(web_contents->GetBrowserContext())); | 73 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( |
| 74 web_contents->GetBrowserContext())); |
73 host_zoom_map->SetZoomLevelForWebContents( | 75 host_zoom_map->SetZoomLevelForWebContents( |
74 *static_cast<const WebContentsImpl*>(web_contents), level); | 76 *static_cast<const WebContentsImpl*>(web_contents), level); |
75 } | 77 } |
76 | 78 |
77 HostZoomMapImpl::HostZoomMapImpl() | 79 HostZoomMapImpl::HostZoomMapImpl() |
78 : default_zoom_level_(0.0) { | 80 : default_zoom_level_(0.0) { |
79 registrar_.Add( | 81 registrar_.Add( |
80 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, | 82 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, |
81 NotificationService::AllSources()); | 83 NotificationService::AllSources()); |
82 } | 84 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 GetZoomLevelForHost( | 369 GetZoomLevelForHost( |
368 GetHostFromProcessView(render_process_id, render_view_id)))); | 370 GetHostFromProcessView(render_process_id, render_view_id)))); |
369 } | 371 } |
370 | 372 |
371 void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, | 373 void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
372 const std::string& host, | 374 const std::string& host, |
373 double level) { | 375 double level) { |
374 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 376 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
375 !i.IsAtEnd(); i.Advance()) { | 377 !i.IsAtEnd(); i.Advance()) { |
376 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 378 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
377 if (HostZoomMap::GetForBrowserContext( | 379 if (HostZoomMap::GetDefaultForBrowserContext( |
378 render_process_host->GetBrowserContext()) == this) { | 380 render_process_host->GetBrowserContext()) == this) { |
379 render_process_host->Send( | 381 render_process_host->Send( |
380 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); | 382 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
381 } | 383 } |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
385 HostZoomMapImpl::~HostZoomMapImpl() { | 387 HostZoomMapImpl::~HostZoomMapImpl() { |
386 } | 388 } |
387 | 389 |
388 } // namespace content | 390 } // namespace content |
OLD | NEW |