Bug 1348050 - Part 4: Mark channel as urgent-start for loading media. r=baku
The part is mainly to set urgent-start for loading media when it's initiated by
user interaction. For the HTMLMedia element, it has its algorithm to pre-load
the media and users will get feedback once they play the media. Thus, I only
set urgent-start when the media element has autoplay attribute since the sooner
enough resource is loaded the sooner the media will be played.
MozReview-Commit-ID: 7nu3PUt8iYo
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1159,16 +1159,20 @@ public:
aElement->NotifyLoadError();
return;
}
nsCOMPtr<nsIClassOfService> cos;
if (aElement->mUseUrgentStartForChannel &&
(cos = do_QueryInterface(channel))) {
cos->AddClassFlags(nsIClassOfService::UrgentStart);
+
+ // Reset the flag to avoid loading again without initiated by user
+ // interaction.
+ aElement->mUseUrgentStartForChannel = false;
}
// The listener holds a strong reference to us. This creates a
// reference cycle, once we've set mChannel, which is manually broken
// in the listener's OnStartRequest method after it is finished with
// the element. The cycle will also be broken if we get a shutdown
// notification before OnStartRequest fires. Necko guarantees that
// OnStartRequest will eventually fire if we don't shut down first.
@@ -1872,16 +1876,22 @@ void HTMLMediaElement::DoLoad()
}
// Detect if user has interacted with element so that play will not be
// blocked when initiated by a script. This enables sites to capture user
// intent to play by calling load() in the click handler of a "catalog
// view" of a gallery of videos.
if (EventStateManager::IsHandlingUserInput()) {
mHasUserInteraction = true;
+
+ // Mark the channel as urgent-start when autopaly so that it will play the
+ // media from src after loading enough resource.
+ if (HasAttr(kNameSpaceID_None, nsGkAtoms::autoplay)) {
+ mUseUrgentStartForChannel = true;
+ }
}
SetPlayedOrSeeked(false);
mIsRunningLoadMethod = true;
AbortExistingLoads();
SetPlaybackRate(mDefaultPlaybackRate);
QueueSelectResourceTask();
ResetState();