38
38
#include " third_party/blink/renderer/platform/wtf/text/case_folding_hash.h"
39
39
#include " third_party/blink/renderer/platform/wtf/text/string_hasher.h"
40
40
41
+ #include < optional>
42
+
41
43
namespace blink {
42
44
43
45
enum FontFaceCreationType {
@@ -49,19 +51,10 @@ class FontFaceCreationParams {
49
51
USING_FAST_MALLOC (FontFaceCreationParams);
50
52
51
53
public:
52
- FontFaceCreationParams ()
53
- : creation_type_(kCreateFontByFamily ),
54
- family_ (AtomicString()),
55
- filename_(std::string()),
56
- fontconfig_interface_id_(0 ),
57
- ttc_index_(0 ) {}
54
+ FontFaceCreationParams () : creation_type_(kCreateFontByFamily ) {}
58
55
59
56
explicit FontFaceCreationParams (AtomicString family)
60
- : creation_type_(kCreateFontByFamily ),
61
- family_(family),
62
- filename_(std::string()),
63
- fontconfig_interface_id_(0 ),
64
- ttc_index_(0 ) {
57
+ : creation_type_(kCreateFontByFamily ), family_(family) {
65
58
#if BUILDFLAG(IS_WIN)
66
59
// Leading "@" in the font name enables Windows vertical flow flag for the
67
60
// font. Because we do vertical flow by ourselves, we don't want to use the
@@ -88,8 +81,14 @@ class FontFaceCreationParams {
88
81
}
89
82
const std::string& Filename () const {
90
83
DCHECK_EQ (creation_type_, kCreateFontByFciIdAndTtcIndex );
84
+ #if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_QTWEBENGINE)
85
+ DCHECK (filename_.has_value ());
86
+ return *filename_;
87
+ #else
91
88
return filename_;
89
+ #endif
92
90
}
91
+
93
92
int FontconfigInterfaceId () const {
94
93
DCHECK_EQ (creation_type_, kCreateFontByFciIdAndTtcIndex );
95
94
return fontconfig_interface_id_;
@@ -106,8 +105,11 @@ class FontFaceCreationParams {
106
105
// encoding and endianness. However, since the hash is not transferred
107
106
// over a network or permanently stored and only used for the runtime of
108
107
// Chromium, this is not a concern.
109
- hasher.AddCharacters (reinterpret_cast <const LChar*>(filename_.data ()),
110
- static_cast <unsigned >(filename_.length ()));
108
+ if (HasFilename ()) {
109
+ const auto & filename = Filename ();
110
+ hasher.AddCharacters (reinterpret_cast <const LChar*>(filename.data ()),
111
+ static_cast <unsigned >(filename.length ()));
112
+ }
111
113
hasher.AddCharacters (reinterpret_cast <const LChar*>(&ttc_index_),
112
114
sizeof (ttc_index_));
113
115
hasher.AddCharacters (
@@ -121,17 +123,56 @@ class FontFaceCreationParams {
121
123
bool operator ==(const FontFaceCreationParams& other) const {
122
124
return creation_type_ == other.creation_type_ &&
123
125
DeprecatedEqualIgnoringCase (family_, other.family_ ) &&
124
- filename_ == other. filename_ &&
126
+ FilenameEqual ( other) &&
125
127
fontconfig_interface_id_ == other.fontconfig_interface_id_ &&
126
128
ttc_index_ == other.ttc_index_ ;
127
129
}
128
130
129
131
private:
130
132
FontFaceCreationType creation_type_;
131
133
AtomicString family_;
134
+
135
+ void SetFilename (std::string& filename) {
136
+ #if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_QTWEBENGINE)
137
+ *filename_ = filename;
138
+ #else
139
+ filename_ = filename;
140
+ #endif
141
+ }
142
+
143
+ bool FilenameEqual (const FontFaceCreationParams& other) const {
144
+ #if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_QTWEBENGINE)
145
+ if (!filename_.has_value () || !other.filename_ .has_value ()) {
146
+ return filename_.has_value () == other.filename_ .has_value ();
147
+ }
148
+ return *filename_ == *other.filename_ ;
149
+ #else
150
+ return filename_ == other.filename_ ;
151
+ #endif
152
+ }
153
+
154
+ bool HasFilename () const {
155
+ #if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_QTWEBENGINE)
156
+ return filename_.has_value ();
157
+ #else
158
+ return true ;
159
+ #endif
160
+ }
161
+
162
+ #if defined(ADDRESS_SANITIZER) || BUILDFLAG(IS_QTWEBENGINE)
163
+ // We put the `std::string` behind an optional as ASAN counter checks require
164
+ // that we properly call constructors and destructors for all strings. This is
165
+ // not the case when `FontFaceCreationParams` is used in `WTF::HashMap` as key
166
+ // where we also cosntruct empty and deleted values that are never properly
167
+ // destroyed.
168
+ //
169
+ // See crbug.com/346174906.
170
+ std::optional<std::string> filename_;
171
+ #else
132
172
std::string filename_;
133
- int fontconfig_interface_id_;
134
- int ttc_index_;
173
+ #endif
174
+ int fontconfig_interface_id_ = 0 ;
175
+ int ttc_index_ = 0 ;
135
176
};
136
177
137
178
} // namespace blink
0 commit comments