source: webkit/trunk/Source/WebCore/css/CSSFontSelector.h

Last change on this file was 287066, checked in by [email protected], 3 years ago

ActiveDOMObject::suspendIfNeeded() should not be called within constructors
https://bugs.webkit.org/show_bug.cgi?id=233945

Reviewed by Chris Dumez and Darin Adler.

  • Modules/applepay/ApplePaySession.cpp:

(WebCore::ApplePaySession::create):

  • Modules/applepay/ApplePaySetup.cpp:

(WebCore::ApplePaySetup::create):
(WebCore::ApplePaySetup::ApplePaySetup):

  • Modules/applepay/ApplePaySetupWebCore.h:

(WebCore::ApplePaySetup::create): Deleted.

  • Modules/cache/DOMCache.cpp:

(WebCore::DOMCache::create):
(WebCore::DOMCache::DOMCache):

  • Modules/cache/DOMCache.h:
  • Modules/cache/DOMCacheStorage.cpp:

(WebCore::DOMCacheStorage::create):
(WebCore::DOMCacheStorage::DOMCacheStorage):

  • Modules/cache/DOMCacheStorage.h:

(WebCore::DOMCacheStorage::create): Deleted.

  • Modules/entriesapi/FileSystemDirectoryReader.cpp:

(WebCore::FileSystemDirectoryReader::create):
(WebCore::FileSystemDirectoryReader::FileSystemDirectoryReader):

  • Modules/entriesapi/FileSystemDirectoryReader.h:
  • Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:

(WebCore::FileSystemSyncAccessHandle::create):
(WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):

  • Modules/geolocation/Geolocation.cpp:

(WebCore::Geolocation::create):

  • Modules/mediastream/MediaStream.cpp:

(WebCore::MediaStream::create):
(WebCore::MediaStream::MediaStream):

  • Modules/paymentrequest/PaymentRequest.cpp:

(WebCore::PaymentRequest::create):

  • Modules/remoteplayback/RemotePlayback.cpp:

(WebCore::RemotePlayback::create):
(WebCore::RemotePlayback::RemotePlayback):

  • Modules/webaudio/ScriptProcessorNode.cpp:

(WebCore::ScriptProcessorNode::create):
(WebCore::ScriptProcessorNode::ScriptProcessorNode):

  • Modules/webxr/WebXRSession.cpp:

(WebCore::WebXRSession::create):
(WebCore::WebXRSession::WebXRSession):

  • Modules/webxr/WebXRSystem.cpp:

(WebCore::WebXRSystem::create):
(WebCore::WebXRSystem::WebXRSystem):

  • css/CSSFontSelector.cpp:

(WebCore::CSSFontSelector::create):
(WebCore::m_version):

  • css/CSSFontSelector.h:
  • dom/MessagePort.cpp:

(WebCore::MessagePort::create):
(WebCore::MessagePort::MessagePort):

  • workers/WorkerAnimationController.cpp:

(WebCore::WorkerAnimationController::create):
(WebCore::WorkerAnimationController::WorkerAnimationController):

  • workers/service/ServiceWorker.cpp:

(WebCore::ServiceWorker::getOrCreate):
(WebCore::ServiceWorker::ServiceWorker):

  • workers/service/ServiceWorkerRegistration.cpp:

(WebCore::ServiceWorkerRegistration::getOrCreate):
(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):

  • Property svn:eol-style set to native
