Title: [238819] trunk
Revision
238819
Author
[email protected]
Date
2018-12-03 13:47:08 -0800 (Mon, 03 Dec 2018)

Log Message

Add WKWebProcessPlugInLoadDelegate SPI willStartProvisionalLoadForFrame with a completion handler
https://bugs.webkit.org/show_bug.cgi?id=192272

Reviewed by Brady Eidson.

Source/WebCore:

This is needed for rdar://problem/45910057
Covered by an API test.

* loader/EmptyFrameLoaderClient.h:
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::prepareForLoadStart):
(WebCore::FrameLoader::continueLoadAfterNavigationPolicy):
(WebCore::FrameLoader::loadProvisionalItemFromCachedPage):
* loader/FrameLoader.h:
* loader/FrameLoaderClient.h:

Source/WebKit:

* WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h:
(API::InjectedBundle::PageLoaderClient::didStartProvisionalLoadForFrame):
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h:
* WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp:
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(ResourceLoadClient::ResourceLoadClient):
(ResourceLoadClient::loadDelegate const):
(ResourceLoadClient::pluginContextController const):
(PageLoaderClient::PageLoaderClient):
(PageLoaderClient::loadDelegate const):
(PageLoaderClient::pluginContextController const):
(PageLoaderClient::didStartProvisionalLoadForFrame):
(PageLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame):
(PageLoaderClient::didFinishLoadForFrame):
(PageLoaderClient::globalObjectIsAvailableForFrame):
(PageLoaderClient::didRemoveFrameFromHierarchy):
(PageLoaderClient::didCommitLoadForFrame):
(PageLoaderClient::didFinishDocumentLoadForFrame):
(PageLoaderClient::didFailProvisionalLoadWithErrorForFrame):
(PageLoaderClient::didFailLoadWithErrorForFrame):
(PageLoaderClient::didSameDocumentNavigationForFrame):
(PageLoaderClient::didLayoutForFrame):
(PageLoaderClient::didReachLayoutMilestone):
(PageLoaderClient::didFirstVisuallyNonEmptyLayoutForFrame):
(PageLoaderClient::didHandleOnloadEventsForFrame):
(PageLoaderClient::userAgentForURL const):
(ResourceLoadClient::willSendRequestForFrame):
(ResourceLoadClient::didInitiateLoadForResource):
(ResourceLoadClient::didFinishLoadForResource):
(ResourceLoadClient::didFailLoadForResource):
(-[WKWebProcessPlugInBrowserContextController setLoadDelegate:]):
(didStartProvisionalLoadForFrame): Deleted.
(didReceiveServerRedirectForProvisionalLoadForFrame): Deleted.
(didFinishLoadForFrame): Deleted.
(globalObjectIsAvailableForFrame): Deleted.
(didRemoveFrameFromHierarchy): Deleted.
(didCommitLoadForFrame): Deleted.
(didFinishDocumentLoadForFrame): Deleted.
(didFailProvisionalLoadWithErrorForFrame): Deleted.
(didFailLoadWithErrorForFrame): Deleted.
(didSameDocumentNavigationForFrame): Deleted.
(didLayoutForFrame): Deleted.
(didReachLayoutMilestone): Deleted.
(didFirstVisuallyNonEmptyLayoutForFrame): Deleted.
(didHandleOnloadEventsForFrame): Deleted.
(userAgentForURL): Deleted.
(setUpPageLoaderClient): Deleted.
(willSendRequestForFrame): Deleted.
(didInitiateLoadForResource): Deleted.
(didFinishLoadForResource): Deleted.
(didFailLoadForResource): Deleted.
(setUpResourceLoadClient): Deleted.
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
(WebKit::InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame):
* WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::dispatchDidStartProvisionalLoad):
* WebProcess/WebCoreSupport/WebFrameLoaderClient.h:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebFrameLoaderClient.h:
* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::dispatchDidStartProvisionalLoad):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ParserYieldTokenPlugIn.mm:
(-[ParserYieldTokenPlugIn webProcessPlugInBrowserContextController:willStartProvisionalLoadForFrame:completionHandler:]):
(-[ParserYieldTokenPlugIn webProcessPlugInBrowserContextController:didCommitLoadForFrame:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (238818 => 238819)


--- trunk/Source/WebCore/ChangeLog	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebCore/ChangeLog	2018-12-03 21:47:08 UTC (rev 238819)
@@ -1,3 +1,21 @@
+2018-12-03  Alex Christensen  <[email protected]>
+
+        Add WKWebProcessPlugInLoadDelegate SPI willStartProvisionalLoadForFrame with a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=192272
+
+        Reviewed by Brady Eidson.
+
+        This is needed for rdar://problem/45910057
+        Covered by an API test.
+
+        * loader/EmptyFrameLoaderClient.h:
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::prepareForLoadStart):
+        (WebCore::FrameLoader::continueLoadAfterNavigationPolicy):
+        (WebCore::FrameLoader::loadProvisionalItemFromCachedPage):
+        * loader/FrameLoader.h:
+        * loader/FrameLoaderClient.h:
+
 2018-12-03  Zalan Bujtas  <[email protected]>
 
         [iOS] Unreviewed build fix.

Modified: trunk/Source/WebCore/loader/EmptyFrameLoaderClient.h (238818 => 238819)


--- trunk/Source/WebCore/loader/EmptyFrameLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebCore/loader/EmptyFrameLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -81,7 +81,7 @@
     void dispatchDidReplaceStateWithinPage() final { }
     void dispatchDidPopStateWithinPage() final { }
     void dispatchWillClose() final { }
-    void dispatchDidStartProvisionalLoad() final { }
+    void dispatchDidStartProvisionalLoad(CompletionHandler<void()>&& completionHandler) final { completionHandler(); }
     void dispatchDidReceiveTitle(const StringWithDirection&) final { }
     void dispatchDidCommitLoad(std::optional<HasInsecureContent>) final { }
     void dispatchDidFailProvisionalLoad(const ResourceError&) final { }

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (238818 => 238819)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2018-12-03 21:47:08 UTC (rev 238819)
@@ -1207,19 +1207,20 @@
         frame->loader().m_isComplete = false;
 }
 
