Title: [199197] trunk/Source
Revision
199197
Author
[email protected]
Date
2016-04-07 15:34:58 -0700 (Thu, 07 Apr 2016)

Log Message

Web Automation: implement Automation.addSingleCookie
https://bugs.webkit.org/show_bug.cgi?id=156319
<rdar://problem/25589605>

Reviewed by Timothy Hatcher.

Source/WebCore:

* platform/Cookie.h: Document the units used by the 'expires' field.

Source/WebKit2:

Implement this command by converting the protocol cookie to
WebCore::Cookie, then sending the cookie to NetworkProcess to
be added to the storage session using CookieJar::addCookie.

* UIProcess/Automation/Automation.json:
Clarify the units used in the 'expires' field and how the default value
for the domain field should be computed.

* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::addSingleCookie):
Parse the cookie and send it out via WebCookieManagerProxy.

* UIProcess/WebCookieManagerProxy.cpp:
(WebKit::WebCookieManagerProxy::addCookie): Added.
* UIProcess/WebCookieManagerProxy.h:
* WebProcess/Cookies/WebCookieManager.cpp:
(WebKit::WebCookieManager::addCookie):
* WebProcess/Cookies/WebCookieManager.h:
* WebProcess/Cookies/WebCookieManager.messages.in:
Forward the message to WebCore::addCookie.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (199196 => 199197)


--- trunk/Source/WebCore/ChangeLog	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebCore/ChangeLog	2016-04-07 22:34:58 UTC (rev 199197)
@@ -1,3 +1,13 @@
+2016-04-07  Brian Burg  <[email protected]>
+
+        Web Automation: implement Automation.addSingleCookie
+        https://bugs.webkit.org/show_bug.cgi?id=156319
+        <rdar://problem/25589605>
+
+        Reviewed by Timothy Hatcher.
+
+        * platform/Cookie.h: Document the units used by the 'expires' field.
+
 2016-04-07  Jon Davis  <[email protected]>
 
         Add ImageBitmap as under consideration on Feature Status page

Modified: trunk/Source/WebCore/platform/Cookie.h (199196 => 199197)


--- trunk/Source/WebCore/platform/Cookie.h	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebCore/platform/Cookie.h	2016-04-07 22:34:58 UTC (rev 199197)
@@ -52,6 +52,7 @@
         String value;
         String domain;
         String path;
+        // Expiration date, expressed as milliseconds since the UNIX epoch.
         double expires;
         bool httpOnly;
         bool secure;

Modified: trunk/Source/WebKit2/ChangeLog (199196 => 199197)


--- trunk/Source/WebKit2/ChangeLog	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/ChangeLog	2016-04-07 22:34:58 UTC (rev 199197)
@@ -1,3 +1,32 @@
+2016-04-07  Brian Burg  <[email protected]>
+
+        Web Automation: implement Automation.addSingleCookie
+        https://bugs.webkit.org/show_bug.cgi?id=156319
+        <rdar://problem/25589605>
+
+        Reviewed by Timothy Hatcher.
+
+        Implement this command by converting the protocol cookie to
+        WebCore::Cookie, then sending the cookie to NetworkProcess to
+        be added to the storage session using CookieJar::addCookie.
+
+        * UIProcess/Automation/Automation.json:
+        Clarify the units used in the 'expires' field and how the default value
+        for the domain field should be computed.
+
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::addSingleCookie):
+        Parse the cookie and send it out via WebCookieManagerProxy.
+
+        * UIProcess/WebCookieManagerProxy.cpp:
+        (WebKit::WebCookieManagerProxy::addCookie): Added.
+        * UIProcess/WebCookieManagerProxy.h:
+        * WebProcess/Cookies/WebCookieManager.cpp:
+        (WebKit::WebCookieManager::addCookie):
+        * WebProcess/Cookies/WebCookieManager.h:
+        * WebProcess/Cookies/WebCookieManager.messages.in:
+        Forward the message to WebCore::addCookie.
+
 2016-04-06  Ada Chan  <[email protected]>
 
         Add WebKitAdditions extension points around preferences

Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (199196 => 199197)


--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-04-07 22:34:58 UTC (rev 199197)
@@ -196,7 +196,7 @@
                 { "name": "value", "type": "string", "description": "Cookie value." },
                 { "name": "domain", "type": "string", "description": "Cookie domain. If empty, the domain is inherited from the relevant browsing context." },
                 { "name": "path", "type": "string", "description": "Cookie path." },
-                { "name": "expires", "type": "number", "description": "Cookie expires." },
+                { "name": "expires", "type": "number", "description": "Cookie expiration in seconds since the UNIX epoch." },
                 { "name": "size", "type": "integer", "description": "Cookie size." },
                 { "name": "httpOnly", "type": "boolean", "description": "True if cookie is http-only." },
                 { "name": "secure", "type": "boolean", "description": "True if cookie is secure." },

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (199196 => 199197)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-04-07 22:34:58 UTC (rev 199197)
@@ -745,16 +745,55 @@
     callback->sendSuccess();
 }
 
-void WebAutomationSession::addSingleCookie(ErrorString& errorString, const String& browsingContextHandle, const Inspector::InspectorObject& cookie, Ref<AddSingleCookieCallback>&& callback)
+void WebAutomationSession::addSingleCookie(ErrorString& errorString, const String& browsingContextHandle, const Inspector::InspectorObject& cookieObject, Ref<AddSingleCookieCallback>&& callback)
 {
-    // FIXME: Implementing this command requires a new CookieJar API <https://webkit.org/b/156091>
-    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);
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
 
