From cedca668f68d2c725be621a376dd83abfce3e62f Mon Sep 17 00:00:00 2001 From: Felipe Gomes Date: Tue, 24 Jan 2017 03:07:51 -0200 Subject: [PATCH] Bug 1282484 - Cache the value of PreferFallback() because ShouldPlay() is called several times during the load process. r=qDot MozReview-Commit-ID: DqjCHssaJde --- dom/base/nsObjectLoadingContent.cpp | 12 ++++++++++-- dom/base/nsObjectLoadingContent.h | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 63edefb043a7b..e5ea23ef89225 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -666,7 +666,9 @@ nsObjectLoadingContent::nsObjectLoadingContent() , mIsStopping(false) , mIsLoading(false) , mScriptRequested(false) - , mRewrittenYoutubeEmbed(false) {} + , mRewrittenYoutubeEmbed(false) + , mPreferFallback(false) + , mPreferFallbackKnown(false) {} nsObjectLoadingContent::~nsObjectLoadingContent() { @@ -3457,7 +3459,13 @@ nsObjectLoadingContent::HasGoodFallback() { bool nsObjectLoadingContent::PreferFallback(bool aIsPluginClickToPlay) { - return FavorFallbackMode(aIsPluginClickToPlay) && HasGoodFallback(); + if (mPreferFallbackKnown) { + return mPreferFallback; + } + + mPreferFallbackKnown = true; + mPreferFallback = FavorFallbackMode(aIsPluginClickToPlay) && HasGoodFallback(); + return mPreferFallback; } nsIDocument* diff --git a/dom/base/nsObjectLoadingContent.h b/dom/base/nsObjectLoadingContent.h index fe2d687ccd46f..62ec406f99f97 100644 --- a/dom/base/nsObjectLoadingContent.h +++ b/dom/base/nsObjectLoadingContent.h @@ -705,6 +705,11 @@ class nsObjectLoadingContent : public nsImageLoadingContent // videos. bool mRewrittenYoutubeEmbed : 1; + // Cache the answer of PreferFallback() because ShouldPlay is called several + // times during the load process. + bool mPreferFallback : 1; + bool mPreferFallbackKnown : 1; + nsWeakFrame mPrintFrame; RefPtr mInstanceOwner;