Make it possible for apps that use both WK1 and WK2 to use MessagePorts.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jan 2018 17:45:17 +0000 (17:45 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jan 2018 17:45:17 +0000 (17:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182229

Reviewed by Chris Dumez.

Source/WebCore:

Covered by existing LayoutTests and a new API test.

* dom/messageports/MessagePortChannel.cpp:
(WebCore::MessagePortChannel::checkRemotePortForActivity): Don't use the global singleton
  provider. Instead use the provider that belongs to the owning registry.

* dom/messageports/MessagePortChannelProviderImpl.cpp:
(WebCore::MessagePortChannelProviderImpl::MessagePortChannelProviderImpl): Pass a reference
  to *this to the Registry.
* dom/messageports/MessagePortChannelProviderImpl.h:

* dom/messageports/MessagePortChannelRegistry.cpp:
(WebCore::MessagePortChannelRegistry::MessagePortChannelRegistry): Keep a Provider member so
  MessagePortChannels can get to it instead of relying on the global singleton provider.
* dom/messageports/MessagePortChannelRegistry.h:
(WebCore::MessagePortChannelRegistry::provider):

Source/WebKit:

* UIProcess/UIMessagePortChannelProvider.cpp:
(WebKit::UIMessagePortChannelProvider::UIMessagePortChannelProvider):

* UIProcess/WebPageProxy.cpp:
(WebKit::m_configurationPreferenceValues): The UI process does not need to override the
  global singleton provider. It can remain the default ProviderImpl to allow WK1 views
  to work fine, too.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/MessagePortProviders.mm: Added.

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/messageports/MessagePortChannel.cpp
Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.cpp
Source/WebCore/dom/messageports/MessagePortChannelProviderImpl.h
Source/WebCore/dom/messageports/MessagePortChannelRegistry.cpp
Source/WebCore/dom/messageports/MessagePortChannelRegistry.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/UIMessagePortChannelProvider.cpp
Source/WebKit/UIProcess/WebPageProxy.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/MessagePortProviders.mm [new file with mode: 0644]

index 8984611..a5a0d97 100644 (file)
@@ -1,3 +1,27 @@
+2018-01-29  Brady Eidson  <beidson@apple.com>
+
+        Make it possible for apps that use both WK1 and WK2 to use MessagePorts.
+        https://bugs.webkit.org/show_bug.cgi?id=182229
+
+        Reviewed by Chris Dumez.
+
+        Covered by existing LayoutTests and a new API test.
+
+        * dom/messageports/MessagePortChannel.cpp:
+        (WebCore::MessagePortChannel::checkRemotePortForActivity): Don't use the global singleton
+          provider. Instead use the provider that belongs to the owning registry.
+
+        * dom/messageports/MessagePortChannelProviderImpl.cpp:
+        (WebCore::MessagePortChannelProviderImpl::MessagePortChannelProviderImpl): Pass a reference
+          to *this to the Registry.
+        * dom/messageports/MessagePortChannelProviderImpl.h:
+
+        * dom/messageports/MessagePortChannelRegistry.cpp:
+        (WebCore::MessagePortChannelRegistry::MessagePortChannelRegistry): Keep a Provider member so
+          MessagePortChannels can get to it instead of relying on the global singleton provider.
+        * dom/messageports/MessagePortChannelRegistry.h:
+        (WebCore::MessagePortChannelRegistry::provider):
+
 2018-01-29  Per Arne Vollan  <pvollan@apple.com>
 
         Layout Test fast/events/beforeunload-dom-manipulation-crash.html is crashing
index 26fbafb..d7506f0 100644 (file)
@@ -240,7 +240,7 @@ void MessagePortChannel::checkRemotePortForActivity(const MessagePortIdentifier&
         callback(hasActivity);
     } };
 
-    MessagePortChannelProvider::singleton().checkProcessLocalPortForActivity(remotePort, *m_processes[i], WTFMove(outerCallback));
+    m_registry.provider().checkProcessLocalPortForActivity(remotePort, *m_processes[i], WTFMove(outerCallback));
 }
 
 bool MessagePortChannel::hasAnyMessagesPendingOrInFlight() const
