ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / host_zoom_map_impl.h
blob468bf68b735f47f20706ca76760ef2e6345faee1
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
6 #define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/compiler_specific.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "base/synchronization/lock.h"
15 #include "content/public/browser/host_zoom_map.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
19 namespace content {
21 class WebContentsImpl;
23 // HostZoomMap needs to be deleted on the UI thread because it listens
24 // to notifications on there (and holds a NotificationRegistrar).
25 class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap),
26 public NotificationObserver {
27 public:
28 HostZoomMapImpl();
29 ~HostZoomMapImpl() override;
31 // HostZoomMap implementation:
32 void CopyFrom(HostZoomMap* copy) override;
33 double GetZoomLevelForHostAndScheme(const std::string& scheme,
34 const std::string& host) const override;
35 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
36 bool HasZoomLevel(const std::string& scheme,
37 const std::string& host) const override;
38 ZoomLevelVector GetAllZoomLevels() const override;
39 void SetZoomLevelForHost(const std::string& host, double level) override;
40 void SetZoomLevelForHostAndScheme(const std::string& scheme,
41 const std::string& host,
42 double level) override;
43 bool UsesTemporaryZoomLevel(int render_process_id,
44 int render_view_id) const override;
45 void SetTemporaryZoomLevel(int render_process_id,
46 int render_view_id,
47 double level) override;
49 void ClearTemporaryZoomLevel(int render_process_id,
50 int render_view_id) override;
51 double GetDefaultZoomLevel() const override;
52 void SetDefaultZoomLevel(double level) override;
53 scoped_ptr<Subscription> AddZoomLevelChangedCallback(
54 const ZoomLevelChangedCallback& callback) override;
56 // Returns the current zoom level for the specified WebContents. This may
57 // be a temporary zoom level, depending on UsesTemporaryZoomLevel().
58 double GetZoomLevelForWebContents(
59 const WebContentsImpl& web_contents_impl) const;
61 // Sets the zoom level for this WebContents. If this WebContents is using
62 // a temporary zoom level, then level is only applied to this WebContents.
63 // Otherwise, the level will be applied on a host level.
64 void SetZoomLevelForWebContents(const WebContentsImpl& web_contents_impl,
65 double level);
67 // Sets the zoom level for the specified view. The level may be set for only
68 // this view, or for the host, depending on UsesTemporaryZoomLevel().
69 void SetZoomLevelForView(int render_process_id,
70 int render_view_id,
71 double level,
72 const std::string& host);
74 // Returns the temporary zoom level that's only valid for the lifetime of
75 // the given WebContents (i.e. isn't saved and doesn't affect other
76 // WebContentses) if it exists, the default zoom level otherwise.
78 // This may be called on any thread.
79 double GetTemporaryZoomLevel(int render_process_id,
80 int render_view_id) const;
82 // Returns the zoom level regardless of whether it's temporary, host-keyed or
83 // scheme+host-keyed.
85 // This may be called on any thread.
86 double GetZoomLevelForView(const GURL& url,
87 int render_process_id,
88 int render_view_id) const;
90 // NotificationObserver implementation.
91 void Observe(int type,
92 const NotificationSource& source,
93 const NotificationDetails& details) override;
95 void SendErrorPageZoomLevelRefresh();
97 private:
98 typedef std::map<std::string, double> HostZoomLevels;
99 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels;
101 struct RenderViewKey {
102 int render_process_id;
103 int render_view_id;
104 RenderViewKey(int render_process_id, int render_view_id)
105 : render_process_id(render_process_id),
106 render_view_id(render_view_id) {}
107 bool operator<(const RenderViewKey& other) const {
108 return render_process_id < other.render_process_id ||
109 ((render_process_id == other.render_process_id) &&
110 (render_view_id < other.render_view_id));
114 typedef std::map<RenderViewKey, double> TemporaryZoomLevels;
116 double GetZoomLevelForHost(const std::string& host) const;
118 // Non-locked versions for internal use. These should only be called within
119 // a scope where a lock has been acquired.
120 double GetZoomLevelForHostInternal(const std::string& host) const;
121 double GetZoomLevelForHostAndSchemeInternal(const std::string& scheme,
122 const std::string& host) const;
124 // Notifies the renderers from this browser context to change the zoom level
125 // for the specified host and scheme.
126 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
127 void SendZoomLevelChange(const std::string& scheme,
128 const std::string& host,
129 double level);
131 // Callbacks called when zoom level changes.
132 base::CallbackList<void(const ZoomLevelChange&)>
133 zoom_level_changed_callbacks_;
135 // Copy of the pref data, so that we can read it on the IO thread.
136 HostZoomLevels host_zoom_levels_;
137 SchemeHostZoomLevels scheme_host_zoom_levels_;
138 double default_zoom_level_;
140 // Don't expect more than a couple of tabs that are using a temporary zoom
141 // level, so vector is fine for now.
142 TemporaryZoomLevels temporary_zoom_levels_;
144 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
145 // |temporary_zoom_levels_| to guarantee thread safety.
146 mutable base::Lock lock_;
148 NotificationRegistrar registrar_;
150 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl);
153 } // namespace content
155 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_