Changeset 229117 in webkit


Ignore:
Timestamp:
Feb 28, 2018, 6:12:31 PM (8 years ago)
Author:
BJ Burg
Message:

[Cocoa] Web Automation: provide a way to ask clients the type of a JavaScript dialog
https://bugs.webkit.org/show_bug.cgi?id=182660
<rdar://problem/37408183>

Reviewed by Tim Horton and Carlos Garcia Campos.

Add another delegate method to ask what type of dialog is being shown.
This is used to implement §18.4 Step 5, where sending text to a dialog
without a prompt will return several different kinds of errors.

No new tests, covered by web platform tests once Safari side has landed.

  • UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h: Update FIXME radar numbers.
  • UIProcess/Cocoa/AutomationSessionClient.h:
  • UIProcess/Cocoa/AutomationSessionClient.mm:

(WebKit::AutomationSessionClient::AutomationSessionClient):
(WebKit::toImpl):
(WebKit::AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage):
If there is no current dialog to be checked, the client can return the 'None'
type. This gets converted into a std::nullopt and causes a command error later.

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r229115 r229117  
     12018-02-28  Brian Burg  <bburg@apple.com>
     2
     3        [Cocoa] Web Automation: provide a way to ask clients the type of a JavaScript dialog
     4        https://bugs.webkit.org/show_bug.cgi?id=182660
     5        <rdar://problem/37408183>
     6
     7        Reviewed by Tim Horton and Carlos Garcia Campos.
     8
     9        Add another delegate method to ask what type of dialog is being shown.
     10        This is used to implement §18.4 Step 5, where sending text to a dialog
     11        without a prompt will return several different kinds of errors.
     12
     13        No new tests, covered by web platform tests once Safari side has landed.
     14
     15        * UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h: Update FIXME radar numbers.
     16        * UIProcess/Cocoa/AutomationSessionClient.h:
     17        * UIProcess/Cocoa/AutomationSessionClient.mm:
     18        (WebKit::AutomationSessionClient::AutomationSessionClient):
     19        (WebKit::toImpl):
     20        (WebKit::AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage):
     21        If there is no current dialog to be checked, the client can return the 'None'
     22        type. This gets converted into a std::nullopt and causes a command error later.
     23
    1242018-02-28  John Wilander  <wilander@apple.com>
    225
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h

    r228920 r229117  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016, 2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434@class _WKAutomationSession;
    3535
     36typedef NS_ENUM(NSInteger, _WKAutomationSessionJavaScriptDialogType) {
     37    _WKAutomationSessionJavaScriptDialogTypeNone = 1,
     38    _WKAutomationSessionJavaScriptDialogTypeAlert,
     39    _WKAutomationSessionJavaScriptDialogTypeConfirm,
     40    _WKAutomationSessionJavaScriptDialogTypePrompt,
     41} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     42
    3643@protocol _WKAutomationSessionDelegate <NSObject>
    3744@optional
     
    4552- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
    4653- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     54- (_WKAutomationSessionJavaScriptDialogType)_automationSession:(_WKAutomationSession *)automationSession typeOfCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    4755
    48 // FIXME: Objective-C delegate methods shouldn't use C API types like WKPageRef. We need to
     56// FIXME 37408718: Objective-C delegate methods shouldn't use C API types like WKPageRef. We need to
    4957// migrate clients to use WKWebView, or expose the same behavior via a C SPI for those clients.
    50 - (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
    51 - (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page;
    52 - (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page;
    53 - (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page;
    54 - (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page;
    55 - (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page;
     58- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     59- (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     60- (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     61- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     62- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     63- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
     64- (_WKAutomationSessionJavaScriptDialogType)_automationSession:(_WKAutomationSession *)automationSession typeOfCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    5665@end
    5766
  • trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h

    r228920 r229117  
    6565        bool messageOfCurrentJavaScriptDialogForWebView : 1;
    6666        bool setUserInputForCurrentJavaScriptPromptForWebView : 1;
     67        bool typeOfCurrentJavaScriptDialogForWebView : 1;
    6768
    68         // FIXME 28524687: these delegate methods should be removed.
     69        // FIXME 37408718: these delegate methods should be removed.
    6970        bool didRequestNewWindow : 1;
    7071        bool isShowingJavaScriptDialogOnPage : 1;
     
    7374        bool messageOfCurrentJavaScriptDialogOnPage : 1;
    7475        bool setUserInputForCurrentJavaScriptPromptOnPage : 1;
     76        bool typeOfCurrentJavaScriptDialogOnPage : 1;
    7577    } m_delegateMethods;
    7678};
  • trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm

    r228920 r229117  
    4949    m_delegateMethods.messageOfCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogForWebView:)];
    5050    m_delegateMethods.setUserInputForCurrentJavaScriptPromptForWebView = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogForWebView:)];
     51    m_delegateMethods.typeOfCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:typeOfCurrentJavaScriptDialogForWebView:)];
    5152
    52     // FIXME 28524687: these delegate methods should be removed.
     53    // FIXME 37408718: these delegate methods should be removed.
    5354    m_delegateMethods.didRequestNewWindow = [delegate respondsToSelector:@selector(_automationSessionDidRequestNewWindow:)];
    5455    m_delegateMethods.isShowingJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:isShowingJavaScriptDialogOnPage:)];
     
    5758    m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogOnPage:)];
    5859    m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogOnPage:)];
     60    m_delegateMethods.typeOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:typeOfCurrentJavaScriptDialogOnPage:)];
    5961}
    6062
     
    6567}
    6668
    67 // FIXME 28524687: support for WKPageRef-based delegate methods should be removed.
     69// FIXME 37408718: support for WKPageRef-based delegate methods should be removed.
    6870// Until these are removed, prefer to use the WKWebView delegate methods if implemented.
    6971WebPageProxy* AutomationSessionClient::didRequestNewWindow(WebAutomationSession& session)
     
    124126}
    125127
    126 std::optional<API::AutomationSessionClient::JavaScriptDialogType> AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&)
     128static std::optional<API::AutomationSessionClient::JavaScriptDialogType> toImpl(_WKAutomationSessionJavaScriptDialogType type)
    127129{
    128     // FIXME: Implement it. This is only used in WebAutomationSession::setUserInputForCurrentJavaScriptPrompt() so for now we return
    129     // always Prompt type for compatibility.
     130    switch (type) {
     131    case _WKAutomationSessionJavaScriptDialogTypeNone:
     132        return std::nullopt;
     133    case _WKAutomationSessionJavaScriptDialogTypePrompt:
     134        return API::AutomationSessionClient::JavaScriptDialogType::Prompt;
     135    case _WKAutomationSessionJavaScriptDialogTypeConfirm:
     136        return API::AutomationSessionClient::JavaScriptDialogType::Confirm;
     137    case _WKAutomationSessionJavaScriptDialogTypeAlert:
     138        return API::AutomationSessionClient::JavaScriptDialogType::Alert;
     139    }
     140}
     141
     142std::optional<API::AutomationSessionClient::JavaScriptDialogType> AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession& session, WebPageProxy& page)
     143{
     144    if (m_delegateMethods.typeOfCurrentJavaScriptDialogForWebView)
     145        return toImpl([m_delegate.get() _automationSession:wrapper(session) typeOfCurrentJavaScriptDialogForWebView:fromWebPageProxy(page)]);
     146    if (m_delegateMethods.typeOfCurrentJavaScriptDialogOnPage)
     147        return toImpl([m_delegate.get() _automationSession:wrapper(session) typeOfCurrentJavaScriptDialogOnPage:toAPI(&page)]);
     148
    130149    return API::AutomationSessionClient::JavaScriptDialogType::Prompt;
    131150}
Note: See TracChangeset for help on using the changeset viewer.