| 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..ed84420a4bc74bcdda7589356ad9c6767b8075c6 100644
|
| --- a/chrome/browser/ui/zoom/zoom_controller.cc
|
| +++ b/chrome/browser/ui/zoom/zoom_controller.cc
|
| @@ -14,6 +14,8 @@
|
| #include "content/public/browser/notification_details.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/notification_types.h"
|
| +#include "content/public/browser/render_process_host.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/page_zoom.h"
|
| #include "grit/theme_resources.h"
|
| @@ -28,10 +30,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 +59,109 @@ int ZoomController::GetResourceForZoomLevel() const {
|
| return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS;
|
| }
|
|
|
| +const extensions::Extension* ZoomController::last_extension() const {
|
| + return last_extension_.get();
|
| +}
|
| +
|
| +bool ZoomController::SetZoomLevel(double zoom_level) {
|
| + // Cannot zoom in disabled mode.
|
| + if (zoom_mode_ == kZoomModeDisabled)
|
| + return false;
|
| +
|
| + // An extension did not initiate this zoom change.
|
| + extensions_.push(NULL);
|
| +
|
| + // Do not actually rescale the page in manual mode.
|
| + if (zoom_mode_ == kZoomModeManual) {
|
| + content::HostZoomMap* zoom_map = content::HostZoomMap::GetForBrowserContext(
|
| + web_contents()->GetBrowserContext());
|
| + DCHECK(zoom_map);
|
| + int render_process_id = web_contents()->GetRenderProcessHost()->GetID();
|
| + int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID();
|
| + std::string host = net::GetHostOrSpecFromURL(
|
| + web_contents()->GetController().GetLastCommittedEntry()->GetURL());
|
| + zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
|
| + host, zoom_level);
|
| + } else {
|
| + web_contents()->SetZoomLevel(zoom_level);
|
| + }
|
| + observer_->OnZoomChangeInitiated(web_contents(),
|
| + web_contents()->GetZoomLevel(),
|
| + zoom_level,
|
| + zoom_mode_);
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool ZoomController::SetZoomLevelByExtension(
|
| + double zoom_level,
|
| + scoped_refptr<const extensions::Extension> extension) {
|
| + if (!SetZoomLevel(zoom_level))
|
| + return false;
|
| +
|
| + // Store extension data so that |extension| can be attributed when the zoom
|
| + // change completes..
|
| + extensions_.front() = extension.get();
|
| + return true;
|
| +}
|
| +
|
| +void ZoomController::SetZoomMode(ZoomMode new_mode) {
|
| + if (new_mode == zoom_mode_)
|
| + return;
|
| +
|
| + content::HostZoomMap* zoom_map = content::HostZoomMap::GetForBrowserContext(
|
| + web_contents()->GetBrowserContext());
|
| + DCHECK(zoom_map);
|
| + int render_process_id = web_contents()->GetRenderProcessHost()->GetID();
|
| + int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID();
|
| + std::string host = net::GetHostOrSpecFromURL(
|
| + web_contents()->GetController().GetLastCommittedEntry()->GetURL());
|
| + double original_zoom_level = web_contents()->GetZoomLevel();
|
| +
|
| + switch (new_mode) {
|
| + case kZoomModeDefault: {
|
| + zoom_map->SetZoomLevelForHost(host, original_zoom_level);
|
| + // Remove per-tab zoom data for this tab.
|
| + zoom_map->EraseTemporaryZoomLevel(render_process_id, render_view_id);
|
| + break;
|
| + }
|
| + case kZoomModeIsolated: {
|
| + // Unless the zoom mode was |kZoomModeDisabled| before this call, the page
|
| + // needs an initial isolated zoom back to the same level it was at in the
|
| + // other mode.
|
| + if (zoom_mode_ != kZoomModeDisabled) {
|
| + zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
|
| + host, original_zoom_level);
|
| + }
|
| + break;
|
| + }
|
| + case kZoomModeManual: {
|
| + // Unless the zoom mode was |kZoomModeDisabled| before this call, the page
|
| + // needs to be resized to the default zoom before calling SetZoomLevel()
|
| + // so that the page can be resized manually to the same zoom as before.
|
| + if (zoom_mode_ != kZoomModeDisabled) {
|
| + zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
|
| + host, 0);
|
| + zoom_mode_ = new_mode;
|
| + SetZoomLevel(original_zoom_level);
|
| + }
|
| + break;
|
| + }
|
| + case kZoomModeDisabled: {
|
| + // The page needs to be zoomed back to default before disabling the zoom
|
| + // (unless it was just in |kZoomModeManual| mode, in which case this is
|
| + // already done).
|
| + if (zoom_mode_ != kZoomModeManual)
|
| + zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
|
| + host, 0);
|
| + break;
|
| + }
|
| + }
|
| +
|
| + zoom_mode_ = new_mode;
|
| + web_contents()->SetTemporaryZoomSettings(new_mode != kZoomModeDefault);
|
| +}
|
| +
|
| void ZoomController::DidNavigateMainFrame(
|
| const content::LoadCommittedDetails& details,
|
| const content::FrameNavigateParams& params) {
|
| @@ -65,10 +172,21 @@ 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_|.
|
| + DCHECK(!extensions_.empty());
|
| + last_extension_ = extensions_.front().get();
|
| + extensions_.pop();
|
| +
|
| // 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 +198,18 @@ 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 =
|
| + zoom_mode_ != kZoomModeDefault ||
|
| + (!host.empty() && !is_temporary_zoom);
|
| + observer_->OnZoomChanged(web_contents(), can_show_bubble);
|
| + }
|
| +
|
| + last_extension_ = NULL;
|
| }
|
|
|