index fedafc9..efb83fd 100644 (file)
 
 namespace WebCore {
 
+MessagePortChannelProviderImpl::MessagePortChannelProviderImpl()
+    : m_registry(*this)
+{
+}
+
 MessagePortChannelProviderImpl::~MessagePortChannelProviderImpl()
 {
     ASSERT_NOT_REACHED();
index b4771f4..28f6ad5 100644 (file)
@@ -32,6 +32,7 @@ namespace WebCore {
 
 class MessagePortChannelProviderImpl : public MessagePortChannelProvider {
 public:
+    MessagePortChannelProviderImpl();
     ~MessagePortChannelProviderImpl() final;
 
 private:
index c77a8ff..7e78e03 100644 (file)
 
 namespace WebCore {
 
+MessagePortChannelRegistry::MessagePortChannelRegistry(MessagePortChannelProvider& provider)
+    : m_provider(provider)
+{
+}
+
 MessagePortChannelRegistry::~MessagePortChannelRegistry()
 {
     ASSERT(m_openChannels.isEmpty());
index a5108b0..42a9f36 100644 (file)
@@ -35,6 +35,7 @@ namespace WebCore {
 
 class MessagePortChannelRegistry {
 public:
+    WEBCORE_EXPORT MessagePortChannelRegistry(MessagePortChannelProvider&);
     WEBCORE_EXPORT ~MessagePortChannelRegistry();
     
     WEBCORE_EXPORT void didCreateMessagePortChannel(const MessagePortIdentifier& port1, const MessagePortIdentifier& port2);
@@ -50,8 +51,12 @@ public:
     WEBCORE_EXPORT void messagePortChannelCreated(MessagePortChannel&);
     WEBCORE_EXPORT void messagePortChannelDestroyed(MessagePortChannel&);
 
+    MessagePortChannelProvider& provider() { return m_provider; }
+
 private:
     HashMap<MessagePortIdentifier, MessagePortChannel*> m_openChannels;
+    MessagePortChannelProvider& m_provider;
+
 };
 
 } // namespace WebCore
index ee9886b..e2812d1 100644 (file)
@@ -1,3 +1,18 @@
+2018-01-29  Brady Eidson  <beidson@apple.com>
+
+        Make it possible for apps that use both WK1 and WK2 to use MessagePorts.
+        https://bugs.webkit.org/show_bug.cgi?id=182229
+
+        Reviewed by Chris Dumez.
+
+        * UIProcess/UIMessagePortChannelProvider.cpp:
+        (WebKit::UIMessagePortChannelProvider::UIMessagePortChannelProvider):
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::m_configurationPreferenceValues): The UI process does not need to override the 
+          global singleton provider. It can remain the default ProviderImpl to allow WK1 views 
+          to work fine, too.
+
 2018-01-29  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         WebDriver: ASSERTION FAILED: !m_loadTimer.isActive()
index 3d6ca1e..5f68f31 100644 (file)
@@ -41,6 +41,7 @@ UIMessagePortChannelProvider& UIMessagePortChannelProvider::singleton()
 }
 
 UIMessagePortChannelProvider::UIMessagePortChannelProvider()
+    : m_registry(*this)
 {
 }
 
index 3ec2b88..96eb5a9 100644 (file)
@@ -415,11 +415,6 @@ WebPageProxy::WebPageProxy(PageClient& pageClient, WebProcessProxy& process, uin
         this->dispatchActivityStateChange();
     });
 #endif
-
-    static std::once_flag once;
-    std::call_once(once, [] {
-        MessagePortChannelProvider::setSharedProvider(UIMessagePortChannelProvider::singleton());
-    });
 }
 
 WebPageProxy::~WebPageProxy()
index aa1d746..8658f6a 100644 (file)
@@ -1,3 +1,13 @@
+2018-01-29  Brady Eidson  <beidson@apple.com>
+
+        Make it possible for apps that use both WK1 and WK2 to use MessagePorts.
+        https://bugs.webkit.org/show_bug.cgi?id=182229
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/MessagePortProviders.mm: Added.
+
 2018-01-29  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         WebDriver: properly recover w3c tests after a webdriver server crash
index a062919..bbb17f9 100644 (file)
                514958BE1F7427AC00E87BAD /* WKWebViewAutofillTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */; };
                515BE16F1D428BB100DD7C68 /* StoreBlobToBeDeleted.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */; };
                515BE1711D428E4B00DD7C68 /* StoreBlobThenDelete.mm in Sources */ = {isa = PBXBuildFile; fileRef = 515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */; };
