Use asynchronous ResourceHandleClient calls for WebKit1
https://bugs.webkit.org/show_bug.cgi?id=160677

Reviewed by Brady Eidson.

Source/WebCore:

Covered by existing tests.

* PlatformAppleWin.cmake:
* PlatformMac.cmake:
* WebCore.xcodeproj/project.pbxproj:
* loader/ResourceLoader.cpp:
(WebCore::ResourceLoader::willSendRequestAsync):
(WebCore::ResourceLoader::didReceiveResponseAsync):
(WebCore::ResourceLoader::canAuthenticateAgainstProtectionSpaceAsync):
* loader/ResourceLoader.h:
* loader/appcache/ApplicationCacheGroup.cpp:
(WebCore::ApplicationCacheGroup::didReceiveResponseAsync):
(WebCore::ApplicationCacheGroup::willSendRequestAsync):
(WebCore::ApplicationCacheGroup::canAuthenticateAgainstProtectionSpaceAsync):
(WebCore::ApplicationCacheGroup::didReceiveResponse): Deleted.
* loader/appcache/ApplicationCacheGroup.h:
* platform/network/BlobResourceHandle.cpp:
(WebCore::BlobResourceHandle::continueDidReceiveResponse):
(WebCore::BlobResourceHandle::getSizeForNext):
(WebCore::BlobResourceHandle::notifyResponseOnSuccess):
(WebCore::BlobResourceHandle::notifyResponseOnError):
* platform/network/PingHandle.h:
* platform/network/ResourceHandle.cpp:
(WebCore::ResourceHandle::didReceiveResponse):
(WebCore::ResourceHandle::usesAsyncCallbacks): Deleted.
* platform/network/ResourceHandle.h:
* platform/network/ResourceHandleClient.cpp:
(WebCore::ResourceHandleClient::~ResourceHandleClient):
(WebCore::ResourceHandleClient::willSendRequest): Deleted.
(WebCore::ResourceHandleClient::willSendRequestAsync): Deleted.
(WebCore::ResourceHandleClient::didReceiveResponseAsync): Deleted.
(WebCore::ResourceHandleClient::canAuthenticateAgainstProtectionSpaceAsync): Deleted.
* platform/network/ResourceHandleClient.h:
(WebCore::ResourceHandleClient::didReceiveAuthenticationChallenge):
(WebCore::ResourceHandleClient::didReceiveResponse): Deleted.
(WebCore::ResourceHandleClient::usesAsyncCallbacks): Deleted.
(WebCore::ResourceHandleClient::canAuthenticateAgainstProtectionSpace): Deleted.
* platform/network/ResourceHandleInternal.h:
(WebCore::ResourceHandleInternal::ResourceHandleInternal):
* platform/network/SynchronousLoaderClient.cpp:
(WebCore::SynchronousLoaderClient::willSendRequestAsync):
(WebCore::SynchronousLoaderClient::canAuthenticateAgainstProtectionSpaceAsync):
(WebCore::SynchronousLoaderClient::didReceiveResponseAsync):
(WebCore::SynchronousLoaderClient::didFinishLoading):
(WebCore::SynchronousLoaderClient::didFail):
(WebCore::SynchronousLoaderClient::willSendRequest): Deleted.
(WebCore::SynchronousLoaderClient::canAuthenticateAgainstProtectionSpace): Deleted.
(WebCore::SynchronousLoaderClient::didReceiveResponse): Deleted.
* platform/network/SynchronousLoaderClient.h:
* platform/network/cf/ResourceHandleCFNet.cpp:
(WebCore::ResourceHandle::createCFURLConnection):
(WebCore::ResourceHandle::start):
(WebCore::ResourceHandle::willSendRequest):
(WebCore::ResourceHandle::shouldUseCredentialStorage):
(WebCore::ResourceHandle::canAuthenticateAgainstProtectionSpace):
(WebCore::ResourceHandle::platformLoadResourceSynchronously):
* platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.cpp:
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::ResourceHandleCFURLConnectionDelegateWithOperationQueue):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::releaseHandle):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::willSendRequest):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveResponse):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveData):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didFinishLoading):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didFail):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::willCacheResponse):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didReceiveChallenge):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::didSendBodyData):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::shouldUseCredentialStorage):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::canRespondToProtectionSpace):
(WebCore::ResourceHandleCFURLConnectionDelegateWithOperationQueue::continueCanAuthenticateAgainstProtectionSpace):
* platform/network/cf/ResourceHandleCFURLConnectionDelegateWithOperationQueue.h:
* platform/network/cf/SynchronousResourceHandleCFURLConnectionDelegate.cpp: Removed.
* platform/network/cf/SynchronousResourceHandleCFURLConnectionDelegate.h: Removed.
* platform/network/mac/ResourceHandleMac.mm:
(WebCore::ResourceHandle::start):
(WebCore::ResourceHandle::schedule):
(WebCore::ResourceHandle::makeDelegate):
(WebCore::ResourceHandle::delegate):
(WebCore::ResourceHandle::platformLoadResourceSynchronously):
(WebCore::ResourceHandle::willSendRequest):
(WebCore::ResourceHandle::continueWillSendRequest):
(WebCore::ResourceHandle::continueDidReceiveResponse):
(WebCore::ResourceHandle::canAuthenticateAgainstProtectionSpace):
(WebCore::ResourceHandle::continueCanAuthenticateAgainstProtectionSpace):
(WebCore::ResourceHandle::continueWillCacheResponse):
(WebCore::ResourceHandle::shouldUseCredentialStorage): Deleted.
* platform/network/mac/WebCoreResourceHandleAsDelegate.h: Removed.
* platform/network/mac/WebCoreResourceHandleAsDelegate.mm: Removed.
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.h:
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:willSendRequest:redirectResponse:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveAuthenticationChallenge:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:canAuthenticateAgainstProtectionSpace:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveResponse:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:didReceiveData:lengthReceived:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:didFailWithError:]):
(-[WebCoreResourceHandleAsOperationQueueDelegate connection:willCacheResponse:]):

