Bug 1348053 - add the UrgentStart flag to the channel when the loading is initiated by a user interaction for quicker network response.
MozReview-Commit-ID: 1tk9k8u1zTu
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -17,16 +17,17 @@
#include "base/basictypes.h"
#include "nsIDOMHTMLMediaElement.h"
#include "nsIDOMHTMLSourceElement.h"
#include "TimeRanges.h"
#include "nsGenericHTMLElement.h"
#include "nsAttrValueInlines.h"
#include "nsPresContext.h"
+#include "nsIClassOfService.h"
#include "nsIPresShell.h"
#include "nsGkAtoms.h"
#include "nsSize.h"
#include "nsIFrame.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDocShell.h"
#include "nsError.h"
@@ -1154,16 +1155,22 @@ public:
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS);
if (NS_FAILED(rv)) {
// Notify load error so the element will try next resource candidate.
aElement->NotifyLoadError();
return;
}
+ nsCOMPtr<nsIClassOfService> cos;
+ if (aElement->mUseUrgentStartForChannel &&
+ (cos = do_QueryInterface(channel))) {
+ cos->AddClassFlags(nsIClassOfService::UrgentStart);
+ }
+
// 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.
RefPtr<MediaLoadListener> loadListener = new MediaLoadListener(aElement);
@@ -3886,16 +3893,24 @@ HTMLMediaElement::PlayInternal(ErrorResu
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
mPendingPlayPromises.AppendElement(promise);
// Play was not blocked so assume user interacted with the element.
mHasUserInteraction = true;
+ if (mPreloadAction == HTMLMediaElement::PRELOAD_NONE) {
+ // The media load algorithm will be initiated by a user interaction.
+ // We want to boost the channel priority for better responsiveness.
+ // Note this must be done before UpdatePreloadAction() which will
+ // update |mPreloadAction|.
+ mUseUrgentStartForChannel = true;
+ }
+
StopSuspendingAfterFirstFrame();
SetPlayedOrSeeked(true);
// 4.8.12.8 - Step 4:
// If the media element's networkState attribute has the value NETWORK_EMPTY,
// invoke the media element's resource selection algorithm.
MaybeDoLoad();
if (mSuspendedForPreloadNone) {
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1619,16 +1619,20 @@ protected:
bool mSuspendedForPreloadNone;
// True if we've connected mSrcStream to the media element output.
bool mSrcStreamIsPlaying;
// True if a same-origin check has been done for the media element and resource.
bool mMediaSecurityVerified;
+ // True if we should set nsIClassOfService::UrgentStart to the channel to
+ // get the response ASAP for better user responsiveness.
+ bool mUseUrgentStartForChannel = false;
+
// The CORS mode when loading the media element
CORSMode mCORSMode;
// Info about the played media.
MediaInfo mMediaInfo;
// True if the media has encryption information.
bool mIsEncrypted;