@@ -952,11 +952,9 @@ void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument, Document& new
952952 ASSERT_WITH_SECURITY_IMPLICATION (&document () == &newDocument);
953953
954954 // Handle lazy loading observer transfer between documents
955- if (newDocument.settings ().lazyMediaLoadingEnabled ()) {
956- oldDocument.lazyLoadMediaObserver ().unobserve (*this , oldDocument);
957- if (isLazyLoadable ())
958- LazyLoadMediaObserver::observe (*this );
959- }
955+ oldDocument.lazyLoadMediaObserver ().unobserve (*this , oldDocument);
956+ if (newDocument.settings ().lazyMediaLoadingEnabled () && isLazyLoadable ())
957+ LazyLoadMediaObserver::observe (*this );
960958
961959 if (m_shouldDelayLoadEvent) {
962960 oldDocument.decrementLoadEventDelayCount ();
@@ -1037,7 +1035,7 @@ void HTMLMediaElement::attributeChanged(const QualifiedName& name, const AtomStr
10371035 // If a src attribute of a media element is set or changed, the user
10381036 // agent must invoke the media element's media element load algorithm.
10391037 if (!newValue.isNull ()) {
1040- if (isLazyLoadable () && document ().settings ().lazyMediaLoadingEnabled () && m_networkState == NETWORK_EMPTY )
1038+ if (m_networkState == NETWORK_EMPTY && document ().settings ().lazyMediaLoadingEnabled () && isLazyLoadable () )
10411039 LazyLoadMediaObserver::observe (*this );
10421040 else
10431041 prepareForLoad ();
@@ -1142,11 +1140,11 @@ void HTMLMediaElement::didFinishInsertingNode()
11421140
11431141 if (m_inActiveDocument && m_networkState == NETWORK_EMPTY) {
11441142 if (!attributeWithoutSynchronization (srcAttr).isEmpty ()) {
1145- if (isLazyLoadable () && document ().settings ().lazyMediaLoadingEnabled ())
1143+ if (document ().settings ().lazyMediaLoadingEnabled () && isLazyLoadable ())
11461144 LazyLoadMediaObserver::observe (*this );
11471145 else
11481146 prepareForLoad ();
1149- } else if (auto firstSource = childrenOfType<HTMLSourceElement>(*this ).first ()) {
1147+ } else if (RefPtr firstSource = childrenOfType<HTMLSourceElement>(*this ).first ()) {
11501148 // If there are source children, they will trigger sourceWasAdded() which handles lazy loading
11511149 // But if source children are already present when video is inserted, we need to check here 1
11521150 sourceWasAdded (*firstSource);
@@ -1230,8 +1228,11 @@ void HTMLMediaElement::removedFromAncestor(RemovalType removalType, ContainerNod
12301228{
12311229 HTMLMEDIAELEMENT_RELEASE_LOG (REMOVEDFROMANCESTOR);
12321230
1233- if (document ().settings ().lazyMediaLoadingEnabled ())
1234- document ().lazyLoadMediaObserver ().unobserve (*this , document ());
1231+ {
1232+ Ref document = this ->document ();
1233+ if (document->settings ().lazyMediaLoadingEnabled ())
1234+ document->lazyLoadMediaObserver ().unobserve (*this , document);
1235+ }
12351236
12361237 setInActiveDocument (false );
12371238 if (removalType.disconnectedFromDocument ) {
@@ -1538,18 +1539,20 @@ bool HTMLMediaElement::hasLazyLoadableAttributeValue(StringView attributeValue)
15381539
15391540bool HTMLMediaElement::isLazyLoadable () const
15401541{
1541- if (!document ().frame () || !document ().frame ()->checkedScript ()->canExecuteScripts (ReasonForCallingCanExecuteScripts::NotAboutToExecuteScript))
1542+ Ref document = this ->document ();
1543+ if (!document->frame () || !protect (document->frame ()->script ())->canExecuteScripts (ReasonForCallingCanExecuteScripts::NotAboutToExecuteScript))
15421544 return false ;
15431545
1544- if (document (). paginated ())
1546+ if (document-> paginated ())
15451547 return false ;
15461548 return hasLazyLoadableAttributeValue (attributeWithoutSynchronization (HTMLNames::loadingAttr));
15471549}
15481550
15491551void HTMLMediaElement::loadDeferredMedia ()
15501552{
1551- if (document ().settings ().lazyMediaLoadingEnabled ())
1552- document ().lazyLoadMediaObserver ().unobserve (*this , document ());
1553+ Ref document = this ->document ();
1554+ if (document->settings ().lazyMediaLoadingEnabled ())
1555+ document->lazyLoadMediaObserver ().unobserve (*this , document);
15531556
15541557 // Load the media - load() will handle both src attribute and source children
15551558 if (networkState () == NETWORK_EMPTY) {
@@ -1561,8 +1564,9 @@ void HTMLMediaElement::loadDeferredMedia()
15611564void HTMLMediaElement::resumeLazyLoadingIfNeeded ()
15621565{
15631566 // Per HTML spec: user-initiated play() triggers lazy load resumption steps
1564- if (document ().settings ().lazyMediaLoadingEnabled ()) {
1565- auto & observer = document ().lazyLoadMediaObserver ();
1567+ Ref document = this ->document ();
1568+ if (document->settings ().lazyMediaLoadingEnabled ()) {
1569+ auto & observer = document->lazyLoadMediaObserver ();
15661570 if (observer.isObserved (*this ))
15671571 loadDeferredMedia ();
15681572 }
@@ -5900,7 +5904,7 @@ void HTMLMediaElement::sourceWasAdded(HTMLSourceElement& source)
59005904 // the media element's resource selection algorithm.
59015905 if (m_networkState == NETWORK_EMPTY) {
59025906 m_nextChildNodeToConsider = source;
5903- if (isLazyLoadable () && document ().settings ().lazyMediaLoadingEnabled ()) {
5907+ if (document ().settings ().lazyMediaLoadingEnabled () && isLazyLoadable ()) {
59045908 LazyLoadMediaObserver::observe (*this );
59055909 return ;
59065910 }
0 commit comments