Bug 1309653 - Part1: Add new API for updating current top level outer content windowId - v2, r=honzab
authorKershaw Chang <kechang@mozilla.com>
Fri, 10 Mar 2017 01:32:00 +0100
changeset 347141 200abfdbd8ef47d2f4a0b401437044fc719d1e38
parent 347140 d2620293368cb56446f884124a99686fc72abb3f
child 347142 275de64c0218461b7437e072274afeee79114434
push id31491
push usercbook@mozilla.com
push dateMon, 13 Mar 2017 14:24:00 +0000
treeherdermozilla-central@8d9fd089cabd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1309653
milestone55.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 1309653 - Part1: Add new API for updating current top level outer content windowId - v2, r=honzab
netwerk/base/nsNetUtil.cpp
netwerk/base/nsNetUtil.h
netwerk/ipc/NeckoParent.cpp
netwerk/ipc/NeckoParent.h
netwerk/ipc/PNecko.ipdl
netwerk/protocol/http/nsHttpHandler.cpp
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -2707,16 +2707,37 @@ NS_IsOffline()
     nsCOMPtr<nsIIOService> ios = do_GetIOService();
     if (ios) {
         ios->GetOffline(&offline);
         ios->GetConnectivity(&connectivity);
     }
     return offline || !connectivity;
 }
 
+nsresult
+NS_NotifyCurrentTopLevelOuterContentWindowId(uint64_t aWindowId)
+{
+  nsCOMPtr<nsIObserverService> obs =
+    do_GetService("@mozilla.org/observer-service;1");
+  if (!obs) {
+    return NS_ERROR_FAILURE;
+  }
+
+  nsCOMPtr<nsISupportsPRUint64> wrapper =
+    do_CreateInstance(NS_SUPPORTS_PRUINT64_CONTRACTID);
+  if (!wrapper) {
+    return NS_ERROR_FAILURE;
+  }
+
+  wrapper->SetData(aWindowId);
+  return obs->NotifyObservers(wrapper,
+                              "net:current-toplevel-outer-content-windowid",
+                              nullptr);
+}
+
 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
@@ -938,16 +938,21 @@ nsresult NS_GetSecureUpgradedURI(nsIURI*
 nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel);
 
 /**
  * Return default referrer policy which is controlled by user
  * pref network.http.referer.userControlPolicy
  */
 uint32_t NS_GetDefaultReferrerPolicy();
 
+/**
+ * Update the window id of the current focused top level content window.
+ */
+nsresult NS_NotifyCurrentTopLevelOuterContentWindowId(uint64_t aWindowId);
+
 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/ipc/NeckoParent.cpp
+++ b/netwerk/ipc/NeckoParent.cpp
@@ -40,16 +40,17 @@
 #include "SerializedLoadContext.h"
 #include "nsAuthInformationHolder.h"
 #include "nsIAuthPromptCallback.h"
 #include "nsPrincipal.h"
 #include "nsINetworkPredictor.h"
 #include "nsINetworkPredictorVerifier.h"
 #include "nsISpeculativeConnect.h"
 #include "nsIThrottlingService.h"
+#include "nsNetUtil.h"
 
 using mozilla::OriginAttributes;
 using mozilla::dom::ChromeUtils;
 using mozilla::dom::ContentParent;
 using mozilla::dom::TabContext;
 using mozilla::dom::TabParent;
 using mozilla::net::PTCPSocketParent;
 using mozilla::dom::TCPSocketParent;
@@ -909,10 +910,20 @@ NeckoParent::RecvDecreaseThrottlePressur
 {
   MOZ_ASSERT(!mThrottlers.IsEmpty());
   // We do this because we don't actually care which throttler gets removed,
   // just that one of them does.
   mThrottlers.RemoveElementAt(0);
   return IPC_OK();
 }
 
+mozilla::ipc::IPCResult
+NeckoParent::RecvNotifyCurrentTopLevelOuterContentWindowId(const uint64_t& aWindowId)
+{
+  if (NS_FAILED(NS_NotifyCurrentTopLevelOuterContentWindowId(aWindowId))) {
+    NS_WARNING("NS_NotifyCurrentTopLevelOuterContentWindowId failed!");
+  }
+
+  return IPC_OK();
+}
+
 } // namespace net
 } // namespace mozilla
