Title: [228111] trunk/Source
Revision
228111
Author
[email protected]
Date
2018-02-05 12:03:48 -0800 (Mon, 05 Feb 2018)

Log Message

Improve NetworkResourceLoader logging so it can be used for 'setCookiesFromDOM'
https://bugs.webkit.org/show_bug.cgi?id=182455
<rdar://problem/36626601>

Reviewed by Chris Dumez.

Source/WebCore:

After this refactoring, a convenience method I added in r227860 is no longer needed.
This patch removes this dead code.

* platform/network/NetworkStorageSession.h: Export 'cookieStoragePartition' so it can
be used in WebKit.
* platform/network/cf/NetworkStorageSessionCFNet.cpp: 
(WebCore::NetworkStorageSession::hasStorageAccessForFrame): Deleted unused method.

Source/WebKit:

Refactor "logCookieInformation" so that it can be used for resource loads and DOM cookie
manipulation. Place the generally useful logic in a static method that can be invoked
from other places in the NetworkProcess.

Call the new refactored method from NetworkConnectionToWebProcess::setCookiesFromDOM so
we can perform logging there as well.

* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Call the new logging method
(when enabled).
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::shouldLogCookieInformation): Changed to static method.
(WebKit::escapeForJSON): Made a static function so it could be shared between multiple
methods.
(WebKit::NetworkResourceLoader::logCookieInformation const): Refactor into two methods.
(WebKit::NetworkResourceLoader::logCookieInformation): Ditto.
(WebKit::NetworkResourceLoader::shouldLogCookieInformation const): Deleted.
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa): Switch to user-enabled release logging
to track partitioning and blocking behavior.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228110 => 228111)


