Bug 1309653 - Part1: Add new API for updating current top level outer content windowId - v2, r=honzab

--HG--
extra : rebase_source : a7a9797ad94d66e9ecb9b13a6d7103c0af2303ff
This commit is contained in:
Kershaw Chang 2017-03-10 01:32:00 +01:00
parent 4d87f0665b
commit 3310ba5db8
6 changed files with 68 additions and 0 deletions

View File

@ -2712,6 +2712,27 @@ NS_IsOffline()
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 {

View File

@ -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 {

View File

@ -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

View File

@ -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<mozilla::UniquePtr<mozilla::net::Throttler>> mThrottlers;
};

View File

@ -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.

View File

@ -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<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;