Skip to content

Commit

Permalink
Adjust storage access quirk prompt based on feedback
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=269970
rdar://123490355

Reviewed by Charlie Wolfe.

Adjust storage access quirk prompt based on feedback. This change removes the
accessory text, so we get rid of that complexity (which I introduced in
271821@main), as well.

* Source/WebCore/en.lproj/Localizable.strings:
* Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.h:
* Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.mm:
(WebKit::presentStorageAccessAlert):
(WebKit::presentStorageAccessAlertQuirk):
(WebKit::presentStorageAccessAlertSSOQuirk):
(WebKit::displayStorageAccessAlert):

Canonical link: https://commits.webkit.org/275891@main
  • Loading branch information
sysrqb authored and Matthew Finkel committed Mar 10, 2024
1 parent f93c856 commit ae6662f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
6 changes: 6 additions & 0 deletions Source/WebCore/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@
/* Message for requesting cross-site cookie and website data access. */
"Do you want to allow “%@” to use cookies and website data while browsing “%@”?" = "Do you want to allow “%@” to use cookies and website data while browsing “%@”?";

/* Message for requesting cross-site cookie and website data access. */
"Do you want to allow %@ websites to access one another's cookies and website data?" = "Do you want to allow %@ websites to access one another's cookies and website data?";

/* Informative text for requesting cross-site cookie and website data access. */
"Logging into this website requires %s and %s to access one another's cookies and website data. Allowing access is necessary for the website to work correctly." = "Logging into this website requires %s and %s to access one another's cookies and website data. Allowing access is necessary for the website to work correctly.";

/* Codec Strings */
"Dolby Vision Codec String" = "Dolby Vision";

Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace WebKit {
void presentStorageAccessAlert(WKWebView *, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&&);
void presentStorageAccessAlertQuirk(WKWebView *, const WebCore::RegistrableDomain& firstRequestingDomain, const WebCore::RegistrableDomain& secondRequestingDomain, const WebCore::RegistrableDomain& current, CompletionHandler<void(bool)>&&);
void presentStorageAccessAlertSSOQuirk(WKWebView *, const String& organizationName, const HashMap<WebCore::RegistrableDomain, Vector<WebCore::RegistrableDomain>>&, CompletionHandler<void(bool)>&&);
void displayStorageAccessAlert(WKWebView *, NSString *, NSString *, NSArray<NSString *> *, CompletionHandler<void(bool)>&&);
void displayStorageAccessAlert(WKWebView *, NSString *, NSString *, CompletionHandler<void(bool)>&&);

}

Expand Down
51 changes: 20 additions & 31 deletions Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void presentStorageAccessAlert(WKWebView *webView, const WebCore::RegistrableDom

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.get()];

displayStorageAccessAlert(webView, alertTitle, informativeText, nil, WTFMove(completionHandler));
displayStorageAccessAlert(webView, alertTitle, informativeText, WTFMove(completionHandler));
}

void presentStorageAccessAlertQuirk(WKWebView *webView, const WebCore::RegistrableDomain& firstRequesting, const WebCore::RegistrableDomain& secondRequesting, const WebCore::RegistrableDomain& current, CompletionHandler<void(bool)>&& completionHandler)
Expand All @@ -73,24 +73,32 @@ void presentStorageAccessAlertQuirk(WKWebView *webView, const WebCore::Registrab

NSString *informativeText = [NSString stringWithFormat:WEB_UI_NSSTRING(@"This will allow “%@” and “%@” to track your activity.", @"Informative text for requesting cross-site cookie and website data access."), firstRequestingDomain.get(), secondRequestingDomain.get()];

displayStorageAccessAlert(webView, alertTitle, informativeText, nil, WTFMove(completionHandler));
displayStorageAccessAlert(webView, alertTitle, informativeText, WTFMove(completionHandler));
}

