Diff
Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.cpp (295184 => 295185)
--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.cpp 2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.cpp 2022-06-03 06:45:32 UTC (rev 295185)
@@ -216,7 +216,6 @@
: ActiveDOMObject(document)
, m_startTime(start)
, m_endTime(end)
- , m_document(document)
, m_cueNode(WTFMove(cueFragment))
{
}
@@ -225,15 +224,19 @@
: ActiveDOMObject(document)
, m_startTime(start)
, m_endTime(end)
- , m_document(document)
{
}
ScriptExecutionContext* TextTrackCue::scriptExecutionContext() const
{
- return &m_document;
+ return ActiveDOMObject::scriptExecutionContext();
}
+Document* TextTrackCue::document() const
+{
+ return downcast<Document>(scriptExecutionContext());
+}
+
void TextTrackCue::willChange()
{
if (++m_processingCueChanges > 1)
@@ -436,7 +439,11 @@
if (!m_cueNode)
return nullptr;
- auto clonedFragment = DocumentFragment::create(ownerDocument());
+ auto* document = this->document();
+ if (!document)
+ return nullptr;
+
+ auto clonedFragment = DocumentFragment::create(*document);
m_cueNode->cloneChildNodes(clonedFragment);
for (Node* node = clonedFragment->firstChild(); node; node = node->nextSibling())
@@ -485,21 +492,25 @@
if (!m_cueNode)
return;
+ RefPtr document = this->document();
+ if (!document)
+ return;
+
ScriptDisallowedScope::EventAllowedScope allowedScopeForReferenceTree(*m_cueNode);
if (!m_displayTree) {
- m_displayTree = TextTrackCueBox::create(ownerDocument(), *this);
+ m_displayTree = TextTrackCueBox::create(*document, *this);
m_displayTree->setPseudo(ShadowPseudoIds::webkitGenericCueRoot());
}
m_displayTree->removeChildren();
- auto clonedFragment = DocumentFragment::create(ownerDocument());
+ auto clonedFragment = DocumentFragment::create(*document);
m_cueNode->cloneChildNodes(clonedFragment);
m_displayTree->appendChild(clonedFragment);
if (m_fontSize) {
- if (auto page = ownerDocument().page()) {
- auto style = HTMLStyleElement::create(HTMLNames::styleTag, ownerDocument(), false);
+ if (auto page = document->page()) {
+ auto style = HTMLStyleElement::create(HTMLNames::styleTag, *document, false);
style->setTextContent(makeString(page->captionUserPreferencesStyleSheet(),
" ::", ShadowPseudoIds::cue(), "{font-size:", m_fontSize, m_fontSizeIsImportant ? "px !important}" : "px}"));
m_displayTree->appendChild(style);
Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.h (295184 => 295185)
--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.h 2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCue.h 2022-06-03 06:45:32 UTC (rev 295185)
@@ -126,7 +126,7 @@
protected:
TextTrackCue(Document&, const MediaTime& start, const MediaTime& end);
- Document& ownerDocument() { return m_document; }
+ Document* document() const;
virtual bool cueContentsMatch(const TextTrackCue&) const;
virtual void toJSON(JSON::Object&) const;
@@ -154,8 +154,6 @@
TextTrack* m_track { nullptr };
- Document& m_document;
-
RefPtr<DocumentFragment> m_cueNode;
RefPtr<TextTrackCueBox> m_displayTree;
Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.cpp (295184 => 295185)
--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.cpp 2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.cpp 2022-06-03 06:45:32 UTC (rev 295185)
@@ -171,9 +171,11 @@
{
}
-Ref<VTTCueBox> TextTrackCueGeneric::createDisplayTree()
+RefPtr<VTTCueBox> TextTrackCueGeneric::createDisplayTree()
{
- return TextTrackCueGenericBoxElement::create(ownerDocument(), *this);
+ if (auto* document = this->document())
+ return TextTrackCueGenericBoxElement::create(*document, *this);
+ return nullptr;
}
ExceptionOr<void> TextTrackCueGeneric::setLine(const LineAndPositionSetting& line)
@@ -205,7 +207,8 @@
double size = videoSize.height() * baseFontSizeRelativeToVideoHeight() / 100;
if (fontSizeMultiplier())
size *= fontSizeMultiplier() / 100;
- displayTreeInternal().setInlineStyleProperty(CSSPropertyFontSize, lround(size), CSSUnitType::CSS_PX);
+ if (auto* displayTree = displayTreeInternal())
+ displayTree->setInlineStyleProperty(CSSPropertyFontSize, lround(size), CSSUnitType::CSS_PX);
}
bool TextTrackCueGeneric::cueContentsMatch(const TextTrackCue& otherTextTrackCue) const
Modified: branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.h (295184 => 295185)
--- branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.h 2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/TextTrackCueGeneric.h 2022-06-03 06:45:32 UTC (rev 295185)
@@ -69,7 +69,7 @@
bool isOrderedBefore(const TextTrackCue*) const final;
bool isPositionedAbove(const TextTrackCue*) const final;
- Ref<VTTCueBox> createDisplayTree() final;
+ RefPtr<VTTCueBox> createDisplayTree() final;
bool cueContentsMatch(const TextTrackCue&) const final;
Modified: branches/safari-613-branch/Source/WebCore/html/track/VTTCue.cpp (295184 => 295185)
--- branches/safari-613-branch/Source/WebCore/html/track/VTTCue.cpp 2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/VTTCue.cpp 2022-06-03 06:45:32 UTC (rev 295185)
@@ -271,7 +271,7 @@
, m_content(WTFMove(content))
, m_originalStartTime(MediaTime::zeroTime())
{
- initialize();
+ initialize(document);
}
VTTCue::VTTCue(Document& document, const WebVTTCueData& cueData)
@@ -278,7 +278,7 @@
: TextTrackCue(document, MediaTime::zeroTime(), MediaTime::zeroTime())
, m_originalStartTime(cueData.originalStartTime())
{
- initialize();
+ initialize(document);
setText(cueData.content());
setStartTime(cueData.startTime());
setEndTime(cueData.endTime());
@@ -290,25 +290,27 @@
{
}
-void VTTCue::initialize()
+void VTTCue::initialize(Document& document)
{
- m_cueBackdropBox = HTMLDivElement::create(ownerDocument());
- m_cueHighlightBox = HTMLSpanElement::create(spanTag, ownerDocument());
+ m_cueBackdropBox = HTMLDivElement::create(document);
+ m_cueHighlightBox = HTMLSpanElement::create(spanTag, document);
m_snapToLines = true;
m_displayTreeShouldChange = true;
m_notifyRegion = true;
}
-Ref<VTTCueBox> VTTCue::createDisplayTree()
+RefPtr<VTTCueBox> VTTCue::createDisplayTree()
{
- return VTTCueBox::create(ownerDocument(), *this);
+ if (auto* document = this->document())
+ return VTTCueBox::create(*document, *this);
+ return nullptr;
}
-VTTCueBox& VTTCue::displayTreeInternal()
+VTTCueBox* VTTCue::displayTreeInternal()
{
if (!m_displayTree)
m_displayTree = createDisplayTree();
- return *m_displayTree;
+ return m_displayTree.get();
}
void VTTCue::didChange()
@@ -593,8 +595,8 @@
void VTTCue::createWebVTTNodeTree()
{
- if (!m_webVTTNodeTree)
- m_webVTTNodeTree = WebVTTParser::createDocumentFragmentFromCueText(ownerDocument(), m_content);
+ if (!m_webVTTNodeTree && document())
+ m_webVTTNodeTree = WebVTTParser::createDocumentFragmentFromCueText(*document(), m_content);
}
static void copyWebVTTNodeToDOMTree(ContainerNode& webVTTNode, Node& parent)
@@ -617,7 +619,11 @@
if (!m_webVTTNodeTree)
return nullptr;
- auto clonedFragment = DocumentFragment::create(ownerDocument());
+ auto* document = this->document();
+ if (!document)
+ return nullptr;
+
+ auto clonedFragment = DocumentFragment::create(*document);
copyWebVTTNodeToDOMTree(*m_webVTTNodeTree, clonedFragment);
return clonedFragment;
}
@@ -628,8 +634,12 @@
if (!m_webVTTNodeTree)
return nullptr;
- auto clonedFragment = DocumentFragment::create(ownerDocument());
+ auto* document = this->document();
+ if (!document)
+ return nullptr;
+ auto clonedFragment = DocumentFragment::create(*document);
+
// The cloned fragment is never exposed to author scripts so it's safe to dispatch events here.
ScriptDisallowedScope::EventAllowedScope allowedScope(clonedFragment);
@@ -966,8 +976,8 @@
RefPtr<TextTrackCueBox> VTTCue::getDisplayTree(const IntSize& videoSize, int fontSize)
{
- Ref<VTTCueBox> displayTree = displayTreeInternal();
- if (!m_displayTreeShouldChange || !track()->isRendered())
+ RefPtr displayTree = displayTreeInternal();
+ if (!displayTree || !m_displayTreeShouldChange || !track()->isRendered())
return displayTree;
// 10.1 - 10.10
@@ -1040,9 +1050,13 @@
m_region->willRemoveTextTrackCueBox(m_displayTree.get());
}
+ RefPtr displayTree = displayTreeInternal();
+ if (!displayTree)
+ return;
+
// The display tree is never exposed to author scripts so it's safe to dispatch events here.
- ScriptDisallowedScope::EventAllowedScope allowedScope(displayTreeInternal());
- displayTreeInternal().remove();
+ ScriptDisallowedScope::EventAllowedScope allowedScope(*displayTree);
+ displayTree->remove();
}
std::pair<double, double> VTTCue::getPositionCoordinates() const
Modified: branches/safari-613-branch/Source/WebCore/html/track/VTTCue.h (295184 => 295185)
--- branches/safari-613-branch/Source/WebCore/html/track/VTTCue.h 2022-06-03 06:45:29 UTC (rev 295184)
+++ branches/safari-613-branch/Source/WebCore/html/track/VTTCue.h 2022-06-03 06:45:32 UTC (rev 295185)
@@ -195,8 +195,8 @@
bool cueContentsMatch(const TextTrackCue&) const override;
- virtual Ref<VTTCueBox> createDisplayTree();
- VTTCueBox& displayTreeInternal();
+ virtual RefPtr<VTTCueBox> createDisplayTree();
+ VTTCueBox* displayTreeInternal();
void toJSON(JSON::Object&) const override;
@@ -203,7 +203,7 @@
private:
VTTCue(Document&, const WebVTTCueData&);
- void initialize();
+ void initialize(Document&);
void createWebVTTNodeTree();
void parseSettings(const String&);