Add default prompt implementation for the Storage Access API
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 22:11:00 +0000 (22:11 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Mar 2019 22:11:00 +0000 (22:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195866
<rdar://problem/45150009>

Reviewed by Chris Dumez.

Source/WebCore:

* en.lproj/Localizable.strings: Update with new strings used by the
Storage Access API dialog.

Source/WebKit:

This patch revises the UIDelegate implementation with a default permission dialog
for the Storage Access API. This allows us to use and test the API in MiniBrowser,
rather than requiring a full-fledged web browser to drive testing.

* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::UIClient::presentStorageAccessConfirmDialog): Added.
(WebKit::UIDelegate::UIClient::requestStorageAccessConfirm): Modify to call new default
implementation if the WKWebVIew client doesn't implement the necessary SPI.
* UIProcess/Cocoa/WKStorageAccessAlert.h: Added.
* UIProcess/Cocoa/WKStorageAccessAlert.mm: Added.
(WebKit::presentStorageAccessAlert):
* WebKit.xcodeproj/project.pbxproj:

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

Source/WebCore/ChangeLog
Source/WebCore/en.lproj/Localizable.strings
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.h [new file with mode: 0644]
Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.mm [new file with mode: 0644]
Source/WebKit/WebKit.xcodeproj/project.pbxproj

index 284eb1c..c592c3b 100644 (file)
@@ -1,3 +1,14 @@
+2019-03-19  Brent Fulgham  <bfulgham@apple.com>
+
+        Add default prompt implementation for the Storage Access API
+        https://bugs.webkit.org/show_bug.cgi?id=195866
+        <rdar://problem/45150009>
+
+        Reviewed by Chris Dumez.
+
+        * en.lproj/Localizable.strings: Update with new strings used by the
+        Storage Access API dialog.
+
 2019-03-19  Thibault Saunier  <tsaunier@igalia.com>
 
         [GStreamer][WebRTC] Create sps/pps for all frames to please libwebrtc
index 96df5a4..3b45a3f 100644 (file)
 /* Undo action name */
 "Align Right (Undo action name)" = "Align Right";
 
+/* Allow Storage Access API */
+"Allow" = "Allow";
+
+/* Title for Allow button label in the Storage Access API request dialog */
+"Allow (cross-site cookie and website data access)" = "Allow";
+
+/* Storage Access API request validation (iOS phrasing) */
+"Allow \"%@\" to use cookies and website data while browsing \"%@\"?" = "Allow \"%@\" to use cookies and website data while browsing \"%@\"?";
+
 /* WKErrorUnknown description */
 "An unknown error occurred" = "An unknown error occurred";
 
 /* Undo action name */
 "Dictation (Undo action name)" = "Dictation";
 
+/* Storage Access API request validation (macOS phrasing) */
+"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 \"%@\"?";
+
+/* Storage Access API deny access */
+"Don't Allow" = "Don't Allow";
+
+/* Title for Don't Allow button label in the Storage Access API request dialog */
+"Don't Allow (cross-site cookie and website data access)" = "Don't Allow";
+
 /* Title of the Done button for zoomed form controls. */
 "Done" = "Done";
 
 /* Unwanted software warning */
 "This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove." = "This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove.";
 
+/* Storage Access API tracking warning */
+"This will allow \"%@\" to track your activity." = "This will allow \"%@\" to track your activity.";
+
 /* Undo action name */
 "Tighten Kerning (Undo action name)" = "Tighten Kerning";
 
index 3c06ec8..41c95ad 100644 (file)
@@ -1,3 +1,25 @@
+2019-03-19  Brent Fulgham  <bfulgham@apple.com>
+
+        Add default prompt implementation for the Storage Access API
+        https://bugs.webkit.org/show_bug.cgi?id=195866
+        <rdar://problem/45150009>
+
+        Reviewed by Chris Dumez.
+
+        This patch revises the UIDelegate implementation with a default permission dialog
+        for the Storage Access API. This allows us to use and test the API in MiniBrowser,
+        rather than requiring a full-fledged web browser to drive testing.
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::UIClient::presentStorageAccessConfirmDialog): Added.
+        (WebKit::UIDelegate::UIClient::requestStorageAccessConfirm): Modify to call new default
+        implementation if the WKWebVIew client doesn't implement the necessary SPI.
+        * UIProcess/Cocoa/WKStorageAccessAlert.h: Added.
+        * UIProcess/Cocoa/WKStorageAccessAlert.mm: Added.
+        (WebKit::presentStorageAccessAlert):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2019-03-19  Conrad Shultz  <conrad_shultz@apple.com>
 
         REGRESSION (r242369): Only use picker-supported UTIs when creating image picker
