output_protection_delegate.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2013 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 ASH_DISPLAY_OUTPUT_PROTECTION_DELEGATE_H_
  5. #define ASH_DISPLAY_OUTPUT_PROTECTION_DELEGATE_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "ash/ash_export.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. #include "ui/aura/window.h"
  11. #include "ui/aura/window_observer.h"
  12. #include "ui/display/display_observer.h"
  13. #include "ui/display/types/display_constants.h"
  14. namespace ash {
  15. // Proxies output protection requests for an associated window, and renews them
  16. // when the window is reparented to another display.
  17. class ASH_EXPORT OutputProtectionDelegate : public aura::WindowObserver,
  18. public display::DisplayObserver {
  19. public:
  20. using QueryStatusCallback = base::OnceCallback<
  21. void(bool success, uint32_t connection_mask, uint32_t protection_mask)>;
  22. using SetProtectionCallback = base::OnceCallback<void(bool success)>;
  23. explicit OutputProtectionDelegate(aura::Window* window);
  24. OutputProtectionDelegate(const OutputProtectionDelegate&) = delete;
  25. OutputProtectionDelegate& operator=(const OutputProtectionDelegate&) = delete;
  26. ~OutputProtectionDelegate() override;
  27. void QueryStatus(QueryStatusCallback callback);
  28. void SetProtection(uint32_t protection_mask, SetProtectionCallback callback);
  29. private:
  30. // display::DisplayObserver:
  31. void OnDisplayMetricsChanged(const display::Display& display,
  32. uint32_t changed_metrics) override;
  33. // aura::WindowObserver:
  34. void OnWindowHierarchyChanged(
  35. const aura::WindowObserver::HierarchyChangeParams& params) override;
  36. void OnWindowDestroying(aura::Window* window) override;
  37. void OnWindowMayHaveMovedToAnotherDisplay();
  38. bool RegisterClientIfNecessary();
  39. // Native window being observed.
  40. aura::Window* window_ = nullptr;
  41. // Display ID of the observed window.
  42. int64_t display_id_;
  43. // Last requested ContentProtectionMethod bitmask, applied when the observed
  44. // window moves to another display.
  45. uint32_t protection_mask_ = display::CONTENT_PROTECTION_METHOD_NONE;
  46. // RAII wrapper to register/unregister ContentProtectionManager client.
  47. struct ClientIdHolder;
  48. std::unique_ptr<ClientIdHolder> client_;
  49. absl::optional<display::ScopedDisplayObserver> display_observer_{this};
  50. };
  51. } // namespace ash
  52. #endif // ASH_DISPLAY_OUTPUT_PROTECTION_DELEGATE_H_