blob: cb394f81cbe857e051b70d813d74c5893b129699 [file] [log] [blame]
[email protected]9f76c1e2012-03-05 15:15:581// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]40bd6582009-12-04 23:49:512// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5c9250872012-01-30 17:24:055#include "content/browser/host_zoom_map_impl.h"
[email protected]40bd6582009-12-04 23:49:516
[email protected]fce823222014-05-30 16:24:307#include <algorithm>
[email protected]b9e7c479f2013-04-12 04:33:248#include <cmath>
9
10#include "base/strings/string_piece.h"
[email protected]74ebfb12013-06-07 20:48:0011#include "base/strings/utf_string_conversions.h"
[email protected]d407cc02011-09-13 16:01:4612#include "base/values.h"
[email protected]fce823222014-05-30 16:24:3013#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]f3b1a082011-11-18 00:34:3014#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3215#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]fce823222014-05-30 16:24:3016#include "content/browser/web_contents/web_contents_impl.h"
[email protected]4e2a25a2012-01-27 00:42:0817#include "content/common/view_messages.h"
18#include "content/public/browser/browser_context.h"
[email protected]c38831a12011-10-28 12:44:4919#include "content/public/browser/browser_thread.h"
[email protected]ad50def52011-10-19 23:17:0720#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1621#include "content/public/browser/notification_types.h"
[email protected]5fe3713a2012-02-22 08:31:5622#include "content/public/browser/resource_context.h"
wjmacleancaa7d6d2014-11-12 16:42:1123#include "content/public/browser/site_instance.h"
24#include "content/public/browser/storage_partition.h"
[email protected]0f083402011-11-22 02:59:0125#include "content/public/common/page_zoom.h"
wjmacleande29ed52014-10-28 21:09:0626#include "content/public/common/url_constants.h"
[email protected]9d797f32010-04-23 07:17:5427#include "net/base/net_util.h"
[email protected]40bd6582009-12-04 23:49:5128
[email protected]5c9250872012-01-30 17:24:0529namespace content {
30
[email protected]d42bf472014-06-14 01:49:3831namespace {
32
33std::string GetHostFromProcessView(int render_process_id, int render_view_id) {
mostynb4c27d042015-03-18 21:47:4734 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]d42bf472014-06-14 01:49:3835 RenderViewHost* render_view_host =
36 RenderViewHost::FromID(render_process_id, render_view_id);
37 if (!render_view_host)
38 return std::string();
39
40 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host);
41
42 NavigationEntry* entry =
43 web_contents->GetController().GetLastCommittedEntry();
44 if (!entry)
45 return std::string();
46
wjmacleande29ed52014-10-28 21:09:0647 return net::GetHostOrSpecFromURL(HostZoomMap::GetURLFromEntry(entry));
[email protected]d42bf472014-06-14 01:49:3848}
49
50} // namespace
51
wjmacleande29ed52014-10-28 21:09:0652GURL HostZoomMap::GetURLFromEntry(const NavigationEntry* entry) {
53 switch (entry->GetPageType()) {
54 case PAGE_TYPE_ERROR:
55 return GURL(kUnreachableWebDataURL);
56 // TODO(wjmaclean): In future, give interstitial pages special treatment as
57 // well.
58 default:
59 return entry->GetURL();
60 }
61}
62
wjmacleanf9b6ec82014-08-27 14:33:2463HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) {
wjmacleancaa7d6d2014-11-12 16:42:1164 StoragePartition* partition =
65 BrowserContext::GetDefaultStoragePartition(context);
66 DCHECK(partition);
67 return partition->GetHostZoomMap();
68}
69
70HostZoomMap* HostZoomMap::Get(SiteInstance* instance) {
71 StoragePartition* partition = BrowserContext::GetStoragePartition(
72 instance->GetBrowserContext(), instance);
73 DCHECK(partition);
74 return partition->GetHostZoomMap();
75}
76
77HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) {
mcnee432e47d2015-11-09 19:37:4678 // TODO(wjmaclean): Update this behaviour to work with OOPIF.
79 // See crbug.com/528407.
wjmacleancaa7d6d2014-11-12 16:42:1180 StoragePartition* partition =
81 BrowserContext::GetStoragePartition(contents->GetBrowserContext(),
82 contents->GetSiteInstance());
83 DCHECK(partition);
84 return partition->GetHostZoomMap();
[email protected]5c9250872012-01-30 17:24:0585}
86
[email protected]fce823222014-05-30 16:24:3087// Helper function for setting/getting zoom levels for WebContents without
88// having to import HostZoomMapImpl everywhere.
89double HostZoomMap::GetZoomLevel(const WebContents* web_contents) {
wjmacleancaa7d6d2014-11-12 16:42:1190 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
91 HostZoomMap::GetForWebContents(web_contents));
[email protected]fce823222014-05-30 16:24:3092 return host_zoom_map->GetZoomLevelForWebContents(
93 *static_cast<const WebContentsImpl*>(web_contents));
94}
95
ccameronb7c1d6c2015-03-09 17:08:2496bool HostZoomMap::PageScaleFactorIsOne(const WebContents* web_contents) {
97 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
98 HostZoomMap::GetForWebContents(web_contents));
99 return host_zoom_map->PageScaleFactorIsOneForWebContents(
100 *static_cast<const WebContentsImpl*>(web_contents));
101}
102
[email protected]fce823222014-05-30 16:24:30103void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) {
wjmacleancaa7d6d2014-11-12 16:42:11104 HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>(
105 HostZoomMap::GetForWebContents(web_contents));
[email protected]fce823222014-05-30 16:24:30106 host_zoom_map->SetZoomLevelForWebContents(
107 *static_cast<const WebContentsImpl*>(web_contents), level);
108}
109
wjmacleande29ed52014-10-28 21:09:06110void HostZoomMap::SendErrorPageZoomLevelRefresh(
111 const WebContents* web_contents) {
112 HostZoomMapImpl* host_zoom_map =
113 static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext(
114 web_contents->GetBrowserContext()));
115 host_zoom_map->SendErrorPageZoomLevelRefresh();
116}
117
[email protected]5c9250872012-01-30 17:24:05118HostZoomMapImpl::HostZoomMapImpl()
[email protected]4e2a25a2012-01-27 00:42:08119 : default_zoom_level_(0.0) {
[email protected]b75b8292010-10-01 07:28:25120 registrar_.Add(
[email protected]46488322012-10-30 03:22:20121 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
122 NotificationService::AllSources());
[email protected]40bd6582009-12-04 23:49:51123}
124
[email protected]5c9250872012-01-30 17:24:05125void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) {
[email protected]4e2a25a2012-01-27 00:42:08126 // This can only be called on the UI thread to avoid deadlocks, otherwise
127 // UI: a.CopyFrom(b);
128 // IO: b.CopyFrom(a);
129 // can deadlock.
mostynb4c27d042015-03-18 21:47:47130 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5c9250872012-01-30 17:24:05131 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface);
[email protected]4e2a25a2012-01-27 00:42:08132 base::AutoLock auto_lock(lock_);
133 base::AutoLock copy_auto_lock(copy->lock_);
[email protected]367c5c1d2013-03-11 18:59:02134 host_zoom_levels_.
135 insert(copy->host_zoom_levels_.begin(), copy->host_zoom_levels_.end());
136 for (SchemeHostZoomLevels::const_iterator i(copy->
137 scheme_host_zoom_levels_.begin());
138 i != copy->scheme_host_zoom_levels_.end(); ++i) {
139 scheme_host_zoom_levels_[i->first] = HostZoomLevels();
140 scheme_host_zoom_levels_[i->first].
141 insert(i->second.begin(), i->second.end());
[email protected]4e2a25a2012-01-27 00:42:08142 }
[email protected]19d26692013-01-12 19:56:33143 default_zoom_level_ = copy->default_zoom_level_;
[email protected]4e2a25a2012-01-27 00:42:08144}
145
[email protected]367c5c1d2013-03-11 18:59:02146double HostZoomMapImpl::GetZoomLevelForHost(const std::string& host) const {
[email protected]20305ec2011-01-21 04:55:52147 base::AutoLock auto_lock(lock_);
wjmacleanc62490492015-02-13 22:02:07148 return GetZoomLevelForHostInternal(host);
149}
150
151double HostZoomMapImpl::GetZoomLevelForHostInternal(
152 const std::string& host) const {
[email protected]40bd6582009-12-04 23:49:51153 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host));
[email protected]d0b8d092010-10-25 04:05:17154 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second;
[email protected]40bd6582009-12-04 23:49:51155}
156
[email protected]d42bf472014-06-14 01:49:38157bool HostZoomMapImpl::HasZoomLevel(const std::string& scheme,
158 const std::string& host) const {
159 base::AutoLock auto_lock(lock_);
160
161 SchemeHostZoomLevels::const_iterator scheme_iterator(
162 scheme_host_zoom_levels_.find(scheme));
163
164 const HostZoomLevels& zoom_levels =
165 (scheme_iterator != scheme_host_zoom_levels_.end())
166 ? scheme_iterator->second
167 : host_zoom_levels_;
168
169 HostZoomLevels::const_iterator i(zoom_levels.find(host));
170 return i != zoom_levels.end();
171}
172
wjmacleanc62490492015-02-13 22:02:07173double HostZoomMapImpl::GetZoomLevelForHostAndSchemeInternal(
174 const std::string& scheme,
175 const std::string& host) const {
176 SchemeHostZoomLevels::const_iterator scheme_iterator(
177 scheme_host_zoom_levels_.find(scheme));
178 if (scheme_iterator != scheme_host_zoom_levels_.end()) {
179 HostZoomLevels::const_iterator i(scheme_iterator->second.find(host));
180 if (i != scheme_iterator->second.end())
181 return i->second;
182 }
183
184 return GetZoomLevelForHostInternal(host);
185}
186
[email protected]367c5c1d2013-03-11 18:59:02187double HostZoomMapImpl::GetZoomLevelForHostAndScheme(
188 const std::string& scheme,
189 const std::string& host) const {
wjmacleanc62490492015-02-13 22:02:07190 base::AutoLock auto_lock(lock_);
191 return GetZoomLevelForHostAndSchemeInternal(scheme, host);
[email protected]367c5c1d2013-03-11 18:59:02192}
193
[email protected]0f374052014-03-18 20:37:22194HostZoomMap::ZoomLevelVector HostZoomMapImpl::GetAllZoomLevels() const {
195 HostZoomMap::ZoomLevelVector result;
196 {
197 base::AutoLock auto_lock(lock_);
198 result.reserve(host_zoom_levels_.size() + scheme_host_zoom_levels_.size());
199 for (HostZoomLevels::const_iterator i = host_zoom_levels_.begin();
200 i != host_zoom_levels_.end();
201 ++i) {
202 ZoomLevelChange change = {HostZoomMap::ZOOM_CHANGED_FOR_HOST,
203 i->first, // host
204 std::string(), // scheme
205 i->second // zoom level
206 };
207 result.push_back(change);
208 }
209 for (SchemeHostZoomLevels::const_iterator i =
210 scheme_host_zoom_levels_.begin();
211 i != scheme_host_zoom_levels_.end();
212 ++i) {
213 const std::string& scheme = i->first;
214 const HostZoomLevels& host_zoom_levels = i->second;
215 for (HostZoomLevels::const_iterator j = host_zoom_levels.begin();
216 j != host_zoom_levels.end();
217 ++j) {
218 ZoomLevelChange change = {HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST,
219 j->first, // host
220 scheme, // scheme
221 j->second // zoom level
222 };
223 result.push_back(change);
224 }
225 }
226 }
227 return result;
228}
229
[email protected]367c5c1d2013-03-11 18:59:02230void HostZoomMapImpl::SetZoomLevelForHost(const std::string& host,
231 double level) {
mostynb4c27d042015-03-18 21:47:47232 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]3ef4bc632010-04-09 04:25:31233
[email protected]40bd6582009-12-04 23:49:51234 {
[email protected]20305ec2011-01-21 04:55:52235 base::AutoLock auto_lock(lock_);
[email protected]0f083402011-11-22 02:59:01236
[email protected]46488322012-10-30 03:22:20237 if (ZoomValuesEqual(level, default_zoom_level_))
[email protected]40bd6582009-12-04 23:49:51238 host_zoom_levels_.erase(host);
239 else
240 host_zoom_levels_[host] = level;
241 }
242
[email protected]d42bf472014-06-14 01:49:38243 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
244 SendZoomLevelChange(std::string(), host, level);
245
[email protected]367c5c1d2013-03-11 18:59:02246 HostZoomMap::ZoomLevelChange change;
247 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST;
248 change.host = host;
249 change.zoom_level = level;
250
[email protected]117832812013-10-02 07:06:02251 zoom_level_changed_callbacks_.Notify(change);
[email protected]367c5c1d2013-03-11 18:59:02252}
253
254void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme,
255 const std::string& host,
256 double level) {
mostynb4c27d042015-03-18 21:47:47257 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]367c5c1d2013-03-11 18:59:02258 {
259 base::AutoLock auto_lock(lock_);
260 scheme_host_zoom_levels_[scheme][host] = level;
261 }
262
[email protected]d42bf472014-06-14 01:49:38263 SendZoomLevelChange(scheme, host, level);
[email protected]4e2a25a2012-01-27 00:42:08264
[email protected]367c5c1d2013-03-11 18:59:02265 HostZoomMap::ZoomLevelChange change;
266 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST;
267 change.host = host;
268 change.scheme = scheme;
269 change.zoom_level = level;
270
[email protected]117832812013-10-02 07:06:02271 zoom_level_changed_callbacks_.Notify(change);
[email protected]40bd6582009-12-04 23:49:51272}
273
[email protected]5c9250872012-01-30 17:24:05274double HostZoomMapImpl::GetDefaultZoomLevel() const {
mostynb4c27d042015-03-18 21:47:47275 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5c9250872012-01-30 17:24:05276 return default_zoom_level_;
277}
278
279void HostZoomMapImpl::SetDefaultZoomLevel(double level) {
mostynb4c27d042015-03-18 21:47:47280 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]5c9250872012-01-30 17:24:05281 default_zoom_level_ = level;
282}
283
[email protected]117832812013-10-02 07:06:02284scoped_ptr<HostZoomMap::Subscription>
285HostZoomMapImpl::AddZoomLevelChangedCallback(
[email protected]89c9aca2013-02-07 15:08:42286 const ZoomLevelChangedCallback& callback) {
[email protected]117832812013-10-02 07:06:02287 return zoom_level_changed_callbacks_.Add(callback);
[email protected]89c9aca2013-02-07 15:08:42288}
289
[email protected]fce823222014-05-30 16:24:30290double HostZoomMapImpl::GetZoomLevelForWebContents(
291 const WebContentsImpl& web_contents_impl) const {
292 int render_process_id = web_contents_impl.GetRenderProcessHost()->GetID();
293 int routing_id = web_contents_impl.GetRenderViewHost()->GetRoutingID();
294
295 if (UsesTemporaryZoomLevel(render_process_id, routing_id))
296 return GetTemporaryZoomLevel(render_process_id, routing_id);
297
[email protected]acda0ef32014-06-05 23:13:30298 // Get the url from the navigation controller directly, as calling
299 // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that
300 // is different than is stored in the map.
[email protected]fce823222014-05-30 16:24:30301 GURL url;
302 NavigationEntry* entry =
303 web_contents_impl.GetController().GetLastCommittedEntry();
[email protected]acda0ef32014-06-05 23:13:30304 // It is possible for a WebContent's zoom level to be queried before
305 // a navigation has occurred.
[email protected]fce823222014-05-30 16:24:30306 if (entry)
wjmacleande29ed52014-10-28 21:09:06307 url = GetURLFromEntry(entry);
[email protected]fce823222014-05-30 16:24:30308 return GetZoomLevelForHostAndScheme(url.scheme(),
309 net::GetHostOrSpecFromURL(url));
310}
311
312void HostZoomMapImpl::SetZoomLevelForWebContents(
313 const WebContentsImpl& web_contents_impl,
314 double level) {
315 int render_process_id = web_contents_impl.GetRenderProcessHost()->GetID();
316 int render_view_id = web_contents_impl.GetRenderViewHost()->GetRoutingID();
317 if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) {
[email protected]fce823222014-05-30 16:24:30318 SetTemporaryZoomLevel(render_process_id, render_view_id, level);
319 } else {
[email protected]acda0ef32014-06-05 23:13:30320 // Get the url from the navigation controller directly, as calling
321 // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that
322 // is different than what the render view is using. If the two don't match,
323 // the attempt to set the zoom will fail.
[email protected]acda0ef32014-06-05 23:13:30324 NavigationEntry* entry =
325 web_contents_impl.GetController().GetLastCommittedEntry();
[email protected]f3b3e5e2014-06-10 15:47:41326 // Tests may invoke this function with a null entry, but we don't
327 // want to save zoom levels in this case.
328 if (!entry)
329 return;
330
wjmacleande29ed52014-10-28 21:09:06331 GURL url = GetURLFromEntry(entry);
[email protected]acda0ef32014-06-05 23:13:30332 SetZoomLevelForHost(net::GetHostOrSpecFromURL(url), level);
[email protected]fce823222014-05-30 16:24:30333 }
334}
335
336void HostZoomMapImpl::SetZoomLevelForView(int render_process_id,
337 int render_view_id,
338 double level,
339 const std::string& host) {
340 if (UsesTemporaryZoomLevel(render_process_id, render_view_id))
341 SetTemporaryZoomLevel(render_process_id, render_view_id, level);
342 else
343 SetZoomLevelForHost(host, level);
344}
345
ccameronb7c1d6c2015-03-09 17:08:24346void HostZoomMapImpl::SetPageScaleFactorIsOneForView(int render_process_id,
347 int render_view_id,
348 bool is_one) {
349 {
350 base::AutoLock auto_lock(lock_);
351 view_page_scale_factors_are_one_[RenderViewKey(render_process_id,
352 render_view_id)] = is_one;
353 }
354 HostZoomMap::ZoomLevelChange change;
355 change.mode = HostZoomMap::PAGE_SCALE_IS_ONE_CHANGED;
356 zoom_level_changed_callbacks_.Notify(change);
357}
358
359bool HostZoomMapImpl::PageScaleFactorIsOneForWebContents(
360 const WebContentsImpl& web_contents_impl) const {
361 if (!web_contents_impl.GetRenderProcessHost())
362 return true;
363 base::AutoLock auto_lock(lock_);
364 auto found = view_page_scale_factors_are_one_.find(
365 RenderViewKey(web_contents_impl.GetRenderProcessHost()->GetID(),
366 web_contents_impl.GetRoutingID()));
367 if (found == view_page_scale_factors_are_one_.end())
368 return true;
369 return found->second;
370}
371
372void HostZoomMapImpl::ClearPageScaleFactorIsOneForView(int render_process_id,
373 int render_view_id) {
374 base::AutoLock auto_lock(lock_);
375 view_page_scale_factors_are_one_.erase(
376 RenderViewKey(render_process_id, render_view_id));
377}
378
[email protected]fce823222014-05-30 16:24:30379bool HostZoomMapImpl::UsesTemporaryZoomLevel(int render_process_id,
380 int render_view_id) const {
[email protected]d42bf472014-06-14 01:49:38381 RenderViewKey key(render_process_id, render_view_id);
[email protected]fce823222014-05-30 16:24:30382
383 base::AutoLock auto_lock(lock_);
[email protected]d42bf472014-06-14 01:49:38384 return ContainsKey(temporary_zoom_levels_, key);
[email protected]fce823222014-05-30 16:24:30385}
386
[email protected]5c9250872012-01-30 17:24:05387double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id,
388 int render_view_id) const {
[email protected]20305ec2011-01-21 04:55:52389 base::AutoLock auto_lock(lock_);
[email protected]d42bf472014-06-14 01:49:38390 RenderViewKey key(render_process_id, render_view_id);
391 if (!ContainsKey(temporary_zoom_levels_, key))
392 return 0;
[email protected]fce823222014-05-30 16:24:30393
[email protected]d42bf472014-06-14 01:49:38394 return temporary_zoom_levels_.find(key)->second;
[email protected]b75b8292010-10-01 07:28:25395}
396
[email protected]5c9250872012-01-30 17:24:05397void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id,
398 int render_view_id,
399 double level) {
mostynb4c27d042015-03-18 21:47:47400 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]b75b8292010-10-01 07:28:25401
402 {
[email protected]d42bf472014-06-14 01:49:38403 RenderViewKey key(render_process_id, render_view_id);
[email protected]20305ec2011-01-21 04:55:52404 base::AutoLock auto_lock(lock_);
[email protected]d42bf472014-06-14 01:49:38405 temporary_zoom_levels_[key] = level;
[email protected]b75b8292010-10-01 07:28:25406 }
407
[email protected]d42bf472014-06-14 01:49:38408 RenderViewHost* host =
409 RenderViewHost::FromID(render_process_id, render_view_id);
410 host->Send(new ViewMsg_SetZoomLevelForView(render_view_id, true, level));
411
[email protected]367c5c1d2013-03-11 18:59:02412 HostZoomMap::ZoomLevelChange change;
413 change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM;
[email protected]d42bf472014-06-14 01:49:38414 change.host = GetHostFromProcessView(render_process_id, render_view_id);
[email protected]367c5c1d2013-03-11 18:59:02415 change.zoom_level = level;
416
[email protected]117832812013-10-02 07:06:02417 zoom_level_changed_callbacks_.Notify(change);
[email protected]b75b8292010-10-01 07:28:25418}
419
wjmacleanc62490492015-02-13 22:02:07420double HostZoomMapImpl::GetZoomLevelForView(const GURL& url,
421 int render_process_id,
422 int render_view_id) const {
423 RenderViewKey key(render_process_id, render_view_id);
424 base::AutoLock auto_lock(lock_);
425
426 if (ContainsKey(temporary_zoom_levels_, key))
427 return temporary_zoom_levels_.find(key)->second;
428
429 return GetZoomLevelForHostAndSchemeInternal(url.scheme(),
430 net::GetHostOrSpecFromURL(url));
431}
432
[email protected]46488322012-10-30 03:22:20433void HostZoomMapImpl::Observe(int type,
434 const NotificationSource& source,
435 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27436 switch (type) {
[email protected]46488322012-10-30 03:22:20437 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: {
[email protected]46488322012-10-30 03:22:20438 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID();
[email protected]6c2381d2011-10-19 02:52:53439 int render_process_id =
[email protected]46488322012-10-30 03:22:20440 Source<RenderViewHost>(source)->GetProcess()->GetID();
[email protected]d42bf472014-06-14 01:49:38441 ClearTemporaryZoomLevel(render_process_id, render_view_id);
ccameronb7c1d6c2015-03-09 17:08:24442 ClearPageScaleFactorIsOneForView(render_process_id, render_view_id);
[email protected]b75b8292010-10-01 07:28:25443 break;
[email protected]3ef4bc632010-04-09 04:25:31444 }
[email protected]b75b8292010-10-01 07:28:25445 default:
446 NOTREACHED() << "Unexpected preference observed.";
[email protected]3ef4bc632010-04-09 04:25:31447 }
[email protected]779c3362010-01-30 01:09:33448}
449
[email protected]d42bf472014-06-14 01:49:38450void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id,
451 int render_view_id) {
452 {
453 base::AutoLock auto_lock(lock_);
454 RenderViewKey key(render_process_id, render_view_id);
455 TemporaryZoomLevels::iterator it = temporary_zoom_levels_.find(key);
456 if (it == temporary_zoom_levels_.end())
457 return;
458 temporary_zoom_levels_.erase(it);
459 }
460 RenderViewHost* host =
461 RenderViewHost::FromID(render_process_id, render_view_id);
462 DCHECK(host);
463 // Send a new zoom level, host-specific if one exists.
464 host->Send(new ViewMsg_SetZoomLevelForView(
465 render_view_id,
466 false,
467 GetZoomLevelForHost(
468 GetHostFromProcessView(render_process_id, render_view_id))));
469}
470
471void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme,
472 const std::string& host,
473 double level) {
474 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator());
475 !i.IsAtEnd(); i.Advance()) {
476 RenderProcessHost* render_process_host = i.GetCurrentValue();
wjmacleancaa7d6d2014-11-12 16:42:11477 // TODO(wjmaclean) This will need to be cleaned up when
478 // RenderProcessHost::GetStoragePartition() goes away. Perhaps have
479 // RenderProcessHost expose a GetHostZoomMap() function?
480 if (render_process_host->GetStoragePartition()->GetHostZoomMap() == this) {
[email protected]d42bf472014-06-14 01:49:38481 render_process_host->Send(
482 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level));
483 }
484 }
485}
486
wjmacleande29ed52014-10-28 21:09:06487void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() {
488 GURL error_url(kUnreachableWebDataURL);
489 std::string host = net::GetHostOrSpecFromURL(error_url);
490 double error_page_zoom_level = GetZoomLevelForHost(host);
491
492 SendZoomLevelChange(std::string(), host, error_page_zoom_level);
493}
494
[email protected]5c9250872012-01-30 17:24:05495HostZoomMapImpl::~HostZoomMapImpl() {
mostynb4c27d042015-03-18 21:47:47496 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]40bd6582009-12-04 23:49:51497}
[email protected]46488322012-10-30 03:22:20498
499} // namespace content