index f41a6d6..3c23f8b 100644 (file)
@@ -87,6 +87,7 @@ private:
         void runJavaScriptAlert(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void()>&& completionHandler) final;
         void runJavaScriptConfirm(WebPageProxy*, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(bool)>&& completionHandler) final;
         void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&&) final;
+        void presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
         void requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&) final;
         void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) final;
         bool canRunBeforeUnloadConfirmPanel() const final;
index 96b88bf..a57952f 100644 (file)
@@ -40,6 +40,7 @@
 #import "WKNavigationActionInternal.h"
 #import "WKOpenPanelParametersInternal.h"
 #import "WKSecurityOriginInternal.h"
+#import "WKStorageAccessAlert.h"
 #import "WKUIDelegatePrivate.h"
 #import "WKWebViewConfigurationInternal.h"
 #import "WKWebViewInternal.h"
@@ -338,17 +339,17 @@ void UIDelegate::UIClient::runJavaScriptPrompt(WebPageProxy*, const WTF::String&
 
 void UIDelegate::UIClient::requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
 {
-    if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {
-        completionHandler(true);
-        return;
-    }
-
     auto delegate = m_uiDelegate.m_delegate.get();
     if (!delegate) {
-        completionHandler(true);
+        completionHandler(false);
         return;
     }
     
+    if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {
+        presentStorageAccessAlert(m_uiDelegate.m_webView, requestingDomain, currentDomain, WTFMove(completionHandler));
+        return;
+    }
+
     auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:));
     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestStorageAccessPanelForDomain:requestingDomain underCurrentDomain:currentDomain completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
         if (checker->completionHandlerHasBeenCalled())
