Bug 1377158 - (Part 5) Decide style backend type according to the loading document. r=heycam
☠☠ backed out by 01e4f85ad7f6 ☠ ☠
authorKuoE0 <kuoe0.tw@gmail.com>
Thu, 29 Jun 2017 16:14:47 -0700
changeset 421924 1310d6d8b5c091998951a05ce7ac05e4ffac7b28
parent 421923 b05327c3c55f15d52e7b3adf474e944ce600ef03
child 421925 30b7a45177bf28e258b8d811c08ef6ab8b4a135d
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1377158
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1377158 - (Part 5) Decide style backend type according to the loading document. r=heycam MozReview-Commit-ID: GGx0XUrGT2e
image/imgLoader.cpp
image/imgRequest.cpp
image/imgRequest.h
--- a/image/imgLoader.cpp
+++ b/image/imgLoader.cpp
@@ -2239,19 +2239,24 @@ imgLoader::LoadImage(nsIURI* aURI,
 
     nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(newChannel));
     if (cos && aUseUrgentStartForChannel) {
       cos->AddClassFlags(nsIClassOfService::UrgentStart);
     }
 
     nsCOMPtr<nsILoadGroup> channelLoadGroup;
     newChannel->GetLoadGroup(getter_AddRefs(channelLoadGroup));
