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 BRIGHTRAY_BROWSER_ZOOM_LEVEL_DELEGATE_H_
  5. #define BRIGHTRAY_BROWSER_ZOOM_LEVEL_DELEGATE_H_
  6. #include <string>
  7. #include "base/files/file_path.h"
  8. #include "base/macros.h"
  9. #include "components/prefs/pref_service.h"
  10. #include "content/public/browser/host_zoom_map.h"
  11. #include "content/public/browser/zoom_level_delegate.h"
  12. namespace base {
  13. class DictionaryValue;
  14. }
  15. class PrefRegistrySimple;
  16. namespace brightray {
  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. void SetDefaultZoomLevelPref(double level);
  30. double GetDefaultZoomLevelPref() const;
  31. // content::ZoomLevelDelegate:
  32. void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override;
  33. private:
  34. void ExtractPerHostZoomLevels(
  35. const base::DictionaryValue* host_zoom_dictionary);
  36. // This is a callback function that receives notifications from HostZoomMap
  37. // when per-host zoom levels change. It is used to update the per-host
  38. // zoom levels (if any) managed by this class (for its associated partition).
  39. void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change);
  40. PrefService* pref_service_;
  41. content::HostZoomMap* host_zoom_map_;
  42. std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
  43. std::string partition_key_;
  44. DISALLOW_COPY_AND_ASSIGN(ZoomLevelDelegate);
  45. };
  46. } // namespace brightray
  47. #endif // BRIGHTRAY_BROWSER_ZOOM_LEVEL_DELEGATE_H_