Bug 1119037 - Add context attribute to Request. r=baku

This commit is contained in:
Nikhil Marathe 2015-01-27 15:43:09 -08:00
parent aa8347555e
commit f974b823e3
7 changed files with 25 additions and 20 deletions

View File

@ -350,7 +350,7 @@ FetchDriver::HttpFetch(bool aCORSFlag, bool aCORSPreflightFlag, bool aAuthentica
uri,
mPrincipal,
nsILoadInfo::SEC_NORMAL,
mRequest->GetContext(),
mRequest->ContentPolicyType(),
mLoadGroup,
nullptr, /* aCallbacks */
nsIRequest::LOAD_NORMAL | credentialsFlag,

View File

@ -36,7 +36,7 @@ InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult
copy->mPreserveContentCodings = true;
// The default referrer is already about:client.
copy->mContext = nsIContentPolicy::TYPE_FETCH;
copy->mContentPolicyType = nsIContentPolicy::TYPE_FETCH;
copy->mMode = mMode;
copy->mCredentialsMode = mCredentialsMode;
copy->mCacheMode = mCacheMode;

View File

@ -37,14 +37,6 @@ class InternalRequest MOZ_FINAL
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest)
enum ContextFrameType
{
FRAMETYPE_AUXILIARY = 0,
FRAMETYPE_TOP_LEVEL,
FRAMETYPE_NESTED,
FRAMETYPE_NONE,
};
enum ResponseTainting
{
RESPONSETAINT_BASIC,
@ -55,7 +47,6 @@ public:
explicit InternalRequest()
: mMethod("GET")
, mHeaders(new InternalHeaders(HeadersGuardEnum::None))
, mContextFrameType(FRAMETYPE_NONE)
, mReferrer(NS_LITERAL_STRING(kFETCH_CLIENT_REFERRER_STR))
, mMode(RequestMode::No_cors)
, mCredentialsMode(RequestCredentials::Omit)
@ -81,8 +72,7 @@ public:
, mURL(aOther.mURL)
, mHeaders(aOther.mHeaders)
, mBodyStream(aOther.mBodyStream)
, mContext(aOther.mContext)
, mContextFrameType(aOther.mContextFrameType)
, mContentPolicyType(aOther.mContentPolicyType)
, mReferrer(aOther.mReferrer)
, mMode(aOther.mMode)
, mCredentialsMode(aOther.mCredentialsMode)
@ -240,9 +230,9 @@ public:
}
nsContentPolicyType
GetContext() const
ContentPolicyType() const
{
return mContext;
return mContentPolicyType;
}
bool
@ -312,9 +302,7 @@ private:
// nsContentPolicyType does not cover the complete set defined in the spec,
// but it is a good start.
nsContentPolicyType mContext;
ContextFrameType mContextFrameType;
nsContentPolicyType mContentPolicyType;
// Empty string: no-referrer
// "about:client": client (default)

View File

@ -33,6 +33,7 @@ Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest)
: FetchBody<Request>()
, mOwner(aOwner)
, mRequest(aRequest)
, mContext(RequestContext::Fetch)
{
}

View File

@ -6,6 +6,7 @@
#ifndef mozilla_dom_Request_h
#define mozilla_dom_Request_h
#include "nsIContentPolicy.h"
#include "nsISupportsImpl.h"
#include "nsWrapperCache.h"
@ -74,6 +75,12 @@ public:
return mRequest->GetCacheMode();
}
RequestContext
Context() const
{
return mContext;
}
void
GetReferrer(nsAString& aReferrer) const
{
@ -112,6 +119,7 @@ private:
nsRefPtr<InternalRequest> mRequest;
// Lazily created.
nsRefPtr<Headers> mHeaders;
RequestContext mContext;
};
} // namespace dom

View File

@ -17,7 +17,7 @@ interface Request {
readonly attribute USVString url;
[SameObject] readonly attribute Headers headers;
// FIXME(nsm) Bug 1119037: readonly attribute RequestContext context;
readonly attribute RequestContext context;
readonly attribute DOMString referrer;
readonly attribute RequestMode mode;
readonly attribute RequestCredentials credentials;
@ -36,7 +36,13 @@ dictionary RequestInit {
RequestCache cache;
};
// FIXME(nsm): Bug 1119037 Implement RequestContext.
enum RequestContext {
"audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch",
"font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import",
"internal", "location", "manifest", "object", "ping", "plugin", "prefetch", "script",
"serviceworker", "sharedworker", "subresource", "style", "track", "video", "worker",
"xmlhttprequest", "xslt"
};
// cors-with-forced-preflight is internal to the Fetch spec, but adding it here
// allows us to use the various conversion conveniences offered by the WebIDL

View File

@ -11,6 +11,7 @@ function testDefaultCtor() {
is(req.method, "GET", "Default Request method is GET");
ok(req.headers instanceof Headers, "Request should have non-null Headers object");
is(req.url, self.location.href, "URL should be resolved with entry settings object's API base URL");
is(req.context, "fetch", "Default context is fetch.");
is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
is(req.mode, "cors", "Request mode for string input is cors");
is(req.credentials, "omit", "Default Request credentials is omit");
@ -19,6 +20,7 @@ function testDefaultCtor() {
is(req.method, "GET", "Default Request method is GET");
ok(req.headers instanceof Headers, "Request should have non-null Headers object");
is(req.url, self.location.href, "URL should be resolved with entry settings object's API base URL");
is(req.context, "fetch", "Default context is fetch.");
is(req.referrer, "about:client", "Default referrer is `client` which serializes to about:client.");
is(req.mode, "cors", "Request mode string input is cors");
is(req.credentials, "omit", "Default Request credentials is omit");