Title: [199682] trunk/Source
Revision
199682
Author
[email protected]
Date
2016-04-18 11:49:56 -0700 (Mon, 18 Apr 2016)

Log Message

[WK2][iOS] Only adjust network responses' MIME type for QuickLook in the context of a main resource load
https://bugs.webkit.org/show_bug.cgi?id=156639
<rdar://problem/25765848>

Reviewed by Alex Christensen.

Source/WebCore:

Only adjust network responses' MIME type for QuickLook in the context of a main
resource load since we can only preview main resources with QuickLook. This
avoids doing unnecessary work during page load. Also, this makes it a lot less
likely to dlopen() the QuickLook library during page load since we now only
adjust MIME type for QuickLook for main resources, and main resources usually
have the well-known 'text/html' MIME type for which we know we will not use
QuickLook.

After this change, we no longer need to dlopen() the QuickLook library in the
NetworkProcess in the context of the PLT. We would previously dlopen() the
library during the first page load, thus significantly slowing it down. As a
result, we see a ~22% speed up in the PLT's first page load and a 0.9-1% overall
PLT progression.

* platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveResponse):
Pass flag to adjustMIMETypeIfNecessary() indicated if this is a main resource load.

* platform/network/ios/WebCoreURLResponseIOS.mm:
(WebCore::adjustMIMETypeIfNecessary):
Only adjust the MIME type for QuickLook if the isMainResourceLoad parameter is true.

* platform/network/mac/WebCoreResourceHandleAsDelegate.mm:
(-[WebCoreResourceHandleAsDelegate connection:didReceiveResponse:]):
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveResponse:]):
Only adjust the MIME type for QuickLook if the isMainResourceLoad parameter is true.

* platform/network/mac/WebCoreURLResponse.h:
* platform/network/mac/WebCoreURLResponse.mm:
(WebCore::adjustMIMETypeIfNecessary):

Source/WebKit2:

* NetworkProcess/NetworkDataTask.h:
(WebKit::NetworkDataTask::firstRequest):
Add getter to return the first request.

* NetworkProcess/cocoa/NetworkSessionCocoa.mm:
(-[WKNetworkSessionDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]):
Pass flag to adjustMIMETypeIfNecessary() indicated if this is a main resource load.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (199681 => 199682)


--- trunk/Source/WebCore/ChangeLog	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/ChangeLog	2016-04-18 18:49:56 UTC (rev 199682)
@@ -1,3 +1,43 @@
+2016-04-18  Chris Dumez  <[email protected]>
+
+        [WK2][iOS] Only adjust network responses' MIME type for QuickLook in the context of a main resource load
+        https://bugs.webkit.org/show_bug.cgi?id=156639
+        <rdar://problem/25765848>
+
+        Reviewed by Alex Christensen.
+
+        Only adjust network responses' MIME type for QuickLook in the context of a main
+        resource load since we can only preview main resources with QuickLook. This
+        avoids doing unnecessary work during page load. Also, this makes it a lot less
+        likely to dlopen() the QuickLook library during page load since we now only
+        adjust MIME type for QuickLook for main resources, and main resources usually
+        have the well-known 'text/html' MIME type for which we know we will not use
+        QuickLook.
+
+        After this change, we no longer need to dlopen() the QuickLook library in the
+        NetworkProcess in the context of the PLT. We would previously dlopen() the
+        library during the first page load, thus significantly slowing it down. As a
+        result, we see a ~22% speed up in the PLT's first page load and a 0.9-1% overall
+        PLT progression.
+
+        * platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:
+        (WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveResponse):
+        Pass flag to adjustMIMETypeIfNecessary() indicated if this is a main resource load.
+
+        * platform/network/ios/WebCoreURLResponseIOS.mm:
+        (WebCore::adjustMIMETypeIfNecessary):
+        Only adjust the MIME type for QuickLook if the isMainResourceLoad parameter is true.
+
+        * platform/network/mac/WebCoreResourceHandleAsDelegate.mm:
+        (-[WebCoreResourceHandleAsDelegate connection:didReceiveResponse:]):
+        * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
+        (-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveResponse:]):
+        Only adjust the MIME type for QuickLook if the isMainResourceLoad parameter is true.
+
+        * platform/network/mac/WebCoreURLResponse.h:
+        * platform/network/mac/WebCoreURLResponse.mm:
+        (WebCore::adjustMIMETypeIfNecessary):
+
 2016-04-18  Brent Fulgham  <[email protected]>
 
         CSP: Remove stubs for dynamically-added favicons (via link rel="icon")

