zoom_level_delegate.h 2.1 KB

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