⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243210 in webkit


Ignore:
Timestamp:
Mar 20, 2019, 9:41:15 AM (7 years ago)
Author:
Brent Fulgham
Message:

Adopt RegistrableDomain in the Storage Access API prompt code paths
https://bugs.webkit.org/show_bug.cgi?id=195957
<rdar://problem/49048028>

Reviewed by Chris Dumez.

While making the code changes in Bug 195866 we noticed that strings were being
used to pass the origins for the API calls. We should adopt the RegistrableDomain
class to improve type safety and avoid introducing bugs in the future.

  • UIProcess/API/APIUIClient.h:

(API::UIClient::requestStorageAccessConfirm):

  • UIProcess/API/C/WKPage.cpp:

(WKPageSetPageUIClient):

  • UIProcess/Cocoa/UIDelegate.h:
  • UIProcess/Cocoa/UIDelegate.mm:

(WebKit::UIDelegate::UIClient::requestStorageAccessConfirm):

  • UIProcess/Cocoa/WKStorageAccessAlert.h:
  • UIProcess/Cocoa/WKStorageAccessAlert.mm:

(WebKit::presentStorageAccessAlert):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::requestStorageAccessConfirm):

Location:
trunk/Source/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r243205 r243210  
     12019-03-20  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Adopt RegistrableDomain in the Storage Access API prompt code paths
     4        https://bugs.webkit.org/show_bug.cgi?id=195957
     5        <rdar://problem/49048028>
     6
     7        Reviewed by Chris Dumez.
     8
     9        While making the code changes in Bug 195866 we noticed that strings were being
     10        used to pass the origins for the API calls. We should adopt the RegistrableDomain
     11        class to improve type safety and avoid introducing bugs in the future.
     12
     13        * UIProcess/API/APIUIClient.h:
     14        (API::UIClient::requestStorageAccessConfirm):
     15        * UIProcess/API/C/WKPage.cpp:
     16        (WKPageSetPageUIClient):
     17        * UIProcess/Cocoa/UIDelegate.h:
     18        * UIProcess/Cocoa/UIDelegate.mm:
     19        (WebKit::UIDelegate::UIClient::requestStorageAccessConfirm):
     20        * UIProcess/Cocoa/WKStorageAccessAlert.h:
     21        * UIProcess/Cocoa/WKStorageAccessAlert.mm:
     22        (WebKit::presentStorageAccessAlert):
     23        * UIProcess/WebPageProxy.cpp:
     24        (WebKit::WebPageProxy::requestStorageAccessConfirm):
     25
    1262019-03-20  Chris Dumez  <cdumez@apple.com>
    227
  • trunk/Source/WebKit/UIProcess/API/APIUIClient.h

    r242823 r243210  
    4040
    4141namespace WebCore {
     42class RegistrableDomain;
    4243class ResourceRequest;
    4344struct FontAttributes;
     
    133134    virtual void checkUserMediaPermissionForOrigin(WebKit::WebPageProxy&, WebKit::WebFrameProxy&, SecurityOrigin&, SecurityOrigin&, WebKit::UserMediaPermissionCheckProxy& request) { request.deny(); }
    134135    virtual void decidePolicyForNotificationPermissionRequest(WebKit::WebPageProxy&, SecurityOrigin&, Function<void(bool)>&& completionHandler) { completionHandler(false); }
    135     virtual void requestStorageAccessConfirm(WebKit::WebPageProxy&, WebKit::WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler) { completionHandler(true); }
     136    virtual void requestStorageAccessConfirm(WebKit::WebPageProxy&, WebKit::WebFrameProxy*, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&& completionHandler) { completionHandler(true); }
    136137
    137138    // Printing.
  • trunk/Source/WebKit/UIProcess/API/C/WKPage.cpp

    r242823 r243210  
    18891889        }
    18901890
    1891         void requestStorageAccessConfirm(WebPageProxy& page, WebFrameProxy* frame, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler) final
     1891        void requestStorageAccessConfirm(WebPageProxy& page, WebFrameProxy* frame, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&& completionHandler) final
    18921892        {
    18931893            if (!m_client.requestStorageAccessConfirm) {
     
    18971897
    18981898            auto listener = RequestStorageAccessConfirmResultListener::create(WTFMove(completionHandler));
    1899             m_client.requestStorageAccessConfirm(toAPI(&page), toAPI(frame), toAPI(requestingDomain.impl()), toAPI(currentDomain.impl()), toAPI(listener.ptr()), m_client.base.clientInfo);
     1899            m_client.requestStorageAccessConfirm(toAPI(&page), toAPI(frame), toAPI(requestingDomain.string().impl()), toAPI(currentDomain.string().impl()), toAPI(listener.ptr()), m_client.base.clientInfo);
    19001900        }
    19011901
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h

    r243173 r243210  
    4242}
    4343
     44namespace WebCore {
     45class RegistrableDomain;
     46}
     47
    4448namespace WebKit {
    4549
     
    8993        void runJavaScriptPrompt(WebPageProxy*, const WTF::String&, const WTF::String&, WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void(const WTF::String&)>&&) final;
    9094        void presentStorageAccessConfirmDialog(const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
    91         void requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&) final;
     95        void requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&&) final;
    9296        void decidePolicyForGeolocationPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, Function<void(bool)>&) final;
    9397        bool canRunBeforeUnloadConfirmPanel() const final;
     
    164168        bool webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
    165169        bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
    166         bool webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler : 1;
     170        bool webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler : 1;
    167171        bool webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler : 1;
    168172        bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
  • trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm

    r243178 r243210  
    105105    m_delegateMethods.webViewRunJavaScriptConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
    106106    m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
    107     m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler = [delegate respondsToSelector:@selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:)];
     107    m_delegateMethods.webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler = [delegate respondsToSelector:@selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:)];
    108108    m_delegateMethods.webViewRunBeforeUnloadConfirmPanelWithMessageInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:completionHandler:)];
    109109    m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)];
     
    338338}
    339339
    340 void UIDelegate::UIClient::requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
     340void UIDelegate::UIClient::requestStorageAccessConfirm(WebPageProxy&, WebFrameProxy*, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
    341341{
    342342    auto delegate = m_uiDelegate.m_delegate.get();
     
    346346    }
    347347   
    348     if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelForTopPrivatelyControlledDomainUnderFirstPartyTopPrivatelyControlledDomainCompletionHandler) {
     348    if (!m_uiDelegate.m_delegateMethods.webViewRequestStorageAccessPanelUnderFirstPartyCompletionHandler) {
    349349#if !PLATFORM(WATCHOS) && !PLATFORM(APPLETV)
    350350        presentStorageAccessAlert(m_uiDelegate.m_webView, requestingDomain, currentDomain, WTFMove(completionHandler));
     
    354354
    355355    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:requestStorageAccessPanelForDomain:underCurrentDomain:completionHandler:));
    356     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestStorageAccessPanelForDomain:requestingDomain underCurrentDomain:currentDomain completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
     356    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView requestStorageAccessPanelForDomain:requestingDomain.string() underCurrentDomain:currentDomain.string() completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
    357357        if (checker->completionHandlerHasBeenCalled())
    358358            return;
  • trunk/Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.h

    r243173 r243210  
    3636}
    3737
     38namespace WebCore {
     39class RegistrableDomain;
     40}
     41
    3842namespace WebKit {
    3943
    40 void presentStorageAccessAlert(WKWebView *, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&&);
     44void presentStorageAccessAlert(WKWebView *, const WebCore::RegistrableDomain& requestingDomain, const WebCore::RegistrableDomain& currentDomain, CompletionHandler<void(bool)>&&);
    4145
    4246}
  • trunk/Source/WebKit/UIProcess/Cocoa/WKStorageAccessAlert.mm

    r243173 r243210  
    3131#import "WKWebViewInternal.h"
    3232#import <WebCore/LocalizedStrings.h>
     33#import <WebCore/RegistrableDomain.h>
    3334#import <wtf/BlockPtr.h>
    3435
    3536namespace WebKit {
    3637
    37 void presentStorageAccessAlert(WKWebView *webView, const WTF::String& requestingDomain, const WTF::String& currentDomain, CompletionHandler<void(bool)>&& completionHandler)
     38void presentStorageAccessAlert(WKWebView *webView, const WebCore::RegistrableDomain& requesting, const WebCore::RegistrableDomain& current, CompletionHandler<void(bool)>&& completionHandler)
    3839{
    3940    auto completionBlock = makeBlockPtr([completionHandler = WTFMove(completionHandler)](bool shouldAllow) mutable {
     
    4142    });
    4243
     44    auto requestingDomain = requesting.string().createCFString();
     45    auto currentDomain = current.string().createCFString();
     46
    4347#if PLATFORM(MAC)
    44     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()];
     48    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.get(), currentDomain.get()];
    4549#else
    46     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()];
     50    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.get(), currentDomain.get()];
    4751#endif
    4852
    49     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()];
     53    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()];
    5054    NSString *allowButtonString = WEB_UI_STRING_KEY(@"Allow", "Allow (cross-site cookie and website data access)", @"Button title in Storage Access API prompt");
    5155    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");
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r243205 r243210  
    84608460void WebPageProxy::requestStorageAccessConfirm(const RegistrableDomain& subFrameDomain, const RegistrableDomain& topFrameDomain, uint64_t frameID, CompletionHandler<void(bool)>&& completionHandler)
    84618461{
    8462     m_uiClient->requestStorageAccessConfirm(*this, m_process->webFrame(frameID), subFrameDomain.string(), topFrameDomain.string(), WTFMove(completionHandler));
     8462    m_uiClient->requestStorageAccessConfirm(*this, m_process->webFrame(frameID), subFrameDomain, topFrameDomain, WTFMove(completionHandler));
    84638463}
    84648464#endif
Note: See TracChangeset for help on using the changeset viewer.