summaryrefslogtreecommitdiffstats
path: root/components/ui
diff options
context:
space:
mode:
authorwjmaclean <wjmaclean@chromium.org>2014-12-16 07:05:38 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-16 15:06:58 +0000
commitc7bcb77d7708a5790933890686b3da059dac041b (patch)
tree0905a8102f0184154726712dcf5134004c81e749 /components/ui
parent9016ef32769c396deb32c17dc5f3ff4a6d8acdd4 (diff)
downloadchromium_src-c7bcb77d7708a5790933890686b3da059dac041b.zip
chromium_src-c7bcb77d7708a5790933890686b3da059dac041b.tar.gz
chromium_src-c7bcb77d7708a5790933890686b3da059dac041b.tar.bz2
Update HostZoomMap event subscription when RenderViewHost changes.
Each ZoomController is associated with a WebContents and a HostZoomMap. However, it is possible that a WebContents can, as it navigates, change its StoragePartition, and therefore its HostZoomMap. This CL monitors WebContentsObserver for changes in RenderViewHost, and updates the HostZoomMap subscription if the HostZoomMap changes. BUG=438979 Review URL: https://codereview.chromium.org/767293006 Cr-Commit-Position: refs/heads/master@{#308585}
Diffstat (limited to 'components/ui')
-rw-r--r--components/ui/zoom/zoom_controller.cc21
-rw-r--r--components/ui/zoom/zoom_controller.h4
2 files changed, 21 insertions, 4 deletions
diff --git a/components/ui/zoom/zoom_controller.cc b/components/ui/zoom/zoom_controller.cc
index cc07e31..a2e49a8 100644
--- a/components/ui/zoom/zoom_controller.cc
+++ b/components/ui/zoom/zoom_controller.cc
@@ -26,11 +26,10 @@ ZoomController::ZoomController(content::WebContents* web_contents)
zoom_mode_(ZOOM_MODE_DEFAULT),
zoom_level_(1.0),
browser_context_(web_contents->GetBrowserContext()) {
- content::HostZoomMap* host_zoom_map =
- content::HostZoomMap::GetForWebContents(web_contents);
- zoom_level_ = host_zoom_map->GetDefaultZoomLevel();
+ host_zoom_map_ = content::HostZoomMap::GetForWebContents(web_contents);
+ zoom_level_ = host_zoom_map_->GetDefaultZoomLevel();
- zoom_subscription_ = host_zoom_map->AddZoomLevelChangedCallback(
+ zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(
base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this)));
UpdateState(std::string());
@@ -253,6 +252,20 @@ void ZoomController::WebContentsDestroyed() {
observers_.Clear();
}
+void ZoomController::RenderFrameHostChanged(
+ content::RenderFrameHost* old_host,
+ content::RenderFrameHost* new_host) {
+ // If our associated HostZoomMap changes, update our event subscription.
+ content::HostZoomMap* new_host_zoom_map =
+ content::HostZoomMap::GetForWebContents(web_contents());
+ if (new_host_zoom_map == host_zoom_map_)
+ return;
+
+ host_zoom_map_ = new_host_zoom_map;
+ zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(
+ base::Bind(&ZoomController::OnZoomLevelChanged, base::Unretained(this)));
+}
+
void ZoomController::OnZoomLevelChanged(
const content::HostZoomMap::ZoomLevelChange& change) {
UpdateState(change.host);
diff --git a/components/ui/zoom/zoom_controller.h b/components/ui/zoom/zoom_controller.h
index 5814345..f661ba4 100644
--- a/components/ui/zoom/zoom_controller.h
+++ b/components/ui/zoom/zoom_controller.h
@@ -140,6 +140,8 @@ class ZoomController : public content::WebContentsObserver,
const content::LoadCommittedDetails& details,
const content::FrameNavigateParams& params) override;
void WebContentsDestroyed() override;
+ void RenderFrameHostChanged(content::RenderFrameHost* old_host,
+ content::RenderFrameHost* new_host) override;
protected:
// Protected for testing.
@@ -176,6 +178,8 @@ class ZoomController : public content::WebContentsObserver,
ObserverList<ZoomObserver> observers_;
content::BrowserContext* browser_context_;
+ // Keep track of the HostZoomMap we're currently subscribed to.
+ content::HostZoomMap* host_zoom_map_;
scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;