Source/WebKitLegacy:

* WebCoreSupport/WebResourceLoadScheduler.cpp:
(WebResourceLoadScheduler::createPingHandle):

Tools:

* TestWebKitAPI/Tests/mac/SimplifyMarkup.mm:
(TestWebKitAPI::TEST):
The HTML being loaded contains an iframe, so testing if the main resource has loaded doesn't necessarily mean all subresources are loaded.
Wait until they are loaded before continuing the test.  This is a test of editing commands once the page has loaded, not a test of loading.

LayoutTests:

* TestExpectations:
* platform/gtk/TestExpectations:
* platform/ios-wk2/TestExpectations:
* platform/mac-wk2/TestExpectations:
* platform/wk2/TestExpectations:

http/tests/cache/iframe-304-crash.html used to deterministically record its didFinishLoading callback,
but only for WK1.  It was marked as flaky for all WK2 ports.  It is now flaky in WK1 because the order
of the testRunner.notifyDone call and the didFinishLoading logging is no longer deterministic with
asynchronous loading, but the test still verifies that there is no crash.

http/tests/security/cross-origin-modal-dialog-base.html does navigation during showModalDialog, which
probably should've never worked in WK1 and never worked in WK2.  WK1 behavior now matches WK2 behavior.
I'm not aware of any complaints about no navigation working during showModalDialog in WK2 and I imagine
nobody will be regressed by this change, but if we do find such a problem, creative use of MessageQueues
like we do with sync xhr in WK1 now could theoretically fix the problem, but we are trying to get
rid of showModalDialog anyway.  The test was written to verify that the SecurityOrigin doesn't fall back
to the wrong origin, and it certainly doesn't now.