-void FrameLoader::prepareForLoadStart()
+void FrameLoader::prepareForLoadStart(CompletionHandler<void()>&& completionHandler)
 {
     RELEASE_LOG_IF_ALLOWED("prepareForLoadStart: Starting frame load (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame());
 
     m_progressTracker->progressStarted();
-    m_client.dispatchDidStartProvisionalLoad();
-
-    if (AXObjectCache::accessibilityEnabled()) {
-        if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) {
-            AXObjectCache::AXLoadingEvent loadingEvent = loadType() == FrameLoadType::Reload ? AXObjectCache::AXLoadingReloaded : AXObjectCache::AXLoadingStarted;
-            cache->frameLoadingEventNotification(&m_frame, loadingEvent);
+    m_client.dispatchDidStartProvisionalLoad([this, protectedFrame = makeRef(m_frame), completionHandler = WTFMove(completionHandler)] () mutable {
+        if (AXObjectCache::accessibilityEnabled()) {
+            if (AXObjectCache* cache = m_frame.document()->existingAXObjectCache()) {
+                AXObjectCache::AXLoadingEvent loadingEvent = loadType() == FrameLoadType::Reload ? AXObjectCache::AXLoadingReloaded : AXObjectCache::AXLoadingStarted;
+                cache->frameLoadingEventNotification(&m_frame, loadingEvent);
+            }
         }
-    }
+        completionHandler();
+    });
 }
 
 void FrameLoader::setupForReplace()
@@ -3341,37 +3342,38 @@
         diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::pageCacheKey(), DiagnosticLoggingKeys::retrievalKey(), DiagnosticLoggingResultFail, ShouldSample::Yes);
     }
 
