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 "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 | 21 |
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); | 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); |
23 | 23 |
24 ZoomController::ZoomController(content::WebContents* web_contents) | 24 ZoomController::ZoomController(content::WebContents* web_contents) |
25 : content::WebContentsObserver(web_contents), | 25 : content::WebContentsObserver(web_contents), |
26 zoom_percent_(100), | 26 zoom_percent_(100), |
27 observer_(NULL), | 27 observer_(NULL), |
28 browser_context_(web_contents->GetBrowserContext()) { | 28 browser_context_(web_contents->GetBrowserContext()) { |
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(), | 31 default_zoom_level_.Init( |
32 base::Bind(&ZoomController::UpdateState, | 32 prefs::kDefaultZoomLevel, profile->GetPrefs(), |
33 base::Unretained(this), | 33 base::Bind(static_cast<void(ZoomController::*)( |
34 std::string())); | 34 const std::string&)>(&ZoomController::UpdateState), |
35 base::Unretained(this), | |
36 std::string())); | |
35 | 37 |
36 zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( | 38 zoom_subscription_ = content::HostZoomMap::GetForBrowserContext( |
37 browser_context_)->AddZoomLevelChangedCallback( | 39 browser_context_)->AddZoomLevelChangedCallback( |
38 base::Bind(&ZoomController::OnZoomLevelChanged, | 40 base::Bind(&ZoomController::OnZoomLevelChanged, |
39 base::Unretained(this))); | 41 base::Unretained(this))); |
40 | 42 |
41 UpdateState(std::string()); | 43 UpdateState(std::string()); |
42 } | 44 } |
43 | 45 |
44 ZoomController::~ZoomController() {} | 46 ZoomController::~ZoomController() {} |
45 | 47 |
46 bool ZoomController::IsAtDefaultZoom() const { | 48 bool ZoomController::IsAtDefaultZoom() const { |
47 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(), | 49 return content::ZoomValuesEqual(web_contents()->GetZoomLevel(), |
48 default_zoom_level_.GetValue()); | 50 default_zoom_level_.GetValue()); |
49 } | 51 } |
50 | 52 |
51 int ZoomController::GetResourceForZoomLevel() const { | 53 int ZoomController::GetResourceForZoomLevel() const { |
52 if (IsAtDefaultZoom()) | 54 if (IsAtDefaultZoom()) |
53 return IDR_ZOOM_NORMAL; | 55 return IDR_ZOOM_NORMAL; |
54 double zoom = web_contents()->GetZoomLevel(); | 56 double zoom = web_contents()->GetZoomLevel(); |
55 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS; | 57 return zoom > default_zoom_level_.GetValue() ? IDR_ZOOM_PLUS : IDR_ZOOM_MINUS; |
56 } | 58 } |
57 | 59 |
60 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
| |
61 return last_extension_.get(); | |
62 } | |
63 | |
64 bool ZoomController::SetZoomLevelByExtension( | |
65 double zoom_level, | |
66 scoped_refptr<const extensions::Extension> extension, | |
67 const base::Callback<void(void)>& callback) { | |
68 if (web_contents()->GetZoomMode() == content::kZoomModeDisabled) | |
69 return false; | |
70 | |
71 // Call WebContents::SetZoomLevel() with a wrapper callback that calls both | |
72 // ZoomController::ZoomCallback and the passed-in |callback|. | |
73 const base::Callback<void(void)>& wrapper_callback = | |
74 base::Bind(&ZoomController::ZoomCallback, base::Unretained(this), | |
75 extension, callback); | |
76 web_contents()->SetZoomLevel(zoom_level, wrapper_callback); | |
77 return true; | |
78 } | |
79 | |
58 void ZoomController::DidNavigateMainFrame( | 80 void ZoomController::DidNavigateMainFrame( |
59 const content::LoadCommittedDetails& details, | 81 const content::LoadCommittedDetails& details, |
60 const content::FrameNavigateParams& params) { | 82 const content::FrameNavigateParams& params) { |
61 // If the main frame's content has changed, the new page may have a different | 83 // If the main frame's content has changed, the new page may have a different |
62 // zoom level from the old one. | 84 // zoom level from the old one. |
63 UpdateState(std::string()); | 85 UpdateState(std::string()); |
64 } | 86 } |
65 | 87 |
66 void ZoomController::OnZoomLevelChanged( | 88 void ZoomController::OnZoomLevelChanged( |
67 const content::HostZoomMap::ZoomLevelChange& change) { | 89 const content::HostZoomMap::ZoomLevelChange& change) { |
68 UpdateState(change.host); | 90 UpdateState(change.host, |
91 change.mode == content::HostZoomMap::ZOOM_CHANGED_TEMPORARY_ZOOM); | |
69 } | 92 } |
70 | 93 |
71 void ZoomController::UpdateState(const std::string& host) { | 94 void ZoomController::UpdateState(const std::string& host) { |
95 UpdateState(host, false); | |
96 } | |
97 | |
98 void ZoomController::UpdateState(const std::string& host, | |
99 bool is_temporary_zoom) { | |
100 // Update |last_extension_|. | |
101 last_extension_ = pending_extension_; | |
102 pending_extension_ = NULL; | |
103 | |
72 // If |host| is empty, all observers should be updated. | 104 // If |host| is empty, all observers should be updated. |
73 if (!host.empty()) { | 105 if (!host.empty()) { |
74 // Use the navigation entry's URL instead of the WebContents' so virtual | 106 // Use the navigation entry's URL instead of the WebContents' so virtual |
75 // URLs work (e.g. chrome://settings). http://crbug.com/153950 | 107 // URLs work (e.g. chrome://settings). http://crbug.com/153950 |
76 content::NavigationEntry* entry = | 108 content::NavigationEntry* entry = |
77 web_contents()->GetController().GetLastCommittedEntry(); | 109 web_contents()->GetController().GetLastCommittedEntry(); |
78 if (!entry || | 110 if (!entry || |
79 host != net::GetHostOrSpecFromURL(entry->GetURL())) { | 111 host != net::GetHostOrSpecFromURL(entry->GetURL())) { |
80 return; | 112 return; |
81 } | 113 } |
82 } | 114 } |
83 | |
84 bool dummy; | 115 bool dummy; |
85 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy); | 116 zoom_percent_ = web_contents()->GetZoomPercent(&dummy, &dummy); |
86 | 117 |
87 if (observer_) | 118 if (observer_) { |
88 observer_->OnZoomChanged(web_contents(), !host.empty()); | 119 // The zoom bubble can be shown for all normal, per-origin zoom changes |
120 // (where the host will not be empty and the zoom is not temporary), or any | |
121 // special zoom changes (where the zoom mode will not be "default"). | |
122 bool can_show_bubble = | |
123 web_contents()->GetZoomMode() != content::kZoomModeDefault || | |
124 (!host.empty() && !is_temporary_zoom); | |
125 observer_->OnZoomChanged(web_contents(), can_show_bubble); | |
126 } | |
127 | |
128 last_extension_ = NULL; | |
89 } | 129 } |
130 | |
131 void ZoomController::ZoomCallback( | |
132 scoped_refptr<const extensions::Extension> extension, | |
133 const base::Callback<void(void)>& callback) { | |
134 pending_extension_ = extension; | |
135 callback.Run(); | |
136 } | |
OLD | NEW |