These tests dump load delegate call order, which are less deterministic now but the tests still behave correctly.
http/tests/svg/svg-use-external.html
http/tests/loading/text-content-type-with-binary-extension.html
http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-iframe-in-main-frame.html



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@224267 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index c6ad277..eda63601 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,34 @@
+2017-10-31  Alex Christensen  <achristensen@webkit.org>
+
+        Use asynchronous ResourceHandleClient calls for WebKit1
+        https://bugs.webkit.org/show_bug.cgi?id=160677
+
+        Reviewed by Brady Eidson.
+
+        * TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/ios-wk2/TestExpectations:
+        * platform/mac-wk2/TestExpectations:
+        * platform/wk2/TestExpectations:
+
+        http/tests/cache/iframe-304-crash.html used to deterministically record its didFinishLoading callback,
+        but only for WK1.  It was marked as flaky for all WK2 ports.  It is now flaky in WK1 because the order
+        of the testRunner.notifyDone call and the didFinishLoading logging is no longer deterministic with
+        asynchronous loading, but the test still verifies that there is no crash.
+
+        http/tests/security/cross-origin-modal-dialog-base.html does navigation during showModalDialog, which
+        probably should've never worked in WK1 and never worked in WK2.  WK1 behavior now matches WK2 behavior.
+        I'm not aware of any complaints about no navigation working during showModalDialog in WK2 and I imagine
+        nobody will be regressed by this change, but if we do find such a problem, creative use of MessageQueues
+        like we do with sync xhr in WK1 now could theoretically fix the problem, but we are trying to get
+        rid of showModalDialog anyway.  The test was written to verify that the SecurityOrigin doesn't fall back
+        to the wrong origin, and it certainly doesn't now.
+
+        These tests dump load delegate call order, which are less deterministic now but the tests still behave correctly.
+        http/tests/svg/svg-use-external.html
+        http/tests/loading/text-content-type-with-binary-extension.html
+        http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-iframe-in-main-frame.html
+
 2017-10-31  Simon Fraser  <simon.fraser@apple.com>
 
         Rubber-banding overflow-scrolling-touch shows black
diff --git a/LayoutTests/TestExpectations b/LayoutTests/TestExpectations
index 5d9a1d5..d0b824c 100644
--- a/LayoutTests/TestExpectations
+++ b/LayoutTests/TestExpectations
@@ -40,6 +40,9 @@
 
 # window.showModalDialog is only tested in DumpRenderTree on Mac.
 editing/execCommand/show-modal-dialog-during-execCommand.html [ Skip ]
+http/tests/security/cross-origin-modal-dialog-base.html [ Skip ]
+fast/events/scroll-event-during-modal-dialog.html [ Skip ]
+fast/harness/show-modal-dialog.html [ Skip ]
 
 fast/shadow-dom/touch-event-on-text-assigned-to-slot.html [ Skip ]
 
@@ -489,6 +492,11 @@
 webkit.org/b/169565 imported/w3c/web-platform-tests/cors/status-async.htm [ Failure ]
 webkit.org/b/169565 imported/w3c/web-platform-tests/cors/304.htm [ Failure ]
 
+# These tests used to have deterministic load delegate callback order before webkit.org/b/160677
+http/tests/svg/svg-use-external.html [ Pass Failure ]
+http/tests/loading/text-content-type-with-binary-extension.html [ Pass Failure ]
+http/tests/security/contentSecurityPolicy/block-all-mixed-content/insecure-iframe-in-main-frame.html [ Pass Failure ]
+
 # Tests that are flakey due to unhandled promise rejection error messages
 webkit.org/b/171094 imported/w3c/web-platform-tests/streams/readable-streams/tee.html [ Pass Failure ]
 webkit.org/b/171094 streams/brand-checks.html [ Pass Failure ]
@@ -825,6 +833,7 @@
 
 webkit.org/b/140043 js/dom/Promise.html [ Pass Failure ]
 
+webkit.org/b/134550 http/tests/cache/iframe-304-crash.html [ Failure Pass ]
 webkit.org/b/141267 http/tests/misc/detached-frame-console.html [ Pass Failure ]
 
 # Aborting application cache abort tests are intrinsically flaky.
