ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / public / browser / host_zoom_map.h
blob653d24882fe0c5532e15524bf44129373748f276
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_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
6 #define CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/callback_list.h"
15 #include "content/common/content_export.h"
16 #include "url/gurl.h"
18 namespace content {
20 class NavigationEntry;
21 class BrowserContext;
22 class ResourceContext;
23 class SiteInstance;
24 class WebContents;
26 // Maps hostnames to custom zoom levels. Written on the UI thread and read on
27 // any thread. One instance per browser context. Must be created on the UI
28 // thread, and it'll delete itself on the UI thread as well.
29 // Zoom can be defined at three levels: default zoom, zoom for host, and zoom
30 // for host with specific scheme. Setting any of the levels leaves settings
31 // for other settings intact. Getting the zoom level starts at the most
32 // specific setting and progresses to the less specific: first the zoom for the
33 // host and scheme pair is checked, secondly the zoom for the host only and
34 // lastly default zoom.
36 class HostZoomMap {
37 public:
38 // Enum that indicates what was the scope of zoom level change.
39 enum ZoomLevelChangeMode {
40 ZOOM_CHANGED_FOR_HOST, // Zoom level changed for host.
41 ZOOM_CHANGED_FOR_SCHEME_AND_HOST, // Zoom level changed for scheme/host
42 // pair.
43 ZOOM_CHANGED_TEMPORARY_ZOOM, // Temporary zoom change for specific
44 // renderer, no scheme/host is specified.
47 // Structure used to notify about zoom changes. Host and/or scheme are empty
48 // if not applicable to |mode|.
49 struct ZoomLevelChange {
50 ZoomLevelChangeMode mode;
51 std::string host;
52 std::string scheme;
53 double zoom_level;
56 typedef std::vector<ZoomLevelChange> ZoomLevelVector;
58 // Extracts the URL from NavigationEntry, substituting the error page
59 // URL in the event that the error page is showing.
60 CONTENT_EXPORT static GURL GetURLFromEntry(const NavigationEntry* entry);
62 CONTENT_EXPORT static HostZoomMap* GetDefaultForBrowserContext(
63 BrowserContext* browser_context);
65 // Returns the HostZoomMap associated with this SiteInstance. The SiteInstance
66 // may serve multiple WebContents, and the HostZoomMap is the same for all of
67 // these WebContents.
68 CONTENT_EXPORT static HostZoomMap* Get(SiteInstance* instance);
70 // Returns the HostZoomMap associated with this WebContent's main frame. If
71 // multiple WebContents share the same SiteInstance, then they share a single
72 // HostZoomMap.
73 CONTENT_EXPORT static HostZoomMap* GetForWebContents(
74 const WebContents* contents);
76 // Returns the current zoom level for the specified WebContents. May be
77 // temporary or host-specific.
78 CONTENT_EXPORT static double GetZoomLevel(const WebContents* web_contents);
80 // Sets the current zoom level for the specified WebContents. The level may
81 // be temporary or host-specific depending on the particular WebContents.
82 CONTENT_EXPORT static void SetZoomLevel(const WebContents* web_contents,
83 double level);
85 // Send an IPC to refresh any displayed error page's zoom levels. Needs to
86 // be called since error pages don't get loaded via the normal channel.
87 CONTENT_EXPORT static void SendErrorPageZoomLevelRefresh(
88 const WebContents* web_contents);
90 // Copy the zoom levels from the given map. Can only be called on the UI
91 // thread.
92 virtual void CopyFrom(HostZoomMap* copy) = 0;
94 // Here |host| is the host portion of URL, or (in the absence of a host)
95 // the complete spec of the URL.
96 // Returns the zoom for the specified |scheme| and |host|. See class
97 // description for details.
99 // This may be called on any thread.
100 virtual double GetZoomLevelForHostAndScheme(
101 const std::string& scheme,
102 const std::string& host) const = 0;
104 // Returns true if the specified |scheme| and/or |host| has a zoom level
105 // currently set.
107 // This may be called on any thread.
108 virtual bool HasZoomLevel(const std::string& scheme,
109 const std::string& host) const = 0;
111 // Returns all non-temporary zoom levels. Can be called on any thread.
112 virtual ZoomLevelVector GetAllZoomLevels() const = 0;
114 // Here |host| is the host portion of URL, or (in the absence of a host)
115 // the complete spec of the URL.
116 // Sets the zoom level for the |host| to |level|. If the level matches the
117 // current default zoom level, the host is erased from the saved preferences;
118 // otherwise the new value is written out.
119 // Zoom levels specified for both scheme and host are not affected.
121 // This should only be called on the UI thread.
122 virtual void SetZoomLevelForHost(const std::string& host, double level) = 0;
124 // Here |host| is the host portion of URL, or (in the absence of a host)
125 // the complete spec of the URL.
126 // Sets the zoom level for the |scheme|/|host| pair to |level|. No values
127 // will be erased during this operation, and this value will not be stored in
128 // the preferences.
130 // This should only be called on the UI thread.
131 virtual void SetZoomLevelForHostAndScheme(const std::string& scheme,
132 const std::string& host,
133 double level) = 0;
135 // Returns whether the view manages its zoom level independently of other
136 // views displaying content from the same host.
137 virtual bool UsesTemporaryZoomLevel(int render_process_id,
138 int render_view_id) const = 0;
140 // Sets the temporary zoom level that's only valid for the lifetime of this
141 // WebContents.
143 // This should only be called on the UI thread.
144 virtual void SetTemporaryZoomLevel(int render_process_id,
145 int render_view_id,
146 double level) = 0;
148 // Clears the temporary zoom level stored for this WebContents.
150 // This should only be called on the UI thread.
151 virtual void ClearTemporaryZoomLevel(int render_process_id,
152 int render_view_id) = 0;
154 // Get/Set the default zoom level for pages that don't override it.
155 virtual double GetDefaultZoomLevel() const = 0;
156 virtual void SetDefaultZoomLevel(double level) = 0;;
158 typedef base::Callback<void(const ZoomLevelChange&)> ZoomLevelChangedCallback;
159 typedef base::CallbackList<void(const ZoomLevelChange&)>::Subscription
160 Subscription;
161 // Add and remove zoom level changed callbacks.
162 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback(
163 const ZoomLevelChangedCallback& callback) = 0;
165 protected:
166 virtual ~HostZoomMap() {}
169 } // namespace content
171 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_