Modified: trunk/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp (199681 => 199682)


--- trunk/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp	2016-04-18 18:49:56 UTC (rev 199682)
@@ -144,8 +144,10 @@
         auto msg = CFURLResponseGetHTTPResponse(cfResponse);
         int statusCode = msg ? CFHTTPMessageGetResponseStatusCode(msg) : 0;
 
-        if (statusCode != 304)
-            adjustMIMETypeIfNecessary(cfResponse);
+        if (statusCode != 304) {
+            bool isMainResourceLoad = m_handle->firstRequest().requester() == ResourceRequest::Requester::Main;
+            adjustMIMETypeIfNecessary(cfResponse, isMainResourceLoad);
+        }
 
 #if !PLATFORM(IOS)
         if (_CFURLRequestCopyProtocolPropertyForKey(m_handle->firstRequest().cfURLRequest(DoNotUpdateHTTPBody), CFSTR("ForceHTMLMIMEType")))

Modified: trunk/Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm (199681 => 199682)


--- trunk/Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/platform/network/ios/WebCoreURLResponseIOS.mm	2016-04-18 18:49:56 UTC (rev 199682)
@@ -46,7 +46,7 @@
 
 namespace WebCore {
 
-void adjustMIMETypeIfNecessary(CFURLResponseRef cfResponse)
+void adjustMIMETypeIfNecessary(CFURLResponseRef cfResponse, bool isMainResourceLoad)
 {
     RetainPtr<CFStringRef> mimeType = CFURLResponseGetMIMEType(cfResponse);
     RetainPtr<CFStringRef> updatedMIMEType = mimeType;
@@ -56,7 +56,7 @@
 #if USE(QUICK_LOOK)
     // We must ensure that the MIME type is correct, so that QuickLook's web plugin is called when needed.
     // We filter the basic MIME types so that we don't do unnecessary work in standard browsing situations.
-    if (shouldUseQuickLookForMIMEType((NSString *)updatedMIMEType.get())) {
+    if (isMainResourceLoad && shouldUseQuickLookForMIMEType((NSString *)updatedMIMEType.get())) {
         RetainPtr<CFStringRef> suggestedFilename = adoptCF(CFURLResponseCopySuggestedFilename(cfResponse));
         RetainPtr<CFStringRef> quickLookMIMEType = adoptCF((CFStringRef)QLTypeCopyBestMimeTypeForFileNameAndMimeType((NSString *)suggestedFilename.get(), (NSString *)mimeType.get()));
         if (!quickLookMIMEType) {
@@ -73,6 +73,8 @@
         if (quickLookMIMEType)
             updatedMIMEType = quickLookMIMEType;
     }
+#else
+    UNUSED_PARAM(isMainResourceLoad);
 #endif // USE(QUICK_LOOK)
     if (!mimeType || CFStringCompare(mimeType.get(), updatedMIMEType.get(), kCFCompareCaseInsensitive) != kCFCompareEqualTo)
         CFURLResponseSetMIMEType(cfResponse, updatedMIMEType.get());

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsDelegate.mm (199681 => 199682)


--- trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsDelegate.mm	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsDelegate.mm	2016-04-18 18:49:56 UTC (rev 199682)
@@ -153,8 +153,10 @@
 
     // Avoid MIME type sniffing if the response comes back as 304 Not Modified.
     int statusCode = [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0;
-    if (statusCode != 304)
-        adjustMIMETypeIfNecessary([r _CFURLResponse]);
+    if (statusCode != 304) {
+        bool isMainResourceLoad = m_handle->firstRequest().requester() == ResourceRequest::Requester::Main;
+        adjustMIMETypeIfNecessary([r _CFURLResponse], isMainResourceLoad);
+    }
 
 #if !PLATFORM(IOS)
     if ([m_handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) _propertyForKey:@"ForceHTMLMIMEType"])

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm (199681 => 199682)


--- trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm	2016-04-18 18:49:56 UTC (rev 199682)
@@ -203,8 +203,10 @@
 
         // Avoid MIME type sniffing if the response comes back as 304 Not Modified.
         int statusCode = [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0;
-        if (statusCode != 304)
-            adjustMIMETypeIfNecessary([r _CFURLResponse]);
+        if (statusCode != 304) {
+            bool isMainResourceLoad = m_handle->firstRequest().requester() == ResourceRequest::Requester::Main;
+            adjustMIMETypeIfNecessary([r _CFURLResponse], isMainResourceLoad);
+        }
 
         if ([m_handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) _propertyForKey:@"ForceHTMLMIMEType"])
             [r _setMIMEType:@"text/html"];

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.h (199681 => 199682)


--- trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.h	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.h	2016-04-18 18:49:56 UTC (rev 199682)
@@ -43,5 +43,5 @@
 #endif // __OBJC__
 
 namespace WebCore {
-WEBCORE_EXPORT void adjustMIMETypeIfNecessary(CFURLResponseRef);
+WEBCORE_EXPORT void adjustMIMETypeIfNecessary(CFURLResponseRef, bool isMainResourceLoad);
 }

Modified: trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm (199681 => 199682)


--- trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebCore/platform/network/mac/WebCoreURLResponse.mm	2016-04-18 18:49:56 UTC (rev 199682)
@@ -286,8 +286,9 @@
     return CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys, (const void**)&values, sizeof(keys)/sizeof(CFStringRef), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 }
 
-void adjustMIMETypeIfNecessary(CFURLResponseRef cfResponse)
+void adjustMIMETypeIfNecessary(CFURLResponseRef cfResponse, bool isMainResourceLoad)
 {
+    UNUSED_PARAM(isMainResourceLoad);
     RetainPtr<CFStringRef> result = CFURLResponseGetMIMEType(cfResponse);
     RetainPtr<CFStringRef> originalResult = result;
 

Modified: trunk/Source/WebKit2/ChangeLog (199681 => 199682)


--- trunk/Source/WebKit2/ChangeLog	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebKit2/ChangeLog	2016-04-18 18:49:56 UTC (rev 199682)
@@ -1,3 +1,19 @@
+2016-04-18  Chris Dumez  <[email protected]>
+
+        [WK2][iOS] Only adjust network responses' MIME type for QuickLook in the context of a main resource load
+        https://bugs.webkit.org/show_bug.cgi?id=156639
+        <rdar://problem/25765848>
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/NetworkDataTask.h:
+        (WebKit::NetworkDataTask::firstRequest):
+        Add getter to return the first request.
+
+        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
+        (-[WKNetworkSessionDelegate URLSession:dataTask:didReceiveResponse:completionHandler:]):
+        Pass flag to adjustMIMETypeIfNecessary() indicated if this is a main resource load.
+
 2016-04-18  Brian Burg  <[email protected]>
 
         Web Automation: provide detailed error messages when an automation command fails

Modified: trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h (199681 => 199682)


--- trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkDataTask.h	2016-04-18 18:49:56 UTC (rev 199682)
@@ -123,6 +123,7 @@
     void setPendingDownloadLocation(const String& filename, const SandboxExtension::Handle&);
     const String& pendingDownloadLocation() { return m_pendingDownloadLocation; }
 
+    const WebCore::ResourceRequest& firstRequest() const { return m_firstRequest; }
     WebCore::ResourceRequest currentRequest();
     String suggestedFilename();
     void willPerformHTTPRedirection(const WebCore::ResourceResponse&, WebCore::ResourceRequest&&, RedirectCompletionHandler);

Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm (199681 => 199682)


--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-04-18 18:41:33 UTC (rev 199681)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkSessionCocoa.mm	2016-04-18 18:49:56 UTC (rev 199682)
@@ -206,9 +206,11 @@
         
         // Avoid MIME type sniffing if the response comes back as 304 Not Modified.
         int statusCode = [response respondsToSelector:@selector(statusCode)] ? [(id)response statusCode] : 0;
-        if (statusCode != 304)
-            WebCore::adjustMIMETypeIfNecessary(response._CFURLResponse);
-        
+        if (statusCode != 304) {
+            bool isMainResourceLoad = networkDataTask->firstRequest().requester() == WebCore::ResourceRequest::Requester::Main;
+            WebCore::adjustMIMETypeIfNecessary(response._CFURLResponse, isMainResourceLoad);
+        }
+
         WebCore::ResourceResponse resourceResponse(response);
         copyTimingData([dataTask _timingData], resourceResponse.resourceLoadTiming());
         auto completionHandlerCopy = Block_copy(completionHandler);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to