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 CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 double level) OVERRIDE; | 39 double level) OVERRIDE; |
40 virtual void SetZoomLevelForHostAndScheme( | 40 virtual void SetZoomLevelForHostAndScheme( |
41 const std::string& scheme, | 41 const std::string& scheme, |
42 const std::string& host, | 42 const std::string& host, |
43 double level) OVERRIDE; | 43 double level) OVERRIDE; |
44 virtual double GetDefaultZoomLevel() const OVERRIDE; | 44 virtual double GetDefaultZoomLevel() const OVERRIDE; |
45 virtual void SetDefaultZoomLevel(double level) OVERRIDE; | 45 virtual void SetDefaultZoomLevel(double level) OVERRIDE; |
46 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( | 46 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( |
47 const ZoomLevelChangedCallback& callback) OVERRIDE; | 47 const ZoomLevelChangedCallback& callback) OVERRIDE; |
48 | 48 |
| 49 // Stores a callback to be called when the associated zoom change has |
| 50 // completed. |
| 51 void AddZoomCallback(int zoom_id, const base::Callback<void(void)>& callback); |
| 52 |
49 // Returns the temporary zoom level that's only valid for the lifetime of | 53 // Returns the temporary zoom level that's only valid for the lifetime of |
50 // the given WebContents (i.e. isn't saved and doesn't affect other | 54 // the given WebContents (i.e. isn't saved and doesn't affect other |
51 // WebContentses) if it exists, the default zoom level otherwise. | 55 // WebContentses) if it exists, the default zoom level otherwise. |
52 // | 56 // |
53 // This may be called on any thread. | 57 // This may be called on any thread. |
54 double GetTemporaryZoomLevel(int render_process_id, | 58 double GetTemporaryZoomLevel(int render_process_id, |
55 int render_view_id) const; | 59 int render_view_id) const; |
56 | 60 |
| 61 // Additionally calls the callback associated with the zoom ID |zoom_id|. |
| 62 virtual void SetZoomLevelForHost( |
| 63 const std::string& host, |
| 64 int zoom_id, |
| 65 double level); |
| 66 |
57 // Sets the temporary zoom level that's only valid for the lifetime of this | 67 // Sets the temporary zoom level that's only valid for the lifetime of this |
58 // WebContents. | 68 // WebContents. |
59 // | 69 // |
60 // This should only be called on the UI thread. | 70 // This should only be called on the UI thread. |
61 void SetTemporaryZoomLevel(int render_process_id, | 71 void SetTemporaryZoomLevel(int render_process_id, |
62 int render_view_id, | 72 int render_view_id, |
| 73 const std::string& host, |
| 74 int zoom_id, |
63 double level); | 75 double level); |
64 | 76 |
65 // NotificationObserver implementation. | 77 // NotificationObserver implementation. |
66 virtual void Observe(int type, | 78 virtual void Observe(int type, |
67 const NotificationSource& source, | 79 const NotificationSource& source, |
68 const NotificationDetails& details) OVERRIDE; | 80 const NotificationDetails& details) OVERRIDE; |
69 | 81 |
70 private: | 82 private: |
| 83 // Erases an entry in |temporary_zoom_levels_|. |
| 84 void EraseTemporaryZoomLevel(int render_process_id, int render_view_id); |
| 85 |
| 86 // Called when the zoom change with ID |zoom_id| has completed, and its |
| 87 // associated callback should be called. Each callback can only be called |
| 88 // once, and is removed from the |zoom_callback_map_| after calling. |
| 89 void CallZoomCallback(int zoom_id); |
| 90 |
71 double GetZoomLevelForHost(const std::string& host) const; | 91 double GetZoomLevelForHost(const std::string& host) const; |
72 | 92 |
| 93 // Notifies the renderers from this browser context to change the zoom level |
| 94 // for the specified host and scheme. |
| 95 void SendZoomLevelChange(const std::string& scheme, |
| 96 const std::string& host, |
| 97 double level); |
| 98 |
73 typedef std::map<std::string, double> HostZoomLevels; | 99 typedef std::map<std::string, double> HostZoomLevels; |
74 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; | 100 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; |
75 | 101 |
76 // Callbacks called when zoom level changes. | 102 // Callbacks called when zoom level changes. |
77 base::CallbackList<void(const ZoomLevelChange&)> | 103 base::CallbackList<void(const ZoomLevelChange&)> |
78 zoom_level_changed_callbacks_; | 104 zoom_level_changed_callbacks_; |
79 | 105 |
80 // Copy of the pref data, so that we can read it on the IO thread. | 106 // Copy of the pref data, so that we can read it on the IO thread. |
81 HostZoomLevels host_zoom_levels_; | 107 HostZoomLevels host_zoom_levels_; |
82 SchemeHostZoomLevels scheme_host_zoom_levels_; | 108 SchemeHostZoomLevels scheme_host_zoom_levels_; |
83 double default_zoom_level_; | 109 double default_zoom_level_; |
84 | 110 |
85 struct TemporaryZoomLevel { | 111 struct TemporaryZoomLevel { |
86 int render_process_id; | 112 int render_process_id; |
87 int render_view_id; | 113 int render_view_id; |
88 double zoom_level; | 114 double zoom_level; |
89 }; | 115 }; |
90 | 116 |
91 // Don't expect more than a couple of tabs that are using a temporary zoom | 117 // Don't expect more than a couple of tabs that are using a temporary zoom |
92 // level, so vector is fine for now. | 118 // level, so vector is fine for now. |
93 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; | 119 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; |
94 | 120 |
| 121 // Stores callbacks to be called when the associated zoom changes complete. |
| 122 std::map<int, base::Callback<void(void)> > zoom_callback_map_; |
| 123 |
95 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 124 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
96 // |temporary_zoom_levels_| to guarantee thread safety. | 125 // |temporary_zoom_levels_| to guarantee thread safety. |
97 mutable base::Lock lock_; | 126 mutable base::Lock lock_; |
98 | 127 |
99 NotificationRegistrar registrar_; | 128 NotificationRegistrar registrar_; |
100 | 129 |
101 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 130 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
102 }; | 131 }; |
103 | 132 |
104 } // namespace content | 133 } // namespace content |
105 | 134 |
106 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 135 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
OLD | NEW |