<!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>[199091] trunk/Source/WebKit2</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/199091">199091</a></dd>
<dt>Author</dt> <dd>bburg@apple.com</dd>
<dt>Date</dt> <dd>2016-04-05 20:23:18 -0700 (Tue, 05 Apr 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Automation: add support for getting, deleting, and adding cookies
https://bugs.webkit.org/show_bug.cgi?id=156090
&lt;rdar://problem/25477678&gt;

Reviewed by Timothy Hatcher.

Add protocol commands for manipulating cookies with respect to a given page.
Implement all but the addSingleCookie command, which needs a new WebCore API.

* UIProcess/Automation/Automation.json:
Copy the Page domain Cookie object. Add new commands.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::getAllCookies):
(WebKit::buildObjectForCookie): Copied from InspectorPageAgent.
(WebKit::buildArrayForCookies): Copied from InspectorPageAgent.
(WebKit::WebAutomationSession::didGetCookiesForFrame):
(WebKit::WebAutomationSession::deleteSingleCookie):
(WebKit::WebAutomationSession::didDeleteCookie):
(WebKit::WebAutomationSession::addSingleCookie): Added a stub for now.
(WebKit::WebAutomationSession::deleteAllCookies):
This command can use the WebCookieManager supplement directly instead of
proxying through AutomationSession. It doesn't block until the delete is
performed like the other methods do, but this shouldn't be a problem.

