zoom_level_delegate.h 2.1 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 "components/prefs/pref_service.h"
  8. #include "content/public/browser/host_zoom_map.h"
  9. #include "content/public/browser/zoom_level_delegate.h"
  10. namespace base {
  11. class DictionaryValue;
  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(
  37. const base::DictionaryValue* 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. PrefService* pref_service_;
  43. 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_