File: key_system_support_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (109 lines) | stat: -rw-r--r-- 4,332 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_MEDIA_KEY_SYSTEM_SUPPORT_IMPL_H_
#define CONTENT_BROWSER_MEDIA_KEY_SYSTEM_SUPPORT_IMPL_H_

#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/callback_list.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/weak_ptr.h"
#include "content/browser/media/cdm_registry_impl.h"
#include "content/common/content_export.h"
#include "content/public/browser/document_user_data.h"
#include "content/public/browser/permission_controller.h"
#include "content/public/browser/render_frame_host.h"
#include "media/mojo/mojom/key_system_support.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/permissions/permission_status.mojom.h"
#include "third_party/blink/public/mojom/renderer_preference_watcher.mojom.h"

namespace content {

// A class living in the browser process per render frame handling all
// KeySystemSupport requests for that frame.
class CONTENT_EXPORT KeySystemSupportImpl final
    : public DocumentUserData<KeySystemSupportImpl>,
      public blink::mojom::RendererPreferenceWatcher,
      public media::mojom::KeySystemSupport {
 public:
  ~KeySystemSupportImpl() final;

  KeySystemSupportImpl(const KeySystemSupportImpl&) = delete;
  KeySystemSupportImpl& operator=(const KeySystemSupportImpl&) = delete;

  // `get_support_cb_for_testing` is used to get support update for testing.
  // If null, we'll use `CdmRegistryImpl` to get the update.
  using GetKeySystemCapabilitiesUpdateCB =
      base::RepeatingCallback<void(bool allow_hw_secure_capability_check,
                                   KeySystemCapabilitiesUpdateCB)>;
  void SetGetKeySystemCapabilitiesUpdateCbForTesting(
      GetKeySystemCapabilitiesUpdateCB get_support_cb_for_testing);

  // Binds the `receiver` to `this`.
  void Bind(mojo::PendingReceiver<media::mojom::KeySystemSupport> receiver);

  // media::mojom::KeySystemSupport implementation.
  void SetObserver(mojo::PendingRemote<media::mojom::KeySystemSupportObserver>
                       observer) final;

 private:
  friend class KeySystemSupportImplTest;
  friend class DocumentUserData<KeySystemSupportImpl>;

  explicit KeySystemSupportImpl(RenderFrameHost* rfh);
  DOCUMENT_USER_DATA_KEY_DECL();

  // Initializes permissions values `is_protected_content_allowed_` and
  // `is_protected_identifier_allowed_`.
  void InitializePermissions();

  // Sets up permission listeners for updates.
  void SetUpPermissionListeners();

  // Initializes `is_protected_identifier_allowed_` with `status`.
  void OnProtectedMediaIdentifierPermissionInitialized(
      blink::mojom::PermissionStatus status);

  // Updates `is_protected_identifier_allowed_` with `status`.
  void OnProtectedMediaIdentifierPermissionUpdated(
      blink::mojom::PermissionStatus status);

  // blink::mojom::RendererPreferenceWatcher.
  void NotifyUpdate(const blink::RendererPreferences& new_prefs) override;

  // Returns whether HW secure capability check is allow based on site settings.
  bool allow_hw_secure_capability_check() const;

  void ObserveKeySystemCapabilities();

  void OnKeySystemCapabilitiesUpdated(
      KeySystemCapabilities key_system_capabilities);

  GetKeySystemCapabilitiesUpdateCB get_support_cb_for_testing_;
  mojo::Receiver<KeySystemSupport> key_system_support_receiver_{this};
  mojo::Remote<media::mojom::KeySystemSupportObserver> observer_remote_;
  std::optional<KeySystemCapabilities> key_system_capabilities_;
  // Callback subscription to keep the callback alive in the CdmRegistry.
  base::CallbackListSubscription cb_subscription_;

  bool is_protected_content_allowed_ = false;
  bool is_protected_identifier_allowed_ = false;
  bool are_permissions_initialized_ = false;
  mojo::Receiver<blink::mojom::RendererPreferenceWatcher>
      preference_watcher_receiver_{this};
  PermissionController::SubscriptionId permission_subscription_id_;

  base::WeakPtrFactory<KeySystemSupportImpl> weak_ptr_factory_{this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_MEDIA_KEY_SYSTEM_SUPPORT_IMPL_H_