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

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: Fix content_browsertests compilation. Created 6 years, 2 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_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),
25 zoom_mode_(ZOOM_MODE_DEFAULT), 26 zoom_mode_(ZOOM_MODE_DEFAULT),
26 zoom_level_(1.0), 27 zoom_level_(1.0),
27 browser_context_(web_contents->GetBrowserContext()) { 28 browser_context_(web_contents->GetBrowserContext()),
29 is_error_page_(false) {
28 // TODO(wjmaclean) Make calls to HostZoomMap::GetDefaultForBrowserContext() 30 // TODO(wjmaclean) Make calls to HostZoomMap::GetDefaultForBrowserContext()
29 // refer to the webcontents-specific HostZoomMap when that becomes available. 31 // refer to the webcontents-specific HostZoomMap when that becomes available.
30 content::HostZoomMap* host_zoom_map = 32 content::HostZoomMap* host_zoom_map =
31 content::HostZoomMap::GetDefaultForBrowserContext(browser_context_); 33 content::HostZoomMap::GetDefaultForBrowserContext(browser_context_);
32 zoom_level_ = host_zoom_map->GetDefaultZoomLevel(); 34 zoom_level_ = host_zoom_map->GetDefaultZoomLevel();
33 35
34 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback( 36 zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback(
35 base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this))); 37 base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this)));
36 38
37 UpdateState(std::string()); 39 UpdateState(std::string());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 74
73 bool ZoomController::SetZoomLevel(double zoom_level) { 75 bool ZoomController::SetZoomLevel(double zoom_level) {
74 // An extension did not initiate this zoom change. 76 // An extension did not initiate this zoom change.
75 return SetZoomLevelByExtension(zoom_level, NULL); 77 return SetZoomLevelByExtension(zoom_level, NULL);
76 } 78 }
77 79
78 bool ZoomController::SetZoomLevelByExtension( 80 bool ZoomController::SetZoomLevelByExtension(
79 double zoom_level, 81 double zoom_level,
80 const scoped_refptr<const extensions::Extension>& extension) { 82 const scoped_refptr<const extensions::Extension>& extension) {
81 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on 83 // Cannot zoom in disabled mode. Also, don't allow changing zoom level on
82 // a crashed tab. 84 // a crashed tab or an error page.
83 if (zoom_mode_ == ZOOM_MODE_DISABLED || 85 if (zoom_mode_ == ZOOM_MODE_DISABLED ||
84 !web_contents()->GetRenderViewHost()->IsRenderViewLive()) 86 !web_contents()->GetRenderViewHost()->IsRenderViewLive() ||
87 is_error_page_)
85 return false; 88 return false;
86 89
87 // 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
88 // 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
89 // any observers that require this information will have requested it. 92 // any observers that require this information will have requested it.
90 last_extension_ = extension; 93 last_extension_ = extension;
91 94
92 // Do not actually rescale the page in manual mode. 95 // Do not actually rescale the page in manual mode.
93 if (zoom_mode_ == ZOOM_MODE_MANUAL) { 96 if (zoom_mode_ == ZOOM_MODE_MANUAL) {
94 double old_zoom_level = zoom_level_; 97 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()); 235 render_process_id, render_view_id, GetDefaultZoomLevel());
233 break; 236 break;
234 } 237 }
235 } 238 }
236 // Any event data we've stored should have been consumed by this point. 239 // Any event data we've stored should have been consumed by this point.
237 DCHECK(!event_data_); 240 DCHECK(!event_data_);
238 241
239 zoom_mode_ = new_mode; 242 zoom_mode_ = new_mode;
240 } 243 }
241 244
245 void ZoomController::DidCommitProvisionalLoadForFrame(
246 content::RenderFrameHost* render_frame_host,
247 const GURL& url,
248 bool url_is_unreachable,
249 ui::PageTransition transition_type) {
250 is_error_page_ = url_is_unreachable;
251 }
252
242 void ZoomController::DidNavigateMainFrame( 253 void ZoomController::DidNavigateMainFrame(
243 const content::LoadCommittedDetails& details, 254 const content::LoadCommittedDetails& details,
244 const content::FrameNavigateParams& params) { 255 const content::FrameNavigateParams& params) {
245 // If the main frame's content has changed, the new page may have a different 256 // If the main frame's content has changed, the new page may have a different
246 // zoom level from the old one. 257 // zoom level from the old one.
247 UpdateState(std::string()); 258 UpdateState(std::string());
248 } 259 }
249 260
250 void ZoomController::WebContentsDestroyed() { 261 void ZoomController::WebContentsDestroyed() {
251 // At this point we should no longer be sending any zoom events with this 262 // 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 { 297 } else {
287 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and 298 // TODO(wjmaclean) Should we consider having HostZoomMap send both old and
288 // new zoom levels here? 299 // new zoom levels here?
289 double zoom_level = GetZoomLevel(); 300 double zoom_level = GetZoomLevel();
290 ZoomChangedEventData zoom_change_data( 301 ZoomChangedEventData zoom_change_data(
291 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble); 302 web_contents(), zoom_level, zoom_level, zoom_mode_, can_show_bubble);
292 FOR_EACH_OBSERVER( 303 FOR_EACH_OBSERVER(
293 ZoomObserver, observers_, OnZoomChanged(zoom_change_data)); 304 ZoomObserver, observers_, OnZoomChanged(zoom_change_data));
294 } 305 }
295 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698