diff --git a/Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.h b/Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.h
new file mode 100644 (file)
index 0000000..12e590d
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+
+#import <wtf/CompletionHandler.h>
+
+@class WKWebView;
+
+namespace WTF {
+class String;
+}
+
+namespace WebKit {
+
+void presentStorageAccessAlert(WKWebView *, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
+
+}
+
+#endif // PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
diff --git a/Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.mm b/Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.mm
new file mode 100644 (file)
index 0000000..69e6ab0
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKStorageAccessAlert.h"
+
+#if PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
+
+#import "WKWebViewInternal.h"
+#import <WebCore/LocalizedStrings.h>
+#import <wtf/BlockPtr.h>
+
+namespace WebKit {
+
+void presentStorageAccessAlert(WKWebView *webView, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
+{
+    auto completionBlock = makeBlockPtr([completionHandler = WTFMove(completionHandler)](bool shouldAllow) mutable {
+        completionHandler(shouldAllow);
+    });
+
+#if PLATFORM(MAC)
+    NSString *alertTitle = [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()];
+#else
+    NSString *alertTitle = [NSString stringWithFormat:WEB_UI_NSSTRING(@"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()];
+#endif
+
+    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()];
+    NSString *allowButtonString = WEB_UI_STRING_KEY(@"Allow", "Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt");
+    NSString *doNotAllowButtonString = WEB_UI_STRING_KEY(@"Don't Allow", "Don't Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt");
+
+#if PLATFORM(MAC)
+    auto alert = adoptNS([NSAlert new]);
+    [alert setMessageText:alertTitle];
+    [alert setInformativeText:informativeText];
+    [alert addButtonWithTitle:allowButtonString];
+    [alert addButtonWithTitle:doNotAllowButtonString];
+    [alert beginSheetModalForWindow:webView.window completionHandler:[completionBlock](NSModalResponse returnCode) {
+        auto shouldAllow = returnCode == NSAlertFirstButtonReturn;
+        completionBlock(shouldAllow);
+    }];
+#else
+    UIAlertController* alert = [UIAlertController alertControllerWithTitle:alertTitle message:informativeText preferredStyle:UIAlertControllerStyleAlert];
+
+    UIAlertAction* doNotAllowAction = [UIAlertAction actionWithTitle:allowButtonString style:UIAlertActionStyleCancel handler:[completionBlock](UIAlertAction *action) {
+        completionBlock(false);
+    }];
+
+    UIAlertAction* allowAction = [UIAlertAction actionWithTitle:doNotAllowButtonString style:UIAlertActionStyleDefault handler:[completionBlock](UIAlertAction *action) {
+        completionBlock(true);
+    }];
+
+    [alert addAction:doNotAllowAction];
+    [alert addAction:allowAction];
+
+    [[UIViewController _viewControllerForFullScreenPresentationFromView:webView] presentViewController:alert animated:YES completion:nil];
+#endif
+}
+
+}
+
+#endif // PLATFORM(COCOA) && !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
index ab3ab88..6249b1c 100644 (file)
                7A3FECA221F7C09700F267CD /* StorageAccessStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A3FECA121F7C09700F267CD /* StorageAccessStatus.h */; };
                7A41E9FB21F81DAD00B88CDB /* ShouldGrandfatherStatistics.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A41E9FA21F81DAC00B88CDB /* ShouldGrandfatherStatistics.h */; };
                7A772C8D1DDD4A25000F34F1 /* com.apple.WebKit.plugin-common.sb in Copy Plug-in Sandbox Profiles */ = {isa = PBXBuildFile; fileRef = 7A1506721DD56298001F4B58 /* com.apple.WebKit.plugin-common.sb */; };
+               7A78FF32224191960096483E /* WKStorageAccessAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A78FF2E224191750096483E /* WKStorageAccessAlert.h */; };
+               7A78FF332241919B0096483E /* WKStorageAccessAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7A78FF2F224191760096483E /* WKStorageAccessAlert.mm */; };
                7A791EFA1C7CFCF100C4C52B /* WebResourceLoadStatisticsStoreMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A791EF91C7CFB3700C4C52B /* WebResourceLoadStatisticsStoreMessageReceiver.cpp */; };
                7A791EFB1C7CFD0100C4C52B /* WebResourceLoadStatisticsStoreMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A791EF81C7CFB1000C4C52B /* WebResourceLoadStatisticsStoreMessages.h */; };
                7A821F4C1E2F673900604577 /* LegacyCustomProtocolManagerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A821F4B1E2F664800604577 /* LegacyCustomProtocolManagerClient.h */; };
                7A3FECA121F7C09700F267CD /* StorageAccessStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StorageAccessStatus.h; path = Classifier/StorageAccessStatus.h; sourceTree = "<group>"; };
                7A41E9FA21F81DAC00B88CDB /* ShouldGrandfatherStatistics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ShouldGrandfatherStatistics.h; path = Classifier/ShouldGrandfatherStatistics.h; sourceTree = "<group>"; };
                7A5E39491D5BD8A700B4B7CE /* com.macromedia.Flash Player ESR.plugin.sb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "com.macromedia.Flash Player ESR.plugin.sb"; sourceTree = "<group>"; };
+               7A78FF2E224191750096483E /* WKStorageAccessAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKStorageAccessAlert.h; sourceTree = "<group>"; };
+               7A78FF2F224191760096483E /* WKStorageAccessAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKStorageAccessAlert.mm; sourceTree = "<group>"; };
                7A791EF81C7CFB1000C4C52B /* WebResourceLoadStatisticsStoreMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebResourceLoadStatisticsStoreMessages.h; path = DerivedSources/WebKit2/WebResourceLoadStatisticsStoreMessages.h; sourceTree = BUILT_PRODUCTS_DIR; };
                7A791EF91C7CFB3700C4C52B /* WebResourceLoadStatisticsStoreMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = WebResourceLoadStatisticsStoreMessageReceiver.cpp; path = DerivedSources/WebKit2/WebResourceLoadStatisticsStoreMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
                7A821F491E2F65DD00604577 /* LegacyCustomProtocolManagerProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LegacyCustomProtocolManagerProxy.cpp; path = CustomProtocols/LegacyCustomProtocolManagerProxy.cpp; sourceTree = "<group>"; };
                                5CA26D7F217ABBB600F97A35 /* WKSafeBrowsingWarning.mm */,
                                1DE0D095211CC21300439B5F /* WKShareSheet.h */,
                                1DBBB061211CC3CB00502ECC /* WKShareSheet.mm */,
+                               7A78FF2E224191750096483E /* WKStorageAccessAlert.h */,
+                               7A78FF2F224191760096483E /* WKStorageAccessAlert.mm */,
                                2D7AAFD218C8640600A7ACD4 /* WKWebViewContentProvider.h */,
                                2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */,
                                2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */,
                                1DB01943211CF002009FB3E8 /* WKShareSheet.h in Headers */,
                                513E462D1AD837560016234A /* WKSharingServicePickerDelegate.h in Headers */,
                                93F549B41E3174B7000E7239 /* WKSnapshotConfiguration.h in Headers */,
+                               7A78FF32224191960096483E /* WKStorageAccessAlert.h in Headers */,
                                BC407606124FF0270068F20A /* WKString.h in Headers */,
                                BC40761A124FF0370068F20A /* WKStringCF.h in Headers */,
                                BC9099801256A98200083756 /* WKStringPrivate.h in Headers */,
                                637281A321ADC744009E0DE6 /* WKDownloadProgress.mm in Sources */,
                                5CA26D83217AD1B800F97A35 /* WKSafeBrowsingWarning.mm in Sources */,
                                1DB01944211CF005009FB3E8 /* WKShareSheet.mm in Sources */,
+                               7A78FF332241919B0096483E /* WKStorageAccessAlert.mm in Sources */,
                                26F10BE919187E2E001D0E68 /* WKSyntheticTapGestureRecognizer.m in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;