Add overloads of HTTPHeaderMap::find and remove that take enums
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jun 2014 17:33:45 +0000 (17:33 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 13 Jun 2014 17:33:45 +0000 (17:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133823

Reviewed by Sam Weinig.

Source/WebCore:
* WebCore.exp.in:
Update symbols.

* WebCore.xcodeproj/project.pbxproj:
Make HTTPHeaderNames.h private.

* platform/network/HTTPHeaderMap.cpp:
(WebCore::HTTPHeaderMap::contains):
Convert the enum value to a string and call the contains overload that takes a string.

(WebCore::HTTPHeaderMap::remove):
Convert the enum value to a string and call the remove overload that takes a string.

* platform/network/HTTPHeaderMap.h:
Add new overloads taking HTTPHeaderName and mark the versions taking string literals as deleted.

* platform/network/HTTPHeaderNames.in:
Add new header names.

* platform/network/ResourceRequestBase.cpp:
(WebCore::ResourceRequestBase::clearHTTPAuthorization):
(WebCore::ResourceRequestBase::clearHTTPContentType):
(WebCore::ResourceRequestBase::clearHTTPReferrer):
(WebCore::ResourceRequestBase::clearHTTPOrigin):
(WebCore::ResourceRequestBase::clearHTTPUserAgent):
(WebCore::ResourceRequestBase::clearHTTPAccept):
Update functions to use HTTPHeaderName enums.

(WebCore::ResourceRequestBase::isConditional):
(WebCore::ResourceRequestBase::makeUnconditional):
Simplify these.

Source/WebKit2:
* WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
(WebKit::parsePostBuffer):
Update for WebCore changes.

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/network/HTTPHeaderMap.cpp
Source/WebCore/platform/network/HTTPHeaderMap.h
Source/WebCore/platform/network/HTTPHeaderNames.in
Source/WebCore/platform/network/ResourceRequestBase.cpp
Source/WebCore/plugins/PluginView.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp

index 82721e7..4cb8fdf 100644 (file)
@@ -1,3 +1,42 @@
+2014-06-12  Anders Carlsson  <andersca@apple.com>
+
+        Add overloads of HTTPHeaderMap::find and remove that take enums
+        https://bugs.webkit.org/show_bug.cgi?id=133823
+
+        Reviewed by Sam Weinig.
+
+        * WebCore.exp.in:
+        Update symbols.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Make HTTPHeaderNames.h private.
+
+        * platform/network/HTTPHeaderMap.cpp:
+        (WebCore::HTTPHeaderMap::contains):
+        Convert the enum value to a string and call the contains overload that takes a string.
+
+        (WebCore::HTTPHeaderMap::remove):
+        Convert the enum value to a string and call the remove overload that takes a string.
+
+        * platform/network/HTTPHeaderMap.h:
+        Add new overloads taking HTTPHeaderName and mark the versions taking string literals as deleted.
+
+        * platform/network/HTTPHeaderNames.in:
+        Add new header names.
+
+        * platform/network/ResourceRequestBase.cpp:
+        (WebCore::ResourceRequestBase::clearHTTPAuthorization):
+        (WebCore::ResourceRequestBase::clearHTTPContentType):
+        (WebCore::ResourceRequestBase::clearHTTPReferrer):
+        (WebCore::ResourceRequestBase::clearHTTPOrigin):
+        (WebCore::ResourceRequestBase::clearHTTPUserAgent):
+        (WebCore::ResourceRequestBase::clearHTTPAccept):
+        Update functions to use HTTPHeaderName enums.
+
+        (WebCore::ResourceRequestBase::isConditional):
+        (WebCore::ResourceRequestBase::makeUnconditional):
+        Simplify these.
+
 2014-06-13  Jarek Czekalski  <jarekczek@poczta.onet.pl>
 
         [ATK] Fix text inside "span" block in "a" block was not accessible.
index 3bfbf66..5b92921 100644 (file)
@@ -291,7 +291,7 @@ __ZN7WebCore13GraphicsLayerC2ERNS_19GraphicsLayerClientE
 __ZN7WebCore13GraphicsLayerD2Ev
 __ZN7WebCore13HTTPHeaderMap3addERKN3WTF12AtomicStringERKNS1_6StringE
 __ZN7WebCore13HTTPHeaderMap3setERKN3WTF12AtomicStringERKNS1_6StringE
-__ZN7WebCore13HTTPHeaderMap6removeEPKc
+__ZN7WebCore13HTTPHeaderMap6removeENS_14HTTPHeaderNameE
 __ZN7WebCore13HTTPHeaderMapC1Ev
 __ZN7WebCore13HTTPHeaderMapD1Ev
 __ZN7WebCore13HitTestResultC1ERKNS_11LayoutPointE
index 0aea705..4062e91 100644 (file)
                1AB1AE7B0C051FDE00139F4F /* zoomOutCursor.png in Resources */ = {isa = PBXBuildFile; fileRef = 1AB1AE790C051FDE00139F4F /* zoomOutCursor.png */; };
                1AB33DA512551E320024457A /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AB33DA412551E320024457A /* IOKit.framework */; };
                1AB5EBD0194A1D170059AC70 /* ShapeValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB5EBCF194A1D170059AC70 /* ShapeValue.cpp */; };
+               1AB5EBD2194A50F30059AC70 /* HTTPHeaderNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC900C21943C0A0008625B5 /* HTTPHeaderNames.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1AB7FC680A8B92EC00D9D37B /* XPathEvaluator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB7FC470A8B92EC00D9D37B /* XPathEvaluator.cpp */; };
                1AB7FC690A8B92EC00D9D37B /* XPathEvaluator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AB7FC480A8B92EC00D9D37B /* XPathEvaluator.h */; };
                1AB7FC6B0A8B92EC00D9D37B /* XPathExpression.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AB7FC4A0A8B92EC00D9D37B /* XPathExpression.cpp */; };
                                CDC69DD61632026C007C38DF /* WebCoreFullScreenWarningView.h in Headers */,
                                CD127DEE14F3098400E84779 /* WebCoreFullScreenWindow.h in Headers */,
                                BC53D911114310CC000D817E /* WebCoreJSClientData.h in Headers */,
+                               1AB5EBD2194A50F30059AC70 /* HTTPHeaderNames.h in Headers */,
                                93F199BB08245E59001E9ABC /* WebCoreKeyboardUIMode.h in Headers */,
                                3140379B124BEA7F00AF40E4 /* WebCoreMotionManager.h in Headers */,
                                934D9BA70B8C1175007B42A9 /* WebCoreNSStringExtras.h in Headers */,
index e39f928..54ce072 100644 (file)
@@ -31,7 +31,9 @@
 #include "config.h"
 #include "HTTPHeaderMap.h"
 
+#include "HTTPHeaderNames.h"
 #include <utility>
+#include <wtf/text/StringView.h>
 
 namespace WebCore {
 
@@ -97,6 +99,11 @@ struct CaseFoldingCStringTranslator {
     }
 };
 
+bool HTTPHeaderMap::contains(HTTPHeaderName name) const
+{
+    return m_headers.contains(httpHeaderNameString(name).toStringWithoutCopying());
+}
+
 String HTTPHeaderMap::get(const char* name) const
 {
     auto it = find(name);
@@ -104,20 +111,15 @@ String HTTPHeaderMap::get(const char* name) const
         return String();
     return it->value;
 }
-    
-bool HTTPHeaderMap::contains(const char* name) const
-{
-    return find(name) != end();
-}
 
 HTTPHeaderMap::const_iterator HTTPHeaderMap::find(const char* name) const
 {
     return m_headers.find<CaseFoldingCStringTranslator>(name);
 }
 
-bool HTTPHeaderMap::remove(const char* name)
+bool HTTPHeaderMap::remove(HTTPHeaderName name)
 {
-    return m_headers.remove(m_headers.find<CaseFoldingCStringTranslator>(name));
+    return m_headers.remove(httpHeaderNameString(name).toStringWithoutCopying());
 }
 
 } // namespace WebCore
index caad785..7f8922a 100644 (file)
@@ -36,6 +36,8 @@
 
 namespace WebCore {
 
+enum class HTTPHeaderName;
+
 typedef Vector<std::pair<String, String>> CrossThreadHTTPHeaderMapData;
 
 // FIXME: Not every header fits into a map. Notably, multiple Set-Cookie header fields are needed to set multiple cookies.
@@ -58,15 +60,17 @@ public:
     void clear() { m_headers.clear(); }
 
     String get(const AtomicString& name) const;
-
     void set(const AtomicString& name, const String& value);
     void add(const AtomicString& name, const String& value);
 
-    // Alternate accessors that are faster than converting the char* to AtomicString first.
-    bool contains(const char*) const;
+    bool contains(HTTPHeaderName) const;
     String get(const char*) const;
     const_iterator find(const char*) const;
-    bool remove(const char*);
+    bool remove(HTTPHeaderName);
+
+    // Instead of passing a string literal to any of these functions, just use a HTTPHeaderName instead.
+    template<size_t length> bool contains(const char (&)[length]) = delete;
+    template<size_t length> bool remove(const char (&)[length]) = delete;
 
     const_iterator begin() const { return m_headers.begin(); }
     const_iterator end() const { return m_headers.end(); }
@@ -82,7 +86,7 @@ public:
     }
 
 private:
-    HashMap<AtomicString, String, CaseFoldingHash> m_headers;
+    HashMapType m_headers;
 };
 
 } // namespace WebCore
index 549b173..0491d93 100644 (file)
 //
 
 Accept
+Authorization
+Content-Length
+Content-Type
+If-Match
+If-Modified-Since
+If-None-Match
+If-Range
+If-Unmodified-Since
 Location
+Origin
+Referer
+User-Agent
\ No newline at end of file
index fcad2c7..79b26ed 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "ResourceRequestBase.h"
 
+#include "HTTPHeaderNames.h"
 #include "ResourceRequest.h"
 #include <wtf/PassOwnPtr.h>
 
@@ -264,7 +265,7 @@ void ResourceRequestBase::clearHTTPAuthorization()
 {
     updateResourceRequest(); 
 
-    if (!m_httpHeaderFields.remove("Authorization"))
+    if (!m_httpHeaderFields.remove(HTTPHeaderName::Authorization))
         return;
 
     if (url().protocolIsInHTTPFamily())
@@ -285,7 +286,7 @@ void ResourceRequestBase::clearHTTPContentType()
 {
     updateResourceRequest(); 
 
-    m_httpHeaderFields.remove("Content-Type");
+    m_httpHeaderFields.remove(HTTPHeaderName::ContentType);
 
     if (url().protocolIsInHTTPFamily())
         m_platformRequestUpdated = false;
@@ -305,7 +306,7 @@ void ResourceRequestBase::clearHTTPReferrer()
 {
     updateResourceRequest(); 
 
-    m_httpHeaderFields.remove("Referer");
+    m_httpHeaderFields.remove(HTTPHeaderName::Referer);
 
     if (url().protocolIsInHTTPFamily())
         m_platformRequestUpdated = false;
@@ -325,7 +326,7 @@ void ResourceRequestBase::clearHTTPOrigin()
 {
     updateResourceRequest(); 
 
-    m_httpHeaderFields.remove("Origin");
+    m_httpHeaderFields.remove(HTTPHeaderName::Origin);
 
     if (url().protocolIsInHTTPFamily())
         m_platformRequestUpdated = false;
@@ -345,7 +346,7 @@ void ResourceRequestBase::clearHTTPUserAgent()
 {
     updateResourceRequest(); 
 
-    m_httpHeaderFields.remove("User-Agent");
+    m_httpHeaderFields.remove(HTTPHeaderName::UserAgent);
 
     if (url().protocolIsInHTTPFamily())
         m_platformRequestUpdated = false;
@@ -365,7 +366,7 @@ void ResourceRequestBase::clearHTTPAccept()
 {
     updateResourceRequest(); 
 
-    m_httpHeaderFields.remove("Accept");
+    m_httpHeaderFields.remove(HTTPHeaderName::Accept);
 
     if (url().protocolIsInHTTPFamily())
         m_platformRequestUpdated = false;
@@ -511,22 +512,28 @@ bool ResourceRequestBase::compare(const ResourceRequest& a, const ResourceReques
     return ResourceRequest::platformCompare(a, b);
 }
 
+static const HTTPHeaderName conditionalHeaderNames[] = {
+    HTTPHeaderName::IfMatch,
+    HTTPHeaderName::IfModifiedSince,
+    HTTPHeaderName::IfNoneMatch,
+    HTTPHeaderName::IfRange,
+    HTTPHeaderName::IfUnmodifiedSince
+};
+
 bool ResourceRequestBase::isConditional() const
 {
-    return (m_httpHeaderFields.contains("If-Match") ||
-            m_httpHeaderFields.contains("If-Modified-Since") ||
-            m_httpHeaderFields.contains("If-None-Match") ||
-            m_httpHeaderFields.contains("If-Range") ||
-            m_httpHeaderFields.contains("If-Unmodified-Since"));
+    for (auto headerName : conditionalHeaderNames) {
+        if (m_httpHeaderFields.contains(headerName))
+            return true;
+    }
+
+    return false;
 }
 
 void ResourceRequestBase::makeUnconditional()
 {
-    m_httpHeaderFields.remove("If-Match");
-    m_httpHeaderFields.remove("If-Modified-Since");
-    m_httpHeaderFields.remove("If-None-Match");
-    m_httpHeaderFields.remove("If-Range");
-    m_httpHeaderFields.remove("If-Unmodified-Since");
+    for (auto headerName : conditionalHeaderNames)
+        m_httpHeaderFields.remove(headerName);
 }
 
 double ResourceRequestBase::defaultTimeoutInterval()
index 948c390..b808b42 100644 (file)
@@ -44,6 +44,7 @@
 #include "GraphicsContext.h"
 #include "HTMLNames.h"
 #include "HTMLPlugInElement.h"
+#include "HTTPHeaderNames.h"
 #include "Image.h"
 #include "JSDOMBinding.h"
 #include "JSDOMWindow.h"
@@ -1165,7 +1166,7 @@ NPError PluginView::handlePost(const char* url, const char* target, uint32_t len
 
                 if (!contentLength.isNull())
                     dataLength = min(contentLength.toInt(), (int)dataLength);
-                headerFields.remove("Content-Length");
+                headerFields.remove(HTTPHeaderName::ContentLength);
 
                 postData += location;
                 postDataLength = dataLength;
index ba3e0ad..a706eb4 100644 (file)
@@ -1,3 +1,14 @@
+2014-06-12  Anders Carlsson  <andersca@apple.com>
+
+        Add overloads of HTTPHeaderMap::find and remove that take enums
+        https://bugs.webkit.org/show_bug.cgi?id=133823
+
+        Reviewed by Sam Weinig.
+
+        * WebProcess/Plugins/Netscape/NetscapeBrowserFuncs.cpp:
+        (WebKit::parsePostBuffer):
+        Update for WebCore changes.
+
 2014-06-12  Benjamin Poulain  <bpoulain@apple.com>
 
         [iOS][WK2] Do not update the viewport configuration on load until the first viewport arguments is received
index 2f70743..a0da448 100644 (file)
@@ -32,6 +32,7 @@
 #include "NetscapePlugin.h"
 #include "PluginController.h"
 #include <WebCore/HTTPHeaderMap.h>
+#include <WebCore/HTTPHeaderNames.h>
 #include <WebCore/IdentifierRep.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ProtectionSpace.h>
@@ -249,11 +250,10 @@ static NPError parsePostBuffer(bool isFile, const char *buffer, uint32_t length,
                 
                 if (!contentLength.isNull())
                     dataLength = std::min(contentLength.toInt(), (int)dataLength);
-                headerFields.remove("Content-Length");
+                headerFields.remove(HTTPHeaderName::ContentLength);
                 
                 postBuffer += location;
                 postBufferSize = dataLength;
-                
             }
         }
     }