<!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>[243012] 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/243012">243012</a></dd>
<dt>Author</dt> <dd>timothy@apple.com</dd>
<dt>Date</dt> <dd>2019-03-15 14:36:56 -0700 (Fri, 15 Mar 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add support to WebPage for getting the contents as an attributed string.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Tim Horton.

Source/WebKit:

* Shared/mac/AttributedString.h:
(WebKit::AttributedString::AttributedString):
* Shared/mac/AttributedString.mm:
(IPC::ArgumentCoder<WebKit::AttributedString>::encode):
(IPC::ArgumentCoder<WebKit::AttributedString>::decode):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _getContentsAsAttributedStringWithCompletionHandler:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::getContentsAsAttributedString):
* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::getContentsAsAttributedString):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm:
(TEST(WKWebView, GetContentsShouldReturnAttributedString): Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedmacAttributedStringh">trunk/Source/WebKit/Shared/mac/AttributedString.h</a></li>
<li><a href="#trunkSourceWebKitSharedmacAttributedStringmm">trunk/Source/WebKit/Shared/mac/AttributedString.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxycpp">trunk/Source/WebKit/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxyh">trunk/Source/WebKit/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageCocoaWebPageCocoamm">trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPagemessagesin">trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKitCocoaWKWebViewGetContentsmm">trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/ChangeLog       2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2019-03-15  Timothy Hatcher  <timothy@apple.com>
+
+        Add support to WebPage for getting the contents as an attributed string.
+        https://bugs.webkit.org/show_bug.cgi?id=195636
+        rdar://problem/45055697
+
+        Reviewed by Tim Horton.
+
+        * Shared/mac/AttributedString.h:
+        (WebKit::AttributedString::AttributedString):
+        * Shared/mac/AttributedString.mm:
+        (IPC::ArgumentCoder<WebKit::AttributedString>::encode):
+        (IPC::ArgumentCoder<WebKit::AttributedString>::decode):
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _getContentsAsAttributedStringWithCompletionHandler:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::getContentsAsAttributedString):
+        * UIProcess/WebPageProxy.h:
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::getContentsAsAttributedString):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
</ins><span class="cx"> 2019-03-15  Per Arne Vollan  <pvollan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS] Fix sandbox violation
</span></span></pre></div>
<a id="trunkSourceWebKitSharedmacAttributedStringh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/mac/AttributedString.h (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/mac/AttributedString.h        2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/Shared/mac/AttributedString.h   2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -38,8 +38,9 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> #if defined(__OBJC__)
</span><del>-    AttributedString(NSAttributedString *attributedString)
</del><ins>+    AttributedString(NSAttributedString *attributedString, NSDictionary *documentAttributes = nil)
</ins><span class="cx">         : string(attributedString)
</span><ins>+        , documentAttributes(documentAttributes)
</ins><span class="cx">     {
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -48,8 +49,9 @@
</span><span class="cx">         return string.get();
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><del>-    
</del><ins>+
</ins><span class="cx">     RetainPtr<NSAttributedString> string;
</span><ins>+    RetainPtr<NSDictionary> documentAttributes;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitSharedmacAttributedStringmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/mac/AttributedString.mm (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/mac/AttributedString.mm       2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/Shared/mac/AttributedString.mm  2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -34,7 +34,7 @@
</span><span class="cx"> 
</span><span class="cx"> void ArgumentCoder<WebKit::AttributedString>::encode(Encoder& encoder, const WebKit::AttributedString& attributedString)
</span><span class="cx"> {
</span><del>-    encoder << attributedString.string;
</del><ins>+    encoder << attributedString.string << attributedString.documentAttributes;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Optional<WebKit::AttributedString> ArgumentCoder<WebKit::AttributedString>::decode(Decoder& decoder)
</span><span class="lines">@@ -42,7 +42,10 @@
</span><span class="cx">     RetainPtr<NSAttributedString> attributedString;
</span><span class="cx">     if (!IPC::decode(decoder, attributedString))
</span><span class="cx">         return WTF::nullopt;
</span><del>-    return WebKit::AttributedString { attributedString.get() };
</del><ins>+    RetainPtr<NSDictionary> documentAttributes;
+    if (!IPC::decode(decoder, documentAttributes))
+        return WTF::nullopt;
+    return WebKit::AttributedString { attributedString.get(), documentAttributes.get() };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm     2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm        2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #import "APIFormClient.h"
</span><span class="cx"> #import "APIPageConfiguration.h"
</span><span class="cx"> #import "APISerializedScriptValue.h"
</span><ins>+#import "AttributedString.h"
</ins><span class="cx"> #import "CompletionHandlerCallChecker.h"
</span><span class="cx"> #import "DiagnosticLoggingClient.h"
</span><span class="cx"> #import "DynamicViewportSizeUpdate.h"
</span><span class="lines">@@ -5253,6 +5254,16 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_getContentsAsAttributedStringWithCompletionHandler:(void (^)(NSAttributedString *, NSDictionary<NSAttributedStringDocumentAttributeKey, id> *, NSError *))completionHandler
+{
+    _page->getContentsAsAttributedString([handler = makeBlockPtr(completionHandler)](auto& attributedString) {
+        if (attributedString.string)
+            handler([[attributedString.string.get() retain] autorelease], [[attributedString.documentAttributes.get() retain] autorelease], nil);
+        else
+            handler(nil, nil, createNSError(WKErrorUnknown).get());
+    });
+}
+
</ins><span class="cx"> - (void)_getApplicationManifestWithCompletionHandler:(void (^)(_WKApplicationManifest *))completionHandler
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(APPLICATION_MANIFEST)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h       2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h  2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -364,6 +364,7 @@
</span><span class="cx"> - (void)_getMainResourceDataWithCompletionHandler:(void (^)(NSData *, NSError *))completionHandler;
</span><span class="cx"> - (void)_getWebArchiveDataWithCompletionHandler:(void (^)(NSData *, NSError *))completionHandler;
</span><span class="cx"> - (void)_getContentsAsStringWithCompletionHandler:(void (^)(NSString *, NSError *))completionHandler WK_API_AVAILABLE(macosx(10.13), ios(11.0));
</span><ins>+- (void)_getContentsAsAttributedStringWithCompletionHandler:(void (^)(NSAttributedString *, NSDictionary<NSAttributedStringDocumentAttributeKey, id> *, NSError *))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_MAC_TBA));
</ins><span class="cx"> 
</span><span class="cx"> - (void)_getApplicationManifestWithCompletionHandler:(void (^)(_WKApplicationManifest *))completionHandler WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp   2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp      2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -52,6 +52,7 @@
</span><span class="cx"> #include "APIUIClient.h"
</span><span class="cx"> #include "APIURLRequest.h"
</span><span class="cx"> #include "APIWebsitePolicies.h"
</span><ins>+#include "AttributedString.h"
</ins><span class="cx"> #include "AuthenticationChallengeProxy.h"
</span><span class="cx"> #include "AuthenticationDecisionListener.h"
</span><span class="cx"> #include "DataReference.h"
</span><span class="lines">@@ -3601,6 +3602,21 @@
</span><span class="cx">     m_process->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPageProxy::getContentsAsAttributedString(CompletionHandler<void(const AttributedString&)>&& completionHandler)
+{
+#if PLATFORM(COCOA)
+    if (!isValid()) {
+        completionHandler(AttributedString());
+        return;
+    }
+
+    m_process->connection()->sendWithAsyncReply(Messages::WebPage::GetContentsAsAttributedString(), WTFMove(completionHandler), m_pageID);
+#else
+    ASSERT_NOT_REACHED();
+    completionHandler(AttributedString());
+#endif
+}
+
</ins><span class="cx"> void WebPageProxy::getBytecodeProfile(WTF::Function<void (const String&, CallbackBase::Error)>&& callbackFunction)
</span><span class="cx"> {
</span><span class="cx">     if (!isValid()) {
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.h     2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h        2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -973,6 +973,7 @@
</span><span class="cx">     void didFindStringMatches(const String&, const Vector<Vector<WebCore::IntRect>>& matchRects, int32_t firstIndexAfterSelection);
</span><span class="cx"> 
</span><span class="cx">     void getContentsAsString(WTF::Function<void (const String&, CallbackBase::Error)>&&);
</span><ins>+    void getContentsAsAttributedString(CompletionHandler<void(const AttributedString&)>&&);
</ins><span class="cx">     void getBytecodeProfile(WTF::Function<void (const String&, CallbackBase::Error)>&&);
</span><span class="cx">     void getSamplingProfilerOutput(WTF::Function<void (const String&, CallbackBase::Error)>&&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageCocoaWebPageCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm     2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm        2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #import "WebPage.h"
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+#import "AttributedString.h"
</ins><span class="cx"> #import "LoadParameters.h"
</span><span class="cx"> #import "PluginView.h"
</span><span class="cx"> #import "WebPageProxyMessages.h"
</span><span class="lines">@@ -42,6 +43,7 @@
</span><span class="cx"> #import <WebCore/PlatformMediaSessionManager.h>
</span><span class="cx"> #import <WebCore/RenderElement.h>
</span><span class="cx"> #import <WebCore/RenderObject.h>
</span><ins>+#import <WebCore/TextIterator.h>
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx"> 
</span><span class="lines">@@ -201,6 +203,21 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+void WebPage::getContentsAsAttributedString(CompletionHandler<void(const AttributedString&)>&& completionHandler)
+{
+    Frame& frame = m_page->mainFrame();
+
+    RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame.document()->documentElement(), 0, INT_MAX);
+
+    NSDictionary* documentAttributes = nil;
+
+    AttributedString result;
+    result.string = attributedStringFromRange(*range, &documentAttributes);
+    result.documentAttributes = documentAttributes;
+
+    completionHandler({ result });
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> 
</span><span class="cx"> #endif // PLATFORM(COCOA)
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -1315,6 +1315,9 @@
</span><span class="cx">     void viewWillEndLiveResize();
</span><span class="cx"> 
</span><span class="cx">     void getContentsAsString(CallbackID);
</span><ins>+#if PLATFORM(COCOA)
+    void getContentsAsAttributedString(CompletionHandler<void(const AttributedString&)>&&);
+#endif
</ins><span class="cx"> #if ENABLE(MHTML)
</span><span class="cx">     void getContentsAsMHTMLData(CallbackID);
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in       2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in  2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -182,6 +182,9 @@
</span><span class="cx"> 
</span><span class="cx">     # Callbacks.
</span><span class="cx">     GetContentsAsString(WebKit::CallbackID callbackID)
</span><ins>+#if PLATFORM(COCOA)
+    GetContentsAsAttributedString() -> (struct WebKit::AttributedString result) Async
+#endif
</ins><span class="cx"> #if ENABLE(MHTML)
</span><span class="cx">     GetContentsAsMHTMLData(WebKit::CallbackID callbackID)
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog    2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Tools/ChangeLog       2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2019-03-15  Timothy Hatcher  <timothy@apple.com>
+
+        Add support to WebPage for getting the contents as an attributed string.
+        https://bugs.webkit.org/show_bug.cgi?id=195636
+        rdar://problem/45055697
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm:
+        (TEST(WKWebView, GetContentsShouldReturnAttributedString): Added.
+
</ins><span class="cx"> 2019-03-15  Chris Dumez  <cdumez@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [PSON] Make sure the WebProcessCache is leverage when relaunching a process after termination
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKitCocoaWKWebViewGetContentsmm"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm (243011 => 243012)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm      2019-03-15 21:33:09 UTC (rev 243011)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm 2019-03-15 21:36:56 UTC (rev 243012)
</span><span class="lines">@@ -48,3 +48,48 @@
</span><span class="cx"> 
</span><span class="cx">     TestWebKitAPI::Util::run(&finished);
</span><span class="cx"> }
</span><ins>+
+TEST(WKWebView, GetContentsShouldReturnAttributedString)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView synchronouslyLoadHTMLString:@"<body bgcolor='red'>Hello <b>World!</b>"];
+
+    __block bool finished = false;
+
+#if USE(APPKIT)
+    using PlatformFont = NSFont;
+    using PlatformColor = NSColor;
+#else
+    using PlatformFont = UIFont;
+    using PlatformColor = UIColor;
+#endif
+
+    [webView _getContentsAsAttributedStringWithCompletionHandler:^(NSAttributedString *attributedString, NSDictionary<NSAttributedStringDocumentAttributeKey, id> *documentAttributes, NSError *error) {
+        EXPECT_NOT_NULL(attributedString);
+        EXPECT_NOT_NULL(documentAttributes);
+        EXPECT_NULL(error);
+
+        __block size_t i = 0;
+        [attributedString enumerateAttributesInRange:NSMakeRange(0, attributedString.length) options:0 usingBlock:^(NSDictionary *attributes, NSRange attributeRange, BOOL *stop) {
+            auto* substring = [attributedString attributedSubstringFromRange:attributeRange];
+
+            if (!i) {
+                EXPECT_WK_STREQ(@"Hello ", substring.string);
+                EXPECT_WK_STREQ(@"Times-Roman", dynamic_objc_cast<PlatformFont>(attributes[NSFontAttributeName]).fontName);
+            } else if (i == 1) {
+                EXPECT_WK_STREQ(@"World!", substring.string);
+                EXPECT_WK_STREQ(@"Times-Bold", dynamic_objc_cast<PlatformFont>(attributes[NSFontAttributeName]).fontName);
+            } else
+                ASSERT_NOT_REACHED();
+
+            ++i;
+        }];
+
+        EXPECT_WK_STREQ(@"sRGB IEC61966-2.1 colorspace 1 0 0 1", dynamic_objc_cast<PlatformColor>(documentAttributes[NSBackgroundColorDocumentAttribute]).description);
+
+        finished = true;
+    }];
+
+    TestWebKitAPI::Util::run(&finished);
+}
</ins></span></pre>
</div>
</div>

</body>
</html>