--- a/netwerk/ipc/NeckoParent.h
+++ b/netwerk/ipc/NeckoParent.h
@@ -224,16 +224,18 @@ protected:
   virtual mozilla::ipc::IPCResult RecvPredReset() override;
 
   virtual mozilla::ipc::IPCResult RecvRemoveRequestContext(const nsCString& rcid) override;
 
   /* Throttler messages */
   virtual mozilla::ipc::IPCResult RecvIncreaseThrottlePressure() override;
   virtual mozilla::ipc::IPCResult RecvDecreaseThrottlePressure() override;
 
+  virtual mozilla::ipc::IPCResult
+  RecvNotifyCurrentTopLevelOuterContentWindowId(const uint64_t& aWindowId) override;
 private:
   nsTArray<mozilla::UniquePtr<mozilla::net::Throttler>> mThrottlers;
 };
 
 } // namespace net
 } // namespace mozilla
 
 #endif // mozilla_net_NeckoParent_h
--- a/netwerk/ipc/PNecko.ipdl
+++ b/netwerk/ipc/PNecko.ipdl
@@ -118,16 +118,18 @@ parent:
   async PAltDataOutputStream(nsCString type, PHttpChannel channel);
 
   /**
    * Throttling of channels
    */
   async IncreaseThrottlePressure();
   async DecreaseThrottlePressure();
 
+  prio(high) async NotifyCurrentTopLevelOuterContentWindowId(uint64_t windowId);
+
 child:
   /*
    * Bring up the http auth prompt for a nested remote mozbrowser.
    * NestedFrameId is the id corresponding to the PBrowser.  It is the same id
    * that was passed to the PBrowserOrId param in to the PHttpChannel constructor
    */
   async AsyncAuthPromptForNestedFrame(TabId nestedFrameId, nsCString uri,
                                       nsString realm, uint64_t callbackId);
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -48,16 +48,17 @@
 #include "nsINetworkLinkService.h"
 #include "nsHttpChannelAuthProvider.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsSocketTransportService2.h"
 #include "nsIOService.h"
 #include "nsIUUIDGenerator.h"
 #include "nsIThrottlingService.h"
+#include "nsISupportsPrimitives.h"
 
 #include "mozilla/net/NeckoChild.h"
 #include "mozilla/net/NeckoParent.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 #include "mozilla/BasePrincipal.h"
 
@@ -380,16 +381,19 @@ nsHttpHandler::Init()
         obsService->AddObserver(this, "net:clear-active-logins", true);
         obsService->AddObserver(this, "net:prune-dead-connections", true);
         // Sent by the TorButton add-on in the Tor Browser
         obsService->AddObserver(this, "net:prune-all-connections", true);
         obsService->AddObserver(this, "last-pb-context-exited", true);
         obsService->AddObserver(this, "browser:purge-session-history", true);
         obsService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
         obsService->AddObserver(this, "application-background", true);
+        obsService->AddObserver(this,
+                                "net:current-toplevel-outer-content-windowid",
+                                true);
 
         // disabled as its a nop right now
         // obsService->AddObserver(this, "net:failed-to-process-uri-content", true);
     }
 
     MakeNewRequestTokenBucket();
     mWifiTickler = new Tickler();
     if (NS_FAILED(mWifiTickler->Init()))
@@ -2121,16 +2125,39 @@ nsHttpHandler::Observe(nsISupports *subj
         // down idle connections for power conservation
         if (mConnMgr) {
             rv = mConnMgr->DoShiftReloadConnectionCleanup(nullptr);
             if (NS_FAILED(rv)) {
                 LOG(("    DoShiftReloadConnectionCleanup failed (%08x)\n",
                      static_cast<uint32_t>(rv)));
             }
         }
+    } else if (!strcmp(topic, "net:current-toplevel-outer-content-windowid")) {
+        nsCOMPtr<nsISupportsPRUint64> wrapper = do_QueryInterface(subject);
+        MOZ_RELEASE_ASSERT(wrapper);
+
+        uint64_t windowId = 0;
+        wrapper->GetData(&windowId);
+        MOZ_ASSERT(windowId);
+
+        if (IsNeckoChild()) {
+            if (gNeckoChild) {
+                gNeckoChild->SendNotifyCurrentTopLevelOuterContentWindowId(
+                    windowId);
+            }
+        } else {
+            static uint64_t sCurrentTopLevelOuterContentWindowId = 0;
+            if (sCurrentTopLevelOuterContentWindowId != windowId) {
+                sCurrentTopLevelOuterContentWindowId = windowId;
+                if (mConnMgr) {
+                    mConnMgr->UpdateCurrentTopLevelOuterContentWindowId(
+                        sCurrentTopLevelOuterContentWindowId);
+                }
+            }
+        }
     }
 
     return NS_OK;
 }
 
 // nsISpeculativeConnect
 
 nsresult