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 ATOM_BROWSER_ZOOM_LEVEL_DELEGATE_H_
  5. #define ATOM_BROWSER_ZOOM_LEVEL_DELEGATE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/files/file_path.h"
  9. #include "base/macros.h"
  10. #include "components/prefs/pref_service.h"
  11. #include "content/public/browser/host_zoom_map.h"
  12. #include "content/public/browser/zoom_level_delegate.h"
  13. namespace base {
  14. class DictionaryValue;
  15. }
  16. class PrefRegistrySimple;
  17. namespace atom {
  18. // A class to manage per-partition default and per-host zoom levels.
  19. // It implements an interface between the content/ zoom
  20. // levels in HostZoomMap and preference system. All changes
  21. // to the per-partition default zoom levels flow through this
  22. // class. Any changes to per-host levels are updated when HostZoomMap calls
  23. // OnZoomLevelChanged.
  24. class ZoomLevelDelegate : public content::ZoomLevelDelegate {
  25. public:
  26. static void RegisterPrefs(PrefRegistrySimple* pref_registry);
  27. ZoomLevelDelegate(PrefService* pref_service,
  28. const base::FilePath& partition_path);
  29. ~ZoomLevelDelegate() override;
  30. void SetDefaultZoomLevelPref(double level);
  31. double GetDefaultZoomLevelPref() const;
  32. // content::ZoomLevelDelegate:
  33. void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override;
  34. private:
  35. void ExtractPerHostZoomLevels(
  36. const base::DictionaryValue* 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_;
  43. std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
  44. std::string partition_key_;
  45. DISALLOW_COPY_AND_ASSIGN(ZoomLevelDelegate);
  46. };
  47. } // namespace atom
  48. #endif // ATOM_BROWSER_ZOOM_LEVEL_DELEGATE_H_