-    CompletionHandler<void()> completionHandler = [this, shouldContinue] {
+    CompletionHandler<void()> completionHandler = [this, protectedFrame = makeRef(m_frame), shouldContinue] () mutable {
         if (!m_provisionalDocumentLoader)
             return;
         
-        prepareForLoadStart();
-        
-        // The load might be cancelled inside of prepareForLoadStart(), nulling out the m_provisionalDocumentLoader,
-        // so we need to null check it again.
-        if (!m_provisionalDocumentLoader) {
-            RELEASE_LOG_IF_ALLOWED("dispatchWillSubmitForm completionHandler: Frame load canceled (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame());
-            return;
-        }
-        
-        DocumentLoader* activeDocLoader = activeDocumentLoader();
-        if (activeDocLoader && activeDocLoader->isLoadingMainResource()) {
-            RELEASE_LOG_IF_ALLOWED("dispatchWillSubmitForm completionHandler: Main frame already being loaded (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame());
-            return;
-        }
-        
-        m_loadingFromCachedPage = false;
+        prepareForLoadStart([this, protectedFrame = WTFMove(protectedFrame), shouldContinue] {
 
-        // We handle suspension by navigating forward to about:blank, which leaves us setup to navigate back to resume.
-        if (shouldContinue == ShouldContinue::ForSuspension) {
-            // Make sure we do a standard load to about:blank instead of reusing whatever the load type was on process swap.
-            // For example, using a Back/Forward load to load about blank would cause the current HistoryItem's url to be
-            // overwritten with 'about:blank', which we do not want.
-            m_loadType = FrameLoadType::Standard;
-            m_provisionalDocumentLoader->willContinueMainResourceLoadAfterRedirect({ WTF::blankURL() });
-        }
+            // The load might be cancelled inside of prepareForLoadStart(), nulling out the m_provisionalDocumentLoader,
+            // so we need to null check it again.
+            if (!m_provisionalDocumentLoader) {
+                RELEASE_LOG_IF_ALLOWED("dispatchWillSubmitForm completionHandler: Frame load canceled (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame());
+                return;
+            }
+            
+            DocumentLoader* activeDocLoader = activeDocumentLoader();
+            if (activeDocLoader && activeDocLoader->isLoadingMainResource()) {
+                RELEASE_LOG_IF_ALLOWED("dispatchWillSubmitForm completionHandler: Main frame already being loaded (frame = %p, main = %d)", &m_frame, m_frame.isMainFrame());
+                return;
+            }
+            
+            m_loadingFromCachedPage = false;
 
-        m_provisionalDocumentLoader->startLoadingMainResource(shouldContinue);
+            // We handle suspension by navigating forward to about:blank, which leaves us setup to navigate back to resume.
+            if (shouldContinue == ShouldContinue::ForSuspension) {
+                // Make sure we do a standard load to about:blank instead of reusing whatever the load type was on process swap.
+                // For example, using a Back/Forward load to load about blank would cause the current HistoryItem's url to be
+                // overwritten with 'about:blank', which we do not want.
+                m_loadType = FrameLoadType::Standard;
+                m_provisionalDocumentLoader->willContinueMainResourceLoadAfterRedirect({ WTF::blankURL() });
+            }
+
+            m_provisionalDocumentLoader->startLoadingMainResource(shouldContinue);
+        });
     };
     
     if (!formState) {
@@ -3514,20 +3516,20 @@
 
 void FrameLoader::loadProvisionalItemFromCachedPage()
 {
-    DocumentLoader* provisionalLoader = provisionalDocumentLoader();
-    LOG(PageCache, "WebCorePageCache: Loading provisional DocumentLoader %p with URL '%s' from CachedPage", provisionalDocumentLoader(), provisionalDocumentLoader()->url().stringCenterEllipsizedToLength().utf8().data());
+    prepareForLoadStart([this, protectedFrame = makeRef(m_frame)] {
+        DocumentLoader* provisionalLoader = provisionalDocumentLoader();
+        LOG(PageCache, "WebCorePageCache: Loading provisional DocumentLoader %p with URL '%s' from CachedPage", provisionalDocumentLoader(), provisionalDocumentLoader()->url().stringCenterEllipsizedToLength().utf8().data());
 
-    prepareForLoadStart();
-
-    m_loadingFromCachedPage = true;
-
-    // Should have timing data from previous time(s) the page was shown.
-    ASSERT(provisionalLoader->timing().startTime());
-    provisionalLoader->resetTiming();
-    provisionalLoader->timing().markStartTime();
-
-    provisionalLoader->setCommitted(true);
-    commitProvisionalLoad();
+        m_loadingFromCachedPage = true;
+        
+        // Should have timing data from previous time(s) the page was shown.
+        ASSERT(provisionalLoader->timing().startTime());
+        provisionalLoader->resetTiming();
+        provisionalLoader->timing().markStartTime();
+        
+        provisionalLoader->setCommitted(true);
+        commitProvisionalLoad();
+    });
 }
 
 bool FrameLoader::shouldTreatURLAsSameAsCurrent(const URL& url) const

Modified: trunk/Source/WebCore/loader/FrameLoader.h (238818 => 238819)


--- trunk/Source/WebCore/loader/FrameLoader.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebCore/loader/FrameLoader.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -387,7 +387,7 @@
 
     void loadInSameDocument(const URL&, SerializedScriptValue* stateObject, bool isNewNavigation);
 
-    void prepareForLoadStart();
+    void prepareForLoadStart(CompletionHandler<void()>&&);
     void provisionalLoadStarted();
 
     void willTransitionToCommitted();

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (238818 => 238819)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -173,7 +173,7 @@
     virtual void dispatchDidPopStateWithinPage() = 0;
     virtual void dispatchWillClose() = 0;
     virtual void dispatchDidReceiveIcon() { }
-    virtual void dispatchDidStartProvisionalLoad() = 0;
+    virtual void dispatchDidStartProvisionalLoad(CompletionHandler<void()>&&) = 0;
     virtual void dispatchDidReceiveTitle(const StringWithDirection&) = 0;
     virtual void dispatchDidCommitLoad(std::optional<HasInsecureContent>) = 0;
     virtual void dispatchDidFailProvisionalLoad(const ResourceError&) = 0;

Modified: trunk/Source/WebKit/ChangeLog (238818 => 238819)


--- trunk/Source/WebKit/ChangeLog	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/ChangeLog	2018-12-03 21:47:08 UTC (rev 238819)
@@ -1,3 +1,69 @@
+2018-12-03  Alex Christensen  <[email protected]>
+
+        Add WKWebProcessPlugInLoadDelegate SPI willStartProvisionalLoadForFrame with a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=192272
+
+        Reviewed by Brady Eidson.
+
+        * WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h:
+        (API::InjectedBundle::PageLoaderClient::didStartProvisionalLoadForFrame):
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h:
+        * WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp:
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        (ResourceLoadClient::ResourceLoadClient):
+        (ResourceLoadClient::loadDelegate const):
+        (ResourceLoadClient::pluginContextController const):
+        (PageLoaderClient::PageLoaderClient):
+        (PageLoaderClient::loadDelegate const):
+        (PageLoaderClient::pluginContextController const):
+        (PageLoaderClient::didStartProvisionalLoadForFrame):
+        (PageLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame):
+        (PageLoaderClient::didFinishLoadForFrame):
+        (PageLoaderClient::globalObjectIsAvailableForFrame):
+        (PageLoaderClient::didRemoveFrameFromHierarchy):
+        (PageLoaderClient::didCommitLoadForFrame):
+        (PageLoaderClient::didFinishDocumentLoadForFrame):
+        (PageLoaderClient::didFailProvisionalLoadWithErrorForFrame):
+        (PageLoaderClient::didFailLoadWithErrorForFrame):
+        (PageLoaderClient::didSameDocumentNavigationForFrame):
+        (PageLoaderClient::didLayoutForFrame):
+        (PageLoaderClient::didReachLayoutMilestone):
+        (PageLoaderClient::didFirstVisuallyNonEmptyLayoutForFrame):
+        (PageLoaderClient::didHandleOnloadEventsForFrame):
+        (PageLoaderClient::userAgentForURL const):
+        (ResourceLoadClient::willSendRequestForFrame):
+        (ResourceLoadClient::didInitiateLoadForResource):
+        (ResourceLoadClient::didFinishLoadForResource):
+        (ResourceLoadClient::didFailLoadForResource):
+        (-[WKWebProcessPlugInBrowserContextController setLoadDelegate:]):
+        (didStartProvisionalLoadForFrame): Deleted.
+        (didReceiveServerRedirectForProvisionalLoadForFrame): Deleted.
+        (didFinishLoadForFrame): Deleted.
+        (globalObjectIsAvailableForFrame): Deleted.
+        (didRemoveFrameFromHierarchy): Deleted.
+        (didCommitLoadForFrame): Deleted.
+        (didFinishDocumentLoadForFrame): Deleted.
+        (didFailProvisionalLoadWithErrorForFrame): Deleted.
+        (didFailLoadWithErrorForFrame): Deleted.
+        (didSameDocumentNavigationForFrame): Deleted.
+        (didLayoutForFrame): Deleted.
+        (didReachLayoutMilestone): Deleted.
+        (didFirstVisuallyNonEmptyLayoutForFrame): Deleted.
+        (didHandleOnloadEventsForFrame): Deleted.
+        (userAgentForURL): Deleted.
+        (setUpPageLoaderClient): Deleted.
+        (willSendRequestForFrame): Deleted.
+        (didInitiateLoadForResource): Deleted.
+        (didFinishLoadForResource): Deleted.
+        (didFailLoadForResource): Deleted.
+        (setUpResourceLoadClient): Deleted.
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp:
+        (WebKit::InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame):
+        * WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::dispatchDidStartProvisionalLoad):
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
+
 2018-12-03  Tim Horton  <[email protected]>
 
         Swipe snapshot stays up too long swiping around on apple.com (waiting for first paint)

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/APIInjectedBundlePageLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -27,6 +27,7 @@
 
 #include "SameDocumentNavigationType.h"
 #include <WebCore/LayoutMilestone.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/Forward.h>
 #include <wtf/WallTime.h>
 #include <wtf/text/WTFString.h>
@@ -57,7 +58,7 @@
     virtual void willLoadURLRequest(WebKit::WebPage&, const WebCore::ResourceRequest&, API::Object*) { }
     virtual void willLoadDataRequest(WebKit::WebPage&, const WebCore::ResourceRequest&, WebCore::SharedBuffer*, const WTF::String&, const WTF::String&, const WTF::URL&, API::Object*) { }
 
-    virtual void didStartProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) { }
+    virtual void didStartProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, CompletionHandler<void(RefPtr<API::Object>&&)>&& completionHandler) { completionHandler(nullptr); }
     virtual void didReceiveServerRedirectForProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) { }
     virtual void didFailProvisionalLoadWithErrorForFrame(WebKit::WebPage&, WebKit::WebFrame&, const WebCore::ResourceError&, RefPtr<API::Object>&) { }
     virtual void didCommitLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) { }

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInLoadDelegate.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -37,6 +37,7 @@
 // Frame loading
 
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didStartProvisionalLoadForFrame:(WKWebProcessPlugInFrame *)frame;
+- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller willStartProvisionalLoadForFrame:(WKWebProcessPlugInFrame *)frame completionHandler:(void(^)(void))completionHandler;
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didReceiveServerRedirectForProvisionalLoadForFrame:(WKWebProcessPlugInFrame *)frame;
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didCommitLoadForFrame:(WKWebProcessPlugInFrame *)frame;
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller didFinishDocumentLoadForFrame:(WKWebProcessPlugInFrame *)frame;

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp	2018-12-03 21:47:08 UTC (rev 238819)
@@ -170,11 +170,12 @@
         return documentLoader->url().string().utf8();
     }
 