+               5165FE04201EE620009F7EC3 /* MessagePortProviders.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5165FE03201EE617009F7EC3 /* MessagePortProviders.mm */; };
                51714EB41CF8C78C004723C4 /* WebProcessKillIDBCleanup-1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */; };
                51714EB51CF8C78C004723C4 /* WebProcessKillIDBCleanup-2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */; };
                51714EB81CF8CA17004723C4 /* WebProcessKillIDBCleanup.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */; };
                514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewAutofillTests.mm; sourceTree = "<group>"; };
                515BE16E1D4288FF00DD7C68 /* StoreBlobToBeDeleted.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = StoreBlobToBeDeleted.html; sourceTree = "<group>"; };
                515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StoreBlobThenDelete.mm; sourceTree = "<group>"; };
+               5165FE03201EE617009F7EC3 /* MessagePortProviders.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MessagePortProviders.mm; sourceTree = "<group>"; };
                51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "WebProcessKillIDBCleanup-1.html"; sourceTree = "<group>"; };
                51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "WebProcessKillIDBCleanup-2.html"; sourceTree = "<group>"; };
                51714EB61CF8C7A4004723C4 /* WebProcessKillIDBCleanup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebProcessKillIDBCleanup.mm; sourceTree = "<group>"; };
                                51E6A8921D2F1BEC00C004B6 /* LocalStorageClear.mm */,
                                46C519D81D355A7300DAA51A /* LocalStorageNullEntries.mm */,
                                7A6A2C6F1DCCF87B00C0D085 /* LocalStorageQuirkTest.mm */,
+                               5165FE03201EE617009F7EC3 /* MessagePortProviders.mm */,
                                51CD1C6A1B38CE3600142CA5 /* ModalAlerts.mm */,
                                1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
                                5CAE4637201937CD0051610F /* NetworkProcessCrashNonPersistentDataStore.mm */,
                                7CCE7F0C1A411AE600447C4C /* PrivateBrowsingPushStateNoHistoryCallback.cpp in Sources */,
                                4647B1261EBA3B850041D7EF /* ProcessDidTerminate.cpp in Sources */,
                                7C83E0C11D0A652F00FEBCF3 /* ProvisionalURLNotChange.mm in Sources */,
+                               5165FE04201EE620009F7EC3 /* MessagePortProviders.mm in Sources */,
                                7CCE7EC81A411A7E00447C4C /* PublicSuffix.mm in Sources */,
                                7C83E0C21D0A653500FEBCF3 /* QuickLook.mm in Sources */,
                                7CCE7F0D1A411AE600447C4C /* ReloadPageAfterCrash.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/MessagePortProviders.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/MessagePortProviders.mm
new file mode 100644 (file)
index 0000000..5542c41
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WebFrame.h>
+#import <wtf/RetainPtr.h>
+
+static bool didFinishLoad;
+
+@interface MessagePortFrameLoadDelegate : NSObject <WebFrameLoadDelegate> {
+}
+@end
+@implementation MessagePortFrameLoadDelegate
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(MessagePort, Providers)
+{
+    // Loading a WebView that uses message ports guarantees that the default MessagePortChannelProviderImpl is set.
+    auto wk1View = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) frameName:nil groupName:nil]);
+    auto delegate = adoptNS([[MessagePortFrameLoadDelegate alloc] init]);
+    [wk1View.get() setFrameLoadDelegate:delegate.get()];
+    [[wk1View mainFrame] loadHTMLString:@"<script>new MessageChannel;</script>" baseURL:nil];
+
+    Util::run(&didFinishLoad);
+
+    // Now using a WKWebView to load content that uses message ports will use the WK2-style message ports.
+    // This should not conflict with WK1-style message ports.
+    // The conflict is caught by a RELEASE_ASSERT so, if this doesn't crash, it passes.
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:@"<script>new MessageChannel;</script>"];
+}
+
+} // namespace TestWebKitAPI
+
+#endif // WK_API_ENABLED