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 #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
11 #include "content/public/browser/host_zoom_map.h" | 11 #include "content/public/browser/host_zoom_map.h" |
12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 14 #include "extensions/common/extension.h" |
14 | 15 |
15 class ZoomObserver; | 16 class ZoomObserver; |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 class WebContents; | 19 class WebContents; |
19 } | 20 } |
20 | 21 |
21 // Per-tab class to manage the Omnibox zoom icon. | 22 // Per-tab class to manage the Omnibox zoom icon. |
22 class ZoomController : public content::WebContentsObserver, | 23 class ZoomController : public content::WebContentsObserver, |
23 public content::WebContentsUserData<ZoomController> { | 24 public content::WebContentsUserData<ZoomController> { |
24 public: | 25 public: |
25 virtual ~ZoomController(); | 26 virtual ~ZoomController(); |
26 | 27 |
27 int zoom_percent() const { return zoom_percent_; } | 28 int zoom_percent() const { return zoom_percent_; } |
28 | 29 |
29 // Convenience method to quickly check if the tab's at default zoom. | 30 // Convenience method to quickly check if the tab's at default zoom. |
30 bool IsAtDefaultZoom() const; | 31 bool IsAtDefaultZoom() const; |
31 | 32 |
32 // Returns which image should be loaded for the current zoom level. | 33 // Returns which image should be loaded for the current zoom level. |
33 int GetResourceForZoomLevel() const; | 34 int GetResourceForZoomLevel() const; |
34 | 35 |
| 36 const extensions::Extension* last_extension() const; |
| 37 |
35 void set_observer(ZoomObserver* observer) { observer_ = observer; } | 38 void set_observer(ZoomObserver* observer) { observer_ = observer; } |
36 | 39 |
| 40 // Sets the zoom level through WebContents::SetZoomLevel(). Returns a boolean |
| 41 // flag indicating success (true) or failure (false). |
| 42 bool SetZoomLevelByExtension( |
| 43 double zoom_level, |
| 44 scoped_refptr<const extensions::Extension> extension, |
| 45 const base::Callback<void(void)>& callback); |
| 46 |
37 // content::WebContentsObserver overrides: | 47 // content::WebContentsObserver overrides: |
38 virtual void DidNavigateMainFrame( | 48 virtual void DidNavigateMainFrame( |
39 const content::LoadCommittedDetails& details, | 49 const content::LoadCommittedDetails& details, |
40 const content::FrameNavigateParams& params) OVERRIDE; | 50 const content::FrameNavigateParams& params) OVERRIDE; |
41 | 51 |
42 private: | 52 private: |
43 explicit ZoomController(content::WebContents* web_contents); | 53 explicit ZoomController(content::WebContents* web_contents); |
44 friend class content::WebContentsUserData<ZoomController>; | 54 friend class content::WebContentsUserData<ZoomController>; |
45 friend class ZoomControllerTest; | 55 friend class ZoomControllerTest; |
46 | 56 |
47 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); | 57 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); |
48 | 58 |
49 // Updates the zoom icon and zoom percentage based on current values and | 59 // Updates the zoom icon and zoom percentage based on current values and |
50 // notifies the observer if changes have occurred. |host| may be empty, | 60 // notifies the observer if changes have occurred. |host| may be empty, |
51 // meaning the change should apply to ~all sites. If it is not empty, the | 61 // meaning the change should apply to ~all sites. If it is not empty, the |
52 // change only affects sites with the given host. | 62 // change only affects sites with the given host. |
53 void UpdateState(const std::string& host); | 63 void UpdateState(const std::string& host); |
| 64 void UpdateState(const std::string& host, bool is_temporary_zoom); |
| 65 |
| 66 // This function serves as a callback that will be called after a zoom |
| 67 // change has completed that is initiated from SetZoomLevelByExtension(). |
| 68 void ZoomCallback(scoped_refptr<const extensions::Extension> extension, |
| 69 const base::Callback<void(void)>& callback); |
54 | 70 |
55 // The current zoom percentage. | 71 // The current zoom percentage. |
56 int zoom_percent_; | 72 int zoom_percent_; |
57 | 73 |
58 // Used to access the default zoom level preference. | 74 // Used to access the default zoom level preference. |
59 DoublePrefMember default_zoom_level_; | 75 DoublePrefMember default_zoom_level_; |
60 | 76 |
| 77 // Keeps track of the extension (if any) that initiated the last zoom change |
| 78 // that took effect. |
| 79 scoped_refptr<const extensions::Extension> last_extension_; |
| 80 |
| 81 // Temporary buffer that stores the extension (if any) that initiated the zoom |
| 82 // change that the ZoomController is about to be notified about. |
| 83 scoped_refptr<const extensions::Extension> pending_extension_; |
| 84 |
61 // Observer receiving notifications on state changes. | 85 // Observer receiving notifications on state changes. |
62 ZoomObserver* observer_; | 86 ZoomObserver* observer_; |
63 | 87 |
64 content::BrowserContext* browser_context_; | 88 content::BrowserContext* browser_context_; |
65 | 89 |
66 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 90 scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
67 | 91 |
68 DISALLOW_COPY_AND_ASSIGN(ZoomController); | 92 DISALLOW_COPY_AND_ASSIGN(ZoomController); |
69 }; | 93 }; |
70 | 94 |
71 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ | 95 #endif // CHROME_BROWSER_UI_ZOOM_ZOOM_CONTROLLER_H_ |
OLD | NEW |