blob: 543ab3a53a5aeb44613c2c1a9f91a53ba961bc95 [file] [log] [blame]
[email protected]3bbacc5b2012-04-17 17:46:151// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5c9250872012-01-30 17:24:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
6#define CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_
[email protected]5c9250872012-01-30 17:24:057
8#include <map>
9#include <string>
jsbell71dafdfe2015-11-20 19:40:3810#include <tuple>
[email protected]5c9250872012-01-30 17:24:0511#include <vector>
12
Keishi Hattori0e45c022021-11-27 09:25:5213#include "base/memory/raw_ptr.h"
Patrick Monette643cdf62021-10-15 19:13:4214#include "base/task/sequenced_task_runner_helpers.h"
Gabriel Charetted87f10f2022-03-31 00:44:2215#include "base/time/time.h"
Lei Zhang7ab313752021-11-17 01:26:0016#include "content/common/content_export.h"
[email protected]5c9250872012-01-30 17:24:0517#include "content/public/browser/host_zoom_map.h"
[email protected]5c9250872012-01-30 17:24:0518
[email protected]46488322012-10-30 03:22:2019namespace content {
20
[email protected]fce823222014-05-30 16:24:3021class WebContentsImpl;
22
Lei Zhang9d40e7902017-11-20 19:54:3623// HostZoomMap lives on the UI thread.
Sam McNallye741fd662017-08-30 02:07:5024class CONTENT_EXPORT HostZoomMapImpl : public HostZoomMap {
[email protected]5c9250872012-01-30 17:24:0525 public:
26 HostZoomMapImpl();
Peter Boström828b9022021-09-21 02:28:4327
28 HostZoomMapImpl(const HostZoomMapImpl&) = delete;
29 HostZoomMapImpl& operator=(const HostZoomMapImpl&) = delete;
30
dchengc2282aa2014-10-21 12:07:5831 ~HostZoomMapImpl() override;
[email protected]5c9250872012-01-30 17:24:0532
33 // HostZoomMap implementation:
dchengc2282aa2014-10-21 12:07:5834 void CopyFrom(HostZoomMap* copy) override;
35 double GetZoomLevelForHostAndScheme(const std::string& scheme,
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0436 const std::string& host) override;
[email protected]d42bf472014-06-14 01:49:3837 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
dchengc2282aa2014-10-21 12:07:5838 bool HasZoomLevel(const std::string& scheme,
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0439 const std::string& host) override;
40 ZoomLevelVector GetAllZoomLevels() override;
dchengc2282aa2014-10-21 12:07:5841 void SetZoomLevelForHost(const std::string& host, double level) override;
Christian Dullwebercc736c12017-09-04 09:27:5042 void InitializeZoomLevelForHost(const std::string& host,
43 double level,
44 base::Time last_modified) override;
dchengc2282aa2014-10-21 12:07:5845 void SetZoomLevelForHostAndScheme(const std::string& scheme,
46 const std::string& host,
47 double level) override;
48 bool UsesTemporaryZoomLevel(int render_process_id,
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0449 int render_view_id) override;
dchengc2282aa2014-10-21 12:07:5850 void SetTemporaryZoomLevel(int render_process_id,
51 int render_view_id,
52 double level) override;
Christian Dullwebercc736c12017-09-04 09:27:5053 void ClearZoomLevels(base::Time delete_begin, base::Time delete_end) override;
dchengc2282aa2014-10-21 12:07:5854 void ClearTemporaryZoomLevel(int render_process_id,
55 int render_view_id) override;
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0456 double GetDefaultZoomLevel() override;
dchengc2282aa2014-10-21 12:07:5857 void SetDefaultZoomLevel(double level) override;
Peter Kasting7ba9440c2020-11-22 01:49:0258 base::CallbackListSubscription AddZoomLevelChangedCallback(
danakj6aa13ea2019-12-10 14:53:2659 ZoomLevelChangedCallback callback) override;
[email protected]5c9250872012-01-30 17:24:0560
[email protected]fce823222014-05-30 16:24:3061 // Returns the current zoom level for the specified WebContents. This may
62 // be a temporary zoom level, depending on UsesTemporaryZoomLevel().
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0463 double GetZoomLevelForWebContents(WebContentsImpl* web_contents_impl);
[email protected]fce823222014-05-30 16:24:3064
65 // Sets the zoom level for this WebContents. If this WebContents is using
66 // a temporary zoom level, then level is only applied to this WebContents.
67 // Otherwise, the level will be applied on a host level.
Lucas Furukawa Gadanie1c5dfda2018-11-29 17:57:4168 void SetZoomLevelForWebContents(WebContentsImpl* web_contents_impl,
[email protected]fce823222014-05-30 16:24:3069 double level);
70
[email protected]5c9250872012-01-30 17:24:0571 // Returns the temporary zoom level that's only valid for the lifetime of
[email protected]3bbacc5b2012-04-17 17:46:1572 // the given WebContents (i.e. isn't saved and doesn't affect other
73 // WebContentses) if it exists, the default zoom level otherwise.
[email protected]5c9250872012-01-30 17:24:0574 double GetTemporaryZoomLevel(int render_process_id,
75 int render_view_id) const;
76
wjmacleande29ed52014-10-28 21:09:0677 void SendErrorPageZoomLevelRefresh();
78
Sam McNallye741fd662017-08-30 02:07:5079 void WillCloseRenderView(int render_process_id, int render_view_id);
80
tzik67025f672017-11-29 05:04:4481 void SetClockForTesting(base::Clock* clock) override;
Christian Dullwebercc736c12017-09-04 09:27:5082
[email protected]5c9250872012-01-30 17:24:0583 private:
Christian Dullwebercc736c12017-09-04 09:27:5084 struct ZoomLevel {
85 double level;
86 base::Time last_modified;
87 };
88 typedef std::map<std::string, ZoomLevel> HostZoomLevels;
[email protected]367c5c1d2013-03-11 18:59:0289 typedef std::map<std::string, HostZoomLevels> SchemeHostZoomLevels;
[email protected]5c9250872012-01-30 17:24:0590
[email protected]d42bf472014-06-14 01:49:3891 struct RenderViewKey {
[email protected]fce823222014-05-30 16:24:3092 int render_process_id;
93 int render_view_id;
[email protected]d42bf472014-06-14 01:49:3894 RenderViewKey(int render_process_id, int render_view_id)
95 : render_process_id(render_process_id),
96 render_view_id(render_view_id) {}
97 bool operator<(const RenderViewKey& other) const {
jsbell71dafdfe2015-11-20 19:40:3898 return std::tie(render_process_id, render_view_id) <
99 std::tie(other.render_process_id, other.render_view_id);
[email protected]d42bf472014-06-14 01:49:38100 }
[email protected]fce823222014-05-30 16:24:30101 };
102
[email protected]d42bf472014-06-14 01:49:38103 typedef std::map<RenderViewKey, double> TemporaryZoomLevels;
[email protected]fce823222014-05-30 16:24:30104
105 double GetZoomLevelForHost(const std::string& host) const;
106
Christian Dullwebercc736c12017-09-04 09:27:50107 // Set a zoom level for |host| and store the |last_modified| timestamp.
108 // Use only to explicitly set a timestamp.
109 void SetZoomLevelForHostInternal(const std::string& host,
110 double level,
111 base::Time last_modified);
112
[email protected]d42bf472014-06-14 01:49:38113 // Notifies the renderers from this browser context to change the zoom level
114 // for the specified host and scheme.
akaba3483d8f2018-07-10 21:43:09115 // |zoom level| will be extracted from |host_zoom_levels_| when needed, so no
116 // need to pass them in.
[email protected]d42bf472014-06-14 01:49:38117 // TODO(wjmaclean) Should we use a GURL here? crbug.com/384486
akabac6bd1212018-06-25 20:10:48118 void SendZoomLevelChange(const std::string& scheme, const std::string& host);
[email protected]d42bf472014-06-14 01:49:38119
[email protected]89c9aca2013-02-07 15:08:42120 // Callbacks called when zoom level changes.
Fabrice de Gans-Riberid82d1222021-03-22 22:23:11121 base::RepeatingCallbackList<void(const ZoomLevelChange&)>
[email protected]117832812013-10-02 07:06:02122 zoom_level_changed_callbacks_;
[email protected]89c9aca2013-02-07 15:08:42123
Lei Zhang9d40e7902017-11-20 19:54:36124 // Copy of the pref data.
[email protected]5c9250872012-01-30 17:24:05125 HostZoomLevels host_zoom_levels_;
[email protected]367c5c1d2013-03-11 18:59:02126 SchemeHostZoomLevels scheme_host_zoom_levels_;
[email protected]5c9250872012-01-30 17:24:05127 double default_zoom_level_;
128
[email protected]fce823222014-05-30 16:24:30129 TemporaryZoomLevels temporary_zoom_levels_;
[email protected]5c9250872012-01-30 17:24:05130
Keishi Hattori0e45c022021-11-27 09:25:52131 raw_ptr<base::Clock> clock_;
[email protected]5c9250872012-01-30 17:24:05132};
133
[email protected]46488322012-10-30 03:22:20134} // namespace content
135
[email protected]5c9250872012-01-30 17:24:05136#endif // CONTENT_BROWSER_HOST_ZOOM_MAP_IMPL_H_