Changeset 276983 in webkit


Ignore:
Timestamp:
May 4, 2021 2:32:05 PM (3 years ago)
Author:
achristensen@apple.com
Message:

localStorage changes aren't reflected between WKWebViews using WKWebViewConfiguration._groupIdentifier
https://bugs.webkit.org/show_bug.cgi?id=225344
<rdar://77496721>

Reviewed by Brady Eidson.

Source/WebKit:

When we switched from using _pageGroup to _groupIdentifier, we also broke localStorage by making a new pageGroupID for each WKWebView.
This is the low-risk solution to this problem that remembers what pageGroupID we used for this same identifier, creating the effect of
using the same StorageNamespaceIdentifier for each _groupIdentifier like we did when we used _pageGroup.
See the comment in StorageAreaMap::dispatchLocalStorageEvent.

The higher-risk solution that needs to be done but probably shouldn't be merged to a branch at this point is to remove StorageNamespaceIdentifier.
I plan to do that in a follow-up patch.

  • UIProcess/WebPageGroup.cpp:

(WebKit::pageGroupData):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:

(TEST):

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r276979 r276983  
     12021-05-04  Alex Christensen  <achristensen@webkit.org>
     2
     3        localStorage changes aren't reflected between WKWebViews using WKWebViewConfiguration._groupIdentifier
     4        https://bugs.webkit.org/show_bug.cgi?id=225344
     5        <rdar://77496721>
     6
     7        Reviewed by Brady Eidson.
     8
     9        When we switched from using _pageGroup to _groupIdentifier, we also broke localStorage by making a new pageGroupID for each WKWebView.
     10        This is the low-risk solution to this problem that remembers what pageGroupID we used for this same identifier, creating the effect of
     11        using the same StorageNamespaceIdentifier for each _groupIdentifier like we did when we used _pageGroup.
     12        See the comment in StorageAreaMap::dispatchLocalStorageEvent.
     13
     14        The higher-risk solution that needs to be done but probably shouldn't be merged to a branch at this point is to remove StorageNamespaceIdentifier.
     15        I plan to do that in a follow-up patch.
     16
     17        * UIProcess/WebPageGroup.cpp:
     18        (WebKit::pageGroupData):
     19
    1202021-05-04  Jer Noble  <jer.noble@apple.com>
    221
  • trunk/Source/WebKit/UIProcess/WebPageGroup.cpp

    r274117 r276983  
    7878    WebPageGroupData data;
    7979
    80     data.pageGroupID = generatePageGroupID();
     80    static NeverDestroyed<HashMap<String, uint64_t>> map;
     81    if (HashMap<String, uint64_t>::isValidKey(identifier)) {
     82        data.pageGroupID = map.get().ensure(identifier, [] {
     83            return generatePageGroupID();
     84        }).iterator->value;
     85    } else
     86        data.pageGroupID = generatePageGroupID();
    8187
    8288    if (!identifier.isEmpty())
  • trunk/Tools/ChangeLog

    r276970 r276983  
     12021-05-04  Alex Christensen  <achristensen@webkit.org>
     2
     3        localStorage changes aren't reflected between WKWebViews using WKWebViewConfiguration._groupIdentifier
     4        https://bugs.webkit.org/show_bug.cgi?id=225344
     5        <rdar://77496721>
     6
     7        Reviewed by Brady Eidson.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
     10        (TEST):
     11
    1122021-05-04  Aakash Jain  <aakash_jain@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm

    r267763 r276983  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import "TestNavigationDelegate.h"
     31#import "TestUIDelegate.h"
    3032#import <WebKit/WKProcessPoolPrivate.h>
    3133#import <WebKit/WKUserContentControllerPrivate.h>
     
    416418    finishedRunningScript = false;
    417419}
     420
     421TEST(WKWebView, LocalStorageGroup)
     422{
     423    auto runTest = [] (bool setGroupIdentifier) {
     424        auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     425        [configuration setWebsiteDataStore:[WKWebsiteDataStore nonPersistentDataStore]];
     426        if (setGroupIdentifier)
     427            [configuration _setGroupIdentifier:@"testgroupidentifier"];
     428        auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     429        NSString *html1 = @""
     430        "<script>"
     431        "localStorage.setItem('testkey', 'testvalue1');"
     432        "window.onstorage = function(e) { alert('storage changed key ' + e.key + ' value from ' + e.oldValue + ' to ' + e.newValue) };"
     433        "</script>";
     434        [webView1 loadHTMLString:html1 baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
     435        [webView1 _test_waitForDidFinishNavigation];
     436
     437        auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     438        NSString *html2 = @""
     439        "<script>"
     440        "alert('second web view got value ' + localStorage.getItem('testkey'));"
     441        "localStorage.setItem('testkey', 'testvalue2');"
     442        "</script>";
     443        [webView2 loadHTMLString:html2 baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
     444        EXPECT_WK_STREQ([webView2 _test_waitForAlert], "second web view got value testvalue1");
     445
     446        EXPECT_WK_STREQ([webView1 _test_waitForAlert], "storage changed key testkey value from testvalue1 to testvalue2");
     447    };
     448    runTest(true);
     449    runTest(false);
     450}
Note: See TracChangeset for help on using the changeset viewer.