Bug 1282484 - Cache the value of PreferFallback() because ShouldPlay() is called several times during the load process draft
authorFelipe Gomes <felipc@gmail.com>
Tue, 08 Nov 2016 17:23:42 -0200
changeset 435452 dff29cfe89c8b32340ccd0b5a55f38f2a3b04c8c
parent 435451 9897c256b0165973fa69583f8e33c20b97d03a70
child 435456 9c21f2a0761d92e99b38f742e390be5ab7a16777
push id35050
push userfelipc@gmail.com
push dateTue, 08 Nov 2016 19:24:26 +0000
bugs1282484
milestone52.0a1
Bug 1282484 - Cache the value of PreferFallback() because ShouldPlay() is called several times during the load process MozReview-Commit-ID: DBVDmX6cAbF
dom/base/nsObjectLoadingContent.cpp
dom/base/nsObjectLoadingContent.h
--- a/dom/base/nsObjectLoadingContent.cpp
+++ b/dom/base/nsObjectLoadingContent.cpp
@@ -732,17 +732,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();
@@ -3604,17 +3606,23 @@ nsObjectLoadingContent::HasGoodFallback(
     }
   }
 
   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