Update Fetch to use enum class instead of string for enumerations
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 May 2016 00:17:55 +0000 (00:17 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 May 2016 00:17:55 +0000 (00:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157241

Reviewed by Chris Dumez.

Source/WebCore:

* Modules/fetch/FetchOptions.h: Changed this class into a struct,
getting rid of all the getter and setter functions. Moved all the
enumeration types out of this class to the WebCore namespace level
and gave them all the names and values that match the ones from the
IDL file.

* Modules/fetch/FetchRequest.cpp:
(WebCore::setReferrerPolicy): Updated for the changes to FetchOptions.
The string matching here will likely go away when we change dictionary
so it sets up a structure, which will parse the enumeration values, but
that won't be for a while, so this stays for now.
(WebCore::setMode): Ditto.
(WebCore::setCredentials): Ditto.
(WebCore::setCache): Ditto.
(WebCore::setRedirect): Ditto.
(WebCore::buildOptions): Updated for changes to FetchOptions.
(WebCore::buildHeaders): Ditto.
(WebCore::FetchRequest::create): Ditto.
(WebCore::FetchRequest::type): Moved this to the header and changed its
return type to the enum; it's not just a single return statement.
(WebCore::FetchRequest::destination): Ditto.
(WebCore::FetchRequest::referrerPolicy): Ditto.
(WebCore::FetchRequest::mode): Ditto.
(WebCore::FetchRequest::credentials): Ditto.
(WebCore::FetchRequest::cache): Ditto.
(WebCore::FetchRequest::redirect): Ditto.

* Modules/fetch/FetchRequest.h: Changed all the getters that return
enumerations to return the enum class values instead of strings.
Put all the inline versions here in the header.

* bindings/scripts/CodeGenerator.pm: Removed the seven enum types that
are in FetchRequest.idl from the list of "string-based" enums.

* dom/Document.cpp:
(WebCore::Document::Document): Updated for the change where I
renamed ReferrerPolicy to ReferrerHeaderPolicy, at least for now.
(WebCore::Document::processReferrerPolicy): Ditto.
(WebCore::Document::applyContentDispositionAttachmentSandbox): Ditto.
* dom/Document.h: Ditto.
* loader/FrameNetworkingContext.h: Ditto.
* page/SecurityPolicy.cpp:
(WebCore::SecurityPolicy::generateReferrerHeader): Ditto.
* page/SecurityPolicy.h: Ditto.

* platform/ReferrerPolicy.h: Renamed this enum from ReferrerPolicy to
ReferrerHeaderPolicy, since the one specified in the Fetch API has the
name ReferrerPolicy. I think the best way to resolve this longer term is
to merge them since they really do represent the same concept, although
the one from the Fetch API has a few more features.

Source/WebKit2:

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::WebLoaderStrategy::loadResource): Updated for the change where I
renamed ReferrerPolicy to ReferrerHeaderPolicy, at least for now.
(WebKit::WebLoaderStrategy::schedulePluginStreamLoad): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200313 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchOptions.h
Source/WebCore/Modules/fetch/FetchRequest.cpp
Source/WebCore/Modules/fetch/FetchRequest.h
Source/WebCore/bindings/scripts/CodeGenerator.pm
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/Document.h
Source/WebCore/loader/FrameNetworkingContext.h
Source/WebCore/page/SecurityPolicy.cpp
Source/WebCore/page/SecurityPolicy.h
Source/WebCore/platform/ReferrerPolicy.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp

index dbe02a4..37d45f1 100644 (file)
@@ -1,3 +1,61 @@
+2016-05-01  Darin Adler  <darin@apple.com>
+
+        Update Fetch to use enum class instead of string for enumerations
+        https://bugs.webkit.org/show_bug.cgi?id=157241
+
+        Reviewed by Chris Dumez.
+
+        * Modules/fetch/FetchOptions.h: Changed this class into a struct,
+        getting rid of all the getter and setter functions. Moved all the
+        enumeration types out of this class to the WebCore namespace level
+        and gave them all the names and values that match the ones from the
+        IDL file.
+
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::setReferrerPolicy): Updated for the changes to FetchOptions.
+        The string matching here will likely go away when we change dictionary
+        so it sets up a structure, which will parse the enumeration values, but
+        that won't be for a while, so this stays for now.
+        (WebCore::setMode): Ditto.
+        (WebCore::setCredentials): Ditto.
+        (WebCore::setCache): Ditto.
+        (WebCore::setRedirect): Ditto.
+        (WebCore::buildOptions): Updated for changes to FetchOptions.
+        (WebCore::buildHeaders): Ditto.
+        (WebCore::FetchRequest::create): Ditto.
+        (WebCore::FetchRequest::type): Moved this to the header and changed its
+        return type to the enum; it's not just a single return statement.
+        (WebCore::FetchRequest::destination): Ditto.
+        (WebCore::FetchRequest::referrerPolicy): Ditto.
+        (WebCore::FetchRequest::mode): Ditto.
+        (WebCore::FetchRequest::credentials): Ditto.
+        (WebCore::FetchRequest::cache): Ditto.
+        (WebCore::FetchRequest::redirect): Ditto.
+
+        * Modules/fetch/FetchRequest.h: Changed all the getters that return
+        enumerations to return the enum class values instead of strings.
+        Put all the inline versions here in the header.
+
+        * bindings/scripts/CodeGenerator.pm: Removed the seven enum types that
+        are in FetchRequest.idl from the list of "string-based" enums.
+
+        * dom/Document.cpp:
+        (WebCore::Document::Document): Updated for the change where I
+        renamed ReferrerPolicy to ReferrerHeaderPolicy, at least for now.
+        (WebCore::Document::processReferrerPolicy): Ditto.
+        (WebCore::Document::applyContentDispositionAttachmentSandbox): Ditto.
+        * dom/Document.h: Ditto.
+        * loader/FrameNetworkingContext.h: Ditto.
+        * page/SecurityPolicy.cpp:
+        (WebCore::SecurityPolicy::generateReferrerHeader): Ditto.
+        * page/SecurityPolicy.h: Ditto.
+
+        * platform/ReferrerPolicy.h: Renamed this enum from ReferrerPolicy to
+        ReferrerHeaderPolicy, since the one specified in the Fetch API has the
+        name ReferrerPolicy. I think the best way to resolve this longer term is
+        to merge them since they really do represent the same concept, although
+        the one from the Fetch API has a few more features.
+
 2016-05-01  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed attempt to fix Windows build after r200288.