-    void didStartProvisionalLoadForFrame(WebPage&, WebFrame& frame, RefPtr<API::Object>&) override
+    void didStartProvisionalLoadForFrame(WebPage&, WebFrame& frame, CompletionHandler<void(RefPtr<API::Object>&&)>&& completionHandler) override
     {
         if (!frame.isMainFrame())
-            return;
+            return completionHandler(nullptr);
         webkitWebPageSetURI(m_webPage, getDocumentLoaderURL(frame.coreFrame()->loader().provisionalDocumentLoader()));
+        completionHandler(nullptr);
     }
 
     void didReceiveServerRedirectForProvisionalLoadForFrame(WebPage&, WebFrame& frame, RefPtr<API::Object>&) override

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm	2018-12-03 21:47:08 UTC (rev 238819)
@@ -29,6 +29,7 @@
 #if WK_API_ENABLED
 
 #import "APIData.h"
+#import "CompletionHandlerCallChecker.h"
 #import "RemoteObjectRegistry.h"
 #import "RemoteObjectRegistryMessages.h"
 #import "WKBrowsingContextHandleInternal.h"
@@ -64,6 +65,7 @@
 #import <WebCore/HTMLFormElement.h>
 #import <WebCore/HTMLInputElement.h>
 #import <pal/spi/cocoa/NSKeyedArchiverSPI.h>
+#import <wtf/BlockPtr.h>
 #import <wtf/WeakObjCPtr.h>
 
 @interface NSObject (WKDeprecatedDelegateMethods)
@@ -70,6 +72,59 @@
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller didSameDocumentNavigationForFrame:(WKWebProcessPlugInFrame *)frame;
 @end
 
+class ResourceLoadClient : public API::InjectedBundle::ResourceLoadClient {
+public:
+    explicit ResourceLoadClient(WKWebProcessPlugInBrowserContextController *controller, id <WKWebProcessPlugInLoadDelegate> delegate)
+        : m_controller(controller)
+        , m_delegate(delegate) { }
+    
+    void didInitiateLoadForResource(WebKit::WebPage&, WebKit::WebFrame&, uint64_t identifier, const WebCore::ResourceRequest&, bool) override;
+    void willSendRequestForFrame(WebKit::WebPage&, WebKit::WebFrame&, uint64_t identifier, WebCore::ResourceRequest&, const WebCore::ResourceResponse&) override;
+    void didFinishLoadForResource(WebKit::WebPage&, WebKit::WebFrame&, uint64_t identifier) override;
+    void didFailLoadForResource(WebKit::WebPage&, WebKit::WebFrame&, uint64_t identifier, const WebCore::ResourceError&) override;
+
+private:
+    id <WKWebProcessPlugInLoadDelegate> loadDelegate() const { return m_delegate.get().get(); }
+    WKWebProcessPlugInBrowserContextController *pluginContextController() const { return m_controller.get().get(); }
+    
+    WeakObjCPtr<WKWebProcessPlugInBrowserContextController> m_controller;
+    WeakObjCPtr<id <WKWebProcessPlugInLoadDelegate>> m_delegate;
+};
+
+class PageLoaderClient : public API::InjectedBundle::PageLoaderClient {
+public:
+    explicit PageLoaderClient(WKWebProcessPlugInBrowserContextController *controller, id <WKWebProcessPlugInLoadDelegate> delegate)
+        : m_controller(controller)
+        , m_delegate(delegate) { }
+    
+    void didStartProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, CompletionHandler<void(RefPtr<API::Object>&&)>&&) override;
+    void didReceiveServerRedirectForProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) override;
+    void didFailProvisionalLoadWithErrorForFrame(WebKit::WebPage&, WebKit::WebFrame&, const WebCore::ResourceError&, RefPtr<API::Object>&) override;
+    void didCommitLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) override;
+    void didFinishDocumentLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) override;
+    void didFinishLoadForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) override;
+    void didFailLoadWithErrorForFrame(WebKit::WebPage&, WebKit::WebFrame&, const WebCore::ResourceError&, RefPtr<API::Object>&) override;
+    void didSameDocumentNavigationForFrame(WebKit::WebPage&, WebKit::WebFrame&, WebKit::SameDocumentNavigationType, RefPtr<API::Object>&) override;
+    void didRemoveFrameFromHierarchy(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) override;
+    
+    void didFirstVisuallyNonEmptyLayoutForFrame(WebKit::WebPage&, WebKit::WebFrame&, RefPtr<API::Object>&) override;
+    void didLayoutForFrame(WebKit::WebPage&, WebKit::WebFrame&) override;
+    void didReachLayoutMilestone(WebKit::WebPage&, OptionSet<WebCore::LayoutMilestone>, RefPtr<API::Object>&) override;
+    
+    void didHandleOnloadEventsForFrame(WebKit::WebPage&, WebKit::WebFrame&) override;
+    
+    void globalObjectIsAvailableForFrame(WebKit::WebPage&, WebKit::WebFrame&, WebCore::DOMWrapperWorld&) override;
+
+    WTF::String userAgentForURL(WebKit::WebFrame&, const URL&) const override;
+    
+private:
+    id <WKWebProcessPlugInLoadDelegate> loadDelegate() const { return m_delegate.get().get(); }
+    WKWebProcessPlugInBrowserContextController *pluginContextController() const { return m_controller.get().get(); }
+
+    WeakObjCPtr<WKWebProcessPlugInBrowserContextController> m_controller;
+    WeakObjCPtr<id <WKWebProcessPlugInLoadDelegate>> m_delegate;
+};
+
 @implementation WKWebProcessPlugInBrowserContextController {
     API::ObjectStorage<WebKit::WebPage> _page;
     WeakObjCPtr<id <WKWebProcessPlugInLoadDelegate>> _loadDelegate;
@@ -79,254 +134,164 @@
     RetainPtr<_WKRemoteObjectRegistry> _remoteObjectRegistry;
 }
 
-static void didStartProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userDataRef, const void *clientInfo)
+void PageLoaderClient::didStartProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, CompletionHandler<void(RefPtr<API::Object>&&)>&& completionHandler)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didStartProvisionalLoadForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didStartProvisionalLoadForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didStartProvisionalLoadForFrame:)]) {
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didStartProvisionalLoadForFrame:wrapper(frame)];
+        completionHandler(nullptr);
+        return;
+    }
+    SEL selector = @selector(webProcessPlugInBrowserContextController:willStartProvisionalLoadForFrame:completionHandler:);
+    if ([loadDelegate() respondsToSelector:selector]) {
+        auto checker = WebKit::CompletionHandlerCallChecker::create(loadDelegate(), selector);
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() willStartProvisionalLoadForFrame:wrapper(frame) completionHandler:BlockPtr<void()>::fromCallable([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] () mutable {
+            if (checker->completionHandlerHasBeenCalled())
+                return;
+            checker->didCallCompletionHandler();
+            completionHandler(nullptr);
+        }).get()];
+        return;
+    }
+    completionHandler(nullptr);
 }
 
