Update broken references to image assets
[chromium-blink-merge.git] / content / public / browser / host_zoom_map.h
bloba4aca1d232f6a97423333490ad242b6d32e06842
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.
45 PAGE_SCALE_IS_ONE_CHANGED, // Page scale factor equal to one changed
46 // for a host.
49 // Structure used to notify about zoom changes. Host and/or scheme are empty
50 // if not applicable to |mode|.
51 struct ZoomLevelChange {
52 ZoomLevelChangeMode mode;
53 std::string host;
54 std::string scheme;
55 double zoom_level;
58 typedef std::vector<ZoomLevelChange> ZoomLevelVector;
60 // Extracts the URL from NavigationEntry, substituting the error page
61 // URL in the event that the error page is showing.
62 CONTENT_EXPORT static GURL GetURLFromEntry(const NavigationEntry* entry);
64 CONTENT_EXPORT static HostZoomMap* GetDefaultForBrowserContext(
65 BrowserContext* browser_context);
67 // Returns the HostZoomMap associated with this SiteInstance. The SiteInstance
68 // may serve multiple WebContents, and the HostZoomMap is the same for all of
69 // these WebContents.
70 CONTENT_EXPORT static HostZoomMap* Get(SiteInstance* instance);
72 // Returns the HostZoomMap associated with this WebContent's main frame. If
73 // multiple WebContents share the same SiteInstance, then they share a single
74 // HostZoomMap.
75 CONTENT_EXPORT static HostZoomMap* GetForWebContents(
76 const WebContents* contents);
78 // Returns the current zoom level for the specified WebContents. May be
79 // temporary or host-specific.
80 CONTENT_EXPORT static double GetZoomLevel(const WebContents* web_contents);
82 // Returns true if the page scale factor for the WebContents is one.
83 CONTENT_EXPORT static bool PageScaleFactorIsOne(
84 const WebContents* web_contents);
86 // Sets the current zoom level for the specified WebContents. The level may
87 // be temporary or host-specific depending on the particular WebContents.
88 CONTENT_EXPORT static void SetZoomLevel(const WebContents* web_contents,
89 double level);
91 // Send an IPC to refresh any displayed error page's zoom levels. Needs to
92 // be called since error pages don't get loaded via the normal channel.
93 CONTENT_EXPORT static void SendErrorPageZoomLevelRefresh(
94 const WebContents* web_contents);
96 // Set or clear whether or not the page scale factor for a view is one.
97 virtual void SetPageScaleFactorIsOneForView(
98 int render_process_id, int render_view_id, bool is_one) = 0;
99 virtual void ClearPageScaleFactorIsOneForView(
100 int render_process_id, int render_view_id) = 0;
102 // Copy the zoom levels from the given map. Can only be called on the UI
103 // thread.
104 virtual void CopyFrom(HostZoomMap* copy) = 0;
106 // Here |host| is the host portion of URL, or (in the absence of a host)
107 // the complete spec of the URL.
108 // Returns the zoom for the specified |scheme| and |host|. See class
109 // description for details.
111 // This may be called on any thread.
112 virtual double GetZoomLevelForHostAndScheme(
113 const std::string& scheme,
114 const std::string& host) const = 0;
116 // Returns true if the specified |scheme| and/or |host| has a zoom level
117 // currently set.
119 // This may be called on any thread.
120 virtual bool HasZoomLevel(const std::string& scheme,
121 const std::string& host) const = 0;
123 // Returns all non-temporary zoom levels. Can be called on any thread.
124 virtual ZoomLevelVector GetAllZoomLevels() const = 0;
126 // Here |host| is the host portion of URL, or (in the absence of a host)
127 // the complete spec of the URL.
128 // Sets the zoom level for the |host| to |level|. If the level matches the
129 // current default zoom level, the host is erased from the saved preferences;
130 // otherwise the new value is written out.
131 // Zoom levels specified for both scheme and host are not affected.
133 // This should only be called on the UI thread.
134 virtual void SetZoomLevelForHost(const std::string& host, double level) = 0;
136 // Here |host| is the host portion of URL, or (in the absence of a host)
137 // the complete spec of the URL.
138 // Sets the zoom level for the |scheme|/|host| pair to |level|. No values
139 // will be erased during this operation, and this value will not be stored in
140 // the preferences.
142 // This should only be called on the UI thread.
143 virtual void SetZoomLevelForHostAndScheme(const std::string& scheme,
144 const std::string& host,
145 double level) = 0;
147 // Returns whether the view manages its zoom level independently of other
148 // views displaying content from the same host.
149 virtual bool UsesTemporaryZoomLevel(int render_process_id,
150 int render_view_id) const = 0;
152 // Sets the temporary zoom level that's only valid for the lifetime of this
153 // WebContents.
155 // This should only be called on the UI thread.
156 virtual void SetTemporaryZoomLevel(int render_process_id,
157 int render_view_id,
158 double level) = 0;
160 // Clears the temporary zoom level stored for this WebContents.
162 // This should only be called on the UI thread.
163 virtual void ClearTemporaryZoomLevel(int render_process_id,
164 int render_view_id) = 0;
166 // Get/Set the default zoom level for pages that don't override it.
167 virtual double GetDefaultZoomLevel() const = 0;
168 virtual void SetDefaultZoomLevel(double level) = 0;;
170 typedef base::Callback<void(const ZoomLevelChange&)> ZoomLevelChangedCallback;
171 typedef base::CallbackList<void(const ZoomLevelChange&)>::Subscription
172 Subscription;
173 // Add and remove zoom level changed callbacks.
174 virtual scoped_ptr<Subscription> AddZoomLevelChangedCallback(
175 const ZoomLevelChangedCallback& callback) = 0;
177 protected:
178 virtual ~HostZoomMap() {}
181 } // namespace content
183 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_