Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/ui/zoom/zoom_controller.cc

Issue 580133002: Update entry page type to include error pages when appropriate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fix for unit_tests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_zoom.h" 15 #include "content/public/common/page_zoom.h"
16 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
17 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 19
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController);
21 21
22 ZoomController::ZoomController(content::WebContents* web_contents) 22 ZoomController::ZoomController(content::WebContents* web_contents)
23 : content::WebContentsObserver(web_contents), 23 : content::WebContentsObserver(web_contents),
24 can_show_bubble_(true), 24 can_show_bubble_(true),
25 zoom_mode_(ZOOM_MODE_DEFAULT), 25 zoom_mode_(ZOOM_MODE_DEFAULT),
26 zoom_level_(1.0), 26 zoom_level_(1.0),
27 browser_context_(web_contents->GetBrowserContext()) { 27 browser_context_(web_contents->GetBrowserContext()),
28 is_error_page_(false) {
28 // TODO(wjmaclean) Make calls to HostZoomMap::GetDefaultForBrowserContext() 29 // TODO(wjmaclean) Make calls to HostZoomMap::GetDefaultForBrowserContext()
29 // refer to the webcontents-specific HostZoomMap when that becomes available. 30 // refer to the webcontents-specific HostZoomMap when that becomes available.
30 content::HostZoomMap* host_zoom_map = 31 content::HostZoomMap* host_zoom_map =
31 content::HostZoomMap::GetDefaultForBrowserContext(browser_context_); 32 content::HostZoomMap::GetDefaultForBrowserContext(browser_context_);
32 zoom_level_ = host_zoom_map->GetDefaultZoomLevel(); 33 zoom_level_ = host_zoom_map->GetDefaultZoomLevel();
33 34
34 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( 35 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback(
35 base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this))); 36 base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this)));
36 37
37 UpdateState(std::string()); 38 UpdateState(std::string());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
81 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on 82 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on
82 // a crashed tab. 83 // a crashed tab or an error page.
83 if (zoom_mode_ == ZOOM_MODE_DISABLED || 84 if (zoom_mode_ == ZOOM_MODE_DISABLED ||
84 !web_contents()->GetRenderViewHost()->IsRenderViewLive()) 85 !web_contents()->GetRenderViewHost()->IsRenderViewLive() ||
86 is_error_page_)
85 return false; 87 return false;
86 88
87 // Store extension data so that |extension| can be attributed when the zoom 89 // 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 90 // change completes. We expect that by the time this function returns that
89 // any observers that require this information will have requested it. 91 // any observers that require this information will have requested it.
90 last_extension_ = extension; 92 last_extension_ = extension;
91 93
92 // Do not actually rescale the page in manual mode. 94 // Do not actually rescale the page in manual mode.
93 if (zoom_mode_ == ZOOM_MODE_MANUAL) { 95 if (zoom_mode_ == ZOOM_MODE_MANUAL) {
94 double old_zoom_level = zoom_level_; 96 double old_zoom_level = zoom_level_;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 render_process_id, render_view_id, GetDefaultZoomLevel()); 234 render_process_id, render_view_id, GetDefaultZoomLevel());
233 break; 235 break;
234 } 236 }
235 } 237 }
236 // Any event data we've stored should have been consumed by this point. 238 // Any event data we've stored should have been consumed by this point.
237 DCHECK(!event_data_); 239 DCHECK(!event_data_);
238 240
239 zoom_mode_ = new_mode; 241 zoom_mode_ = new_mode;
240 } 242 }
241 243
244 void ZoomController::DidCommitProvisionalLoadForFrame(
245 content::RenderFrameHost* render_frame_host,
246 const GURL& url,
247 bool url_is_unreachable,
248 ui::PageTransition transition_type) {
249 is_error_page_ = url_is_unreachable;
250 }
251
242 void ZoomController::DidNavigateMainFrame( 252 void ZoomController::DidNavigateMainFrame(
243 const content::LoadCommittedDetails& details, 253 const content::LoadCommittedDetails& details,
244 const content::FrameNavigateParams& params) { 254 const content::FrameNavigateParams& params) {
245 // If the main frame's content has changed, the new page may have a different 255 // If the main frame's content has changed, the new page may have a different
246 // zoom level from the old one. 256 // zoom level from the old one.
247 UpdateState(std::string()); 257 UpdateState(std::string());
248 } 258 }
249 259
250 void ZoomController::WebContentsDestroyed() { 260 void ZoomController::WebContentsDestroyed() {
251 // At this point we should no longer be sending any zoom events with this 261 // At this point we should no longer be sending any zoom events with this
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } else { 296 } else {
287 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and 297 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and
288 // new zoom levels here? 298 // new zoom levels here?
289 double zoom_level = GetZoomLevel(); 299 double zoom_level = GetZoomLevel();
290 ZoomChangedEventData zoom_change_data( 300 ZoomChangedEventData zoom_change_data(
291 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); 301 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble);
292 FOR_EACH_OBSERVER( 302 FOR_EACH_OBSERVER(
293 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); 303 ZoomObserver, observers_, OnZoomChanged(zoom_change_data));
294 } 304 }
295 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698