-static void didReceiveServerRedirectForProvisionalLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef *userDataRef, const void *clientInfo)
+void PageLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didReceiveServerRedirectForProvisionalLoadForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didReceiveServerRedirectForProvisionalLoadForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didReceiveServerRedirectForProvisionalLoadForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didReceiveServerRedirectForProvisionalLoadForFrame:wrapper(frame)];
 }
 
-static void didFinishLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didFinishLoadForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFinishLoadForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didFinishLoadForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFinishLoadForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didFinishLoadForFrame:wrapper(frame)];
 }
 
-static void globalObjectIsAvailableForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKBundleScriptWorldRef scriptWorld, const void* clientInfo)
+void PageLoaderClient::globalObjectIsAvailableForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, WebCore::DOMWrapperWorld& scriptWorld)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:globalObjectIsAvailableForFrame:inScriptWorld:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController globalObjectIsAvailableForFrame:wrapper(*WebKit::toImpl(frame)) inScriptWorld:wrapper(*WebKit::toImpl(scriptWorld))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:globalObjectIsAvailableForFrame:inScriptWorld:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() globalObjectIsAvailableForFrame:wrapper(frame) inScriptWorld:API::wrapper(WebKit::InjectedBundleScriptWorld::getOrCreate(scriptWorld))];
 }
 
-static void didRemoveFrameFromHierarchy(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void* clientInfo)
+void PageLoaderClient::didRemoveFrameFromHierarchy(WebKit::WebPage&, WebKit::WebFrame& frame, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didRemoveFrameFromHierarchy:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didRemoveFrameFromHierarchy:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didRemoveFrameFromHierarchy:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didRemoveFrameFromHierarchy:wrapper(frame)];
 }
 
-static void didCommitLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didCommitLoadForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didCommitLoadForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didCommitLoadForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didCommitLoadForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didCommitLoadForFrame:wrapper(frame)];
 }
 
-static void didFinishDocumentLoadForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didFinishDocumentLoadForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFinishDocumentLoadForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didFinishDocumentLoadForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFinishDocumentLoadForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didFinishDocumentLoadForFrame:wrapper(frame)];
 }
 
-static void didFailProvisionalLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef wkError, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didFailProvisionalLoadWithErrorForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, const WebCore::ResourceError& error, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFailProvisionalLoadWithErrorForFrame:error:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didFailProvisionalLoadWithErrorForFrame:wrapper(*WebKit::toImpl(frame)) error:wrapper(*WebKit::toImpl(wkError))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFailProvisionalLoadWithErrorForFrame:error:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didFailProvisionalLoadWithErrorForFrame:wrapper(frame) error:error];
 }
 
-static void didFailLoadWithErrorForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKErrorRef wkError, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didFailLoadWithErrorForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, const WebCore::ResourceError& error, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFailLoadWithErrorForFrame:error:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didFailLoadWithErrorForFrame:wrapper(*WebKit::toImpl(frame)) error:wrapper(*WebKit::toImpl(wkError))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFailLoadWithErrorForFrame:error:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didFailLoadWithErrorForFrame:wrapper(frame) error:error];
 }
 
-static void didSameDocumentNavigationForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKSameDocumentNavigationType type, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didSameDocumentNavigationForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, WebKit::SameDocumentNavigationType type, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didSameDocumentNavigation:forFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didSameDocumentNavigation:toWKSameDocumentNavigationType(WebKit::toSameDocumentNavigationType(type)) forFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didSameDocumentNavigation:forFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didSameDocumentNavigation:toWKSameDocumentNavigationType(type) forFrame:wrapper(frame)];
     else {
         // FIXME: Remove this once clients switch to implementing the above delegate method.
-        if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didSameDocumentNavigationForFrame:)])
-            [(NSObject *)loadDelegate webProcessPlugInBrowserContextController:pluginContextController didSameDocumentNavigationForFrame:wrapper(*WebKit::toImpl(frame))];
+        if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didSameDocumentNavigationForFrame:)])
+            [(NSObject *)loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didSameDocumentNavigationForFrame:wrapper(frame)];
     }
 }
 
-static void didLayoutForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void* clientInfo)
+void PageLoaderClient::didLayoutForFrame(WebKit::WebPage&, WebKit::WebFrame& frame)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didLayoutForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didLayoutForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didLayoutForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didLayoutForFrame:wrapper(frame)];
 }
 
-static void didReachLayoutMilestone(WKBundlePageRef page, WKLayoutMilestones milestones, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didReachLayoutMilestone(WebKit::WebPage&, OptionSet<WebCore::LayoutMilestone> milestones, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:renderingProgressDidChange:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController renderingProgressDidChange:renderingProgressEvents(WebKit::toLayoutMilestones(milestones))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:renderingProgressDidChange:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() renderingProgressDidChange:renderingProgressEvents(milestones)];
 }
 
-static void didFirstVisuallyNonEmptyLayoutForFrame(WKBundlePageRef page, WKBundleFrameRef frame, WKTypeRef* userData, const void *clientInfo)
+void PageLoaderClient::didFirstVisuallyNonEmptyLayoutForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, RefPtr<API::Object>&)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFirstVisuallyNonEmptyLayoutForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didFirstVisuallyNonEmptyLayoutForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didFirstVisuallyNonEmptyLayoutForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didFirstVisuallyNonEmptyLayoutForFrame:wrapper(frame)];
 }
 
-static void didHandleOnloadEventsForFrame(WKBundlePageRef page, WKBundleFrameRef frame, const void* clientInfo)
+void PageLoaderClient::didHandleOnloadEventsForFrame(WebKit::WebPage&, WebKit::WebFrame& frame)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:didHandleOnloadEventsForFrame:)])
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController didHandleOnloadEventsForFrame:wrapper(*WebKit::toImpl(frame))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:didHandleOnloadEventsForFrame:)])
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() didHandleOnloadEventsForFrame:wrapper(frame)];
 }
 
-static WKStringRef userAgentForURL(WKBundleFrameRef frame, WKURLRef url, const void* clientInfo)
+WTF::String PageLoaderClient::userAgentForURL(WebKit::WebFrame& frame, const URL& url) const
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-    
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:userAgentForURL:)]) {
-        WKWebProcessPlugInFrame *newFrame = wrapper(*WebKit::toImpl(frame));
-        NSString *string = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:newFrame userAgentForURL:wrapper(*WebKit::toImpl(url))];
-        if (!string)
-            return nullptr;
-
-        return WKStringCreateWithCFString((__bridge CFStringRef)string);
-    }
-    
-    return nullptr;
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:userAgentForURL:)])
+        return [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) userAgentForURL:url];
+    return { };
 }
 
