Changeset 231524 in webkit


Ignore:
Timestamp:
May 8, 2018 4:59:29 PM (6 years ago)
Author:
wilander@apple.com
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:
Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r231521 r231524  
     12018-05-08  John Wilander  <wilander@apple.com>
     2
     3        Storage Access API: Make user opt-in sticky
     4        https://bugs.webkit.org/show_bug.cgi?id=185454
     5        <rdar://problem/40003946>
     6
     7        Reviewed by Alex Christensen.
     8
     9        This patch persists the user's choice to opt-in to access under specific domains.
     10        Such storage access should age out with the accessing domain's cookies and website
     11        data. The opt-in prompt is still an experimental feature.
     12
     13        * UIProcess/WebResourceLoadStatisticsStore.cpp:
     14        (WebKit::WebResourceLoadStatisticsStore::hasStorageAccess):
     15        (WebKit::WebResourceLoadStatisticsStore::requestStorageAccess):
     16        (WebKit::WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener):
     17        (WebKit::WebResourceLoadStatisticsStore::grantStorageAccess):
     18        (WebKit::WebResourceLoadStatisticsStore::grantStorageAccessInternal):
     19        (WebKit::WebResourceLoadStatisticsStore::hasUserGrantedStorageAccessThroughPrompt const):
     20        (WebKit::WebResourceLoadStatisticsStore::hasHadUnexpiredRecentUserInteraction const):
     21        * UIProcess/WebResourceLoadStatisticsStore.h:
     22
    1232018-05-08  Daniel Bates  <dabates@apple.com>
    224
  • trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp

    r231501 r231524  
    343343        auto& subFrameStatistic = ensureResourceStatisticsForPrimaryDomain(subFramePrimaryDomain);
    344344        if (shouldBlockCookies(subFrameStatistic)) {
    345             callback(false);
     345            RunLoop::main().dispatch([callback = WTFMove(callback)] {
     346                callback(false);
     347            });
    346348            return;
    347349        }
    348350
    349351        if (!shouldPartitionCookies(subFrameStatistic)) {
    350             callback(true);
     352            RunLoop::main().dispatch([callback = WTFMove(callback)] {
     353                callback(true);
     354            });
    351355            return;
    352356        }
    353357
    354         m_hasStorageAccessForFrameHandler(subFramePrimaryDomain, topFramePrimaryDomain, frameID, pageID, WTFMove(callback));
     358        m_hasStorageAccessForFrameHandler(subFramePrimaryDomain, topFramePrimaryDomain, frameID, pageID, [callback = WTFMove(callback)] (bool value) mutable {
     359            RunLoop::main().dispatch([callback = WTFMove(callback), value] () mutable {
     360                callback(value);
     361            });
     362        });
    355363    });
    356364}
     
    385393        }
    386394
    387         if (promptEnabled) {
     395        auto userWasPromptedEarlier = promptEnabled && hasUserGrantedStorageAccessThroughPrompt(subFrameStatistic, topFramePrimaryDomain);
     396        if (promptEnabled && !userWasPromptedEarlier) {
    388397            RunLoop::main().dispatch([callback = WTFMove(callback)] {
    389398                callback(StorageAccessStatus::RequiresUserPrompt);
     
    394403        subFrameStatistic.timesAccessedAsFirstPartyDueToStorageAccessAPI++;
    395404
    396         grantStorageAccessInternal(WTFMove(subFramePrimaryDomain), WTFMove(topFramePrimaryDomain), frameID, pageID, false, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
     405        grantStorageAccessInternal(WTFMove(subFramePrimaryDomain), WTFMove(topFramePrimaryDomain), frameID, pageID, userWasPromptedEarlier, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
    397406            RunLoop::main().dispatch([callback = WTFMove(callback), wasGrantedAccess] () mutable {
    398407                callback(wasGrantedAccess ? StorageAccessStatus::HasAccess : StorageAccessStatus::CannotRequestAccess);
     
    402411}
    403412
    404 void WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener(String&& domainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerDomain, bool isTriggeredByUserGesture)
    405 {
    406     ASSERT(domainInNeedOfStorageAccess != openerDomain);
    407     ASSERT(!RunLoop::isMain());
    408 
    409     if (domainInNeedOfStorageAccess == openerDomain)
    410         return;
    411 
    412     auto& domainInNeedOfStorageAccessStatistic = ensureResourceStatisticsForPrimaryDomain(domainInNeedOfStorageAccess);
     413void WebResourceLoadStatisticsStore::requestStorageAccessUnderOpener(String&& primaryDomainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerPrimaryDomain, bool isTriggeredByUserGesture)
     414{
     415    ASSERT(primaryDomainInNeedOfStorageAccess != openerPrimaryDomain);
     416    ASSERT(!RunLoop::isMain());
     417
     418    if (primaryDomainInNeedOfStorageAccess == openerPrimaryDomain)
     419        return;
     420
     421    auto& domainInNeedOfStorageAccessStatistic = ensureResourceStatisticsForPrimaryDomain(primaryDomainInNeedOfStorageAccess);
    413422    auto cookiesBlocked = shouldBlockCookies(domainInNeedOfStorageAccessStatistic);
    414423
     
    421430        return;
    422431
    423     grantStorageAccessInternal(WTFMove(domainInNeedOfStorageAccess), WTFMove(openerDomain), std::nullopt, openerPageID, false, [](bool) { });
    424432#if !RELEASE_LOG_DISABLED
    425     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"));
     433    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"));
    426434#endif
    427 }
    428 
    429 void WebResourceLoadStatisticsStore::grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&& callback)
     435    grantStorageAccessInternal(WTFMove(primaryDomainInNeedOfStorageAccess), WTFMove(openerPrimaryDomain), std::nullopt, openerPageID, false, [](bool) { });
     436}
     437
     438void WebResourceLoadStatisticsStore::grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPromptedNow, CompletionHandler<void(bool)>&& callback)
    430439{
    431440    ASSERT(RunLoop::isMain());
    432     m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), subFrameHost = crossThreadCopy(subFrameHost), topFrameHost = crossThreadCopy(topFrameHost), frameID, pageID, userWasPrompted, callback = WTFMove(callback)] () mutable {
    433         grantStorageAccessInternal(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, userWasPrompted, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
     441    m_statisticsQueue->dispatch([this, protectedThis = makeRef(*this), subFrameHost = crossThreadCopy(subFrameHost), topFrameHost = crossThreadCopy(topFrameHost), frameID, pageID, userWasPromptedNow, callback = WTFMove(callback)] () mutable {
     442        auto subFramePrimaryDomain = isolatedPrimaryDomain(subFrameHost);
     443        auto topFramePrimaryDomain = isolatedPrimaryDomain(topFrameHost);
     444        if (userWasPromptedNow) {
     445            auto& subFrameStatistic = ensureResourceStatisticsForPrimaryDomain(subFramePrimaryDomain);
     446            ASSERT(subFrameStatistic.hadUserInteraction);
     447            subFrameStatistic.storageAccessUnderTopFrameOrigins.add(topFramePrimaryDomain);
     448        }
     449        grantStorageAccessInternal(WTFMove(subFrameHost), WTFMove(topFrameHost), frameID, pageID, userWasPromptedNow, [callback = WTFMove(callback)] (bool wasGrantedAccess) mutable {
    434450            RunLoop::main().dispatch([callback = WTFMove(callback), wasGrantedAccess] () mutable {
    435451                callback(wasGrantedAccess);
     
    439455}
    440456
    441 void WebResourceLoadStatisticsStore::grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&& callback)
    442 {
    443     ASSERT(!RunLoop::isMain());
    444     auto subFramePrimaryDomain = isolatedPrimaryDomain(subFrameHost);
    445     auto topFramePrimaryDomain = isolatedPrimaryDomain(topFrameHost);
     457void WebResourceLoadStatisticsStore::grantStorageAccessInternal(String&& subFramePrimaryDomain, String&& topFramePrimaryDomain, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPromptedNowOrEarlier, CompletionHandler<void(bool)>&& callback)
     458{
     459    UNUSED_PARAM(userWasPromptedNowOrEarlier);
     460    ASSERT(!RunLoop::isMain());
     461
    446462    if (subFramePrimaryDomain == topFramePrimaryDomain) {
    447463        callback(true);
    448464        return;
    449465    }
    450    
     466
    451467    m_grantStorageAccessHandler(subFramePrimaryDomain, topFramePrimaryDomain, frameID, pageID, WTFMove(callback));
    452468}
     
    10461062}
    10471063
     1064bool WebResourceLoadStatisticsStore::hasUserGrantedStorageAccessThroughPrompt(const ResourceLoadStatistics& statistic, const String& firstPartyPrimaryDomain) const
     1065{
     1066    return statistic.storageAccessUnderTopFrameOrigins.contains(firstPartyPrimaryDomain);
     1067}
     1068
    10481069void WebResourceLoadStatisticsStore::updateCookiePartitioning(CompletionHandler<void()>&& callback)
    10491070{
     
    11941215        // it has been reset as opposed to its default -1.
    11951216        resourceStatistic.mostRecentUserInteractionTime = { };
     1217        resourceStatistic.storageAccessUnderTopFrameOrigins.clear();
    11961218        resourceStatistic.hadUserInteraction = false;
    11971219    }
  • trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h

    r231501 r231524  
    9292    void hasStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, WTF::CompletionHandler<void (bool)>&& callback);
    9393    void requestStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool promptEnabled, CompletionHandler<void(StorageAccessStatus)>&&);
    94     void requestStorageAccessUnderOpener(String&& domainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerDomain, bool isTriggeredByUserGesture);
    95     void grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&&);
     94    void requestStorageAccessUnderOpener(String&& primaryDomainInNeedOfStorageAccess, uint64_t openerPageID, String&& openerPrimaryDomain, bool isTriggeredByUserGesture);
     95    void grantStorageAccess(String&& subFrameHost, String&& topFrameHost, uint64_t frameID, uint64_t pageID, bool userWasPromptedNow, CompletionHandler<void(bool)>&&);
    9696    void requestStorageAccessCallback(bool wasGranted, uint64_t contextId);
    9797
     
    172172    bool shouldPartitionCookies(const WebCore::ResourceLoadStatistics&) const;
    173173    bool shouldBlockCookies(const WebCore::ResourceLoadStatistics&) const;
     174    bool hasUserGrantedStorageAccessThroughPrompt(const WebCore::ResourceLoadStatistics&, const String& firstPartyPrimaryDomain) const;
    174175    bool hasStatisticsExpired(const WebCore::ResourceLoadStatistics&) const;
    175176    bool hasHadUnexpiredRecentUserInteraction(WebCore::ResourceLoadStatistics&) const;
     
    186187
    187188    void resetCookiePartitioningState();
    188     void grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPrompted, CompletionHandler<void(bool)>&&);
     189    StorageAccessStatus storageAccessStatus(const String& subFramePrimaryDomain, const String& topFramePrimaryDomain);
     190    void grantStorageAccessInternal(String&& subFrameHost, String&& topFrameHost, std::optional<uint64_t> frameID, uint64_t pageID, bool userWasPromptedNowOrEarlier, CompletionHandler<void(bool)>&&);
    189191    void removeAllStorageAccess();
    190192
Note: See TracChangeset for help on using the changeset viewer.