<!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>[169765] trunk/Source</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/169765">169765</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-06-10 14:25:54 -0700 (Tue, 10 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add -[WKWebView evaluateJavaScript:completionHandler:]
https://bugs.webkit.org/show_bug.cgi?id=133689
&lt;rdar://problem/17152685&gt;

Reviewed by Geoffrey Garen.

Source/WebCore:
* English.lproj/Localizable.strings:
Add new localizable strings.

Source/WebKit2:
* Shared/API/c/WKErrorRef.h:
Remove WKErrorCode typedef from here.

* UIProcess/API/C/WKPageLoaderClient.h:
Use uint32_t instead of WKErrorCode.

* UIProcess/API/Cocoa/WKError.h:
(NS_ENUM):
Add a WKErrorDomain and a WKErrorCode enum.

* UIProcess/API/Cocoa/WKError.mm:
(localizedDescriptionForErrorCode):
Helper that returns the localized description given an error code.

(createNSError):
Helper that creates an NSError with the correct localized description given an error code.

* UIProcess/API/Cocoa/WKErrorInternal.h:
Add helpers.

* UIProcess/API/Cocoa/WKWebView.h:
Add evaluateJavaScript:completionHandler: method.

* UIProcess/API/Cocoa/WKWebView.mm:
(callbackErrorCode):
Helper that returns a WKErrorCode from a WebKit::CallbackBase::Error enum.

(-[WKWebView evaluateJavaScript:completionHandler:]):
Run the JavaScript code and handle all the error cases.

(-[WKWebView _runJavaScriptInMainFrame:]):
Reimplement this using the API method.

