Bug 1148064 - Enable interception of pings through service workers; r=nsm,smaug

Currently when sending a beacon, HttpBaseChannel::ShouldIntercept tries
to get access to the nsINetworkInterceptController interface through the
channel's notification callbacks, but in this case the notification
callback is the nsPingListener object.

This patch extends nsPingListener to make it aware of
nsINetworkInterceptController, and have it route the request for
nsINetworkInterceptController correctly to the docshell without the need
to mess with the notification callbacks.

This will be tested in bug 1147699.
This commit is contained in:
Ehsan Akhgari 2015-03-26 15:57:46 -04:00
parent 65ddce3ade
commit 29cd945f5d
2 changed files with 23 additions and 7 deletions

View File

@ -446,6 +446,11 @@ public:
nsresult StartTimeout();
void SetInterceptController(nsINetworkInterceptController* aInterceptController)
{
mInterceptController = aInterceptController;
}
private:
~nsPingListener();
@ -453,6 +458,7 @@ private:
nsCOMPtr<nsIContent> mContent;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsINetworkInterceptController> mInterceptController;
};
NS_IMPL_ISUPPORTS(nsPingListener, nsIStreamListener, nsIRequestObserver,
@ -517,8 +523,15 @@ NS_IMETHODIMP
nsPingListener::GetInterface(const nsIID& aIID, void** aResult)
{
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
NS_ADDREF_THIS();
*aResult = (nsIChannelEventSink*)this;
nsCOMPtr<nsIChannelEventSink> copy(this);
*aResult = copy.forget().take();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsINetworkInterceptController)) &&
mInterceptController) {
nsCOMPtr<nsINetworkInterceptController> copy(mInterceptController);
*aResult = copy.forget().take();
return NS_OK;
}
@ -557,13 +570,14 @@ nsPingListener::AsyncOnChannelRedirect(nsIChannel* aOldChan,
return NS_OK;
}
struct SendPingInfo
struct MOZ_STACK_CLASS SendPingInfo
{
int32_t numPings;
int32_t maxPings;
bool requireSameHost;
nsIURI* target;
nsIURI* referrer;
nsIDocShell* docShell;
uint32_t referrerPolicy;
};
@ -697,6 +711,8 @@ SendPing(void* aClosure, nsIContent* aContent, nsIURI* aURI,
nsPingListener* pingListener =
new nsPingListener(info->requireSameHost, aContent, loadGroup);
nsCOMPtr<nsINetworkInterceptController> interceptController = do_QueryInterface(info->docShell);
pingListener->SetInterceptController(interceptController);
nsCOMPtr<nsIStreamListener> listener(pingListener);
// Observe redirects as well:
@ -721,7 +737,8 @@ SendPing(void* aClosure, nsIContent* aContent, nsIURI* aURI,
// Spec: http://whatwg.org/specs/web-apps/current-work/#ping
static void
DispatchPings(nsIContent* aContent,
DispatchPings(nsIDocShell* aDocShell,
nsIContent* aContent,
nsIURI* aTarget,
nsIURI* aReferrer,
uint32_t aReferrerPolicy)
@ -739,6 +756,7 @@ DispatchPings(nsIContent* aContent,
info.target = aTarget;
info.referrer = aReferrer;
info.referrerPolicy = aReferrerPolicy;
info.docShell = aDocShell;
ForEachPing(aContent, SendPing, &info);
}
@ -13522,7 +13540,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent,
aDocShell, // DocShell out-param
aRequest); // Request out-param
if (NS_SUCCEEDED(rv)) {
DispatchPings(aContent, aURI, referer, refererPolicy);
DispatchPings(this, aContent, aURI, referer, refererPolicy);
}
return rv;
}

View File

@ -208,8 +208,6 @@
}
function testPing() {
// FIXME: Temporarily disabled until bug 1148064 gets fixed.
return Promise.resolve();
return new Promise(function(resolve, reject) {
var iframe = document.createElement("iframe");
iframe.src = "ping.html";