void presentStorageAccessAlertSSOQuirk(WKWebView *webView, const String& organizationName, const HashMap<WebCore::RegistrableDomain, Vector<WebCore::RegistrableDomain>>& domainPairings, CompletionHandler<void(bool)>&& completionHandler)
{
NSString *alertTitle = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Are you logging in to this website, and do you want to allow other %@ sites access to your website data while browsing the websites listed below?", @"Message for requesting cross-site cookie and website data access."), organizationName.createCFString().get()];
NSString *informativeText = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Allowing access to website data is necessary for the website to work correctly.", @"Informative text for requesting cross-site cookie and website data access.")];

auto* accessoryTextList = [NSMutableArray arrayWithCapacity:domainPairings.size()];
for (const auto& domains : domainPairings) {
auto embeddedDomains = makeStringByJoining(domains.value.map([](auto& domain) { return domain.string(); }).span(), "\n - "_s);
NSString *accessoryText = [NSString stringWithFormat:WEB_UI_NSSTRING(@"While you are visiting %@, the following related websites will gain access to their cookies:\n - %@", @"Accessory text for requesting cross-site cookie and website data access."), domains.key.string().createCFString().get(), embeddedDomains.createCFString().get()];
[accessoryTextList addObject:accessoryText];
NSString *alertTitle = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Do you want to allow %@ websites to access one another's cookies and website data?", @"Message for requesting cross-site cookie and website data access."), organizationName.createCFString().get()];

HashSet<String> allDomains;
for (auto&& domains : domainPairings) {
allDomains.add(domains.key.string());
for (auto&& subFrameDomain : domains.value)
allDomains.add(subFrameDomain.string());
}
displayStorageAccessAlert(webView, alertTitle, informativeText, accessoryTextList, WTFMove(completionHandler));

Vector<String> uniqueDomainList = copyToVector(allDomains);
std::sort(uniqueDomainList.begin(), uniqueDomainList.end());
auto lastDomain = uniqueDomainList.takeLast();

auto initialDomainList = makeStringByJoining(uniqueDomainList.span(), ", "_s);

NSString *informativeText = [NSString stringWithFormat:WEB_UI_NSSTRING(@"Logging into this website requires %s and %s to access one another's cookies and website data. Allowing access is necessary for the website to work correctly.", @"Informative text for requesting cross-site cookie and website data access."), initialDomainList.utf8().data(), lastDomain.utf8().data()];

displayStorageAccessAlert(webView, alertTitle, informativeText, WTFMove(completionHandler));
}

void displayStorageAccessAlert(WKWebView *webView, NSString *alertTitle, NSString *informativeText, NSArray<NSString *> *accessoryTextList, CompletionHandler<void(bool)>&& completionHandler)
void displayStorageAccessAlert(WKWebView *webView, NSString *alertTitle, NSString *informativeText, CompletionHandler<void(bool)>&& completionHandler)
{
auto completionBlock = makeBlockPtr([completionHandler = WTFMove(completionHandler)](bool shouldAllow) mutable {
completionHandler(shouldAllow);
Expand All @@ -103,17 +111,6 @@ void displayStorageAccessAlert(WKWebView *webView, NSString *alertTitle, NSStrin
auto alert = adoptNS([NSAlert new]);
[alert setMessageText:alertTitle];
[alert setInformativeText:informativeText];
if (accessoryTextList) {
auto accessory = adoptNS([[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, 200, 15)]);
auto *mutableString = [[accessory textStorage] mutableString];
[mutableString setString:[accessoryTextList componentsJoinedByString:@"\n"]];
[[accessory textStorage] setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
[[accessory textStorage] setForegroundColor:NSColor.whiteColor];
[accessory setEditable:NO];
[accessory setDrawsBackground:NO];
[alert setAccessoryView:accessory.get()];
[alert layout];
}
[alert addButtonWithTitle:allowButtonString];
[alert addButtonWithTitle:doNotAllowButtonString];
[alert beginSheetModalForWindow:webView.window completionHandler:[completionBlock](NSModalResponse returnCode) {
Expand All @@ -123,14 +120,6 @@ void displayStorageAccessAlert(WKWebView *webView, NSString *alertTitle, NSStrin
#else
auto alert = WebKit::createUIAlertController(alertTitle, informativeText);

if (accessoryTextList) {
[accessoryTextList enumerateObjectsUsingBlock:^(NSString *line, NSUInteger index, BOOL *stop) {
[alert addTextFieldWithConfigurationHandler:[&line](UITextField *textField) {
textField.text = line;
}];
}];
}

UIAlertAction* allowAction = [UIAlertAction actionWithTitle:allowButtonString style:UIAlertActionStyleCancel handler:[completionBlock](UIAlertAction *action) {
completionBlock(true);
}];
Expand Down

0 comments on commit ae6662f

Please sign in to comment.