[Cocoa] Expose the bundle form client
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Feb 2014 06:04:27 +0000 (06:04 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Feb 2014 06:04:27 +0000 (06:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128792

Reviewed by Anders Carlsson.

* WebKit2.xcodeproj/project.pbxproj: Added new file.
* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFormDelegatePrivate.h: Added.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(didFocusTextField): Implemented this WKBundlePageFormClient callback by calling the form
delegate.
(setUpFormClient): Added. Initializes the form client with the above function.
(-[WKWebProcessPlugInBrowserContextController _formDelegate]): Added this getter.
(-[WKWebProcessPlugInBrowserContextController _setFormDelegate:]): Added. Initializes or
clears the form client.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextControllerPrivate.h:
Declared _formDelegate property.

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

Source/WebKit2/ChangeLog
Source/WebKit2/WebKit2.xcodeproj/project.pbxproj
Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFormDelegatePrivate.h [new file with mode: 0644]
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextControllerPrivate.h

index 575caa4..a1dd81c 100644 (file)
@@ -1,5 +1,24 @@
 2014-02-13  Dan Bernstein  <mitz@apple.com>
 
+        [Cocoa] Expose the bundle form client
+        https://bugs.webkit.org/show_bug.cgi?id=128792
+
+        Reviewed by Anders Carlsson.
+
+        * WebKit2.xcodeproj/project.pbxproj: Added new file.
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFormDelegatePrivate.h: Added.
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        (didFocusTextField): Implemented this WKBundlePageFormClient callback by calling the form
+        delegate.
+        (setUpFormClient): Added. Initializes the form client with the above function.
+        (-[WKWebProcessPlugInBrowserContextController _formDelegate]): Added this getter.
+        (-[WKWebProcessPlugInBrowserContextController _setFormDelegate:]): Added. Initializes or
+        clears the form client.
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextControllerPrivate.h:
+        Declared _formDelegate property.
+
+2014-02-13  Dan Bernstein  <mitz@apple.com>
+
         [Cocoa] Add a way to get the page from a frame in the injected bundle
         https://bugs.webkit.org/show_bug.cgi?id=128791
 
index 3551aba..e87c0af 100644 (file)
                37948404150C350600E52CE9 /* WebRenderLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 37948402150C350600E52CE9 /* WebRenderLayer.h */; };
                37948408150C4B9700E52CE9 /* WKRenderLayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37948406150C4B9600E52CE9 /* WKRenderLayer.cpp */; };
                37948409150C4B9700E52CE9 /* WKRenderLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 37948407150C4B9600E52CE9 /* WKRenderLayer.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               3795789C18AD4F1900B9ED2E /* WKWebProcessPlugInFormDelegatePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 3795789B18AD4F1100B9ED2E /* WKWebProcessPlugInFormDelegatePrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                37C4C08618149C5B003688B9 /* WKBackForwardListItem.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37C4C08418149C5B003688B9 /* WKBackForwardListItem.mm */; };
                37C4C08718149C5B003688B9 /* WKBackForwardListItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08518149C5B003688B9 /* WKBackForwardListItem.h */; settings = {ATTRIBUTES = (Public, ); }; };
                37C4C08918149F23003688B9 /* WKBackForwardListItemInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */; };
                37948402150C350600E52CE9 /* WebRenderLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebRenderLayer.h; sourceTree = "<group>"; };
                37948406150C4B9600E52CE9 /* WKRenderLayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKRenderLayer.cpp; sourceTree = "<group>"; };
                37948407150C4B9600E52CE9 /* WKRenderLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKRenderLayer.h; sourceTree = "<group>"; };
+               3795789B18AD4F1100B9ED2E /* WKWebProcessPlugInFormDelegatePrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebProcessPlugInFormDelegatePrivate.h; sourceTree = "<group>"; };
                37C4C08418149C5B003688B9 /* WKBackForwardListItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKBackForwardListItem.mm; sourceTree = "<group>"; };
                37C4C08518149C5B003688B9 /* WKBackForwardListItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListItem.h; sourceTree = "<group>"; };
                37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBackForwardListItemInternal.h; sourceTree = "<group>"; };
                1F0181681858DC1500F92884 /* Cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               3795789B18AD4F1100B9ED2E /* WKWebProcessPlugInFormDelegatePrivate.h */,
                                1F0181691858DC1500F92884 /* WKWebProcessPlugInFrame.h */,
                                1F01816A1858DC1500F92884 /* WKWebProcessPlugInFrame.mm */,
                                1F01816B1858DC1500F92884 /* WKWebProcessPlugInFrameInternal.h */,
                                BC5C75C814954DA600BC4775 /* WKConnectionInternal.h in Headers */,
                                BC4A6297147313A0006C681A /* WKConnectionRef.h in Headers */,
                                BCB9E24B1120E15C00A137E0 /* WKContext.h in Headers */,
