| 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 <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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { | 48 void HostZoomMapImpl::CopyFrom(HostZoomMap* copy_interface) { |
| 49 // This can only be called on the UI thread to avoid deadlocks, otherwise | 49 // This can only be called on the UI thread to avoid deadlocks, otherwise |
| 50 // UI: a.CopyFrom(b); | 50 // UI: a.CopyFrom(b); |
| 51 // IO: b.CopyFrom(a); | 51 // IO: b.CopyFrom(a); |
| 52 // can deadlock. | 52 // can deadlock. |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); | 54 HostZoomMapImpl* copy = static_cast<HostZoomMapImpl*>(copy_interface); |
| 55 base::AutoLock auto_lock(lock_); | 55 base::AutoLock auto_lock(lock_); |
| 56 base::AutoLock copy_auto_lock(copy->lock_); | 56 base::AutoLock copy_auto_lock(copy->lock_); |
| 57 for (HostZoomLevels::const_iterator i(copy->host_zoom_levels_.begin()); | 57 host_zoom_levels_. |
| 58 i != copy->host_zoom_levels_.end(); ++i) { | 58 insert(copy->host_zoom_levels_.begin(), copy->host_zoom_levels_.end()); |
| 59 host_zoom_levels_[i->first] = i->second; | 59 for (SchemeHostZoomLevels::const_iterator i(copy-> |
| 60 scheme_host_zoom_levels_.begin()); |
| 61 i != copy->scheme_host_zoom_levels_.end(); ++i) { |
| 62 scheme_host_zoom_levels_[i->first] = HostZoomLevels(); |
| 63 scheme_host_zoom_levels_[i->first]. |
| 64 insert(i->second.begin(), i->second.end()); |
| 60 } | 65 } |
| 61 default_zoom_level_ = copy->default_zoom_level_; | 66 default_zoom_level_ = copy->default_zoom_level_; |
| 62 } | 67 } |
| 63 | 68 |
| 64 double HostZoomMapImpl::GetZoomLevel(const std::string& host) const { | 69 double HostZoomMapImpl::GetZoomLevelForHost(const std::string& host) const { |
| 65 base::AutoLock auto_lock(lock_); | 70 base::AutoLock auto_lock(lock_); |
| 66 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); | 71 HostZoomLevels::const_iterator i(host_zoom_levels_.find(host)); |
| 67 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; | 72 return (i == host_zoom_levels_.end()) ? default_zoom_level_ : i->second; |
| 68 } | 73 } |
| 69 | 74 |
| 70 void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { | 75 double HostZoomMapImpl::GetZoomLevelForHostAndScheme( |
| 76 const std::string& scheme, |
| 77 const std::string& host) const { |
| 78 { |
| 79 base::AutoLock auto_lock(lock_); |
| 80 SchemeHostZoomLevels::const_iterator scheme_iterator( |
| 81 scheme_host_zoom_levels_.find(scheme)); |
| 82 if (scheme_iterator != scheme_host_zoom_levels_.end()) { |
| 83 HostZoomLevels::const_iterator i(scheme_iterator->second.find(host)); |
| 84 if (i != scheme_iterator->second.end()) |
| 85 return i->second; |
| 86 } |
| 87 } |
| 88 return GetZoomLevelForHost(host); |
| 89 } |
| 90 |
| 91 void HostZoomMapImpl::SetZoomLevelForHost(const std::string& host, |
| 92 double level) { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 72 | 94 |
| 73 { | 95 { |
| 74 base::AutoLock auto_lock(lock_); | 96 base::AutoLock auto_lock(lock_); |
| 75 | 97 |
| 76 if (ZoomValuesEqual(level, default_zoom_level_)) | 98 if (ZoomValuesEqual(level, default_zoom_level_)) |
| 77 host_zoom_levels_.erase(host); | 99 host_zoom_levels_.erase(host); |
| 78 else | 100 else |
| 79 host_zoom_levels_[host] = level; | 101 host_zoom_levels_[host] = level; |
| 80 } | 102 } |
| 81 | 103 |
| 82 // Notify renderers from this browser context. | 104 // Notify renderers from this browser context. |
| 83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 105 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 84 !i.IsAtEnd(); i.Advance()) { | 106 !i.IsAtEnd(); i.Advance()) { |
| 85 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 107 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| 86 if (HostZoomMap::GetForBrowserContext( | 108 if (HostZoomMap::GetForBrowserContext( |
| 87 render_process_host->GetBrowserContext()) == this) { | 109 render_process_host->GetBrowserContext()) == this) { |
| 88 render_process_host->Send( | 110 render_process_host->Send( |
| 89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); | 111 new ViewMsg_SetZoomLevelForCurrentURL(std::string(), host, level)); |
| 112 } |
| 113 } |
| 114 HostZoomMap::ZoomLevelChange change; |
| 115 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; |
| 116 change.host = host; |
| 117 change.zoom_level = level; |
| 118 |
| 119 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) |
| 120 zoom_level_changed_callbacks_[i].Run(change); |
| 121 } |
| 122 |
| 123 void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, |
| 124 const std::string& host, |
| 125 double level) { |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 127 { |
| 128 base::AutoLock auto_lock(lock_); |
| 129 scheme_host_zoom_levels_[scheme][host] = level; |
| 130 } |
| 131 |
| 132 // Notify renderers from this browser context. |
| 133 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 134 !i.IsAtEnd(); i.Advance()) { |
| 135 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| 136 if (HostZoomMap::GetForBrowserContext( |
| 137 render_process_host->GetBrowserContext()) == this) { |
| 138 render_process_host->Send( |
| 139 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
| 90 } | 140 } |
| 91 } | 141 } |
| 92 | 142 |
| 143 HostZoomMap::ZoomLevelChange change; |
| 144 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; |
| 145 change.host = host; |
| 146 change.scheme = scheme; |
| 147 change.zoom_level = level; |
| 148 |
| 93 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) | 149 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) |
| 94 zoom_level_changed_callbacks_[i].Run(host); | 150 zoom_level_changed_callbacks_[i].Run(change); |
| 95 } | 151 } |
| 96 | 152 |
| 97 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 153 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
| 98 return default_zoom_level_; | 154 return default_zoom_level_; |
| 99 } | 155 } |
| 100 | 156 |
| 101 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { | 157 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
| 102 default_zoom_level_ = level; | 158 default_zoom_level_ = level; |
| 103 } | 159 } |
| 104 | 160 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 208 |
| 153 if (level && i == temporary_zoom_levels_.size()) { | 209 if (level && i == temporary_zoom_levels_.size()) { |
| 154 TemporaryZoomLevel temp; | 210 TemporaryZoomLevel temp; |
| 155 temp.render_process_id = render_process_id; | 211 temp.render_process_id = render_process_id; |
| 156 temp.render_view_id = render_view_id; | 212 temp.render_view_id = render_view_id; |
| 157 temp.zoom_level = level; | 213 temp.zoom_level = level; |
| 158 temporary_zoom_levels_.push_back(temp); | 214 temporary_zoom_levels_.push_back(temp); |
| 159 } | 215 } |
| 160 } | 216 } |
| 161 | 217 |
| 218 HostZoomMap::ZoomLevelChange change; |
| 219 change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM; |
| 220 change.zoom_level = level; |
| 221 |
| 162 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) | 222 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) |
| 163 zoom_level_changed_callbacks_[i].Run(std::string()); | 223 zoom_level_changed_callbacks_[i].Run(change); |
| 164 } | 224 } |
| 165 | 225 |
| 166 void HostZoomMapImpl::Observe(int type, | 226 void HostZoomMapImpl::Observe(int type, |
| 167 const NotificationSource& source, | 227 const NotificationSource& source, |
| 168 const NotificationDetails& details) { | 228 const NotificationDetails& details) { |
| 169 switch (type) { | 229 switch (type) { |
| 170 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { | 230 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { |
| 171 base::AutoLock auto_lock(lock_); | 231 base::AutoLock auto_lock(lock_); |
| 172 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); | 232 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); |
| 173 int render_process_id = | 233 int render_process_id = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 184 } | 244 } |
| 185 default: | 245 default: |
| 186 NOTREACHED() << "Unexpected preference observed."; | 246 NOTREACHED() << "Unexpected preference observed."; |
| 187 } | 247 } |
| 188 } | 248 } |
| 189 | 249 |
| 190 HostZoomMapImpl::~HostZoomMapImpl() { | 250 HostZoomMapImpl::~HostZoomMapImpl() { |
| 191 } | 251 } |
| 192 | 252 |
| 193 } // namespace content | 253 } // namespace content |
| OLD | NEW |