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 12 matching lines...) Expand all Loading... |
23 // to notifications on there (and holds a NotificationRegistrar). | 23 // to notifications on there (and holds a NotificationRegistrar). |
24 class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), | 24 class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), |
25 public NotificationObserver, | 25 public NotificationObserver, |
26 public base::SupportsUserData::Data { | 26 public base::SupportsUserData::Data { |
27 public: | 27 public: |
28 HostZoomMapImpl(); | 28 HostZoomMapImpl(); |
29 virtual ~HostZoomMapImpl(); | 29 virtual ~HostZoomMapImpl(); |
30 | 30 |
31 // HostZoomMap implementation: | 31 // HostZoomMap implementation: |
32 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; | 32 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; |
33 virtual double GetZoomLevel(const std::string& host) const OVERRIDE; | 33 virtual double GetZoomLevelForHostAndScheme( |
34 virtual void SetZoomLevel(const std::string& host, double level) OVERRIDE; | 34 const std::string& scheme, |
| 35 const std::string& host) const OVERRIDE; |
| 36 virtual void SetZoomLevelForHost( |
| 37 const std::string& host, |
| 38 double level) OVERRIDE; |
| 39 virtual void SetZoomLevelForHostAndScheme( |
| 40 const std::string& scheme, |
| 41 const std::string& host, |
| 42 double level) OVERRIDE; |
35 virtual double GetDefaultZoomLevel() const OVERRIDE; | 43 virtual double GetDefaultZoomLevel() const OVERRIDE; |
36 virtual void SetDefaultZoomLevel(double level) OVERRIDE; | 44 virtual void SetDefaultZoomLevel(double level) OVERRIDE; |
37 virtual void AddZoomLevelChangedCallback( | 45 virtual void AddZoomLevelChangedCallback( |
38 const ZoomLevelChangedCallback& callback) OVERRIDE; | 46 const ZoomLevelChangedCallback& callback) OVERRIDE; |
39 virtual void RemoveZoomLevelChangedCallback( | 47 virtual void RemoveZoomLevelChangedCallback( |
40 const ZoomLevelChangedCallback& callback) OVERRIDE; | 48 const ZoomLevelChangedCallback& callback) OVERRIDE; |
41 | 49 |
42 // Returns the temporary zoom level that's only valid for the lifetime of | 50 // Returns the temporary zoom level that's only valid for the lifetime of |
43 // the given WebContents (i.e. isn't saved and doesn't affect other | 51 // the given WebContents (i.e. isn't saved and doesn't affect other |
44 // WebContentses) if it exists, the default zoom level otherwise. | 52 // WebContentses) if it exists, the default zoom level otherwise. |
45 // | 53 // |
46 // This may be called on any thread. | 54 // This may be called on any thread. |
47 double GetTemporaryZoomLevel(int render_process_id, | 55 double GetTemporaryZoomLevel(int render_process_id, |
48 int render_view_id) const; | 56 int render_view_id) const; |
49 | 57 |
50 // Sets the temporary zoom level that's only valid for the lifetime of this | 58 // Sets the temporary zoom level that's only valid for the lifetime of this |
51 // WebContents. | 59 // WebContents. |
52 // | 60 // |
53 // This should only be called on the UI thread. | 61 // This should only be called on the UI thread. |
54 void SetTemporaryZoomLevel(int render_process_id, | 62 void SetTemporaryZoomLevel(int render_process_id, |
55 int render_view_id, | 63 int render_view_id, |
56 double level); | 64 double level); |
57 | 65 |
58 // NotificationObserver implementation. | 66 // NotificationObserver implementation. |
59 virtual void Observe(int type, | 67 virtual void Observe(int type, |
60 const NotificationSource& source, | 68 const NotificationSource& source, |
61 const NotificationDetails& details) OVERRIDE; | 69 const NotificationDetails& details) OVERRIDE; |
62 | 70 |
63 private: | 71 private: |
| 72 double GetZoomLevelForHost(const std::string& host) const; |
| 73 |
64 typedef std::map<std::string, double> HostZoomLevels; | 74 typedef std::map<std::string, double> HostZoomLevels; |
| 75 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; |
65 | 76 |
66 // Callbacks called when zoom level changes. | 77 // Callbacks called when zoom level changes. |
67 std::vector<ZoomLevelChangedCallback> zoom_level_changed_callbacks_; | 78 std::vector<ZoomLevelChangedCallback> zoom_level_changed_callbacks_; |
68 | 79 |
69 // Copy of the pref data, so that we can read it on the IO thread. | 80 // Copy of the pref data, so that we can read it on the IO thread. |
70 HostZoomLevels host_zoom_levels_; | 81 HostZoomLevels host_zoom_levels_; |
| 82 SchemeHostZoomLevels scheme_host_zoom_levels_; |
71 double default_zoom_level_; | 83 double default_zoom_level_; |
72 | 84 |
73 struct TemporaryZoomLevel { | 85 struct TemporaryZoomLevel { |
74 int render_process_id; | 86 int render_process_id; |
75 int render_view_id; | 87 int render_view_id; |
76 double zoom_level; | 88 double zoom_level; |
77 }; | 89 }; |
78 | 90 |
79 // Don't expect more than a couple of tabs that are using a temporary zoom | 91 // Don't expect more than a couple of tabs that are using a temporary zoom |
80 // level, so vector is fine for now. | 92 // level, so vector is fine for now. |
81 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; | 93 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; |
82 | 94 |
83 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 95 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
84 // |temporary_zoom_levels_| to guarantee thread safety. | 96 // |temporary_zoom_levels_| to guarantee thread safety. |
85 mutable base::Lock lock_; | 97 mutable base::Lock lock_; |
86 | 98 |
87 NotificationRegistrar registrar_; | 99 NotificationRegistrar registrar_; |
88 | 100 |
89 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 101 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
90 }; | 102 }; |
91 | 103 |
92 } // namespace content | 104 } // namespace content |
93 | 105 |
94 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 106 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
OLD | NEW |