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 "chrome/browser/ui/zoom/zoom_controller.h" | 5 #include "chrome/browser/ui/zoom/zoom_controller.h" |
6 | 6 |
7 #include "chrome/browser/ui/sad_tab.h" | 7 #include "chrome/browser/ui/sad_tab.h" |
8 #include "chrome/browser/ui/zoom/zoom_event_manager.h" | 8 #include "chrome/browser/ui/zoom/zoom_event_manager.h" |
9 #include "chrome/browser/ui/zoom/zoom_observer.h" | 9 #include "chrome/browser/ui/zoom/zoom_observer.h" |
10 #include "content/public/browser/host_zoom_map.h" | 10 #include "content/public/browser/host_zoom_map.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 bool ZoomController::SetZoomLevel(double zoom_level) { | 74 bool ZoomController::SetZoomLevel(double zoom_level) { |
75 // An extension did not initiate this zoom change. | 75 // An extension did not initiate this zoom change. |
76 return SetZoomLevelByExtension(zoom_level, NULL); | 76 return SetZoomLevelByExtension(zoom_level, NULL); |
77 } | 77 } |
78 | 78 |
79 bool ZoomController::SetZoomLevelByExtension( | 79 bool ZoomController::SetZoomLevelByExtension( |
80 double zoom_level, | 80 double zoom_level, |
81 const scoped_refptr<const extensions::Extension>& extension) { | 81 const scoped_refptr<const extensions::Extension>& extension) { |
82 content::NavigationEntry* entry = | 82 content::NavigationEntry* entry = |
83 web_contents()->GetController().GetLastCommittedEntry(); | 83 web_contents()->GetController().GetLastCommittedEntry(); |
84 bool is_normal_page = | |
85 entry && entry->GetPageType() == content::PAGE_TYPE_NORMAL; | |
86 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on | 84 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on |
87 // a crashed tab, an error page or an interstitial page. | 85 // a crashed tab, an error page or an interstitial page. |
88 if (zoom_mode_ == ZOOM_MODE_DISABLED || | 86 if (zoom_mode_ == ZOOM_MODE_DISABLED || |
89 !web_contents()->GetRenderViewHost()->IsRenderViewLive() || | 87 !web_contents()->GetRenderViewHost()->IsRenderViewLive()) |
90 !is_normal_page) | |
91 return false; | 88 return false; |
92 | 89 |
93 // Store extension data so that |extension| can be attributed when the zoom | 90 // Store extension data so that |extension| can be attributed when the zoom |
94 // change completes. We expect that by the time this function returns that | 91 // change completes. We expect that by the time this function returns that |
95 // any observers that require this information will have requested it. | 92 // any observers that require this information will have requested it. |
96 last_extension_ = extension; | 93 last_extension_ = extension; |
97 | 94 |
98 // Do not actually rescale the page in manual mode. | 95 // Do not actually rescale the page in manual mode. |
99 if (zoom_mode_ == ZOOM_MODE_MANUAL) { | 96 if (zoom_mode_ == ZOOM_MODE_MANUAL) { |
100 double old_zoom_level = zoom_level_; | 97 double old_zoom_level = zoom_level_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); | 129 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); |
133 if (zoom_mode_ == ZOOM_MODE_ISOLATED || | 130 if (zoom_mode_ == ZOOM_MODE_ISOLATED || |
134 zoom_map->UsesTemporaryZoomLevel(render_process_id, render_view_id)) { | 131 zoom_map->UsesTemporaryZoomLevel(render_process_id, render_view_id)) { |
135 zoom_map->SetTemporaryZoomLevel( | 132 zoom_map->SetTemporaryZoomLevel( |
136 render_process_id, render_view_id, zoom_level); | 133 render_process_id, render_view_id, zoom_level); |
137 } else { | 134 } else { |
138 if (!entry) { | 135 if (!entry) { |
139 last_extension_ = NULL; | 136 last_extension_ = NULL; |
140 return false; | 137 return false; |
141 } | 138 } |
142 std::string host = net::GetHostOrSpecFromURL(entry->GetURL()); | 139 std::string host = |
| 140 net::GetHostOrSpecFromURL(content::HostZoomMap::GetURLFromEntry(entry)); |
143 zoom_map->SetZoomLevelForHost(host, zoom_level); | 141 zoom_map->SetZoomLevelForHost(host, zoom_level); |
144 } | 142 } |
145 | 143 |
146 DCHECK(!event_data_); | 144 DCHECK(!event_data_); |
147 last_extension_ = NULL; | 145 last_extension_ = NULL; |
148 return true; | 146 return true; |
149 } | 147 } |
150 | 148 |
151 void ZoomController::SetZoomMode(ZoomMode new_mode) { | 149 void ZoomController::SetZoomMode(ZoomMode new_mode) { |
152 if (new_mode == zoom_mode_) | 150 if (new_mode == zoom_mode_) |
(...skipping 12 matching lines...) Expand all Loading... |
165 original_zoom_level, | 163 original_zoom_level, |
166 new_mode, | 164 new_mode, |
167 new_mode != ZOOM_MODE_DEFAULT)); | 165 new_mode != ZOOM_MODE_DEFAULT)); |
168 | 166 |
169 switch (new_mode) { | 167 switch (new_mode) { |
170 case ZOOM_MODE_DEFAULT: { | 168 case ZOOM_MODE_DEFAULT: { |
171 content::NavigationEntry* entry = | 169 content::NavigationEntry* entry = |
172 web_contents()->GetController().GetLastCommittedEntry(); | 170 web_contents()->GetController().GetLastCommittedEntry(); |
173 | 171 |
174 if (entry) { | 172 if (entry) { |
175 GURL url = entry->GetURL(); | 173 GURL url = content::HostZoomMap::GetURLFromEntry(entry); |
176 std::string host = net::GetHostOrSpecFromURL(url); | 174 std::string host = net::GetHostOrSpecFromURL(url); |
177 | 175 |
178 if (zoom_map->HasZoomLevel(url.scheme(), host)) { | 176 if (zoom_map->HasZoomLevel(url.scheme(), host)) { |
179 // If there are other tabs with the same origin, then set this tab's | 177 // If there are other tabs with the same origin, then set this tab's |
180 // zoom level to match theirs. The temporary zoom level will be | 178 // zoom level to match theirs. The temporary zoom level will be |
181 // cleared below, but this call will make sure this tab re-draws at | 179 // cleared below, but this call will make sure this tab re-draws at |
182 // the correct zoom level. | 180 // the correct zoom level. |
183 double origin_zoom_level = | 181 double origin_zoom_level = |
184 zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), host); | 182 zoom_map->GetZoomLevelForHostAndScheme(url.scheme(), host); |
185 event_data_->new_zoom_level = origin_zoom_level; | 183 event_data_->new_zoom_level = origin_zoom_level; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 260 } |
263 | 261 |
264 void ZoomController::UpdateState(const std::string& host) { | 262 void ZoomController::UpdateState(const std::string& host) { |
265 // If |host| is empty, all observers should be updated. | 263 // If |host| is empty, all observers should be updated. |
266 if (!host.empty()) { | 264 if (!host.empty()) { |
267 // Use the navigation entry's URL instead of the WebContents' so virtual | 265 // Use the navigation entry's URL instead of the WebContents' so virtual |
268 // URLs work (e.g. chrome://settings). http://crbug.com/153950 | 266 // URLs work (e.g. chrome://settings). http://crbug.com/153950 |
269 content::NavigationEntry* entry = | 267 content::NavigationEntry* entry = |
270 web_contents()->GetController().GetLastCommittedEntry(); | 268 web_contents()->GetController().GetLastCommittedEntry(); |
271 if (!entry || | 269 if (!entry || |
272 host != net::GetHostOrSpecFromURL(entry->GetURL())) { | 270 host != net::GetHostOrSpecFromURL( |
| 271 content::HostZoomMap::GetURLFromEntry(entry))) { |
273 return; | 272 return; |
274 } | 273 } |
275 } | 274 } |
276 | 275 |
277 // The zoom bubble should not be shown for zoom changes where the host is | 276 // The zoom bubble should not be shown for zoom changes where the host is |
278 // empty. | 277 // empty. |
279 bool can_show_bubble = can_show_bubble_ && !host.empty(); | 278 bool can_show_bubble = can_show_bubble_ && !host.empty(); |
280 | 279 |
281 if (event_data_) { | 280 if (event_data_) { |
282 // For state changes initiated within the ZoomController, information about | 281 // For state changes initiated within the ZoomController, information about |
283 // the change should be sent. | 282 // the change should be sent. |
284 ZoomChangedEventData zoom_change_data = *event_data_; | 283 ZoomChangedEventData zoom_change_data = *event_data_; |
285 event_data_.reset(); | 284 event_data_.reset(); |
286 zoom_change_data.can_show_bubble = can_show_bubble; | 285 zoom_change_data.can_show_bubble = can_show_bubble; |
287 FOR_EACH_OBSERVER( | 286 FOR_EACH_OBSERVER( |
288 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 287 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
289 } else { | 288 } else { |
290 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and | 289 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and |
291 // new zoom levels here? | 290 // new zoom levels here? |
292 double zoom_level = GetZoomLevel(); | 291 double zoom_level = GetZoomLevel(); |
293 ZoomChangedEventData zoom_change_data( | 292 ZoomChangedEventData zoom_change_data( |
294 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); | 293 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); |
295 FOR_EACH_OBSERVER( | 294 FOR_EACH_OBSERVER( |
296 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 295 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
297 } | 296 } |
298 } | 297 } |
OLD | NEW |