Title: [231524] trunk/Source/WebKit
Revision
231524
Author
[email protected]
Date
2018-05-08 16:59:29 -0700 (Tue, 08 May 2018)

Log Message

Storage Access API: Make user opt-in sticky
https://bugs.webkit.org/show_bug.cgi?id=185454
<rdar://problem/40003946>

Reviewed by Alex Christensen.

This patch persists the user's choice to opt-in to access under specific domains.
Such storage access should age out with the accessing domain's cookies and website
data. The opt-in prompt is still an experimental feature.

* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::hasStorageAccess):
(WebKit::WebResourceLoadStatisticsStore::requestStorageAccess):
(WebKit::WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener):
(WebKit::WebResourceLoadStatisticsStore::grantStorageAccess):
(WebKit::WebResourceLoadStatisticsStore::grantStorageAccessInternal):
(WebKit::WebResourceLoadStatisticsStore::hasUserGrantedStorageAccessThroughPrompt const):
(WebKit::WebResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction const):
* UIProcess/WebResourceLoadStatisticsStore.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (231523 => 231524)


--- trunk/Source/WebKit/ChangeLog	2018-05-08 23:33:13 UTC (rev 231523)
+++ trunk/Source/WebKit/ChangeLog	2018-05-08 23:59:29 UTC (rev 231524)
@@ -1,3 +1,25 @@
+2018-05-08  John Wilander  <[email protected]>
+
+        Storage Access API: Make user opt-in sticky
+        https://bugs.webkit.org/show_bug.cgi?id=185454
+        <rdar://problem/40003946>
+
+        Reviewed by Alex Christensen.
+
+        This patch persists the user's choice to opt-in to access under specific domains.
+        Such storage access should age out with the accessing domain's cookies and website
+        data. The opt-in prompt is still an experimental feature.
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::hasStorageAccess):
+        (WebKit::WebResourceLoadStatisticsStore::requestStorageAccess):
+        (WebKit::WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener):
+        (WebKit::WebResourceLoadStatisticsStore::grantStorageAccess):
+        (WebKit::WebResourceLoadStatisticsStore::grantStorageAccessInternal):
+        (WebKit::WebResourceLoadStatisticsStore::hasUserGrantedStorageAccessThroughPrompt const):
+        (WebKit::WebResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction const):
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+
 2018-05-08  Daniel Bates  <[email protected]>
 
         Do not apply X-Frame-Options and CSP frame-ancestors to Quick Look-applicable responses in NetworkProcess

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp (231523 => 231524)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-05-08 23:33:13 UTC (rev 231523)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-05-08 23:59:29 UTC (rev 231524)
@@ -342,16 +342,24 @@
         
         auto& subFrameStatistic = ensureResourceStatisticsForPrimaryDomain(subFramePrimaryDomain);
         if (shouldBlockCookies(subFrameStatistic)) {
-            callback(false);
+            RunLoop::main().dispatch([callback = WTFMove(callback)] {
+                callback(false);
+            });
             return;
         }
 
         if (!shouldPartitionCookies(subFrameStatistic)) {
-            callback(true);
+            RunLoop::main().dispatch([callback = WTFMove(callback)] {
+                callback(true);
+            });
             return;
         }
 
-        m_hasStorageAccessForFrameHandler(subFramePrimaryDomain, topFramePrimaryDomain, frameID, pageID, WTFMove(callback));
+        m_hasStorageAccessForFrameHandler(subFramePrimaryDomain, topFramePrimaryDomain, frameID, pageID, [callback = WTFMove(callback)] (bool value) mutable {
+            RunLoop::main().dispatch([callback = WTFMove(callback), value] () mutable {
+                callback(value);
+            });
+        });
     });
 }
 
@@ -384,7 +392,8 @@
             return;
         }
 