-static void setUpPageLoaderClient(WKWebProcessPlugInBrowserContextController *contextController, WebKit::WebPage& page)
+void ResourceLoadClient::willSendRequestForFrame(WebKit::WebPage&, WebKit::WebFrame& frame, uint64_t resourceIdentifier, WebCore::ResourceRequest& request, const WebCore::ResourceResponse& redirectResponse)
 {
-    WKBundlePageLoaderClientV9 client;
-    memset(&client, 0, sizeof(client));
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequestForResource:request:redirectResponse:)]) {
+        RetainPtr<NSURLRequest> originalRequest = request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+        RetainPtr<NSURLRequest> substituteRequest = [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) willSendRequestForResource:resourceIdentifier
+            request:originalRequest.get() redirectResponse:redirectResponse.nsURLResponse()];
 
-    client.base.version = 8;
-    client.base.clientInfo = (__bridge void*)contextController;
-    client.didStartProvisionalLoadForFrame = didStartProvisionalLoadForFrame;
-    client.didReceiveServerRedirectForProvisionalLoadForFrame = didReceiveServerRedirectForProvisionalLoadForFrame;
-    client.didCommitLoadForFrame = didCommitLoadForFrame;
-    client.didFinishDocumentLoadForFrame = didFinishDocumentLoadForFrame;
-    client.didFailProvisionalLoadWithErrorForFrame = didFailProvisionalLoadWithErrorForFrame;
-    client.didFailLoadWithErrorForFrame = didFailLoadWithErrorForFrame;
-    client.didSameDocumentNavigationForFrame = didSameDocumentNavigationForFrame;
-    client.didFinishLoadForFrame = didFinishLoadForFrame;
-    client.globalObjectIsAvailableForFrame = globalObjectIsAvailableForFrame;
-    client.didRemoveFrameFromHierarchy = didRemoveFrameFromHierarchy;
-    client.didHandleOnloadEventsForFrame = didHandleOnloadEventsForFrame;
-    client.didFirstVisuallyNonEmptyLayoutForFrame = didFirstVisuallyNonEmptyLayoutForFrame;
-    client.userAgentForURL = userAgentForURL;
+        if (substituteRequest != originalRequest) {
+            request = substituteRequest.get();
+            return;
+        }
+    } else if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequest:redirectResponse:)]) {
+        RetainPtr<NSURLRequest> originalRequest = request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody);
+        RetainPtr<NSURLRequest> substituteRequest = [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) willSendRequest:originalRequest.get()
+            redirectResponse:redirectResponse.nsURLResponse()];
 
-    client.didLayoutForFrame = didLayoutForFrame;
-    client.didLayout = didReachLayoutMilestone;
-
-    WKBundlePageSetPageLoaderClient(toAPI(&page), &client.base);
-}
-
-static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void* clientInfo)
-{
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequestForResource:request:redirectResponse:)]) {
-        NSURLRequest *originalRequest = wrapper(*WebKit::toImpl(request));
-        RetainPtr<NSURLRequest> substituteRequest = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*WebKit::toImpl(frame)) willSendRequestForResource:resourceIdentifier
-            request:originalRequest redirectResponse:WebKit::toImpl(redirectResponse)->resourceResponse().nsURLResponse()];
-
-        if (substituteRequest != originalRequest)
-            return substituteRequest ? WKURLRequestCreateWithNSURLRequest(substituteRequest.get()) : nullptr;
-    } else if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:willSendRequest:redirectResponse:)]) {
-        NSURLRequest *originalRequest = wrapper(*WebKit::toImpl(request));
-        RetainPtr<NSURLRequest> substituteRequest = [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*WebKit::toImpl(frame)) willSendRequest:originalRequest
-            redirectResponse:WebKit::toImpl(redirectResponse)->resourceResponse().nsURLResponse()];
-
-        if (substituteRequest != originalRequest)
-            return substituteRequest ? WKURLRequestCreateWithNSURLRequest(substituteRequest.get()) : nullptr;
+        if (substituteRequest != originalRequest) {
+            request = substituteRequest.get();
+            return;
+        }
     }
-
-    WKRetain(request);
-    return request;
 }
 
-static void didInitiateLoadForResource(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, WKURLRequestRef request, bool pageIsProvisionallyLoading, const void* clientInfo)
+void ResourceLoadClient::didInitiateLoadForResource(WebKit::WebPage&, WebKit::WebFrame& frame, uint64_t resourceIdentifier, const WebCore::ResourceRequest& request, bool pageIsProvisionallyLoading)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didInitiateLoadForResource:request:pageIsProvisionallyLoading:)]) {
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*WebKit::toImpl(frame)) didInitiateLoadForResource:resourceIdentifier request:wrapper(*WebKit::toImpl(request))
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didInitiateLoadForResource:request:pageIsProvisionallyLoading:)]) {
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) didInitiateLoadForResource:resourceIdentifier request:request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody)
             pageIsProvisionallyLoading:pageIsProvisionallyLoading];
-    } else if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didInitiateLoadForResource:request:)]) {
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*WebKit::toImpl(frame)) didInitiateLoadForResource:resourceIdentifier request:wrapper(*WebKit::toImpl(request))];
+    } else if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didInitiateLoadForResource:request:)]) {
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) didInitiateLoadForResource:resourceIdentifier request:request.nsURLRequest(WebCore::HTTPBodyUpdatePolicy::DoNotUpdateHTTPBody)];
     }
 }
 
-static void didFinishLoadForResource(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, const void* clientInfo)
+void ResourceLoadClient::didFinishLoadForResource(WebKit::WebPage&, WebKit::WebFrame& frame, uint64_t resourceIdentifier)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didFinishLoadForResource:)]) {
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*WebKit::toImpl(frame)) didFinishLoadForResource:resourceIdentifier];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didFinishLoadForResource:)]) {
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) didFinishLoadForResource:resourceIdentifier];
     }
 }
 
-static void didFailLoadForResource(WKBundlePageRef, WKBundleFrameRef frame, uint64_t resourceIdentifier, WKErrorRef error, const void* clientInfo)
+void ResourceLoadClient::didFailLoadForResource(WebKit::WebPage&, WebKit::WebFrame& frame, uint64_t resourceIdentifier, const WebCore::ResourceError& error)
 {
-    auto pluginContextController = (__bridge WKWebProcessPlugInBrowserContextController *)clientInfo;
-    auto loadDelegate = pluginContextController->_loadDelegate.get();
-
-    if ([loadDelegate respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didFailLoadForResource:error:)]) {
-        [loadDelegate webProcessPlugInBrowserContextController:pluginContextController frame:wrapper(*WebKit::toImpl(frame)) didFailLoadForResource:resourceIdentifier error:wrapper(*WebKit::toImpl(error))];
+    if ([loadDelegate() respondsToSelector:@selector(webProcessPlugInBrowserContextController:frame:didFailLoadForResource:error:)]) {
+        [loadDelegate() webProcessPlugInBrowserContextController:pluginContextController() frame:wrapper(frame) didFailLoadForResource:resourceIdentifier error:error];
     }
 }
 
