File: font_access_manager.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 (108 lines) | stat: -rw-r--r-- 3,503 bytes parent folder | download | duplicates (8)
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
// Copyright 2020 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_FONT_ACCESS_FONT_ACCESS_MANAGER_H_
#define CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_MANAGER_H_

#include <map>
#include <memory>
#include <vector>

#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "base/thread_annotations.h"
#include "base/threading/sequence_bound.h"
#include "base/types/pass_key.h"
#include "content/common/content_export.h"
#include "content/public/browser/global_routing_id.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "third_party/blink/public/mojom/font_access/font_access.mojom.h"

namespace content {

class FontEnumerationCache;

// The ownership hierarchy for this class is:
//
// StoragePartitionImpl (1) <- (1) FontAccessManager
//
// FontAccessManager (1) <- (*) BindingContext
//
// BindingContext (1) <- (1) GlobalRenderFrameHostId
//
// Legend:
//
// <- : owns
// <-- : corresponds to
// (N) : N is a number or *, which denotes zero or more
//
// In English:
// * There's one FontAccessManager per StoragePartitionImpl
// * Frames are bound to FontAccessManager via a BindingContext.
class CONTENT_EXPORT FontAccessManager
    : public blink::mojom::FontAccessManager {
 public:
  // Factory method for production instances.
  static std::unique_ptr<FontAccessManager> Create();

  // Factory method with dependency injection support for testing.
  static std::unique_ptr<FontAccessManager> CreateForTesting(
      base::SequenceBound<FontEnumerationCache> font_enumeration_cache);

  // The constructor is public for internal use of std::make_unique.
  //
  // Production code should call FontAccessManager::Create(). Testing code
  // should call FontAccessManager::CreateForTesting().
  FontAccessManager(
      base::SequenceBound<FontEnumerationCache> font_enumeration_cache,
      base::PassKey<FontAccessManager>);

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

  ~FontAccessManager() override;

  void BindReceiver(
      GlobalRenderFrameHostId frame_id,
      mojo::PendingReceiver<blink::mojom::FontAccessManager> receiver);

  // blink::mojom::FontAccessManager:
  void EnumerateLocalFonts(EnumerateLocalFontsCallback callback) override;

  void SkipPrivacyChecksForTesting(bool skip) {
    DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
    skip_privacy_checks_for_testing_ = skip;
  }

 private:
  struct BindingContext {
    GlobalRenderFrameHostId frame_id;
  };

  void DidRequestPermission(EnumerateLocalFontsCallback callback,
                            blink::mojom::PermissionStatus status);

  SEQUENCE_CHECKER(sequence_checker_);

  base::SequenceBound<FontEnumerationCache> font_enumeration_cache_
      GUARDED_BY_CONTEXT(sequence_checker_);

  // Registered clients.
  mojo::ReceiverSet<blink::mojom::FontAccessManager, BindingContext> receivers_
      GUARDED_BY_CONTEXT(sequence_checker_);

  const scoped_refptr<base::TaskRunner> results_task_runner_;

  bool skip_privacy_checks_for_testing_ GUARDED_BY_CONTEXT(sequence_checker_) =
      false;

  base::WeakPtrFactory<FontAccessManager> weak_ptr_factory_
      GUARDED_BY_CONTEXT(sequence_checker_){this};
};

}  // namespace content

#endif  // CONTENT_BROWSER_FONT_ACCESS_FONT_ACCESS_MANAGER_H_