* UIProcess/Automation/WebAutomationSession.h:
* UIProcess/Automation/WebAutomationSession.messages.in:
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::WebAutomationSessionProxy::getCookiesForFrame):
(WebKit::WebAutomationSessionProxy::deleteCookie):
* WebProcess/Automation/WebAutomationSessionProxy.h:
* WebProcess/Automation/WebAutomationSessionProxy.messages.in:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationAutomationjson">trunk/Source/WebKit2/UIProcess/Automation/Automation.json</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessionh">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAutomationWebAutomationSessionmessagesin">trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxycpp">trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxyh">trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxymessagesin">trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/ChangeLog        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2016-04-05  Brian Burg  &lt;bburg@apple.com&gt;
+
+        Web Automation: add support for getting, deleting, and adding cookies
+        https://bugs.webkit.org/show_bug.cgi?id=156090
+        &lt;rdar://problem/25477678&gt;
+
+        Reviewed by Timothy Hatcher.
+
+        Add protocol commands for manipulating cookies with respect to a given page.
+        Implement all but the addSingleCookie command, which needs a new WebCore API.
+
+        * UIProcess/Automation/Automation.json:
+        Copy the Page domain Cookie object. Add new commands.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::getAllCookies):
+        (WebKit::buildObjectForCookie): Copied from InspectorPageAgent.
+        (WebKit::buildArrayForCookies): Copied from InspectorPageAgent.
+        (WebKit::WebAutomationSession::didGetCookiesForFrame):
+        (WebKit::WebAutomationSession::deleteSingleCookie):
+        (WebKit::WebAutomationSession::didDeleteCookie):
+        (WebKit::WebAutomationSession::addSingleCookie): Added a stub for now.
+        (WebKit::WebAutomationSession::deleteAllCookies):
+        This command can use the WebCookieManager supplement directly instead of
+        proxying through AutomationSession. It doesn't block until the delete is
+        performed like the other methods do, but this shouldn't be a problem.
+
+        * UIProcess/Automation/WebAutomationSession.h:
+        * UIProcess/Automation/WebAutomationSession.messages.in:
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::WebAutomationSessionProxy::getCookiesForFrame):
+        (WebKit::WebAutomationSessionProxy::deleteCookie):
+        * WebProcess/Automation/WebAutomationSessionProxy.h:
+        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
+
</ins><span class="cx"> 2016-04-05  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix Range requests when not using the NetworkCache with NetworkSession
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationAutomationjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -187,6 +187,21 @@
</span><span class="cx">                 { &quot;name&quot;: &quot;key&quot;, &quot;$ref&quot;: &quot;VirtualKey&quot;, &quot;optional&quot;: true, &quot;description&quot;: &quot;A virtual key to be used to perform the specified interaction.&quot; },
</span><span class="cx">                 { &quot;name&quot;: &quot;text&quot;, &quot;type&quot;: &quot;string&quot;, &quot;optional&quot;: true, &quot;description&quot;: &quot;A unicode string to be delivered to the page. The sequence of key events is determined by splitting the string at grapheme cluster boundaries.&quot; }
</span><span class="cx">             ]
</span><ins>+        },
+        {
+            &quot;id&quot;: &quot;Cookie&quot;,
+            &quot;type&quot;: &quot;object&quot;,
+            &quot;properties&quot;: [
+                { &quot;name&quot;: &quot;name&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Cookie name.&quot; },
+                { &quot;name&quot;: &quot;value&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Cookie value.&quot; },
+                { &quot;name&quot;: &quot;domain&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Cookie domain. If empty, the domain is inherited from the relevant browsing context.&quot; },
+                { &quot;name&quot;: &quot;path&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Cookie path.&quot; },
+                { &quot;name&quot;: &quot;expires&quot;, &quot;type&quot;: &quot;number&quot;, &quot;description&quot;: &quot;Cookie expires.&quot; },
+                { &quot;name&quot;: &quot;size&quot;, &quot;type&quot;: &quot;integer&quot;, &quot;description&quot;: &quot;Cookie size.&quot; },
+                { &quot;name&quot;: &quot;httpOnly&quot;, &quot;type&quot;: &quot;boolean&quot;, &quot;description&quot;: &quot;True if cookie is http-only.&quot; },
+                { &quot;name&quot;: &quot;secure&quot;, &quot;type&quot;: &quot;boolean&quot;, &quot;description&quot;: &quot;True if cookie is secure.&quot; },
+                { &quot;name&quot;: &quot;session&quot;, &quot;type&quot;: &quot;boolean&quot;, &quot;description&quot;: &quot;True in case of session cookie.&quot; }
+            ]
</ins><span class="cx">         }
</span><span class="cx">     ],
</span><span class="cx">     &quot;commands&quot;: [
</span><span class="lines">@@ -410,6 +425,43 @@
</span><span class="cx">                 { &quot;name&quot;: &quot;browsingContextHandle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context.&quot; },
</span><span class="cx">                 { &quot;name&quot;: &quot;userInput&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;The text to enter in the prompt.&quot; }
</span><span class="cx">             ]
</span><ins>+        },
+        {
+            &quot;name&quot;: &quot;getAllCookies&quot;,
+            &quot;description&quot;: &quot;Returns all cookies visible to the specified browsing context.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;browsingContextHandle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context.&quot; }
+            ],
+            &quot;returns&quot;: [
+                { &quot;name&quot;: &quot;cookies&quot;, &quot;type&quot;: &quot;array&quot;, &quot;items&quot;: { &quot;$ref&quot;: &quot;Cookie&quot; }, &quot;description&quot;: &quot;Array of cookie objects.&quot; }
+            ],
+            &quot;async&quot;: true
+        },
+        {
+            &quot;name&quot;: &quot;deleteSingleCookie&quot;,
+            &quot;description&quot;: &quot;Deletes a cookie with the given name if visible to the specified browsing context.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;browsingContextHandle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context.&quot; },
+                { &quot;name&quot;: &quot;cookieName&quot;, &quot;type&quot;: &quot;string&quot;, &quot;description&quot;: &quot;Name of the cookie to remove.&quot; }
+            ],
+            &quot;async&quot;: true
+        },
+        {
+            &quot;name&quot;: &quot;addSingleCookie&quot;,
+            &quot;description&quot;: &quot;Add a cookie to cookie storage for the specified browsing context.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;browsingContextHandle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context.&quot; },
+                { &quot;name&quot;: &quot;cookie&quot;, &quot;$ref&quot;: &quot;Cookie&quot;, &quot;description&quot;: &quot;The cookie that should be added to storage.&quot; }
+            ],
+            &quot;async&quot;: true
+        },
+        {
+            &quot;name&quot;: &quot;deleteAllCookies&quot;,
+            &quot;description&quot;: &quot;Delete all cookies that are visible to the specified browsing context.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;browsingContextHandle&quot;, &quot;$ref&quot;: &quot;BrowsingContextHandle&quot;, &quot;description&quot;: &quot;The handle for the browsing context.&quot; }
+            ],
+            &quot;async&quot;: true
</ins><span class="cx">         }
</span><span class="cx">     ]
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include &quot;AutomationProtocolObjects.h&quot;
</span><span class="cx"> #include &quot;WebAutomationSessionMessages.h&quot;
</span><span class="cx"> #include &quot;WebAutomationSessionProxyMessages.h&quot;
</span><ins>+#include &quot;WebCookieManagerProxy.h&quot;
</ins><span class="cx"> #include &quot;WebProcessPool.h&quot;
</span><span class="cx"> #include &lt;JavaScriptCore/InspectorBackendDispatcher.h&gt;
</span><span class="cx"> #include &lt;JavaScriptCore/InspectorFrontendRouter.h&gt;
</span><span class="lines">@@ -657,6 +658,118 @@
</span><span class="cx">     m_client-&gt;setUserInputForCurrentJavaScriptPromptOnPage(this, page, promptValue);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebAutomationSession::getAllCookies(ErrorString&amp; errorString, const String&amp; browsingContextHandle, Ref&lt;GetAllCookiesCallback&gt;&amp;&amp; callback)
+{
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    WebFrameProxy* mainFrame = page-&gt;mainFrame();
+    ASSERT(mainFrame);
+    if (!mainFrame)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    uint64_t callbackID = m_nextGetCookiesCallbackID++;
+    m_getCookieCallbacks.set(callbackID, WTFMove(callback));
+
+    page-&gt;process().send(Messages::WebAutomationSessionProxy::GetCookiesForFrame(mainFrame-&gt;frameID(), callbackID), 0);
+}
+
+static Ref&lt;Inspector::Protocol::Automation::Cookie&gt; buildObjectForCookie(const WebCore::Cookie&amp; cookie)
+{
+    return Inspector::Protocol::Automation::Cookie::create()
+        .setName(cookie.name)
+        .setValue(cookie.value)
+        .setDomain(cookie.domain)
+        .setPath(cookie.path)
+        .setExpires(cookie.expires)
+        .setSize((cookie.name.length() + cookie.value.length()))
+        .setHttpOnly(cookie.httpOnly)
+        .setSecure(cookie.secure)
+        .setSession(cookie.session)
+        .release();
+}
+
+static Ref&lt;Inspector::Protocol::Array&lt;Inspector::Protocol::Automation::Cookie&gt;&gt; buildArrayForCookies(Vector&lt;WebCore::Cookie&gt;&amp; cookiesList)
+{
+    auto cookies = Inspector::Protocol::Array&lt;Inspector::Protocol::Automation::Cookie&gt;::create();
+
+    for (const auto&amp; cookie : cookiesList)
+        cookies-&gt;addItem(buildObjectForCookie(cookie));
+
+    return cookies;
+}
+
+void WebAutomationSession::didGetCookiesForFrame(uint64_t callbackID, Vector&lt;WebCore::Cookie&gt; cookies, const String&amp; errorType)
+{
+    auto callback = m_getCookieCallbacks.take(callbackID);
+    if (!callback)
+        return;
+
+    if (!errorType.isEmpty()) {
+        callback-&gt;sendFailure(errorType);
+        return;
+    }
+
+    callback-&gt;sendSuccess(buildArrayForCookies(cookies));
+}
+
+void WebAutomationSession::deleteSingleCookie(ErrorString&amp; errorString, const String&amp; browsingContextHandle, const String&amp; cookieName, Ref&lt;DeleteSingleCookieCallback&gt;&amp;&amp; callback)
+{
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    WebFrameProxy* mainFrame = page-&gt;mainFrame();
+    ASSERT(mainFrame);
+    if (!mainFrame)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    uint64_t callbackID = m_nextDeleteCookieCallbackID++;
+    m_deleteCookieCallbacks.set(callbackID, WTFMove(callback));
+
+    page-&gt;process().send(Messages::WebAutomationSessionProxy::DeleteCookie(mainFrame-&gt;frameID(), cookieName, callbackID), 0);
+}
+
+void WebAutomationSession::didDeleteCookie(uint64_t callbackID, const String&amp; errorType)
+{
+    auto callback = m_deleteCookieCallbacks.take(callbackID);
+    if (!callback)
+        return;
+
+    if (!errorType.isEmpty()) {
+        callback-&gt;sendFailure(errorType);
+        return;
+    }
+
+    callback-&gt;sendSuccess();
+}
+
+void WebAutomationSession::addSingleCookie(ErrorString&amp; errorString, const String&amp; browsingContextHandle, const Inspector::InspectorObject&amp; cookie, Ref&lt;AddSingleCookieCallback&gt;&amp;&amp; callback)
+{
+    // FIXME: Implementing this command requires a new CookieJar API &lt;https://webkit.org/b/156091&gt;
+    UNUSED_PARAM(browsingContextHandle);
+    // FIXME: if the incoming cookie's domain is the string '(inherit)',
+    // then it should be inherited from the main frame's domain.
+    UNUSED_PARAM(cookie);
+    UNUSED_PARAM(callback);
+
+    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+}
+
+void WebAutomationSession::deleteAllCookies(ErrorString&amp; errorString, const String&amp; browsingContextHandle, Ref&lt;DeleteAllCookiesCallback&gt;&amp;&amp; callback)
+{
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    WebCore::URL activeURL = WebCore::URL(WebCore::URL(), page-&gt;pageLoadState().activeURL());
+    ASSERT(activeURL.isValid());
+
+    WebCookieManagerProxy* cookieManager = m_processPool-&gt;supplement&lt;WebCookieManagerProxy&gt;();
+    cookieManager-&gt;deleteCookiesForHostname(activeURL.host());
+}
+
</ins><span class="cx"> #if USE(APPKIT)
</span><span class="cx"> static WebEvent::Modifiers protocolModifierToWebEventModifier(Inspector::Protocol::Automation::KeyModifier modifier)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -46,11 +46,10 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><ins>+class IntPoint;
</ins><span class="cx"> class IntRect;
</span><del>-}
</del><span class="cx"> 
</span><del>-namespace WebCore {
-class IntPoint;
</del><ins>+struct Cookie;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if USE(APPKIT)
</span><span class="lines">@@ -117,7 +116,10 @@
</span><span class="cx">     void acceptCurrentJavaScriptDialog(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle) override;
</span><span class="cx">     void messageOfCurrentJavaScriptDialog(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, String* text) override;
</span><span class="cx">     void setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String&amp; text) override;
</span><del>-
</del><ins>+    void getAllCookies(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, Ref&lt;GetAllCookiesCallback&gt;&amp;&amp;) override;
+    void deleteSingleCookie(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const String&amp; cookieName, Ref&lt;DeleteSingleCookieCallback&gt;&amp;&amp;) override;
+    void addSingleCookie(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, const Inspector::InspectorObject&amp; cookie, Ref&lt;AddSingleCookieCallback&gt;&amp;&amp;) override;
+    void deleteAllCookies(Inspector::ErrorString&amp;, const String&amp; browsingContextHandle, Ref&lt;DeleteAllCookiesCallback&gt;&amp;&amp;) override;
</ins><span class="cx"> #if USE(APPKIT)
</span><span class="cx">     bool wasEventSynthesizedForAutomation(NSEvent *);
</span><span class="cx"> #endif
</span><span class="lines">@@ -140,6 +142,8 @@
</span><span class="cx">     void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String&amp; errorType);
</span><span class="cx">     void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String&amp; errorType);
</span><span class="cx">     void didTakeScreenshot(uint64_t callbackID, const ShareableBitmap::Handle&amp;, const String&amp; errorType);
</span><ins>+    void didGetCookiesForFrame(uint64_t callbackID, Vector&lt;WebCore::Cookie&gt;, const String&amp; errorType);
+    void didDeleteCookie(uint64_t callbackID, const String&amp; errorType);
</ins><span class="cx"> 
</span><span class="cx">     // Platform-specific helper methods.
</span><span class="cx">     void platformSimulateMouseInteraction(WebPageProxy&amp;, const WebCore::IntPoint&amp; viewPosition, Inspector::Protocol::Automation::MouseInteraction, Inspector::Protocol::Automation::MouseButton, WebEvent::Modifiers);
</span><span class="lines">@@ -186,6 +190,12 @@
</span><span class="cx">     uint64_t m_nextScreenshotCallbackID { 1 };
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;Inspector::AutomationBackendDispatcherHandler::TakeScreenshotCallback&gt;&gt; m_screenshotCallbacks;
</span><span class="cx"> 
</span><ins>+    uint64_t m_nextGetCookiesCallbackID { 1 };
+    HashMap&lt;uint64_t, RefPtr&lt;Inspector::AutomationBackendDispatcherHandler::GetAllCookiesCallback&gt;&gt; m_getCookieCallbacks;
+
+    uint64_t m_nextDeleteCookieCallbackID { 1 };
+    HashMap&lt;uint64_t, RefPtr&lt;Inspector::AutomationBackendDispatcherHandler::DeleteSingleCookieCallback&gt;&gt; m_deleteCookieCallbacks;
+
</ins><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="cx">     Inspector::FrontendChannel* m_remoteChannel { nullptr };
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAutomationWebAutomationSessionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -29,4 +29,7 @@
</span><span class="cx">     DidComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, String errorType)
</span><span class="cx"> 
</span><span class="cx">     DidTakeScreenshot(uint64_t callbackID, WebKit::ShareableBitmap::Handle imageDataHandle, String errorType)
</span><ins>+
+    DidGetCookiesForFrame(uint64_t callbackID, Vector&lt;WebCore::Cookie&gt; cookies, String errorType)
+    DidDeleteCookie(uint64_t callbackID, String errorType)
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> #include &lt;JavaScriptCore/JSRetainPtr.h&gt;
</span><span class="cx"> #include &lt;JavaScriptCore/JSStringRefPrivate.h&gt;
</span><span class="cx"> #include &lt;JavaScriptCore/OpaqueJSString.h&gt;
</span><ins>+#include &lt;WebCore/CookieJar.h&gt;
</ins><span class="cx"> #include &lt;WebCore/DOMWindow.h&gt;
</span><span class="cx"> #include &lt;WebCore/Frame.h&gt;
</span><span class="cx"> #include &lt;WebCore/FrameTree.h&gt;
</span><span class="lines">@@ -492,4 +493,38 @@
</span><span class="cx">     WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, String()), 0);    
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebAutomationSessionProxy::getCookiesForFrame(uint64_t frameID, uint64_t callbackID)
+{
+    String frameNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
+
+    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
+    if (!frame || !frame-&gt;coreFrame() || !frame-&gt;coreFrame()-&gt;document()) {
+        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidGetCookiesForFrame(callbackID, Vector&lt;WebCore::Cookie&gt;(), frameNotFoundErrorType), 0);
+        return;
+    }
+
+    // This returns the same list of cookies as when evaluating `document.cookies` in JavaScript.
+    WebCore::Document* document = frame-&gt;coreFrame()-&gt;document();
+    Vector&lt;WebCore::Cookie&gt; foundCookies;
+    WebCore::getRawCookies(document, document-&gt;cookieURL(), foundCookies);
+
+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidGetCookiesForFrame(callbackID, foundCookies, String()), 0);
+}
+
+void WebAutomationSessionProxy::deleteCookie(uint64_t frameID, String cookieName, uint64_t callbackID)
+{
+    String frameNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
+
+    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
+    if (!frame || !frame-&gt;coreFrame() || !frame-&gt;coreFrame()-&gt;document()) {
+        WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidDeleteCookie(callbackID, frameNotFoundErrorType), 0);
+        return;
+    }
+
+    WebCore::Document* document = frame-&gt;coreFrame()-&gt;document();
+    WebCore::deleteCookie(document, document-&gt;cookieURL(), cookieName);
+
+    WebProcess::singleton().parentProcessConnection()-&gt;send(Messages::WebAutomationSession::DidDeleteCookie(callbackID, String()), 0);
+}
+
</ins><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -66,6 +66,8 @@
</span><span class="cx">     void focusFrame(uint64_t frameID);
</span><span class="cx">     void computeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID);
</span><span class="cx">     void takeScreenshot(uint64_t pageID, uint64_t callbackID);
</span><ins>+    void getCookiesForFrame(uint64_t frameID, uint64_t callbackID);
+    void deleteCookie(uint64_t frameID, String cookieName, uint64_t callbackID);
</ins><span class="cx"> 
</span><span class="cx">     String m_sessionIdentifier;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessAutomationWebAutomationSessionProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in (199090 => 199091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in        2016-04-06 01:37:07 UTC (rev 199090)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in        2016-04-06 03:23:18 UTC (rev 199091)
</span><span class="lines">@@ -33,4 +33,7 @@
</span><span class="cx">     ComputeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
</span><span class="cx"> 
</span><span class="cx">     TakeScreenshot(uint64_t pageID, uint64_t callbackID)
</span><ins>+
+    GetCookiesForFrame(uint64_t frameID, uint64_t callbackID)
+    DeleteCookie(uint64_t frameID, String cookieName, uint64_t callbackID)
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>