Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: content/browser/host_zoom_map_impl.cc

Issue 9416070: Move creation and ownership of HostZoomMap to content instead of having every embedder do this. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac/cros browsertests Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/host_zoom_map_impl.h ('k') | content/browser/host_zoom_map_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 }
40 return rv;
32 } 41 }
33 42
34 } // namespace content 43 } // namespace content
35 44
36 HostZoomMapImpl::HostZoomMapImpl() 45 HostZoomMapImpl::HostZoomMapImpl()
37 : default_zoom_level_(0.0) { 46 : default_zoom_level_(0.0) {
38 registrar_.Add( 47 registrar_.Add(
39 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 48 this, content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
40 content::NotificationService::AllSources()); 49 content::NotificationService::AllSources());
41 } 50 }
(...skipping 28 matching lines...) Expand all
70 if (content::ZoomValuesEqual(level, default_zoom_level_)) 79 if (content::ZoomValuesEqual(level, default_zoom_level_))
71 host_zoom_levels_.erase(host); 80 host_zoom_levels_.erase(host);
72 else 81 else
73 host_zoom_levels_[host] = level; 82 host_zoom_levels_[host] = level;
74 } 83 }
75 84
76 // Notify renderers from this browser context. 85 // Notify renderers from this browser context.
77 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); 86 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
78 !i.IsAtEnd(); i.Advance()) { 87 !i.IsAtEnd(); i.Advance()) {
79 RenderProcessHost* render_process_host = i.GetCurrentValue(); 88 RenderProcessHost* render_process_host = i.GetCurrentValue();
80 if (render_process_host->GetBrowserContext()->GetHostZoomMap() == this) { 89 if (HostZoomMap::GetForBrowserContext(
90 render_process_host->GetBrowserContext()) == this) {
81 render_process_host->Send( 91 render_process_host->Send(
82 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); 92 new ViewMsg_SetZoomLevelForCurrentURL(host, level));
83 } 93 }
84 } 94 }
85 95
86 content::NotificationService::current()->Notify( 96 content::NotificationService::current()->Notify(
87 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 97 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
88 content::Source<HostZoomMap>(this), 98 content::Source<HostZoomMap>(this),
89 content::Details<const std::string>(&host)); 99 content::Details<const std::string>(&host));
90 } 100 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 content::NotificationService::current()->Notify( 152 content::NotificationService::current()->Notify(
143 content::NOTIFICATION_ZOOM_LEVEL_CHANGED, 153 content::NOTIFICATION_ZOOM_LEVEL_CHANGED,
144 content::Source<HostZoomMap>(this), 154 content::Source<HostZoomMap>(this),
145 content::Details<const std::string>(&host)); 155 content::Details<const std::string>(&host));
146 } 156 }
147 157
148 void HostZoomMapImpl::Observe( 158 void HostZoomMapImpl::Observe(
149 int type, 159 int type,
150 const content::NotificationSource& source, 160 const content::NotificationSource& source,
151 const content::NotificationDetails& details) { 161 const content::NotificationDetails& details) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
153
154 switch (type) { 162 switch (type) {
155 case content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { 163 case content::NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: {
156 base::AutoLock auto_lock(lock_); 164 base::AutoLock auto_lock(lock_);
157 int render_view_id = 165 int render_view_id =
158 content::Source<RenderViewHost>(source)->routing_id(); 166 content::Source<RenderViewHost>(source)->routing_id();
159 int render_process_id = 167 int render_process_id =
160 content::Source<RenderViewHost>(source)->process()->GetID(); 168 content::Source<RenderViewHost>(source)->process()->GetID();
161 169
162 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { 170 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) {
163 if (temporary_zoom_levels_[i].render_process_id == render_process_id && 171 if (temporary_zoom_levels_[i].render_process_id == render_process_id &&
164 temporary_zoom_levels_[i].render_view_id == render_view_id) { 172 temporary_zoom_levels_[i].render_view_id == render_view_id) {
165 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i); 173 temporary_zoom_levels_.erase(temporary_zoom_levels_.begin() + i);
166 break; 174 break;
167 } 175 }
168 } 176 }
169 break; 177 break;
170 } 178 }
171 default: 179 default:
172 NOTREACHED() << "Unexpected preference observed."; 180 NOTREACHED() << "Unexpected preference observed.";
173 } 181 }
174 } 182 }
175 183
176 HostZoomMapImpl::~HostZoomMapImpl() { 184 HostZoomMapImpl::~HostZoomMapImpl() {
177 } 185 }
OLDNEW
« no previous file with comments | « content/browser/host_zoom_map_impl.h ('k') | content/browser/host_zoom_map_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698