Bug 195866 - Add default prompt implementation for Storage Access API
Summary: Add default prompt implementation for Storage Access API
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
: 195424 (view as bug list)
Depends on:
Blocks: 195957
  Show dependency treegraph
 
Reported: 2019-03-17 16:17 PDT by Brent Fulgham
Modified: 2019-03-20 19:32 PDT (History)
9 users (show)

See Also:


Attachments
Patch (7.84 KB, patch)
2019-03-17 16:24 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews115 for mac-highsierra (2.28 MB, application/zip)
2019-03-17 18:11 PDT, EWS Watchlist
no flags Details
Patch (10.88 KB, patch)
2019-03-18 11:00 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (10.88 KB, patch)
2019-03-18 15:02 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (10.90 KB, patch)
2019-03-18 21:24 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (11.09 KB, patch)
2019-03-19 11:32 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-highsierra-wk2 (3.20 MB, application/zip)
2019-03-19 12:43 PDT, EWS Watchlist
no flags Details
Patch (19.83 KB, patch)
2019-03-19 14:27 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2019-03-17 16:17:55 PDT
This patch provides a default storage access API prompt at the WebKit level, rather than relying on a custom version in the WebKit embedder.
Comment 1 Brent Fulgham 2019-03-17 16:19:47 PDT
<rdar://problem/45150009>
Comment 2 Brent Fulgham 2019-03-17 16:24:47 PDT
Created attachment 364982 [details]
Patch
Comment 3 EWS Watchlist 2019-03-17 18:11:15 PDT
Comment on attachment 364982 [details]
Patch

Attachment 364982 [details] did not pass mac-debug-ews (mac):
Output: https://webkit-queues.webkit.org/results/11544704

New failing tests:
jquery/offset.html
Comment 4 EWS Watchlist 2019-03-17 18:11:17 PDT
Created attachment 364991 [details]
Archive of layout-test-results from ews115 for mac-highsierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews115  Port: mac-highsierra  Platform: Mac OS X 10.13.6
Comment 5 Brent Fulgham 2019-03-18 11:00:46 PDT
Created attachment 365032 [details]
Patch
Comment 6 Brent Fulgham 2019-03-18 15:02:15 PDT
Created attachment 365071 [details]
Patch
Comment 7 Brent Fulgham 2019-03-18 21:24:26 PDT
Created attachment 365121 [details]
Patch
Comment 8 John Wilander 2019-03-19 10:53:26 PDT
Comment on attachment 365121 [details]
Patch

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

> Source/WebCore/ChangeLog:3
> +        Add default prompt implementation for Storage Access API

Since you used to ask me, I'll do the same – please add a "the." :)

> Source/WebKit/ChangeLog:3
> +        Add default prompt implementation for Storage Access API

Ditto.

> Source/WebCore/en.lproj/Localizable.strings:106
> +/* Allow Storage Access API */

This sounds like allowing the API. Could "for the" help here? Or reverse it to "Storage Access API allow access" to match the comment for the deny case further down.

> Source/WebCore/en.lproj/Localizable.strings:109
> +/* Title for Allow button label in Storage Access API request dialog */

the Storage Access API …

> Source/WebCore/en.lproj/Localizable.strings:262
> +/* Title for Don't Allow button label in Storage Access API request dialog */

the

> Source/WebCore/en.lproj/Localizable.strings:263
> +"Donât Allow (cross-site cookie and website data access)" = "Donât Allow";

I assume it's just Bugzilla messing up the apostrophe character.

> Source/WebKit/UIProcess/Cocoa/UIDelegate.h:90
> +        void presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);

Could WebCore::RegistrableDomain be used here?

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:339
> +void UIDelegate::UIClient::presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)

We should use WebCore::RegistrableDomain here, if at all possible.

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:342
> +    NSString *alertMessageString = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Do you want to allow â%@â to use cookies and website data while browsing â%@â?", @"Message for requesting cross-site cookie and website data access."), requestingDomain.createCFString().get(), currentDomain.createCFString().get()];

I saw the labels and strings went into some localized infrastructure. So these will be localized, right?

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:343
> +    NSString *informativeText = [NSString stringWithFormat:WEB_UI_NSSTRING(@"This will allow â%@â to track your activity.", @"Informative text for requesting cross-site cookie and website data access."), requestingDomain.createCFString().get()];

I'm no expert on CF APIs but I know we use adoptCF() in cpp files. Not the case in mm? I see instances where we use RetainPtr<CFStringRef>.

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:353
> +        bool shouldAllow = returnCode == NSAlertFirstButtonReturn;

auto?

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:382
> +    [alert addAction:allowAction];

