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" |
11 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/page_type.h" |
15 #include "content/public/common/page_zoom.h" | 16 #include "content/public/common/page_zoom.h" |
16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
17 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
19 | 20 |
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); | 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); |
21 | 22 |
22 ZoomController::ZoomController(content::WebContents* web_contents) | 23 ZoomController::ZoomController(content::WebContents* web_contents) |
23 : content::WebContentsObserver(web_contents), | 24 : content::WebContentsObserver(web_contents), |
24 can_show_bubble_(true), | 25 can_show_bubble_(true), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 72 } |
72 | 73 |
73 bool ZoomController::SetZoomLevel(double zoom_level) { | 74 bool ZoomController::SetZoomLevel(double zoom_level) { |
74 // An extension did not initiate this zoom change. | 75 // An extension did not initiate this zoom change. |
75 return SetZoomLevelByExtension(zoom_level, NULL); | 76 return SetZoomLevelByExtension(zoom_level, NULL); |
76 } | 77 } |
77 | 78 |
78 bool ZoomController::SetZoomLevelByExtension( | 79 bool ZoomController::SetZoomLevelByExtension( |
79 double zoom_level, | 80 double zoom_level, |
80 const scoped_refptr<const extensions::Extension>& extension) { | 81 const scoped_refptr<const extensions::Extension>& extension) { |
| 82 bool is_error_page = |
| 83 web_contents()->GetController().GetLastCommittedEntry()->GetPageType() == |
| 84 content::PAGE_TYPE_ERROR; |
81 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on | 85 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on |
82 // a crashed tab. | 86 // a crashed tab or an error page. |
83 if (zoom_mode_ == ZOOM_MODE_DISABLED || | 87 if (zoom_mode_ == ZOOM_MODE_DISABLED || |
84 !web_contents()->GetRenderViewHost()->IsRenderViewLive()) | 88 !web_contents()->GetRenderViewHost()->IsRenderViewLive() || |
| 89 is_error_page) |
85 return false; | 90 return false; |
86 | 91 |
87 // Store extension data so that |extension| can be attributed when the zoom | 92 // Store extension data so that |extension| can be attributed when the zoom |
88 // change completes. We expect that by the time this function returns that | 93 // change completes. We expect that by the time this function returns that |
89 // any observers that require this information will have requested it. | 94 // any observers that require this information will have requested it. |
90 last_extension_ = extension; | 95 last_extension_ = extension; |
91 | 96 |
92 // Do not actually rescale the page in manual mode. | 97 // Do not actually rescale the page in manual mode. |
93 if (zoom_mode_ == ZOOM_MODE_MANUAL) { | 98 if (zoom_mode_ == ZOOM_MODE_MANUAL) { |
94 double old_zoom_level = zoom_level_; | 99 double old_zoom_level = zoom_level_; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } else { | 291 } else { |
287 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and | 292 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and |
288 // new zoom levels here? | 293 // new zoom levels here? |
289 double zoom_level = GetZoomLevel(); | 294 double zoom_level = GetZoomLevel(); |
290 ZoomChangedEventData zoom_change_data( | 295 ZoomChangedEventData zoom_change_data( |
291 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); | 296 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); |
292 FOR_EACH_OBSERVER( | 297 FOR_EACH_OBSERVER( |
293 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); | 298 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); |
294 } | 299 } |
295 } | 300 } |
OLD | NEW |