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_
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/callback_list.h"
15 #include "content/common/content_export.h"
20 class ResourceContext
;
23 // Maps hostnames to custom zoom levels. Written on the UI thread and read on
24 // any thread. One instance per browser context. Must be created on the UI
25 // thread, and it'll delete itself on the UI thread as well.
26 // Zoom can be defined at three levels: default zoom, zoom for host, and zoom
27 // for host with specific scheme. Setting any of the levels leaves settings
28 // for other settings intact. Getting the zoom level starts at the most
29 // specific setting and progresses to the less specific: first the zoom for the
30 // host and scheme pair is checked, secondly the zoom for the host only and
31 // lastly default zoom.
35 // Enum that indicates what was the scope of zoom level change.
36 enum ZoomLevelChangeMode
{
37 ZOOM_CHANGED_FOR_HOST
, // Zoom level changed for host.
38 ZOOM_CHANGED_FOR_SCHEME_AND_HOST
, // Zoom level changed for scheme/host
40 ZOOM_CHANGED_TEMPORARY_ZOOM
, // Temporary zoom change for specific
41 // renderer, no scheme/host is specified.
44 // Structure used to notify about zoom changes. Host and/or scheme are empty
45 // if not applicable to |mode|.
46 struct ZoomLevelChange
{
47 ZoomLevelChangeMode mode
;
53 typedef std::vector
<ZoomLevelChange
> ZoomLevelVector
;
55 CONTENT_EXPORT
static HostZoomMap
* GetDefaultForBrowserContext(
56 BrowserContext
* browser_context
);
58 // Returns the current zoom level for the specified WebContents. May be
59 // temporary or host-specific.
60 CONTENT_EXPORT
static double GetZoomLevel(const WebContents
* web_contents
);
62 // Sets the current zoom level for the specified WebContents. The level may
63 // be temporary or host-specific depending on the particular WebContents.
64 CONTENT_EXPORT
static void SetZoomLevel(const WebContents
* web_contents
,
67 // Copy the zoom levels from the given map. Can only be called on the UI
69 virtual void CopyFrom(HostZoomMap
* copy
) = 0;
71 // Here |host| is the host portion of URL, or (in the absence of a host)
72 // the complete spec of the URL.
73 // Returns the zoom for the specified |scheme| and |host|. See class
74 // description for details.
76 // This may be called on any thread.
77 virtual double GetZoomLevelForHostAndScheme(
78 const std::string
& scheme
,
79 const std::string
& host
) const = 0;
81 // Returns true if the specified |scheme| and/or |host| has a zoom level
84 // This may be called on any thread.
85 virtual bool HasZoomLevel(const std::string
& scheme
,
86 const std::string
& host
) const = 0;
88 // Returns all non-temporary zoom levels. Can be called on any thread.
89 virtual ZoomLevelVector
GetAllZoomLevels() const = 0;
91 // Here |host| is the host portion of URL, or (in the absence of a host)
92 // the complete spec of the URL.
93 // Sets the zoom level for the |host| to |level|. If the level matches the
94 // current default zoom level, the host is erased from the saved preferences;
95 // otherwise the new value is written out.
96 // Zoom levels specified for both scheme and host are not affected.
98 // This should only be called on the UI thread.
99 virtual void SetZoomLevelForHost(const std::string
& host
, double level
) = 0;
101 // Here |host| is the host portion of URL, or (in the absence of a host)
102 // the complete spec of the URL.
103 // Sets the zoom level for the |scheme|/|host| pair to |level|. No values
104 // will be erased during this operation, and this value will not be stored in
107 // This should only be called on the UI thread.
108 virtual void SetZoomLevelForHostAndScheme(const std::string
& scheme
,
109 const std::string
& host
,
112 // Returns whether the view manages its zoom level independently of other
113 // views displaying content from the same host.
114 virtual bool UsesTemporaryZoomLevel(int render_process_id
,
115 int render_view_id
) const = 0;
117 // Sets the temporary zoom level that's only valid for the lifetime of this
120 // This should only be called on the UI thread.
121 virtual void SetTemporaryZoomLevel(int render_process_id
,
125 // Clears the temporary zoom level stored for this WebContents.
127 // This should only be called on the UI thread.
128 virtual void ClearTemporaryZoomLevel(int render_process_id
,
129 int render_view_id
) = 0;
131 // Get/Set the default zoom level for pages that don't override it.
132 virtual double GetDefaultZoomLevel() const = 0;
133 virtual void SetDefaultZoomLevel(double level
) = 0;;
135 typedef base::Callback
<void(const ZoomLevelChange
&)> ZoomLevelChangedCallback
;
136 typedef base::CallbackList
<void(const ZoomLevelChange
&)>::Subscription
138 // Add and remove zoom level changed callbacks.
139 virtual scoped_ptr
<Subscription
> AddZoomLevelChangedCallback(
140 const ZoomLevelChangedCallback
& callback
) = 0;
143 virtual ~HostZoomMap() {}
146 } // namespace content
148 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_