OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "content/browser/host_zoom_map_impl.h" | 7 #include "content/browser/host_zoom_map_impl.h" |
8 | 8 |
9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
13 #include "content/browser/renderer_host/render_view_host.h" | 13 #include "content/browser/renderer_host/render_view_host.h" |
14 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/resource_context.h" |
19 #include "content/public/common/page_zoom.h" | 20 #include "content/public/common/page_zoom.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
23 | 24 |
24 using WebKit::WebView; | 25 using WebKit::WebView; |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
26 using content::RenderProcessHost; | 27 using content::RenderProcessHost; |
27 | 28 |
| 29 static const char* kHostZoomMapKeyName = "content_host_zoom_map"; |
| 30 |
28 namespace content { | 31 namespace content { |
29 | 32 |
30 HostZoomMap* HostZoomMap::Create() { | 33 HostZoomMap* HostZoomMap::GetForBrowserContext(BrowserContext* context) { |
31 return new HostZoomMapImpl(); | 34 HostZoomMapImpl* rv = static_cast<HostZoomMapImpl*>( |
| 35 context->GetUserData(kHostZoomMapKeyName)); |
| 36 if (!rv) { |
| 37 rv = new HostZoomMapImpl(); |
| 38 context->SetUserData(kHostZoomMapKeyName, rv); |
| 39 context->GetResourceContext()->SetUserData(kHostZoomMapKeyName, rv); |
| 40 } |
| 41 return rv; |
| 42 } |
| 43 |
| 44 HostZoomMap* HostZoomMap::GetForResourceContext(ResourceContext* context) { |
| 45 return static_cast<HostZoomMapImpl*>( |
| 46 context->GetUserData(kHostZoomMapKeyName)); |
32 } | 47 } |
33 | 48 |
34 } // namespace content | 49 } // namespace content |
35 | 50 |
36 HostZoomMapImpl::HostZoomMapImpl() | 51 HostZoomMapImpl::HostZoomMapImpl() |
37 : default_zoom_level_(0.0) { | 52 : default_zoom_level_(0.0) { |
38 registrar_.Add( | 53 registrar_.Add( |
39 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, | 54 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, |
40 content::NotificationService::AllSources()); | 55 content::NotificationService::AllSources()); |
41 } | 56 } |
(...skipping 28 matching lines...) Expand all Loading... |
70 if (content::ZoomValuesEqual(level, default_zoom_level_)) | 85 if (content::ZoomValuesEqual(level, default_zoom_level_)) |
71 host_zoom_levels_.erase(host); | 86 host_zoom_levels_.erase(host); |
72 else | 87 else |
73 host_zoom_levels_[host] = level; | 88 host_zoom_levels_[host] = level; |
74 } | 89 } |
75 | 90 |
76 // Notify renderers from this browser context. | 91 // Notify renderers from this browser context. |
77 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 92 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
78 !i.IsAtEnd(); i.Advance()) { | 93 !i.IsAtEnd(); i.Advance()) { |
79 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 94 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
80 if (render_process_host->GetBrowserContext()->GetHostZoomMap() == this) { | 95 if (HostZoomMap::GetForBrowserContext( |
| 96 render_process_host->GetBrowserContext()) == this) { |
81 render_process_host->Send( | 97 render_process_host->Send( |
82 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); | 98 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); |
83 } | 99 } |
84 } | 100 } |
85 | 101 |
86 content::NotificationService::current()->Notify( | 102 content::NotificationService::current()->Notify( |
87 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 103 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
88 content::Source<HostZoomMap>(this), | 104 content::Source<HostZoomMap>(this), |
89 content::Details<const std::string>(&host)); | 105 content::Details<const std::string>(&host)); |
90 } | 106 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 184 } |
169 break; | 185 break; |
170 } | 186 } |
171 default: | 187 default: |
172 NOTREACHED() << "Unexpected preference observed."; | 188 NOTREACHED() << "Unexpected preference observed."; |
173 } | 189 } |
174 } | 190 } |
175 | 191 |
176 HostZoomMapImpl::~HostZoomMapImpl() { | 192 HostZoomMapImpl::~HostZoomMapImpl() { |
177 } | 193 } |
OLD | NEW |