--- trunk/Source/WebCore/ChangeLog	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebCore/ChangeLog	2018-02-05 20:03:48 UTC (rev 228111)
@@ -1,3 +1,19 @@
+2018-02-02  Brent Fulgham  <[email protected]>
+
+        Improve NetworkResourceLoader logging so it can be used for 'setCookiesFromDOM'
+        https://bugs.webkit.org/show_bug.cgi?id=182455
+        <rdar://problem/36626601>
+
+        Reviewed by Chris Dumez.
+
+        After this refactoring, a convenience method I added in r227860 is no longer needed.
+        This patch removes this dead code.
+
+        * platform/network/NetworkStorageSession.h: Export 'cookieStoragePartition' so it can
+        be used in WebKit.
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp: 
+        (WebCore::NetworkStorageSession::hasStorageAccessForFrame): Deleted unused method.
+
 2018-02-05  Antti Koivisto  <[email protected]>
 
         Make ASSERT_WITH_SECURITY_IMPLICATION in CachedResourceClientWalker::next a release assert

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (228110 => 228111)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2018-02-05 20:03:48 UTC (rev 228111)
@@ -101,11 +101,10 @@
     WEBCORE_EXPORT String cookieStoragePartition(const ResourceRequest&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     WEBCORE_EXPORT bool shouldBlockCookies(const ResourceRequest&) const;
     bool shouldBlockCookies(const URL& firstPartyForCookies, const URL& resource) const;
-    String cookieStoragePartition(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
+    WEBCORE_EXPORT String cookieStoragePartition(const URL& firstPartyForCookies, const URL& resource, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID) const;
     WEBCORE_EXPORT void setPrevalentDomainsToPartitionOrBlockCookies(const Vector<String>& domainsToPartition, const Vector<String>& domainsToBlock, const Vector<String>& domainsToNeitherPartitionNorBlock, bool clearFirst);
     WEBCORE_EXPORT void removePrevalentDomains(const Vector<String>& domains);
     WEBCORE_EXPORT bool hasStorageAccessForFrame(const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID) const;
-    WEBCORE_EXPORT bool hasStorageAccessForFrame(const ResourceRequest&, uint64_t frameID, uint64_t pageID) const;
     WEBCORE_EXPORT Vector<String> getAllStorageAccessEntries() const;
     WEBCORE_EXPORT void grantStorageAccessForFrame(const String& resourceDomain, const String& firstPartyDomain, uint64_t frameID, uint64_t pageID);
     WEBCORE_EXPORT void removeStorageAccessForFrame(uint64_t frameID, uint64_t pageID);

Modified: trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp (228110 => 228111)


--- trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp	2018-02-05 20:03:48 UTC (rev 228111)
@@ -296,14 +296,6 @@
     return it2->value == resourceDomain;
 }
 
-bool NetworkStorageSession::hasStorageAccessForFrame(const ResourceRequest& request, uint64_t frameID, uint64_t pageID) const
-{
-    if (!cookieStoragePartitioningEnabled)
-        return false;
-
-    return hasStorageAccessForFrame(getPartitioningDomain(request.url()), getPartitioningDomain(request.firstPartyForCookies()), frameID, pageID);
-}
-
 Vector<String> NetworkStorageSession::getAllStorageAccessEntries() const
 {
     Vector<String> entries;

Modified: trunk/Source/WebKit/ChangeLog (228110 => 228111)


--- trunk/Source/WebKit/ChangeLog	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebKit/ChangeLog	2018-02-05 20:03:48 UTC (rev 228111)
@@ -1,3 +1,33 @@
+2018-02-02  Brent Fulgham  <[email protected]>
+
+        Improve NetworkResourceLoader logging so it can be used for 'setCookiesFromDOM'
+        https://bugs.webkit.org/show_bug.cgi?id=182455
+        <rdar://problem/36626601>
+
+        Reviewed by Chris Dumez.
+
+        Refactor "logCookieInformation" so that it can be used for resource loads and DOM cookie
+        manipulation. Place the generally useful logic in a static method that can be invoked
+        from other places in the NetworkProcess.
+
+        Call the new refactored method from NetworkConnectionToWebProcess::setCookiesFromDOM so
+        we can perform logging there as well.
+
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM): Call the new logging method
+        (when enabled).
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::shouldLogCookieInformation): Changed to static method.
+        (WebKit::escapeForJSON): Made a static function so it could be shared between multiple
+        methods.
+        (WebKit::NetworkResourceLoader::logCookieInformation const): Refactor into two methods.
+        (WebKit::NetworkResourceLoader::logCookieInformation): Ditto.
+        (WebKit::NetworkResourceLoader::shouldLogCookieInformation const): Deleted.
+        * NetworkProcess/NetworkResourceLoader.h:
+        * NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
+        (WebKit::NetworkDataTaskCocoa::NetworkDataTaskCocoa): Switch to user-enabled release logging
+        to track partitioning and blocking behavior.
+
 2018-02-05  John Wilander  <[email protected]>
 
         Storage Access API: Add testRunner.getAllStorageAccessEntries() to make testing easier and more explicit

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (228110 => 228111)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2018-02-05 20:03:48 UTC (rev 228111)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -342,7 +342,14 @@
 
 void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
 {
-    WebCore::setCookiesFromDOM(storageSession(sessionID), firstParty, url, frameID, pageID, cookieString);
+    auto& networkStorageSession = storageSession(sessionID);
+    WebCore::setCookiesFromDOM(networkStorageSession, firstParty, url, frameID, pageID, cookieString);
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
+    if (NetworkProcess::singleton().shouldLogCookieInformation()) {
+        auto partition = WebCore::URL(ParsedURLString, networkStorageSession.cookieStoragePartition(firstParty, url, frameID, pageID));
+        NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, partition, url, emptyString(), frameID, pageID, std::nullopt);
+    }
+#endif
 }
 
 void NetworkConnectionToWebProcess::cookiesEnabled(PAL::SessionID sessionID, bool& result)

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (228110 => 228111)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2018-02-05 20:03:48 UTC (rev 228111)
@@ -710,11 +710,16 @@
 }
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
-bool NetworkResourceLoader::shouldLogCookieInformation() const
+bool NetworkResourceLoader::shouldLogCookieInformation()
 {
     return NetworkProcess::singleton().shouldLogCookieInformation();
 }
 
