- Revision
- 228902
- Author
- [email protected]
- Date
- 2018-02-21 15:31:15 -0800 (Wed, 21 Feb 2018)
Log 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.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (228901 => 228902)
--- trunk/Source/WebKit/ChangeLog 2018-02-21 22:37:27 UTC (rev 228901)
+++ trunk/Source/WebKit/ChangeLog 2018-02-21 23:31:15 UTC (rev 228902)
@@ -1,3 +1,26 @@
+2018-02-21 Brian Burg <[email protected]>
+
+ [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.
+
2018-02-21 Yousuke Kimoto <[email protected]>
[WinCairo] Fix compile errors of WebProcess and NetworkProcess due to no implementation for windows
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h (228901 => 228902)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h 2018-02-21 22:37:27 UTC (rev 228901)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSessionDelegate.h 2018-02-21 23:31:15 UTC (rev 228902)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2016, 2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,6 +33,13 @@
@class WKWebView;
@class _WKAutomationSession;
+typedef NS_ENUM(NSInteger, _WKAutomationSessionJavaScriptDialogType) {
+ _WKAutomationSessionJavaScriptDialogTypeNone = 1,
+ _WKAutomationSessionJavaScriptDialogTypeAlert,
+ _WKAutomationSessionJavaScriptDialogTypeConfirm,
+ _WKAutomationSessionJavaScriptDialogTypePrompt,
+} WK_API_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
@protocol _WKAutomationSessionDelegate <NSObject>
@optional
@@ -44,15 +51,17 @@
- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (_WKAutomationSessionJavaScriptDialogType)_automationSession:(_WKAutomationSession *)automationSession typeOfCurrentJavaScriptDialogForWebView:(WKWebView *)webView WK_API_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
-// FIXME: Objective-C delegate methods shouldn't use C API types like WKPageRef. We need to
+// FIXME 37408718: Objective-C delegate methods shouldn't use C API types like WKPageRef. We need to
// migrate clients to use WKWebView, or expose the same behavior via a C SPI for those clients.
-- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession;
-- (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page;
-- (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page;
-- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page;
-- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page;
-- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page;
+- (WKPageRef)_automationSessionDidRequestNewWindow:(_WKAutomationSession *)automationSession WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (BOOL)_automationSession:(_WKAutomationSession *)automationSession isShowingJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (void)_automationSession:(_WKAutomationSession *)automationSession dismissCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (void)_automationSession:(_WKAutomationSession *)automationSession acceptCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (NSString *)_automationSession:(_WKAutomationSession *)automationSession messageOfCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (void)_automationSession:(_WKAutomationSession *)automationSession setUserInput:(NSString *)value forCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(macosx(10.13), ios(11.0));
+- (_WKAutomationSessionJavaScriptDialogType)_automationSession:(_WKAutomationSession *)automationSession typeOfCurrentJavaScriptDialogOnPage:(WKPageRef)page WK_API_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
@end
#endif // WK_API_ENABLED
Modified: trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h (228901 => 228902)
--- trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h 2018-02-21 22:37:27 UTC (rev 228901)
+++ trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.h 2018-02-21 23:31:15 UTC (rev 228902)
@@ -64,8 +64,9 @@
bool acceptCurrentJavaScriptDialogForWebView : 1;
bool messageOfCurrentJavaScriptDialogForWebView : 1;
bool setUserInputForCurrentJavaScriptPromptForWebView : 1;
+ bool typeOfCurrentJavaScriptDialogForWebView : 1;
- // FIXME 28524687: these delegate methods should be removed.
+ // FIXME 37408718: these delegate methods should be removed.
bool didRequestNewWindow : 1;
bool isShowingJavaScriptDialogOnPage : 1;
bool dismissCurrentJavaScriptDialogOnPage : 1;
@@ -72,6 +73,7 @@
bool acceptCurrentJavaScriptDialogOnPage : 1;
bool messageOfCurrentJavaScriptDialogOnPage : 1;
bool setUserInputForCurrentJavaScriptPromptOnPage : 1;
+ bool typeOfCurrentJavaScriptDialogOnPage : 1;
} m_delegateMethods;
};
Modified: trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm (228901 => 228902)
--- trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm 2018-02-21 22:37:27 UTC (rev 228901)
+++ trunk/Source/WebKit/UIProcess/Cocoa/AutomationSessionClient.mm 2018-02-21 23:31:15 UTC (rev 228902)
@@ -48,8 +48,9 @@
m_delegateMethods.acceptCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:acceptCurrentJavaScriptDialogForWebView:)];
m_delegateMethods.messageOfCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogForWebView:)];
m_delegateMethods.setUserInputForCurrentJavaScriptPromptForWebView = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogForWebView:)];
+ m_delegateMethods.typeOfCurrentJavaScriptDialogForWebView = [delegate respondsToSelector:@selector(_automationSession:typeOfCurrentJavaScriptDialogForWebView:)];
- // FIXME 28524687: these delegate methods should be removed.
+ // FIXME 37408718: these delegate methods should be removed.
m_delegateMethods.didRequestNewWindow = [delegate respondsToSelector:@selector(_automationSessionDidRequestNewWindow:)];
m_delegateMethods.isShowingJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:isShowingJavaScriptDialogOnPage:)];
m_delegateMethods.dismissCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:dismissCurrentJavaScriptDialogOnPage:)];
@@ -56,6 +57,7 @@
m_delegateMethods.acceptCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:acceptCurrentJavaScriptDialogOnPage:)];
m_delegateMethods.messageOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:messageOfCurrentJavaScriptDialogOnPage:)];
m_delegateMethods.setUserInputForCurrentJavaScriptPromptOnPage = [delegate respondsToSelector:@selector(_automationSession:setUserInput:forCurrentJavaScriptDialogOnPage:)];
+ m_delegateMethods.typeOfCurrentJavaScriptDialogOnPage = [delegate respondsToSelector:@selector(_automationSession:typeOfCurrentJavaScriptDialogOnPage:)];
}
void AutomationSessionClient::didDisconnectFromRemote(WebAutomationSession& session)
@@ -64,7 +66,7 @@
[m_delegate.get() _automationSessionDidDisconnectFromRemote:wrapper(session)];
}
-// FIXME 28524687: support for WKPageRef-based delegate methods should be removed.
+// FIXME 37408718: support for WKPageRef-based delegate methods should be removed.
// Until these are removed, prefer to use the WKWebView delegate methods if implemented.
WebPageProxy* AutomationSessionClient::didRequestNewWindow(WebAutomationSession& session)
{
@@ -123,10 +125,27 @@
[m_delegate.get() _automationSession:wrapper(session) setUserInput:value forCurrentJavaScriptDialogOnPage:toAPI(&page)];
}
-std::optional<API::AutomationSessionClient::_javascript_DialogType> AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession&, WebPageProxy&)
+static std::optional<API::AutomationSessionClient::_javascript_DialogType> toImpl(_WKAutomationSessionJavaScriptDialogType type)
{
- // FIXME: Implement it. This is only used in WebAutomationSession::setUserInputForCurrentJavaScriptPrompt() so for now we return
- // always Prompt type for compatibility.
+ switch (type) {
+ case _WKAutomationSessionJavaScriptDialogTypeNone:
+ return std::nullopt;
+ case _WKAutomationSessionJavaScriptDialogTypePrompt:
+ return API::AutomationSessionClient::_javascript_DialogType::Prompt;
+ case _WKAutomationSessionJavaScriptDialogTypeConfirm:
+ return API::AutomationSessionClient::_javascript_DialogType::Confirm;
+ case _WKAutomationSessionJavaScriptDialogTypeAlert:
+ return API::AutomationSessionClient::_javascript_DialogType::Alert;
+ }
+}
+
+std::optional<API::AutomationSessionClient::_javascript_DialogType> AutomationSessionClient::typeOfCurrentJavaScriptDialogOnPage(WebAutomationSession& session, WebPageProxy& page)
+{
+ if (m_delegateMethods.typeOfCurrentJavaScriptDialogForWebView)
+ return toImpl([m_delegate.get() _automationSession:wrapper(session) typeOfCurrentJavaScriptDialogForWebView:fromWebPageProxy(page)]);
+ if (m_delegateMethods.typeOfCurrentJavaScriptDialogOnPage)
+ return toImpl([m_delegate.get() _automationSession:wrapper(session) typeOfCurrentJavaScriptDialogOnPage:toAPI(&page)]);
+
return API::AutomationSessionClient::_javascript_DialogType::Prompt;
}