Changeset 246449 in webkit


Ignore:
Timestamp:
Jun 14, 2019 4:05:31 PM (5 years ago)
Author:
youenn@apple.com
Message:

WebResourceLoadStatisticsStore should not use its network session if invalidated
https://bugs.webkit.org/show_bug.cgi?id=198814

Reviewed by Geoffrey Garen.

Source/WebKit:

Tell WebResourceLoadStatisticsStore that its network session is invalidated.
WebResourceLoadStatisticsStore will then clear its reference to the network session.

  • NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:

(WebKit::ResourceLoadStatisticsMemoryStore::updateCookieBlocking):
Added for test purposes to trigger further cookie processing.

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::invalidateAndCancel):

  • NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
  • NetworkProcess/NetworkSession.cpp:

(WebKit::NetworkSession::invalidateAndCancel):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:

(TEST):

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246448 r246449  
     12019-06-14  Youenn Fablet  <youenn@apple.com>
     2
     3        WebResourceLoadStatisticsStore should not use its network session if invalidated
     4        https://bugs.webkit.org/show_bug.cgi?id=198814
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Tell WebResourceLoadStatisticsStore that its network session is invalidated.
     9        WebResourceLoadStatisticsStore will then clear its reference to the network session.
     10
     11        * NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp:
     12        (WebKit::ResourceLoadStatisticsMemoryStore::updateCookieBlocking):
     13        Added for test purposes to trigger further cookie processing.
     14        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
     15        (WebKit::WebResourceLoadStatisticsStore::invalidateAndCancel):
     16        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h:
     17        * NetworkProcess/NetworkSession.cpp:
     18        (WebKit::NetworkSession::invalidateAndCancel):
     19
    1202019-06-14  Joseph Pecoraro  <pecoraro@apple.com>
    221
  • trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsMemoryStore.cpp

    r245796 r246449  
    759759    }
    760760
    761     if (domainsToBlock.isEmpty()) {
     761    if (domainsToBlock.isEmpty() && !debugModeEnabled()) {
    762762        completionHandler();
    763763        return;
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp

    r245868 r246449  
    10221022}
    10231023
     1024void WebResourceLoadStatisticsStore::invalidateAndCancel()
     1025{
     1026    m_networkSession = nullptr;
     1027}
     1028
    10241029void WebResourceLoadStatisticsStore::deleteWebsiteDataForRegistrableDomains(OptionSet<WebsiteDataType> dataTypes, HashMap<RegistrableDomain, WebsiteDataToRemove>&& domainsToRemoveWebsiteDataFor, bool shouldNotifyPage, CompletionHandler<void(const HashSet<RegistrableDomain>&)>&& completionHandler)
    10251030{
  • trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.h

    r245868 r246449  
    177177
    178178    NetworkSession* networkSession();
     179    void invalidateAndCancel();
    179180
    180181    void sendDiagnosticMessageWithValue(const String& message, const String& description, unsigned value, unsigned sigDigits, WebCore::ShouldSample) const;
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.cpp

    r246388 r246449  
    101101    for (auto* task : m_dataTaskSet)
    102102        task->invalidateAndCancel();
     103#if ENABLE(RESOURCE_LOAD_STATISTICS)
     104    if (m_resourceLoadStatistics)
     105        m_resourceLoadStatistics->invalidateAndCancel();
     106#endif
     107#if !ASSERT_DISABLED
     108    m_isInvalidated = true;
     109#endif
    103110}
    104111
     
    106113void NetworkSession::setResourceLoadStatisticsEnabled(bool enable)
    107114{
     115    ASSERT(!m_isInvalidated);
    108116    if (!enable) {
    109117        m_resourceLoadStatistics = nullptr;
  • trunk/Source/WebKit/NetworkProcess/NetworkSession.h

    r246388 r246449  
    128128
    129129    Ref<StorageManager> m_storageManager;
     130#if !ASSERT_DISABLED
     131    bool m_isInvalidated { false };
     132#endif
    130133};
    131134
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r246370 r246449  
    481481}
    482482
     483- (void)_scheduleCookieBlockingUpdate:(void (^)(void))completionHandler
     484{
     485#if ENABLE(RESOURCE_LOAD_STATISTICS)
     486    _websiteDataStore->websiteDataStore().scheduleCookieBlockingUpdate([completionHandler = makeBlockPtr(completionHandler)]() {
     487        completionHandler();
     488    });
     489#else
     490    completionHandler();
     491#endif
     492}
     493
    483494- (void)_setPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler
    484495{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r246360 r246449  
    6868- (bool)_hasRegisteredServiceWorker WK_API_AVAILABLE(macos(10.14), ios(12.0));
    6969
     70- (void)_scheduleCookieBlockingUpdate:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    7071- (void)_setPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    7172- (void)_getIsPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
  • trunk/Tools/ChangeLog

    r246434 r246449  
     12019-06-14  Youenn Fablet  <youenn@apple.com>
     2
     3        WebResourceLoadStatisticsStore should not use its network session if invalidated
     4        https://bugs.webkit.org/show_bug.cgi?id=198814
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
     9        (TEST):
     10
    1112019-06-14  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm

    r246360 r246449  
    2929#import "TestNavigationDelegate.h"
    3030#import <WebKit/WKFoundation.h>
     31#import <WebKit/WKPreferencesPrivate.h>
    3132#import <WebKit/WKProcessPoolPrivate.h>
    3233#import <WebKit/WKWebViewConfigurationPrivate.h>
    3334#import <WebKit/WKWebsiteDataRecordPrivate.h>
    3435#import <WebKit/WKWebsiteDataStorePrivate.h>
     36#import <WebKit/_WKWebsiteDataStoreConfiguration.h>
    3537#import <wtf/RetainPtr.h>
    3638
     
    282284}
    283285
     286TEST(ResourceLoadStatistics, RemoveSessionID)
     287{
     288    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     289    auto websiteDataStoreConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     290    configuration.get().websiteDataStore = [[[WKWebsiteDataStore alloc] _initWithConfiguration:websiteDataStoreConfiguration.get()] autorelease];
     291
     292    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     293
     294    // We load a resource so that the NetworkSession stays alive a little bit longer after the session is removed.
     295
     296    [webView loadHTMLString:@"<a id='link' href='http://webkit.org' download>Click me!</a>" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
     297    [webView _test_waitForDidFinishNavigation];
     298
     299    static bool doneFlag = false;
     300    [webView evaluateJavaScript:@"document.getElementById('link').click();" completionHandler: ^(id, NSError*) {
     301        doneFlag = true;
     302    }];
     303    TestWebKitAPI::Util::run(&doneFlag);
     304
     305    [configuration.get().websiteDataStore _setResourceLoadStatisticsEnabled:YES];
     306    [configuration.get().websiteDataStore _setResourceLoadStatisticsDebugMode:YES];
     307
     308    // Trigger ITP tasks.
     309    [configuration.get().websiteDataStore _scheduleCookieBlockingUpdate: ^(void) { }];
     310    // Trigger removing of the sessionID.
     311    TestWebKitAPI::Util::spinRunLoop(2);
     312    [webView _close];
     313    webView = nullptr;
     314    configuration = nullptr;
     315
     316    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     317    [webView2 loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
     318    [webView2 _test_waitForDidFinishNavigation];
     319}
Note: See TracChangeset for help on using the changeset viewer.