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> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/sequenced_task_runner_helpers.h" | 13 #include "base/sequenced_task_runner_helpers.h" |
14 #include "base/supports_user_data.h" | 14 #include "base/supports_user_data.h" |
15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
16 #include "content/public/browser/host_zoom_map.h" | 16 #include "content/public/browser/host_zoom_map.h" |
17 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
| 22 class WebContentsImpl; |
| 23 |
22 // HostZoomMap needs to be deleted on the UI thread because it listens | 24 // HostZoomMap needs to be deleted on the UI thread because it listens |
23 // to notifications on there (and holds a NotificationRegistrar). | 25 // to notifications on there (and holds a NotificationRegistrar). |
24 class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), | 26 class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), |
25 public NotificationObserver, | 27 public NotificationObserver, |
26 public base::SupportsUserData::Data { | 28 public base::SupportsUserData::Data { |
27 public: | 29 public: |
28 HostZoomMapImpl(); | 30 HostZoomMapImpl(); |
29 virtual ~HostZoomMapImpl(); | 31 virtual ~HostZoomMapImpl(); |
30 | 32 |
31 // HostZoomMap implementation: | 33 // HostZoomMap implementation: |
32 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; | 34 virtual void CopyFrom(HostZoomMap* copy) OVERRIDE; |
33 virtual double GetZoomLevelForHostAndScheme( | 35 virtual double GetZoomLevelForHostAndScheme( |
34 const std::string& scheme, | 36 const std::string& scheme, |
35 const std::string& host) const OVERRIDE; | 37 const std::string& host) const OVERRIDE; |
36 virtual ZoomLevelVector GetAllZoomLevels() const OVERRIDE; | 38 virtual ZoomLevelVector GetAllZoomLevels() const OVERRIDE; |
37 virtual void SetZoomLevelForHost( | 39 virtual void SetZoomLevelForHost( |
38 const std::string& host, | 40 const std::string& host, |
39 double level) OVERRIDE; | 41 double level) OVERRIDE; |
40 virtual void SetZoomLevelForHostAndScheme( | 42 virtual void SetZoomLevelForHostAndScheme( |
41 const std::string& scheme, | 43 const std::string& scheme, |
42 const std::string& host, | 44 const std::string& host, |
43 double level) OVERRIDE; | 45 double level) OVERRIDE; |
44 virtual double GetDefaultZoomLevel() const OVERRIDE; | 46 virtual double GetDefaultZoomLevel() const OVERRIDE; |
45 virtual void SetDefaultZoomLevel(double level) OVERRIDE; | 47 virtual void SetDefaultZoomLevel(double level) OVERRIDE; |
46 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( | 48 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( |
47 const ZoomLevelChangedCallback& callback) OVERRIDE; | 49 const ZoomLevelChangedCallback& callback) OVERRIDE; |
48 | 50 |
| 51 // Returns the current zoom level for the specified WebContents. This may |
| 52 // be a temporary zoom level, depending on UsesTemporaryZoomLevel(). |
| 53 double GetZoomLevelForWebContents( |
| 54 const WebContentsImpl& web_contents_impl) const; |
| 55 |
| 56 // Sets the zoom level for this WebContents. If this WebContents is using |
| 57 // a temporary zoom level, then level is only applied to this WebContents. |
| 58 // Otherwise, the level will be applied on a host level. |
| 59 void SetZoomLevelForWebContents(const WebContentsImpl& web_contents_impl, |
| 60 double level); |
| 61 |
| 62 // Sets the zoom level for the specified view. The level may be set for only |
| 63 // this view, or for the host, depending on UsesTemporaryZoomLevel(). |
| 64 void SetZoomLevelForView(int render_process_id, |
| 65 int render_view_id, |
| 66 double level, |
| 67 const std::string& host); |
| 68 |
| 69 // Returns whether the view manages its zoom level independently of other tabs |
| 70 // displaying content from the same host. |
| 71 bool UsesTemporaryZoomLevel(int render_process_id, int render_view_id) const; |
| 72 |
| 73 // Sets whether the view manages its zoom level independently of other tabs |
| 74 // displaying content from the same host, based on whether |
| 75 // |uses_temporary_zoom_level| is true. |
| 76 void SetUsesTemporaryZoomLevel(int render_process_id, |
| 77 int render_view_id, |
| 78 bool uses_temporary_zoom_level); |
| 79 |
49 // Returns the temporary zoom level that's only valid for the lifetime of | 80 // 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 | 81 // the given WebContents (i.e. isn't saved and doesn't affect other |
51 // WebContentses) if it exists, the default zoom level otherwise. | 82 // WebContentses) if it exists, the default zoom level otherwise. |
52 // | 83 // |
53 // This may be called on any thread. | 84 // This may be called on any thread. |
54 double GetTemporaryZoomLevel(int render_process_id, | 85 double GetTemporaryZoomLevel(int render_process_id, |
55 int render_view_id) const; | 86 int render_view_id) const; |
56 | 87 |
57 // Sets the temporary zoom level that's only valid for the lifetime of this | 88 // Sets the temporary zoom level that's only valid for the lifetime of this |
58 // WebContents. | 89 // WebContents. |
59 // | 90 // |
60 // This should only be called on the UI thread. | 91 // This should only be called on the UI thread. |
61 void SetTemporaryZoomLevel(int render_process_id, | 92 void SetTemporaryZoomLevel(int render_process_id, |
62 int render_view_id, | 93 int render_view_id, |
63 double level); | 94 double level); |
64 | 95 |
65 // NotificationObserver implementation. | 96 // NotificationObserver implementation. |
66 virtual void Observe(int type, | 97 virtual void Observe(int type, |
67 const NotificationSource& source, | 98 const NotificationSource& source, |
68 const NotificationDetails& details) OVERRIDE; | 99 const NotificationDetails& details) OVERRIDE; |
69 | 100 |
70 private: | 101 private: |
71 double GetZoomLevelForHost(const std::string& host) const; | |
72 | |
73 typedef std::map<std::string, double> HostZoomLevels; | 102 typedef std::map<std::string, double> HostZoomLevels; |
74 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; | 103 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; |
75 | 104 |
| 105 struct TemporaryZoomLevel { |
| 106 TemporaryZoomLevel(int process_id, int view_id, double level); |
| 107 TemporaryZoomLevel(int process_id, int view_id); |
| 108 bool operator==(const TemporaryZoomLevel& other) const; |
| 109 |
| 110 int render_process_id; |
| 111 int render_view_id; |
| 112 double zoom_level; |
| 113 }; |
| 114 |
| 115 typedef std::vector<TemporaryZoomLevel> TemporaryZoomLevels; |
| 116 |
| 117 double GetZoomLevelForHost(const std::string& host) const; |
| 118 |
76 // Callbacks called when zoom level changes. | 119 // Callbacks called when zoom level changes. |
77 base::CallbackList<void(const ZoomLevelChange&)> | 120 base::CallbackList<void(const ZoomLevelChange&)> |
78 zoom_level_changed_callbacks_; | 121 zoom_level_changed_callbacks_; |
79 | 122 |
80 // Copy of the pref data, so that we can read it on the IO thread. | 123 // Copy of the pref data, so that we can read it on the IO thread. |
81 HostZoomLevels host_zoom_levels_; | 124 HostZoomLevels host_zoom_levels_; |
82 SchemeHostZoomLevels scheme_host_zoom_levels_; | 125 SchemeHostZoomLevels scheme_host_zoom_levels_; |
83 double default_zoom_level_; | 126 double default_zoom_level_; |
84 | 127 |
85 struct TemporaryZoomLevel { | |
86 int render_process_id; | |
87 int render_view_id; | |
88 double zoom_level; | |
89 }; | |
90 | |
91 // Don't expect more than a couple of tabs that are using a temporary zoom | 128 // Don't expect more than a couple of tabs that are using a temporary zoom |
92 // level, so vector is fine for now. | 129 // level, so vector is fine for now. |
93 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; | 130 TemporaryZoomLevels temporary_zoom_levels_; |
94 | 131 |
95 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and | 132 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and |
96 // |temporary_zoom_levels_| to guarantee thread safety. | 133 // |temporary_zoom_levels_| to guarantee thread safety. |
97 mutable base::Lock lock_; | 134 mutable base::Lock lock_; |
98 | 135 |
99 NotificationRegistrar registrar_; | 136 NotificationRegistrar registrar_; |
100 | 137 |
101 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); | 138 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); |
102 }; | 139 }; |
103 | 140 |
104 } // namespace content | 141 } // namespace content |
105 | 142 |
106 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ | 143 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ |
OLD | NEW |