Chromium Code Reviews| Index: chrome/browser/ui/zoom/zoom_controller.cc |
| diff --git a/chrome/browser/ui/zoom/zoom_controller.cc b/chrome/browser/ui/zoom/zoom_controller.cc |
| index 64ac8efe22d39da6163d5c3e0312324aee2562f3..29d0640450ec100e3a12e2708079ab0353901b06 100644 |
| --- a/chrome/browser/ui/zoom/zoom_controller.cc |
| +++ b/chrome/browser/ui/zoom/zoom_controller.cc |
| @@ -28,10 +28,12 @@ ZoomController::ZoomController(content::WebContents* web_contents) |
| browser_context_(web_contents->GetBrowserContext()) { |
| Profile* profile = |
| Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| - default_zoom_level_.Init(prefs::kDefaultZoomLevel, profile->GetPrefs(), |
| - base::Bind(&ZoomController::UpdateState, |
| - base::Unretained(this), |
| - std::string())); |
| + default_zoom_level_.Init( |
| + prefs::kDefaultZoomLevel, profile->GetPrefs(), |
| + base::Bind(static_cast<void(ZoomController::*)( |
| + const std::string&)>(&ZoomController::UpdateState), |
| + base::Unretained(this), |
| + std::string())); |
| zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( |
| browser_context_)->AddZoomLevelChangedCallback( |
| @@ -55,6 +57,26 @@ int ZoomController::GetResourceForZoomLevel() const { |
| return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS; |
| } |
| +const extensions::Extension* ZoomController::last_extension() const { |
|
not at google - send to devlin
2014/04/11 15:04:25
I can't find where this function, or anything refe
paulmeyer
2014/04/11 19:09:49
This is something that is going to change because
|
| + return last_extension_.get(); |
| +} |
| + |
| +bool ZoomController::SetZoomLevelByExtension( |
| + double zoom_level, |
| + scoped_refptr<const extensions::Extension> extension, |
| + const base::Callback<void(void)>& callback) { |
| + if (web_contents()->GetZoomMode() == content::kZoomModeDisabled) |
| + return false; |
| + |
| + // Call WebContents::SetZoomLevel() with a wrapper callback that calls both |
| + // ZoomController::ZoomCallback and the passed-in |callback|. |
| + const base::Callback<void(void)>& wrapper_callback = |
| + base::Bind(&ZoomController::ZoomCallback, base::Unretained(this), |
| + extension, callback); |
| + web_contents()->SetZoomLevel(zoom_level, wrapper_callback); |
| + return true; |
| +} |
| + |
| void ZoomController::DidNavigateMainFrame( |
| const content::LoadCommittedDetails& details, |
| const content::FrameNavigateParams& params) { |
| @@ -65,10 +87,20 @@ void ZoomController::DidNavigateMainFrame( |
| void ZoomController::OnZoomLevelChanged( |
| const content::HostZoomMap::ZoomLevelChange& change) { |
| - UpdateState(change.host); |
| + UpdateState(change.host, |
| + change.mode == content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM); |
| } |
| void ZoomController::UpdateState(const std::string& host) { |
| + UpdateState(host, false); |
| +} |
| + |
| +void ZoomController::UpdateState(const std::string& host, |
| + bool is_temporary_zoom) { |
| + // Update |last_extension_|. |
| + last_extension_ = pending_extension_; |
| + pending_extension_ = NULL; |
| + |
| // If |host| is empty, all observers should be updated. |
| if (!host.empty()) { |
| // Use the navigation entry's URL instead of the WebContents' so virtual |
| @@ -80,10 +112,25 @@ void ZoomController::UpdateState(const std::string& host) { |
| return; |
| } |
| } |
| - |
| bool dummy; |
| zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy); |
| - if (observer_) |
| - observer_->OnZoomChanged(web_contents(), !host.empty()); |
| + if (observer_) { |
| + // The zoom bubble can be shown for all normal, per-origin zoom changes |
| + // (where the host will not be empty and the zoom is not temporary), or any |
| + // special zoom changes (where the zoom mode will not be "default"). |
| + bool can_show_bubble = |
| + web_contents()->GetZoomMode() != content::kZoomModeDefault || |
| + (!host.empty() && !is_temporary_zoom); |
| + observer_->OnZoomChanged(web_contents(), can_show_bubble); |
| + } |
| + |
| + last_extension_ = NULL; |
| +} |
| + |
| +void ZoomController::ZoomCallback( |
| + scoped_refptr<const extensions::Extension> extension, |
| + const base::Callback<void(void)>& callback) { |
| + pending_extension_ = extension; |
| + callback.Run(); |
| } |