Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 10 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 observer_(NULL) { | 28 observer_(NULL) { |
| 29 Profile* profile = | 29 Profile* profile = |
| 30 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 30 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 31 default_zoom_level_.Init(prefs::kDefaultZoomLevel, profile->GetPrefs(), this); | 31 default_zoom_level_.Init(prefs::kDefaultZoomLevel, profile->GetPrefs(), this); |
| 32 | 32 |
| 33 content::HostZoomMap* zoom_map = | 33 content::HostZoomMap* zoom_map = |
| 34 content::HostZoomMap::GetForBrowserContext(profile); | 34 content::HostZoomMap::GetForBrowserContext(profile); |
| 35 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 35 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
| 36 content::Source<content::HostZoomMap>(zoom_map)); | 36 content::Source<content::HostZoomMap>(zoom_map)); |
| 37 | 37 |
| 38 UpdateState(std::string()); | 38 UpdateState(std::string()); |
|
Dan Beam
2012/11/15 23:05:06
FYI: I don't see the point to this first UpdateSta
Dan Beam
2012/11/15 23:18:33
nevermind, it also sets |zoom_percent_|.
| |
| 39 } | 39 } |
| 40 | 40 |
| 41 ZoomController::~ZoomController() { | 41 ZoomController::~ZoomController() { |
| 42 default_zoom_level_.Destroy(); | 42 default_zoom_level_.Destroy(); |
| 43 registrar_.RemoveAll(); | 43 registrar_.RemoveAll(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool ZoomController::IsAtDefaultZoom() const { | 46 bool ZoomController::IsAtDefaultZoom() const { |
| 47 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(), | 47 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(), |
| 48 default_zoom_level_.GetValue()); | 48 default_zoom_level_.GetValue()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 69 UpdateState(*content::Details<std::string>(details).ptr()); | 69 UpdateState(*content::Details<std::string>(details).ptr()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ZoomController::OnPreferenceChanged(PrefServiceBase* service, | 72 void ZoomController::OnPreferenceChanged(PrefServiceBase* service, |
| 73 const std::string& pref_name) { | 73 const std::string& pref_name) { |
| 74 DCHECK(pref_name == prefs::kDefaultZoomLevel); | 74 DCHECK(pref_name == prefs::kDefaultZoomLevel); |
| 75 UpdateState(std::string()); | 75 UpdateState(std::string()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void ZoomController::UpdateState(const std::string& host) { | 78 void ZoomController::UpdateState(const std::string& host) { |
| 79 if (host.empty()) | 79 // If |host| is empty, all observers should be updated. |
| 80 return; | 80 if (!host.empty()) { |
| 81 | 81 // Use the active navigation entry's URL instead of the WebContents' so |
| 82 // Use the active navigation entry's URL instead of the WebContents' so | 82 // virtual URLs work (e.g. chrome://settings). http://crbug.com/153950 |
| 83 // virtual URLs work (e.g. chrome://settings). http://crbug.com/153950 | 83 content::NavigationEntry* active_entry = |
| 84 content::NavigationEntry* active_entry = | 84 web_contents()->GetController().GetActiveEntry(); |
| 85 web_contents()->GetController().GetActiveEntry(); | 85 if (!active_entry || |
| 86 if (!active_entry || | 86 host != net::GetHostOrSpecFromURL(active_entry->GetURL())) { |
| 87 host != net::GetHostOrSpecFromURL(active_entry->GetURL())) { | 87 return; |
| 88 return; | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool dummy; | 91 bool dummy; |
| 92 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy); | 92 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy); |
| 93 | 93 |
| 94 if (observer_) | 94 if (observer_) |
| 95 observer_->OnZoomChanged(web_contents(), !host.empty()); | 95 observer_->OnZoomChanged(web_contents(), !host.empty()); |
| 96 } | 96 } |
| OLD | NEW |