+                               3795789C18AD4F1900B9ED2E /* WKWebProcessPlugInFormDelegatePrivate.h in Headers */,
                                51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */,
                                51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */,
                                1A15841A189044F50017616C /* WKProcessClass.h in Headers */,
diff --git a/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFormDelegatePrivate.h b/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInFormDelegatePrivate.h
new file mode 100644 (file)
index 0000000..e1f0cf5
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 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 <WebKit2/WKFoundation.h>
+
+#if WK_API_ENABLED
+
+#import <WebKit2/WKWebProcessPlugInBrowserContextController.h>
+#import <WebKit2/WKWebProcessPlugInFrame.h>
+#import <WebKit2/WKWebProcessPlugInNodeHandle.h>
+
+@protocol WKWebProcessPlugInFormDelegatePrivate <NSObject>
+
+@optional
+
+- (void)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller didFocusTextField:(WKWebProcessPlugInNodeHandle *)textField inFrame:(WKWebProcessPlugInFrame *)frame;
+
+@end
+
+#endif // WK_API_ENABLED
index dd8e242..fc58a65 100644 (file)
@@ -42,7 +42,9 @@
 #import "WKURLRequestNS.h"
 #import "WKWebProcessPluginFrameInternal.h"
 #import "WKWebProcessPlugInInternal.h"
+#import "WKWebProcessPlugInFormDelegatePrivate.h"
 #import "WKWebProcessPlugInLoadDelegate.h"
+#import "WKWebProcessPlugInNodeHandleInternal.h"
 #import "WKWebProcessPlugInPageGroupInternal.h"
 #import "WKWebProcessPlugInScriptWorldInternal.h"
 #import "WeakObjCPtr.h"
@@ -57,6 +59,7 @@ using namespace WebKit;
 @implementation WKWebProcessPlugInBrowserContextController {
     API::ObjectStorage<WebPage> _page;
     WeakObjCPtr<id <WKWebProcessPlugInLoadDelegate>> _loadDelegate;
+    WeakObjCPtr<id <WKWebProcessPlugInFormDelegatePrivate>> _formDelegate;
     
     RetainPtr<WKRemoteObjectRegistry> _remoteObjectRegistry;
 }
@@ -203,6 +206,27 @@ static void setUpResourceLoadClient(WKWebProcessPlugInBrowserContextController *
     page.initializeInjectedBundleResourceLoadClient(&client.base);
 }
 
+static void didFocusTextField(WKBundlePageRef page, WKBundleNodeHandleRef htmlInputElementHandleRef, WKBundleFrameRef frameRef, const void* clientInfo)
+{
+    WKWebProcessPlugInBrowserContextController *controller = (WKWebProcessPlugInBrowserContextController *)clientInfo;
+    auto formDelegate = controller->_formDelegate.get();
+
+    if ([formDelegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:didFocusTextField:inFrame:)])
+        [formDelegate _webProcessPlugInBrowserContextController:controller didFocusTextField:wrapper(*toImpl(htmlInputElementHandleRef)) inFrame:wrapper(*toImpl(frameRef))];
+}
+
+static void setUpFormClient(WKWebProcessPlugInBrowserContextController *contextController, WebPage& page)
+{
+    WKBundlePageFormClientV2 client;
+    memset(&client, 0, sizeof(client));
+
+    client.base.version = 2;
+    client.base.clientInfo = contextController;
+    client.didFocusTextField = didFocusTextField;
+
+    page.initializeInjectedBundleFormClient(&client.base);
+}
+
 - (id <WKWebProcessPlugInLoadDelegate>)loadDelegate
 {
     return _loadDelegate.getAutoreleased();
@@ -300,6 +324,21 @@ static void setUpResourceLoadClient(WKWebProcessPlugInBrowserContextController *
     return _remoteObjectRegistry.get();
 }
 
+- (id <WKWebProcessPlugInFormDelegatePrivate>)_formDelegate
+{
+    return _formDelegate.getAutoreleased();
+}
+
+- (void)_setFormDelegate:(id <WKWebProcessPlugInFormDelegatePrivate>)formDelegate
+{
+    _formDelegate = formDelegate;
+
+    if (formDelegate)
+        setUpFormClient(self, *_page);
+    else
+        _page->initializeInjectedBundleFormClient(nullptr);
+}
+
 @end
 
 #endif // WK_API_ENABLED
index 1f1f28e..6bc3d07 100644 (file)
@@ -31,6 +31,7 @@
 
 @class WKBrowsingContextHandle;
 @class WKRemoteObjectRegistry;
+@protocol WKWebProcessPlugInFormDelegatePrivate;
 
 @interface WKWebProcessPlugInBrowserContextController (Private)
 
@@ -40,6 +41,8 @@
 
 @property (nonatomic, readonly) WKRemoteObjectRegistry *remoteObjectRegistry;
 
+@property (weak, setter=_setFormDelegate:) id <WKWebProcessPlugInFormDelegatePrivate> _formDelegate;
+
 + (instancetype)lookUpBrowsingContextFromHandle:(WKBrowsingContextHandle *)handle;
 
 @end