Modernize CJK default font prefs on Mac/Windows/Linux
[chromium-blink-merge.git] / content / browser / host_zoom_map_impl.h
blobf9002872e7c624a5fec63241d63fe1900e19fcc0
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 // NotificationObserver implementation.
83 void Observe(int type,
84 const NotificationSource& source,
85 const NotificationDetails& details) override;
87 void SendErrorPageZoomLevelRefresh();
89 private:
90 typedef std::map<std::string, double> HostZoomLevels;
91 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels;
93 struct RenderViewKey {
94 int render_process_id;
95 int render_view_id;
96 RenderViewKey(int render_process_id, int render_view_id)
97 : render_process_id(render_process_id),
98 render_view_id(render_view_id) {}
99 bool operator<(const RenderViewKey& other) const {
100 return render_process_id < other.render_process_id ||
101 ((render_process_id == other.render_process_id) &&
102 (render_view_id < other.render_view_id));
106 typedef std::map<RenderViewKey, double> TemporaryZoomLevels;
108 double GetZoomLevelForHost(const std::string& host) const;
110 // Notifies the renderers from this browser context to change the zoom level
111 // for the specified host and scheme.
112 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
113 void SendZoomLevelChange(const std::string& scheme,
114 const std::string& host,
115 double level);
117 // Callbacks called when zoom level changes.
118 base::CallbackList<void(const ZoomLevelChange&)>
119 zoom_level_changed_callbacks_;
121 // Copy of the pref data, so that we can read it on the IO thread.
122 HostZoomLevels host_zoom_levels_;
123 SchemeHostZoomLevels scheme_host_zoom_levels_;
124 double default_zoom_level_;
126 // Don't expect more than a couple of tabs that are using a temporary zoom
127 // level, so vector is fine for now.
128 TemporaryZoomLevels temporary_zoom_levels_;
130 // Used around accesses to |host_zoom_levels_|, |default_zoom_level_| and
131 // |temporary_zoom_levels_| to guarantee thread safety.
132 mutable base::Lock lock_;
134 NotificationRegistrar registrar_;
136 DISALLOW_COPY_AND_ASSIGN(HostZoomMapImpl);
139 } // namespace content
141 #endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_