Bug 1360581 - Part3: Add setTopWindowURIIfUnknown in nsIHttpChannelInternal, r=mayhemer

Since the uri classifier needs topWindowURI to decide whether or not to enable channel annotation, we have to allow to change this attribute in js for passing the test.

--HG--
extra : rebase_source : c5effa05fecef0d32600e4c9c926dbfa77c2ca6f
This commit is contained in:
Kershaw Chang 2017-06-13 01:21:00 +02:00
parent c0c44ffb82
commit 14ca5d5894
4 changed files with 38 additions and 0 deletions

View File

@ -2207,6 +2207,33 @@ HttpBaseChannel::GetProtocolVersion(nsACString& aProtocolVersion)
// HttpBaseChannel::nsIHttpChannelInternal
//-----------------------------------------------------------------------------
NS_IMETHODIMP
HttpBaseChannel::SetTopWindowURIIfUnknown(nsIURI *aTopWindowURI)
{
if (!aTopWindowURI) {
return NS_ERROR_INVALID_ARG;
}
if (mTopWindowURI) {
LOG(("HttpChannelBase::SetTopWindowURIIfUnknown [this=%p] "
"mTopWindowURI is already set.\n", this));
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIURI> topWindowURI;
Unused << GetTopWindowURI(getter_AddRefs(topWindowURI));
// Don't modify |mTopWindowURI| if we can get one from GetTopWindowURI().
if (topWindowURI) {
LOG(("HttpChannelBase::SetTopWindowURIIfUnknown [this=%p] "
"Return an error since we got a top window uri.\n", this));
return NS_ERROR_FAILURE;
}
mTopWindowURI = aTopWindowURI;
return NS_OK;
}
NS_IMETHODIMP
HttpBaseChannel::GetTopWindowURI(nsIURI **aTopWindowURI)
{

View File

@ -255,6 +255,7 @@ public:
NS_IMETHOD GetFetchCacheMode(uint32_t* aFetchCacheMode) override;
NS_IMETHOD SetFetchCacheMode(uint32_t aFetchCacheMode) override;
NS_IMETHOD GetTopWindowURI(nsIURI **aTopWindowURI) override;
NS_IMETHOD SetTopWindowURIIfUnknown(nsIURI *aTopWindowURI) override;
NS_IMETHOD GetProxyURI(nsIURI **proxyURI) override;
virtual void SetCorsPreflightParameters(const nsTArray<nsCString>& unsafeHeaders) override;
NS_IMETHOD GetConnectionInfoHashKey(nsACString& aConnectionInfoHashKey) override;

View File

@ -271,6 +271,13 @@ interface nsIHttpChannelInternal : nsISupports
*/
[must_use] readonly attribute nsIURI topWindowURI;
/**
* Set top-level window URI to this channel only when the topWindowURI
* is null and there is no window associated to this channel.
* Note that the current usage of this method is only for xpcshell test.
*/
[must_use] void setTopWindowURIIfUnknown(in nsIURI topWindowURI);
/**
* The network interface id that's associated with this channel.
*/

View File

@ -24,6 +24,8 @@ if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
do_get_profile();
}
const topWindowURI = NetUtil.newURI("http://www.itisatrap.org/");
var Ci = Components.interfaces;
function listener(tracking, priority, nextTest) {
@ -100,6 +102,7 @@ function makeChannel(path) {
chan.QueryInterface(Ci.nsIHttpChannel);
chan.requestMethod = "GET";
chan.loadFlags |= Ci.nsIChannel.LOAD_CLASSIFY_URI;
chan.QueryInterface(Ci.nsIHttpChannelInternal).setTopWindowURIIfUnknown(topWindowURI);
return chan;
}