| 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 13 matching lines...) Expand all Loading... |
| 24 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
| 25 #include "content/public/common/page_zoom.h" | 25 #include "content/public/common/page_zoom.h" |
| 26 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
| 27 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 std::string GetHostFromProcessView(int render_process_id, int render_view_id) { | 33 std::string GetHostFromProcessView(int render_process_id, int render_view_id) { |
| 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 35 RenderViewHost* render_view_host = | 35 RenderViewHost* render_view_host = |
| 36 RenderViewHost::FromID(render_process_id, render_view_id); | 36 RenderViewHost::FromID(render_process_id, render_view_id); |
| 37 if (!render_view_host) | 37 if (!render_view_host) |
| 38 return std::string(); | 38 return std::string(); |
| 39 | 39 |
| 40 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); | 40 WebContents* web_contents = WebContents::FromRenderViewHost(render_view_host); |
| 41 | 41 |
| 42 NavigationEntry* entry = | 42 NavigationEntry* entry = |
| 43 web_contents->GetController().GetLastCommittedEntry(); | 43 web_contents->GetController().GetLastCommittedEntry(); |
| 44 if (!entry) | 44 if (!entry) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 registrar_.Add( | 118 registrar_.Add( |
| 119 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, | 119 this, NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, |
| 120 NotificationService::AllSources()); | 120 NotificationService::AllSources()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { | 123 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { |
| 124 // This can only be called on the UI thread to avoid deadlocks, otherwise | 124 // This can only be called on the UI thread to avoid deadlocks, otherwise |
| 125 // UI: a.CopyFrom(b); | 125 // UI: a.CopyFrom(b); |
| 126 // IO: b.CopyFrom(a); | 126 // IO: b.CopyFrom(a); |
| 127 // can deadlock. | 127 // can deadlock. |
| 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 129 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); | 129 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); |
| 130 base::AutoLock auto_lock(lock_); | 130 base::AutoLock auto_lock(lock_); |
| 131 base::AutoLock copy_auto_lock(copy->lock_); | 131 base::AutoLock copy_auto_lock(copy->lock_); |
| 132 host_zoom_levels_. | 132 host_zoom_levels_. |
| 133 insert(copy->host_zoom_levels_.begin(), copy->host_zoom_levels_.end()); | 133 insert(copy->host_zoom_levels_.begin(), copy->host_zoom_levels_.end()); |
| 134 for (SchemeHostZoomLevels::const_iterator i(copy-> | 134 for (SchemeHostZoomLevels::const_iterator i(copy-> |
| 135 scheme_host_zoom_levels_.begin()); | 135 scheme_host_zoom_levels_.begin()); |
| 136 i != copy->scheme_host_zoom_levels_.end(); ++i) { | 136 i != copy->scheme_host_zoom_levels_.end(); ++i) { |
| 137 scheme_host_zoom_levels_[i->first] = HostZoomLevels(); | 137 scheme_host_zoom_levels_[i->first] = HostZoomLevels(); |
| 138 scheme_host_zoom_levels_[i->first]. | 138 scheme_host_zoom_levels_[i->first]. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 }; | 220 }; |
| 221 result.push_back(change); | 221 result.push_back(change); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 return result; | 225 return result; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void HostZoomMapImpl::SetZoomLevelForHost(const std::string& host, | 228 void HostZoomMapImpl::SetZoomLevelForHost(const std::string& host, |
| 229 double level) { | 229 double level) { |
| 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 231 | 231 |
| 232 { | 232 { |
| 233 base::AutoLock auto_lock(lock_); | 233 base::AutoLock auto_lock(lock_); |
| 234 | 234 |
| 235 if (ZoomValuesEqual(level, default_zoom_level_)) | 235 if (ZoomValuesEqual(level, default_zoom_level_)) |
| 236 host_zoom_levels_.erase(host); | 236 host_zoom_levels_.erase(host); |
| 237 else | 237 else |
| 238 host_zoom_levels_[host] = level; | 238 host_zoom_levels_[host] = level; |
| 239 } | 239 } |
| 240 | 240 |
| 241 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486 | 241 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486 |
| 242 SendZoomLevelChange(std::string(), host, level); | 242 SendZoomLevelChange(std::string(), host, level); |
| 243 | 243 |
| 244 HostZoomMap::ZoomLevelChange change; | 244 HostZoomMap::ZoomLevelChange change; |
| 245 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; | 245 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; |
| 246 change.host = host; | 246 change.host = host; |
| 247 change.zoom_level = level; | 247 change.zoom_level = level; |
| 248 | 248 |
| 249 zoom_level_changed_callbacks_.Notify(change); | 249 zoom_level_changed_callbacks_.Notify(change); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, | 252 void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, |
| 253 const std::string& host, | 253 const std::string& host, |
| 254 double level) { | 254 double level) { |
| 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 255 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 256 { | 256 { |
| 257 base::AutoLock auto_lock(lock_); | 257 base::AutoLock auto_lock(lock_); |
| 258 scheme_host_zoom_levels_[scheme][host] = level; | 258 scheme_host_zoom_levels_[scheme][host] = level; |
| 259 } | 259 } |
| 260 | 260 |
| 261 SendZoomLevelChange(scheme, host, level); | 261 SendZoomLevelChange(scheme, host, level); |
| 262 | 262 |
| 263 HostZoomMap::ZoomLevelChange change; | 263 HostZoomMap::ZoomLevelChange change; |
| 264 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; | 264 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; |
| 265 change.host = host; | 265 change.host = host; |
| 266 change.scheme = scheme; | 266 change.scheme = scheme; |
| 267 change.zoom_level = level; | 267 change.zoom_level = level; |
| 268 | 268 |
| 269 zoom_level_changed_callbacks_.Notify(change); | 269 zoom_level_changed_callbacks_.Notify(change); |
| 270 } | 270 } |
| 271 | 271 |
| 272 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 272 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
| 273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 274 return default_zoom_level_; | 274 return default_zoom_level_; |
| 275 } | 275 } |
| 276 | 276 |
| 277 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { | 277 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
| 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 278 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 279 default_zoom_level_ = level; | 279 default_zoom_level_ = level; |
| 280 } | 280 } |
| 281 | 281 |
| 282 scoped_ptr<HostZoomMap::Subscription> | 282 scoped_ptr<HostZoomMap::Subscription> |
| 283 HostZoomMapImpl::AddZoomLevelChangedCallback( | 283 HostZoomMapImpl::AddZoomLevelChangedCallback( |
| 284 const ZoomLevelChangedCallback& callback) { | 284 const ZoomLevelChangedCallback& callback) { |
| 285 return zoom_level_changed_callbacks_.Add(callback); | 285 return zoom_level_changed_callbacks_.Add(callback); |
| 286 } | 286 } |
| 287 | 287 |
| 288 double HostZoomMapImpl::GetZoomLevelForWebContents( | 288 double HostZoomMapImpl::GetZoomLevelForWebContents( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 RenderViewKey key(render_process_id, render_view_id); | 388 RenderViewKey key(render_process_id, render_view_id); |
| 389 if (!ContainsKey(temporary_zoom_levels_, key)) | 389 if (!ContainsKey(temporary_zoom_levels_, key)) |
| 390 return 0; | 390 return 0; |
| 391 | 391 |
| 392 return temporary_zoom_levels_.find(key)->second; | 392 return temporary_zoom_levels_.find(key)->second; |
| 393 } | 393 } |
| 394 | 394 |
| 395 void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id, | 395 void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id, |
| 396 int render_view_id, | 396 int render_view_id, |
| 397 double level) { | 397 double level) { |
| 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 398 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 399 | 399 |
| 400 { | 400 { |
| 401 RenderViewKey key(render_process_id, render_view_id); | 401 RenderViewKey key(render_process_id, render_view_id); |
| 402 base::AutoLock auto_lock(lock_); | 402 base::AutoLock auto_lock(lock_); |
| 403 temporary_zoom_levels_[key] = level; | 403 temporary_zoom_levels_[key] = level; |
| 404 } | 404 } |
| 405 | 405 |
| 406 RenderViewHost* host = | 406 RenderViewHost* host = |
| 407 RenderViewHost::FromID(render_process_id, render_view_id); | 407 RenderViewHost::FromID(render_process_id, render_view_id); |
| 408 host->Send(new ViewMsg_SetZoomLevelForView(render_view_id, true, level)); | 408 host->Send(new ViewMsg_SetZoomLevelForView(render_view_id, true, level)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 484 |
| 485 void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { | 485 void HostZoomMapImpl::SendErrorPageZoomLevelRefresh() { |
| 486 GURL error_url(kUnreachableWebDataURL); | 486 GURL error_url(kUnreachableWebDataURL); |
| 487 std::string host = net::GetHostOrSpecFromURL(error_url); | 487 std::string host = net::GetHostOrSpecFromURL(error_url); |
| 488 double error_page_zoom_level = GetZoomLevelForHost(host); | 488 double error_page_zoom_level = GetZoomLevelForHost(host); |
| 489 | 489 |
| 490 SendZoomLevelChange(std::string(), host, error_page_zoom_level); | 490 SendZoomLevelChange(std::string(), host, error_page_zoom_level); |
| 491 } | 491 } |
| 492 | 492 |
| 493 HostZoomMapImpl::~HostZoomMapImpl() { | 493 HostZoomMapImpl::~HostZoomMapImpl() { |
| 494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 494 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 495 } | 495 } |
| 496 | 496 |
| 497 } // namespace content | 497 } // namespace content |
| OLD | NEW |