Bug 1282484 - Cache the value of PreferFallback() because ShouldPlay() is called several times during the load process. r=qDot draft
authorFelipe Gomes <felipc@gmail.com>
Wed, 09 Nov 2016 17:24:07 -0200
changeset 436806 5d2e1e5b2457bbdf2f9b6c73517120aa849bc93d
parent 436805 cc62186c8ee3b96853e0dbfc8d5b50fb70fd69c7
child 436807 d417fbfd7a1bb9d71fe4546da9ec4fbf36110338
push id35191
push userfelipc@gmail.com
push dateWed, 09 Nov 2016 19:25:33 +0000
reviewersqDot
bugs1282484
milestone52.0a1
Bug 1282484 - Cache the value of PreferFallback() because ShouldPlay() is called several times during the load process. r=qDot MozReview-Commit-ID: L8H8Y8Mp5Ww
dom/base/nsObjectLoadingContent.cpp
dom/base/nsObjectLoadingContent.h
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -731,17 +731,19 @@ nsObjectLoadingContent::nsObjectLoadingC
   , mChannelLoaded(false)
   , mInstantiating(false)
   , mNetworkCreated(true)
   , mActivated(false)
   , mContentBlockingDisabled(false)
   , mIsStopping(false)
   , mIsLoading(false)
   , mScriptRequested(false)
-  , mRewrittenYoutubeEmbed(false) {}
+  , mRewrittenYoutubeEmbed(false)
+  , mPreferFallback(false)
+  , mPreferFallbackKnown(false) {}
 
 nsObjectLoadingContent::~nsObjectLoadingContent()
 {
   // Should have been unbound from the tree at this point, and
   // CheckPluginStopEvent keeps us alive
   if (mFrameLoader) {
     NS_NOTREACHED("Should not be tearing down frame loaders at this point");
     mFrameLoader->Destroy();
@@ -3589,17 +3591,23 @@ nsObjectLoadingContent::HasGoodFallback(
 
   // xxx to be filled
 
   return false;
 }
 
 bool
 nsObjectLoadingContent::PreferFallback(bool aIsPluginClickToPlay) {
-  return FavorFallbackMode(aIsPluginClickToPlay) && HasGoodFallback();
+  if (mPreferFallbackKnown) {
+    return mPreferFallback;
+  }
+
+  mPreferFallbackKnown = true;
+  mPreferFallback = FavorFallbackMode(aIsPluginClickToPlay) && HasGoodFallback();
+  return mPreferFallback;
 }
 
 nsIDocument*
 nsObjectLoadingContent::GetContentDocument(nsIPrincipal& aSubjectPrincipal)
 {
   nsCOMPtr<nsIContent> thisContent =
     do_QueryInterface(static_cast<nsIImageLoadingContent*>(this));
 
--- a/dom/base/nsObjectLoadingContent.h
+++ b/dom/base/nsObjectLoadingContent.h
@@ -701,16 +701,21 @@ class nsObjectLoadingContent : public ns
     bool                        mScriptRequested : 1;
 
     // True if object represents an object/embed tag pointing to a flash embed
     // for a youtube video. When possible (see IsRewritableYoutubeEmbed function
     // comments for details), we change these to try to load HTML5 versions of
     // 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<nsPluginInstanceOwner> mInstanceOwner;
     nsTArray<mozilla::dom::MozPluginParameter> mCachedAttributes;
     nsTArray<mozilla::dom::MozPluginParameter> mCachedParameters;
 };
 
 #endif