Make sure WebContents passed to chrome_page_zoom::Zoom() have a ZoomController.

Not all WebContents will be zoomed by chrome_page_zoom::Zoom(), but
those that are need to have a ZoomCOntroller. It is assumed that at
the point at which the WebContents is created it should be known if
it will be passed into chrome_page_zoom::Zoom(), so the ZoomController
is created at that point.

BUG=391708

Review URL: https://codereview.chromium.org/373733003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282221 0039d316-1c4b-4281-b951-d872f2087c98
parent bab2b4c1
...@@ -69,6 +69,7 @@ std::vector<double> PresetZoomLevels(double custom_level) { ...@@ -69,6 +69,7 @@ std::vector<double> PresetZoomLevels(double custom_level) {
void Zoom(content::WebContents* web_contents, content::PageZoom zoom) { void Zoom(content::WebContents* web_contents, content::PageZoom zoom) {
ZoomController* zoom_controller = ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents); ZoomController::FromWebContents(web_contents);
DCHECK(zoom_controller);
double current_zoom_level = zoom_controller->GetZoomLevel(); double current_zoom_level = zoom_controller->GetZoomLevel();
double default_zoom_level = double default_zoom_level =
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/webui/devtools_ui.h" #include "chrome/browser/ui/webui/devtools_ui.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
...@@ -707,6 +708,11 @@ DevToolsWindow::DevToolsWindow(Profile* profile, ...@@ -707,6 +708,11 @@ DevToolsWindow::DevToolsWindow(Profile* profile,
DevToolsUIBindings::ApplyThemeToURL(profile, url)); DevToolsUIBindings::ApplyThemeToURL(profile, url));
// Bindings take ownership over devtools as its delegate. // Bindings take ownership over devtools as its delegate.
bindings_->SetDelegate(this); bindings_->SetDelegate(this);
// DevTools uses chrome_page_zoom::Zoom(), so main_web_contents_ requires a
// ZoomController.
ZoomController::CreateForWebContents(main_web_contents_);
ZoomController::FromWebContents(main_web_contents_)
->SetShowsNotificationBubble(false);
g_instances.Get().push_back(this); g_instances.Get().push_back(this);
......
...@@ -1846,7 +1846,7 @@ void Browser::OnZoomChanged(const ZoomController::ZoomChangedEventData& data) { ...@@ -1846,7 +1846,7 @@ void Browser::OnZoomChanged(const ZoomController::ZoomChangedEventData& data) {
if (data.web_contents == tab_strip_model_->GetActiveWebContents()) { if (data.web_contents == tab_strip_model_->GetActiveWebContents()) {
// Only show the zoom bubble for zoom changes in the active window. // Only show the zoom bubble for zoom changes in the active window.
window_->ZoomChangedForActiveTab(data.can_show_bubble && window_->ZoomChangedForActiveTab(data.can_show_bubble &&
window_->IsActive() && !is_devtools()); window_->IsActive());
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h" #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
#include "content/public/browser/invalidate_type.h" #include "content/public/browser/invalidate_type.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -54,6 +55,9 @@ void PanelHost::Init(const GURL& url) { ...@@ -54,6 +55,9 @@ void PanelHost::Init(const GURL& url) {
web_contents_.reset(content::WebContents::Create(create_params)); web_contents_.reset(content::WebContents::Create(create_params));
extensions::SetViewType(web_contents_.get(), extensions::VIEW_TYPE_PANEL); extensions::SetViewType(web_contents_.get(), extensions::VIEW_TYPE_PANEL);
web_contents_->SetDelegate(this); web_contents_->SetDelegate(this);
// web_contents_ may be passed to chrome_page_zoom::Zoom(), so it needs
// a ZoomController.
ZoomController::CreateForWebContents(web_contents_.get());
content::WebContentsObserver::Observe(web_contents_.get()); content::WebContentsObserver::Observe(web_contents_.get());
// Needed to give the web contents a Tab ID. Extension APIs // Needed to give the web contents a Tab ID. Extension APIs
......
...@@ -27,6 +27,7 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); ...@@ -27,6 +27,7 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController);
ZoomController::ZoomController(content::WebContents* web_contents) ZoomController::ZoomController(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
can_show_bubble_(true),
zoom_mode_(ZOOM_MODE_DEFAULT), zoom_mode_(ZOOM_MODE_DEFAULT),
zoom_level_(1.0), zoom_level_(1.0),
browser_context_(web_contents->GetBrowserContext()) { browser_context_(web_contents->GetBrowserContext()) {
...@@ -274,9 +275,9 @@ void ZoomController::UpdateState(const std::string& host) { ...@@ -274,9 +275,9 @@ void ZoomController::UpdateState(const std::string& host) {
} }
} }
// The zoom bubble can be shown for all zoom changes where the host is // The zoom bubble should not be shown for zoom changes where the host is
// not empty. // empty.
bool can_show_bubble = !host.empty(); bool can_show_bubble = can_show_bubble_ && !host.empty();
if (event_data_) { if (event_data_) {
// For state changes initiated within the ZoomController, information about // For state changes initiated within the ZoomController, information about
......
...@@ -83,6 +83,13 @@ class ZoomController : public content::WebContentsObserver, ...@@ -83,6 +83,13 @@ class ZoomController : public content::WebContentsObserver,
void AddObserver(ZoomObserver* observer); void AddObserver(ZoomObserver* observer);
void RemoveObserver(ZoomObserver* observer); void RemoveObserver(ZoomObserver* observer);
// Used to set whether the zoom notification bubble can be shown when the
// zoom level is changed for this controller. Default behavior is to show
// the bubble.
void SetShowsNotificationBubble(bool can_show_bubble) {
can_show_bubble_ = can_show_bubble;
}
// Gets the current zoom level by querying HostZoomMap (if not in manual zoom // Gets the current zoom level by querying HostZoomMap (if not in manual zoom
// mode) or from the ZoomController local value otherwise. // mode) or from the ZoomController local value otherwise.
double GetZoomLevel() const; double GetZoomLevel() const;
...@@ -121,6 +128,9 @@ class ZoomController : public content::WebContentsObserver, ...@@ -121,6 +128,9 @@ class ZoomController : public content::WebContentsObserver,
// change only affects sites with the given host. // change only affects sites with the given host.
void UpdateState(const std::string& host); void UpdateState(const std::string& host);
// True if changes to zoom level can trigger the zoom notification bubble.
bool can_show_bubble_;
// The current zoom mode. // The current zoom mode.
ZoomMode zoom_mode_; ZoomMode zoom_mode_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment