Serialize ResourceRequests without platform request
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jun 2014 19:07:47 +0000 (19:07 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jun 2014 19:07:47 +0000 (19:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133679

Reviewed by Alexey Proskuryakov.

Source/WebCore:
We create platform requests in the web process just so we can serialize them. This is unnecessary work.

* platform/network/ResourceRequestBase.h:
(WebCore::ResourceRequestBase::encodingRequiresPlatformData):
(WebCore::ResourceRequestBase::encodeWithoutPlatformData):
(WebCore::ResourceRequestBase::decodeWithoutPlatformData):

    Add encoding and decoding functions here to avoid exposing internals.

* platform/network/cf/ResourceRequest.h:
(WebCore::ResourceRequest::encodingRequiresPlatformData):

    Allow encoding without platform data if it hasn't been created yet and there is no request body.

Source/WebKit2:
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<ResourceRequest>::encode):
(IPC::ArgumentCoder<ResourceRequest>::decode):

    Encode ResourceRequest directly if possible.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/ResourceRequestBase.h
Source/WebCore/platform/network/cf/ResourceRequest.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

index 9d0e509..7be1741 100644 (file)
@@ -1,3 +1,24 @@
+2014-06-10  Antti Koivisto  <antti@apple.com>
+
+        Serialize ResourceRequests without platform request
+        https://bugs.webkit.org/show_bug.cgi?id=133679
+
+        Reviewed by Alexey Proskuryakov.
+
+        We create platform requests in the web process just so we can serialize them. This is unnecessary work.
+
+        * platform/network/ResourceRequestBase.h:
+        (WebCore::ResourceRequestBase::encodingRequiresPlatformData):
+        (WebCore::ResourceRequestBase::encodeWithoutPlatformData):
+        (WebCore::ResourceRequestBase::decodeWithoutPlatformData):
+        
+            Add encoding and decoding functions here to avoid exposing internals.
+
+        * platform/network/cf/ResourceRequest.h:
+        (WebCore::ResourceRequest::encodingRequiresPlatformData):
+        
+            Allow encoding without platform data if it hasn't been created yet and there is no request body.
+
 2014-06-10  Brady Eidson  <beidson@apple.com>
 
         Send more context about text selection to telephone number scanner
index 6c48398..c1fb18b 100644 (file)
@@ -143,6 +143,12 @@ namespace WebCore {
         void setHiddenFromInspector(bool hiddenFromInspector) { m_hiddenFromInspector = hiddenFromInspector; }
 #endif
 
+#if !PLATFORM(COCOA)
+        bool encodingRequiresPlatformData() const { return true; }
+#endif
+        template<class Encoder> void encodeWithoutPlatformData(Encoder&) const;
+        template<class Decoder> bool decodeWithoutPlatformData(Decoder&);
+
         static double defaultTimeoutInterval(); // May return 0 when using platform default.
         static void setDefaultTimeoutInterval(double);
 
@@ -257,6 +263,66 @@ namespace WebCore {
 #if PLATFORM(IOS)
     void initializeHTTPConnectionSettingsOnStartup();
 #endif
+
+template<class Encoder>
+void ResourceRequestBase::encodeWithoutPlatformData(Encoder& encoder) const
+{
+    ASSERT(!m_httpBody);
+    ASSERT(!m_platformRequestUpdated);
+    encoder << m_url.string();
+    encoder << m_timeoutInterval;
+    encoder << m_firstPartyForCookies.string();
+    encoder << m_httpMethod;
+    encoder << m_httpHeaderFields;
+    encoder << m_responseContentDispositionEncodingFallbackArray;
+    encoder.encodeEnum(m_cachePolicy);
+    encoder << m_allowCookies;
+    encoder.encodeEnum(m_priority);
+}
+
+template<class Decoder>
+bool ResourceRequestBase::decodeWithoutPlatformData(Decoder& decoder)
+{
+    String url;
+    if (!decoder.decode(url))
+        return false;
+    m_url = URL(ParsedURLString, url);
+
+    if (!decoder.decode(m_timeoutInterval))
+        return false;
+
+    String firstPartyForCookies;
+    if (!decoder.decode(firstPartyForCookies))
+        return false;
+    m_firstPartyForCookies = URL(ParsedURLString, firstPartyForCookies);
+
+    if (!decoder.decode(m_httpMethod))
+        return false;
+
+    if (!decoder.decode(m_httpHeaderFields))
+        return false;
+
+    if (!decoder.decode(m_responseContentDispositionEncodingFallbackArray))
+        return false;
+
+    ResourceRequestCachePolicy cachePolicy;
+    if (!decoder.decodeEnum(cachePolicy))
+        return false;
+    m_cachePolicy = cachePolicy;
+
+    bool allowCookies;
+    if (!decoder.decode(allowCookies))
+        return false;
+    m_allowCookies = allowCookies;
+
+    ResourceLoadPriority priority;
+    if (!decoder.decodeEnum(priority))
+        return false;
+    m_priority = priority;
+
+    return true;
+}
+
 } // namespace WebCore
 
 #endif // ResourceRequestBase_h
index 93e5ac3..c2a6613 100644 (file)
@@ -108,6 +108,7 @@ namespace WebCore {
         void applyWebArchiveHackForMail();
 #endif
 #if PLATFORM(COCOA)
+        bool encodingRequiresPlatformData() const { return m_httpBody || m_nsRequest; }
         NSURLRequest *nsURLRequest(HTTPBodyUpdatePolicy) const;
 #endif
 
index 97e647e..328638d 100644 (file)
@@ -1,3 +1,16 @@
+2014-06-10  Antti Koivisto  <antti@apple.com>
+
+        Serialize ResourceRequests without platform request
+        https://bugs.webkit.org/show_bug.cgi?id=133679
+
+        Reviewed by Alexey Proskuryakov.
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<ResourceRequest>::encode):
+        (IPC::ArgumentCoder<ResourceRequest>::decode):
+        
+            Encode ResourceRequest directly if possible.
+
 2014-06-09  Anders Carlsson  <andersca@apple.com>
 
         Fix build.
index 7273223..648338d 100644 (file)
@@ -675,7 +675,13 @@ void ArgumentCoder<ResourceRequest>::encode(ArgumentEncoder& encoder, const Reso
     encoder << resourceRequest.hiddenFromInspector();
 #endif
 
-    encodePlatformData(encoder, resourceRequest);
+    if (resourceRequest.encodingRequiresPlatformData()) {
+        encoder << true;
+        encodePlatformData(encoder, resourceRequest);
+        return;
+    }
+    encoder << false;
+    resourceRequest.encodeWithoutPlatformData(encoder);
 }
 
 bool ArgumentCoder<ResourceRequest>::decode(ArgumentDecoder& decoder, ResourceRequest& resourceRequest)
@@ -730,7 +736,13 @@ bool ArgumentCoder<ResourceRequest>::decode(ArgumentDecoder& decoder, ResourceRe
     resourceRequest.setHiddenFromInspector(isHiddenFromInspector);
 #endif
 
-    return decodePlatformData(decoder, resourceRequest);
+    bool hasPlatformData;
+    if (!decoder.decode(hasPlatformData))
+        return false;
+    if (hasPlatformData)
+        return decodePlatformData(decoder, resourceRequest);
+
+    return resourceRequest.decodeWithoutPlatformData(decoder);
 }
 
 void ArgumentCoder<ResourceResponse>::encode(ArgumentEncoder& encoder, const ResourceResponse& resourceResponse)