Set minimum priority for fast lane connections
[WebKit-https.git] / Source / WebCore / platform / network / cf / ResourceRequestCFNet.cpp
index 410a649..0a0bc7c 100644 (file)
 #include "config.h"
 #include "ResourceRequestCFNet.h"
 
-#if USE(CFNETWORK)
-
-#include "FormDataStreamCFNet.h"
 #include "ResourceRequest.h"
 
+#if PLATFORM(MAC)
+#include "ResourceLoadPriority.h"
+#include "WebCoreSystemInterface.h"
+#endif
+
+#if USE(CFNETWORK)
+#include "FormDataStreamCFNet.h"
 #include <CFNetwork/CFURLRequestPriv.h>
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
+#endif
 
 namespace WebCore {
 
+#if USE(CFNETWORK)
+
 typedef void (*CFURLRequestSetContentDispositionEncodingFallbackArrayFunction)(CFMutableURLRequestRef, CFArrayRef);
 typedef CFArrayRef (*CFURLRequestCopyContentDispositionEncodingFallbackArrayFunction)(CFURLRequestRef);
 
@@ -189,12 +196,56 @@ void ResourceRequest::doUpdateResourceRequest()
     m_httpBody = httpBodyFromRequest(m_cfRequest.get());
 }
 
+#if USE(CFURLSTORAGESESSIONS)
+
+void ResourceRequest::setStorageSession(CFURLStorageSessionRef storageSession)
+{
+    CFMutableURLRequestRef cfRequest = CFURLRequestCreateMutableCopy(0, m_cfRequest.get());
+    wkSetRequestStorageSession(storageSession, cfRequest);
+    m_cfRequest.adoptCF(cfRequest);
+}
+
+#endif
+
+#endif // USE(CFNETWORK)
+
 unsigned initializeMaximumHTTPConnectionCountPerHost()
 {
     static const unsigned preferredConnectionCount = 6;
-    return wkInitializeMaximumHTTPConnectionCountPerHost(preferredConnectionCount);
+    static const unsigned unlimitedConnectionCount = 10000;
+
+    // Always set the connection count per host, even when pipelining.
+    unsigned maximumHTTPConnectionCountPerHost = wkInitializeMaximumHTTPConnectionCountPerHost(preferredConnectionCount);
+
+#if PLATFORM(MAC)
+    if (isHTTPPipeliningEnabled()) {
+        wkSetHTTPPipeliningMaximumPriority(ResourceLoadPriorityHighest);
+        wkSetHTTPPipeliningMinimumFastLanePriority(ResourceLoadPriorityMedium);
+        // When pipelining do not rate-limit requests sent from WebCore since CFNetwork handles that.
+        return unlimitedConnectionCount;
+    }
+#endif
+
+    return maximumHTTPConnectionCountPerHost;
 }
 
-} // namespace WebCore
+static inline bool readBooleanPreference(CFStringRef key)
+{
+    Boolean keyExistsAndHasValidFormat;
+    Boolean result = CFPreferencesGetAppBooleanValue(key, kCFPreferencesCurrentApplication, &keyExistsAndHasValidFormat);
+    return keyExistsAndHasValidFormat ? result : false;
+}
 
-#endif // USE(CFNETWORK)
+bool isHTTPPipeliningEnabled()
+{
+    static bool isEnabled = readBooleanPreference(CFSTR("WebKitEnableHTTPPipelining"));
+    return isEnabled;
+}
+
+bool shouldForceHTTPPipeliningPriorityHigh()
+{
+    static bool shouldForcePriorityHigh = readBooleanPreference(CFSTR("WebKitForceHTTPPipeliningPriorityHigh"));
+    return shouldForcePriorityHigh;
+}
+
+} // namespace WebCore