| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 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 = |
| 83 web_contents()->GetController().GetLastCommittedEntry(); |
| 82 bool is_normal_page = | 84 bool is_normal_page = |
| 83 web_contents()->GetController().GetLastCommittedEntry()->GetPageType() == | 85 entry && entry->GetPageType() == content::PAGE_TYPE_NORMAL; |
| 84 content::PAGE_TYPE_NORMAL; | |
| 85 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on | 86 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on |
| 86 // a crashed tab, an error page or an interstitial page. | 87 // a crashed tab, an error page or an interstitial page. |
| 87 if (zoom_mode_ == ZOOM_MODE_DISABLED || | 88 if (zoom_mode_ == ZOOM_MODE_DISABLED || |
| 88 !web_contents()->GetRenderViewHost()->IsRenderViewLive() || | 89 !web_contents()->GetRenderViewHost()->IsRenderViewLive() || |
| 89 !is_normal_page) | 90 !is_normal_page) |
| 90 return false; | 91 return false; |
| 91 | 92 |
| 92 // Store extension data so that |extension| can be attributed when the zoom | 93 // Store extension data so that |extension| can be attributed when the zoom |
| 93 // change completes. We expect that by the time this function returns that | 94 // change completes. We expect that by the time this function returns that |
| 94 // any observers that require this information will have requested it. | 95 // any observers that require this information will have requested it. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 zoom_level, | 128 zoom_level, |
| 128 zoom_mode_, | 129 zoom_mode_, |
| 129 false /* can_show_bubble */)); | 130 false /* can_show_bubble */)); |
| 130 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); | 131 int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); |
| 131 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); | 132 int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); |
| 132 if (zoom_mode_ == ZOOM_MODE_ISOLATED || | 133 if (zoom_mode_ == ZOOM_MODE_ISOLATED || |
| 133 zoom_map->UsesTemporaryZoomLevel(render_process_id, render_view_id)) { | 134 zoom_map->UsesTemporaryZoomLevel(render_process_id, render_view_id)) { |
| 134 zoom_map->SetTemporaryZoomLevel( | 135 zoom_map->SetTemporaryZoomLevel( |
| 135 render_process_id, render_view_id, zoom_level); | 136 render_process_id, render_view_id, zoom_level); |
| 136 } else { | 137 } else { |
| 137 content::NavigationEntry* entry = | |
| 138 web_contents()->GetController().GetLastCommittedEntry(); | |
| 139 | |
| 140 if (!entry) { | 138 if (!entry) { |
| 141 last_extension_ = NULL; | 139 last_extension_ = NULL; |
| 142 return false; | 140 return false; |
| 143 } | 141 } |
| 144 std::string host = net::GetHostOrSpecFromURL(entry->GetURL()); | 142 std::string host = net::GetHostOrSpecFromURL(entry->GetURL()); |
| 145 zoom_map->SetZoomLevelForHost(host, zoom_level); | 143 zoom_map->SetZoomLevelForHost(host, zoom_level); |
| 146 } | 144 } |
| 147 | 145 |
| 148 DCHECK(!event_data_); | 146 DCHECK(!event_data_); |
| 149 last_extension_ = NULL; | 147 last_extension_ = NULL; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } else { | 289 } else { |
| 292 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and | 290 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and |
| 293 // new zoom levels here? | 291 // new zoom levels here? |
| 294 double zoom_level = GetZoomLevel(); | 292 double zoom_level = GetZoomLevel(); |
| 295 ZoomChangedEventData zoom_change_data( | 293 ZoomChangedEventData zoom_change_data( |
| 296 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); | 294 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); |
| 297 FOR_EACH_OBSERVER( | 295 FOR_EACH_OBSERVER( |
| 298 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 296 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
| 299 } | 297 } |
| 300 } | 298 } |
| OLD | NEW |