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

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

Issue 224733018: Changes to content/ to facilitate new zoom extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 8 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 28 matching lines...) Expand all
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
77 // Erases the temporary zoom level stored for a WebContents.
78 //
79 // This should only be called on the UI thread.
80 void EraseTemporaryZoomLevel(int render_process_id, int render_view_id);
81
65 // NotificationObserver implementation. 82 // NotificationObserver implementation.
66 virtual void Observe(int type, 83 virtual void Observe(int type,
67 const NotificationSource& source, 84 const NotificationSource& source,
68 const NotificationDetails& details) OVERRIDE; 85 const NotificationDetails& details) OVERRIDE;
69 86
70 private: 87 private:
88 // Called when the zoom change with ID |zoom_id| has completed, and its
89 // associated callback should be called. Each callback can only be called
90 // once, and is removed from the |zoom_callback_map_| after calling.
91 void CallZoomCallback(int zoom_id);
92
71 double GetZoomLevelForHost(const std::string& host) const; 93 double GetZoomLevelForHost(const std::string& host) const;
72 94
95 // Notifies the renderers from this browser context to change the zoom level
96 // for the specified host and scheme.
97 void SendZoomLevelChange(const std::string& scheme,
98 const std::string& host,
99 double level);
100
73 typedef std::map<std::string, double> HostZoomLevels; 101 typedef std::map<std::string, double> HostZoomLevels;
74 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels; 102 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels;
75 103
76 // Callbacks called when zoom level changes. 104 // Callbacks called when zoom level changes.
77 base::CallbackList<void(const ZoomLevelChange&)> 105 base::CallbackList<void(const ZoomLevelChange&)>
78 zoom_level_changed_callbacks_; 106 zoom_level_changed_callbacks_;
79 107
80 // Copy of the pref data, so that we can read it on the IO thread. 108 // Copy of the pref data, so that we can read it on the IO thread.
81 HostZoomLevels host_zoom_levels_; 109 HostZoomLevels host_zoom_levels_;
82 SchemeHostZoomLevels scheme_host_zoom_levels_; 110 SchemeHostZoomLevels scheme_host_zoom_levels_;
83 double default_zoom_level_; 111 double default_zoom_level_;
84 112
85 struct TemporaryZoomLevel { 113 struct TemporaryZoomLevel {
86 int render_process_id; 114 int render_process_id;
87 int render_view_id; 115 int render_view_id;
88 double zoom_level; 116 double zoom_level;
89 }; 117 };
90 118
91 // Don't expect more than a couple of tabs that are using a temporary zoom 119 // Don't expect more than a couple of tabs that are using a temporary zoom
92 // level, so vector is fine for now. 120 // level, so vector is fine for now.
93 std::vector<TemporaryZoomLevel> temporary_zoom_levels_; 121 std::vector<TemporaryZoomLevel> temporary_zoom_levels_;
94 122
123 // Stores callbacks to be called when the associated zoom changes complete.
124 std::map<int, base::Callback<void(void)> > zoom_callback_map_;
125
95 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and 126 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
96 // |temporary_zoom_levels_| to guarantee thread safety. 127 // |temporary_zoom_levels_| to guarantee thread safety.
97 mutable base::Lock lock_; 128 mutable base::Lock lock_;
98 129
99 NotificationRegistrar registrar_; 130 NotificationRegistrar registrar_;
100 131
101 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl); 132 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl);
102 }; 133 };
103 134
104 } // namespace content 135 } // namespace content
105 136
106 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_ 137 #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/public/browser/web_contents.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698