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