Backed out 10 changesets (bug 1214305) for leaks on linux debug m-e10s(bc7)
authorWes Kocher <wkocher@mozilla.com>
Mon, 04 Jan 2016 10:34:24 -0800
changeset 278332 c315a91b6edb1ab48c71b6975cc4d12a7fe35185
parent 278331 0e4bdac31c326ba2c22082469cdf9fb6626fe912
child 278333 11acb7e361fe445eb563fa43d552f3d10dac56d9
push id69733
push userkwierso@gmail.com
push dateMon, 04 Jan 2016 18:34:32 +0000
treeherdermozilla-inbound@c315a91b6edb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1214305
milestone46.0a1
backs out1f482566235a007d579bd42682e8afa26d2d087e
001b314897561c53b94b75ab1abf800f95805a81
4e94d20882191a1c448bab61706ff43607387424
fba4a5bcea4172e7652fd4a3ecfa3cdfb9a3dde9
100f8e24900720858a485cfb9f86d35538401b41
a59c453192dce3e7a6d79b9d8e5be3f96c03ccb1
2daa86fc1fb9e3fe00a02a934c82c90e071f69f8
c04efb57b0ed18c8b70dffae6c471c24472ad4f3
52046e843c60ba6fd77acb865a59a3bb5941f9dd
ac4fd6615828929a1aed4c5b2a356c3e7a372589
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
Backed out 10 changesets (bug 1214305) for leaks on linux debug m-e10s(bc7) Backed out changeset 1f482566235a (bug 1214305) Backed out changeset 001b31489756 (bug 1214305) Backed out changeset 4e94d2088219 (bug 1214305) Backed out changeset fba4a5bcea41 (bug 1214305) Backed out changeset 100f8e249007 (bug 1214305) Backed out changeset a59c453192dc (bug 1214305) Backed out changeset 2daa86fc1fb9 (bug 1214305) Backed out changeset c04efb57b0ed (bug 1214305) Backed out changeset 52046e843c60 (bug 1214305) Backed out changeset ac4fd6615828 (bug 1214305)
devtools/client/webconsole/test/browser_bug1045902_console_csp_ignore_reflected_xss_message.js
dom/ipc/ContentParent.cpp
dom/workers/ServiceWorkerManager.cpp
dom/workers/ServiceWorkerPrivate.cpp
dom/workers/test/serviceworkers/mochitest.ini
modules/libjar/InterceptedJARChannel.cpp
netwerk/base/nsINetworkInterceptController.idl
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
netwerk/protocol/http/HttpBaseChannel.cpp
netwerk/protocol/http/HttpBaseChannel.h
netwerk/protocol/http/HttpChannelChild.cpp
netwerk/protocol/http/InterceptedChannel.cpp
netwerk/protocol/http/InterceptedChannel.h
netwerk/protocol/http/nsHttpChannel.cpp
--- a/devtools/client/webconsole/test/browser_bug1045902_console_csp_ignore_reflected_xss_message.js
+++ b/devtools/client/webconsole/test/browser_bug1045902_console_csp_ignore_reflected_xss_message.js
@@ -30,19 +30,26 @@ add_task(function* () {
 
   yield loadDocument(browser);
   yield testViolationMessage();
 
   hud = null;
 });
 
 function loadDocument(browser) {
+  let deferred = promise.defer();
+
   hud.jsterm.clearOutput();
-  browser.loadURI(TEST_FILE);
-  return BrowserTestUtils.browserLoaded(browser);
+  browser.addEventListener("load", function onLoad() {
+    browser.removeEventListener("load", onLoad, true);
+    deferred.resolve();
+  }, true);
+  content.location = TEST_FILE;
+
+  return deferred.promise;
 }
 
 function testViolationMessage() {
   let aOutputNode = hud.outputNode;
 
   return waitForSuccess({
       name: "Confirming that CSP logs messages to the console when " +
             "'reflected-xss' directive is used!",
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -2756,19 +2756,16 @@ ContentParent::RecvReadFontList(Infallib
 #endif
     return true;
 }
 
 bool
 ContentParent::RecvReadDataStorageArray(const nsString& aFilename,
                                         InfallibleTArray<DataStorageItem>* aValues)
 {
-    // Ensure the SSS is initialized before we try to use its storage.
-    nsCOMPtr<nsISiteSecurityService> sss = do_GetService("@mozilla.org/ssservice;1");
-
     RefPtr<DataStorage> storage = DataStorage::Get(aFilename);
     storage->GetAll(aValues);
     return true;
 }
 
 bool
 ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions)
 {
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -3586,17 +3586,17 @@ ServiceWorkerManager::PrepareFetchEvent(
       return nullptr;
     }
 
     internalChannel->GetLoadGroup(getter_AddRefs(loadGroup));
 
     documentId = aDocumentIdForTopLevelNavigation;
 
     nsCOMPtr<nsIURI> uri;
-    aRv = aChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri));
+    aRv = internalChannel->GetURI(getter_AddRefs(uri));
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
 
     RefPtr<ServiceWorkerRegistrationInfo> registration =
       GetServiceWorkerRegistrationInfo(aOriginAttributes, uri);
     if (!registration) {
       NS_WARNING("No registration found when dispatching the fetch event");
--- a/dom/workers/ServiceWorkerPrivate.cpp
+++ b/dom/workers/ServiceWorkerPrivate.cpp
@@ -1047,17 +1047,17 @@ public:
   Init()
   {
     AssertIsOnMainThread();
     nsCOMPtr<nsIChannel> channel;
     nsresult rv = mInterceptedChannel->GetChannel(getter_AddRefs(channel));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIURI> uri;
-    rv = mInterceptedChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri));
+    rv = channel->GetURI(getter_AddRefs(uri));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = uri->GetSpec(mSpec);
     NS_ENSURE_SUCCESS(rv, rv);
 
     uint32_t loadFlags;
     rv = channel->GetLoadFlags(&loadFlags);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/dom/workers/test/serviceworkers/mochitest.ini
+++ b/dom/workers/test/serviceworkers/mochitest.ini
@@ -281,16 +281,18 @@ skip-if = toolkit == "android" || toolki
 [test_opaque_intercept.html]
 [test_xslt.html]
 [test_escapedSlashes.html]
 [test_eventsource_intercept.html]
 [test_not_intercept_plugin.html]
 [test_file_blob_upload.html]
 [test_unresolved_fetch_interception.html]
 [test_hsts_upgrade_intercept.html]
+skip-if = e10s # Bug 1214305
 [test_csp_upgrade-insecure_intercept.html]
+skip-if = e10s # Bug 1214305
 [test_serviceworker_header.html]
 [test_openWindow.html]
 skip-if = toolkit == "android" || toolkit == "gonk"
 [test_imagecache.html]
 [test_imagecache_max_age.html]
 [test_importscript_mixedcontent.html]
 tags = mcb
--- a/modules/libjar/InterceptedJARChannel.cpp
+++ b/modules/libjar/InterceptedJARChannel.cpp
@@ -41,22 +41,16 @@ InterceptedJARChannel::GetInternalConten
 NS_IMETHODIMP
 InterceptedJARChannel::GetChannel(nsIChannel** aChannel)
 {
   NS_IF_ADDREF(*aChannel = mChannel);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-InterceptedJARChannel::GetSecureUpgradedChannelURI(nsIURI** aURI)
-{
-  return mChannel->GetURI(aURI);
-}
-
-NS_IMETHODIMP
 InterceptedJARChannel::ResetInterception()
 {
   if (!mChannel) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   mResponseBody = nullptr;
   mSynthesizedInput = nullptr;
--- a/netwerk/base/nsINetworkInterceptController.idl
+++ b/netwerk/base/nsINetworkInterceptController.idl
@@ -24,17 +24,17 @@ class ChannelInfo;
 
 /**
  * Interface to allow implementors of nsINetworkInterceptController to control the behaviour
  * of intercepted channels without tying implementation details of the interception to
  * the actual channel. nsIInterceptedChannel is expected to be implemented by objects
  * which do not implement nsIChannel.
  */
 
-[scriptable, uuid(f4b82975-6a86-4cc4-87fe-9a1fd430c86d)]
+[scriptable, uuid(64439e24-eda5-4f39-9a7e-162c4b5e0150)]
 interface nsIInterceptedChannel : nsISupports
 {
     /**
      * Instruct a channel that has been intercepted to continue with the original
      * network request.
      */
     void resetInterception();
 
@@ -72,22 +72,16 @@ interface nsIInterceptedChannel : nsISup
     readonly attribute nsIOutputStream responseBody;
 
     /**
      * The underlying channel object that was intercepted.
      */
     readonly attribute nsIChannel channel;
 
     /**
-     * The URL of the underlying channel object, corrected for a potential
-     * secure upgrade.
-     */
-    readonly attribute nsIURI secureUpgradedChannelURI;
-
-    /**
      * This method allows to override the channel info for the channel.
      */
     [noscript]
     void setChannelInfo(in ChannelInfo channelInfo);
 
     /**
      * Get the internal load type from the underlying channel.
      */
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1,17 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim:set ts=4 sw=4 sts=4 et cin: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-// HttpLog.h should generally be included first
-#include "HttpLog.h"
-
 #include "mozilla/LoadContext.h"
 #include "mozilla/LoadInfo.h"
 #include "mozilla/BasePrincipal.h"
 #include "nsNetUtil.h"
 #include "nsNetUtil.inl"
 #include "mozIApplicationClearPrivateDataParams.h"
 #include "nsCategoryCache.h"
 #include "nsContentUtils.h"
@@ -56,20 +53,16 @@
 #include "nsIUnicharStreamLoader.h"
 #include "nsIURIWithPrincipal.h"
 #include "nsIURLParser.h"
 #include "nsIUUIDGenerator.h"
 #include "nsIViewSourceChannel.h"
 #include "nsInterfaceRequestorAgg.h"
 #include "plstr.h"
 #include "nsINestedURI.h"
-#include "mozilla/dom/nsCSPUtils.h"
-#include "nsIScriptError.h"
-#include "nsISiteSecurityService.h"
-#include "nsHttpHandler.h"
 
 #ifdef MOZ_WIDGET_GONK
 #include "nsINetworkManager.h"
 #include "nsThreadUtils.h" // for NS_IsMainThread
 #endif
 
 #include <limits>
 
@@ -2227,110 +2220,16 @@ NS_IsSrcdocChannel(nsIChannel *aChannel)
   nsCOMPtr<nsIViewSourceChannel> vsc = do_QueryInterface(aChannel);
   if (vsc) {
     vsc->GetIsSrcdocChannel(&isSrcdoc);
     return isSrcdoc;
   }
   return false;
 }
 
-nsresult
-NS_ShouldSecureUpgrade(nsIURI* aURI,
-                       nsILoadInfo* aLoadInfo,
-                       nsIPrincipal* aChannelResultPrincipal,
-                       bool aPrivateBrowsing,
-                       bool aAllowSTS,
-                       bool& aShouldUpgrade)
-{
-  // Even if we're in private browsing mode, we still enforce existing STS
-  // data (it is read-only).
-  // if the connection is not using SSL and either the exact host matches or
-  // a superdomain wants to force HTTPS, do it.
-  bool isHttps = false;
-  nsresult rv = aURI->SchemeIs("https", &isHttps);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!isHttps) {
-    // If any of the documents up the chain to the root doucment makes use of
-    // the CSP directive 'upgrade-insecure-requests', then it's time to fulfill
-    // the promise to CSP and mixed content blocking to upgrade the channel
-    // from http to https.
-    if (aLoadInfo) {
-      bool isPreload = nsContentUtils::IsPreloadType(aLoadInfo->InternalContentPolicyType());
-      bool upgradeRequests =
-        ((isPreload && aLoadInfo->GetUpgradeInsecurePreloads()) ||
-         (aLoadInfo->GetUpgradeInsecureRequests()));
-
-      // Please note that cross origin top level navigations are not subject
-      // to upgrade-insecure-requests, see:
-      // http://www.w3.org/TR/upgrade-insecure-requests/#examples
-      bool crossOriginNavigation =
-        (aLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) &&
-        (!aChannelResultPrincipal->Equals(aLoadInfo->LoadingPrincipal()));
-
-      if (upgradeRequests && !crossOriginNavigation) {
-        // let's log a message to the console that we are upgrading a request
-        nsAutoCString spec, scheme;
-        aURI->GetSpec(spec);
-        aURI->GetScheme(scheme);
-        // append the additional 's' for security to the scheme :-)
-        scheme.AppendASCII("s");
-        NS_ConvertUTF8toUTF16 reportSpec(spec);
-        NS_ConvertUTF8toUTF16 reportScheme(scheme);
-
-        const char16_t* params[] = { reportSpec.get(), reportScheme.get() };
-        uint32_t innerWindowId = aLoadInfo->GetInnerWindowID();
-        CSP_LogLocalizedStr(MOZ_UTF16("upgradeInsecureRequest"),
-                            params, ArrayLength(params),
-                            EmptyString(), // aSourceFile
-                            EmptyString(), // aScriptSample
-                            0, // aLineNumber
-                            0, // aColumnNumber
-                            nsIScriptError::warningFlag, "CSP",
-                            innerWindowId);
-
-        Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 4);
-        aShouldUpgrade = true;
-        return NS_OK;
-      }
-    }
-
-    // enforce Strict-Transport-Security
-    nsISiteSecurityService* sss = gHttpHandler->GetSSService();
-    NS_ENSURE_TRUE(sss, NS_ERROR_OUT_OF_MEMORY);
-
-    bool isStsHost = false;
-    uint32_t flags = aPrivateBrowsing ? nsISocketProvider::NO_PERMANENT_STORAGE : 0;
-    rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS, aURI, flags,
-                          &isStsHost);
-
-    // if the SSS check fails, it's likely because this load is on a
-    // malformed URI or something else in the setup is wrong, so any error
-    // should be reported.
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (isStsHost) {
-      LOG(("nsHttpChannel::Connect() STS permissions found\n"));
-      if (aAllowSTS) {
-        Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 3);
-        aShouldUpgrade = true;
-        return NS_OK;
-      } else {
-        Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 2);
-      }
-    } else {
-      Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 1);
-    }
-  } else {
-    Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 0);
-  }
-  aShouldUpgrade = false;
-  return NS_OK;
-}
-
 namespace mozilla {
 namespace net {
 
 bool
 InScriptableRange(int64_t val)
 {
     return (val <= kJS_MAX_SAFE_INTEGER) && (val >= kJS_MIN_SAFE_INTEGER);
 }
--- a/netwerk/base/nsNetUtil.h
+++ b/netwerk/base/nsNetUtil.h
@@ -974,26 +974,16 @@ bool NS_IsSrcdocChannel(nsIChannel *aCha
 bool NS_IsReasonableHTTPHeaderValue(const nsACString &aValue);
 
 /**
  * Return true if the given string is a valid HTTP token per RFC 2616 section
  * 2.2.
  */
 bool NS_IsValidHTTPToken(const nsACString &aToken);
 
-/**
- * Return true if the given request must be upgraded to HTTPS.
- */
-nsresult NS_ShouldSecureUpgrade(nsIURI* aURI,
-                                nsILoadInfo* aLoadInfo,
-                                nsIPrincipal* aChannelResultPrincipal,
-                                bool aPrivateBrowsing,
-                                bool aAllowSTS,
-                                bool& aShouldUpgrade);
-
 namespace mozilla {
 namespace net {
 
 const static uint64_t kJS_MAX_SAFE_UINTEGER = +9007199254740991ULL;
 const static  int64_t kJS_MIN_SAFE_INTEGER  = -9007199254740991LL;
 const static  int64_t kJS_MAX_SAFE_INTEGER  = +9007199254740991LL;
 
 // Make sure a 64bit value can be captured by JS MAX_SAFE_INTEGER
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -2440,23 +2440,23 @@ HttpBaseChannel::IsNavigation()
 
 bool
 HttpBaseChannel::BypassServiceWorker() const
 {
   return mLoadFlags & LOAD_BYPASS_SERVICE_WORKER;
 }
 
 bool
-HttpBaseChannel::ShouldIntercept(nsIURI* aURI)
+HttpBaseChannel::ShouldIntercept()
 {
   nsCOMPtr<nsINetworkInterceptController> controller;
   GetCallback(controller);
   bool shouldIntercept = false;
   if (controller && !BypassServiceWorker() && mLoadInfo) {
-    nsresult rv = controller->ShouldPrepareForIntercept(aURI ? aURI : mURI.get(),
+    nsresult rv = controller->ShouldPrepareForIntercept(mURI,
                                                         nsContentUtils::IsNonSubresourceRequest(this),
                                                         &shouldIntercept);
     if (NS_FAILED(rv)) {
       return false;
     }
   }
   return shouldIntercept;
 }
@@ -3148,39 +3148,10 @@ void
 HttpBaseChannel::SetCorsPreflightParameters(const nsTArray<nsCString>& aUnsafeHeaders)
 {
   MOZ_RELEASE_ASSERT(!mRequestObserversCalled);
 
   mRequireCORSPreflight = true;
   mUnsafeHeaders = aUnsafeHeaders;
 }
 
-// static
-nsresult
-HttpBaseChannel::GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI)
-{
-  nsCOMPtr<nsIURI> upgradedURI;
-
-  nsresult rv = aURI->Clone(getter_AddRefs(upgradedURI));
-  NS_ENSURE_SUCCESS(rv,rv);
-
-  upgradedURI->SetScheme(NS_LITERAL_CSTRING("https"));
-
-  int32_t oldPort = -1;
-  rv = aURI->GetPort(&oldPort);
-  if (NS_FAILED(rv)) return rv;
-
-  // Keep any nonstandard ports so only the scheme is changed.
-  // For example:
-  //  http://foo.com:80 -> https://foo.com:443
-  //  http://foo.com:81 -> https://foo.com:81
-
-  if (oldPort == 80 || oldPort == -1)
-      upgradedURI->SetPort(-1);
-  else
-      upgradedURI->SetPort(oldPort);
-
-  upgradedURI.forget(aUpgradedURI);
-  return NS_OK;
-}
-
 } // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/http/HttpBaseChannel.h
+++ b/netwerk/protocol/http/HttpBaseChannel.h
@@ -294,20 +294,16 @@ public: /* Necko internal use only... */
     // mListenerContext.
     nsresult DoApplyContentConversions(nsIStreamListener *aNextListener,
                                        nsIStreamListener **aNewNextListener);
 
     // Callback on main thread when NS_AsyncCopy() is finished populating
     // the new mUploadStream.
     void EnsureUploadStreamIsCloneableComplete(nsresult aStatus);
 
-    // Returns an https URI for channels that need to go through secure
-    // upgrades.
-    static nsresult GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI);
-
 protected:
   nsCOMArray<nsISecurityConsoleMessage> mSecurityConsoleMessages;
 
   // Handle notifying listener, removing from loadgroup if request failed.
   void     DoNotifyListener();
   virtual void DoNotifyListenerCleanup() = 0;
 
   // drop reference to listener, its callbacks, and the progress sink
@@ -342,17 +338,17 @@ protected:
 
   // GetPrincipal Returns the channel's URI principal.
   nsIPrincipal *GetURIPrincipal();
 
   bool BypassServiceWorker() const;
 
   // Returns true if this channel should intercept the network request and prepare
   // for a possible synthesized response instead.
-  bool ShouldIntercept(nsIURI* aURI = nullptr);
+  bool ShouldIntercept();
 
   friend class PrivateBrowsingChannel<HttpBaseChannel>;
   friend class InterceptFailedOnStop;
 
   nsCOMPtr<nsIURI>                  mURI;
   nsCOMPtr<nsIURI>                  mOriginalURI;
   nsCOMPtr<nsIURI>                  mDocumentURI;
   nsCOMPtr<nsIStreamListener>       mListener;
--- a/netwerk/protocol/http/HttpChannelChild.cpp
+++ b/netwerk/protocol/http/HttpChannelChild.cpp
@@ -1808,50 +1808,26 @@ HttpChannelChild::AsyncOpen(nsIStreamLis
     // connection. See nsHttpChannel::AsyncOpen().
     AsyncAbort(mStatus);
     return NS_OK;
   }
 
   // Set user agent override
   HttpBaseChannel::SetDocshellUserAgentOverride();
 
-  bool isHttps = false;
-  rv = mURI->SchemeIs("https", &isHttps);
-  NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIPrincipal> resultPrincipal;
-  if (!isHttps && mLoadInfo) {
-      nsContentUtils::GetSecurityManager()->
-        GetChannelResultPrincipal(this, getter_AddRefs(resultPrincipal));
-  }
-  bool shouldUpgrade = false;
-  rv = NS_ShouldSecureUpgrade(mURI,
-                              mLoadInfo,
-                              resultPrincipal,
-                              mPrivateBrowsing,
-                              mAllowSTS,
-                              shouldUpgrade);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIURI> upgradedURI;
-  if (shouldUpgrade) {
-    rv = GetSecureUpgradedURI(mURI, getter_AddRefs(upgradedURI));
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-
-  if (ShouldIntercept(upgradedURI)) {
+  if (ShouldIntercept()) {
     mResponseCouldBeSynthesized = true;
 
     nsCOMPtr<nsINetworkInterceptController> controller;
     GetCallback(controller);
 
     mInterceptListener = new InterceptStreamListener(this, mListenerContext);
 
     RefPtr<InterceptedChannelContent> intercepted =
-        new InterceptedChannelContent(this, controller,
-                                      mInterceptListener, shouldUpgrade);
+        new InterceptedChannelContent(this, controller, mInterceptListener);
     intercepted->NotifyController();
     return NS_OK;
   }
 
   return ContinueAsyncOpen();
 }
 
 NS_IMETHODIMP
--- a/netwerk/protocol/http/InterceptedChannel.cpp
+++ b/netwerk/protocol/http/InterceptedChannel.cpp
@@ -130,31 +130,16 @@ InterceptedChannelBase::SetReleaseHandle
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(!mReleaseHandle);
   MOZ_ASSERT(aHandle);
   mReleaseHandle = aHandle;
   return NS_OK;
 }
 
-/* static */
-already_AddRefed<nsIURI>
-InterceptedChannelBase::SecureUpgradeChannelURI(nsIChannel* aChannel)
-{
-  nsCOMPtr<nsIURI> uri;
-  nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
-  NS_ENSURE_SUCCESS(rv, nullptr);
-
-  nsCOMPtr<nsIURI> upgradedURI;
-  rv = HttpBaseChannel::GetSecureUpgradedURI(uri, getter_AddRefs(upgradedURI));
-  NS_ENSURE_SUCCESS(rv, nullptr);
-
-  return upgradedURI.forget();
-}
-
 InterceptedChannelChrome::InterceptedChannelChrome(nsHttpChannel* aChannel,
                                                    nsINetworkInterceptController* aController,
                                                    nsICacheEntry* aEntry)
 : InterceptedChannelBase(aController)
 , mChannel(aChannel)
 , mSynthesizedCacheEntry(aEntry)
 {
   nsresult rv = mChannel->GetApplyConversion(&mOldApplyConversion);
@@ -339,30 +324,22 @@ InterceptedChannelChrome::GetInternalCon
   nsCOMPtr<nsILoadInfo> loadInfo;
   nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
   NS_ENSURE_SUCCESS(rv, rv);
 
   *aPolicyType = loadInfo->InternalContentPolicyType();
   return NS_OK;
 }
 
-NS_IMETHODIMP
-InterceptedChannelChrome::GetSecureUpgradedChannelURI(nsIURI** aURI)
-{
-  return mChannel->GetURI(aURI);
-}
-
 InterceptedChannelContent::InterceptedChannelContent(HttpChannelChild* aChannel,
                                                      nsINetworkInterceptController* aController,
-                                                     InterceptStreamListener* aListener,
-                                                     bool aSecureUpgrade)
+                                                     InterceptStreamListener* aListener)
 : InterceptedChannelBase(aController)
 , mChannel(aChannel)
 , mStreamListener(aListener)
-, mSecureUpgrade(aSecureUpgrade)
 {
 }
 
 void
 InterceptedChannelContent::NotifyController()
 {
   nsresult rv = NS_NewPipe(getter_AddRefs(mSynthesizedInput),
                            getter_AddRefs(mResponseBody),
@@ -430,20 +407,16 @@ InterceptedChannelContent::FinishSynthes
 
   nsCOMPtr<nsIURI> originalURI;
   mChannel->GetURI(getter_AddRefs(originalURI));
 
   nsCOMPtr<nsIURI> responseURI;
   if (!aFinalURLSpec.IsEmpty()) {
     nsresult rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec);
     NS_ENSURE_SUCCESS(rv, rv);
-  } else if (mSecureUpgrade) {
-    nsresult rv = HttpBaseChannel::GetSecureUpgradedURI(originalURI,
-                                                        getter_AddRefs(responseURI));
-    NS_ENSURE_SUCCESS(rv, rv);
   } else {
     responseURI = originalURI;
   }
 
   bool equal = false;
   originalURI->Equals(responseURI, &equal);
   if (!equal) {
     mChannel->ForceIntercepted(mSynthesizedInput);
@@ -500,27 +473,10 @@ InterceptedChannelContent::GetInternalCo
   nsCOMPtr<nsILoadInfo> loadInfo;
   nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo));
   NS_ENSURE_SUCCESS(rv, rv);
 
   *aPolicyType = loadInfo->InternalContentPolicyType();
   return NS_OK;
 }
 
-NS_IMETHODIMP
-InterceptedChannelContent::GetSecureUpgradedChannelURI(nsIURI** aURI)
-{
-  nsCOMPtr<nsIURI> uri;
-  if (mSecureUpgrade) {
-    uri = SecureUpgradeChannelURI(mChannel);
-  } else {
-    nsresult rv = mChannel->GetURI(getter_AddRefs(uri));
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-  if (uri) {
-    uri.forget(aURI);
-    return NS_OK;
-  }
-  return NS_ERROR_FAILURE;
-}
-
 } // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/http/InterceptedChannel.h
+++ b/netwerk/protocol/http/InterceptedChannel.h
@@ -52,19 +52,16 @@ public:
   // and prepare the response body output stream.
   virtual void NotifyController() = 0;
 
   NS_DECL_ISUPPORTS
 
   NS_IMETHOD GetResponseBody(nsIOutputStream** aOutput) override;
   NS_IMETHOD GetConsoleReportCollector(nsIConsoleReportCollector** aCollectorOut) override;
   NS_IMETHOD SetReleaseHandle(nsISupports* aHandle) override;
-
-  static already_AddRefed<nsIURI>
-  SecureUpgradeChannelURI(nsIChannel* aChannel);
 };
 
 class InterceptedChannelChrome : public InterceptedChannelBase
 {
   // The actual channel being intercepted.
   RefPtr<nsHttpChannel> mChannel;
 
   // Writeable cache entry for use when synthesizing a response in a parent process
@@ -78,17 +75,16 @@ class InterceptedChannelChrome : public 
 public:
   InterceptedChannelChrome(nsHttpChannel* aChannel,
                            nsINetworkInterceptController* aController,
                            nsICacheEntry* aEntry);
 
   NS_IMETHOD ResetInterception() override;
   NS_IMETHOD FinishSynthesizedResponse(const nsACString& aFinalURLSpec) override;
   NS_IMETHOD GetChannel(nsIChannel** aChannel) override;
-  NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override;
   NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override;
   NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override;
   NS_IMETHOD Cancel(nsresult aStatus) override;
   NS_IMETHOD SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo) override;
   NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override;
 
   virtual void NotifyController() override;
 };
