<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[209775] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/209775">209775</a></dd>
<dt>Author</dt> <dd>aestes@apple.com</dd>
<dt>Date</dt> <dd>2016-12-13 14:08:49 -0800 (Tue, 13 Dec 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Cocoa] Implement -shouldInsertText: on WKWebProcessPlugInEditingDelegate
https://bugs.webkit.org/show_bug.cgi?id=165785
&lt;rdar://problem/26929398&gt;

Reviewed by Darin Adler.

Source/WebKit2:

* WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h: Defined
WKEditorInsertAction and declared
-_webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction:.
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(toWK): Added. Mapped a WebCore::EditorInsertAction to a WKEditorInsertAction.
(-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]): Implemented
EditorClient::shouldInsertText() by calling
-_webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction: with
the text, wrapped range handle, and action. Added shouldInsertText to DelegateMethods and
initialized it according to whether the delegate responds to shouldInsertText:.

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm:
(-[BundleEditingDelegateRemoteObject shouldInsertText:replacingRange:givenAction:]): Added
expectations for the text, range, and action.
(TEST): Set the &quot;EditingDelegateShouldInsertText&quot; bundle parameter to NO so that the plug-in
will return NO in -_webProcessPlugInBrowserContextController:willInsertText:. Added a
plain-text string to the pasteboard, executed a paste action, and verified that the selected
text in the web view did not change.
* TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegatePlugIn.mm:
(-[BundleEditingDelegatePlugIn webProcessPlugIn:didCreateBrowserContextController:]): Set
_editingDelegateShouldInsertText according to the &quot;EditingDelegateShouldInsertText&quot; bundle
parameter.
(-[BundleEditingDelegatePlugIn _webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction:]):
Added. Called -shouldInsertText:replacingRange:givenAction: on the remote object proxy
and returned the value of _editingDelegateShouldInsertText.
* TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegateProtocol.h: Declared
-shouldInsertText:replacingRange:givenAction:.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleAPICocoaWKWebProcessPlugInEditingDelegateh">trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessInjectedBundleAPImacWKWebProcessPlugInBrowserContextControllermm">trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaBundleEditingDelegatemm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaBundleEditingDelegatePlugInmm">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegatePlugIn.mm</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2CocoaBundleEditingDelegateProtocolh">trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegateProtocol.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Source/WebKit2/ChangeLog        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-12-13  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [Cocoa] Implement -shouldInsertText: on WKWebProcessPlugInEditingDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=165785
+        &lt;rdar://problem/26929398&gt;
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h: Defined
+        WKEditorInsertAction and declared
+        -_webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction:.
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        (toWK): Added. Mapped a WebCore::EditorInsertAction to a WKEditorInsertAction.
+        (-[WKWebProcessPlugInBrowserContextController _setEditingDelegate:]): Implemented
+        EditorClient::shouldInsertText() by calling
+        -_webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction: with
+        the text, wrapped range handle, and action. Added shouldInsertText to DelegateMethods and
+        initialized it according to whether the delegate responds to shouldInsertText:.
+
</ins><span class="cx"> 2016-12-13  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         NSArray leaks seen in Safari, allocated under WKIconDatabaseTryCopyCGImageArrayForURL
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleAPICocoaWKWebProcessPlugInEditingDelegateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/Cocoa/WKWebProcessPlugInEditingDelegate.h        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -32,11 +32,18 @@
</span><span class="cx"> 
</span><span class="cx"> NS_ASSUME_NONNULL_BEGIN
</span><span class="cx"> 
</span><ins>+typedef NS_ENUM(NSInteger, WKEditorInsertAction) {
+    WKEditorInsertActionTyped,
+    WKEditorInsertActionPasted,
+    WKEditorInsertActionDropped,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
</ins><span class="cx"> WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA))
</span><span class="cx"> @protocol WKWebProcessPlugInEditingDelegate &lt;NSObject&gt;
</span><span class="cx"> 
</span><span class="cx"> @optional
</span><span class="cx"> 
</span><ins>+- (BOOL)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller shouldInsertText:(NSString *)text replacingRange:(WKWebProcessPlugInRangeHandle *)range givenAction:(WKEditorInsertAction)action;
</ins><span class="cx"> - (void)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller willWriteRangeToPasteboard:(WKWebProcessPlugInRangeHandle *)range;
</span><span class="cx"> - (NSDictionary&lt;NSString *, NSData *&gt; *)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller pasteboardDataForRange:(WKWebProcessPlugInRangeHandle *)range;
</span><span class="cx"> - (void)_webProcessPlugInBrowserContextControllerDidWriteToPasteboard:(WKWebProcessPlugInBrowserContextController *)controller;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessInjectedBundleAPImacWKWebProcessPlugInBrowserContextControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -573,6 +573,18 @@
</span><span class="cx">     return _editingDelegate.getAutoreleased();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static inline WKEditorInsertAction toWK(EditorInsertAction action)
+{
+    switch (action) {
+    case EditorInsertActionTyped:
+        return WKEditorInsertActionTyped;
+    case EditorInsertActionPasted:
+        return WKEditorInsertActionPasted;
+    case EditorInsertActionDropped:
+        return WKEditorInsertActionDropped;
+    }
+}
+
</ins><span class="cx"> - (void)_setEditingDelegate:(id &lt;WKWebProcessPlugInEditingDelegate&gt;)editingDelegate
</span><span class="cx"> {
</span><span class="cx">     _editingDelegate = editingDelegate;
</span><span class="lines">@@ -586,6 +598,14 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">     private:
</span><ins>+        bool shouldInsertText(WebPage&amp;, StringImpl* text, Range* rangeToReplace, EditorInsertAction action) final
+        {
+            if (!m_delegateMethods.shouldInsertText)
+                return true;
+
+            return [m_controller-&gt;_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller shouldInsertText:String(text) replacingRange:wrapper(*InjectedBundleRangeHandle::getOrCreate(rangeToReplace)) givenAction:toWK(action)];
+        }
+
</ins><span class="cx">         void willWriteToPasteboard(WebKit::WebPage&amp;, WebCore::Range* range) final
</span><span class="cx">         {
</span><span class="cx">             if (!m_delegateMethods.willWriteToPasteboard)
</span><span class="lines">@@ -617,12 +637,14 @@
</span><span class="cx">         WKWebProcessPlugInBrowserContextController *m_controller;
</span><span class="cx">         const struct DelegateMethods {
</span><span class="cx">             DelegateMethods(RetainPtr&lt;id &lt;WKWebProcessPlugInEditingDelegate&gt;&gt; delegate)
</span><del>-                : willWriteToPasteboard([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:willWriteRangeToPasteboard:)])
</del><ins>+                : shouldInsertText([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction:)])
+                , willWriteToPasteboard([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:willWriteRangeToPasteboard:)])
</ins><span class="cx">                 , getPasteboardDataForRange([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextController:pasteboardDataForRange:)])
</span><span class="cx">                 , didWriteToPasteboard([delegate respondsToSelector:@selector(_webProcessPlugInBrowserContextControllerDidWriteToPasteboard:)])
</span><span class="cx">             {
</span><span class="cx">             }
</span><span class="cx"> 
</span><ins>+            bool shouldInsertText;
</ins><span class="cx">             bool willWriteToPasteboard;
</span><span class="cx">             bool getPasteboardDataForRange;
</span><span class="cx">             bool didWriteToPasteboard;
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Tools/ChangeLog        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-12-13  Andy Estes  &lt;aestes@apple.com&gt;
+
+        [Cocoa] Implement -shouldInsertText: on WKWebProcessPlugInEditingDelegate
+        https://bugs.webkit.org/show_bug.cgi?id=165785
+        &lt;rdar://problem/26929398&gt;
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm:
+        (-[BundleEditingDelegateRemoteObject shouldInsertText:replacingRange:givenAction:]): Added
+        expectations for the text, range, and action.
+        (TEST): Set the &quot;EditingDelegateShouldInsertText&quot; bundle parameter to NO so that the plug-in
+        will return NO in -_webProcessPlugInBrowserContextController:willInsertText:. Added a
+        plain-text string to the pasteboard, executed a paste action, and verified that the selected
+        text in the web view did not change.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegatePlugIn.mm:
+        (-[BundleEditingDelegatePlugIn webProcessPlugIn:didCreateBrowserContextController:]): Set
+        _editingDelegateShouldInsertText according to the &quot;EditingDelegateShouldInsertText&quot; bundle
+        parameter.
+        (-[BundleEditingDelegatePlugIn _webProcessPlugInBrowserContextController:shouldInsertText:replacingRange:givenAction:]):
+        Added. Called -shouldInsertText:replacingRange:givenAction: on the remote object proxy
+        and returned the value of _editingDelegateShouldInsertText.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegateProtocol.h: Declared
+        -shouldInsertText:replacingRange:givenAction:.
+
</ins><span class="cx"> 2016-12-13  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r209544.
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaBundleEditingDelegatemm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -35,11 +35,13 @@
</span><span class="cx"> #import &quot;Test.h&quot;
</span><span class="cx"> #import &quot;TestNavigationDelegate.h&quot;
</span><span class="cx"> #import &quot;WKWebViewConfigurationExtras.h&quot;
</span><ins>+#import &lt;WebKit/WKProcessPoolPrivate.h&gt;
</ins><span class="cx"> #import &lt;WebKit/WKWebViewPrivate.h&gt;
</span><span class="cx"> #import &lt;WebKit/_WKRemoteObjectInterface.h&gt;
</span><span class="cx"> #import &lt;WebKit/_WKRemoteObjectRegistry.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><ins>+static bool shouldInsertTextCalled;
</ins><span class="cx"> static bool willWriteToPasteboard;
</span><span class="cx"> static bool didWriteToPasteboard;
</span><span class="cx"> 
</span><span class="lines">@@ -48,6 +50,14 @@
</span><span class="cx"> 
</span><span class="cx"> @implementation BundleEditingDelegateRemoteObject
</span><span class="cx"> 
</span><ins>+- (void)shouldInsertText:(NSString *)text replacingRange:(NSString *)rangeAsString givenAction:(WKEditorInsertAction)action
+{
+    EXPECT_WK_STREQ(&quot;hello&quot;, text);
+    EXPECT_WK_STREQ(&quot;something&quot;, rangeAsString);
+    EXPECT_EQ(WKEditorInsertActionPasted, action);
+    shouldInsertTextCalled = true;
+}
+
</ins><span class="cx"> - (void)willWriteToPasteboard:(NSString *)rangeAsString
</span><span class="cx"> {
</span><span class="cx">     willWriteToPasteboard = true;
</span><span class="lines">@@ -64,10 +74,11 @@
</span><span class="cx"> TEST(WebKit2, WKWebProcessPlugInEditingDelegate)
</span><span class="cx"> {
</span><span class="cx">     RetainPtr&lt;WKWebViewConfiguration&gt; configuration = retainPtr([WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@&quot;BundleEditingDelegatePlugIn&quot;]);
</span><ins>+    [[configuration processPool] _setObject:[NSNumber numberWithBool:NO] forBundleParameter:@&quot;EditingDelegateShouldInsertText&quot;];
</ins><span class="cx">     
</span><span class="cx">     RetainPtr&lt;WKWebView&gt; webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
</span><span class="cx"> 
</span><del>-    [webView loadHTMLString:@&quot;Just something to copy &lt;script&gt; var textNode = document.body.firstChild; document.getSelection().setBaseAndExtent(textNode, 5, textNode, 14) &lt;/script&gt;&quot; baseURL:nil];
</del><ins>+    [webView loadHTMLString:@&quot;&lt;body style='-webkit-user-modify: read-write-plaintext-only'&gt;Just something to copy &lt;script&gt; var textNode = document.body.firstChild; document.getSelection().setBaseAndExtent(textNode, 5, textNode, 14) &lt;/script&gt;&quot; baseURL:nil];
</ins><span class="cx">     [webView _test_waitForDidFinishNavigation];
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;BundleEditingDelegateRemoteObject&gt; object = adoptNS([[BundleEditingDelegateRemoteObject alloc] init]);
</span><span class="lines">@@ -77,11 +88,33 @@
</span><span class="cx">     [webView performSelector:@selector(copy:) withObject:nil];
</span><span class="cx"> 
</span><span class="cx">     TestWebKitAPI::Util::run(&amp;didWriteToPasteboard);
</span><ins>+
+    NSString *copiedString = nil;
</ins><span class="cx"> #if PLATFORM(MAC)
</span><del>-    EXPECT_STREQ(&quot;hello&quot;, [[NSPasteboard generalPasteboard] stringForType:@&quot;org.webkit.data&quot;].UTF8String);
</del><ins>+    copiedString = [[NSPasteboard generalPasteboard] stringForType:@&quot;org.webkit.data&quot;];
</ins><span class="cx"> #elif PLATFORM(IOS)
</span><del>-    EXPECT_TRUE([[[UIPasteboard generalPasteboard] dataForPasteboardType:@&quot;org.webkit.data&quot;] isEqual:[@&quot;hello&quot; dataUsingEncoding:NSUTF8StringEncoding]]);
</del><ins>+    copiedString = [[[NSString alloc] initWithData:[[UIPasteboard generalPasteboard] dataForPasteboardType:@&quot;org.webkit.data&quot;] encoding:NSUTF8StringEncoding] autorelease];
</ins><span class="cx"> #endif
</span><ins>+    EXPECT_WK_STREQ(&quot;hello&quot;, copiedString);
+
+#if PLATFORM(MAC)
+    [[NSPasteboard generalPasteboard] setString:copiedString forType:@&quot;public.utf8-plain-text&quot;];
+#elif PLATFORM(IOS)
+    [[UIPasteboard generalPasteboard] setValue:copiedString forPasteboardType:@&quot;public.utf8-plain-text&quot;];
+#endif
+    [webView performSelector:@selector(paste:) withObject:nil];
+
+    TestWebKitAPI::Util::run(&amp;shouldInsertTextCalled);
+
+    __block bool doneEvaluatingJavaScript = false;
+    [webView evaluateJavaScript:@&quot;document.body.firstChild.textContent&quot; completionHandler:^(id _Nullable value, NSError * _Nullable error) {
+        EXPECT_NULL(error);
+        EXPECT_TRUE([value isKindOfClass:[NSString class]]);
+        EXPECT_WK_STREQ(&quot;Just something to copy &quot;, (NSString *)value);
+        doneEvaluatingJavaScript = true;
+    }];
+
+    TestWebKitAPI::Util::run(&amp;doneEvaluatingJavaScript);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaBundleEditingDelegatePlugInmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegatePlugIn.mm (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegatePlugIn.mm        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegatePlugIn.mm        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -45,6 +45,7 @@
</span><span class="cx">     RetainPtr&lt;WKWebProcessPlugInBrowserContextController&gt; _browserContextController;
</span><span class="cx">     RetainPtr&lt;WKWebProcessPlugInController&gt; _plugInController;
</span><span class="cx">     RetainPtr&lt;id &lt;BundleEditingDelegateProtocol&gt;&gt; _remoteObject;
</span><ins>+    BOOL _editingDelegateShouldInsertText;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
</span><span class="lines">@@ -54,6 +55,12 @@
</span><span class="cx">     _browserContextController = browserContextController;
</span><span class="cx">     _plugInController = plugInController;
</span><span class="cx"> 
</span><ins>+    if (id shouldInsertText = [plugInController.parameters valueForKey:@&quot;EditingDelegateShouldInsertText&quot;]) {
+        ASSERT([shouldInsertText isKindOfClass:[NSNumber class]]);
+        _editingDelegateShouldInsertText = [(NSNumber *)shouldInsertText boolValue];
+    } else
+        _editingDelegateShouldInsertText = YES;
+
</ins><span class="cx">     _WKRemoteObjectInterface *interface = [_WKRemoteObjectInterface remoteObjectInterfaceWithProtocol:@protocol(BundleEditingDelegateProtocol)];
</span><span class="cx">     _remoteObject = [browserContextController._remoteObjectRegistry remoteObjectProxyWithInterface:interface];
</span><span class="cx"> 
</span><span class="lines">@@ -60,6 +67,13 @@
</span><span class="cx">     [_browserContextController _setEditingDelegate:self];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (BOOL)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller shouldInsertText:(nonnull NSString *)text replacingRange:(nonnull WKWebProcessPlugInRangeHandle *)range givenAction:(WKEditorInsertAction)action
+{
+    JSValue *jsRange = [range.frame jsRangeForRangeHandle:range inWorld:[WKWebProcessPlugInScriptWorld normalWorld]];
+    [_remoteObject shouldInsertText:text replacingRange:[jsRange toString] givenAction:action];
+    return _editingDelegateShouldInsertText;
+}
+
</ins><span class="cx"> - (void)_webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller willWriteRangeToPasteboard:(WKWebProcessPlugInRangeHandle *)range
</span><span class="cx"> {
</span><span class="cx">     JSValue *jsRange = [range.frame jsRangeForRangeHandle:range inWorld:[WKWebProcessPlugInScriptWorld normalWorld]];
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2CocoaBundleEditingDelegateProtocolh"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegateProtocol.h (209774 => 209775)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegateProtocol.h        2016-12-13 22:05:00 UTC (rev 209774)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegateProtocol.h        2016-12-13 22:08:49 UTC (rev 209775)
</span><span class="lines">@@ -27,8 +27,11 @@
</span><span class="cx"> 
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx"> 
</span><ins>+#import &lt;WebKit/WKWebProcessPlugInEditingDelegate.h&gt;
+
</ins><span class="cx"> @protocol BundleEditingDelegateProtocol &lt;NSObject&gt;
</span><span class="cx"> 
</span><ins>+- (void)shouldInsertText:(NSString *)text replacingRange:(NSString *)rangeAsString givenAction:(WKEditorInsertAction)action;
</ins><span class="cx"> - (void)willWriteToPasteboard:(NSString *)rangeAsString;
</span><span class="cx"> - (void)didWriteToPasteboard;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>