+static String escapeForJSON(String s)
+{
+    return s.replace('\\', "\\\\").replace('"', "\\\"");
+}
+
 void NetworkResourceLoader::logCookieInformation() const
 {
     ASSERT(shouldLogCookieInformation());
@@ -725,10 +730,6 @@
 #define LOCAL_LOG(str, ...) \
     RELEASE_LOG_IF_ALLOWED("logCookieInformation: pageID = %" PRIu64 ", frameID = %" PRIu64 ", resourceID = %" PRIu64 ": " str, pageID(), frameID(), identifier(), ##__VA_ARGS__)
 
-    auto escapeForJSON = [](String s) {
-        return s.replace('\\', "\\\\").replace('"', "\\\"");
-    };
-
     auto url = ""
     if (networkStorageSession->shouldBlockCookies(originalRequest())) {
         auto escapedURL = escapeForJSON(url.string());
@@ -741,54 +742,72 @@
         LOCAL_LOG(R"(  "cookies": []})");
         return;
     }
+#undef LOCAL_LOG
 
     auto partition = WebCore::URL(ParsedURLString, networkStorageSession->cookieStoragePartition(originalRequest(), frameID(), pageID()));
-    bool hasStorageAccessForFrame = networkStorageSession->hasStorageAccessForFrame(originalRequest(), frameID(), pageID());
+    NetworkResourceLoader::logCookieInformation("NetworkResourceLoader", reinterpret_cast<const void*>(this), *networkStorageSession, partition, url, originalRequest().httpReferrer(), frameID(), pageID(), identifier());
+}
 
+void NetworkResourceLoader::logCookieInformation(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession& networkStorageSession, const WebCore::URL& partition, const WebCore::URL& url, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier)
+{
+    ASSERT(shouldLogCookieInformation());
+
     Vector<WebCore::Cookie> cookies;
-    bool result = WebCore::getRawCookies(*networkStorageSession, partition, url, frameID(), pageID(), cookies);
+    if (!WebCore::getRawCookies(networkStorageSession, partition, url, frameID, pageID, cookies))
+        return;
 
-    if (result) {
-        auto escapedURL = escapeForJSON(url.string());
-        auto escapedPartition = escapeForJSON(partition.string());
-        auto escapedReferrer = escapeForJSON(originalRequest().httpReferrer());
+    auto escapeIDForJSON = [](std::optional<uint64_t> value) {
+        return value ? String::number(value.value()) : String("None");
+    };
 
-        LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
-        LOCAL_LOG(R"(  "partition": "%{public}s",)", escapedPartition.utf8().data());
-        LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", hasStorageAccessForFrame ? "true" : "false");
-        LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
-        LOCAL_LOG(R"(  "cookies": [)");
+    auto escapedURL = escapeForJSON(url.string());
+    auto escapedPartition = escapeForJSON(partition.string());
+    auto escapedReferrer = escapeForJSON(referrer);
+    auto escapedFrameID = escapeIDForJSON(frameID);
+    auto escapedPageID = escapeIDForJSON(pageID);
+    auto escapedIdentifier = escapeIDForJSON(identifier);
+    bool hasStorageAccessForFrame = (frameID && pageID) ? networkStorageSession.hasStorageAccessForFrame(url.string(), partition.string(), frameID.value(), pageID.value()) : false;
 
-        auto size = cookies.size();
-        decltype(size) count = 0;
-        for (const auto& cookie : cookies) {
-            const char* trailingComma = ",";
-            if (++count == size)
-                trailingComma = "";
+#define LOCAL_LOG_IF_ALLOWED(fmt, ...) RELEASE_LOG_IF(networkStorageSession.sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - %s::" fmt, loggedObject, label.utf8().data(), ##__VA_ARGS__)
+#define LOCAL_LOG(str, ...) \
+    LOCAL_LOG_IF_ALLOWED("logCookieInformation: pageID = %s, frameID = %s, resourceID = %s: " str, escapedPageID.utf8().data(), escapedFrameID.utf8().data(), escapedIdentifier.utf8().data(), ##__VA_ARGS__)
 
-            auto escapedName = escapeForJSON(cookie.name);
-            auto escapedValue = escapeForJSON(cookie.value);
-            auto escapedDomain = escapeForJSON(cookie.domain);
-            auto escapedPath = escapeForJSON(cookie.path);
-            auto escapedComment = escapeForJSON(cookie.comment);
-            auto escapedCommentURL = escapeForJSON(cookie.commentURL.string());
+    LOCAL_LOG(R"({ "url": "%{public}s",)", escapedURL.utf8().data());
+    LOCAL_LOG(R"(  "partition": "%{public}s",)", escapedPartition.utf8().data());
+    LOCAL_LOG(R"(  "hasStorageAccess": %{public}s,)", hasStorageAccessForFrame ? "true" : "false");
+    LOCAL_LOG(R"(  "referer": "%{public}s",)", escapedReferrer.utf8().data());
+    LOCAL_LOG(R"(  "cookies": [)");
 
-            LOCAL_LOG(R"(  { "name": "%{public}s",)", escapedName.utf8().data());
-            LOCAL_LOG(R"(    "value": "%{public}s",)", escapedValue.utf8().data());
-            LOCAL_LOG(R"(    "domain": "%{public}s",)", escapedDomain.utf8().data());
-            LOCAL_LOG(R"(    "path": "%{public}s",)", escapedPath.utf8().data());
-            LOCAL_LOG(R"(    "created": %f,)", cookie.created);
-            LOCAL_LOG(R"(    "expires": %f,)", cookie.expires);
-            LOCAL_LOG(R"(    "httpOnly": %{public}s,)", cookie.httpOnly ? "true" : "false");
-            LOCAL_LOG(R"(    "secure": %{public}s,)", cookie.secure ? "true" : "false");
-            LOCAL_LOG(R"(    "session": %{public}s,)", cookie.session ? "true" : "false");
-            LOCAL_LOG(R"(    "comment": "%{public}s",)", escapedComment.utf8().data());
-            LOCAL_LOG(R"(    "commentURL": "%{public}s")", escapedCommentURL.utf8().data());
-            LOCAL_LOG(R"(  }%{public}s)", trailingComma);
-        }
-        LOCAL_LOG(R"(]})");
+    auto size = cookies.size();
+    decltype(size) count = 0;
+    for (const auto& cookie : cookies) {
+        const char* trailingComma = ",";
+        if (++count == size)
+            trailingComma = "";
+
+        auto escapedName = escapeForJSON(cookie.name);
+        auto escapedValue = escapeForJSON(cookie.value);
+        auto escapedDomain = escapeForJSON(cookie.domain);
+        auto escapedPath = escapeForJSON(cookie.path);
+        auto escapedComment = escapeForJSON(cookie.comment);
+        auto escapedCommentURL = escapeForJSON(cookie.commentURL.string());
+
+        LOCAL_LOG(R"(  { "name": "%{public}s",)", escapedName.utf8().data());
+        LOCAL_LOG(R"(    "value": "%{public}s",)", escapedValue.utf8().data());
+        LOCAL_LOG(R"(    "domain": "%{public}s",)", escapedDomain.utf8().data());
+        LOCAL_LOG(R"(    "path": "%{public}s",)", escapedPath.utf8().data());
+        LOCAL_LOG(R"(    "created": %f,)", cookie.created);
+        LOCAL_LOG(R"(    "expires": %f,)", cookie.expires);
+        LOCAL_LOG(R"(    "httpOnly": %{public}s,)", cookie.httpOnly ? "true" : "false");
+        LOCAL_LOG(R"(    "secure": %{public}s,)", cookie.secure ? "true" : "false");
+        LOCAL_LOG(R"(    "session": %{public}s,)", cookie.session ? "true" : "false");
+        LOCAL_LOG(R"(    "comment": "%{public}s",)", escapedComment.utf8().data());
+        LOCAL_LOG(R"(    "commentURL": "%{public}s")", escapedCommentURL.utf8().data());
+        LOCAL_LOG(R"(  }%{public}s)", trailingComma);
+    }
+    LOCAL_LOG(R"(]})");
 #undef LOCAL_LOG
-    }
+#undef LOCAL_LOG_IF_ALLOWED
 }
 #endif
 

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h (228110 => 228111)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.h	2018-02-05 20:03:48 UTC (rev 228111)
@@ -36,6 +36,7 @@
 
 namespace WebCore {
 class BlobDataFileReference;
+class NetworkStorageSession;
 class ResourceRequest;
 }
 
@@ -103,6 +104,11 @@
     bool isMainResource() const { return m_parameters.request.requester() == WebCore::ResourceRequest::Requester::Main; }
     bool isAlwaysOnLoggingAllowed() const;
 
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
+    static bool shouldLogCookieInformation();
+    static void logCookieInformation(const String& label, const void* loggedObject, const WebCore::NetworkStorageSession&, const WebCore::URL& partition, const WebCore::URL&, const String& referrer, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, std::optional<uint64_t> identifier);
+#endif
+
 private:
     NetworkResourceLoader(const NetworkResourceLoadParameters&, NetworkConnectionToWebProcess&, RefPtr<Messages::NetworkConnectionToWebProcess::PerformSynchronousLoad::DelayedReply>&&);
 
@@ -135,7 +141,6 @@
     void invalidateSandboxExtensions();
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
-    bool shouldLogCookieInformation() const;
     void logCookieInformation() const;
 #endif
 

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (228110 => 228111)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2018-02-05 19:43:35 UTC (rev 228110)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2018-02-05 20:03:48 UTC (rev 228111)
@@ -198,12 +198,22 @@
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING)
     if (auto shouldBlockCookies = session.networkStorageSession().shouldBlockCookies(request)) {
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
+        if (NetworkProcess::singleton().shouldLogCookieInformation())
+            RELEASE_LOG_IF(m_session->sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - NetworkDataTaskCocoa::logCookieInformation: pageID = %llu, frameID = %llu, taskID = %lu: Blocking cookies for URL %s", this, pageID, frameID, (unsigned long)[m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
+#else
         LOG(NetworkSession, "%llu Blocking cookies for URL %s", [m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
+#endif
         applyCookieBlockingPolicy(shouldBlockCookies);
     } else {
         auto storagePartition = session.networkStorageSession().cookieStoragePartition(request, m_frameID, m_pageID);
         if (!storagePartition.isEmpty()) {
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
+            if (NetworkProcess::singleton().shouldLogCookieInformation())
+                RELEASE_LOG_IF(m_session->sessionID().isAlwaysOnLoggingAllowed(), Network, "%p - NetworkDataTaskCocoa::logCookieInformation: pageID = %llu, frameID = %llu, taskID = %lu: Partitioning cookies for URL %s", this, pageID, frameID, (unsigned long)[m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
+#else
             LOG(NetworkSession, "%llu Partitioning cookies for URL %s", [m_task taskIdentifier], nsRequest.URL.absoluteString.UTF8String);
+#endif
             applyCookiePartitioningPolicy(storagePartition, emptyString());
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to