@@ -99,29 +95,24 @@ class InterceptedChannelContent : public
   RefPtr<HttpChannelChild> mChannel;
 
   // Reader-side of the response body when synthesizing in a child proces
   nsCOMPtr<nsIInputStream> mSynthesizedInput;
 
   // Listener for the synthesized response to fix up the notifications before they reach
   // the actual channel.
   RefPtr<InterceptStreamListener> mStreamListener;
-
-  // Set for intercepted channels that have gone through a secure upgrade.
-  bool mSecureUpgrade;
 public:
   InterceptedChannelContent(HttpChannelChild* aChannel,
                             nsINetworkInterceptController* aController,
-                            InterceptStreamListener* aListener,
-                            bool aSecureUpgrade);
+                            InterceptStreamListener* aListener);
 
   NS_IMETHOD ResetInterception() override;
   NS_IMETHOD FinishSynthesizedResponse(const nsACString& aFinalURLSpec) override;
   NS_IMETHOD GetChannel(nsIChannel** aChannel) override;
-  NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override;
   NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override;
   NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override;
   NS_IMETHOD Cancel(nsresult aStatus) override;
   NS_IMETHOD SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo) override;
   NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override;
 
   virtual void NotifyController() override;
 };
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -2,16 +2,17 @@
 /* vim:set expandtab ts=4 sw=4 sts=4 cin: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // HttpLog.h should generally be included first
 #include "HttpLog.h"
 
+#include "mozilla/dom/nsCSPUtils.h"
 #include "mozilla/dom/nsCSPContext.h"
 #include "nsHttp.h"
 #include "nsHttpChannel.h"
 #include "nsHttpHandler.h"
 #include "nsIApplicationCacheService.h"
 #include "nsIApplicationCacheContainer.h"
 #include "nsICacheStorageService.h"
 #include "nsICacheStorage.h"
@@ -50,16 +51,17 @@
 #include "mozilla/Preferences.h"
 #include "nsISSLSocketControl.h"
 #include "sslt.h"
 #include "nsContentUtils.h"
 #include "nsContentSecurityManager.h"
 #include "nsIClassOfService.h"
 #include "nsIPermissionManager.h"
 #include "nsIPrincipal.h"
+#include "nsIScriptError.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsISSLStatus.h"
 #include "nsISSLStatusProvider.h"
 #include "nsITransportSecurityInfo.h"
 #include "nsIWebProgressListener.h"
 #include "LoadContextInfo.h"
 #include "netCore.h"
 #include "nsHttpTransaction.h"
@@ -305,34 +307,98 @@ nsHttpChannel::AddSecurityMessage(const 
 
 nsresult
 nsHttpChannel::Connect()
 {
     nsresult rv;
 
     LOG(("nsHttpChannel::Connect [this=%p]\n", this));
 
+    // Even if we're in private browsing mode, we still enforce existing STS
+    // data (it is read-only).
+    // if the connection is not using SSL and either the exact host matches or
+    // a superdomain wants to force HTTPS, do it.
     bool isHttps = false;
     rv = mURI->SchemeIs("https", &isHttps);
     NS_ENSURE_SUCCESS(rv,rv);
-    nsCOMPtr<nsIPrincipal> resultPrincipal;
-    if (!isHttps && mLoadInfo) {
-        nsContentUtils::GetSecurityManager()->
-          GetChannelResultPrincipal(this, getter_AddRefs(resultPrincipal));
-    }
-    bool shouldUpgrade = false;
-    rv = NS_ShouldSecureUpgrade(mURI,
-                                mLoadInfo,
-                                resultPrincipal,
-                                mPrivateBrowsing,
-                                mAllowSTS,
-                                shouldUpgrade);
-    NS_ENSURE_SUCCESS(rv, rv);
-    if (shouldUpgrade) {
-        return AsyncCall(&nsHttpChannel::HandleAsyncRedirectChannelToHttps);
+
+    if (!isHttps) {
+        // If any of the documents up the chain to the root doucment makes use of
+        // the CSP directive 'upgrade-insecure-requests', then it's time to fulfill
+        // the promise to CSP and mixed content blocking to upgrade the channel
+        // from http to https.
+        if (mLoadInfo) {
+            bool isPreload = nsContentUtils::IsPreloadType(mLoadInfo->InternalContentPolicyType());
+            bool upgradeRequests =
+              ((isPreload && mLoadInfo->GetUpgradeInsecurePreloads()) ||
+               (mLoadInfo->GetUpgradeInsecureRequests()));
+
+            // Please note that cross origin top level navigations are not subject
+            // to upgrade-insecure-requests, see:
+            // http://www.w3.org/TR/upgrade-insecure-requests/#examples
+            nsCOMPtr<nsIPrincipal> resultPrincipal;
+            nsContentUtils::GetSecurityManager()->
+                GetChannelResultPrincipal(this, getter_AddRefs(resultPrincipal));
+            bool crossOriginNavigation =
+                (mLoadInfo->GetExternalContentPolicyType() == nsIContentPolicy::TYPE_DOCUMENT) &&
+                (!resultPrincipal->Equals(mLoadInfo->LoadingPrincipal()));
+
+            if (upgradeRequests && !crossOriginNavigation) {
+                // let's log a message to the console that we are upgrading a request
+                nsAutoCString spec, scheme;
+                mURI->GetSpec(spec);
+                mURI->GetScheme(scheme);
+                // append the additional 's' for security to the scheme :-)
+                scheme.AppendASCII("s");
+                NS_ConvertUTF8toUTF16 reportSpec(spec);
+                NS_ConvertUTF8toUTF16 reportScheme(scheme);
+
+                const char16_t* params[] = { reportSpec.get(), reportScheme.get() };
+                uint32_t innerWindowId = mLoadInfo ? mLoadInfo->GetInnerWindowID() : 0;
+                CSP_LogLocalizedStr(MOZ_UTF16("upgradeInsecureRequest"),
+                                    params, ArrayLength(params),
+                                    EmptyString(), // aSourceFile
+                                    EmptyString(), // aScriptSample
+                                    0, // aLineNumber
+                                    0, // aColumnNumber
+                                    nsIScriptError::warningFlag, "CSP",
+                                    innerWindowId);
+
+                Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 4);
+                return AsyncCall(&nsHttpChannel::HandleAsyncRedirectChannelToHttps);
+            }
+        }
+
+        // enforce Strict-Transport-Security
+        nsISiteSecurityService* sss = gHttpHandler->GetSSService();
+        NS_ENSURE_TRUE(sss, NS_ERROR_OUT_OF_MEMORY);
+
+        bool isStsHost = false;
+        uint32_t flags = mPrivateBrowsing ? nsISocketProvider::NO_PERMANENT_STORAGE : 0;
+        rv = sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS, mURI, flags,
+                              &isStsHost);
+
+        // if the SSS check fails, it's likely because this load is on a
+        // malformed URI or something else in the setup is wrong, so any error
+        // should be reported.
+        NS_ENSURE_SUCCESS(rv, rv);
+
+        if (isStsHost) {
+            LOG(("nsHttpChannel::Connect() STS permissions found\n"));
+            if (mAllowSTS) {
+                Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 3);
+                return AsyncCall(&nsHttpChannel::HandleAsyncRedirectChannelToHttps);
+            } else {
+                Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 2);
+            }
+        } else {
+            Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 1);
+        }
+    } else {
+        Telemetry::Accumulate(Telemetry::HTTP_SCHEME_UPGRADE, 0);
     }
 
     // ensure that we are using a valid hostname
     if (!net_IsValidHostName(nsDependentCString(mConnectionInfo->Origin())))
         return NS_ERROR_UNKNOWN_HOST;
 
     // Finalize ConnectionInfo flags before SpeculativeConnect
     mConnectionInfo->SetAnonymous((mLoadFlags & LOAD_ANONYMOUS) != 0);
@@ -1865,22 +1931,40 @@ nsHttpChannel::HandleAsyncRedirectChanne
     nsresult rv = StartRedirectChannelToHttps();
     if (NS_FAILED(rv))
         ContinueAsyncRedirectChannelToURI(rv);
 }
 
 nsresult
 nsHttpChannel::StartRedirectChannelToHttps()
 {
+    nsresult rv = NS_OK;
     LOG(("nsHttpChannel::HandleAsyncRedirectChannelToHttps() [STS]\n"));
 
     nsCOMPtr<nsIURI> upgradedURI;
-    nsresult rv = GetSecureUpgradedURI(mURI, getter_AddRefs(upgradedURI));
+
+    rv = mURI->Clone(getter_AddRefs(upgradedURI));
     NS_ENSURE_SUCCESS(rv,rv);
 
+    upgradedURI->SetScheme(NS_LITERAL_CSTRING("https"));
+
+    int32_t oldPort = -1;
+    rv = mURI->GetPort(&oldPort);
+    if (NS_FAILED(rv)) return rv;
+
+    // Keep any nonstandard ports so only the scheme is changed.
+    // For example:
+    //  http://foo.com:80 -> https://foo.com:443
+    //  http://foo.com:81 -> https://foo.com:81
+
+    if (oldPort == 80 || oldPort == -1)
+        upgradedURI->SetPort(-1);
+    else
+        upgradedURI->SetPort(oldPort);
+
     return StartRedirectChannelToURI(upgradedURI,
                                      nsIChannelEventSink::REDIRECT_PERMANENT |
                                      nsIChannelEventSink::REDIRECT_STS_UPGRADE);
 }
 
 void
 nsHttpChannel::HandleAsyncAPIRedirect()
 {