+    // We look at the loading document's style backend type to decide which
+    // style backend type should be used for the images. So the images in Chrome
+    // documents would be loaded by Gecko.
     rv = request->Init(aURI, aURI, /* aHadInsecureRedirect = */ false,
                        channelLoadGroup, newChannel, entry, aLoadingDocument,
-                       aLoadingPrincipal, corsmode, aReferrerPolicy);
+                       aLoadingPrincipal, corsmode, aReferrerPolicy,
+                       aLoadingDocument ? aLoadingDocument->GetStyleBackendType()
+                                        : StyleBackendType::None);
     if (NS_FAILED(rv)) {
       return NS_ERROR_FAILURE;
     }
 
     // Add the initiator type for this image load
     nsCOMPtr<nsITimedChannel> timedChannel = do_QueryInterface(newChannel);
     if (timedChannel) {
       timedChannel->SetInitiatorType(initiatorType);
--- a/image/imgRequest.cpp
+++ b/image/imgRequest.cpp
@@ -64,16 +64,17 @@ imgRequest::imgRequest(imgLoader* aLoade
  , mMutex("imgRequest")
  , mProgressTracker(new ProgressTracker())
  , mIsMultiPartChannel(false)
  , mGotData(false)
  , mIsInCache(false)
  , mDecodeRequested(false)
  , mNewPartPending(false)
  , mHadInsecureRedirect(false)
+ , mStyleBackendType(StyleBackendType::None)
 { }
 
 imgRequest::~imgRequest()
 {
   if (mLoader) {
     mLoader->RemoveFromUncachedImages(this);
   }
   if (mURI) {
@@ -90,17 +91,18 @@ imgRequest::Init(nsIURI *aURI,
                  nsIURI *aCurrentURI,
                  bool aHadInsecureRedirect,
                  nsIRequest *aRequest,
                  nsIChannel *aChannel,
                  imgCacheEntry *aCacheEntry,
                  nsISupports* aCX,
                  nsIPrincipal* aLoadingPrincipal,
                  int32_t aCORSMode,
-                 ReferrerPolicy aReferrerPolicy)
+                 ReferrerPolicy aReferrerPolicy,
+                 StyleBackendType aStyleBackendType)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Cannot use nsIURI off main thread!");
 
   LOG_FUNC(gImgLog, "imgRequest::Init");
 
   MOZ_ASSERT(!mImage, "Multiple calls to init");
   MOZ_ASSERT(aURI, "No uri");
   MOZ_ASSERT(aCurrentURI, "No current uri");
@@ -118,16 +120,18 @@ imgRequest::Init(nsIURI *aURI,
   mRequest = aRequest;
   mChannel = aChannel;
   mTimedChannel = do_QueryInterface(mChannel);
 
   mLoadingPrincipal = aLoadingPrincipal;
   mCORSMode = aCORSMode;
   mReferrerPolicy = aReferrerPolicy;
 
+  mStyleBackendType = aStyleBackendType;
+
   // If the original URI and the current URI are different, check whether the
   // original URI is secure. We deliberately don't take the current URI into
   // account, as it needs to be handled using more complicated rules than
   // earlier elements of the redirect chain.
   if (aURI != aCurrentURI) {
     bool isHttps = false;
     bool isChrome = false;
     bool schemeLocal = false;
@@ -962,17 +966,18 @@ struct NewPartResult final
   const bool mIsFirstPart;
   bool mSucceeded;
   bool mShouldResetCacheEntry;
 };
 
 static NewPartResult
 PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount,
                   ImageURL* aURI, bool aIsMultipart, image::Image* aExistingImage,
-                  ProgressTracker* aProgressTracker, uint32_t aInnerWindowId)
+                  ProgressTracker* aProgressTracker, uint32_t aInnerWindowId,
+                  StyleBackendType aStyleBackendType)
 {
   NewPartResult result(aExistingImage);
 
   if (aInStr) {
     mimetype_closure closure;
     closure.newType = &result.mContentType;
 
     // Look at the first few bytes and see if we can tell what the data is from
@@ -1010,17 +1015,17 @@ PrepareForNewPart(nsIRequest* aRequest, 
   // Create the new image and give it ownership of our ProgressTracker.
   if (aIsMultipart) {
     // Create the ProgressTracker and image for this part.
     RefPtr<ProgressTracker> progressTracker = new ProgressTracker();
     RefPtr<image::Image> partImage =
       image::ImageFactory::CreateImage(aRequest, progressTracker,
                                        result.mContentType,
                                        aURI, /* aIsMultipart = */ true,
-                                       aInnerWindowId);
+                                       aInnerWindowId, aStyleBackendType);
 
     if (result.mIsFirstPart) {
       // First part for a multipart channel. Create the MultipartImage wrapper.
       MOZ_ASSERT(aProgressTracker, "Shouldn't have given away tracker yet");
       aProgressTracker->SetIsMultipart();
       result.mImage =
         image::ImageFactory::CreateMultipartImage(partImage, aProgressTracker);
     } else {
@@ -1035,17 +1040,17 @@ PrepareForNewPart(nsIRequest* aRequest, 
     MOZ_ASSERT(!aExistingImage, "New part for non-multipart channel?");
     MOZ_ASSERT(aProgressTracker, "Shouldn't have given away tracker yet");
 
     // Create an image using our progress tracker.
     result.mImage =
       image::ImageFactory::CreateImage(aRequest, aProgressTracker,
                                        result.mContentType,
                                        aURI, /* aIsMultipart = */ false,
-                                       aInnerWindowId);
+                                       aInnerWindowId, aStyleBackendType);
   }
 
   MOZ_ASSERT(result.mImage);
   if (!result.mImage->HasError() || aIsMultipart) {
     // We allow multipart images to fail to initialize (which generally
     // indicates a bad content type) without cancelling the load, because
     // subsequent parts might be fine.
     result.mSucceeded = true;
@@ -1128,17 +1133,18 @@ imgRequest::OnDataAvailable(nsIRequest* 
     mNewPartPending = false;
   }
 
   // If this is a new part, we need to sniff its content type and create an
   // appropriate image.
   if (newPartPending) {
     NewPartResult result = PrepareForNewPart(aRequest, aInStr, aCount, mURI,
                                              isMultipart, image,
-                                             progressTracker, mInnerWindowId);
+                                             progressTracker, mInnerWindowId,
+                                             mStyleBackendType);
     bool succeeded = result.mSucceeded;
 
     if (result.mImage) {
       image = result.mImage;
 
       // Update our state to reflect this new part.
       {
         MutexAutoLock lock(mMutex);
--- a/image/imgRequest.h
+++ b/image/imgRequest.h
@@ -17,16 +17,19 @@
 #include "nsProxyRelease.h"
 #include "nsStringGlue.h"
 #include "nsError.h"
 #include "nsIAsyncVerifyRedirectCallback.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/net/ReferrerPolicy.h"
 #include "ImageCacheKey.h"
 
+#include "X11UndefineNone.h"
+#include "mozilla/StyleBackendType.h"
+
 class imgCacheValidator;
 class imgLoader;
 class imgRequestProxy;
 class imgCacheEntry;
 class nsIApplicationCache;
 class nsIProperties;
 class nsIRequest;
 class nsITimedChannel;
@@ -48,16 +51,17 @@ class imgRequest final : public nsIStrea
                          public nsIInterfaceRequestor,
                          public nsIAsyncVerifyRedirectCallback
 {
   typedef mozilla::image::Image Image;
   typedef mozilla::image::ImageCacheKey ImageCacheKey;
   typedef mozilla::image::ImageURL ImageURL;
   typedef mozilla::image::ProgressTracker ProgressTracker;
   typedef mozilla::net::ReferrerPolicy ReferrerPolicy;
+  typedef mozilla::StyleBackendType StyleBackendType;
 
 public:
   imgRequest(imgLoader* aLoader, const ImageCacheKey& aCacheKey);
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSISTREAMLISTENER
   NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
   NS_DECL_NSIREQUESTOBSERVER
@@ -69,17 +73,18 @@ public:
                              nsIURI* aCurrentURI,
                              bool aHadInsecureRedirect,
                              nsIRequest* aRequest,
                              nsIChannel* aChannel,
                              imgCacheEntry* aCacheEntry,
                              nsISupports* aCX,
                              nsIPrincipal* aLoadingPrincipal,
                              int32_t aCORSMode,
-                             ReferrerPolicy aReferrerPolicy);
+                             ReferrerPolicy aReferrerPolicy,
+                             StyleBackendType aBackendType = StyleBackendType::None);
 
   void ClearLoader();
 
   // Callers must call imgRequestProxy::Notify later.
   void AddProxy(imgRequestProxy* proxy);
 
   nsresult RemoveProxy(imgRequestProxy* proxy, nsresult aStatus);
 
@@ -290,11 +295,14 @@ private:
   RefPtr<ProgressTracker> mProgressTracker;
   RefPtr<Image> mImage;
   bool mIsMultiPartChannel : 1;
   bool mGotData : 1;
   bool mIsInCache : 1;
   bool mDecodeRequested : 1;
   bool mNewPartPending : 1;
   bool mHadInsecureRedirect : 1;
+
+  // The backend used for this image document.
+  mozilla::StyleBackendType mStyleBackendType;
 };
 
 #endif // mozilla_image_imgRequest_h