[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 5 | #include "content/browser/host_zoom_map_impl.h" |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 6 | |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 8 | #include <cmath> |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 9 | #include <memory> |
| 10 | #include <utility> |
[email protected] | b9e7c479f | 2013-04-12 04:33:24 | [diff] [blame] | 11 | |
| 12 | #include "base/strings/string_piece.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 13 | #include "base/strings/utf_string_conversions.h" |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 14 | #include "base/time/default_clock.h" |
[email protected] | d407cc0 | 2011-09-13 16:01:46 | [diff] [blame] | 15 | #include "base/values.h" |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 16 | #include "content/browser/frame_host/navigation_entry_impl.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 17 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 18 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 19 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 4e2a25a | 2012-01-27 00:42:08 | [diff] [blame] | 20 | #include "content/common/view_messages.h" |
| 21 | #include "content/public/browser/browser_context.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 22 | #include "content/public/browser/browser_thread.h" |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 23 | #include "content/public/browser/render_frame_host.h" |
[email protected] | 5fe3713a | 2012-02-22 08:31:56 | [diff] [blame] | 24 | #include "content/public/browser/resource_context.h" |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 25 | #include "content/public/browser/site_instance.h" |
| 26 | #include "content/public/browser/storage_partition.h" |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 27 | #include "content/public/common/page_zoom.h" |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 28 | #include "content/public/common/url_constants.h" |
tfarina | 7a4a7fd | 2016-01-20 14:23:44 | [diff] [blame] | 29 | #include "net/base/url_util.h" |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 30 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 31 | namespace content { |
| 32 | |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 33 | namespace { |
| 34 | |
| 35 | std::string GetHostFromProcessView(int render_process_id, int render_view_id) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 36 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 37 | RenderViewHost* render_view_host = |
| 38 | RenderViewHost::FromID(render_process_id, render_view_id); |
| 39 | if (!render_view_host) |
| 40 | return std::string(); |
| 41 | |
| 42 | WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| 43 | |
| 44 | NavigationEntry* entry = |
| 45 | web_contents->GetController().GetLastCommittedEntry(); |
| 46 | if (!entry) |
| 47 | return std::string(); |
| 48 | |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 49 | return net::GetHostOrSpecFromURL(HostZoomMap::GetURLFromEntry(entry)); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | } // namespace |
| 53 | |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 54 | GURL HostZoomMap::GetURLFromEntry(const NavigationEntry* entry) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 55 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 56 | switch (entry->GetPageType()) { |
| 57 | case PAGE_TYPE_ERROR: |
| 58 | return GURL(kUnreachableWebDataURL); |
| 59 | // TODO(wjmaclean): In future, give interstitial pages special treatment as |
| 60 | // well. |
| 61 | default: |
| 62 | return entry->GetURL(); |
| 63 | } |
| 64 | } |
| 65 | |
wjmaclean | f9b6ec8 | 2014-08-27 14:33:24 | [diff] [blame] | 66 | HostZoomMap* HostZoomMap::GetDefaultForBrowserContext(BrowserContext* context) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 67 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 68 | StoragePartition* partition = |
| 69 | BrowserContext::GetDefaultStoragePartition(context); |
| 70 | DCHECK(partition); |
| 71 | return partition->GetHostZoomMap(); |
| 72 | } |
| 73 | |
| 74 | HostZoomMap* HostZoomMap::Get(SiteInstance* instance) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 75 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 76 | StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 77 | instance->GetBrowserContext(), instance); |
| 78 | DCHECK(partition); |
| 79 | return partition->GetHostZoomMap(); |
| 80 | } |
| 81 | |
| 82 | HostZoomMap* HostZoomMap::GetForWebContents(const WebContents* contents) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 83 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 84 | // TODO(wjmaclean): Update this behaviour to work with OOPIF. |
| 85 | // See crbug.com/528407. |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 86 | StoragePartition* partition = |
| 87 | BrowserContext::GetStoragePartition(contents->GetBrowserContext(), |
| 88 | contents->GetSiteInstance()); |
| 89 | DCHECK(partition); |
| 90 | return partition->GetHostZoomMap(); |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 93 | // Helper function for setting/getting zoom levels for WebContents without |
| 94 | // having to import HostZoomMapImpl everywhere. |
| 95 | double HostZoomMap::GetZoomLevel(const WebContents* web_contents) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 96 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 97 | HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 98 | HostZoomMap::GetForWebContents(web_contents)); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 99 | return host_zoom_map->GetZoomLevelForWebContents( |
| 100 | *static_cast<const WebContentsImpl*>(web_contents)); |
| 101 | } |
| 102 | |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 103 | bool HostZoomMap::PageScaleFactorIsOne(const WebContents* web_contents) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 104 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 105 | HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 106 | HostZoomMap::GetForWebContents(web_contents)); |
| 107 | return host_zoom_map->PageScaleFactorIsOneForWebContents( |
| 108 | *static_cast<const WebContentsImpl*>(web_contents)); |
| 109 | } |
| 110 | |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 111 | void HostZoomMap::SetZoomLevel(const WebContents* web_contents, double level) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 112 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 113 | HostZoomMapImpl* host_zoom_map = static_cast<HostZoomMapImpl*>( |
| 114 | HostZoomMap::GetForWebContents(web_contents)); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 115 | host_zoom_map->SetZoomLevelForWebContents( |
| 116 | *static_cast<const WebContentsImpl*>(web_contents), level); |
| 117 | } |
| 118 | |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 119 | void HostZoomMap::SendErrorPageZoomLevelRefresh( |
| 120 | const WebContents* web_contents) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 121 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 122 | HostZoomMapImpl* host_zoom_map = |
| 123 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetDefaultForBrowserContext( |
| 124 | web_contents->GetBrowserContext())); |
| 125 | host_zoom_map->SendErrorPageZoomLevelRefresh(); |
| 126 | } |
| 127 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 128 | HostZoomMapImpl::HostZoomMapImpl() |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 129 | : default_zoom_level_(0.0), |
| 130 | store_last_modified_(false), |
tzik | 67025f67 | 2017-11-29 05:04:44 | [diff] [blame] | 131 | clock_(base::DefaultClock::GetInstance()) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 132 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 133 | } |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 134 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 135 | void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 136 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 137 | HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 138 | host_zoom_levels_.insert(copy->host_zoom_levels_.begin(), |
| 139 | copy->host_zoom_levels_.end()); |
| 140 | for (const auto& it : copy->scheme_host_zoom_levels_) { |
| 141 | const std::string& host = it.first; |
| 142 | scheme_host_zoom_levels_[host] = HostZoomLevels(); |
| 143 | scheme_host_zoom_levels_[host].insert(it.second.begin(), it.second.end()); |
[email protected] | 4e2a25a | 2012-01-27 00:42:08 | [diff] [blame] | 144 | } |
[email protected] | 19d2669 | 2013-01-12 19:56:33 | [diff] [blame] | 145 | default_zoom_level_ = copy->default_zoom_level_; |
[email protected] | 4e2a25a | 2012-01-27 00:42:08 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 148 | double HostZoomMapImpl::GetZoomLevelForHost(const std::string& host) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 149 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 150 | const auto it = host_zoom_levels_.find(host); |
| 151 | return it != host_zoom_levels_.end() ? it->second.level : default_zoom_level_; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 154 | bool HostZoomMapImpl::HasZoomLevel(const std::string& scheme, |
| 155 | const std::string& host) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 156 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 157 | SchemeHostZoomLevels::const_iterator scheme_iterator( |
| 158 | scheme_host_zoom_levels_.find(scheme)); |
| 159 | |
| 160 | const HostZoomLevels& zoom_levels = |
| 161 | (scheme_iterator != scheme_host_zoom_levels_.end()) |
| 162 | ? scheme_iterator->second |
| 163 | : host_zoom_levels_; |
| 164 | |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 165 | return base::ContainsKey(zoom_levels, host); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 166 | } |
| 167 | |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 168 | double HostZoomMapImpl::GetZoomLevelForHostAndScheme( |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 169 | const std::string& scheme, |
| 170 | const std::string& host) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 171 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 172 | SchemeHostZoomLevels::const_iterator scheme_iterator( |
| 173 | scheme_host_zoom_levels_.find(scheme)); |
| 174 | if (scheme_iterator != scheme_host_zoom_levels_.end()) { |
| 175 | HostZoomLevels::const_iterator i(scheme_iterator->second.find(host)); |
| 176 | if (i != scheme_iterator->second.end()) |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 177 | return i->second.level; |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 178 | } |
| 179 | |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 180 | return GetZoomLevelForHost(host); |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 181 | } |
| 182 | |
[email protected] | 0f37405 | 2014-03-18 20:37:22 | [diff] [blame] | 183 | HostZoomMap::ZoomLevelVector HostZoomMapImpl::GetAllZoomLevels() const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 184 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0f37405 | 2014-03-18 20:37:22 | [diff] [blame] | 185 | HostZoomMap::ZoomLevelVector result; |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 186 | result.reserve(host_zoom_levels_.size() + scheme_host_zoom_levels_.size()); |
| 187 | for (const auto& entry : host_zoom_levels_) { |
| 188 | ZoomLevelChange change = { |
| 189 | HostZoomMap::ZOOM_CHANGED_FOR_HOST, |
| 190 | entry.first, // host |
| 191 | std::string(), // scheme |
| 192 | entry.second.level, // zoom level |
| 193 | entry.second.last_modified // last modified |
| 194 | }; |
| 195 | result.push_back(change); |
| 196 | } |
| 197 | for (const auto& scheme_entry : scheme_host_zoom_levels_) { |
| 198 | const std::string& scheme = scheme_entry.first; |
| 199 | const HostZoomLevels& host_zoom_levels = scheme_entry.second; |
| 200 | for (const auto& entry : host_zoom_levels) { |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 201 | ZoomLevelChange change = { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 202 | HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST, |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 203 | entry.first, // host |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 204 | scheme, // scheme |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 205 | entry.second.level, // zoom level |
| 206 | entry.second.last_modified // last modified |
[email protected] | 0f37405 | 2014-03-18 20:37:22 | [diff] [blame] | 207 | }; |
| 208 | result.push_back(change); |
| 209 | } |
[email protected] | 0f37405 | 2014-03-18 20:37:22 | [diff] [blame] | 210 | } |
| 211 | return result; |
| 212 | } |
| 213 | |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 214 | void HostZoomMapImpl::SetZoomLevelForHost(const std::string& host, |
| 215 | double level) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 216 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 217 | base::Time last_modified = |
| 218 | store_last_modified_ ? clock_->Now() : base::Time(); |
| 219 | SetZoomLevelForHostInternal(host, level, last_modified); |
| 220 | } |
| 221 | |
| 222 | void HostZoomMapImpl::InitializeZoomLevelForHost(const std::string& host, |
| 223 | double level, |
| 224 | base::Time last_modified) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 225 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 226 | SetZoomLevelForHostInternal(host, level, last_modified); |
| 227 | } |
| 228 | |
| 229 | void HostZoomMapImpl::SetZoomLevelForHostInternal(const std::string& host, |
| 230 | double level, |
| 231 | base::Time last_modified) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 232 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 3ef4bc63 | 2010-04-09 04:25:31 | [diff] [blame] | 233 | |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 234 | if (ZoomValuesEqual(level, default_zoom_level_)) { |
| 235 | host_zoom_levels_.erase(host); |
| 236 | } else { |
| 237 | ZoomLevel& zoomLevel = host_zoom_levels_[host]; |
| 238 | zoomLevel.level = level; |
| 239 | zoomLevel.last_modified = last_modified; |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 242 | // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486 |
| 243 | SendZoomLevelChange(std::string(), host, level); |
| 244 | |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 245 | HostZoomMap::ZoomLevelChange change; |
| 246 | change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; |
| 247 | change.host = host; |
| 248 | change.zoom_level = level; |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 249 | change.last_modified = last_modified; |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 250 | |
[email protected] | 11783281 | 2013-10-02 07:06:02 | [diff] [blame] | 251 | zoom_level_changed_callbacks_.Notify(change); |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, |
| 255 | const std::string& host, |
| 256 | double level) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 257 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 258 | // No last_modified timestamp for scheme and host because they are |
| 259 | // not persistet and are used for special cases only. |
| 260 | scheme_host_zoom_levels_[scheme][host].level = level; |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 261 | |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 262 | SendZoomLevelChange(scheme, host, level); |
[email protected] | 4e2a25a | 2012-01-27 00:42:08 | [diff] [blame] | 263 | |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 264 | HostZoomMap::ZoomLevelChange change; |
| 265 | change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; |
| 266 | change.host = host; |
| 267 | change.scheme = scheme; |
| 268 | change.zoom_level = level; |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 269 | change.last_modified = base::Time(); |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 270 | |
[email protected] | 11783281 | 2013-10-02 07:06:02 | [diff] [blame] | 271 | zoom_level_changed_callbacks_.Notify(change); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 272 | } |
| 273 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 274 | double HostZoomMapImpl::GetDefaultZoomLevel() const { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 275 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 276 | return default_zoom_level_; |
| 277 | } |
| 278 | |
| 279 | void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 280 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 281 | |
| 282 | if (ZoomValuesEqual(level, default_zoom_level_)) |
| 283 | return; |
| 284 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 285 | default_zoom_level_ = level; |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 286 | |
| 287 | // First, remove all entries that match the new default zoom level. |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 288 | for (auto it = host_zoom_levels_.begin(); it != host_zoom_levels_.end();) { |
| 289 | if (ZoomValuesEqual(it->second.level, default_zoom_level_)) |
| 290 | it = host_zoom_levels_.erase(it); |
| 291 | else |
| 292 | it++; |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | // Second, update zoom levels for all pages that do not have an overriding |
| 296 | // entry. |
vmpstr | 10e0d5f | 2016-07-21 23:46:09 | [diff] [blame] | 297 | for (auto* web_contents : WebContentsImpl::GetAllWebContents()) { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 298 | // Only change zoom for WebContents tied to the StoragePartition this |
| 299 | // HostZoomMap serves. |
| 300 | if (GetForWebContents(web_contents) != this) |
| 301 | continue; |
| 302 | |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 303 | int render_process_id = |
| 304 | web_contents->GetRenderViewHost()->GetProcess()->GetID(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 305 | int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 306 | |
| 307 | // Get the url from the navigation controller directly, as calling |
| 308 | // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that |
| 309 | // is different than the one stored in the map. |
| 310 | GURL url; |
| 311 | std::string host; |
| 312 | std::string scheme; |
| 313 | |
| 314 | NavigationEntry* entry = |
| 315 | web_contents->GetController().GetLastCommittedEntry(); |
| 316 | // It is possible for a WebContent's zoom level to be queried before |
| 317 | // a navigation has occurred. |
| 318 | if (entry) { |
| 319 | url = GetURLFromEntry(entry); |
| 320 | scheme = url.scheme(); |
| 321 | host = net::GetHostOrSpecFromURL(url); |
| 322 | } |
| 323 | |
| 324 | bool uses_default_zoom = |
| 325 | !HasZoomLevel(scheme, host) && |
| 326 | !UsesTemporaryZoomLevel(render_process_id, render_view_id); |
| 327 | |
| 328 | if (uses_default_zoom) { |
| 329 | web_contents->UpdateZoom(level); |
| 330 | |
| 331 | HostZoomMap::ZoomLevelChange change; |
| 332 | change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; |
| 333 | change.host = host; |
| 334 | change.zoom_level = level; |
| 335 | |
| 336 | zoom_level_changed_callbacks_.Notify(change); |
| 337 | } |
| 338 | } |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 339 | } |
| 340 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 341 | std::unique_ptr<HostZoomMap::Subscription> |
[email protected] | 11783281 | 2013-10-02 07:06:02 | [diff] [blame] | 342 | HostZoomMapImpl::AddZoomLevelChangedCallback( |
[email protected] | 89c9aca | 2013-02-07 15:08:42 | [diff] [blame] | 343 | const ZoomLevelChangedCallback& callback) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 344 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 11783281 | 2013-10-02 07:06:02 | [diff] [blame] | 345 | return zoom_level_changed_callbacks_.Add(callback); |
[email protected] | 89c9aca | 2013-02-07 15:08:42 | [diff] [blame] | 346 | } |
| 347 | |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 348 | double HostZoomMapImpl::GetZoomLevelForWebContents( |
| 349 | const WebContentsImpl& web_contents_impl) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 350 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 351 | int render_process_id = |
| 352 | web_contents_impl.GetRenderViewHost()->GetProcess()->GetID(); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 353 | int routing_id = web_contents_impl.GetRenderViewHost()->GetRoutingID(); |
| 354 | |
| 355 | if (UsesTemporaryZoomLevel(render_process_id, routing_id)) |
| 356 | return GetTemporaryZoomLevel(render_process_id, routing_id); |
| 357 | |
[email protected] | acda0ef3 | 2014-06-05 23:13:30 | [diff] [blame] | 358 | // Get the url from the navigation controller directly, as calling |
| 359 | // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that |
| 360 | // is different than is stored in the map. |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 361 | GURL url; |
| 362 | NavigationEntry* entry = |
| 363 | web_contents_impl.GetController().GetLastCommittedEntry(); |
[email protected] | acda0ef3 | 2014-06-05 23:13:30 | [diff] [blame] | 364 | // It is possible for a WebContent's zoom level to be queried before |
| 365 | // a navigation has occurred. |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 366 | if (entry) |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 367 | url = GetURLFromEntry(entry); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 368 | return GetZoomLevelForHostAndScheme(url.scheme(), |
| 369 | net::GetHostOrSpecFromURL(url)); |
| 370 | } |
| 371 | |
| 372 | void HostZoomMapImpl::SetZoomLevelForWebContents( |
| 373 | const WebContentsImpl& web_contents_impl, |
| 374 | double level) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 375 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 376 | int render_process_id = |
| 377 | web_contents_impl.GetRenderViewHost()->GetProcess()->GetID(); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 378 | int render_view_id = web_contents_impl.GetRenderViewHost()->GetRoutingID(); |
| 379 | if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) { |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 380 | SetTemporaryZoomLevel(render_process_id, render_view_id, level); |
| 381 | } else { |
[email protected] | acda0ef3 | 2014-06-05 23:13:30 | [diff] [blame] | 382 | // Get the url from the navigation controller directly, as calling |
| 383 | // WebContentsImpl::GetLastCommittedURL() may give us a virtual url that |
| 384 | // is different than what the render view is using. If the two don't match, |
| 385 | // the attempt to set the zoom will fail. |
[email protected] | acda0ef3 | 2014-06-05 23:13:30 | [diff] [blame] | 386 | NavigationEntry* entry = |
| 387 | web_contents_impl.GetController().GetLastCommittedEntry(); |
[email protected] | f3b3e5e | 2014-06-10 15:47:41 | [diff] [blame] | 388 | // Tests may invoke this function with a null entry, but we don't |
| 389 | // want to save zoom levels in this case. |
| 390 | if (!entry) |
| 391 | return; |
| 392 | |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 393 | GURL url = GetURLFromEntry(entry); |
[email protected] | acda0ef3 | 2014-06-05 23:13:30 | [diff] [blame] | 394 | SetZoomLevelForHost(net::GetHostOrSpecFromURL(url), level); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
| 398 | void HostZoomMapImpl::SetZoomLevelForView(int render_process_id, |
| 399 | int render_view_id, |
| 400 | double level, |
| 401 | const std::string& host) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 402 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 403 | if (UsesTemporaryZoomLevel(render_process_id, render_view_id)) |
| 404 | SetTemporaryZoomLevel(render_process_id, render_view_id, level); |
| 405 | else |
| 406 | SetZoomLevelForHost(host, level); |
| 407 | } |
| 408 | |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 409 | void HostZoomMapImpl::SetPageScaleFactorIsOneForView(int render_process_id, |
| 410 | int render_view_id, |
| 411 | bool is_one) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 412 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 413 | view_page_scale_factors_are_one_[RenderViewKey(render_process_id, |
| 414 | render_view_id)] = is_one; |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 415 | HostZoomMap::ZoomLevelChange change; |
| 416 | change.mode = HostZoomMap::PAGE_SCALE_IS_ONE_CHANGED; |
| 417 | zoom_level_changed_callbacks_.Notify(change); |
| 418 | } |
| 419 | |
| 420 | bool HostZoomMapImpl::PageScaleFactorIsOneForWebContents( |
| 421 | const WebContentsImpl& web_contents_impl) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 422 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 423 | if (!web_contents_impl.GetRenderViewHost()->GetProcess()) |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 424 | return true; |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 425 | |
| 426 | const auto it = view_page_scale_factors_are_one_.find(RenderViewKey( |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 427 | web_contents_impl.GetRenderViewHost()->GetProcess()->GetID(), |
| 428 | web_contents_impl.GetRenderViewHost()->GetRoutingID())); |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 429 | return it != view_page_scale_factors_are_one_.end() ? it->second : true; |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void HostZoomMapImpl::ClearPageScaleFactorIsOneForView(int render_process_id, |
| 433 | int render_view_id) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 434 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 435 | view_page_scale_factors_are_one_.erase( |
| 436 | RenderViewKey(render_process_id, render_view_id)); |
| 437 | } |
| 438 | |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 439 | bool HostZoomMapImpl::UsesTemporaryZoomLevel(int render_process_id, |
| 440 | int render_view_id) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 441 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 442 | RenderViewKey key(render_process_id, render_view_id); |
skyostil | 66bd6791 | 2016-08-12 12:33:11 | [diff] [blame] | 443 | return base::ContainsKey(temporary_zoom_levels_, key); |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 444 | } |
| 445 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 446 | double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, |
| 447 | int render_view_id) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 448 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 449 | RenderViewKey key(render_process_id, render_view_id); |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 450 | const auto it = temporary_zoom_levels_.find(key); |
| 451 | return it != temporary_zoom_levels_.end() ? it->second : 0; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 454 | void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id, |
| 455 | int render_view_id, |
| 456 | double level) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 457 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 458 | |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 459 | RenderViewKey key(render_process_id, render_view_id); |
| 460 | temporary_zoom_levels_[key] = level; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 461 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 462 | WebContentsImpl* web_contents = |
| 463 | static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( |
| 464 | RenderViewHost::FromID(render_process_id, render_view_id))); |
| 465 | web_contents->SetTemporaryZoomLevel(level, true); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 466 | |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 467 | HostZoomMap::ZoomLevelChange change; |
| 468 | change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM; |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 469 | change.host = GetHostFromProcessView(render_process_id, render_view_id); |
[email protected] | 367c5c1d | 2013-03-11 18:59:02 | [diff] [blame] | 470 | change.zoom_level = level; |
| 471 | |
[email protected] | 11783281 | 2013-10-02 07:06:02 | [diff] [blame] | 472 | zoom_level_changed_callbacks_.Notify(change); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 473 | } |
| 474 | |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 475 | double HostZoomMapImpl::GetZoomLevelForView(const GURL& url, |
| 476 | int render_process_id, |
| 477 | int render_view_id) const { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 478 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 479 | RenderViewKey key(render_process_id, render_view_id); |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 480 | |
skyostil | 66bd6791 | 2016-08-12 12:33:11 | [diff] [blame] | 481 | if (base::ContainsKey(temporary_zoom_levels_, key)) |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 482 | return temporary_zoom_levels_.find(key)->second; |
| 483 | |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 484 | return GetZoomLevelForHostAndScheme(url.scheme(), |
| 485 | net::GetHostOrSpecFromURL(url)); |
wjmaclean | c6249049 | 2015-02-13 22:02:07 | [diff] [blame] | 486 | } |
| 487 | |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 488 | void HostZoomMapImpl::ClearZoomLevels(base::Time delete_begin, |
| 489 | base::Time delete_end) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 490 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 491 | double default_zoom_level = GetDefaultZoomLevel(); |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 492 | for (const auto& zoom_level : GetAllZoomLevels()) { |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 493 | if (zoom_level.scheme.empty() && delete_begin <= zoom_level.last_modified && |
| 494 | (delete_end.is_null() || zoom_level.last_modified < delete_end)) { |
| 495 | SetZoomLevelForHost(zoom_level.host, default_zoom_level); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | void HostZoomMapImpl::SetStoreLastModified(bool store_last_modified) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 501 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 502 | store_last_modified_ = store_last_modified; |
| 503 | } |
| 504 | |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 505 | void HostZoomMapImpl::ClearTemporaryZoomLevel(int render_process_id, |
| 506 | int render_view_id) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 507 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 508 | RenderViewKey key(render_process_id, render_view_id); |
| 509 | TemporaryZoomLevels::iterator it = temporary_zoom_levels_.find(key); |
| 510 | if (it == temporary_zoom_levels_.end()) |
| 511 | return; |
| 512 | |
| 513 | temporary_zoom_levels_.erase(it); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 514 | WebContentsImpl* web_contents = |
| 515 | static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost( |
| 516 | RenderViewHost::FromID(render_process_id, render_view_id))); |
| 517 | web_contents->SetTemporaryZoomLevel(GetZoomLevelForHost( |
| 518 | GetHostFromProcessView(render_process_id, render_view_id)), false); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void HostZoomMapImpl::SendZoomLevelChange(const std::string& scheme, |
| 522 | const std::string& host, |
| 523 | double level) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 524 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 525 | // We'll only send to WebContents not using temporary zoom levels. The one |
| 526 | // other case of interest is where the renderer is hosting a plugin document; |
| 527 | // that should be reflected in our temporary zoom level map, but we will |
| 528 | // double check on the renderer side to avoid the possibility of any races. |
vmpstr | 10e0d5f | 2016-07-21 23:46:09 | [diff] [blame] | 529 | for (auto* web_contents : WebContentsImpl::GetAllWebContents()) { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 530 | // Only send zoom level changes to WebContents that are using this |
| 531 | // HostZoomMap. |
| 532 | if (GetForWebContents(web_contents) != this) |
| 533 | continue; |
| 534 | |
Lukasz Anforowicz | c773bbd | 2017-10-02 19:25:29 | [diff] [blame] | 535 | int render_process_id = |
| 536 | web_contents->GetRenderViewHost()->GetProcess()->GetID(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 537 | int render_view_id = web_contents->GetRenderViewHost()->GetRoutingID(); |
| 538 | |
| 539 | if (!UsesTemporaryZoomLevel(render_process_id, render_view_id)) |
| 540 | web_contents->UpdateZoomIfNecessary(scheme, host, level); |
[email protected] | d42bf47 | 2014-06-14 01:49:38 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 544 | void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 545 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
wjmaclean | de29ed5 | 2014-10-28 21:09:06 | [diff] [blame] | 546 | GURL error_url(kUnreachableWebDataURL); |
| 547 | std::string host = net::GetHostOrSpecFromURL(error_url); |
| 548 | double error_page_zoom_level = GetZoomLevelForHost(host); |
| 549 | |
| 550 | SendZoomLevelChange(std::string(), host, error_page_zoom_level); |
| 551 | } |
| 552 | |
Sam McNally | e741fd66 | 2017-08-30 02:07:50 | [diff] [blame] | 553 | void HostZoomMapImpl::WillCloseRenderView(int render_process_id, |
| 554 | int render_view_id) { |
Lei Zhang | 9d40e790 | 2017-11-20 19:54:36 | [diff] [blame] | 555 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Sam McNally | e741fd66 | 2017-08-30 02:07:50 | [diff] [blame] | 556 | ClearTemporaryZoomLevel(render_process_id, render_view_id); |
| 557 | ClearPageScaleFactorIsOneForView(render_process_id, render_view_id); |
| 558 | } |
| 559 | |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 560 | HostZoomMapImpl::~HostZoomMapImpl() { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 561 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 40bd658 | 2009-12-04 23:49:51 | [diff] [blame] | 562 | } |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 563 | |
tzik | 67025f67 | 2017-11-29 05:04:44 | [diff] [blame] | 564 | void HostZoomMapImpl::SetClockForTesting(base::Clock* clock) { |
| 565 | clock_ = clock; |
Christian Dullweber | cc736c1 | 2017-09-04 09:27:50 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 568 | } // namespace content |