Bug 1119044 - Fetch API WebIDL Fixes. r=bkelly,baku
Add various [SameObject]/[NewObject] annotations. Adds RequestCache enum. Ensures that cors-with-forced-preflight is translated to cors in getter. Reject cors-with-forced-preflight as a valid mode value in Request constructor.
This commit is contained in:
@@ -32,6 +32,7 @@ InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult
|
|||||||
copy->mContext = nsIContentPolicy::TYPE_FETCH;
|
copy->mContext = nsIContentPolicy::TYPE_FETCH;
|
||||||
copy->mMode = mMode;
|
copy->mMode = mMode;
|
||||||
copy->mCredentialsMode = mCredentialsMode;
|
copy->mCredentialsMode = mCredentialsMode;
|
||||||
|
copy->mCacheMode = mCacheMode;
|
||||||
return copy.forget();
|
return copy.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
, mCredentialsMode(RequestCredentials::Omit)
|
, mCredentialsMode(RequestCredentials::Omit)
|
||||||
, mResponseTainting(RESPONSETAINT_BASIC)
|
, mResponseTainting(RESPONSETAINT_BASIC)
|
||||||
, mRedirectCount(0)
|
, mRedirectCount(0)
|
||||||
|
, mCacheMode(RequestCache::Default)
|
||||||
, mAuthenticationFlag(false)
|
, mAuthenticationFlag(false)
|
||||||
, mForceOriginHeader(false)
|
, mForceOriginHeader(false)
|
||||||
, mManualRedirect(false)
|
, mManualRedirect(false)
|
||||||
@@ -91,6 +92,7 @@ public:
|
|||||||
, mCredentialsMode(aOther.mCredentialsMode)
|
, mCredentialsMode(aOther.mCredentialsMode)
|
||||||
, mResponseTainting(aOther.mResponseTainting)
|
, mResponseTainting(aOther.mResponseTainting)
|
||||||
, mRedirectCount(aOther.mRedirectCount)
|
, mRedirectCount(aOther.mRedirectCount)
|
||||||
|
, mCacheMode(aOther.mCacheMode)
|
||||||
, mAuthenticationFlag(aOther.mAuthenticationFlag)
|
, mAuthenticationFlag(aOther.mAuthenticationFlag)
|
||||||
, mForceOriginHeader(aOther.mForceOriginHeader)
|
, mForceOriginHeader(aOther.mForceOriginHeader)
|
||||||
, mManualRedirect(aOther.mManualRedirect)
|
, mManualRedirect(aOther.mManualRedirect)
|
||||||
@@ -200,6 +202,12 @@ public:
|
|||||||
mResponseTainting = aTainting;
|
mResponseTainting = aTainting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestCache
|
||||||
|
GetCacheMode() const
|
||||||
|
{
|
||||||
|
return mCacheMode;
|
||||||
|
}
|
||||||
|
|
||||||
nsContentPolicyType
|
nsContentPolicyType
|
||||||
GetContext() const
|
GetContext() const
|
||||||
{
|
{
|
||||||
@@ -278,6 +286,7 @@ private:
|
|||||||
RequestMode mMode;
|
RequestMode mMode;
|
||||||
RequestCredentials mCredentialsMode;
|
RequestCredentials mCredentialsMode;
|
||||||
ResponseTainting mResponseTainting;
|
ResponseTainting mResponseTainting;
|
||||||
|
RequestCache mCacheMode;
|
||||||
|
|
||||||
uint32_t mRedirectCount;
|
uint32_t mRedirectCount;
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,16 @@ Request::Constructor(const GlobalObject& aGlobal,
|
|||||||
fallbackCredentials = RequestCredentials::Omit;
|
fallbackCredentials = RequestCredentials::Omit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CORS-with-forced-preflight is not publicly exposed and should not be
|
||||||
|
// considered a valid value.
|
||||||
|
if (aInit.mMode.WasPassed() &&
|
||||||
|
aInit.mMode.Value() == RequestMode::Cors_with_forced_preflight) {
|
||||||
|
NS_NAMED_LITERAL_STRING(sourceDescription, "'mode' member of RequestInit");
|
||||||
|
NS_NAMED_LITERAL_STRING(value, "cors-with-forced-preflight");
|
||||||
|
NS_NAMED_LITERAL_STRING(type, "RequestMode");
|
||||||
|
aRv.ThrowTypeError(MSG_INVALID_ENUM_VALUE, &sourceDescription, &value, &type);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
RequestMode mode = aInit.mMode.WasPassed() ? aInit.mMode.Value() : fallbackMode;
|
RequestMode mode = aInit.mMode.WasPassed() ? aInit.mMode.Value() : fallbackMode;
|
||||||
RequestCredentials credentials =
|
RequestCredentials credentials =
|
||||||
aInit.mCredentials.WasPassed() ? aInit.mCredentials.Value()
|
aInit.mCredentials.WasPassed() ? aInit.mCredentials.Value()
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ public:
|
|||||||
RequestMode
|
RequestMode
|
||||||
Mode() const
|
Mode() const
|
||||||
{
|
{
|
||||||
|
if (mRequest->mMode == RequestMode::Cors_with_forced_preflight) {
|
||||||
|
return RequestMode::Cors;
|
||||||
|
}
|
||||||
return mRequest->mMode;
|
return mRequest->mMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +68,12 @@ public:
|
|||||||
return mRequest->mCredentialsMode;
|
return mRequest->mCredentialsMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestCache
|
||||||
|
Cache() const
|
||||||
|
{
|
||||||
|
return mRequest->GetCacheMode();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
GetReferrer(DOMString& aReferrer) const
|
GetReferrer(DOMString& aReferrer) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,15 +15,16 @@ typedef (Request or USVString) RequestInfo;
|
|||||||
interface Request {
|
interface Request {
|
||||||
readonly attribute ByteString method;
|
readonly attribute ByteString method;
|
||||||
readonly attribute USVString url;
|
readonly attribute USVString url;
|
||||||
readonly attribute Headers headers;
|
[SameObject] readonly attribute Headers headers;
|
||||||
|
|
||||||
|
// FIXME(nsm) Bug 1119037: readonly attribute RequestContext context;
|
||||||
readonly attribute DOMString referrer;
|
readonly attribute DOMString referrer;
|
||||||
readonly attribute RequestMode mode;
|
readonly attribute RequestMode mode;
|
||||||
readonly attribute RequestCredentials credentials;
|
readonly attribute RequestCredentials credentials;
|
||||||
|
readonly attribute RequestCache cache;
|
||||||
|
|
||||||
Request clone();
|
[NewObject] Request clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
Request implements Body;
|
Request implements Body;
|
||||||
|
|
||||||
dictionary RequestInit {
|
dictionary RequestInit {
|
||||||
@@ -32,7 +33,17 @@ dictionary RequestInit {
|
|||||||
BodyInit body;
|
BodyInit body;
|
||||||
RequestMode mode;
|
RequestMode mode;
|
||||||
RequestCredentials credentials;
|
RequestCredentials credentials;
|
||||||
|
RequestCache cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME(nsm): Bug 1119037 Implement RequestContext.
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// codegen. The Request constructor has explicit checks to prevent it being
|
||||||
|
// passed as a valid value, while Request.mode never returns it. Since enums
|
||||||
|
// are only exposed as strings to client JS, this has the same effect as not
|
||||||
|
// exposing it at all.
|
||||||
enum RequestMode { "same-origin", "no-cors", "cors", "cors-with-forced-preflight" };
|
enum RequestMode { "same-origin", "no-cors", "cors", "cors-with-forced-preflight" };
|
||||||
enum RequestCredentials { "omit", "same-origin", "include" };
|
enum RequestCredentials { "omit", "same-origin", "include" };
|
||||||
|
enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
|
||||||
|
|||||||
@@ -11,19 +11,18 @@
|
|||||||
Exposed=(Window,Worker),
|
Exposed=(Window,Worker),
|
||||||
Func="mozilla::dom::Headers::PrefEnabled"]
|
Func="mozilla::dom::Headers::PrefEnabled"]
|
||||||
interface Response {
|
interface Response {
|
||||||
static Response error();
|
[NewObject] static Response error();
|
||||||
static Response redirect(USVString url, optional unsigned short status = 302);
|
[NewObject] static Response redirect(USVString url, optional unsigned short status = 302);
|
||||||
|
|
||||||
readonly attribute ResponseType type;
|
readonly attribute ResponseType type;
|
||||||
|
|
||||||
readonly attribute USVString url;
|
readonly attribute USVString url;
|
||||||
readonly attribute unsigned short status;
|
readonly attribute unsigned short status;
|
||||||
readonly attribute ByteString statusText;
|
readonly attribute ByteString statusText;
|
||||||
readonly attribute Headers headers;
|
[SameObject] readonly attribute Headers headers;
|
||||||
|
|
||||||
Response clone();
|
[NewObject] Response clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
Response implements Body;
|
Response implements Body;
|
||||||
|
|
||||||
dictionary ResponseInit {
|
dictionary ResponseInit {
|
||||||
|
|||||||
@@ -205,6 +205,28 @@ function testBodyExtraction() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mode cannot be set to "CORS-with-forced-preflight" from javascript.
|
||||||
|
function testModeCorsPreflightEnumValue() {
|
||||||
|
try {
|
||||||
|
var r = new Request(".", { mode: "cors-with-forced-preflight" });
|
||||||
|
ok(false, "Creating Request with mode cors-with-forced-preflight should fail.");
|
||||||
|
} catch(e) {
|
||||||
|
ok(true, "Creating Request with mode cors-with-forced-preflight should fail.");
|
||||||
|
// Also ensure that the error message matches error messages for truly
|
||||||
|
// invalid strings.
|
||||||
|
var invalidMode = "not-in-requestmode-enum";
|
||||||
|
var invalidExc;
|
||||||
|
try {
|
||||||
|
var r = new Request(".", { mode: invalidMode });
|
||||||
|
} catch(e) {
|
||||||
|
invalidExc = e;
|
||||||
|
}
|
||||||
|
var expectedMessage = invalidExc.message.replace(invalidMode, 'cors-with-forced-preflight');
|
||||||
|
is(e.message, expectedMessage,
|
||||||
|
"mode cors-with-forced-preflight should throw same error as invalid RequestMode strings.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onmessage = function() {
|
onmessage = function() {
|
||||||
var done = function() { postMessage({ type: 'finish' }) }
|
var done = function() { postMessage({ type: 'finish' }) }
|
||||||
|
|
||||||
@@ -214,6 +236,7 @@ onmessage = function() {
|
|||||||
testUrlFragment();
|
testUrlFragment();
|
||||||
testMethod();
|
testMethod();
|
||||||
testBug1109574();
|
testBug1109574();
|
||||||
|
testModeCorsPreflightEnumValue();
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(testBodyCreation)
|
.then(testBodyCreation)
|
||||||
|
|||||||
Reference in New Issue
Block a user