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 17 matching lines...) Expand all Loading... |
28 public base::SupportsUserData::Data { | 28 public base::SupportsUserData::Data { |
29 public: | 29 public: |
30 HostZoomMapImpl(); | 30 HostZoomMapImpl(); |
31 virtual ~HostZoomMapImpl(); | 31 virtual ~HostZoomMapImpl(); |
32 | 32 |
33 // HostZoomMap implementation: | 33 // HostZoomMap implementation: |
34 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; | 34 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; |
35 virtual double GetZoomLevelForHostAndScheme( | 35 virtual double GetZoomLevelForHostAndScheme( |
36 const std::string& scheme, | 36 const std::string& scheme, |
37 const std::string& host) const OVERRIDE; | 37 const std::string& host) const OVERRIDE; |
| 38 virtual bool HasZoomLevelInMap(const std::string& scheme, |
| 39 const std::string& host) const OVERRIDE; |
38 virtual ZoomLevelVector GetAllZoomLevels() const OVERRIDE; | 40 virtual ZoomLevelVector GetAllZoomLevels() const OVERRIDE; |
39 virtual void SetZoomLevelForHost( | 41 virtual void SetZoomLevelForHost( |
40 const std::string& host, | 42 const std::string& host, |
41 double level) OVERRIDE; | 43 double level) OVERRIDE; |
42 virtual void SetZoomLevelForHostAndScheme( | 44 virtual void SetZoomLevelForHostAndScheme( |
43 const std::string& scheme, | 45 const std::string& scheme, |
44 const std::string& host, | 46 const std::string& host, |
45 double level) OVERRIDE; | 47 double level) OVERRIDE; |
| 48 virtual void SetTemporaryZoomLevel(int render_process_id, |
| 49 int render_view_id, |
| 50 const std::string& host, |
| 51 double level, |
| 52 bool send_level_to_view) OVERRIDE; |
| 53 virtual void EraseTemporaryZoomLevel(int render_process_id, |
| 54 int render_view_id) OVERRIDE; |
46 virtual double GetDefaultZoomLevel() const OVERRIDE; | 55 virtual double GetDefaultZoomLevel() const OVERRIDE; |
47 virtual void SetDefaultZoomLevel(double level) OVERRIDE; | 56 virtual void SetDefaultZoomLevel(double level) OVERRIDE; |
48 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( | 57 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( |
49 const ZoomLevelChangedCallback& callback) OVERRIDE; | 58 const ZoomLevelChangedCallback& callback) OVERRIDE; |
50 | 59 |
51 // Returns the current zoom level for the specified WebContents. This may | 60 // Returns the current zoom level for the specified WebContents. This may |
52 // be a temporary zoom level, depending on UsesTemporaryZoomLevel(). | 61 // be a temporary zoom level, depending on UsesTemporaryZoomLevel(). |
53 double GetZoomLevelForWebContents( | 62 double GetZoomLevelForWebContents( |
54 const WebContentsImpl& web_contents_impl) const; | 63 const WebContentsImpl& web_contents_impl) const; |
55 | 64 |
(...skipping 22 matching lines...) Expand all Loading... |
78 bool uses_temporary_zoom_level); | 87 bool uses_temporary_zoom_level); |
79 | 88 |
80 // Returns the temporary zoom level that's only valid for the lifetime of | 89 // Returns the temporary zoom level that's only valid for the lifetime of |
81 // the given WebContents (i.e. isn't saved and doesn't affect other | 90 // the given WebContents (i.e. isn't saved and doesn't affect other |
82 // WebContentses) if it exists, the default zoom level otherwise. | 91 // WebContentses) if it exists, the default zoom level otherwise. |
83 // | 92 // |
84 // This may be called on any thread. | 93 // This may be called on any thread. |
85 double GetTemporaryZoomLevel(int render_process_id, | 94 double GetTemporaryZoomLevel(int render_process_id, |
86 int render_view_id) const; | 95 int render_view_id) const; |
87 | 96 |
88 // Sets the temporary zoom level that's only valid for the lifetime of this | |
89 // WebContents. | |
90 // | |
91 // This should only be called on the UI thread. | |
92 void SetTemporaryZoomLevel(int render_process_id, | |
93 int render_view_id, | |
94 double level); | |
95 | |
96 // NotificationObserver implementation. | 97 // NotificationObserver implementation. |
97 virtual void Observe(int type, | 98 virtual void Observe(int type, |
98 const NotificationSource& source, | 99 const NotificationSource& source, |
99 const NotificationDetails& details) OVERRIDE; | 100 const NotificationDetails& details) OVERRIDE; |
100 | 101 |
101 private: | 102 private: |
102 typedef std::map<std::string, double> HostZoomLevels; | 103 typedef std::map<std::string, double> HostZoomLevels; |
103 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; | 104 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; |
104 | 105 |
105 struct TemporaryZoomLevel { | 106 struct TemporaryZoomLevel { |
106 TemporaryZoomLevel(int process_id, int view_id, double level); | 107 TemporaryZoomLevel(int process_id, int view_id, double level); |
107 TemporaryZoomLevel(int process_id, int view_id); | 108 TemporaryZoomLevel(int process_id, int view_id); |
108 bool operator==(const TemporaryZoomLevel& other) const; | 109 bool operator==(const TemporaryZoomLevel& other) const; |
109 | 110 |
110 int render_process_id; | 111 int render_process_id; |
111 int render_view_id; | 112 int render_view_id; |
112 double zoom_level; | 113 double zoom_level; |
113 }; | 114 }; |
114 | 115 |
115 typedef std::vector<TemporaryZoomLevel> TemporaryZoomLevels; | 116 typedef std::vector<TemporaryZoomLevel> TemporaryZoomLevels; |
116 | 117 |
117 double GetZoomLevelForHost(const std::string& host) const; | 118 double GetZoomLevelForHost(const std::string& host) const; |
118 | 119 |
| 120 // Notify a particular render view to change its zoom level. |
| 121 void SendZoomLevelChange(int render_process_id, |
| 122 int render_view_id, |
| 123 double level); |
| 124 |
| 125 // Notifies the renderers from this browser context to change the zoom level |
| 126 // for the specified host and scheme. |
| 127 void SendZoomLevelChange(const std::string& scheme, |
| 128 const std::string& host, |
| 129 double level); |
| 130 |
119 // Callbacks called when zoom level changes. | 131 // Callbacks called when zoom level changes. |
120 base::CallbackList<void(const ZoomLevelChange&)> | 132 base::CallbackList<void(const ZoomLevelChange&)> |
121 zoom_level_changed_callbacks_; | 133 zoom_level_changed_callbacks_; |
122 | 134 |
123 // Copy of the pref data, so that we can read it on the IO thread. | 135 // Copy of the pref data, so that we can read it on the IO thread. |
124 HostZoomLevels host_zoom_levels_; | 136 HostZoomLevels host_zoom_levels_; |
125 SchemeHostZoomLevels scheme_host_zoom_levels_; | 137 SchemeHostZoomLevels scheme_host_zoom_levels_; |
126 double default_zoom_level_; | 138 double default_zoom_level_; |
127 | 139 |
128 // Don't expect more than a couple of tabs that are using a temporary zoom | 140 // Don't expect more than a couple of tabs that are using a temporary zoom |
129 // level, so vector is fine for now. | 141 // level, so vector is fine for now. |
130 TemporaryZoomLevels temporary_zoom_levels_; | 142 TemporaryZoomLevels temporary_zoom_levels_; |
131 | 143 |
132 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 144 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
133 // |temporary_zoom_levels_| to guarantee thread safety. | 145 // |temporary_zoom_levels_| to guarantee thread safety. |
134 mutable base::Lock lock_; | 146 mutable base::Lock lock_; |
135 | 147 |
136 NotificationRegistrar registrar_; | 148 NotificationRegistrar registrar_; |
137 | 149 |
138 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 150 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
139 }; | 151 }; |
140 | 152 |
141 } // namespace content | 153 } // namespace content |
142 | 154 |
143 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 155 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
OLD | NEW |