<!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
<rdar://problem/26929398>
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 "EditingDelegateShouldInsertText" 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 "EditingDelegateShouldInsertText" 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 <aestes@apple.com>
+
+ [Cocoa] Implement -shouldInsertText: on WKWebProcessPlugInEditingDelegate
+ https://bugs.webkit.org/show_bug.cgi?id=165785
+ <rdar://problem/26929398>
+
+ 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 <pecoraro@apple.com>
</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 <NSObject>
</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<NSString *, NSData *> *)_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 <WKWebProcessPlugInEditingDelegate>)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&, StringImpl* text, Range* rangeToReplace, EditorInsertAction action) final
+ {
+ if (!m_delegateMethods.shouldInsertText)
+ return true;
+
+ return [m_controller->_editingDelegate.get() _webProcessPlugInBrowserContextController:m_controller shouldInsertText:String(text) replacingRange:wrapper(*InjectedBundleRangeHandle::getOrCreate(rangeToReplace)) givenAction:toWK(action)];
+ }
+
</ins><span class="cx"> void willWriteToPasteboard(WebKit::WebPage&, 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<id <WKWebProcessPlugInEditingDelegate>> 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 <aestes@apple.com>
+
+ [Cocoa] Implement -shouldInsertText: on WKWebProcessPlugInEditingDelegate
+ https://bugs.webkit.org/show_bug.cgi?id=165785
+ <rdar://problem/26929398>
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WebKit2Cocoa/BundleEditingDelegate.mm:
+ (-[BundleEditingDelegateRemoteObject shouldInsertText:replacingRange:givenAction:]): Added
+ expectations for the text, range, and action.
+ (TEST): Set the "EditingDelegateShouldInsertText" 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 "EditingDelegateShouldInsertText" 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 <cdumez@apple.com>
</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 "Test.h"
</span><span class="cx"> #import "TestNavigationDelegate.h"
</span><span class="cx"> #import "WKWebViewConfigurationExtras.h"
</span><ins>+#import <WebKit/WKProcessPoolPrivate.h>
</ins><span class="cx"> #import <WebKit/WKWebViewPrivate.h>
</span><span class="cx"> #import <WebKit/_WKRemoteObjectInterface.h>
</span><span class="cx"> #import <WebKit/_WKRemoteObjectRegistry.h>
</span><span class="cx"> #import <wtf/RetainPtr.h>
</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("hello", text);
+ EXPECT_WK_STREQ("something", 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<WKWebViewConfiguration> configuration = retainPtr([WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@"BundleEditingDelegatePlugIn"]);
</span><ins>+ [[configuration processPool] _setObject:[NSNumber numberWithBool:NO] forBundleParameter:@"EditingDelegateShouldInsertText"];
</ins><span class="cx">
</span><span class="cx"> RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
</span><span class="cx">
</span><del>- [webView loadHTMLString:@"Just something to copy <script> var textNode = document.body.firstChild; document.getSelection().setBaseAndExtent(textNode, 5, textNode, 14) </script>" baseURL:nil];
</del><ins>+ [webView loadHTMLString:@"<body style='-webkit-user-modify: read-write-plaintext-only'>Just something to copy <script> var textNode = document.body.firstChild; document.getSelection().setBaseAndExtent(textNode, 5, textNode, 14) </script>" baseURL:nil];
</ins><span class="cx"> [webView _test_waitForDidFinishNavigation];
</span><span class="cx">
</span><span class="cx"> RetainPtr<BundleEditingDelegateRemoteObject> 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(&didWriteToPasteboard);
</span><ins>+
+ NSString *copiedString = nil;
</ins><span class="cx"> #if PLATFORM(MAC)
</span><del>- EXPECT_STREQ("hello", [[NSPasteboard generalPasteboard] stringForType:@"org.webkit.data"].UTF8String);
</del><ins>+ copiedString = [[NSPasteboard generalPasteboard] stringForType:@"org.webkit.data"];
</ins><span class="cx"> #elif PLATFORM(IOS)
</span><del>- EXPECT_TRUE([[[UIPasteboard generalPasteboard] dataForPasteboardType:@"org.webkit.data"] isEqual:[@"hello" dataUsingEncoding:NSUTF8StringEncoding]]);
</del><ins>+ copiedString = [[[NSString alloc] initWithData:[[UIPasteboard generalPasteboard] dataForPasteboardType:@"org.webkit.data"] encoding:NSUTF8StringEncoding] autorelease];
</ins><span class="cx"> #endif
</span><ins>+ EXPECT_WK_STREQ("hello", copiedString);
+
+#if PLATFORM(MAC)
+ [[NSPasteboard generalPasteboard] setString:copiedString forType:@"public.utf8-plain-text"];
+#elif PLATFORM(IOS)
+ [[UIPasteboard generalPasteboard] setValue:copiedString forPasteboardType:@"public.utf8-plain-text"];
+#endif
+ [webView performSelector:@selector(paste:) withObject:nil];
+
+ TestWebKitAPI::Util::run(&shouldInsertTextCalled);
+
+ __block bool doneEvaluatingJavaScript = false;
+ [webView evaluateJavaScript:@"document.body.firstChild.textContent" completionHandler:^(id _Nullable value, NSError * _Nullable error) {
+ EXPECT_NULL(error);
+ EXPECT_TRUE([value isKindOfClass:[NSString class]]);
+ EXPECT_WK_STREQ("Just something to copy ", (NSString *)value);
+ doneEvaluatingJavaScript = true;
+ }];
+
+ TestWebKitAPI::Util::run(&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<WKWebProcessPlugInBrowserContextController> _browserContextController;
</span><span class="cx"> RetainPtr<WKWebProcessPlugInController> _plugInController;
</span><span class="cx"> RetainPtr<id <BundleEditingDelegateProtocol>> _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:@"EditingDelegateShouldInsertText"]) {
+ 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 <WebKit/WKWebProcessPlugInEditingDelegate.h>
+
</ins><span class="cx"> @protocol BundleEditingDelegateProtocol <NSObject>
</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>