Diff
Modified: trunk/Source/WebCore/ChangeLog (209230 => 209231)
--- trunk/Source/WebCore/ChangeLog 2016-12-02 03:30:37 UTC (rev 209230)
+++ trunk/Source/WebCore/ChangeLog 2016-12-02 05:31:07 UTC (rev 209231)
@@ -1,3 +1,34 @@
+2016-11-30 Darin Adler <[email protected]>
+
+ Stop using WebCore::Dictionary in bindings for Fetch
+ https://bugs.webkit.org/show_bug.cgi?id=165241
+
+ Reviewed by Chris Dumez.
+
+ * Modules/fetch/DOMWindowFetch.idl: Use RequestInit instead of Dictionary.
+ No effect on code generated since this is a JSBuiltin.
+
+ * Modules/fetch/FetchRequest.cpp:
+ (WebCore::setReferrerPolicy): Deleted. Bindings handle this now.
+ (WebCore::setMode): Ditto.
+ (WebCore::setCredentials): Ditto.
+ (WebCore::setCache): Ditto.
+ (WebCore::setRedirect): Ditto.
+ (WebCore::setReferrer): Changed argument from Dictionary to String.
+ (WebCore::buildOptions): Changed argument from Dictionary to FetchRequest::Init,
+ and simplified the code accordingly.
+ (WebCore::FetchRequest::initializeOptions): Ditto.
+ (WebCore::FetchRequest::initializeWith): Ditto.
+ * Modules/fetch/FetchRequest.h: Updated for above changes. Also added the Init struct.
+
+ * Modules/fetch/FetchRequest.idl: Added missing "only-if-cached" value to RequestCache.
+ Added RequestInit dictionary and used it instead of Dictionary. Used more-specific string
+ types for the method and referrer attributes; no effect at runtime, since the code for
+ getters is the same for ByteString, USVString, and DOMString and these are read-only.
+
+ * Modules/fetch/WorkerGlobalScopeFetch.idl: Use RequestInit instead of Dictionary.
+ No effect on code generated since this is a JSBuiltin.
+
2016-12-01 Jiewen Tan <[email protected]>
Add a runtime flag for SubtleCrypto
Modified: trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.idl (209230 => 209231)
--- trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.idl 2016-12-02 03:30:37 UTC (rev 209230)
+++ trunk/Source/WebCore/Modules/fetch/DOMWindowFetch.idl 2016-12-02 05:31:07 UTC (rev 209231)
@@ -30,7 +30,6 @@
Conditional=FETCH_API,
EnabledAtRuntime=FetchAPI,
] partial interface DOMWindow {
- [JSBuiltin] Promise<Response> fetch(any input, optional Dictionary init);
-
+ [JSBuiltin] Promise<Response> fetch(any input, optional RequestInit init);
[PrivateIdentifier, ImplementedAs=fetch] Promise<Response> fetchRequest(FetchRequest request);
};
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (209230 => 209231)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-12-02 03:30:37 UTC (rev 209230)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-12-02 05:31:07 UTC (rev 209231)
@@ -31,7 +31,6 @@
#if ENABLE(FETCH_API)
-#include "Dictionary.h"
#include "ExceptionCode.h"
#include "HTTPParsers.h"
#include "ScriptExecutionContext.h"
@@ -39,85 +38,6 @@
namespace WebCore {
-static std::optional<Exception> setReferrerPolicy(FetchOptions& options, const String& referrerPolicy)
-{
- if (referrerPolicy.isEmpty())
- options.referrerPolicy = FetchOptions::ReferrerPolicy::EmptyString;
- else if (referrerPolicy == "no-referrer")
- options.referrerPolicy = FetchOptions::ReferrerPolicy::NoReferrer;
- else if (referrerPolicy == "no-referrer-when-downgrade")
- options.referrerPolicy = FetchOptions::ReferrerPolicy::NoReferrerWhenDowngrade;
- else if (referrerPolicy == "origin")
- options.referrerPolicy = FetchOptions::ReferrerPolicy::Origin;
- else if (referrerPolicy == "origin-when-cross-origin")
- options.referrerPolicy = FetchOptions::ReferrerPolicy::OriginWhenCrossOrigin;
- else if (referrerPolicy == "unsafe-url")
- options.referrerPolicy = FetchOptions::ReferrerPolicy::UnsafeUrl;
- else
- return Exception { TypeError, ASCIILiteral("Bad referrer policy value.") };
- return std::nullopt;
-}
-
-static std::optional<Exception> setMode(FetchOptions& options, const String& mode)
-{
- if (mode == "navigate")
- options.mode = FetchOptions::Mode::Navigate;
- else if (mode == "same-origin")
- options.mode = FetchOptions::Mode::SameOrigin;
- else if (mode == "no-cors")
- options.mode = FetchOptions::Mode::NoCors;
- else if (mode == "cors")
- options.mode = FetchOptions::Mode::Cors;
- else
- return Exception { TypeError, ASCIILiteral("Bad fetch mode value.") };
- return std::nullopt;
-}
-
-static std::optional<Exception> setCredentials(FetchOptions& options, const String& credentials)
-{
- if (credentials == "omit")
- options.credentials = FetchOptions::Credentials::Omit;
- else if (credentials == "same-origin")
- options.credentials = FetchOptions::Credentials::SameOrigin;
- else if (credentials == "include")
- options.credentials = FetchOptions::Credentials::Include;
- else
- return Exception { TypeError, ASCIILiteral("Bad credentials mode value.") };
- return std::nullopt;
-}
-
-static std::optional<Exception> setCache(FetchOptions& options, const String& cache)
-{
- if (cache == "default")
- options.cache = FetchOptions::Cache::Default;
- else if (cache == "no-store")
- options.cache = FetchOptions::Cache::NoStore;
- else if (cache == "reload")
- options.cache = FetchOptions::Cache::Reload;
- else if (cache == "no-cache")
- options.cache = FetchOptions::Cache::NoCache;
- else if (cache == "force-cache")
- options.cache = FetchOptions::Cache::ForceCache;
- else if (cache == "only-if-cached")
- options.cache = FetchOptions::Cache::OnlyIfCached;
- else
- return Exception { TypeError, ASCIILiteral("Bad cache mode value.") };
- return std::nullopt;
-}
-
-static std::optional<Exception> setRedirect(FetchOptions& options, const String& redirect)
-{
- if (redirect == "follow")
- options.redirect = FetchOptions::Redirect::Follow;
- else if (redirect == "error")
- options.redirect = FetchOptions::Redirect::Error;
- else if (redirect == "manual")
- options.redirect = FetchOptions::Redirect::Manual;
- else
- return Exception { TypeError, ASCIILiteral("Bad redirect mode value.") };
- return std::nullopt;
-}
-
static std::optional<Exception> setMethod(ResourceRequest& request, const String& initMethod)
{
if (!isValidHTTPToken(initMethod))
@@ -132,11 +52,8 @@
return std::nullopt;
}
-static std::optional<Exception> setReferrer(FetchRequest::InternalRequest& request, ScriptExecutionContext& context, const Dictionary& init)
+static std::optional<Exception> setReferrer(FetchRequest::InternalRequest& request, ScriptExecutionContext& context, const String& referrer)
{
- String referrer;
- if (!init.get("referrer", referrer))
- return std::nullopt;
if (referrer.isEmpty()) {
request.referrer = ASCIILiteral("no-referrer");
return std::nullopt;
@@ -158,61 +75,43 @@
return std::nullopt;
}
-static std::optional<Exception> buildOptions(FetchRequest::InternalRequest& request, ScriptExecutionContext& context, const Dictionary& init)
+static std::optional<Exception> buildOptions(FetchRequest::InternalRequest& request, ScriptExecutionContext& context, const FetchRequest::Init& init)
{
- JSC::JSValue window;
- if (init.get("window", window)) {
- if (!window.isNull())
- return Exception { TypeError, ASCIILiteral("Window can only be null.") };
- }
+ if (!init.window.isUndefinedOrNull())
+ return Exception { TypeError, ASCIILiteral("Window can only be null.") };
- auto exception = setReferrer(request, context, init);
- if (exception)
- return exception;
-
- String value;
- if (init.get("referrerPolicy", value)) {
- exception = setReferrerPolicy(request.options, value);
- if (exception)
+ if (!init.referrer.isNull()) {
+ if (auto exception = setReferrer(request, context, init.referrer))
return exception;
}
- if (init.get("mode", value)) {
- exception = setMode(request.options, value);
- if (exception)
- return exception;
- }
+ if (init.referrerPolicy)
+ request.options.referrerPolicy = init.referrerPolicy.value();
+
+ if (init.mode)
+ request.options.mode = init.mode.value();
if (request.options.mode == FetchOptions::Mode::Navigate)
return Exception { TypeError, ASCIILiteral("Request constructor does not accept navigate fetch mode.") };
- if (init.get("credentials", value)) {
- exception = setCredentials(request.options, value);
- if (exception)
- return exception;
- }
+ if (init.credentials)
+ request.options.credentials = init.credentials.value();
- if (init.get("cache", value)) {
- exception = setCache(request.options, value);
- if (exception)
- return exception;
- }
-
+ if (init.cache)
+ request.options.cache = init.cache.value();
if (request.options.cache == FetchOptions::Cache::OnlyIfCached && request.options.mode != FetchOptions::Mode::SameOrigin)
return Exception { TypeError, ASCIILiteral("only-if-cached cache option requires fetch mode to be same-origin.") };
- if (init.get("redirect", value)) {
- exception = setRedirect(request.options, value);
- if (exception)
- return exception;
- }
+ if (init.redirect)
+ request.options.redirect = init.redirect.value();
- init.get("integrity", request.integrity);
+ if (!init.integrity.isNull())
+ request.integrity = init.integrity;
- if (init.get("method", value)) {
- exception = setMethod(request.request, value);
- if (exception)
+ if (!init.method.isNull()) {
+ if (auto exception = setMethod(request.request, init.method))
return exception;
}
+
return std::nullopt;
}
@@ -221,7 +120,7 @@
return internalRequest.request.httpMethod() != "GET" && internalRequest.request.httpMethod() != "HEAD";
}
-ExceptionOr<FetchHeaders&> FetchRequest::initializeOptions(const Dictionary& init)
+ExceptionOr<FetchHeaders&> FetchRequest::initializeOptions(const Init& init)
{
ASSERT(scriptExecutionContext());
@@ -240,7 +139,7 @@
return m_headers.get();
}
-ExceptionOr<FetchHeaders&> FetchRequest::initializeWith(const String& url, const Dictionary& init)
+ExceptionOr<FetchHeaders&> FetchRequest::initializeWith(const String& url, const Init& init)
{
ASSERT(scriptExecutionContext());
// FIXME: Tighten the URL parsing algorithm according https://url.spec.whatwg.org/#concept-url-parser.
@@ -257,7 +156,7 @@
return initializeOptions(init);
}
-ExceptionOr<FetchHeaders&> FetchRequest::initializeWith(FetchRequest& input, const Dictionary& init)
+ExceptionOr<FetchHeaders&> FetchRequest::initializeWith(FetchRequest& input, const Init& init)
{
if (input.isDisturbedOrLocked())
return Exception {TypeError, ASCIILiteral("Request input is disturbed or locked.") };
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.h (209230 => 209231)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.h 2016-12-02 03:30:37 UTC (rev 209230)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.h 2016-12-02 05:31:07 UTC (rev 209231)
@@ -38,15 +38,36 @@
namespace WebCore {
-class Dictionary;
+class Blob;
class ScriptExecutionContext;
+class URLSearchParams;
class FetchRequest final : public FetchBodyOwner {
public:
static Ref<FetchRequest> create(ScriptExecutionContext& context) { return adoptRef(*new FetchRequest(context, std::nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { })); }
- ExceptionOr<FetchHeaders&> initializeWith(FetchRequest&, const Dictionary&);
- ExceptionOr<FetchHeaders&> initializeWith(const String&, const Dictionary&);
+ using Cache = FetchOptions::Cache;
+ using Credentials = FetchOptions::Credentials;
+ using Destination = FetchOptions::Destination;
+ using Mode = FetchOptions::Mode;
+ using Redirect = FetchOptions::Redirect;
+ using ReferrerPolicy = FetchOptions::ReferrerPolicy;
+ using Type = FetchOptions::Type;
+
+ struct Init {
+ String method;
+ String referrer;
+ std::optional<ReferrerPolicy> referrerPolicy;
+ std::optional<Mode> mode;
+ std::optional<Credentials> credentials;
+ std::optional<Cache> cache;
+ std::optional<Redirect> redirect;
+ String integrity;
+ JSC::JSValue window;
+ };
+
+ ExceptionOr<FetchHeaders&> initializeWith(FetchRequest&, const Init&);
+ ExceptionOr<FetchHeaders&> initializeWith(const String&, const Init&);
ExceptionOr<void> setBody(JSC::ExecState&, JSC::JSValue, FetchRequest*);
const String& method() const { return m_internalRequest.request.httpMethod(); }
@@ -53,27 +74,13 @@
const String& url() const;
FetchHeaders& headers() { return m_headers.get(); }
- using Type = FetchOptions::Type;
Type type() const;
-
- using Destination = FetchOptions::Destination;
Destination destination() const;
-
String referrer() const;
-
- using ReferrerPolicy = FetchOptions::ReferrerPolicy;
ReferrerPolicy referrerPolicy() const;
-
- using Mode = FetchOptions::Mode;
Mode mode() const;
-
- using Credentials = FetchOptions::Credentials;
Credentials credentials() const;
-
- using Cache = FetchOptions::Cache;
Cache cache() const;
-
- using Redirect = FetchOptions::Redirect;
Redirect redirect() const;
const String& integrity() const { return m_internalRequest.integrity; }
@@ -95,7 +102,7 @@
private:
FetchRequest(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, InternalRequest&&);
- ExceptionOr<FetchHeaders&> initializeOptions(const Dictionary&);
+ ExceptionOr<FetchHeaders&> initializeOptions(const Init&);
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.idl (209230 => 209231)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2016-12-02 03:30:37 UTC (rev 209230)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.idl 2016-12-02 05:31:07 UTC (rev 209231)
@@ -30,14 +30,29 @@
enum RequestDestination { "", "document", "sharedworker", "subresource", "unknown", "worker" };
enum RequestMode { "navigate", "same-origin", "no-cors", "cors" };
enum RequestCredentials { "omit", "same-origin", "include" };
-enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache" };
+enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" };
enum RequestRedirect { "follow", "error", "manual" };
enum ReferrerPolicy { "", "no-referrer", "no-referrer-when-downgrade", "origin", "origin-when-cross-origin", "unsafe-url" };
+dictionary RequestInit {
+ ByteString method;
+ // FIXME: Should add: HeadersInit headers;
+ // FIXME: Should add: BodyInit? body;
+ USVString referrer;
+ ReferrerPolicy referrerPolicy;
+ RequestMode mode;
+ RequestCredentials credentials;
+ RequestCache cache;
+ RequestRedirect redirect;
+ DOMString integrity;
+ // FIXME: Should add: boolean keepalive;
+ any window; // can only be set to null
+};
+
[
ActiveDOMObject,
Conditional=FETCH_API,
- Constructor(any input, optional Dictionary init),
+ Constructor(any input, optional RequestInit init),
EnabledAtRuntime=FetchAPI,
Exposed=(Window,Worker),
InterfaceName=Request,
@@ -45,13 +60,13 @@
PrivateIdentifier,
PublicIdentifier,
] interface FetchRequest {
- readonly attribute DOMString method;
+ readonly attribute ByteString method;
readonly attribute DOMString url;
readonly attribute FetchHeaders headers;
readonly attribute RequestType type;
readonly attribute RequestDestination destination;
- readonly attribute DOMString referrer;
+ readonly attribute USVString referrer;
readonly attribute ReferrerPolicy referrerPolicy;
readonly attribute RequestMode mode;
readonly attribute RequestCredentials credentials;
@@ -61,8 +76,8 @@
[CallWith=ScriptExecutionContext, MayThrowException, NewObject] FetchRequest clone();
- [MayThrowException, NewObject, PrivateIdentifier] FetchHeaders initializeWith(FetchRequest input, Dictionary init);
- [MayThrowException, NewObject, PrivateIdentifier] FetchHeaders initializeWith(DOMString input, Dictionary init);
+ [MayThrowException, NewObject, PrivateIdentifier] FetchHeaders initializeWith(FetchRequest input, RequestInit init);
+ [MayThrowException, NewObject, PrivateIdentifier] FetchHeaders initializeWith(DOMString input, RequestInit init);
[CallWith=ScriptState, MayThrowException, PrivateIdentifier] void setBody(any body, FetchRequest? request);
};
Modified: trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.idl (209230 => 209231)
--- trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.idl 2016-12-02 03:30:37 UTC (rev 209230)
+++ trunk/Source/WebCore/Modules/fetch/WorkerGlobalScopeFetch.idl 2016-12-02 05:31:07 UTC (rev 209231)
@@ -30,7 +30,6 @@
Conditional=FETCH_API,
EnabledAtRuntime=FetchAPI,
] partial interface WorkerGlobalScope {
- [JSBuiltin] Promise<Response> fetch(any input, optional Dictionary init);
-
+ [JSBuiltin] Promise<Response> fetch(any input, optional RequestInit init);
[PrivateIdentifier, ImplementedAs=fetch] Promise<Response> fetchRequest(FetchRequest request);
};