OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHROME_ZOOM_LEVEL_PREFS_H_ | 5 #ifndef CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ |
6 #define CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ | 6 #define CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "components/prefs/json_pref_store.h" | 14 #include "chrome/browser/ui/zoom/chrome_zoom_prefs_helper.h" |
15 #include "components/prefs/pref_change_registrar.h" | |
16 #include "components/prefs/pref_service.h" | 15 #include "components/prefs/pref_service.h" |
17 #include "components/prefs/pref_store.h" | 16 #include "components/zoom/zoom_prefs_delegate.h" |
18 #include "content/public/browser/host_zoom_map.h" | 17 #include "content/public/browser/host_zoom_map.h" |
19 #include "content/public/browser/zoom_level_delegate.h" | |
20 | 18 |
21 namespace base { | 19 namespace base { |
22 class DictionaryValue; | 20 class DictionaryValue; |
23 } | 21 } |
24 | 22 |
25 namespace zoom { | 23 namespace zoom { |
26 class ZoomEventManager; | 24 class ZoomEventManager; |
27 } | 25 } |
28 | 26 |
29 // A class to manage per-partition default and per-host zoom levels in Chrome's | 27 // A class to manage per-partition default and per-host zoom levels as well as |
30 // preference system. It implements an interface between the content/ zoom | 28 // the zoom scope pref in Chrome's preference system. It implements an |
31 // levels in HostZoomMap and Chrome's preference system. All changes | 29 // interface to Chrome's preference system for the content/ zoom levels in |
32 // to the per-partition default zoom levels from chrome/ flow through this | 30 // HostZoomMap and the zoom scope in ZoomController. All changes to the |
| 31 // per-partition default zoom levels and scope from chrome/ flow through this |
33 // class. Any changes to per-host levels are updated when HostZoomMap calls | 32 // class. Any changes to per-host levels are updated when HostZoomMap calls |
34 // OnZoomLevelChanged. | 33 // OnZoomLevelChanged. |
35 class ChromeZoomLevelPrefs : public content::ZoomLevelDelegate { | 34 class ChromeZoomLevelPrefs : public zoom::ZoomPrefsDelegate { |
36 public: | 35 public: |
37 typedef base::CallbackList<void(void)>::Subscription | 36 typedef base::CallbackList<void(void)>::Subscription |
38 DefaultZoomLevelSubscription; | 37 DefaultZoomLevelSubscription; |
39 | 38 |
40 // Initialize the pref_service and the partition_key via the constructor, | 39 // Initialize our ChromeZoomPrefsHelper with pref_service and the partition |
41 // as these concepts won't be available in the content base class | 40 // information via this constructor, as these concepts won't be available in |
42 // ZoomLevelDelegate, which will define the InitHostZoomMap interface. | 41 // the content base class ZoomLevelDelegate (which will define the |
| 42 // InitHostZoomMap interface) nor in the components class ZoomPrefsDelegate |
| 43 // (which will define the interface for the zoom scope pref). |
43 // |pref_service_| must outlive this class. | 44 // |pref_service_| must outlive this class. |
44 ChromeZoomLevelPrefs( | 45 ChromeZoomLevelPrefs( |
45 PrefService* pref_service, | 46 PrefService* pref_service, |
46 const base::FilePath& profile_path, | 47 const base::FilePath& profile_path, |
47 const base::FilePath& partition_path, | 48 const base::FilePath& partition_path, |
48 base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager); | 49 base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager); |
49 ~ChromeZoomLevelPrefs() override; | 50 ~ChromeZoomLevelPrefs() override; |
50 | 51 |
51 static std::string GetHashForTesting(const base::FilePath& relative_path); | 52 static std::string GetHashForTesting(const base::FilePath& relative_path); |
52 | 53 |
53 void SetDefaultZoomLevelPref(double level); | 54 void SetDefaultZoomLevelPref(double level); |
54 double GetDefaultZoomLevelPref() const; | 55 double GetDefaultZoomLevelPref() const; |
55 std::unique_ptr<DefaultZoomLevelSubscription> | 56 std::unique_ptr<DefaultZoomLevelSubscription> |
56 RegisterDefaultZoomLevelCallback(const base::Closure& callback); | 57 RegisterDefaultZoomLevelCallback(const base::Closure& callback); |
57 | 58 |
| 59 void SetZoomScopeIsPerOriginPref(bool is_per_origin); |
| 60 |
58 void ExtractPerHostZoomLevels( | 61 void ExtractPerHostZoomLevels( |
59 const base::DictionaryValue* host_zoom_dictionary, | 62 const base::DictionaryValue* host_zoom_dictionary, |
60 bool sanitize_partition_host_zoom_levels); | 63 bool sanitize_partition_host_zoom_levels); |
61 | 64 |
62 // content::ZoomLevelDelegate | 65 // zoom::ZoomPrefsDelegate |
63 void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override; | 66 void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override; |
64 | 67 |
| 68 bool GetZoomScopeIsPerOriginPref() const override; |
| 69 std::unique_ptr<DefaultZoomScopeSubscription> |
| 70 RegisterDefaultZoomScopeCallback(const base::Closure& callback) override; |
| 71 |
65 private: | 72 private: |
66 // This is a callback function that receives notifications from HostZoomMap | 73 // This is a callback function that receives notifications from HostZoomMap |
67 // when per-host zoom levels change. It is used to update the per-host | 74 // when per-host zoom levels change. It is used to update the per-host |
68 // zoom levels (if any) managed by this class (for its associated partition). | 75 // zoom levels (if any) managed by this class (for its associated partition). |
69 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); | 76 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); |
70 | 77 |
71 PrefService* pref_service_; | 78 ChromeZoomPrefsHelper partitioned_prefs_; |
72 base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager_; | 79 base::WeakPtr<zoom::ZoomEventManager> zoom_event_manager_; |
73 content::HostZoomMap* host_zoom_map_; | 80 content::HostZoomMap* host_zoom_map_; |
74 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 81 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
75 std::string partition_key_; | |
76 base::CallbackList<void(void)> default_zoom_changed_callbacks_; | 82 base::CallbackList<void(void)> default_zoom_changed_callbacks_; |
| 83 base::CallbackList<void(void)> default_scope_changed_callbacks_; |
77 | 84 |
78 DISALLOW_COPY_AND_ASSIGN(ChromeZoomLevelPrefs); | 85 DISALLOW_COPY_AND_ASSIGN(ChromeZoomLevelPrefs); |
79 }; | 86 }; |
80 | 87 |
81 #endif // CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ | 88 #endif // CHROME_BROWSER_UI_ZOOM_CHROME_ZOOM_LEVEL_PREFS_H_ |
OLD | NEW |