<!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>[171461] branches/safari-600.1-branch</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/171461">171461</a></dd>
<dt>Author</dt> <dd>lforschler@apple.com</dd>
<dt>Date</dt> <dd>2014-07-23 01:20:39 -0700 (Wed, 23 Jul 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/171355">r171355</a>. <rdar://problem/17735912></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6001branchSourceJavaScriptCoreChangeLog">branches/safari-600.1-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari6001branchSourceJavaScriptCoreruntimeCommonIdentifiersh">branches/safari-600.1-branch/Source/JavaScriptCore/runtime/CommonIdentifiers.h</a></li>
<li><a href="#branchessafari6001branchSourceWebCoreChangeLog">branches/safari-600.1-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari6001branchSourceWebCorebindingsjsJSDOMWindowBasecpp">branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowBase.cpp</a></li>
<li><a href="#branchessafari6001branchSourceWebCorebindingsjsJSDOMWindowCustomcpp">branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp</a></li>
<li><a href="#branchessafari6001branchToolsChangeLog">branches/safari-600.1-branch/Tools/ChangeLog</a></li>
<li><a href="#branchessafari6001branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">branches/safari-600.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari6001branchToolsTestWebKitAPITestsWebKit2CocoaUserContentControllermm">branches/safari-600.1-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6001branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/JavaScriptCore/ChangeLog (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/JavaScriptCore/ChangeLog        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Source/JavaScriptCore/ChangeLog        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -1,5 +1,19 @@
</span><span class="cx"> 2014-07-23 Lucas Forschler <lforschler@apple.com>
</span><span class="cx">
</span><ins>+ Merge r171355
+
+ 2014-07-21 Sam Weinig <sam@webkit.org>
+
+ [Cocoa] WKScriptMessageHandlers don't seem to function properly after navigating
+ https://bugs.webkit.org/show_bug.cgi?id=135148
+
+ Reviewed by Geoffrey Garen.
+
+ * runtime/CommonIdentifiers.h:
+ Add a common identifier for the string "webkit".
+
+2014-07-23 Lucas Forschler <lforschler@apple.com>
+
</ins><span class="cx"> Merge r171354
</span><span class="cx">
</span><span class="cx"> 2014-07-22 Filip Pizlo <fpizlo@apple.com>
</span></span></pre></div>
<a id="branchessafari6001branchSourceJavaScriptCoreruntimeCommonIdentifiersh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/JavaScriptCore/runtime/CommonIdentifiers.h (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/JavaScriptCore/runtime/CommonIdentifiers.h        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Source/JavaScriptCore/runtime/CommonIdentifiers.h        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -166,6 +166,7 @@
</span><span class="cx"> macro(value) \
</span><span class="cx"> macro(valueOf) \
</span><span class="cx"> macro(values) \
</span><ins>+ macro(webkit) \
</ins><span class="cx"> macro(window) \
</span><span class="cx"> macro(writable)
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/ChangeLog (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/ChangeLog        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Source/WebCore/ChangeLog        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -1,5 +1,32 @@
</span><span class="cx"> 2014-07-23 Lucas Forschler <lforschler@apple.com>
</span><span class="cx">
</span><ins>+ Merge r171355
+
+ 2014-07-21 Sam Weinig <sam@webkit.org>
+
+ [Cocoa] WKScriptMessageHandlers don't seem to function properly after navigating
+ https://bugs.webkit.org/show_bug.cgi?id=135148
+
+ Reviewed by Geoffrey Garen.
+
+ The "webkit" property on the window was not getting installed for subsequent
+ loads due to intricate dance playing setting the JSDOMWindow where the DOMWindow
+ object is not yet in a Frame when the JSDOMWindow is created. Since we were
+ adding the "webkit" property on construction, the property was returning null
+ thinking it had no Frame and was in a bad state. We can fix this by making the
+ "webkit" property behave like all the other window properties moving its getting
+ to JSDOMWindow::getOwnPropertySlot.
+
+ Added API test (WebKit2Cocoa/UserContentController).
+
+ * bindings/js/JSDOMWindowBase.cpp:
+ (WebCore::JSDOMWindowBase::finishCreation):
+ * bindings/js/JSDOMWindowCustom.cpp:
+ (WebCore::jsDOMWindowWebKit):
+ (WebCore::JSDOMWindow::getOwnPropertySlot):
+
+2014-07-23 Lucas Forschler <lforschler@apple.com>
+
</ins><span class="cx"> Merge r171353
</span><span class="cx">
</span><span class="cx"> 2014-07-22 Brent Fulgham <bfulgham@apple.com>
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebCorebindingsjsJSDOMWindowBasecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowBase.cpp (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowBase.cpp        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowBase.cpp        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -39,10 +39,6 @@
</span><span class="cx"> #include <runtime/Microtask.h>
</span><span class="cx"> #include <wtf/MainThread.h>
</span><span class="cx">
</span><del>-#if ENABLE(USER_MESSAGE_HANDLERS)
-#include "JSWebKitNamespace.h"
-#endif
-
</del><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> #include "ChromeClient.h"
</span><span class="cx"> #include "WebSafeGCActivityCallbackIOS.h"
</span><span class="lines">@@ -81,11 +77,6 @@
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> addStaticGlobals(staticGlobals, WTF_ARRAY_LENGTH(staticGlobals));
</span><del>-
-#if ENABLE(USER_MESSAGE_HANDLERS)
- if (m_impl->shouldHaveWebKitNamespaceForWorld(world()))
- putDirect(vm, Identifier(&vm, "webkit"), toJS(globalExec(), this, m_impl->webkitNamespace()), DontDelete | ReadOnly);
-#endif
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void JSDOMWindowBase::destroy(JSCell* cell)
</span></span></pre></div>
<a id="branchessafari6001branchSourceWebCorebindingsjsJSDOMWindowCustomcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Source/WebCore/bindings/js/JSDOMWindowCustom.cpp        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -54,6 +54,10 @@
</span><span class="cx"> #include "JSWebSocket.h"
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(USER_MESSAGE_HANDLERS)
+#include "JSWebKitNamespace.h"
+#endif
+
</ins><span class="cx"> using namespace JSC;
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -91,6 +95,16 @@
</span><span class="cx"> return JSValue::encode(toJS(exec, thisObj->globalObject(), toHTMLDocument(document)->windowNamedItem(*atomicPropertyName)));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(USER_MESSAGE_HANDLERS)
+static EncodedJSValue jsDOMWindowWebKit(ExecState* exec, JSObject*, EncodedJSValue thisValue, PropertyName)
+{
+ JSDOMWindow* castedThis = toJSDOMWindow(JSValue::decode(thisValue));
+ if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))
+ return JSValue::encode(jsUndefined());
+ return JSValue::encode(toJS(exec, castedThis->globalObject(), castedThis->impl().webkitNamespace()));
+}
+#endif
+
</ins><span class="cx"> bool JSDOMWindow::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
</span><span class="cx"> {
</span><span class="cx"> JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object);
</span><span class="lines">@@ -174,6 +188,13 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(USER_MESSAGE_HANDLERS)
+ if (propertyName == exec->propertyNames().webkit && thisObject->impl().shouldHaveWebKitNamespaceForWorld(thisObject->world())) {
+ slot.setCacheableCustom(thisObject, allowsAccess ? DontDelete | ReadOnly : ReadOnly | DontDelete | DontEnum, jsDOMWindowWebKit);
+ return true;
+ }
+#endif
+
</ins><span class="cx"> // Do prototype lookup early so that functions and attributes in the prototype can have
</span><span class="cx"> // precedence over the index and name getters.
</span><span class="cx"> JSValue proto = thisObject->prototype();
</span></span></pre></div>
<a id="branchessafari6001branchToolsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Tools/ChangeLog (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Tools/ChangeLog        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Tools/ChangeLog        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2014-07-23 Lucas Forschler <lforschler@apple.com>
+
+ Merge r171355
+
+ 2014-07-21 Sam Weinig <sam@webkit.org>
+
+ [Cocoa] WKScriptMessageHandlers don't seem to function properly after navigating
+ https://bugs.webkit.org/show_bug.cgi?id=135148
+
+ Reviewed by Geoffrey Garen.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm: Added.
+ (-[SimpleNavigationDelegate webView:didFinishNavigation:]):
+ (-[ScriptMessageHandler userContentController:didReceiveScriptMessage:]):
+
</ins><span class="cx"> 2014-07-22 Dana Burkart <dburkart@apple.com>
</span><span class="cx">
</span><span class="cx"> Merge r171284.
</span></span></pre></div>
<a id="branchessafari6001branchToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/safari-600.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (171460 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2014-07-23 08:10:05 UTC (rev 171460)
+++ branches/safari-600.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -122,6 +122,7 @@
</span><span class="cx">                 7C74D42F188228F300E5ED57 /* StringView.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C74D42D188228F300E5ED57 /* StringView.cpp */; };
</span><span class="cx">                 7C8DDAAB1735DEEE00EA5AC0 /* CloseThenTerminate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C8DDAA91735DE1D00EA5AC0 /* CloseThenTerminate.cpp */; };
</span><span class="cx">                 7C9ED98B17A19F4B00E4DC33 /* attributedStringStrikethrough.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7C9ED98A17A19D0600E4DC33 /* attributedStringStrikethrough.html */; };
</span><ins>+                7CC3E1FC197E234100BE6252 /* UserContentController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7CC3E1FA197E234100BE6252 /* UserContentController.mm */; };
</ins><span class="cx">                 7CFBCADF1743234F00B2BFCF /* WillLoad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */; };
</span><span class="cx">                 7CFBCAE51743238F00B2BFCF /* WillLoad_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */; };
</span><span class="cx">                 81B50193140F232300D9EB58 /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 81B50192140F232300D9EB58 /* StringBuilder.cpp */; };
</span><span class="lines">@@ -462,6 +463,7 @@
</span><span class="cx">                 7C74D42D188228F300E5ED57 /* StringView.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringView.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7C8DDAA91735DE1D00EA5AC0 /* CloseThenTerminate.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CloseThenTerminate.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7C9ED98A17A19D0600E4DC33 /* attributedStringStrikethrough.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = attributedStringStrikethrough.html; sourceTree = "<group>"; };
</span><ins>+                7CC3E1FA197E234100BE6252 /* UserContentController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UserContentController.mm; sourceTree = "<group>"; };
</ins><span class="cx">                 7CFBCADD1743234F00B2BFCF /* WillLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7CFBCAE31743238E00B2BFCF /* WillLoad_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillLoad_Bundle.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 81B50192140F232300D9EB58 /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StringBuilder.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -702,6 +704,7 @@
</span><span class="cx">                         children = (
</span><span class="cx">                                 A1A4FE5D18DD3DB700B5EA8A /* Download.mm */,
</span><span class="cx">                                 1ABC3DED1899BE6D004F0626 /* Navigation.mm */,
</span><ins>+                                7CC3E1FA197E234100BE6252 /* UserContentController.mm */,
</ins><span class="cx">                         );
</span><span class="cx">                         name = "WebKit2 Cocoa";
</span><span class="cx">                         path = WebKit2Cocoa;
</span><span class="lines">@@ -1245,6 +1248,7 @@
</span><span class="cx">                                 290F427B172A23A500939FF0 /* TestProtocol.mm in Sources */,
</span><span class="cx">                                 1AA9E55914980A9900001A8A /* Functional.cpp in Sources */,
</span><span class="cx">                                 C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */,
</span><ins>+                                7CC3E1FC197E234100BE6252 /* UserContentController.mm in Sources */,
</ins><span class="cx">                                 F660AA0D15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp in Sources */,
</span><span class="cx">                                 0BCD833514857CE400EA2003 /* HashMap.cpp in Sources */,
</span><span class="cx">                                 2DD7D3AA178205D00026E1E3 /* ResizeReversePaginatedWebView.cpp in Sources */,
</span></span></pre></div>
<a id="branchessafari6001branchToolsTestWebKitAPITestsWebKit2CocoaUserContentControllermmfromrev171355trunkToolsTestWebKitAPITestsWebKit2CocoaUserContentControllermm"></a>
<div class="copfile"><h4>Copied: branches/safari-600.1-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm (from rev 171355, trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm) (0 => 171461)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.1-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm         (rev 0)
+++ branches/safari-600.1-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm        2014-07-23 08:20:39 UTC (rev 171461)
</span><span class="lines">@@ -0,0 +1,129 @@
</span><ins>+/*
+ * 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 "config.h"
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+
+static bool isDoneWithNavigation;
+
+@interface SimpleNavigationDelegate : NSObject <WKNavigationDelegate>
+@end
+
+@implementation SimpleNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+ isDoneWithNavigation = true;
+}
+
+@end
+
+static bool receivedScriptMessage;
+static RetainPtr<WKScriptMessage> lastScriptMessage;
+
+@interface ScriptMessageHandler : NSObject <WKScriptMessageHandler>
+@end
+
+@implementation ScriptMessageHandler
+
+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
+{
+ receivedScriptMessage = true;
+ lastScriptMessage = message;
+}
+
+@end
+
+TEST(WKUserContentController, ScriptMessageHandlerSimple)
+{
+ RetainPtr<ScriptMessageHandler> handler = adoptNS([[ScriptMessageHandler alloc] init]);
+ RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+ [webView loadRequest:request];
+
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+
+ [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Hello')" completionHandler:nil];
+
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+ receivedScriptMessage = false;
+
+ EXPECT_WK_STREQ(@"Hello", (NSString *)[lastScriptMessage body]);
+}
+
+TEST(WKUserContentController, ScriptMessageHandlerWithNavigation)
+{
+ RetainPtr<ScriptMessageHandler> handler = adoptNS([[ScriptMessageHandler alloc] init]);
+ RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [[configuration userContentController] addScriptMessageHandler:handler.get() name:@"testHandler"];
+
+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+ [webView loadRequest:request];
+
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+ isDoneWithNavigation = false;
+
+ [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('First Message')" completionHandler:nil];
+
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+
+ EXPECT_WK_STREQ(@"First Message", (NSString *)[lastScriptMessage body]);
+
+ receivedScriptMessage = false;
+ lastScriptMessage = nullptr;
+
+
+ [webView loadRequest:request];
+ TestWebKitAPI::Util::run(&isDoneWithNavigation);
+ isDoneWithNavigation = false;
+
+ [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Second Message')" completionHandler:nil];
+
+ TestWebKitAPI::Util::run(&receivedScriptMessage);
+
+ EXPECT_WK_STREQ(@"Second Message", (NSString *)[lastScriptMessage body]);
+}
+
+#endif
</ins></span></pre>
</div>
</div>
</body>
</html>