Bug 214905 - -[WKWebsiteDataStore _renameOrigin:] needs to support IndexedDB renames
Summary: -[WKWebsiteDataStore _renameOrigin:] needs to support IndexedDB renames
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit API (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sihui Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-07-28 18:11 PDT by Timothy Hatcher
Modified: 2020-07-31 10:44 PDT (History)
7 users (show)

See Also:


Attachments
Patch (16.36 KB, patch)
2020-07-30 14:06 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (15.60 KB, patch)
2020-07-30 14:07 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (15.40 KB, patch)
2020-07-30 14:44 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch for landing (15.16 KB, patch)
2020-07-31 10:07 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Hatcher 2020-07-28 18:11:28 PDT
For Web Extensions in Safari, we need to rename origins between launches. Right now we are using the -[WKWebsiteDataStore _renameOrigin:] SPI, but it only supports LocalStorage. We need to support IndexedDB as well.

See NetworkProcess::renameOriginInWebsiteData() for where the additional WebsiteDataType::IndexedDBDatabases type support needs added.
Comment 1 Radar WebKit Bug Importer 2020-07-28 18:11:40 PDT Comment hidden (obsolete)
Comment 2 Radar WebKit Bug Importer 2020-07-28 18:12:19 PDT Comment hidden (obsolete)
Comment 3 Timothy Hatcher 2020-07-28 18:12:32 PDT Comment hidden (obsolete)
Comment 4 Timothy Hatcher 2020-07-28 18:19:26 PDT
<rdar://problem/64790993>
Comment 5 Sihui Liu 2020-07-30 14:06:09 PDT
Created attachment 405614 [details]
Patch
Comment 6 Sihui Liu 2020-07-30 14:07:00 PDT
Created attachment 405615 [details]
Patch
Comment 7 Timothy Hatcher 2020-07-30 14:30:04 PDT
Comment on attachment 405615 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405615&action=review

> Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm:616
> +    auto filteredTypes = [dataTypes objectsPassingTest:^BOOL(id obj, BOOL *stop) {
> +        NSString *type = (NSString *)obj;
> +        NSSet *supportedTypes = [NSSet setWithObjects:WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, nil];
> +        return ![supportedTypes containsObject:type];
> +    }];
> +    if (filteredTypes.count) {

A better way to do this would be:

NSSet *supportedTypes = [NSSet setWithObjects:WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, nil];
if (![dataTypes isSubsetOfSet:supportedTypes])
    [NSException raise:...];

Calling the completion handler after the exception is not needed. The exception ended execution of the method.
Comment 8 Sihui Liu 2020-07-30 14:43:37 PDT
Comment on attachment 405615 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405615&action=review

>> Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm:616
>> +    if (filteredTypes.count) {
> 
> A better way to do this would be:
> 
> NSSet *supportedTypes = [NSSet setWithObjects:WKWebsiteDataTypeLocalStorage, WKWebsiteDataTypeIndexedDBDatabases, nil];
> if (![dataTypes isSubsetOfSet:supportedTypes])
>     [NSException raise:...];
> 
> Calling the completion handler after the exception is not needed. The exception ended execution of the method.

Will update!
Comment 9 Sihui Liu 2020-07-30 14:44:33 PDT
Created attachment 405623 [details]
Patch
Comment 10 Alex Christensen 2020-07-30 16:11:17 PDT
Comment on attachment 405623 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=405623&action=review

> Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:721
> +    renameOriginForVersion("v0");

Why would we want to rename v0?  The SPI user of this will only have v1, I think.

> Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:101
> +        postTaskReply(CrossThreadTask([callback = WTFMove(callback)]() mutable {

Could this be simpler instead of making a lambda just to wrap a CompletionHandler?
postTaskReply(CrossThreadTask(WTFMove(callback)));

> Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:561
> +    RetainPtr<WebsiteDataStoreCustomPathsMessageHandler> handler = adoptNS([[WebsiteDataStoreCustomPathsMessageHandler alloc] init]);

These could use auto.
Comment 11 Sihui Liu 2020-07-30 21:55:50 PDT
(In reply to Alex Christensen from comment #10)
> Comment on attachment 405623 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=405623&action=review
> 
> > Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:721
> > +    renameOriginForVersion("v0");
> 
> Why would we want to rename v0?  The SPI user of this will only have v1, I
> think.
> 

I have no idea about that so I rename both. Will update.

> > Source/WebKit/NetworkProcess/IndexedDB/WebIDBServer.cpp:101
> > +        postTaskReply(CrossThreadTask([callback = WTFMove(callback)]() mutable {
> 
> Could this be simpler instead of making a lambda just to wrap a
> CompletionHandler?
> postTaskReply(CrossThreadTask(WTFMove(callback)));
> 
Yes.

> > Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsiteDataStoreCustomPaths.mm:561
> > +    RetainPtr<WebsiteDataStoreCustomPathsMessageHandler> handler = adoptNS([[WebsiteDataStoreCustomPathsMessageHandler alloc] init]);
> 
> These could use auto.

Okay.
Comment 12 Sihui Liu 2020-07-31 10:07:07 PDT
Created attachment 405702 [details]
Patch for landing
Comment 13 EWS 2020-07-31 10:44:24 PDT
Committed r265149: <https://trac.webkit.org/changeset/265149>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 405702 [details].