-    FAIL_WITH_PREDEFINED_ERROR_MESSAGE(NotImplemented);
+    WebCore::URL activeURL = WebCore::URL(WebCore::URL(), page->pageLoadState().activeURL());
+    ASSERT(activeURL.isValid());
+
+    WebCore::Cookie cookie;
+
+    if (!cookieObject.getString(WTF::ASCIILiteral("name"), cookie.name))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    if (!cookieObject.getString(WTF::ASCIILiteral("value"), cookie.value))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    String domain;
+    if (!cookieObject.getString(WTF::ASCIILiteral("domain"), domain))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    // Inherit the domain/host from the main frame's URL if it is not explicitly set.
+    if (domain.isEmpty())
+        domain = activeURL.host();
+
+    cookie.domain = domain;
+
+    if (!cookieObject.getString(WTF::ASCIILiteral("path"), cookie.path))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    double expires;
+    if (!cookieObject.getDouble(WTF::ASCIILiteral("expires"), expires))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    cookie.expires = expires * 1000.0;
+
+    if (!cookieObject.getBoolean(WTF::ASCIILiteral("secure"), cookie.secure))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    if (!cookieObject.getBoolean(WTF::ASCIILiteral("session"), cookie.session))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    if (!cookieObject.getBoolean(WTF::ASCIILiteral("httpOnly"), cookie.httpOnly))
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(MissingParameter);
+
+    WebCookieManagerProxy* cookieManager = m_processPool->supplement<WebCookieManagerProxy>();
+    cookieManager->addCookie(cookie, activeURL.host());
+
+    callback->sendSuccess();
 }
 
 void WebAutomationSession::deleteAllCookies(ErrorString& errorString, const String& browsingContextHandle, Ref<DeleteAllCookiesCallback>&& callback)

Modified: trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp (199196 => 199197)


--- trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.cpp	2016-04-07 22:34:58 UTC (rev 199197)
@@ -128,6 +128,11 @@
     processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::DeleteAllCookiesModifiedSince(time));
 }
 
+void WebCookieManagerProxy::addCookie(const WebCore::Cookie& cookie, const String& hostname)
+{
+    processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::AddCookie(cookie, hostname));
+}
+
 void WebCookieManagerProxy::startObservingCookieChanges()
 {
     processPool()->sendToNetworkingProcessRelaunchingIfNecessary(Messages::WebCookieManager::StartObservingCookieChanges());

Modified: trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.h (199196 => 199197)


--- trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.h	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/UIProcess/WebCookieManagerProxy.h	2016-04-07 22:34:58 UTC (rev 199197)
@@ -43,6 +43,9 @@
 class Array;
 }
 
+namespace WebCore {
+struct Cookie;
+}
 
 namespace WebKit {
 
@@ -65,6 +68,7 @@
     void deleteCookiesForHostname(const String& hostname);
     void deleteAllCookies();
     void deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point);
+    void addCookie(const WebCore::Cookie&, const String& hostname);
 
     void setHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy);
     void getHTTPCookieAcceptPolicy(std::function<void (HTTPCookieAcceptPolicy, CallbackBase::Error)>);

Modified: trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.cpp (199196 => 199197)


--- trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.cpp	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.cpp	2016-04-07 22:34:58 UTC (rev 199197)
@@ -33,6 +33,7 @@
 #include <WebCore/CookieStorage.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/PlatformCookieJar.h>
+#include <WebCore/URL.h>
 #include <wtf/MainThread.h>
 #include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
@@ -83,6 +84,11 @@
     WebCore::deleteAllCookiesModifiedSince(NetworkStorageSession::defaultStorageSession(), time);
 }
 
+void WebCookieManager::addCookie(const Cookie& cookie, const String& hostname)
+{
+    WebCore::addCookie(NetworkStorageSession::defaultStorageSession(), URL(URL(), hostname), cookie);
+}
+
 void WebCookieManager::startObservingCookieChanges()
 {
     WebCore::startObservingCookieChanges(cookiesDidChange);

Modified: trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.h (199196 => 199197)


--- trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.h	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.h	2016-04-07 22:34:58 UTC (rev 199197)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2013, 2016 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,6 +38,10 @@
 #include "SoupCookiePersistentStorageType.h"
 #endif
 
+namespace WebCore {
+struct Cookie;
+}
+
 namespace WebKit {
 
 class ChildProcess;
@@ -62,6 +66,7 @@
     void deleteCookiesForHostname(const String&);
     void deleteAllCookies();
     void deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point);
+    void addCookie(const WebCore::Cookie&, const String& hostname);
 
     void platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy);
     void getHTTPCookieAcceptPolicy(uint64_t callbackID);

Modified: trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.messages.in (199196 => 199197)


--- trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.messages.in	2016-04-07 22:31:56 UTC (rev 199196)
+++ trunk/Source/WebKit2/WebProcess/Cookies/WebCookieManager.messages.in	2016-04-07 22:34:58 UTC (rev 199197)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 2016 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +28,7 @@
     void DeleteCookiesForHostname(String hostname)
     void DeleteAllCookies()
     void DeleteAllCookiesModifiedSince(std::chrono::system_clock::time_point time)
+    void AddCookie(struct WebCore::Cookie cookie, String hostname)
 
     void SetHTTPCookieAcceptPolicy(uint32_t policy)
     void GetHTTPCookieAcceptPolicy(uint64_t callbackID)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to