Bug 1282484 - Cache the value of PreferFallback() because ShouldPlay() is called several times during the load process. r=qDot
MozReview-Commit-ID: L8H8Y8Mp5Ww
--- 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