index ae5e8d5..81f07d1 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef FetchOptions_h
-#define FetchOptions_h
+#pragma once
 
 #if ENABLE(FETCH_API)
 
 namespace WebCore {
 
-class FetchOptions {
-public:
-    enum class Type {
-        Default,
-        Audio,
-        Font,
-        Image,
-        Script,
-        Style,
-        Track,
-        Video
-    };
-    enum class Destination {
-        Default,
-        Document,
-        SharedWorker,
-        Subresource,
-        Unknown,
-        Worker
-    };
-    enum class Mode {
-        NoCors,
-        Navigate,
-        SameOrigin,
-        Cors
-    };
-    enum class Credentials {
-        Omit,
-        SameOrigin,
-        Include
-    };
-    enum class Cache {
-        Default,
-        NoStore,
-        Reload,
-        NoCache,
-        ForceCache,
-    };
-    enum class Redirect {
-        Follow,
-        Error,
-        Manual
-    };
-    enum class ReferrerPolicy {
-        Empty,
-        NoReferrer,
-        NoReferrerWhenDowngrade,
-        OriginOnly,
-        OriginWhenCrossOrigin,
-        UnsafeURL
-    };
-
-    FetchOptions() { }
-    FetchOptions(Type, Destination, Mode, Credentials, Cache, Redirect, ReferrerPolicy);
-
-    Type type() const { return m_type; }
-    Destination destination() const { return m_destination; }
-    Mode mode() const { return m_mode; }
-    Credentials credentials() const { return m_credentials; }
-    Cache cache() const { return m_cache; }
-    Redirect redirect() const { return m_redirect; }
-    ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
-
-    void setType(Type type) { m_type = type; }
-    void setDestination(Destination destination) { m_destination = destination; }
-    void setMode(Mode mode) { m_mode = mode; }
-    void setCredentials(Credentials credentials) { m_credentials = credentials; }
-    void setCache(Cache cache) { m_cache = cache; }
-    void setRedirect(Redirect redirect) { m_redirect = redirect; }
-    void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; }
-
-private:
-    Type m_type = Type::Default;
-    Destination m_destination = Destination::Default;
-    Mode m_mode = Mode::NoCors;
-    Credentials m_credentials = Credentials::Omit;
-    Cache m_cache = Cache::Default;
-    Redirect m_redirect = Redirect:: Follow;
-    ReferrerPolicy m_referrerPolicy = ReferrerPolicy::Empty;
+enum class ReferrerPolicy { EmptyString, NoReferrer, NoReferrerWhenDowngrade, OriginOnly, OriginWhenCrossOrigin, UnsafeUrl };
+enum class RequestCache { Default, NoStore, Reload, NoCache, ForceCache };
+enum class RequestCredentials { Omit, SameOrigin, Include };
+enum class RequestDestination { EmptyString, Document, Sharedworker, Subresource, Unknown, Worker };
+enum class RequestMode { Navigate, SameOrigin, NoCors, Cors };
+enum class RequestRedirect { Follow, Error, Manual };
+enum class RequestType { EmptyString, Audio, Font, Image, Script, Style, Track, Video };
+
+struct FetchOptions {
+    RequestType type { RequestType::EmptyString };
+    RequestDestination destination { RequestDestination::EmptyString };
+    RequestMode mode { RequestMode::NoCors };
+    RequestCredentials credentials { RequestCredentials::Omit };
+    RequestCache cache { RequestCache::Default };
+    RequestRedirect redirect { RequestRedirect::Follow };
+    ReferrerPolicy referrerPolicy { ReferrerPolicy::EmptyString };
 };
 
-inline FetchOptions::FetchOptions(Type type, Destination destination, Mode mode, Credentials credentials, Cache cache, Redirect redirect, ReferrerPolicy referrerPolicy)
-    : m_type(type)
-    , m_destination(destination)
-    , m_mode(mode)
-    , m_credentials(credentials)
-    , m_cache(cache)
-    , m_redirect(redirect)
-    , m_referrerPolicy(referrerPolicy)
-{
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(FETCH_API)
-
-#endif // FetchOptions_h
index df96492..10f7c5c 100644 (file)
@@ -42,17 +42,17 @@ namespace WebCore {
 static bool setReferrerPolicy(FetchOptions& options, const String& referrerPolicy)
 {
     if (referrerPolicy.isEmpty())
-        options.setReferrerPolicy(FetchOptions::ReferrerPolicy::Empty);
+        options.referrerPolicy = ReferrerPolicy::EmptyString;
     else if (referrerPolicy == "no-referrer")
-        options.setReferrerPolicy(FetchOptions::ReferrerPolicy::NoReferrer);
+        options.referrerPolicy = ReferrerPolicy::NoReferrer;
     else if (referrerPolicy == "no-referrer-when-downgrade")
-        options.setReferrerPolicy(FetchOptions::ReferrerPolicy::NoReferrerWhenDowngrade);
+        options.referrerPolicy = ReferrerPolicy::NoReferrerWhenDowngrade;
     else if (referrerPolicy == "origin-only")
-        options.setReferrerPolicy(FetchOptions::ReferrerPolicy::OriginOnly);
+        options.referrerPolicy = ReferrerPolicy::OriginOnly;
     else if (referrerPolicy == "origin-when-cross-origin")
-        options.setReferrerPolicy(FetchOptions::ReferrerPolicy::OriginWhenCrossOrigin);
+        options.referrerPolicy = ReferrerPolicy::OriginWhenCrossOrigin;
     else if (referrerPolicy == "unsafe-url")
-        options.setReferrerPolicy(FetchOptions::ReferrerPolicy::UnsafeURL);
+        options.referrerPolicy = ReferrerPolicy::UnsafeUrl;
     else
         return false;
     return true;
@@ -61,13 +61,13 @@ static bool setReferrerPolicy(FetchOptions& options, const String& referrerPolic
 static bool setMode(FetchOptions& options, const String& mode)
 {
     if (mode == "navigate")
-        options.setMode(FetchOptions::Mode::Navigate);
+        options.mode = RequestMode::Navigate;
     else if (mode == "same-origin")
-        options.setMode(FetchOptions::Mode::SameOrigin);
+        options.mode = RequestMode::SameOrigin;
     else if (mode == "no-cors")
-        options.setMode(FetchOptions::Mode::NoCors);
+        options.mode = RequestMode::NoCors;
     else if (mode == "cors")
-        options.setMode(FetchOptions::Mode::Cors);
+        options.mode = RequestMode::Cors;
     else
         return false;
     return true;
@@ -76,11 +76,11 @@ static bool setMode(FetchOptions& options, const String& mode)
 static bool setCredentials(FetchOptions& options, const String& credentials)
 {
     if (credentials == "omit")
-        options.setCredentials(FetchOptions::Credentials::Omit);
+        options.credentials = RequestCredentials::Omit;
     else if (credentials == "same-origin")
-        options.setCredentials(FetchOptions::Credentials::SameOrigin);
+        options.credentials = RequestCredentials::SameOrigin;
     else if (credentials == "include")
-        options.setCredentials(FetchOptions::Credentials::Include);
+        options.credentials = RequestCredentials::Include;
     else
         return false;
     return true;
@@ -89,15 +89,15 @@ static bool setCredentials(FetchOptions& options, const String& credentials)
 static bool setCache(FetchOptions& options, const String& cache)
 {
     if (cache == "default")
-        options.setCache(FetchOptions::Cache::Default);
+        options.cache = RequestCache::Default;
     else if (cache == "no-store")
-        options.setCache(FetchOptions::Cache::NoStore);
+        options.cache = RequestCache::NoStore;
     else if (cache == "reload")
-        options.setCache(FetchOptions::Cache::Reload);
+        options.cache = RequestCache::Reload;
     else if (cache == "no-cache")
-        options.setCache(FetchOptions::Cache::NoCache);
+        options.cache = RequestCache::NoCache;
     else if (cache == "force-cache")
-        options.setCache(FetchOptions::Cache::ForceCache);
+        options.cache = RequestCache::ForceCache;
     else
         return false;
     return true;
@@ -106,11 +106,11 @@ static bool setCache(FetchOptions& options, const String& cache)
 static bool setRedirect(FetchOptions& options, const String& redirect)
 {
     if (redirect == "follow")
-        options.setRedirect(FetchOptions::Redirect::Follow);
+        options.redirect = RequestRedirect::Follow;
     else if (redirect == "error")
-        options.setRedirect(FetchOptions::Redirect::Error);
+        options.redirect = RequestRedirect::Error;
     else if (redirect == "manual")
-        options.setRedirect(FetchOptions::Redirect::Manual);
+        options.redirect = RequestRedirect::Manual;
     else
         return false;
     return true;
@@ -173,7 +173,7 @@ static bool buildOptions(FetchRequest::InternalRequest& request, ScriptExecution
 
     if (init.get("mode", value) && !setMode(request.options, value))
         return false;
-    if (request.options.mode() == FetchOptions::Mode::Navigate)
+    if (request.options.mode == RequestMode::Navigate)
         return false;
 
     if (init.get("credentials", value) && !setCredentials(request.options, value))
@@ -196,7 +196,7 @@ static bool buildOptions(FetchRequest::InternalRequest& request, ScriptExecution
 static RefPtr<FetchHeaders> buildHeaders(const Dictionary& init, const FetchRequest::InternalRequest& request, const FetchHeaders* inputHeaders = nullptr)
 {
     FetchHeaders::Guard guard = FetchHeaders::Guard::Request;
-    if (request.options.mode() == FetchOptions::Mode::NoCors) {
+    if (request.options.mode == RequestMode::NoCors) {
         const String& method = request.request.httpMethod();
         if (method != "GET" && method != "POST" && method != "HEAD")
             return nullptr;
@@ -244,8 +244,8 @@ RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, const
     }
 
     FetchRequest::InternalRequest internalRequest;
-    internalRequest.options.setMode(FetchOptions::Mode::Cors);
-    internalRequest.options.setCredentials(FetchOptions::Credentials::Omit);
+    internalRequest.options.mode = RequestMode::Cors;
+    internalRequest.options.credentials = RequestCredentials::Omit;
     internalRequest.referrer = ASCIILiteral("client");
     internalRequest.request.setURL(requestURL);
 
@@ -301,70 +301,6 @@ RefPtr<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, Fetch
     return adoptRef(*new FetchRequest(context, WTFMove(body), headers.releaseNonNull(), WTFMove(internalRequest)));
 }
 
-String FetchRequest::type() const
-{
-    switch (m_internalRequest.options.type()) {
-    case FetchOptions::Type::Default:
-        return String();
-    case FetchOptions::Type::Audio :
-        return ASCIILiteral("audio");
-    case FetchOptions::Type::Font :
-        return ASCIILiteral("font");
-    case FetchOptions::Type::Image :
-        return ASCIILiteral("image");
-    case FetchOptions::Type::Script :
-        return ASCIILiteral("script");
-    case FetchOptions::Type::Style :
-        return ASCIILiteral("style");
-    case FetchOptions::Type::Track :
-        return ASCIILiteral("track");
-    case FetchOptions::Type::Video :
-        return ASCIILiteral("video");
-    };
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
-String FetchRequest::destination() const
-{
-    switch (m_internalRequest.options.destination()) {
-    case FetchOptions::Destination::Default:
-        return String();
-    case FetchOptions::Destination::Document:
-        return ASCIILiteral("document");
-    case FetchOptions::Destination::SharedWorker:
-        return ASCIILiteral("sharedworker");
-    case FetchOptions::Destination::Subresource:
-        return ASCIILiteral("subresource");
-    case FetchOptions::Destination::Unknown:
-        return ASCIILiteral("unknown");
-    case FetchOptions::Destination::Worker:
-        return ASCIILiteral("worker");
-    }
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
-String FetchRequest::referrerPolicy() const
-{
-    switch (m_internalRequest.options.referrerPolicy()) {
-    case FetchOptions::ReferrerPolicy::Empty:
-        return String();
-    case FetchOptions::ReferrerPolicy::NoReferrer:
-        return ASCIILiteral("no-referrer");
-    case FetchOptions::ReferrerPolicy::NoReferrerWhenDowngrade:
-        return ASCIILiteral("no-referrer-when-downgrade");
-    case FetchOptions::ReferrerPolicy::OriginOnly:
-        return ASCIILiteral("origin-only");
-    case FetchOptions::ReferrerPolicy::OriginWhenCrossOrigin:
-        return ASCIILiteral("origin-when-cross-origin");
-    case FetchOptions::ReferrerPolicy::UnsafeURL:
-        return ASCIILiteral("unsafe-url");
-    }
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
 String FetchRequest::referrer() const
 {
     if (m_internalRequest.referrer == "no-referrer")
@@ -374,68 +310,6 @@ String FetchRequest::referrer() const
     return m_internalRequest.referrer;
 }
 
-String FetchRequest::mode() const
-{
-    switch (m_internalRequest.options.mode()) {
-    case FetchOptions::Mode::Navigate:
-        return ASCIILiteral("navigate");
-    case FetchOptions::Mode::SameOrigin:
-        return ASCIILiteral("same-origin");
-    case FetchOptions::Mode::NoCors:
-        return ASCIILiteral("no-cors");
-    case FetchOptions::Mode::Cors:
-        return ASCIILiteral("cors");
-    };
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
-String FetchRequest::credentials() const
-{
-    switch (m_internalRequest.options.credentials()) {
-    case FetchOptions::Credentials::Omit:
-        return ASCIILiteral("omit");
-    case FetchOptions::Credentials::SameOrigin:
-        return ASCIILiteral("same-origin");
-    case FetchOptions::Credentials::Include:
-        return ASCIILiteral("include");
-    };
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
-String FetchRequest::cache() const
-{
-    switch (m_internalRequest.options.cache()) {
-    case FetchOptions::Cache::Default:
-        return ASCIILiteral("default");
-    case FetchOptions::Cache::NoStore:
-        return ASCIILiteral("no-store");
-    case FetchOptions::Cache::Reload:
-        return ASCIILiteral("reload");
-    case FetchOptions::Cache::NoCache:
-        return ASCIILiteral("no-cache");
-    case FetchOptions::Cache::ForceCache:
-        return ASCIILiteral("force-cache");
-    }
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
-String FetchRequest::redirect() const
-{
-    switch (m_internalRequest.options.redirect()) {
-    case FetchOptions::Redirect::Follow:
-        return ASCIILiteral("follow");
-    case FetchOptions::Redirect::Error:
-        return ASCIILiteral("error");
-    case FetchOptions::Redirect::Manual:
-        return ASCIILiteral("manual");
-    }
-    ASSERT_NOT_REACHED();
-    return String();
-}
-
 ResourceRequest FetchRequest::internalRequest() const
 {
     ResourceRequest request = m_internalRequest.request;
index 9200bd1..5f54806 100644 (file)
@@ -48,19 +48,18 @@ public:
     static RefPtr<FetchRequest> create(ScriptExecutionContext&, FetchRequest&, const Dictionary&, ExceptionCode&);
     static RefPtr<FetchRequest> create(ScriptExecutionContext&, const String&, const Dictionary&, ExceptionCode&);
 
-    // Request API
     const String& method() const { return m_internalRequest.request.httpMethod(); }
     const String& url() const { return m_internalRequest.request.url().string(); }
     FetchHeaders& headers() { return m_headers.get(); }
 
-    String type() const;
-    String destination() const;
+    RequestType type() const;
+    RequestDestination destination() const;
     String referrer() const;
-    String referrerPolicy() const;
-    String mode() const;
-    String credentials() const;
-    String cache() const;
-    String redirect() const;
+    ReferrerPolicy referrerPolicy() const;
+    RequestMode mode() const;
+    RequestCredentials credentials() const;
+    RequestCache cache() const;
+    RequestRedirect redirect() const;
     const String& integrity() const { return m_internalRequest.integrity; }
 
     RefPtr<FetchRequest> clone(ScriptExecutionContext&, ExceptionCode&);
@@ -93,6 +92,41 @@ inline FetchRequest::FetchRequest(ScriptExecutionContext& context, FetchBody&& b
 {
 }
 
+inline RequestCache FetchRequest::cache() const
+{
+    return m_internalRequest.options.cache;
+}
+
+inline RequestCredentials FetchRequest::credentials() const
+{
+    return m_internalRequest.options.credentials;
+}
+
+inline RequestDestination FetchRequest::destination() const
+{
+    return m_internalRequest.options.destination;
+}
+
+inline RequestMode FetchRequest::mode() const
+{
+    return m_internalRequest.options.mode;
+}
+
+inline RequestRedirect FetchRequest::redirect() const
+{
+    return m_internalRequest.options.redirect;
+}
+
+inline ReferrerPolicy FetchRequest::referrerPolicy() const
+{
+    return m_internalRequest.options.referrerPolicy;
+}
+
+inline RequestType FetchRequest::type() const
+{
+    return m_internalRequest.options.type;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(FETCH_API)
index 2b8ea87..13c64e3 100644 (file)
@@ -133,13 +133,6 @@ my %svgTypeWithWritablePropertiesNeedingTearOff = (
 # enumeration to using an actual enum class in the C++. Once that is done, we should
 # remove this hash and the function that calls it.
 my %stringBasedEnumerationHash = (
-    "ReferrerPolicy" => 1,
-    "RequestCache" => 1,
-    "RequestCredentials" => 1,
-    "RequestDestination" => 1,
-    "RequestMode" => 1,
-    "RequestRedirect" => 1,
-    "RequestType" => 1,
     "TextTrackKind" => 1,
     "TextTrackMode" => 1,
 );
index 42110d6..03f9df9 100644 (file)
@@ -521,7 +521,7 @@ Document::Document(Frame* frame, const URL& url, unsigned documentClasses, unsig
 #endif
     , m_loadEventDelayCount(0)
     , m_loadEventDelayTimer(*this, &Document::loadEventDelayTimerFired)
-    , m_referrerPolicy(ReferrerPolicyDefault)
+    , m_referrerPolicy(ReferrerHeaderPolicy::Default)
     , m_writeRecursionIsTooDeep(false)
     , m_writeRecursionDepth(0)
     , m_lastHandledUserGestureTimestamp(0)
@@ -3360,16 +3360,16 @@ void Document::processReferrerPolicy(const String& policy)
     // Note that we're supporting both the standard and legacy keywords for referrer
     // policies, as defined by http://www.w3.org/TR/referrer-policy/#referrer-policy-delivery-meta
     if (equalLettersIgnoringASCIICase(policy, "no-referrer") || equalLettersIgnoringASCIICase(policy, "never"))
-        setReferrerPolicy(ReferrerPolicyNever);
+        setReferrerPolicy(ReferrerHeaderPolicy::Never);
     else if (equalLettersIgnoringASCIICase(policy, "unsafe-url") || equalLettersIgnoringASCIICase(policy, "always"))
-        setReferrerPolicy(ReferrerPolicyAlways);
+        setReferrerPolicy(ReferrerHeaderPolicy::Always);
     else if (equalLettersIgnoringASCIICase(policy, "origin"))
-        setReferrerPolicy(ReferrerPolicyOrigin);
+        setReferrerPolicy(ReferrerHeaderPolicy::Origin);
     else if (equalLettersIgnoringASCIICase(policy, "no-referrer-when-downgrade") || equalLettersIgnoringASCIICase(policy, "default"))
-        setReferrerPolicy(ReferrerPolicyDefault);
+        setReferrerPolicy(ReferrerHeaderPolicy::Default);
     else {
         addConsoleMessage(MessageSource::Rendering, MessageLevel::Error, "Failed to set referrer policy: The value '" + policy + "' is not one of 'no-referrer', 'origin', 'no-referrer-when-downgrade', or 'unsafe-url'. Defaulting to 'no-referrer'.");
-        setReferrerPolicy(ReferrerPolicyNever);
+        setReferrerPolicy(ReferrerHeaderPolicy::Never);
     }
 }
 
@@ -6937,7 +6937,7 @@ void Document::applyContentDispositionAttachmentSandbox()
 {
     ASSERT(shouldEnforceContentDispositionAttachmentSandbox());
 
-    setReferrerPolicy(ReferrerPolicyNever);
+    setReferrerPolicy(ReferrerHeaderPolicy::Never);
     if (!isMediaDocument())
         enforceSandboxFlags(SandboxAll);
     else
index 1bcb48b..16621eb 100644 (file)
@@ -361,8 +361,8 @@ public:
     bool didDispatchViewportPropertiesChanged() const { return m_didDispatchViewportPropertiesChanged; }
 #endif
 
-    void setReferrerPolicy(ReferrerPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; }
-    ReferrerPolicy referrerPolicy() const { return m_referrerPolicy; }
+    void setReferrerPolicy(ReferrerHeaderPolicy referrerPolicy) { m_referrerPolicy = referrerPolicy; }
+    ReferrerHeaderPolicy referrerPolicy() const { return m_referrerPolicy; }
 
     DocumentType* doctype() const;
 
@@ -1640,7 +1640,7 @@ private:
 
     ViewportArguments m_viewportArguments;
 
-    ReferrerPolicy m_referrerPolicy;
+    ReferrerHeaderPolicy m_referrerPolicy;
 
 #if ENABLE(WEB_TIMING)
     DocumentTiming m_documentTiming;
index c0c2d26..ff51b3b 100644 (file)
@@ -17,8 +17,7 @@
     Boston, MA 02110-1301, USA.
 */
 
-#ifndef FrameNetworkingContext_h
-#define FrameNetworkingContext_h
+#pragma once
 
 #include "Document.h"
 #include "Frame.h"
@@ -40,7 +39,7 @@ public:
         if (!m_frame)
             return true;
 
-        return m_frame->document()->referrerPolicy() == ReferrerPolicyDefault;
+        return m_frame->document()->referrerPolicy() == ReferrerHeaderPolicy::Default;
     }
 
 protected:
@@ -58,5 +57,3 @@ private:
 };
 
 }
-
-#endif // FrameNetworkingContext_h
index 3bd3200..23dcf11 100644 (file)
@@ -66,7 +66,7 @@ bool SecurityPolicy::shouldHideReferrer(const URL& url, const String& referrer)
     return !URLIsSecureURL;
 }
 
-String SecurityPolicy::generateReferrerHeader(ReferrerPolicy referrerPolicy, const URL& url, const String& referrer)
+String SecurityPolicy::generateReferrerHeader(ReferrerHeaderPolicy referrerPolicy, const URL& url, const String& referrer)
 {
     if (referrer.isEmpty())
         return String();
@@ -75,11 +75,11 @@ String SecurityPolicy::generateReferrerHeader(ReferrerPolicy referrerPolicy, con
         return String();
 
     switch (referrerPolicy) {
-    case ReferrerPolicyNever:
+    case ReferrerHeaderPolicy::Never:
         return String();
-    case ReferrerPolicyAlways:
+    case ReferrerHeaderPolicy::Always:
         return referrer;
-    case ReferrerPolicyOrigin: {
+    case ReferrerHeaderPolicy::Origin: {
         String origin = SecurityOrigin::createFromString(referrer)->toString();
         if (origin == "null")
             return String();
@@ -87,7 +87,7 @@ String SecurityPolicy::generateReferrerHeader(ReferrerPolicy referrerPolicy, con
         // to turn it into a canonical URL we can use as referrer.
         return origin + "/";
     }
-    case ReferrerPolicyDefault:
+    case ReferrerHeaderPolicy::Default:
         break;
     }
 
index 7679c9f..ab6e68f 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef SecurityPolicy_h
-#define SecurityPolicy_h
+#pragma once
 
 #include "ReferrerPolicy.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
-class URL;
 class SecurityOrigin;
+class URL;
 
 class SecurityPolicy {
 public:
-    // True if the referrer should be omitted according to the
-    // ReferrerPolicyDefault. If you intend to send a referrer header, you
-    // should use generateReferrerHeader instead.
+    // True if the referrer should be omitted according to ReferrerHeaderPolicy::Default.
+    // If you intend to send a referrer header, you should use generateReferrerHeader instead.
     WEBCORE_EXPORT static bool shouldHideReferrer(const URL&, const String& referrer);
 
     // Returns the referrer modified according to the referrer policy for a
     // navigation to a given URL. If the referrer returned is empty, the
     // referrer header should be omitted.
-    WEBCORE_EXPORT static String generateReferrerHeader(ReferrerPolicy, const URL&, const String& referrer);
+    WEBCORE_EXPORT static String generateReferrerHeader(ReferrerHeaderPolicy, const URL&, const String& referrer);
 
     enum LocalLoadPolicy {
         AllowLocalLoadsForAll, // No restriction on local loads.
@@ -68,5 +66,3 @@ public:
 };
 
 } // namespace WebCore
-
-#endif // SecurityPolicy_h
index 39b60bb..e51c580 100644 (file)
  *
  */
 
-#ifndef ReferrerPolicy_h
-#define ReferrerPolicy_h
+#pragma once
 
 namespace WebCore {
 
-enum ReferrerPolicy {
-    ReferrerPolicyAlways,
-    ReferrerPolicyDefault,
-    ReferrerPolicyNever,
-    // Same as ReferrerPolicyAlways, except that only the origin of the
-    // referring URL is send.
-    ReferrerPolicyOrigin,
+// The following is needed to compile on GTK because of a macro defined in X11.h.
+// FIXME: Move this workaround to a global location, perhaps config.h; maybe a GTK-specific location.
+#undef Always
+
+// FIXME: Merge this with the ReferrerPolicy defined in the Fetch specification.
+// FIXME: Rename back to ReferrerPolicy even before that, if we find a way.
+enum class ReferrerHeaderPolicy {
+    Always,
+    Default,
+    Never,
+    // Same as Always, except that only the origin of the referring URL is sent.
+    Origin,
 };
 
 }
-
-#endif // ReferrerPolicy_h
index e343ca1..54128e4 100644 (file)
@@ -1,3 +1,15 @@
+2016-05-01  Darin Adler  <darin@apple.com>
+
+        Update Fetch to use enum class instead of string for enumerations
+        https://bugs.webkit.org/show_bug.cgi?id=157241
+
+        Reviewed by Chris Dumez.
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::WebLoaderStrategy::loadResource): Updated for the change where I
+        renamed ReferrerPolicy to ReferrerHeaderPolicy, at least for now.
+        (WebKit::WebLoaderStrategy::schedulePluginStreamLoad): Ditto.
+
 2016-05-01  Konstantin Tokarev  <annulen@yandex.ru>
 
         Fixed build with !ENABLED(DATABASE_PROCESS).
index f67ff80..18096c2 100644 (file)
@@ -75,7 +75,7 @@ RefPtr<SubresourceLoader> WebLoaderStrategy::loadResource(Frame* frame, CachedRe
 {
     RefPtr<SubresourceLoader> loader = SubresourceLoader::create(frame, resource, request, options);
     if (loader)
-        scheduleLoad(loader.get(), resource, frame->document()->referrerPolicy() == ReferrerPolicyDefault);
+        scheduleLoad(loader.get(), resource, frame->document()->referrerPolicy() == ReferrerHeaderPolicy::Default);
     return loader;
 }
 
@@ -83,7 +83,7 @@ RefPtr<NetscapePlugInStreamLoader> WebLoaderStrategy::schedulePluginStreamLoad(F
 {
     RefPtr<NetscapePlugInStreamLoader> loader = NetscapePlugInStreamLoader::create(frame, client, request);
     if (loader)
-        scheduleLoad(loader.get(), 0, frame->document()->referrerPolicy() == ReferrerPolicyDefault);
+        scheduleLoad(loader.get(), 0, frame->document()->referrerPolicy() == ReferrerHeaderPolicy::Default);
     return loader;
 }