diff --git a/LayoutTests/platform/gtk/TestExpectations b/LayoutTests/platform/gtk/TestExpectations
index a2df85c..612f5b4 100644
--- a/LayoutTests/platform/gtk/TestExpectations
+++ b/LayoutTests/platform/gtk/TestExpectations
@@ -1633,8 +1633,6 @@
 # Crash is webkit.org/b/176802
 webkit.org/b/36642 fast/replaced/border-radius-clip.html [ Failure Pass Crash ]
 
-webkit.org/b/134550 http/tests/cache/iframe-304-crash.html [ Failure Pass ]
-
 webkit.org/b/134573 media/track/audio-track.html [ Failure Timeout Pass ]
 webkit.org/b/134576 media/track/audio/audio-track-mkv-vorbis-language.html [ Failure Timeout Pass ]
 webkit.org/b/134576 media/track/track-cue-rendering.html [ Failure Timeout Pass ]
diff --git a/LayoutTests/platform/ios-wk2/TestExpectations b/LayoutTests/platform/ios-wk2/TestExpectations
index 152bff0..8273d8c 100644
--- a/LayoutTests/platform/ios-wk2/TestExpectations
+++ b/LayoutTests/platform/ios-wk2/TestExpectations
@@ -367,7 +367,6 @@
 http/tests/xmlhttprequest/cross-origin-authorization-with-embedder.html
 
 # HTTP tests that are flaky:
-http/tests/cache/iframe-304-crash.html [ Failure Pass ]
 http/tests/navigation/forward-and-cancel.html [ Failure Pass ]
 http/tests/security/xss-DENIED-xsl-external-entity-redirect.xml [ Failure Pass ]
 http/tests/webarchive/cross-origin-stylesheet-crash.html [ Failure Pass ]
diff --git a/LayoutTests/platform/mac-wk1/TestExpectations b/LayoutTests/platform/mac-wk1/TestExpectations
index 4ff23cc..44f3b57 100644
--- a/LayoutTests/platform/mac-wk1/TestExpectations
+++ b/LayoutTests/platform/mac-wk1/TestExpectations
@@ -74,6 +74,21 @@
 
 webkit.org/b/172092 [ Debug ] fast/parser/adoption-agency-unload-iframe-4.html [ Pass Timeout ]
 
+# webkit.org/b/178272
+http/tests/media/video-redirect.html [ Pass Failure ]
+http/tests/security/contentSecurityPolicy/audio-redirect-allowed.html [ Pass Failure ]
+http/tests/security/contentSecurityPolicy/video-redirect-allowed.html [ Pass Failure ]
+http/tests/security/contentSecurityPolicy/video-with-http-url-allowed-by-csp-media-src-star.html [ Pass Failure ]
+http/tests/security/local-video-source-from-remote.html [ Pass Failure ]
+http/tests/security/video-cross-origin-accesssameorigin.html [ Pass Failure ]
+http/tests/canvas/webgl/origin-clean-conformance.html [ Pass Timeout ]
+http/tests/media/autoplay-if-audio-is-playing.html [ Pass Timeout ]
+http/tests/media/video-load-twice.html [ Pass Timeout ]
+http/tests/media/video-play-progress.html [ Pass Timeout ]
+http/tests/security/canvas-remote-read-remote-video-localhost.html [ Pass Timeout ]
+http/tests/security/canvas-remote-read-remote-video-redirect.html [ Pass Timeout ]
+http/tests/security/video-cross-origin-caching.html [ Pass Timeout ]
+
 ### END OF (1) Failures with bug reports
 ########################################
 
diff --git a/LayoutTests/platform/mac-wk2/TestExpectations b/LayoutTests/platform/mac-wk2/TestExpectations
index 3be957e..7f1d6c0 100644
--- a/LayoutTests/platform/mac-wk2/TestExpectations
+++ b/LayoutTests/platform/mac-wk2/TestExpectations
@@ -301,8 +301,6 @@
 
 webkit.org/b/162999 accessibility/mac/wk1-set-selected-text-marker-range-input-element.html [ Skip ]
 
