zoom_level_delegate.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2014 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.
  4. #ifndef ELECTRON_SHELL_BROWSER_ZOOM_LEVEL_DELEGATE_H_
  5. #define ELECTRON_SHELL_BROWSER_ZOOM_LEVEL_DELEGATE_H_
  6. #include <string>
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/values.h"
  9. #include "content/public/browser/host_zoom_map.h"
  10. #include "content/public/browser/zoom_level_delegate.h"
  11. namespace base {
  12. class FilePath;
  13. } // namespace base
  14. class PrefService;
  15. class PrefRegistrySimple;
  16. namespace electron {
  17. // A class to manage per-partition default and per-host zoom levels.
  18. // It implements an interface between the content/ zoom
  19. // levels in HostZoomMap and preference system. All changes
  20. // to the per-partition default zoom levels flow through this
  21. // class. Any changes to per-host levels are updated when HostZoomMap calls
  22. // OnZoomLevelChanged.
  23. class ZoomLevelDelegate : public content::ZoomLevelDelegate {
  24. public:
  25. static void RegisterPrefs(PrefRegistrySimple* pref_registry);
  26. ZoomLevelDelegate(PrefService* pref_service,
  27. const base::FilePath& partition_path);
  28. ~ZoomLevelDelegate() override;
  29. // disable copy
  30. ZoomLevelDelegate(const ZoomLevelDelegate&) = delete;
  31. ZoomLevelDelegate& operator=(const ZoomLevelDelegate&) = delete;
  32. void SetDefaultZoomLevelPref(double level);
  33. double GetDefaultZoomLevelPref() const;
  34. // content::ZoomLevelDelegate:
  35. void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override;
  36. private:
  37. void ExtractPerHostZoomLevels(const base::Value::Dict& host_zoom_dictionary);
  38. // This is a callback function that receives notifications from HostZoomMap
  39. // when per-host zoom levels change. It is used to update the per-host
  40. // zoom levels (if any) managed by this class (for its associated partition).
  41. void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
  42. raw_ptr<PrefService> pref_service_;
  43. raw_ptr<content::HostZoomMap> host_zoom_map_ = nullptr;
  44. base::CallbackListSubscription zoom_subscription_;
  45. std::string partition_key_;
  46. };
  47. } // namespace electron
  48. #endif // ELECTRON_SHELL_BROWSER_ZOOM_LEVEL_DELEGATE_H_