diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index a701b14141b6..ddc13df268e2 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -2712,6 +2712,27 @@ NS_IsOffline() return offline || !connectivity; } +nsresult +NS_NotifyCurrentTopLevelOuterContentWindowId(uint64_t aWindowId) +{ + nsCOMPtr obs = + do_GetService("@mozilla.org/observer-service;1"); + if (!obs) { + return NS_ERROR_FAILURE; + } + + nsCOMPtr 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 { diff --git a/netwerk/base/nsNetUtil.h b/netwerk/base/nsNetUtil.h index d7d54b6d9d08..9c562debf36e 100644 --- a/netwerk/base/nsNetUtil.h +++ b/netwerk/base/nsNetUtil.h @@ -943,6 +943,11 @@ nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel); */ 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 { diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index de1596d9405e..b9aabe3fd05e 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -45,6 +45,7 @@ #include "nsINetworkPredictorVerifier.h" #include "nsISpeculativeConnect.h" #include "nsIThrottlingService.h" +#include "nsNetUtil.h" using mozilla::OriginAttributes; using mozilla::dom::ChromeUtils; @@ -914,5 +915,15 @@ NeckoParent::RecvDecreaseThrottlePressure() 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 diff --git a/netwerk/ipc/NeckoParent.h b/netwerk/ipc/NeckoParent.h index c3dd6ce2a24d..75df81d9e0cc 100644 --- a/netwerk/ipc/NeckoParent.h +++ b/netwerk/ipc/NeckoParent.h @@ -229,6 +229,8 @@ protected: virtual mozilla::ipc::IPCResult RecvIncreaseThrottlePressure() override; virtual mozilla::ipc::IPCResult RecvDecreaseThrottlePressure() override; + virtual mozilla::ipc::IPCResult + RecvNotifyCurrentTopLevelOuterContentWindowId(const uint64_t& aWindowId) override; private: nsTArray> mThrottlers; }; diff --git a/netwerk/ipc/PNecko.ipdl b/netwerk/ipc/PNecko.ipdl index 830842aae2de..4583febf598b 100644 --- a/netwerk/ipc/PNecko.ipdl +++ b/netwerk/ipc/PNecko.ipdl @@ -123,6 +123,8 @@ parent: async IncreaseThrottlePressure(); async DecreaseThrottlePressure(); + prio(high) async NotifyCurrentTopLevelOuterContentWindowId(uint64_t windowId); + child: /* * Bring up the http auth prompt for a nested remote mozbrowser. diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index f833109483fa..9f9116da3aa7 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -53,6 +53,7 @@ #include "nsIOService.h" #include "nsIUUIDGenerator.h" #include "nsIThrottlingService.h" +#include "nsISupportsPrimitives.h" #include "mozilla/net/NeckoChild.h" #include "mozilla/net/NeckoParent.h" @@ -385,6 +386,9 @@ nsHttpHandler::Init() 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); @@ -2126,6 +2130,29 @@ nsHttpHandler::Observe(nsISupports *subject, static_cast(rv))); } } + } else if (!strcmp(topic, "net:current-toplevel-outer-content-windowid")) { + nsCOMPtr 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;