Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: components/zoom/zoom_controller.h

Issue 2630583002: Add setting to isolate zoom changes by default. (Closed)
Patch Set: Use code review comments for questions instead of TODOs. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_ 5 #ifndef COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_
6 #define COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_ 6 #define COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "components/prefs/pref_member.h" 15 #include "components/prefs/pref_member.h"
16 #include "components/zoom/zoom_prefs_delegate.h"
15 #include "content/public/browser/host_zoom_map.h" 17 #include "content/public/browser/host_zoom_map.h"
16 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/browser/web_contents_user_data.h" 19 #include "content/public/browser/web_contents_user_data.h"
20 #include "content/public/browser/zoom_level_delegate.h"
18 21
19 class ZoomControllerTest; 22 class ZoomControllerTest;
23 FORWARD_DECLARE_TEST(ZoomControllerTest, OnDefaultZoomScopeChanged);
24 FORWARD_DECLARE_TEST(ZoomControllerPerTabTest, OnDefaultZoomScopeChanged);
20 25
21 namespace content { 26 namespace content {
22 class WebContents; 27 class WebContents;
23 } 28 }
24 29
25 namespace zoom { 30 namespace zoom {
26 class ZoomObserver; 31 class ZoomObserver;
27 32
28 class ZoomRequestClient : public base::RefCounted<ZoomRequestClient> { 33 class ZoomRequestClient : public base::RefCounted<ZoomRequestClient> {
29 public: 34 public:
(...skipping 11 matching lines...) Expand all
41 46
42 // Per-tab class to manage zoom changes and the Omnibox zoom icon. 47 // Per-tab class to manage zoom changes and the Omnibox zoom icon.
43 class ZoomController : public content::WebContentsObserver, 48 class ZoomController : public content::WebContentsObserver,
44 public content::WebContentsUserData<ZoomController> { 49 public content::WebContentsUserData<ZoomController> {
45 public: 50 public:
46 // Defines how zoom changes are handled. 51 // Defines how zoom changes are handled.
47 enum ZoomMode { 52 enum ZoomMode {
48 // Results in default zoom behavior, i.e. zoom changes are handled 53 // Results in default zoom behavior, i.e. zoom changes are handled
49 // automatically and on a per-origin basis, meaning that other tabs 54 // automatically and on a per-origin basis, meaning that other tabs
50 // navigated to the same origin will also zoom. 55 // navigated to the same origin will also zoom.
51 ZOOM_MODE_DEFAULT, 56 ZOOM_MODE_DEFAULT,
Kevin McNee 2017/02/03 23:17:20 Would we want to rename this?
wjmaclean 2017/02/06 16:09:07 Possibly. What did you have in mind? ZOOM_MODE_PER
Kevin McNee 2017/02/06 18:26:12 Yep. This enum is used internally (we convert bet
wjmaclean 2017/02/06 18:48:38 Acknowledged.
52 // Results in zoom changes being handled automatically, but on a per-tab 57 // Results in zoom changes being handled automatically, but on a per-tab
53 // basis. Tabs in this zoom mode will not be affected by zoom changes in 58 // basis. Tabs in this zoom mode will not be affected by zoom changes in
54 // other tabs, and vice versa. 59 // other tabs, and vice versa.
55 ZOOM_MODE_ISOLATED, 60 ZOOM_MODE_ISOLATED,
56 // Overrides the automatic handling of zoom changes. The |onZoomChange| 61 // Overrides the automatic handling of zoom changes. The |onZoomChange|
57 // event will still be dispatched, but the page will not actually be zoomed. 62 // event will still be dispatched, but the page will not actually be zoomed.
58 // These zoom changes can be handled manually by listening for the 63 // These zoom changes can be handled manually by listening for the
59 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis. 64 // |onZoomChange| event. Zooming in this mode is also on a per-tab basis.
60 ZOOM_MODE_MANUAL, 65 ZOOM_MODE_MANUAL,
61 // Disables all zooming in this tab. The tab will revert to the default 66 // Disables all zooming in this tab. The tab will revert to the default
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 double zoom_level, 146 double zoom_level,
142 const scoped_refptr<const ZoomRequestClient>& client); 147 const scoped_refptr<const ZoomRequestClient>& client);
143 148
144 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode). 149 // Sets the zoom mode, which defines zoom behavior (see enum ZoomMode).
145 void SetZoomMode(ZoomMode zoom_mode); 150 void SetZoomMode(ZoomMode zoom_mode);
146 151
147 // Set and query whether or not the page scale factor is one. 152 // Set and query whether or not the page scale factor is one.
148 void SetPageScaleFactorIsOneForTesting(bool is_one); 153 void SetPageScaleFactorIsOneForTesting(bool is_one);
149 bool PageScaleFactorIsOne() const; 154 bool PageScaleFactorIsOne() const;
150 155
156 // Called by TabStripModel to notify us when it replaces a tab's WebContents
157 // with another.
158 // Virtual for testing.
159 virtual void WebContentsReplaced(content::WebContents* new_web_contents);
160
151 // content::WebContentsObserver overrides: 161 // content::WebContentsObserver overrides:
152 void DidFinishNavigation( 162 void DidFinishNavigation(
153 content::NavigationHandle* navigation_handle) override; 163 content::NavigationHandle* navigation_handle) override;
154 void WebContentsDestroyed() override; 164 void WebContentsDestroyed() override;
155 void RenderFrameHostChanged(content::RenderFrameHost* old_host, 165 void RenderFrameHostChanged(content::RenderFrameHost* old_host,
156 content::RenderFrameHost* new_host) override; 166 content::RenderFrameHost* new_host) override;
167 void DidCloneToNewWebContents(
168 content::WebContents* old_web_contents,
169 content::WebContents* new_web_contents) override;
157 170
158 protected: 171 protected:
159 // Protected for testing. 172 // Protected for testing.
160 explicit ZoomController(content::WebContents* web_contents); 173 explicit ZoomController(content::WebContents* web_contents);
161 174
162 private: 175 private:
163 friend class content::WebContentsUserData<ZoomController>; 176 friend class content::WebContentsUserData<ZoomController>;
164 friend class ::ZoomControllerTest; 177 friend class ::ZoomControllerTest;
178 FRIEND_TEST_ALL_PREFIXES(::ZoomControllerTest, OnDefaultZoomScopeChanged);
179 FRIEND_TEST_ALL_PREFIXES(::ZoomControllerPerTabTest,
180 OnDefaultZoomScopeChanged);
165 181
166 void ResetZoomModeOnNavigationIfNeeded(const GURL& url); 182 void ResetZoomModeOnNavigationIfNeeded(const GURL& url);
183 void UpdateZoomModeOnScopeChangeIfNeeded();
184 void PreserveTemporaryZoomLevel(
185 const content::HostZoomMap* old_zoom_map,
186 content::HostZoomMap* new_zoom_map,
187 content::RenderFrameHost* old_host,
188 content::RenderFrameHost* new_host) const;
189 void PreserveTemporaryZoomLevel(
190 content::WebContents* old_web_contents,
191 content::WebContents* new_web_contents) const;
167 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); 192 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
193 void OnDefaultZoomScopeChanged();
168 194
169 // Updates the zoom icon and zoom percentage based on current values and 195 // Updates the zoom icon and zoom percentage based on current values and
170 // notifies the observer if changes have occurred. |host| may be empty, 196 // notifies the observer if changes have occurred. |host| may be empty,
171 // meaning the change should apply to ~all sites. If it is not empty, the 197 // meaning the change should apply to ~all sites. If it is not empty, the
172 // change only affects sites with the given host. 198 // change only affects sites with the given host.
173 void UpdateState(const std::string& host); 199 void UpdateState(const std::string& host);
174 200
175 // True if changes to zoom level can trigger the zoom notification bubble. 201 // True if changes to zoom level can trigger the zoom notification bubble.
176 bool can_show_bubble_; 202 bool can_show_bubble_;
177 203
178 // The current zoom mode. 204 // The current zoom mode.
179 ZoomMode zoom_mode_; 205 ZoomMode zoom_mode_;
180 206
207 // Whether zoom changes are by default scoped to a page's origin.
208 // If false, they are scoped to the tab.
209 bool default_scope_is_per_origin_;
210
181 // Current zoom level. 211 // Current zoom level.
182 double zoom_level_; 212 double zoom_level_;
183 213
184 std::unique_ptr<ZoomChangedEventData> event_data_; 214 std::unique_ptr<ZoomChangedEventData> event_data_;
185 215
186 // Keeps track of the extension (if any) that initiated the last zoom change 216 // Keeps track of the extension (if any) that initiated the last zoom change
187 // that took effect. 217 // that took effect.
188 scoped_refptr<const ZoomRequestClient> last_client_; 218 scoped_refptr<const ZoomRequestClient> last_client_;
189 219
190 // Observer receiving notifications on state changes. 220 // Observer receiving notifications on state changes.
191 base::ObserverList<ZoomObserver> observers_; 221 base::ObserverList<ZoomObserver> observers_;
192 222
193 content::BrowserContext* browser_context_; 223 content::BrowserContext* browser_context_;
194 // Keep track of the HostZoomMap we're currently subscribed to. 224 // Keep track of the HostZoomMap we're currently subscribed to.
195 content::HostZoomMap* host_zoom_map_; 225 content::HostZoomMap* host_zoom_map_;
196 226
197 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; 227 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
228 std::unique_ptr<ZoomPrefsDelegate::DefaultZoomScopeSubscription>
229 default_zoom_scope_subscription_;
198 230
199 DISALLOW_COPY_AND_ASSIGN(ZoomController); 231 DISALLOW_COPY_AND_ASSIGN(ZoomController);
200 }; 232 };
201 233
202 } // namespace zoom 234 } // namespace zoom
203 235
204 #endif // COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_ 236 #endif // COMPONENTS_ZOOM_ZOOM_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698