* WebKit2.xcodeproj/project.pbxproj:
Add new files.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreEnglishlprojLocalizablestrings">trunk/Source/WebCore/English.lproj/Localizable.strings</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedAPIcWKErrorRefh">trunk/Source/WebKit2/Shared/API/c/WKErrorRef.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICWKPageLoaderClienth">trunk/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKErrorh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKErrormm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKErrorInternalh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKErrorInternal.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebCore/ChangeLog        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2014-06-10  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Add -[WKWebView evaluateJavaScript:completionHandler:]
+        https://bugs.webkit.org/show_bug.cgi?id=133689
+        &lt;rdar://problem/17152685&gt;
+
+        Reviewed by Geoffrey Garen.
+
+        * English.lproj/Localizable.strings:
+        Add new localizable strings.
+
</ins><span class="cx"> 2014-06-10  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Serialize ResourceRequests without platform request
</span></span></pre></div>
<a id="trunkSourceWebCoreEnglishlprojLocalizablestrings"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/English.lproj/Localizable.strings (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/English.lproj/Localizable.strings        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebCore/English.lproj/Localizable.strings        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -49,15 +49,15 @@
</span><span class="cx"> /* Visible name of the web process. The argument is the application name. */
</span><span class="cx"> &quot;%@ Web Content&quot; = &quot;%@ Web Content&quot;;
</span><span class="cx"> 
</span><del>-/* Label for PDF page number indicator. The arguments are the current page number and total page count (iOS only) */
-&quot;%d of %d&quot; = &quot;%d of %d&quot;;
-
</del><span class="cx"> /* Name of application's single WebCrypto master key in Keychain */
</span><span class="cx"> &quot;%@ WebCrypto Master Key&quot; = &quot;%@ WebCrypto Master Key&quot;;
</span><span class="cx"> 
</span><span class="cx"> /* Label to describe the number of files selected in a file upload control that allows multiple files */
</span><span class="cx"> &quot;%d files&quot; = &quot;%d files&quot;;
</span><span class="cx"> 
</span><ins>+/* Label for PDF page number indicator. */
+&quot;%d of %d&quot; = &quot;%d of %d&quot;;
+
</ins><span class="cx"> /* Present the number of selected &lt;option&gt; items in a &lt;select multiple&gt; element (iOS only) */
</span><span class="cx"> &quot;%zu Items&quot; = &quot;%zu Items&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -85,6 +85,9 @@
</span><span class="cx"> /* window title for a standalone image (uses multiplication symbol, not x) */
</span><span class="cx"> &quot;&lt;filename&gt; %d×%d pixels&quot; = &quot;&lt;filename&gt; %d×%d pixels&quot;;
</span><span class="cx"> 
</span><ins>+/* WKErrorJavaScriptExceptionOccurred description */
+&quot;A JavaScript exception occurred&quot; = &quot;A JavaScript exception occurred&quot;;
+
</ins><span class="cx"> /* Title for Add to Reading List action button */
</span><span class="cx"> &quot;Add to Reading List&quot; = &quot;Add to Reading List&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -94,6 +97,9 @@
</span><span class="cx"> /* Undo action name */
</span><span class="cx"> &quot;Align Right (Undo action name)&quot; = &quot;Align Right&quot;;
</span><span class="cx"> 
</span><ins>+/* WKErrorUnknown description */
+&quot;An unknown error occurred&quot; = &quot;An unknown error occurred&quot;;
+
</ins><span class="cx"> /* Menu item label for automatic track selection behavior */
</span><span class="cx"> &quot;Auto (Recommended)&quot; = &quot;Auto (Recommended)&quot;;
</span><span class="cx"> 
</span><span class="lines">@@ -565,6 +571,12 @@
</span><span class="cx"> /* WebKitErrorCannotShowURL description */
</span><span class="cx"> &quot;The URL can’t be shown&quot; = &quot;The URL can’t be shown&quot;;
</span><span class="cx"> 
</span><ins>+/* WKErrorWebViewInvalidated description */
+&quot;The WKWebView was invalidated&quot; = &quot;The WKWebView was invalidated&quot;;
+
+/* WKErrorWebContentProcessTerminated description */
+&quot;The Web Content process was terminated&quot; = &quot;The Web Content process was terminated&quot;;
+
</ins><span class="cx"> /* WebKitErrorGeolocationLocationUnknown description */
</span><span class="cx"> &quot;The current location cannot be found.&quot; = &quot;The current location cannot be found.&quot;;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/ChangeLog        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -1,5 +1,49 @@
</span><span class="cx"> 2014-06-10  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Add -[WKWebView evaluateJavaScript:completionHandler:]
+        https://bugs.webkit.org/show_bug.cgi?id=133689
+        &lt;rdar://problem/17152685&gt;
+
+        Reviewed by Geoffrey Garen.
+
+        * Shared/API/c/WKErrorRef.h:
+        Remove WKErrorCode typedef from here.
+
+        * UIProcess/API/C/WKPageLoaderClient.h:
+        Use uint32_t instead of WKErrorCode.
+
+        * UIProcess/API/Cocoa/WKError.h:
+        (NS_ENUM):
+        Add a WKErrorDomain and a WKErrorCode enum.
+
+        * UIProcess/API/Cocoa/WKError.mm:
+        (localizedDescriptionForErrorCode):
+        Helper that returns the localized description given an error code.
+
+        (createNSError):
+        Helper that creates an NSError with the correct localized description given an error code.
+
+        * UIProcess/API/Cocoa/WKErrorInternal.h:
+        Add helpers.
+
+        * UIProcess/API/Cocoa/WKWebView.h:
+        Add evaluateJavaScript:completionHandler: method.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (callbackErrorCode):
+        Helper that returns a WKErrorCode from a WebKit::CallbackBase::Error enum.
+
+        (-[WKWebView evaluateJavaScript:completionHandler:]):
+        Run the JavaScript code and handle all the error cases.
+
+        (-[WKWebView _runJavaScriptInMainFrame:]):
+        Reimplement this using the API method.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Add new files.
+
+2014-06-10  Anders Carlsson  &lt;andersca@apple.com&gt;
+
</ins><span class="cx">         Don't call Connection::terminateSoon if the connection is null
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=133695
</span><span class="cx">         &lt;rdar://problem/17069024&gt;
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedAPIcWKErrorRefh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/API/c/WKErrorRef.h (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/API/c/WKErrorRef.h        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/Shared/API/c/WKErrorRef.h        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -45,7 +45,6 @@
</span><span class="cx">     kWKErrorCodeInsecurePlugInVersion =                          205,
</span><span class="cx">     kWKErrorInternal =                                           300,
</span><span class="cx"> };
</span><del>-typedef uint32_t WKErrorCode;
</del><span class="cx"> 
</span><span class="cx"> WK_EXPORT WKTypeID WKErrorGetTypeID();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICWKPageLoaderClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -73,12 +73,12 @@
</span><span class="cx"> typedef void (*WKPageWillGoToBackForwardListItemCallback)(WKPageRef page, WKBackForwardListItemRef item, WKTypeRef userData, const void *clientInfo);
</span><span class="cx"> typedef void (*WKPageDidLayoutCallback)(WKPageRef page, WKLayoutMilestones milestones, WKTypeRef userData, const void *clientInfo);
</span><span class="cx"> typedef WKPluginLoadPolicy (*WKPagePluginLoadPolicyCallback)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, WKStringRef* unavailabilityDescription, const void* clientInfo);
</span><del>-typedef void (*WKPagePluginDidFailCallback)(WKPageRef page, WKErrorCode errorCode, WKDictionaryRef pluginInfoDictionary, const void* clientInfo);
</del><ins>+typedef void (*WKPagePluginDidFailCallback)(WKPageRef page, uint32_t errorCode, WKDictionaryRef pluginInfoDictionary, const void* clientInfo);
</ins><span class="cx"> typedef WKWebGLLoadPolicy (*WKPageWebGLLoadPolicyCallback)(WKPageRef page, WKStringRef url, const void* clientInfo);
</span><span class="cx"> 
</span><span class="cx"> // Deprecated
</span><span class="cx"> typedef void (*WKPageDidFailToInitializePluginCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef mimeType, const void* clientInfo);
</span><del>-typedef void (*WKPagePluginDidFailCallback_deprecatedForUseWithV1)(WKPageRef page, WKErrorCode errorCode, WKStringRef mimeType, WKStringRef pluginIdentifier, WKStringRef pluginVersion, const void* clientInfo);
</del><ins>+typedef void (*WKPagePluginDidFailCallback_deprecatedForUseWithV1)(WKPageRef page, uint32_t errorCode, WKStringRef mimeType, WKStringRef pluginIdentifier, WKStringRef pluginVersion, const void* clientInfo);
</ins><span class="cx"> typedef WKPluginLoadPolicy (*WKPagePluginLoadPolicyCallback_deprecatedForUseWithV2)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, const void* clientInfo);
</span><span class="cx"> 
</span><span class="cx"> typedef struct WKPageLoaderClientBase {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKErrorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.h (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.h        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.h        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -29,6 +29,21 @@
</span><span class="cx"> 
</span><span class="cx"> #import &lt;Foundation/Foundation.h&gt;
</span><span class="cx"> 
</span><ins>+/*! @constant WKErrorDomain Indicates a WebKit error. */
</ins><span class="cx"> WK_EXTERN NSString * const WKErrorDomain WK_AVAILABLE(10_0, 8_0);
</span><span class="cx"> 
</span><ins>+/*! @enum WKErrorCode
+ @abstract Constants used by NSError to indicate errors in the WebKit domain.
+ @constant WKErrorUnknown                       Indicates that an unknown error occurred.
+ @constant WKErrorWebContentProcessTerminated   Indicates that the Web Content process was terminated.
+ @constant WKErrorWebViewInvalidated            Indicates that the WKWebView was invalidated.
+ @constant WKErrorJavaScriptExceptionOccurred   Indicates that a JavaScript exception occurred.
+ */
+typedef NS_ENUM(NSInteger, WKErrorCode) {
+    WKErrorUnknown = 1,
+    WKErrorWebContentProcessTerminated,
+    WKErrorWebViewInvalidated,
+    WKErrorJavaScriptExceptionOccurred,
+} WK_ENUM_AVAILABLE(10_10, 8_0);
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKErrormm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -24,10 +24,38 @@
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #import &quot;config.h&quot;
</span><del>-#import &quot;WKError.h&quot;
</del><ins>+#import &quot;WKErrorInternal.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx"> 
</span><ins>+#import &lt;WebCore/LocalizedStrings.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
+#import &lt;wtf/text/WTFString.h&gt;
+
</ins><span class="cx"> NSString * const WKErrorDomain = @&quot;WKErrorDomain&quot;;
</span><span class="cx"> 
</span><ins>+static NSString *localizedDescriptionForErrorCode(WKErrorCode errorCode)
+{
+    switch (errorCode) {
+    case WKErrorUnknown:
+        return WEB_UI_STRING(&quot;An unknown error occurred&quot;, &quot;WKErrorUnknown description&quot;);
+
+    case WKErrorWebContentProcessTerminated:
+        return WEB_UI_STRING(&quot;The Web Content process was terminated&quot;, &quot;WKErrorWebContentProcessTerminated description&quot;);
+
+    case WKErrorWebViewInvalidated:
+        return WEB_UI_STRING(&quot;The WKWebView was invalidated&quot;, &quot;WKErrorWebViewInvalidated description&quot;);
+
+    case WKErrorJavaScriptExceptionOccurred:
+        return WEB_UI_STRING(&quot;A JavaScript exception occurred&quot;, &quot;WKErrorJavaScriptExceptionOccurred description&quot;);
+    }
+}
+
+RetainPtr&lt;NSError&gt; createNSError(WKErrorCode errorCode)
+{
+    auto userInfo = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:localizedDescriptionForErrorCode(errorCode), NSLocalizedDescriptionKey, nil]);
+
+    return adoptNS([[NSError alloc] initWithDomain:WKErrorDomain code:errorCode userInfo:userInfo.get()]);
+}
+
</ins><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKErrorInternalhfromrev169763trunkSourceWebKit2UIProcessAPICocoaWKErrormm"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKErrorInternal.h (from rev 169763, trunk/Source/WebKit2/UIProcess/API/Cocoa/WKError.mm) (0 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKErrorInternal.h                                (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKErrorInternal.h        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -0,0 +1,35 @@
</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 &quot;WKError.h&quot;
+
+#if WK_API_ENABLED
+
+#import &lt;wtf/RetainPtr.h&gt;
+#import &quot;GenericCallback.h&quot;
+
+RetainPtr&lt;NSError&gt; createNSError(WKErrorCode);
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -183,6 +183,13 @@
</span><span class="cx">  */
</span><span class="cx"> - (void)stopLoading;
</span><span class="cx"> 
</span><ins>+/* @abstract Evaluates the given JavaScript string.
+ @param javaScriptString The JavaScript string to evaluate.
+ @param completionHandler A block to invoke when script evaluation completes or fails.
+ @discussion The completionHandler is passed the result of the script evaluation or an error.
+*/
+- (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler;
+
</ins><span class="cx"> /*! @abstract A Boolean value indicating whether horizontal swipe gestures
</span><span class="cx">  will trigger back-forward list navigations.
</span><span class="cx">  @discussion The default value is NO.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> #import &quot;WKBackForwardListInternal.h&quot;
</span><span class="cx"> #import &quot;WKBackForwardListItemInternal.h&quot;
</span><span class="cx"> #import &quot;WKBrowsingContextHandleInternal.h&quot;
</span><ins>+#import &quot;WKErrorInternal.h&quot;
</ins><span class="cx"> #import &quot;WKHistoryDelegatePrivate.h&quot;
</span><span class="cx"> #import &quot;WKNSData.h&quot;
</span><span class="cx"> #import &quot;WKNSURLExtras.h&quot;
</span><span class="lines">@@ -60,11 +61,14 @@
</span><span class="cx"> #import &quot;WebPageGroup.h&quot;
</span><span class="cx"> #import &quot;WebPageProxy.h&quot;
</span><span class="cx"> #import &quot;WebProcessProxy.h&quot;
</span><ins>+#import &quot;WebSerializedScriptValue.h&quot;
</ins><span class="cx"> #import &quot;_WKFindDelegate.h&quot;
</span><span class="cx"> #import &quot;_WKFormDelegate.h&quot;
</span><span class="cx"> #import &quot;_WKRemoteObjectRegistryInternal.h&quot;
</span><span class="cx"> #import &quot;_WKVisitedLinkProviderInternal.h&quot;
</span><span class="cx"> #import &quot;_WKWebsiteDataStoreInternal.h&quot;
</span><ins>+#import &lt;JavaScriptCore/JSContext.h&gt;
+#import &lt;JavaScriptCore/JSValue.h&gt;
</ins><span class="cx"> #import &lt;wtf/HashMap.h&gt;
</span><span class="cx"> #import &lt;wtf/NeverDestroyed.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="lines">@@ -459,6 +463,64 @@
</span><span class="cx">     _page-&gt;stopLoading();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static WKErrorCode callbackErrorCode(WebKit::CallbackBase::Error error)
+{
+    switch (error) {
+    case WebKit::CallbackBase::Error::None:
+        ASSERT_NOT_REACHED();
+        return WKErrorUnknown;
+
+    case WebKit::CallbackBase::Error::Unknown:
+        return WKErrorUnknown;
+
+    case WebKit::CallbackBase::Error::ProcessExited:
+        return WKErrorWebContentProcessTerminated;
+
+    case WebKit::CallbackBase::Error::OwnerWasInvalidated:
+        return WKErrorWebViewInvalidated;
+    }
+}
+
+- (void)evaluateJavaScript:(NSString *)javaScriptString completionHandler:(void (^)(id, NSError *))completionHandler
+{
+    auto handler = adoptNS([completionHandler copy]);
+
+    _page-&gt;runJavaScriptInMainFrame(javaScriptString, WebKit::ScriptValueCallback::create([handler](WebKit::WebSerializedScriptValue* serializedScriptValue, WebKit::ScriptValueCallback::Error errorCode) {
+        if (!handler)
+            return;
+
+        auto completionHandler = (void (^)(id, NSError *))handler.get();
+
+        if (errorCode != WebKit::ScriptValueCallback::Error::None) {
+            auto error = createNSError(callbackErrorCode(errorCode));
+            if (errorCode == WebKit::ScriptValueCallback::Error::OwnerWasInvalidated) {
+                // We don't want to call the block from within the call that invalidates the web view,
+                // since that can lead to client code re-entrency bugs (Since calling -[WKWebView _close]
+                // invalidates the callback.
+                // FIXME: It would be even better if GenericCallback did this for us.
+                dispatch_async(dispatch_get_main_queue(), [completionHandler, error] {
+                    completionHandler(nil, error.get());
+                });
+                return;
+            }
+
+            completionHandler(nil, error.get());
+            return;
+        }
+
+        if (!serializedScriptValue) {
+            completionHandler(nil, createNSError(WKErrorJavaScriptExceptionOccurred).get());
+            return;
+        }
+
+        auto context = adoptNS([[JSContext alloc] init]);
+        JSValueRef valueRef = serializedScriptValue-&gt;deserialize([context JSGlobalContextRef], 0);
+        JSValue *value = [JSValue valueWithJSValueRef:valueRef inContext:context.get()];
+
+        completionHandler([value toObject], nil);
+    }));
+}
+
</ins><span class="cx"> #pragma mark iOS-specific methods
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="lines">@@ -1435,7 +1497,7 @@
</span><span class="cx"> 
</span><span class="cx"> - (void)_runJavaScriptInMainFrame:(NSString *)scriptString
</span><span class="cx"> {
</span><del>-    _page-&gt;runJavaScriptInMainFrame(scriptString, WebKit::ScriptValueCallback::create([](bool, WebKit::WebSerializedScriptValue*){}));
</del><ins>+    [self evaluateJavaScript:scriptString completionHandler:^(id, NSError *) { }];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)_getWebArchiveDataWithCompletionHandler:(void (^)(NSData *, NSError *))completionHandler
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (169764 => 169765)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-06-10 21:20:19 UTC (rev 169764)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-06-10 21:25:54 UTC (rev 169765)
</span><span class="lines">@@ -171,6 +171,7 @@
</span><span class="cx">                 1A2A4B0E1586A2240090C9E9 /* ColorSpaceData.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A2A4AFD158693920090C9E9 /* ColorSpaceData.mm */; };
</span><span class="cx">                 1A2BB6D014117B4D000F35D4 /* PluginProcessConnectionMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2BB6CE14117B4D000F35D4 /* PluginProcessConnectionMessageReceiver.cpp */; };
</span><span class="cx">                 1A2BB6D114117B4D000F35D4 /* PluginProcessConnectionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2BB6CF14117B4D000F35D4 /* PluginProcessConnectionMessages.h */; };
</span><ins>+                1A2D252B194688FD004537B0 /* WKErrorInternal.h in Copy Files */ = {isa = PBXBuildFile; fileRef = 1A2D252A194688FD004537B0 /* WKErrorInternal.h */; };
</ins><span class="cx">                 1A2D82A4127F4EAB001EB962 /* NPObjectMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1FA35C127A45BF0050E709 /* NPObjectMessageReceiver.cpp */; };
</span><span class="cx">                 1A2D82A5127F4EAB001EB962 /* NPObjectMessageReceiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1FA35B127A45BF0050E709 /* NPObjectMessageReceiver.h */; };
</span><span class="cx">                 1A2D82A6127F4EAB001EB962 /* NPObjectProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A1FA284127A13BC0050E709 /* NPObjectProxy.cpp */; };
</span><span class="lines">@@ -1889,6 +1890,7 @@
</span><span class="cx">                         dstPath = WebKit.framework;
</span><span class="cx">                         dstSubfolderSpec = 1;
</span><span class="cx">                         files = (
</span><ins>+                                1A2D252B194688FD004537B0 /* WKErrorInternal.h in Copy Files */,
</ins><span class="cx">                                 510CC8491613C85C00D03ED3 /* NetworkProcess.app in Copy Files */,
</span><span class="cx">                                 BCDE0ABF13272708001259FB /* PluginProcess.app in Copy Files */,
</span><span class="cx">                                 51A60B2A180CCEB500F3BF50 /* DatabaseProcess.app in Copy Files */,
</span><span class="lines">@@ -2097,6 +2099,7 @@
</span><span class="cx">                 1A2BB6CC14117A5F000F35D4 /* PluginProcessConnection.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = PluginProcessConnection.messages.in; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A2BB6CE14117B4D000F35D4 /* PluginProcessConnectionMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginProcessConnectionMessageReceiver.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A2BB6CF14117B4D000F35D4 /* PluginProcessConnectionMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PluginProcessConnectionMessages.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                1A2D252A194688FD004537B0 /* WKErrorInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKErrorInternal.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 1A2D8411127F64E8001EB962 /* NPObjectMessageReceiver.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NPObjectMessageReceiver.messages.in; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A2D8437127F65D5001EB962 /* NPObjectMessageReceiverMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NPObjectMessageReceiverMessageReceiver.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A2D8438127F65D5001EB962 /* NPObjectMessageReceiverMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NPObjectMessageReceiverMessages.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -4959,6 +4962,7 @@
</span><span class="cx">                                 37C4C08818149F23003688B9 /* WKBackForwardListItemInternal.h */,
</span><span class="cx">                                 1A79D9F118EB5EF100914CC5 /* WKBackForwardListPrivate.h */,
</span><span class="cx">                                 1AF4592D19464B2000F9D4A2 /* WKError.h */,
</span><ins>+                                1A2D252A194688FD004537B0 /* WKErrorInternal.h */,
</ins><span class="cx">                                 1AF4592C19464B2000F9D4A2 /* WKError.mm */,
</span><span class="cx">                                 1A4D664A18A3030E00D82E21 /* WKFrameInfo.h */,
</span><span class="cx">                                 1A4D664918A3030E00D82E21 /* WKFrameInfo.mm */,
</span></span></pre>
</div>
</div>

</body>
</html>