Merge mozilla-central to autoland. r=merge a=merge CLOSED TREE
authorNoemi Erli <nerli@mozilla.com>
Fri, 12 Jan 2018 03:52:35 +0200
changeset 450757 ce4d5812e03a48bc5e217b721bea750d43577a33
parent 450696 285a70c630f6003c226dcb68725df137df243ae9 (current diff)
parent 450619 f7f5ba2214d2ce7b1ce9647b0e2540490a6098a8 (diff)
child 450758 72823606d8b47ddbbfa7cb2dd975e0e52f4a60a3
push id8543
push userryanvm@gmail.com
push dateTue, 16 Jan 2018 14:33:22 +0000
treeherdermozilla-beta@a6525ed16a32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge, merge
milestone59.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
Merge mozilla-central to autoland. r=merge a=merge CLOSED TREE
--- a/browser/components/sessionstore/test/browser_354894_perwindowpb.js
+++ b/browser/components/sessionstore/test/browser_354894_perwindowpb.js
@@ -136,17 +136,17 @@ let setupTest = async function(options, 
 
   for (let o in observing) {
     Services.obs.addObserver(observer, o);
   }
 
   let private = options.private || false;
   let newWin = await promiseNewWindowLoaded({ private });
 
-  await injectTestTabs(newWin);
+  injectTestTabs(newWin);
 
   await testFunction(newWin, observing);
 
   let count = getBrowserWindowsCount();
   is(count.open, 0, "Got right number of open windows");
   is(count.winstates, 1, "Got right number of stored window states");
 
   for (let o in observing) {
@@ -158,19 +158,19 @@ let setupTest = async function(options, 
 
 /**
  * Loads a TEST_URLS into a browser window.
  *
  * @param win (Window)
  *        The browser window to load the tabs in
  */
 function injectTestTabs(win) {
-  let promises = TEST_URLS.map(url => win.gBrowser.addTab(url))
-                          .map(tab => BrowserTestUtils.browserLoaded(tab.linkedBrowser));
-  return Promise.all(promises);
+  TEST_URLS.forEach(function(url) {
+    win.gBrowser.addTab(url);
+  });
 }
 
 /**
  * Attempts to close a window via BrowserTryToCloseWindow so that
  * we get the browser-lastwindow-close-requested and
  * browser-lastwindow-close-granted observer notifications.
  *
  * @param win (Window)
--- a/modules/libjar/nsJARChannel.cpp
+++ b/modules/libjar/nsJARChannel.cpp
@@ -21,17 +21,16 @@
 #include "nsIPrincipal.h"
 #include "nsIFileURL.h"
 
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Preferences.h"
 #include "nsITabChild.h"
 #include "private/pprio.h"
 #include "nsInputStreamPump.h"
-#include "nsThreadUtils.h"
 
 using namespace mozilla;
 using namespace mozilla::net;
 
 static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
 
 // the entry for a directory will either be empty (in the case of the
 // top-level directory) or will end with a slash
@@ -194,31 +193,27 @@ nsJARInputThunk::IsNonBlocking(bool *non
 
 nsJARChannel::nsJARChannel()
     : mOpened(false)
     , mContentDisposition(0)
     , mContentLength(-1)
     , mLoadFlags(LOAD_NORMAL)
     , mStatus(NS_OK)
     , mIsPending(false)
-    , mEnableOMT(true)
-    , mPendingEvent()
     , mIsUnsafe(true)
     , mBlockRemoteFiles(false)
 {
-    LOG(("nsJARChannel::nsJARChannel [this=%p]\n", this));
     mBlockRemoteFiles = Preferences::GetBool("network.jar.block-remote-files", false);
 
     // hold an owning reference to the jar handler
     NS_ADDREF(gJarHandler);
 }
 
 nsJARChannel::~nsJARChannel()
 {
-    LOG(("nsJARChannel::~nsJARChannel [this=%p]\n", this));
     NS_ReleaseOnMainThreadSystemGroup("nsJARChannel::mLoadInfo",
                                       mLoadInfo.forget());
 
     // release owning reference to the jar handler
     nsJARProtocolHandler *handler = gJarHandler;
     NS_RELEASE(handler); // nullptr parameter
 }
 
@@ -230,24 +225,17 @@ NS_IMPL_ISUPPORTS_INHERITED(nsJARChannel
                             nsIRequestObserver,
                             nsIThreadRetargetableRequest,
                             nsIThreadRetargetableStreamListener,
                             nsIJARChannel)
 
 nsresult
 nsJARChannel::Init(nsIURI *uri)
 {
-    LOG(("nsJARChannel::Init [this=%p]\n", this));
     nsresult rv;
-
-    mWorker = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) {
-        return rv;
-    }
-
     mJarURI = do_QueryInterface(uri, &rv);
     if (NS_FAILED(rv))
         return rv;
 
     mOriginalURI = mJarURI;
 
     // Prevent loading jar:javascript URIs (see bug 290982).
     nsCOMPtr<nsIURI> innerURI;
@@ -265,17 +253,16 @@ nsJARChannel::Init(nsIURI *uri)
 
     mJarURI->GetSpec(mSpec);
     return rv;
 }
 
 nsresult
 nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache, nsJARInputThunk **resultInput)
 {
-    LOG(("nsJARChannel::CreateJarInput [this=%p]\n", this));
     MOZ_ASSERT(resultInput);
     MOZ_ASSERT(mJarFile || mTempMem);
 
     // important to pass a clone of the file since the nsIFile impl is not
     // necessarily MT-safe
     nsCOMPtr<nsIFile> clonedFile;
     nsresult rv = NS_OK;
     if (mJarFile) {
@@ -390,244 +377,34 @@ nsJARChannel::LookupFile(bool aAllowAsyn
             }
         }
     }
 
     return rv;
 }
 
 nsresult
-CreateLocalJarInput(nsIZipReaderCache* aJarCache,
-                    nsIFile* aFile,
-                    const nsACString& aInnerJarEntry,
-                    nsIJARURI* aJarURI,
-                    const nsACString& aJarEntry,
-                    nsJARInputThunk** aResultInput)
-{
-    LOG(("nsJARChannel::CreateLocalJarInput [aJarCache=%p, %s, %s]\n",
-         aJarCache,
-         PromiseFlatCString(aInnerJarEntry).get(),
-         PromiseFlatCString(aJarEntry).get()));
-
-    MOZ_ASSERT(!NS_IsMainThread());
-    MOZ_ASSERT(aJarCache);
-    MOZ_ASSERT(aResultInput);
-
-    nsresult rv;
-
-    nsCOMPtr<nsIZipReader> reader;
-    if (aInnerJarEntry.IsEmpty()) {
-        rv = aJarCache->GetZip(aFile, getter_AddRefs(reader));
-    } else {
-        rv = aJarCache->GetInnerZip(aFile,
-                                    aInnerJarEntry,
-                                    getter_AddRefs(reader));
-    }
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-    }
-
-    RefPtr<nsJARInputThunk> input = new nsJARInputThunk(reader,
-                                                        aJarURI,
-                                                        aJarEntry,
-                                                        aJarCache != nullptr);
-    rv = input->Init();
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-    }
-
-    input.forget(aResultInput);
-    return NS_OK;
-}
-
-nsresult
 nsJARChannel::OpenLocalFile()
 {
-    LOG(("nsJARChannel::OpenLocalFile [this=%p]\n", this));
-
-    MOZ_ASSERT(NS_IsMainThread());
-
-    MOZ_ASSERT(mWorker);
     MOZ_ASSERT(mIsPending);
-    MOZ_ASSERT(mJarFile);
 
     // Local files are always considered safe.
     mIsUnsafe = false;
 
-    nsresult rv;
-
-    // Set mLoadGroup and mOpened before AsyncOpen return, and set back if
-    // if failed when callback.
-    if (mLoadGroup) {
-        mLoadGroup->AddRequest(this, nullptr);
-    }
-    mOpened = true;
-
-    if (!mEnableOMT) {
-
-        RefPtr<nsJARInputThunk> input;
-        rv = CreateJarInput(gJarHandler->JarCache(),
-                            getter_AddRefs(input));
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-            return OnOpenLocalFileComplete(rv);
-        }
-        return ContinueOpenLocalFile(input);
-    }
-
-
-    nsCOMPtr<nsIZipReaderCache> jarCache = gJarHandler->JarCache();
-    if (NS_WARN_IF(!jarCache)) {
-        return NS_ERROR_UNEXPECTED;
-    }
-
-    nsCOMPtr<nsIFile> clonedFile;
-    rv = mJarFile->Clone(getter_AddRefs(clonedFile));
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-    }
-
-    // clone mJarURI
-    nsCOMPtr<nsIURI> clonedURI;
-    rv = mJarURI->Clone(getter_AddRefs(clonedURI));
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-    }
-    nsCOMPtr<nsIJARURI> clonedJarURI = do_QueryInterface(clonedURI, &rv);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
+    RefPtr<nsJARInputThunk> input;
+    nsresult rv = CreateJarInput(gJarHandler->JarCache(),
+                                 getter_AddRefs(input));
+    if (NS_SUCCEEDED(rv)) {
+        // Create input stream pump and call AsyncRead as a block.
+        rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input.forget());
+        if (NS_SUCCEEDED(rv))
+            rv = mPump->AsyncRead(this, nullptr);
     }
 
-    nsAutoCString jarEntry(mJarEntry);
-    nsAutoCString innerJarEntry(mInnerJarEntry);
-
-    RefPtr<nsJARChannel> self = this;
-    return mWorker->Dispatch(
-            NS_NewRunnableFunction("nsJARChannel::OpenLocalFile",
-                                   [self,
-                                   jarCache,
-                                   clonedFile,
-                                   clonedJarURI,
-                                   jarEntry,
-                                   innerJarEntry] () mutable {
-
-        RefPtr<nsJARInputThunk> input;
-        nsresult rv = CreateLocalJarInput(jarCache,
-                                          clonedFile,
-                                          innerJarEntry,
-                                          clonedJarURI,
-                                          jarEntry,
-                                          getter_AddRefs(input));
-
-        NS_ReleaseOnMainThreadSystemGroup("nsJARChannel::clonedJarURI",
-                                          clonedJarURI.forget());
-
-        nsCOMPtr<nsIRunnable> target;
-        if (NS_SUCCEEDED(rv)) {
-            target = NewRunnableMethod<RefPtr<nsJARInputThunk>>(
-                "nsJARChannel::ContinueOpenLocalFile",
-                self,
-                &nsJARChannel::ContinueOpenLocalFile,
-                input);
-        } else {
-            target = NewRunnableMethod<nsresult>(
-                "nsJARChannel::OnOpenLocalFileComplete",
-                self,
-                &nsJARChannel::OnOpenLocalFileComplete,
-                rv);
-        }
-
-        // nsJARChannel must be release on main thread, and sometimes
-        // this still hold nsJARChannel after dispatched.
-        self = nullptr;
-
-        NS_DispatchToMainThread(target);
-    }));
-}
-
-nsresult
-nsJARChannel::ContinueOpenLocalFile(nsJARInputThunk* aInput)
-{
-    LOG(("nsJARChannel::ContinueOpenLocalFile [this=%p %p]\n", this, aInput));
-
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mIsPending);
-
-    // Make GetContentLength meaningful
-    mContentLength = aInput->GetContentLength();
-
-    nsresult rv;
-    RefPtr<nsJARInputThunk> input = aInput;
-    // Create input stream pump and call AsyncRead as a block.
-    rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input.forget());
-    if (NS_SUCCEEDED(rv)) {
-        rv = mPump->AsyncRead(this, nullptr);
-    }
-
-    if (NS_SUCCEEDED(rv)) {
-        rv = CheckPendingEvents();
-    }
-
-    return OnOpenLocalFileComplete(rv);
-}
-
-nsresult
-nsJARChannel::OnOpenLocalFileComplete(nsresult aResult)
-{
-    LOG(("nsJARChannel::OnOpenLocalFileComplete [this=%p %08x]\n",
-         this,
-         static_cast<uint32_t>(aResult)));
-
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mIsPending);
-
-    if (NS_FAILED(aResult)) {
-        if (mIsPending && mEnableOMT) {
-            NotifyError(aResult);
-        }
-
-        if (mLoadGroup) {
-            mLoadGroup->RemoveRequest(this, nullptr, aResult);
-        }
-
-        mOpened = false;
-        mIsPending = false;
-        mListenerContext = nullptr;
-        mListener = nullptr;
-        mCallbacks = nullptr;
-        mProgressSink = nullptr;
-
-        return aResult;
-    }
-
-    return NS_OK;
-}
-
-nsresult nsJARChannel::CheckPendingEvents()
-{
-    MOZ_ASSERT(NS_IsMainThread());
-    MOZ_ASSERT(mIsPending);
-    MOZ_ASSERT(mPump);
-
-    nsresult rv;
-
-    auto suspendCount = mPendingEvent.suspendCount;
-    while (suspendCount--) {
-        if (NS_WARN_IF(NS_FAILED(rv = mPump->Suspend()))) {
-            return rv;
-        }
-    }
-
-    if (mPendingEvent.isCanceled) {
-        if (NS_WARN_IF(NS_FAILED(rv = mPump->Cancel(mStatus)))) {
-            return rv;
-        }
-        mPendingEvent.isCanceled = false;
-    }
-
-    return NS_OK;
+    return rv;
 }
 
 void
 nsJARChannel::NotifyError(nsresult aError)
 {
     MOZ_ASSERT(NS_FAILED(aError));
 
     mStatus = aError;
@@ -671,51 +448,40 @@ nsJARChannel::GetStatus(nsresult *status
         *status = mStatus;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARChannel::Cancel(nsresult status)
 {
     mStatus = status;
-    if (mPump) {
+    if (mPump)
         return mPump->Cancel(status);
-    }
 
-    if (mIsPending) {
-        mPendingEvent.isCanceled = true;
-    }
-
+    NS_ASSERTION(!mIsPending, "need to implement cancel when downloading");
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARChannel::Suspend()
 {
-    ++mPendingEvent.suspendCount;
+    if (mPump)
+        return mPump->Suspend();
 
-    if (mPump) {
-        return mPump->Suspend();
-    }
-
+    NS_ASSERTION(!mIsPending, "need to implement suspend when downloading");
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARChannel::Resume()
 {
-    if (NS_WARN_IF(mPendingEvent.suspendCount == 0)) {
-        return NS_ERROR_UNEXPECTED;
-    }
-    --mPendingEvent.suspendCount;
+    if (mPump)
+        return mPump->Resume();
 
-    if (mPump) {
-        return mPump->Resume();
-    }
-
+    NS_ASSERTION(!mIsPending, "need to implement resume when downloading");
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
 {
     *aLoadFlags = mLoadFlags;
     return NS_OK;
@@ -984,27 +750,25 @@ nsJARChannel::Open(nsIInputStream **stre
     // local files are always considered safe
     mIsUnsafe = false;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARChannel::Open2(nsIInputStream** aStream)
 {
-    LOG(("nsJARChannel::Open2 [this=%p]\n", this));
     nsCOMPtr<nsIStreamListener> listener;
     nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
     NS_ENSURE_SUCCESS(rv, rv);
     return Open(aStream);
 }
 
 NS_IMETHODIMP
 nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
 {
-    LOG(("nsJARChannel::AsyncOpen [this=%p]\n", this));
     MOZ_ASSERT(!mLoadInfo ||
                mLoadInfo->GetSecurityMode() == 0 ||
                mLoadInfo->GetInitialSecurityCheckDone() ||
                (mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
                 nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
                "security flags in loadInfo but asyncOpen2() not called");
 
     LOG(("nsJARChannel::AsyncOpen [this=%p]\n", this));
@@ -1068,46 +832,41 @@ nsJARChannel::AsyncOpen(nsIStreamListene
             return rv;
         }
         if (mLoadInfo && mLoadInfo->GetEnforceSecurity()) {
             rv = channel->AsyncOpen2(downloader);
         }
         else {
             rv = channel->AsyncOpen(downloader, nullptr);
         }
-
     }
     else {
         rv = OpenLocalFile();
-        if (NS_SUCCEEDED(rv)) {
-            return NS_OK;
-        }
     }
 
     if (NS_FAILED(rv)) {
         mIsPending = false;
         mListenerContext = nullptr;
         mListener = nullptr;
         mCallbacks = nullptr;
         mProgressSink = nullptr;
         return rv;
     }
 
     if (mLoadGroup)
         mLoadGroup->AddRequest(this, nullptr);
 
     mOpened = true;
-    LOG(("nsJARChannel::AsyncOpen [this=%p] 8\n", this));
+
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsJARChannel::AsyncOpen2(nsIStreamListener *aListener)
 {
-    LOG(("nsJARChannel::AsyncOpen2 [this=%p]\n", this));
   nsCOMPtr<nsIStreamListener> listener = aListener;
   nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
   if (NS_FAILED(rv)) {
       mIsPending = false;
       mListenerContext = nullptr;
       mListener = nullptr;
       mCallbacks = nullptr;
       mProgressSink = nullptr;
--- a/modules/libjar/nsJARChannel.h
+++ b/modules/libjar/nsJARChannel.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsJARChannel_h__
 #define nsJARChannel_h__
 
 #include "mozilla/net/MemoryDownloader.h"
 #include "nsIJARChannel.h"
 #include "nsIJARURI.h"
-#include "nsIEventTarget.h"
 #include "nsIInputStreamPump.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIProgressEventSink.h"
 #include "nsIStreamListener.h"
 #include "nsIZipReader.h"
 #include "nsILoadGroup.h"
 #include "nsILoadInfo.h"
 #include "nsIThreadRetargetableRequest.h"
@@ -55,19 +54,16 @@ public:
     void SetFile(nsIFile *file);
 
 private:
     virtual ~nsJARChannel();
 
     nsresult CreateJarInput(nsIZipReaderCache *, nsJARInputThunk **);
     nsresult LookupFile(bool aAllowAsync);
     nsresult OpenLocalFile();
-    nsresult ContinueOpenLocalFile(nsJARInputThunk* aInput);
-    nsresult OnOpenLocalFileComplete(nsresult aResult);
-    nsresult CheckPendingEvents();
     void NotifyError(nsresult aError);
     void FireOnProgress(uint64_t aProgress);
     virtual void OnDownloadComplete(mozilla::net::MemoryDownloader* aDownloader,
                                     nsIRequest* aRequest,
                                     nsISupports* aCtxt,
                                     nsresult aStatus,
                                     mozilla::net::MemoryDownloader::Data aData)
         override;
@@ -90,39 +86,28 @@ private:
     nsCString                       mContentCharset;
     nsCString                       mContentDispositionHeader;
     /* mContentDisposition is uninitialized if mContentDispositionHeader is
      * empty */
     uint32_t                        mContentDisposition;
     int64_t                         mContentLength;
     uint32_t                        mLoadFlags;
     nsresult                        mStatus;
-    bool                            mIsPending; // the AsyncOpen is in progress.
-
-    bool                            mEnableOMT;
-    // |Cancel()|, |Suspend()|, and |Resume()| might be called during AsyncOpen.
-    struct {
-        bool isCanceled;
-        uint32_t suspendCount;
-    }                               mPendingEvent;
-
+    bool                            mIsPending;
     bool                            mIsUnsafe;
 
     mozilla::net::MemoryDownloader::Data mTempMem;
     nsCOMPtr<nsIInputStreamPump>    mPump;
     // mRequest is only non-null during OnStartRequest, so we'll have a pointer
     // to the request if we get called back via RetargetDeliveryTo.
     nsCOMPtr<nsIRequest>            mRequest;
     nsCOMPtr<nsIFile>               mJarFile;
     nsCOMPtr<nsIFile>               mJarFileOverride;
     nsCOMPtr<nsIZipReader>          mPreCachedJarReader;
     nsCOMPtr<nsIURI>                mJarBaseURI;
     nsCString                       mJarEntry;
     nsCString                       mInnerJarEntry;
 
-    // use StreamTransportService as background thread
-    nsCOMPtr<nsIEventTarget>        mWorker;
-
     // True if this channel should not download any remote files.
     bool                            mBlockRemoteFiles;
 };
 
 #endif // nsJARChannel_h__