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 "content/common/content_export.h"
19 class ResourceContext
;
21 // Maps hostnames to custom zoom levels. Written on the UI thread and read on
22 // any thread. One instance per browser context. Must be created on the UI
23 // thread, and it'll delete itself on the UI thread as well.
24 // Zoom can be defined at three levels: default zoom, zoom for host, and zoom
25 // for host with specific scheme. Setting any of the levels leaves settings
26 // for other settings intact. Getting the zoom level starts at the most
27 // specific setting and progresses to the less specific: first the zoom for the
28 // host and scheme pair is checked, secondly the zoom for the host only and
29 // lastly default zoom.
33 // Enum that indicates what was the scope of zoom level change.
34 enum ZoomLevelChangeMode
{
35 ZOOM_CHANGED_FOR_HOST
, // Zoom level changed for host.
36 ZOOM_CHANGED_FOR_SCHEME_AND_HOST
, // Zoom level changed for scheme/host
38 ZOOM_CHANGED_TEMPORARY_ZOOM
, // Temporary zoom change for specific
39 // renderer, no scheme/host is specified.
42 // Structure used to notify about zoom changes. Host and/or scheme are empty
43 // if not applicable to |mode|.
44 struct ZoomLevelChange
{
45 ZoomLevelChangeMode mode
;
51 CONTENT_EXPORT
static HostZoomMap
* GetForBrowserContext(
52 BrowserContext
* browser_context
);
54 // Copy the zoom levels from the given map. Can only be called on the UI
56 virtual void CopyFrom(HostZoomMap
* copy
) = 0;
58 // Here |host| is the host portion of URL, or (in the absence of a host)
59 // the complete spec of the URL.
60 // Returns the zoom for the specified |scheme| and |host|. See class
61 // description for details.
63 // This may be called on any thread.
64 virtual double GetZoomLevelForHostAndScheme(
65 const std::string
& scheme
,
66 const std::string
& host
) const = 0;
68 // Here |host| is the host portion of URL, or (in the absence of a host)
69 // the complete spec of the URL.
70 // Sets the zoom level for the |host| to |level|. If the level matches the
71 // current default zoom level, the host is erased from the saved preferences;
72 // otherwise the new value is written out.
73 // Zoom levels specified for both scheme and host are not affected.
75 // This should only be called on the UI thread.
76 virtual void SetZoomLevelForHost(const std::string
& host
, double level
) = 0;
78 // Here |host| is the host portion of URL, or (in the absence of a host)
79 // the complete spec of the URL.
80 // Sets the zoom level for the |scheme|/|host| pair to |level|. No values
81 // will be erased during this operation, and this value will not be stored in
84 // This should only be called on the UI thread.
85 virtual void SetZoomLevelForHostAndScheme(const std::string
& scheme
,
86 const std::string
& host
,
89 // Get/Set the default zoom level for pages that don't override it.
90 virtual double GetDefaultZoomLevel() const = 0;
91 virtual void SetDefaultZoomLevel(double level
) = 0;;
93 typedef base::Callback
<void(const ZoomLevelChange
&)> ZoomLevelChangedCallback
;
95 // Add and remove zoom level changed callbacks.
96 virtual void AddZoomLevelChangedCallback(
97 const ZoomLevelChangedCallback
& callback
) = 0;
98 virtual void RemoveZoomLevelChangedCallback(
99 const ZoomLevelChangedCallback
& callback
) = 0;
102 virtual ~HostZoomMap() {}
105 } // namespace content
107 #endif // CONTENT_PUBLIC_BROWSER_HOST_ZOOM_MAP_H_