Skip to content
Permalink
Browse files

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.
  • Loading branch information...
rmottola committed Jul 2, 2019
1 parent 0e1769b commit 8dc3328cb08e10b632d60c25a63b49ed7182d5a7
Showing with 23 additions and 7 deletions.
  1. +23 −5 docshell/base/nsDocShell.cpp
  2. +0 −2 dom/workers/test/serviceworkers/fetch/context/index.html
@@ -446,13 +446,19 @@ class nsPingListener final

nsresult StartTimeout();

void SetInterceptController(nsINetworkInterceptController* aInterceptController)
{
mInterceptController = aInterceptController;
}

private:
~nsPingListener();

bool mRequireSameHost;
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);
}
@@ -13696,7 +13714,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;
}
@@ -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";

0 comments on commit 8dc3328

Please sign in to comment.
You can’t perform that action at this time.