-static void setUpResourceLoadClient(WKWebProcessPlugInBrowserContextController *contextController, WebKit::WebPage& page)
-{
-    WKBundlePageResourceLoadClientV1 client;
-    memset(&client, 0, sizeof(client));
-
-    client.base.version = 1;
-    client.base.clientInfo = (__bridge void*) contextController;
-    client.willSendRequestForFrame = willSendRequestForFrame;
-    client.didInitiateLoadForResource = didInitiateLoadForResource;
-    client.didFinishLoadForResource = didFinishLoadForResource;
-    client.didFailLoadForResource = didFailLoadForResource;
-
-    WKBundlePageSetResourceLoadClient(toAPI(&page), &client.base);
-}
-
 - (id <WKWebProcessPlugInLoadDelegate>)loadDelegate
 {
     return _loadDelegate.getAutoreleased();
@@ -337,11 +302,11 @@
     _loadDelegate = loadDelegate;
 
     if (loadDelegate) {
-        setUpPageLoaderClient(self, *_page);
-        setUpResourceLoadClient(self, *_page);
+        _page->setInjectedBundlePageLoaderClient(std::make_unique<PageLoaderClient>(self, loadDelegate));
+        _page->setInjectedBundleResourceLoadClient(std::make_unique<ResourceLoadClient>(self, loadDelegate));
     } else {
-        WKBundlePageSetPageLoaderClient(toAPI(_page.get()), nullptr);
-        WKBundlePageSetResourceLoadClient(toAPI(_page.get()), nullptr);
+        _page->setInjectedBundlePageLoaderClient(nullptr);
+        _page->setInjectedBundleResourceLoadClient(nullptr);
     }
 }
 

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.cpp	2018-12-03 21:47:08 UTC (rev 238819)
@@ -81,14 +81,14 @@
     m_client.willLoadDataRequest(toAPI(&page), toAPI(request), toAPI(data.get()), toAPI(MIMEType.impl()), toAPI(encodingName.impl()), toURLRef(unreachableURL.string().impl()), toAPI(userData), m_client.base.clientInfo);
 }
 
-void InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame(WebPage& page, WebFrame& frame, RefPtr<API::Object>& userData)
+void InjectedBundlePageLoaderClient::didStartProvisionalLoadForFrame(WebPage& page, WebFrame& frame, CompletionHandler<void(RefPtr<API::Object>&&)>&& completionHandler)
 {
     if (!m_client.didStartProvisionalLoadForFrame)
-        return;
+        return completionHandler(nullptr);
 
     WKTypeRef userDataToPass = nullptr;
     m_client.didStartProvisionalLoadForFrame(toAPI(&page), toAPI(&frame), &userDataToPass, m_client.base.clientInfo);
-    userData = adoptRef(toImpl(userDataToPass));
+    completionHandler(adoptRef(toImpl(userDataToPass)));
 }
 
 void InjectedBundlePageLoaderClient::didReceiveServerRedirectForProvisionalLoadForFrame(WebPage& page, WebFrame& frame, RefPtr<API::Object>& userData)

Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -49,7 +49,7 @@
     void willLoadURLRequest(WebPage&, const WebCore::ResourceRequest&, API::Object*) override;
     void willLoadDataRequest(WebPage&, const WebCore::ResourceRequest&, WebCore::SharedBuffer*, const WTF::String&, const WTF::String&, const URL&, API::Object*) override;
 
-    void didStartProvisionalLoadForFrame(WebPage&, WebFrame&, RefPtr<API::Object>&) override;
+    void didStartProvisionalLoadForFrame(WebPage&, WebFrame&, CompletionHandler<void(RefPtr<API::Object>&&)>&&) override;
     void didReceiveServerRedirectForProvisionalLoadForFrame(WebPage&, WebFrame&, RefPtr<API::Object>&) override;
     void didFailProvisionalLoadWithErrorForFrame(WebPage&, WebFrame&, const WebCore::ResourceError&, RefPtr<API::Object>&) override;
     void didCommitLoadForFrame(WebPage&, WebFrame&, RefPtr<API::Object>&) override;

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2018-12-03 21:47:08 UTC (rev 238819)
@@ -457,11 +457,11 @@
     notImplemented();
 }
 
-void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
+void WebFrameLoaderClient::dispatchDidStartProvisionalLoad(CompletionHandler<void()>&& completionHandler)
 {
     WebPage* webPage = m_frame->page();
     if (!webPage)
-        return;
+        return completionHandler();
 
 #if ENABLE(FULLSCREEN_API)
     Element* documentElement = m_frame->coreFrame()->document()->documentElement();
@@ -473,16 +473,13 @@
     webPage->sandboxExtensionTracker().didStartProvisionalLoad(m_frame);
 
     WebDocumentLoader& provisionalLoader = static_cast<WebDocumentLoader&>(*m_frame->coreFrame()->loader().provisionalDocumentLoader());
-    auto& url = ""
-    RefPtr<API::Object> userData;
 
     // Notify the bundle client.
-    webPage->injectedBundleLoaderClient().didStartProvisionalLoadForFrame(*webPage, *m_frame, userData);
-
-    auto& unreachableURL = provisionalLoader.unreachableURL();
-
-    // Notify the UIProcess.
-    webPage->send(Messages::WebPageProxy::DidStartProvisionalLoadForFrame(m_frame->frameID(), provisionalLoader.navigationID(), url, unreachableURL, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
+    webPage->injectedBundleLoaderClient().didStartProvisionalLoadForFrame(*webPage, *m_frame, [completionHandler = WTFMove(completionHandler), webPage = makeRef(*webPage), url = "" unreachableURL = provisionalLoader.unreachableURL(), frameID = m_frame->frameID(), navigationID = provisionalLoader.navigationID()] (RefPtr<API::Object>&& userData) mutable {
+        // Notify the UIProcess.
+        webPage->send(Messages::WebPageProxy::DidStartProvisionalLoadForFrame(frameID, navigationID, url, unreachableURL, UserData(WebProcess::singleton().transformObjectsToHandles(userData.get()).get())));
+        completionHandler();
+    });
 }
 
 static constexpr unsigned maxTitleLength = 1000; // Closest power of 10 above the W3C recommendation for Title length.

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (238818 => 238819)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -109,7 +109,7 @@
     void dispatchDidReplaceStateWithinPage() final;
     void dispatchDidPopStateWithinPage() final;
     void dispatchWillClose() final;
-    void dispatchDidStartProvisionalLoad() final;
+    void dispatchDidStartProvisionalLoad(CompletionHandler<void()>&&) final;
     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) final;
     void dispatchDidCommitLoad(std::optional<WebCore::HasInsecureContent>) final;
     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&) final;

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (238818 => 238819)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2018-12-03 21:47:08 UTC (rev 238819)
@@ -1,3 +1,14 @@
+2018-12-03  Alex Christensen  <[email protected]>
+
+        Add WKWebProcessPlugInLoadDelegate SPI willStartProvisionalLoadForFrame with a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=192272
+
+        Reviewed by Brady Eidson.
+
+        * WebCoreSupport/WebFrameLoaderClient.h:
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::dispatchDidStartProvisionalLoad):
+
 2018-12-03  Jer Noble  <[email protected]>
 
         Get rid of old, dead Mac video fullscreen code.

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h (238818 => 238819)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -114,7 +114,7 @@
     void dispatchDidPopStateWithinPage() final;
     
     void dispatchWillClose() final;
