Title: [277190] branches/safari-611-branch
Revision
277190
Author
repst...@apple.com
Date
2021-05-07 11:48:25 -0700 (Fri, 07 May 2021)

Log Message

Cherry-pick r276983. rdar://problem/77581150

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276983 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-611-branch/Source/WebKit/ChangeLog (277189 => 277190)


--- branches/safari-611-branch/Source/WebKit/ChangeLog	2021-05-07 18:48:21 UTC (rev 277189)
+++ branches/safari-611-branch/Source/WebKit/ChangeLog	2021-05-07 18:48:25 UTC (rev 277190)
@@ -1,5 +1,56 @@
 2021-05-06  Russell Epstein  <repst...@apple.com>
 
+        Cherry-pick r276983. rdar://problem/77581150
+
+    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):
+    
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276983 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-05-04  Alex Christensen  <achristen...@webkit.org>
+
+            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.
+
+            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):
+
+2021-05-06  Russell Epstein  <repst...@apple.com>
+
         Cherry-pick r277114. rdar://problem/77638135
 
     Fix crash when WebsiteDataStore is destroyed with outstanding getNetworkProcessConnection request

Modified: branches/safari-611-branch/Source/WebKit/UIProcess/WebPageGroup.cpp (277189 => 277190)


--- branches/safari-611-branch/Source/WebKit/UIProcess/WebPageGroup.cpp	2021-05-07 18:48:21 UTC (rev 277189)
+++ branches/safari-611-branch/Source/WebKit/UIProcess/WebPageGroup.cpp	2021-05-07 18:48:25 UTC (rev 277190)
@@ -68,7 +68,13 @@
 {
     WebPageGroupData data;
 
-    data.pageGroupID = generatePageGroupID();
+    static NeverDestroyed<HashMap<String, uint64_t>> map;
+    if (HashMap<String, uint64_t>::isValidKey(identifier)) {
+        data.pageGroupID = map.get().ensure(identifier, [] {
+            return generatePageGroupID();
+        }).iterator->value;
+    } else
+        data.pageGroupID = generatePageGroupID();
 
     if (!identifier.isEmpty())
         data.identifier = identifier;

Modified: branches/safari-611-branch/Tools/ChangeLog (277189 => 277190)


--- branches/safari-611-branch/Tools/ChangeLog	2021-05-07 18:48:21 UTC (rev 277189)
+++ branches/safari-611-branch/Tools/ChangeLog	2021-05-07 18:48:25 UTC (rev 277190)
@@ -1,3 +1,46 @@
+2021-05-06  Russell Epstein  <repst...@apple.com>
+
+        Cherry-pick r276983. rdar://problem/77581150
+
+    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):
+    
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276983 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-05-04  Alex Christensen  <achristen...@webkit.org>
+
+            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.
+
+            * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
+            (TEST):
+
 2021-04-21  Ruben Turcios  <rubent...@apple.com>
 
         Cherry-pick r276193. rdar://problem/76962916

Modified: branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm (277189 => 277190)


--- branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm	2021-05-07 18:48:21 UTC (rev 277189)
+++ branches/safari-611-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm	2021-05-07 18:48:25 UTC (rev 277190)
@@ -27,6 +27,8 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
+#import "TestUIDelegate.h"
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
@@ -415,3 +417,34 @@
     TestWebKitAPI::Util::run(&finishedRunningScript);
     finishedRunningScript = false;
 }
+
+TEST(WKWebView, LocalStorageGroup)
+{
+    auto runTest = [] (bool setGroupIdentifier) {
+        auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+        [configuration setWebsiteDataStore:[WKWebsiteDataStore nonPersistentDataStore]];
+        if (setGroupIdentifier)
+            [configuration _setGroupIdentifier:@"testgroupidentifier"];
+        auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+        NSString *html1 = @""
+        "<script>"
+        "localStorage.setItem('testkey', 'testvalue1');"
+        "window._onstorage_ = function(e) { alert('storage changed key ' + e.key + ' value from ' + e.oldValue + ' to ' + e.newValue) };"
+        "</script>";
+        [webView1 loadHTMLString:html1 baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+        [webView1 _test_waitForDidFinishNavigation];
+
+        auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+        NSString *html2 = @""
+        "<script>"
+        "alert('second web view got value ' + localStorage.getItem('testkey'));"
+        "localStorage.setItem('testkey', 'testvalue2');"
+        "</script>";
+        [webView2 loadHTMLString:html2 baseURL:[NSURL URLWithString:@"https://webkit.org/"]];
+        EXPECT_WK_STREQ([webView2 _test_waitForAlert], "second web view got value testvalue1");
+
+        EXPECT_WK_STREQ([webView1 _test_waitForAlert], "storage changed key testkey value from testvalue1 to testvalue2");
+    };
+    runTest(true);
+    runTest(false);
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to