Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: content/browser/host_zoom_map_impl.h

Issue 302603012: Zoom Extension API (content changes) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 HasZoomLevel(const std::string& scheme,
palmer 2014/06/13 17:47:01 Seems like a GURL is a better choice here: It's a
wjmaclean 2014/06/13 20:05:22 Filed crbug.com/384486 to investigate the feasibil
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 bool UsesTemporaryZoomLevel(int render_process_id,
49 int render_view_id) const OVERRIDE;
50 virtual void SetTemporaryZoomLevel(int render_process_id,
51 int render_view_id,
52 double level) OVERRIDE;
53
54 virtual void ClearTemporaryZoomLevel(int render_process_id,
55 int render_view_id) OVERRIDE;
46 virtual double GetDefaultZoomLevel() const OVERRIDE; 56 virtual double GetDefaultZoomLevel() const OVERRIDE;
47 virtual void SetDefaultZoomLevel(double level) OVERRIDE; 57 virtual void SetDefaultZoomLevel(double level) OVERRIDE;
48 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback( 58 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback(
49 const ZoomLevelChangedCallback& callback) OVERRIDE; 59 const ZoomLevelChangedCallback& callback) OVERRIDE;
50 60
51 // Returns the current zoom level for the specified WebContents. This may 61 // Returns the current zoom level for the specified WebContents. This may
52 // be a temporary zoom level, depending on UsesTemporaryZoomLevel(). 62 // be a temporary zoom level, depending on UsesTemporaryZoomLevel().
53 double GetZoomLevelForWebContents( 63 double GetZoomLevelForWebContents(
54 const WebContentsImpl& web_contents_impl) const; 64 const WebContentsImpl& web_contents_impl) const;
55 65
56 // Sets the zoom level for this WebContents. If this WebContents is using 66 // 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. 67 // a temporary zoom level, then level is only applied to this WebContents.
58 // Otherwise, the level will be applied on a host level. 68 // Otherwise, the level will be applied on a host level.
59 void SetZoomLevelForWebContents(const WebContentsImpl& web_contents_impl, 69 void SetZoomLevelForWebContents(const WebContentsImpl& web_contents_impl,
60 double level); 70 double level);
61 71
62 // Sets the zoom level for the specified view. The level may be set for only 72 // 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(). 73 // this view, or for the host, depending on UsesTemporaryZoomLevel().
64 void SetZoomLevelForView(int render_process_id, 74 void SetZoomLevelForView(int render_process_id,
65 int render_view_id, 75 int render_view_id,
66 double level, 76 double level,
67 const std::string& host); 77 const std::string& host);
68 78
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
80 // Returns the temporary zoom level that's only valid for the lifetime of 79 // 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 80 // the given WebContents (i.e. isn't saved and doesn't affect other
82 // WebContentses) if it exists, the default zoom level otherwise. 81 // WebContentses) if it exists, the default zoom level otherwise.
83 // 82 //
84 // This may be called on any thread. 83 // This may be called on any thread.
85 double GetTemporaryZoomLevel(int render_process_id, 84 double GetTemporaryZoomLevel(int render_process_id,
86 int render_view_id) const; 85 int render_view_id) const;
87 86
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. 87 // NotificationObserver implementation.
97 virtual void Observe(int type, 88 virtual void Observe(int type,
98 const NotificationSource& source, 89 const NotificationSource& source,
99 const NotificationDetails& details) OVERRIDE; 90 const NotificationDetails& details) OVERRIDE;
100 91
101 private: 92 private:
102 typedef std::map<std::string, double> HostZoomLevels; 93 typedef std::map<std::string, double> HostZoomLevels;
103 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; 94 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels;
104 95
105 struct TemporaryZoomLevel { 96 struct RenderViewKey {
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; 97 int render_process_id;
111 int render_view_id; 98 int render_view_id;
112 double zoom_level; 99 RenderViewKey(int render_process_id, int render_view_id)
100 : render_process_id(render_process_id),
101 render_view_id(render_view_id) {}
102 bool operator<(const RenderViewKey& other) const {
103 return render_process_id < other.render_process_id ||
104 ((render_process_id == other.render_process_id) &&
105 (render_view_id < other.render_view_id));
106 }
113 }; 107 };
114 108
115 typedef std::vector<TemporaryZoomLevel> TemporaryZoomLevels; 109 typedef std::map<RenderViewKey, double> TemporaryZoomLevels;
116 110
117 double GetZoomLevelForHost(const std::string& host) const; 111 double GetZoomLevelForHost(const std::string& host) const;
118 112
113 // Notifies the renderers from this browser context to change the zoom level
114 // for the specified host and scheme.
115 void SendZoomLevelChange(const std::string& scheme,
palmer 2014/06/13 17:47:01 Same comment here: Prefer the more constrained GUR
wjmaclean 2014/06/13 20:05:22 Ditto.
116 const std::string& host,
117 double level);
118
119 // Callbacks called when zoom level changes. 119 // Callbacks called when zoom level changes.
120 base::CallbackList<void(const ZoomLevelChange&)> 120 base::CallbackList<void(const ZoomLevelChange&)>
121 zoom_level_changed_callbacks_; 121 zoom_level_changed_callbacks_;
122 122
123 // 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.
124 HostZoomLevels host_zoom_levels_; 124 HostZoomLevels host_zoom_levels_;
125 SchemeHostZoomLevels scheme_host_zoom_levels_; 125 SchemeHostZoomLevels scheme_host_zoom_levels_;
126 double default_zoom_level_; 126 double default_zoom_level_;
127 127
128 // 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
129 // level, so vector is fine for now. 129 // level, so vector is fine for now.
130 TemporaryZoomLevels temporary_zoom_levels_; 130 TemporaryZoomLevels temporary_zoom_levels_;
131 131
132 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and 132 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
133 // |temporary_zoom_levels_| to guarantee thread safety. 133 // |temporary_zoom_levels_| to guarantee thread safety.
134 mutable base::Lock lock_; 134 mutable base::Lock lock_;
135 135
136 NotificationRegistrar registrar_; 136 NotificationRegistrar registrar_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); 138 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl);
139 }; 139 };
140 140
141 } // namespace content 141 } // namespace content
142 142
143 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ 143 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/host_zoom_map_impl.cc » ('j') | content/browser/host_zoom_map_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698