File size: 5.6 KB
Line 
1/*
2 * Copyright (C) 2007-2021 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "ActiveDOMObject.h"
29#include "CSSFontFace.h"
30#include "CSSFontFaceSet.h"
31#include "CachedResourceHandle.h"
32#include "Font.h"
33#include "FontSelector.h"
34#include "Timer.h"
35#include "WebKitFontFamilyNames.h"
36#include <memory>
37#include <wtf/Forward.h>
38#include <wtf/HashSet.h>
39#include <wtf/RefPtr.h>
40#include <wtf/text/StringHash.h>
41
42namespace WebCore {
43
44class CSSFontFaceRule;
45class CSSPrimitiveValue;
46class CSSSegmentedFontFace;
47class CSSValueList;
48class CachedFont;
49class ScriptExecutionContext;
50class StyleRuleFontFace;
51
52class CSSFontSelector final : public FontSelector, public CSSFontFace::Client, public CanMakeWeakPtr<CSSFontSelector>, public ActiveDOMObject {
53public:
54 static Ref<CSSFontSelector> create(ScriptExecutionContext&);
55 virtual ~CSSFontSelector();
56
57 unsigned version() const final { return m_version; }
58 unsigned uniqueId() const final { return m_uniqueId; }
59
60 FontRanges fontRangesForFamily(const FontDescription&, const AtomString&) final;
61 size_t fallbackFontCount() final;
62 RefPtr<Font> fallbackFontAt(const FontDescription&, size_t) final;
63
64 void clearFonts();
65 void emptyCaches();
66 void buildStarted();
67 void buildCompleted();
68
69 void addFontFaceRule(StyleRuleFontFace&, bool isInitiatingElementInUserAgentShadowTree);
70 void addFontPaletteValuesRule(StyleRuleFontPaletteValues&);
71
72 void fontCacheInvalidated() final;
73
74 bool isEmpty() const;
75
76 void registerForInvalidationCallbacks(FontSelectorClient&) final;
77 void unregisterForInvalidationCallbacks(FontSelectorClient&) final;
78
79 ScriptExecutionContext* scriptExecutionContext() const { return m_context.get(); }
80
81 FontFaceSet* fontFaceSetIfExists();
82 FontFaceSet& fontFaceSet();
83
84 void incrementIsComputingRootStyleFont() { ++m_computingRootStyleFontCount; }
85 void decrementIsComputingRootStyleFont() { --m_computingRootStyleFontCount; }
86
87 void loadPendingFonts();
88
89 void updateStyleIfNeeded();
90
91 // CSSFontFace::Client needs to be able to be held in a RefPtr.
92 void ref() final { FontSelector::ref(); }
93 void deref() final { FontSelector::deref(); }
94
95private:
96 explicit CSSFontSelector(ScriptExecutionContext&);
97
98 void dispatchInvalidationCallbacks();
99
100 void opportunisticallyStartFontDataURLLoading(const FontCascadeDescription&, const AtomString& family) final;
101
102 std::optional<AtomString> resolveGenericFamily(const FontDescription&, const AtomString& family);
103
104 const FontPaletteValues& lookupFontPaletteValues(const AtomString& familyName, const FontDescription&);
105
106 // CSSFontFace::Client
107 void fontLoaded(CSSFontFace&) final;
108 void updateStyleIfNeeded(CSSFontFace&) final;
109
110 void fontModified();
111
112 // ActiveDOMObject
113 const char* activeDOMObjectName() const final { return "CSSFontSelector"_s; }
114
115 struct PendingFontFaceRule {
116 StyleRuleFontFace& styleRuleFontFace;
117 bool isInitiatingElementInUserAgentShadowTree;
118 };
119 Vector<PendingFontFaceRule> m_stagingArea;
120
121 WeakPtr<ScriptExecutionContext> m_context;
122 RefPtr<FontFaceSet> m_fontFaceSet;
123 Ref<CSSFontFaceSet> m_cssFontFaceSet;
124 HashSet<FontSelectorClient*> m_clients;
125
126 struct PaletteMapHash : DefaultHash<std::pair<AtomString, AtomString>> {
127 static unsigned hash(const std::pair<AtomString, AtomString>& key)
128 {
129 return pairIntHash(ASCIICaseInsensitiveHash::hash(key.first), DefaultHash<AtomString>::hash(key.second));
130 }
131
132 static bool equal(const std::pair<AtomString, AtomString>& a, const std::pair<AtomString, AtomString>& b)
133 {
134 return ASCIICaseInsensitiveHash::equal(a.first, b.first) && DefaultHash<AtomString>::equal(a.second, b.second);
135 }
136 };
137 HashMap<std::pair<AtomString, AtomString>, FontPaletteValues, PaletteMapHash> m_paletteMap;
138
139 HashSet<RefPtr<CSSFontFace>> m_cssConnectionsPossiblyToRemove;
140 HashSet<RefPtr<StyleRuleFontFace>> m_cssConnectionsEncounteredDuringBuild;
141
142 CSSFontFaceSet::FontModifiedObserver m_fontModifiedObserver;
143
144 unsigned m_uniqueId;
145 unsigned m_version;
146 unsigned m_computingRootStyleFontCount { 0 };
147 bool m_creatingFont { false };
148 bool m_buildIsUnderway { false };
149 bool m_isStopped { false };
150
151 WebKitFontFamilyNames::FamilyNamesList<AtomString> m_fontFamilyNames;
152};
153
154} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.