Is either of these are highlighted as the default action?

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:396
> +    if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {

Maybe not part of this patch, but we should change the name of this method to webViewRequestStorageAccessPanelForRegistrableDomainUnderFirstPartyRegistrableDomainCompletionHandler.
Comment 9 Chris Dumez 2019-03-19 10:57:53 PDT
Comment on attachment 365121 [details]
Patch

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

>> Source/WebCore/en.lproj/Localizable.strings:263
>> +"Donât Allow (cross-site cookie and website data access)" = "Donât Allow";
> 
> I assume it's just Bugzilla messing up the apostrophe character.

It would not if it were a regular ascii apostrophe. This must be some kind of unicode one. I'd suggest switching to the ascii '
Comment 10 Chris Dumez 2019-03-19 10:58:21 PDT
Comment on attachment 365121 [details]
Patch

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

> Source/WebCore/en.lproj/Localizable.strings:821
> +"This will allow â%@â to track your activity." = "This will allow â%@â to track your activity.";

ditto: %@â
Comment 11 Brent Fulgham 2019-03-19 11:26:50 PDT
Comment on attachment 365121 [details]
Patch

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

>> Source/WebCore/ChangeLog:3
>> +        Add default prompt implementation for Storage Access API
> 
> Since you used to ask me, I'll do the same – please add a "the." :)

Done.

>> Source/WebKit/ChangeLog:3
>> +        Add default prompt implementation for Storage Access API
> 
> Ditto.

Done.

>> Source/WebCore/en.lproj/Localizable.strings:109
>> +/* Title for Allow button label in Storage Access API request dialog */
> 
> the Storage Access API …

Done.

>> Source/WebCore/en.lproj/Localizable.strings:262
>> +/* Title for Don't Allow button label in Storage Access API request dialog */
> 
> the

Done.

>>> Source/WebCore/en.lproj/Localizable.strings:263
>>> +"Donât Allow (cross-site cookie and website data access)" = "Donât Allow";
>> 
>> I assume it's just Bugzilla messing up the apostrophe character.
> 
> It would not if it were a regular ascii apostrophe. This must be some kind of unicode one. I'd suggest switching to the ascii '

Done.

>> Source/WebCore/en.lproj/Localizable.strings:821
>> +"This will allow â%@â to track your activity." = "This will allow â%@â to track your activity.";
> 
> ditto: %@â

Okay. I made the same change on line 257.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.h:90
>> +        void presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
> 
> Could WebCore::RegistrableDomain be used here?

Sounds like a great follow-up fix. We would need to thread RegistrableDomain through several layers, which I don't want to do in this patch. (See new Bug 195957).

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:339
>> +void UIDelegate::UIClient::presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
> 
> We should use WebCore::RegistrableDomain here, if at all possible.

Filed 195957 to do so.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:342
>> +    NSString *alertMessageString = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Do you want to allow â%@â to use cookies and website data while browsing â%@â?", @"Message for requesting cross-site cookie and website data access."), requestingDomain.createCFString().get(), currentDomain.createCFString().get()];
> 
> I saw the labels and strings went into some localized infrastructure. So these will be localized, right?

Right.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:353
>> +        bool shouldAllow = returnCode == NSAlertFirstButtonReturn;
> 
> auto?

Sure!

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:382
>> +    [alert addAction:allowAction];
> 
> Is either of these are highlighted as the default action?

Yes. Allow, just like in Safari.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:396
>> +    if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {
> 
> Maybe not part of this patch, but we should change the name of this method to webViewRequestStorageAccessPanelForRegistrableDomainUnderFirstPartyRegistrableDomainCompletionHandler.

We should definitely change the name, but preferably to something shorter!
Comment 12 John Wilander 2019-03-19 11:30:09 PDT
(In reply to Brent Fulgham from comment #11)
> Comment on attachment 365121 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=365121&action=review
> 
> >> Source/WebCore/ChangeLog:3
> >> +        Add default prompt implementation for Storage Access API
> > 
> > Since you used to ask me, I'll do the same – please add a "the." :)
> 
> Done.
> 
> >> Source/WebKit/ChangeLog:3
> >> +        Add default prompt implementation for Storage Access API
> > 
> > Ditto.
> 
> Done.
> 
> >> Source/WebCore/en.lproj/Localizable.strings:109
> >> +/* Title for Allow button label in Storage Access API request dialog */
> > 
> > the Storage Access API …
> 
> Done.
> 
> >> Source/WebCore/en.lproj/Localizable.strings:262
> >> +/* Title for Don't Allow button label in Storage Access API request dialog */
> > 
> > the
> 
> Done.
> 
> >>> Source/WebCore/en.lproj/Localizable.strings:263
> >>> +"Donât Allow (cross-site cookie and website data access)" = "Donât Allow";
> >> 
> >> I assume it's just Bugzilla messing up the apostrophe character.
> > 
> > It would not if it were a regular ascii apostrophe. This must be some kind of unicode one. I'd suggest switching to the ascii '
> 
> Done.
> 
> >> Source/WebCore/en.lproj/Localizable.strings:821
> >> +"This will allow â%@â to track your activity." = "This will allow â%@â to track your activity.";
> > 
> > ditto: %@â
> 
> Okay. I made the same change on line 257.
> 
> >> Source/WebKit/UIProcess/Cocoa/UIDelegate.h:90
> >> +        void presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
> > 
> > Could WebCore::RegistrableDomain be used here?
> 
> Sounds like a great follow-up fix. We would need to thread RegistrableDomain
> through several layers, which I don't want to do in this patch. (See new Bug
> 195957).
> 
> >> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:339
> >> +void UIDelegate::UIClient::presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
> > 
> > We should use WebCore::RegistrableDomain here, if at all possible.
> 
> Filed 195957 to do so.
> 
> >> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:342
> >> +    NSString *alertMessageString = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Do you want to allow â%@â to use cookies and website data while browsing â%@â?", @"Message for requesting cross-site cookie and website data access."), requestingDomain.createCFString().get(), currentDomain.createCFString().get()];
> > 
> > I saw the labels and strings went into some localized infrastructure. So these will be localized, right?
> 
> Right.
> 
> >> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:353
> >> +        bool shouldAllow = returnCode == NSAlertFirstButtonReturn;
> > 
> > auto?
> 
> Sure!
> 
> >> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:382
> >> +    [alert addAction:allowAction];
> > 
> > Is either of these are highlighted as the default action?
> 
> Yes. Allow, just like in Safari.

I believe Safari does not have a default button for this prompt.

> >> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:396
> >> +    if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {
> > 
> > Maybe not part of this patch, but we should change the name of this method to webViewRequestStorageAccessPanelForRegistrableDomainUnderFirstPartyRegistrableDomainCompletionHandler.
> 
> We should definitely change the name, but preferably to something shorter!

How about webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler?

Once we have RegistrableDomain as parameter types we don't need to mention it in function names.
Comment 13 Brent Fulgham 2019-03-19 11:32:08 PDT
Created attachment 365190 [details]
Patch
Comment 14 EWS Watchlist 2019-03-19 12:43:41 PDT
Comment on attachment 365190 [details]
Patch

Attachment 365190 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/11568886

New failing tests:
http/wpt/mediarecorder/MediaRecorder-AV-audio-video-dataavailable.html
Comment 15 EWS Watchlist 2019-03-19 12:43:43 PDT
Created attachment 365210 [details]
Archive of layout-test-results from ews106 for mac-highsierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-highsierra-wk2  Platform: Mac OS X 10.13.6
Comment 16 Brent Fulgham 2019-03-19 12:46:58 PDT
I'm looking at the two crashes now. Hard to see how my string changes would have broken anything, but ... <shrug>.
Comment 17 Brent Fulgham 2019-03-19 12:50:43 PDT
I don't believe the crashes are related to this patch:

Crash 1: http/wpt/mediarecorder/MediaRecorder-AV-audio-video-dataavailable.html

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   WTFCrashWithInfo(int, char const*, char const*, int) + 19 (Assertions.h:566)
1   initAVEncoderBitRateKey() + 128 (MediaRecorderPrivateWriterCocoa.mm:55)
2   WebCore::MediaRecorderPrivateWriter::setAudioInput() + 38 (MediaRecorderPrivateWriterCocoa.mm:179)
3   WebCore::MediaRecorderPrivateWriter::create(WebCore::MediaStreamTrackPrivate const*, WebCore::MediaStreamTrackPrivate const*) + 574 (MediaRecorderPrivateWriterCocoa.mm:107)
4   WebCore::MediaRecorderPrivateAVFImpl::create(WebCore::MediaStreamPrivate const&) + 643 (RefPtr.h:81)
5   WebCore::MediaRecorder::create(WebCore::Document&, WTF::Ref<WebCore::MediaStream, WTF::DumbPtrTraits<WebCore::MediaStream> >&&, WebCore::MediaRecorder::Options&&) + 128 (memory:2588)
6   WebCore::JSDOMConstructor<WebCore::JSMediaRecorder>::construct(JSC::ExecState*) + 412 (Ref.h:59)

Crash 2: imported/w3c/web-platform-tests/mediacapture-record/MediaRecorder-constructor.html

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   WTFCrashWithInfo(int, char const*, char const*, int) + 19 (Assertions.h:566)
1   initAVEncoderBitRateKey() + 128 (MediaRecorderPrivateWriterCocoa.mm:55)
2   WebCore::MediaRecorderPrivateWriter::setAudioInput() + 38 (MediaRecorderPrivateWriterCocoa.mm:179)
3   WebCore::MediaRecorderPrivateWriter::create(WebCore::MediaStreamTrackPrivate const*, WebCore::MediaStreamTrackPrivate const*) + 574 (MediaRecorderPrivateWriterCocoa.mm:107)
4   WebCore::MediaRecorderPrivateAVFImpl::create(WebCore::MediaStreamPrivate const&) + 643 (RefPtr.h:81)
5   WebCore::MediaRecorder::create(WebCore::Document&, WTF::Ref<WebCore::MediaStream, WTF::DumbPtrTraits<WebCore::MediaStream> >&&, WebCore::MediaRecorder::Options&&) + 128 (memory:2588)
6   WebCore::JSDOMConstructor<WebCore::JSMediaRecorder>::construct(JSC::ExecState*) + 412 (Ref.h:59)
Comment 18 Chris Dumez 2019-03-19 13:02:15 PDT
Comment on attachment 365190 [details]
Patch

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

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:339
> +void UIDelegate::UIClient::presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)

Could we move this to a separate file / class to avoid crowding UIDelegate.mm? UIDelegate normally only acts as a proxy and contains as little code as possible.

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:357
> +    struct CallbackAggregator final : public ThreadSafeRefCounted<CallbackAggregator> {

Could this be replaced by a BlockPtr?

auto completionBlock = makeBlockPtr([completionHandler = WTFMove(completionHandler)](bool shouldAllow) {
    completionHandler(shouldAllow);
});

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:373
> +    UIAlertAction* doNotAllowAction = [UIAlertAction actionWithTitle:WEB_UI_STRING_KEY(@"Don't Allow", "Don't Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt") style:UIAlertActionStyleCancel handler:makeBlockPtr([callbackAggregator = callbackAggregator.copyRef()](UIAlertAction *action) mutable {

UIAlertAction* doNotAllowAction = [UIAlertAction actionWithTitle:WEB_UI_STRING_KEY(@"Don't Allow", "Don't Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt") style:UIAlertActionStyleCancel handler:[completionBlock](UIAlertAction *action) {
    completionBlock(false);
});

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:384
> +    [m_uiDelegate.m_webView.window.rootViewController presentViewController:alert animated:YES completion:nil];

I see some code if relying on [UIViewController _viewControllerForFullScreenPresentationFromView:view] to get the presenting view controller. I personally do not know which one is best. It'd be good to confirm with thorton / Wenson / Andy.
Comment 19 Brent Fulgham 2019-03-19 13:40:00 PDT
Comment on attachment 365190 [details]
Patch

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

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:357
>> +    struct CallbackAggregator final : public ThreadSafeRefCounted<CallbackAggregator> {
> 
> Could this be replaced by a BlockPtr?
> 
> auto completionBlock = makeBlockPtr([completionHandler = WTFMove(completionHandler)](bool shouldAllow) {
>     completionHandler(shouldAllow);
> });

Oh! Seems like it.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:373
>> +    UIAlertAction* doNotAllowAction = [UIAlertAction actionWithTitle:WEB_UI_STRING_KEY(@"Don't Allow", "Don't Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt") style:UIAlertActionStyleCancel handler:makeBlockPtr([callbackAggregator = callbackAggregator.copyRef()](UIAlertAction *action) mutable {
> 
> UIAlertAction* doNotAllowAction = [UIAlertAction actionWithTitle:WEB_UI_STRING_KEY(@"Don't Allow", "Don't Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt") style:UIAlertActionStyleCancel handler:[completionBlock](UIAlertAction *action) {
>     completionBlock(false);
> });

Will do.

>> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:384
>> +    [m_uiDelegate.m_webView.window.rootViewController presentViewController:alert animated:YES completion:nil];
> 
> I see some code if relying on [UIViewController _viewControllerForFullScreenPresentationFromView:view] to get the presenting view controller. I personally do not know which one is best. It'd be good to confirm with thorton / Wenson / Andy.

Wenson says [UIViewController _viewControllerForFullScreenPresentationFromView:view]
Comment 20 Brent Fulgham 2019-03-19 14:27:02 PDT
Created attachment 365228 [details]
Patch
Comment 21 Chris Dumez 2019-03-19 14:32:49 PDT
Comment on attachment 365228 [details]
Patch

r=me
Comment 22 WebKit Commit Bot 2019-03-19 15:11:05 PDT
Comment on attachment 365228 [details]
Patch

Clearing flags on attachment: 365228

Committed r243173: <https://trac.webkit.org/changeset/243173>
Comment 23 WebKit Commit Bot 2019-03-19 15:11:07 PDT
All reviewed patches have been landed.  Closing bug.
Comment 24 Chris Dumez 2019-03-19 16:24:37 PDT
Follow-up build fix: https://trac.webkit.org/r243178.
Comment 25 Brent Fulgham 2019-03-20 19:32:53 PDT
*** Bug 195424 has been marked as a duplicate of this bug. ***