| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 render_process_host->GetBrowserContext()) == this) { | 105 render_process_host->GetBrowserContext()) == this) { |
| 106 render_process_host->Send( | 106 render_process_host->Send( |
| 107 new ViewMsg_SetZoomLevelForCurrentURL(std::string(), host, level)); | 107 new ViewMsg_SetZoomLevelForCurrentURL(std::string(), host, level)); |
| 108 } | 108 } |
| 109 } | 109 } |
| 110 HostZoomMap::ZoomLevelChange change; | 110 HostZoomMap::ZoomLevelChange change; |
| 111 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; | 111 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_HOST; |
| 112 change.host = host; | 112 change.host = host; |
| 113 change.zoom_level = level; | 113 change.zoom_level = level; |
| 114 | 114 |
| 115 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) | 115 zoom_level_changed_callbacks_.Notify(change); |
| 116 zoom_level_changed_callbacks_[i].Run(change); | |
| 117 } | 116 } |
| 118 | 117 |
| 119 void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, | 118 void HostZoomMapImpl::SetZoomLevelForHostAndScheme(const std::string& scheme, |
| 120 const std::string& host, | 119 const std::string& host, |
| 121 double level) { | 120 double level) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 123 { | 122 { |
| 124 base::AutoLock auto_lock(lock_); | 123 base::AutoLock auto_lock(lock_); |
| 125 scheme_host_zoom_levels_[scheme][host] = level; | 124 scheme_host_zoom_levels_[scheme][host] = level; |
| 126 } | 125 } |
| 127 | 126 |
| 128 // Notify renderers from this browser context. | 127 // Notify renderers from this browser context. |
| 129 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 128 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 130 !i.IsAtEnd(); i.Advance()) { | 129 !i.IsAtEnd(); i.Advance()) { |
| 131 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 130 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| 132 if (HostZoomMap::GetForBrowserContext( | 131 if (HostZoomMap::GetForBrowserContext( |
| 133 render_process_host->GetBrowserContext()) == this) { | 132 render_process_host->GetBrowserContext()) == this) { |
| 134 render_process_host->Send( | 133 render_process_host->Send( |
| 135 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); | 134 new ViewMsg_SetZoomLevelForCurrentURL(scheme, host, level)); |
| 136 } | 135 } |
| 137 } | 136 } |
| 138 | 137 |
| 139 HostZoomMap::ZoomLevelChange change; | 138 HostZoomMap::ZoomLevelChange change; |
| 140 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; | 139 change.mode = HostZoomMap::ZOOM_CHANGED_FOR_SCHEME_AND_HOST; |
| 141 change.host = host; | 140 change.host = host; |
| 142 change.scheme = scheme; | 141 change.scheme = scheme; |
| 143 change.zoom_level = level; | 142 change.zoom_level = level; |
| 144 | 143 |
| 145 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) | 144 zoom_level_changed_callbacks_.Notify(change); |
| 146 zoom_level_changed_callbacks_[i].Run(change); | |
| 147 } | 145 } |
| 148 | 146 |
| 149 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 147 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
| 150 return default_zoom_level_; | 148 return default_zoom_level_; |
| 151 } | 149 } |
| 152 | 150 |
| 153 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { | 151 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
| 154 default_zoom_level_ = level; | 152 default_zoom_level_ = level; |
| 155 } | 153 } |
| 156 | 154 |
| 157 void HostZoomMapImpl::AddZoomLevelChangedCallback( | 155 scoped_ptr<HostZoomMap::Subscription> |
| 156 HostZoomMapImpl::AddZoomLevelChangedCallback( |
| 158 const ZoomLevelChangedCallback& callback) { | 157 const ZoomLevelChangedCallback& callback) { |
| 159 zoom_level_changed_callbacks_.push_back(callback); | 158 return zoom_level_changed_callbacks_.Add(callback); |
| 160 } | |
| 161 | |
| 162 void HostZoomMapImpl::RemoveZoomLevelChangedCallback( | |
| 163 const ZoomLevelChangedCallback& callback) { | |
| 164 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) { | |
| 165 if (zoom_level_changed_callbacks_[i].Equals(callback)) { | |
| 166 zoom_level_changed_callbacks_.erase( | |
| 167 zoom_level_changed_callbacks_.begin() + i); | |
| 168 return; | |
| 169 } | |
| 170 } | |
| 171 } | 159 } |
| 172 | 160 |
| 173 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, | 161 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, |
| 174 int render_view_id) const { | 162 int render_view_id) const { |
| 175 base::AutoLock auto_lock(lock_); | 163 base::AutoLock auto_lock(lock_); |
| 176 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { | 164 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { |
| 177 if (temporary_zoom_levels_[i].render_process_id == render_process_id && | 165 if (temporary_zoom_levels_[i].render_process_id == render_process_id && |
| 178 temporary_zoom_levels_[i].render_view_id == render_view_id) { | 166 temporary_zoom_levels_[i].render_view_id == render_view_id) { |
| 179 return temporary_zoom_levels_[i].zoom_level; | 167 return temporary_zoom_levels_[i].zoom_level; |
| 180 } | 168 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 208 temp.render_view_id = render_view_id; | 196 temp.render_view_id = render_view_id; |
| 209 temp.zoom_level = level; | 197 temp.zoom_level = level; |
| 210 temporary_zoom_levels_.push_back(temp); | 198 temporary_zoom_levels_.push_back(temp); |
| 211 } | 199 } |
| 212 } | 200 } |
| 213 | 201 |
| 214 HostZoomMap::ZoomLevelChange change; | 202 HostZoomMap::ZoomLevelChange change; |
| 215 change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM; | 203 change.mode = HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM; |
| 216 change.zoom_level = level; | 204 change.zoom_level = level; |
| 217 | 205 |
| 218 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) | 206 zoom_level_changed_callbacks_.Notify(change); |
| 219 zoom_level_changed_callbacks_[i].Run(change); | |
| 220 } | 207 } |
| 221 | 208 |
| 222 void HostZoomMapImpl::Observe(int type, | 209 void HostZoomMapImpl::Observe(int type, |
| 223 const NotificationSource& source, | 210 const NotificationSource& source, |
| 224 const NotificationDetails& details) { | 211 const NotificationDetails& details) { |
| 225 switch (type) { | 212 switch (type) { |
| 226 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { | 213 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { |
| 227 base::AutoLock auto_lock(lock_); | 214 base::AutoLock auto_lock(lock_); |
| 228 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); | 215 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); |
| 229 int render_process_id = | 216 int render_process_id = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 240 } | 227 } |
| 241 default: | 228 default: |
| 242 NOTREACHED() << "Unexpected preference observed."; | 229 NOTREACHED() << "Unexpected preference observed."; |
| 243 } | 230 } |
| 244 } | 231 } |
| 245 | 232 |
| 246 HostZoomMapImpl::~HostZoomMapImpl() { | 233 HostZoomMapImpl::~HostZoomMapImpl() { |
| 247 } | 234 } |
| 248 | 235 |
| 249 } // namespace content | 236 } // namespace content |
| OLD | NEW |