-        if (promptEnabled) {
+        auto userWasPromptedEarlier = promptEnabled && hasUserGrantedStorageAccessThroughPrompt(subFrameStatistic, topFramePrimaryDomain);
+        if (promptEnabled && !userWasPromptedEarlier) {
             RunLoop::main().dispatch([callback = WTFMove(callback)] {
                 callback(StorageAccessStatus::RequiresUserPrompt);
             });
@@ -393,7 +402,7 @@
 
         subFrameStatistic.timesAccessedAsFirstPartyDueToStorageAccessAPI++;
 
-        grantStorageAccessInternal(WTFMove(subFramePrimaryDomain), WTFMove(topFramePrimaryDomain), frameID, pageID, false, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
+        grantStorageAccessInternal(WTFMove(subFramePrimaryDomain), WTFMove(topFramePrimaryDomain), frameID, pageID, userWasPromptedEarlier, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
             RunLoop::main().dispatch([callback = WTFMove(callback), wasGrantedAccess] () mutable {
                 callback(wasGrantedAccess ? StorageAccessStatus::HasAccess : StorageAccessStatus::CannotRequestAccess);
             });
@@ -401,15 +410,15 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener(String&& domainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerDomain, bool isTriggeredByUserGesture)
+void WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener(String&& primaryDomainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerPrimaryDomain, bool isTriggeredByUserGesture)
 {
-    ASSERT(domainInNeedOfStorageAccess != openerDomain);
+    ASSERT(primaryDomainInNeedOfStorageAccess != openerPrimaryDomain);
     ASSERT(!RunLoop::isMain());
 
-    if (domainInNeedOfStorageAccess == openerDomain)
+    if (primaryDomainInNeedOfStorageAccess == openerPrimaryDomain)
         return;
 
-    auto& domainInNeedOfStorageAccessStatistic = ensureResourceStatisticsForPrimaryDomain(domainInNeedOfStorageAccess);
+    auto& domainInNeedOfStorageAccessStatistic = ensureResourceStatisticsForPrimaryDomain(primaryDomainInNeedOfStorageAccess);
     auto cookiesBlocked = shouldBlockCookies(domainInNeedOfStorageAccessStatistic);
 
     // There are no cookies to get access to if the domain has its cookies blocked and did not get user interaction now.
@@ -420,17 +429,24 @@
     if (!cookiesBlocked && !shouldPartitionCookies(domainInNeedOfStorageAccessStatistic))
         return;
 
-    grantStorageAccessInternal(WTFMove(domainInNeedOfStorageAccess), WTFMove(openerDomain), std::nullopt, openerPageID, false, [](bool) { });
 #if !RELEASE_LOG_DISABLED
-    RELEASE_LOG_INFO_IF(m_debugLoggingEnabled, ResourceLoadStatisticsDebug, "Grant storage access for %{public}s under opener %{public}s, %{public}s user interaction.", domainInNeedOfStorageAccess.utf8().data(), openerDomain.utf8().data(), (isTriggeredByUserGesture ? "with" : "without"));
+    RELEASE_LOG_INFO_IF(m_debugLoggingEnabled, ResourceLoadStatisticsDebug, "Grant storage access for %{public}s under opener %{public}s, %{public}s user interaction.", primaryDomainInNeedOfStorageAccess.utf8().data(), openerPrimaryDomain.utf8().data(), (isTriggeredByUserGesture ? "with" : "without"));
 #endif
+    grantStorageAccessInternal(WTFMove(primaryDomainInNeedOfStorageAccess), WTFMove(openerPrimaryDomain), std::nullopt, openerPageID, false, [](bool) { });
 }
 
-void WebResourceLoadStatisticsStore::grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&& callback)
+void WebResourceLoadStatisticsStore::grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPromptedNow, CompletionHandler<void(bool)>&& callback)
 {
     ASSERT(RunLoop::isMain());
-    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), subFrameHost = crossThreadCopy(subFrameHost), topFrameHost = crossThreadCopy(topFrameHost), frameID, pageID, userWasPrompted, callback = WTFMove(callback)] () mutable {
-        grantStorageAccessInternal(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, userWasPrompted, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
+    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), subFrameHost = crossThreadCopy(subFrameHost), topFrameHost = crossThreadCopy(topFrameHost), frameID, pageID, userWasPromptedNow, callback = WTFMove(callback)] () mutable {
+        auto subFramePrimaryDomain = isolatedPrimaryDomain(subFrameHost);
+        auto topFramePrimaryDomain = isolatedPrimaryDomain(topFrameHost);
+        if (userWasPromptedNow) {
+            auto& subFrameStatistic = ensureResourceStatisticsForPrimaryDomain(subFramePrimaryDomain);
+            ASSERT(subFrameStatistic.hadUserInteraction);
+            subFrameStatistic.storageAccessUnderTopFrameOrigins.add(topFramePrimaryDomain);
+        }
+        grantStorageAccessInternal(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, userWasPromptedNow, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
             RunLoop::main().dispatch([callback = WTFMove(callback), wasGrantedAccess] () mutable {
                 callback(wasGrantedAccess);
             });
@@ -438,16 +454,16 @@
     });
 }
 