-webkit.org/b/134550 http/tests/cache/iframe-304-crash.html [ Pass Failure ]
-
 # testRunner.setUseDeferredFrameLoading is not implemented.
 webkit.org/b/93980 http/tests/appcache/load-from-appcache-defer-resume-crash.html [ Skip ]
 
diff --git a/LayoutTests/platform/wk2/TestExpectations b/LayoutTests/platform/wk2/TestExpectations
index 402f73a..937e7b5 100644
--- a/LayoutTests/platform/wk2/TestExpectations
+++ b/LayoutTests/platform/wk2/TestExpectations
@@ -264,7 +264,6 @@
 # WebKit2 needs showModalDialog
 fast/events/scroll-event-during-modal-dialog.html
 fast/harness/show-modal-dialog.html
-http/tests/security/cross-origin-modal-dialog-base.html [ Skip ]
 
 # WebKit2 needs to support synchronous creation of about:blank/data:url frames
 fast/dom/HTMLDocument/hasFocus.html
diff --git a/LayoutTests/security/block-test.html b/LayoutTests/security/block-test.html
index edde932..1af639b 100644
--- a/LayoutTests/security/block-test.html
+++ b/LayoutTests/security/block-test.html
@@ -67,12 +67,19 @@
             setTimeout("testRunner.notifyDone()", 0); 
         }
     }
+
+    function makeImage() {
+        var image = document.createElement("img");
+        image.onerror=nextBlockedPortTest;
+        image.src="http://255.255.255.255:1/test.jpg";
+        image.id="testIMG";
+        document.body.appendChild(image);
+    }
 </script>
-<body>
+<body onload="makeImage()">
 <p>This test attempts to change the src of an IMG tag to all black listed ports to confirm that WebKit returns the
 correct error for them - blocked instead of cannot find.  It also tries the FTP ports for exemptions.  Due to the 
 nature of this test, the results can only be processed automatically via DumpRenderTree
 </p>
-<img id="testIMG" src="http://255.255.255.255:1/test.jpg" onError="nextBlockedPortTest();"></img>
 </body>
 </html>
diff --git a/LayoutTests/svg/in-html/by-reference.html b/LayoutTests/svg/in-html/by-reference.html
index 3b49cd5..874c18c 100644
--- a/LayoutTests/svg/in-html/by-reference.html
+++ b/LayoutTests/svg/in-html/by-reference.html
@@ -4,6 +4,15 @@
   SVG documents included by reference should be transparent.  Any white visible in the green box is a failure.
 -->
 <head>
+    <script>
+        if (window.testRunner)
+            testRunner.waitUntilDone();
+        var elementsLoaded = 0;
+        function loaded() {
+            if (window.testRunner && ++elementsLoaded == 5)
+                testRunner.notifyDone();
+        }
+    </script>
   <style type='text/css'>
     * {
       margin: 0px;
@@ -21,11 +30,11 @@
 </head>
 <body>
   <div>
-    <object type='image/svg+xml' width='50' height='50' data='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></object>
-    <embed width='50' height='50' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></embed>
-    <iframe width='100' height='100' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></iframe>
-    <object type='text/xml' width='50' height='50' data='data:text/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></object>
-    <object type='application/xml' width='50' height='50' data='data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></object-->
+    <object onload="loaded()" type='image/svg+xml' width='50' height='50' data='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></object>
+    <embed onload="loaded()" width='50' height='50' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></embed>
+    <iframe onload="loaded()" width='100' height='100' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></iframe>
+    <object onload="loaded()" type='text/xml' width='50' height='50' data='data:text/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></object>
+    <object onload="loaded()" type='application/xml' width='50' height='50' data='data:application/xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxzdmcgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciLz4='></object-->
   </div>
 </body>
 </html>