-    void dispatchDidStartProvisionalLoad() final;
+    void dispatchDidStartProvisionalLoad(CompletionHandler<void()>&&) final;
     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) final;
     void dispatchDidCommitLoad(std::optional<WebCore::HasInsecureContent>) final;
     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&) final;

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm (238818 => 238819)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm	2018-12-03 21:47:08 UTC (rev 238819)
@@ -666,7 +666,7 @@
 #endif
 }
 
-void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
+void WebFrameLoaderClient::dispatchDidStartProvisionalLoad(CompletionHandler<void()>&& completionHandler)
 {
     ASSERT(!m_webFrame->_private->provisionalURL);
     m_webFrame->_private->provisionalURL = core(m_webFrame.get())->loader().provisionalDocumentLoader()->url().string();
@@ -683,6 +683,7 @@
     WebFrameLoadDelegateImplementationCache* implementations = WebViewGetFrameLoadDelegateImplementations(webView);
     if (implementations->didStartProvisionalLoadForFrameFunc)
         CallFrameLoadDelegate(implementations->didStartProvisionalLoadForFrameFunc, webView, @selector(webView:didStartProvisionalLoadForFrame:), m_webFrame.get());
+    completionHandler();
 }
 
 static constexpr unsigned maxTitleLength = 1000; // Closest power of 10 above the W3C recommendation for Title length.

Modified: trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp (238818 => 238819)


--- trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.cpp	2018-12-03 21:47:08 UTC (rev 238819)
@@ -419,12 +419,13 @@
         frameLoadDelegate->willCloseFrame(webView, m_webFrame);
 }
 
-void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
+void WebFrameLoaderClient::dispatchDidStartProvisionalLoad(CompletionHandler<void()>&& completionHandler)
 {
     WebView* webView = m_webFrame->webView();
     COMPtr<IWebFrameLoadDelegate> frameLoadDelegate;
     if (SUCCEEDED(webView->frameLoadDelegate(&frameLoadDelegate)))
         frameLoadDelegate->didStartProvisionalLoadForFrame(webView, m_webFrame);
+    completionHandler();
 }
 
 void WebFrameLoaderClient::dispatchDidReceiveTitle(const StringWithDirection& title)

Modified: trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h (238818 => 238819)


--- trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Source/WebKitLegacy/win/WebCoreSupport/WebFrameLoaderClient.h	2018-12-03 21:47:08 UTC (rev 238819)
@@ -91,7 +91,7 @@
     void dispatchDidReplaceStateWithinPage() override;
     void dispatchDidPopStateWithinPage() override;
     void dispatchWillClose() override;
-    void dispatchDidStartProvisionalLoad() override;
+    void dispatchDidStartProvisionalLoad(CompletionHandler<void()>&&) override;
     void dispatchDidReceiveTitle(const WebCore::StringWithDirection&) override;
     void dispatchDidCommitLoad(std::optional<WebCore::HasInsecureContent>) override;
     void dispatchDidFailProvisionalLoad(const WebCore::ResourceError&) override;

Modified: trunk/Tools/ChangeLog (238818 => 238819)


--- trunk/Tools/ChangeLog	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Tools/ChangeLog	2018-12-03 21:47:08 UTC (rev 238819)
@@ -1,3 +1,14 @@
+2018-12-03  Alex Christensen  <[email protected]>
+
+        Add WKWebProcessPlugInLoadDelegate SPI willStartProvisionalLoadForFrame with a completion handler
+        https://bugs.webkit.org/show_bug.cgi?id=192272
+
+        Reviewed by Brady Eidson.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ParserYieldTokenPlugIn.mm:
+        (-[ParserYieldTokenPlugIn webProcessPlugInBrowserContextController:willStartProvisionalLoadForFrame:completionHandler:]):
+        (-[ParserYieldTokenPlugIn webProcessPlugInBrowserContextController:didCommitLoadForFrame:]):
+
 2018-12-03  Wenson Hsieh  <[email protected]>
 
         [iOSMac] Unable to upload non-image files using drag and drop in WKWebView

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ParserYieldTokenPlugIn.mm (238818 => 238819)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ParserYieldTokenPlugIn.mm	2018-12-03 21:41:29 UTC (rev 238818)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ParserYieldTokenPlugIn.mm	2018-12-03 21:47:08 UTC (rev 238819)
@@ -37,6 +37,8 @@
 #import <WebKit/_WKRemoteObjectRegistry.h>
 #import <wtf/RetainPtr.h>
 
+static bool willStartProvisionalLoadForFrameCalled = false;
+
 @interface ParserYieldTokenPlugIn : NSObject <WKWebProcessPlugIn, WKWebProcessPlugInLoadDelegate, ParserYieldTokenTestBundle>
 @end
 
@@ -64,8 +66,16 @@
         --_numberOfTokensToTakeAfterComittingLoad;
 }
 
+- (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController*)controller willStartProvisionalLoadForFrame:(WKWebProcessPlugInFrame *)frame completionHandler:(void(^)(void))completionHandler
+{
+    willStartProvisionalLoadForFrameCalled = true;
+    completionHandler();
+}
+
 - (void)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller didCommitLoadForFrame:(WKWebProcessPlugInFrame *)frame
 {
+    ASSERT(willStartProvisionalLoadForFrameCalled);
+
     _loadCommitted = YES;
     while (_numberOfTokensToTakeAfterComittingLoad) {
         [self takeDocumentParserTokenAfterCommittingLoad];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to