-void WebResourceLoadStatisticsStore::grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&& callback)
+void WebResourceLoadStatisticsStore::grantStorageAccessInternal(String&& subFramePrimaryDomain, String&& topFramePrimaryDomain, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPromptedNowOrEarlier, CompletionHandler<void(bool)>&& callback)
 {
+    UNUSED_PARAM(userWasPromptedNowOrEarlier);
     ASSERT(!RunLoop::isMain());
-    auto subFramePrimaryDomain = isolatedPrimaryDomain(subFrameHost);
-    auto topFramePrimaryDomain = isolatedPrimaryDomain(topFrameHost);
+
     if (subFramePrimaryDomain == topFramePrimaryDomain) {
         callback(true);
         return;
     }
-    
+
     m_grantStorageAccessHandler(subFramePrimaryDomain, topFramePrimaryDomain, frameID, pageID, WTFMove(callback));
 }
 
@@ -1045,6 +1061,11 @@
     return statistic.isPrevalentResource && !statistic.hadUserInteraction;
 }
 
+bool WebResourceLoadStatisticsStore::hasUserGrantedStorageAccessThroughPrompt(const ResourceLoadStatistics& statistic, const String& firstPartyPrimaryDomain) const
+{
+    return statistic.storageAccessUnderTopFrameOrigins.contains(firstPartyPrimaryDomain);
+}
+
 void WebResourceLoadStatisticsStore::updateCookiePartitioning(CompletionHandler<void()>&& callback)
 {
     ASSERT(!RunLoop::isMain());
@@ -1193,6 +1214,7 @@
         // Set timestamp to 0 so that statistics merge will know
         // it has been reset as opposed to its default -1.
         resourceStatistic.mostRecentUserInteractionTime = { };
+        resourceStatistic.storageAccessUnderTopFrameOrigins.clear();
         resourceStatistic.hadUserInteraction = false;
     }
 

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h (231523 => 231524)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-05-08 23:33:13 UTC (rev 231523)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h	2018-05-08 23:59:29 UTC (rev 231524)
@@ -91,8 +91,8 @@
 
     void hasStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback);
     void requestStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool promptEnabled, CompletionHandler<void(StorageAccessStatus)>&&);
-    void requestStorageAccessUnderOpener(String&& domainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerDomain, bool isTriggeredByUserGesture);
-    void grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&&);
+    void requestStorageAccessUnderOpener(String&& primaryDomainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerPrimaryDomain, bool isTriggeredByUserGesture);
+    void grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPromptedNow, CompletionHandler<void(bool)>&&);
     void requestStorageAccessCallback(bool wasGranted, uint64_t contextId);
 
     void processWillOpenConnection(WebProcessProxy&, IPC::Connection&);
@@ -171,6 +171,7 @@
 
     bool shouldPartitionCookies(const WebCore::ResourceLoadStatistics&) const;
     bool shouldBlockCookies(const WebCore::ResourceLoadStatistics&) const;
+    bool hasUserGrantedStorageAccessThroughPrompt(const WebCore::ResourceLoadStatistics&, const String& firstPartyPrimaryDomain) const;
     bool hasStatisticsExpired(const WebCore::ResourceLoadStatistics&) const;
     bool hasHadUnexpiredRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
     void includeTodayAsOperatingDateIfNecessary();
@@ -185,7 +186,8 @@
     void processStatisticsAndDataRecords();
 
     void resetCookiePartitioningState();
-    void grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&&);
+    StorageAccessStatus storageAccessStatus(const String& subFramePrimaryDomain, const String& topFramePrimaryDomain);
+    void grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPromptedNowOrEarlier, CompletionHandler<void(bool)>&&);
     void removeAllStorageAccess();
 
     void setDebugLogggingEnabled(bool enabled) { m_debugLoggingEnabled  = enabled; }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to