| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); | 83 for (RenderProcessHost::iterator i(RenderProcessHost::AllHostsIterator()); |
| 84 !i.IsAtEnd(); i.Advance()) { | 84 !i.IsAtEnd(); i.Advance()) { |
| 85 RenderProcessHost* render_process_host = i.GetCurrentValue(); | 85 RenderProcessHost* render_process_host = i.GetCurrentValue(); |
| 86 if (HostZoomMap::GetForBrowserContext( | 86 if (HostZoomMap::GetForBrowserContext( |
| 87 render_process_host->GetBrowserContext()) == this) { | 87 render_process_host->GetBrowserContext()) == this) { |
| 88 render_process_host->Send( | 88 render_process_host->Send( |
| 89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); | 89 new ViewMsg_SetZoomLevelForCurrentURL(host, level)); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 NotificationService::current()->Notify( | 93 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) |
| 94 NOTIFICATION_ZOOM_LEVEL_CHANGED, | 94 zoom_level_changed_callbacks_[i].Run(host); |
| 95 Source<HostZoomMap>(this), | |
| 96 Details<const std::string>(&host)); | |
| 97 } | 95 } |
| 98 | 96 |
| 99 double HostZoomMapImpl::GetDefaultZoomLevel() const { | 97 double HostZoomMapImpl::GetDefaultZoomLevel() const { |
| 100 return default_zoom_level_; | 98 return default_zoom_level_; |
| 101 } | 99 } |
| 102 | 100 |
| 103 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { | 101 void HostZoomMapImpl::SetDefaultZoomLevel(double level) { |
| 104 default_zoom_level_ = level; | 102 default_zoom_level_ = level; |
| 105 } | 103 } |
| 106 | 104 |
| 105 void HostZoomMapImpl::AddZoomLevelChangedCallback( |
| 106 const ZoomLevelChangedCallback& callback) { |
| 107 zoom_level_changed_callbacks_.push_back(callback); |
| 108 } |
| 109 |
| 110 void HostZoomMapImpl::RemoveZoomLevelChangedCallback( |
| 111 const ZoomLevelChangedCallback& callback) { |
| 112 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) { |
| 113 if (zoom_level_changed_callbacks_[i].Equals(callback)) { |
| 114 zoom_level_changed_callbacks_.erase( |
| 115 zoom_level_changed_callbacks_.begin() + i); |
| 116 return; |
| 117 } |
| 118 } |
| 119 } |
| 120 |
| 107 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, | 121 double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, |
| 108 int render_view_id) const { | 122 int render_view_id) const { |
| 109 base::AutoLock auto_lock(lock_); | 123 base::AutoLock auto_lock(lock_); |
| 110 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { | 124 for (size_t i = 0; i < temporary_zoom_levels_.size(); ++i) { |
| 111 if (temporary_zoom_levels_[i].render_process_id == render_process_id && | 125 if (temporary_zoom_levels_[i].render_process_id == render_process_id && |
| 112 temporary_zoom_levels_[i].render_view_id == render_view_id) { | 126 temporary_zoom_levels_[i].render_view_id == render_view_id) { |
| 113 return temporary_zoom_levels_[i].zoom_level; | 127 return temporary_zoom_levels_[i].zoom_level; |
| 114 } | 128 } |
| 115 } | 129 } |
| 116 return 0; | 130 return 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 138 | 152 |
| 139 if (level && i == temporary_zoom_levels_.size()) { | 153 if (level && i == temporary_zoom_levels_.size()) { |
| 140 TemporaryZoomLevel temp; | 154 TemporaryZoomLevel temp; |
| 141 temp.render_process_id = render_process_id; | 155 temp.render_process_id = render_process_id; |
| 142 temp.render_view_id = render_view_id; | 156 temp.render_view_id = render_view_id; |
| 143 temp.zoom_level = level; | 157 temp.zoom_level = level; |
| 144 temporary_zoom_levels_.push_back(temp); | 158 temporary_zoom_levels_.push_back(temp); |
| 145 } | 159 } |
| 146 } | 160 } |
| 147 | 161 |
| 148 std::string host; | 162 for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) |
| 149 NotificationService::current()->Notify( | 163 zoom_level_changed_callbacks_[i].Run(std::string()); |
| 150 NOTIFICATION_ZOOM_LEVEL_CHANGED, | |
| 151 Source<HostZoomMap>(this), | |
| 152 Details<const std::string>(&host)); | |
| 153 } | 164 } |
| 154 | 165 |
| 155 void HostZoomMapImpl::Observe(int type, | 166 void HostZoomMapImpl::Observe(int type, |
| 156 const NotificationSource& source, | 167 const NotificationSource& source, |
| 157 const NotificationDetails& details) { | 168 const NotificationDetails& details) { |
| 158 switch (type) { | 169 switch (type) { |
| 159 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { | 170 case NOTIFICATION_RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW: { |
| 160 base::AutoLock auto_lock(lock_); | 171 base::AutoLock auto_lock(lock_); |
| 161 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); | 172 int render_view_id = Source<RenderViewHost>(source)->GetRoutingID(); |
| 162 int render_process_id = | 173 int render_process_id = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 173 } | 184 } |
| 174 default: | 185 default: |
| 175 NOTREACHED() << "Unexpected preference observed."; | 186 NOTREACHED() << "Unexpected preference observed."; |
| 176 } | 187 } |
| 177 } | 188 } |
| 178 | 189 |
| 179 HostZoomMapImpl::~HostZoomMapImpl() { | 190 HostZoomMapImpl::~HostZoomMapImpl() { |
| 180 } | 191 } |
| 181 | 192 |
| 182 } // namespace content | 193 } // namespace content |
| OLD | NEW |