Title: [198793] trunk/Source/WebKit2
- Revision
- 198793
- Author
- [email protected]
- Date
- 2016-03-29 13:19:51 -0700 (Tue, 29 Mar 2016)
Log Message
Web Automation: Add SPI to tell whether an NSEvent was synthesized for automation
https://bugs.webkit.org/show_bug.cgi?id=155963
<rdar://problem/25405747>
Reviewed by Timothy Hatcher.
Tag all NSEvents that were synthesized with an associated object before sending.
Do all associated object work below the API layer so we don't get into trouble
using things that may be guarded by WK_API_ENABLED.
* UIProcess/API/Cocoa/_WKAutomationSession.h:
* UIProcess/API/Cocoa/_WKAutomationSession.mm:
(-[_WKAutomationSession wasEventSynthesizedForAutomation:]):
Forward to the wrapped session object.
* UIProcess/Automation/WebAutomationSession.h:
* UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
(WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
Tag outgoing NSEvents with the session identifier as an associated object.
(WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
Check an incoming NSEvent to see if its associated object is the session identifier.
Modified Paths
Diff
Modified: trunk/Source/WebKit2/ChangeLog (198792 => 198793)
--- trunk/Source/WebKit2/ChangeLog 2016-03-29 20:19:45 UTC (rev 198792)
+++ trunk/Source/WebKit2/ChangeLog 2016-03-29 20:19:51 UTC (rev 198793)
@@ -1,3 +1,28 @@
+2016-03-29 Brian Burg <[email protected]>
+
+ Web Automation: Add SPI to tell whether an NSEvent was synthesized for automation
+ https://bugs.webkit.org/show_bug.cgi?id=155963
+ <rdar://problem/25405747>
+
+ Reviewed by Timothy Hatcher.
+
+ Tag all NSEvents that were synthesized with an associated object before sending.
+ Do all associated object work below the API layer so we don't get into trouble
+ using things that may be guarded by WK_API_ENABLED.
+
+ * UIProcess/API/Cocoa/_WKAutomationSession.h:
+ * UIProcess/API/Cocoa/_WKAutomationSession.mm:
+ (-[_WKAutomationSession wasEventSynthesizedForAutomation:]):
+ Forward to the wrapped session object.
+
+ * UIProcess/Automation/WebAutomationSession.h:
+ * UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
+ (WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
+ Tag outgoing NSEvents with the session identifier as an associated object.
+
+ (WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
+ Check an incoming NSEvent to see if its associated object is the session identifier.
+
2016-03-28 Brian Burg <[email protected]>
Web Automation: implement Automation.performMouseInteraction
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSession.h (198792 => 198793)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSession.h 2016-03-29 20:19:45 UTC (rev 198792)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSession.h 2016-03-29 20:19:51 UTC (rev 198793)
@@ -40,6 +40,8 @@
@property (nonatomic, weak) id <_WKAutomationSessionDelegate> delegate;
@property (nonatomic, readonly, getter=isPaired) BOOL paired;
+- (BOOL)wasEventSynthesizedForAutomation:(NSEvent *)event;
+
@end
NS_ASSUME_NONNULL_END
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSession.mm (198792 => 198793)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSession.mm 2016-03-29 20:19:45 UTC (rev 198792)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKAutomationSession.mm 2016-03-29 20:19:51 UTC (rev 198793)
@@ -83,6 +83,11 @@
return _session->isPaired();
}
+- (BOOL)wasEventSynthesizedForAutomation:(NSEvent *)event
+{
+ return _session->wasEventSynthesizedForAutomation(event);
+}
+
#pragma mark WKObject protocol implementation
- (API::Object&)_apiObject
Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (198792 => 198793)
--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h 2016-03-29 20:19:45 UTC (rev 198792)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h 2016-03-29 20:19:51 UTC (rev 198793)
@@ -54,6 +54,7 @@
#if USE(APPKIT)
OBJC_CLASS NSArray;
+OBJC_CLASS NSEvent;
#endif
namespace WebKit {
@@ -112,6 +113,10 @@
void messageOfCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, String* text) override;
void setUserInputForCurrentJavaScriptPrompt(Inspector::ErrorString&, const String& browsingContextHandle, const String& text) override;
+#if USE(APPKIT)
+ bool wasEventSynthesizedForAutomation(NSEvent *);
+#endif
+
private:
WebPageProxy* webPageProxyForHandle(const String&);
String handleForWebPageProxy(const WebPageProxy&);
Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm (198792 => 198793)
--- trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm 2016-03-29 20:19:45 UTC (rev 198792)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm 2016-03-29 20:19:51 UTC (rev 198793)
@@ -39,17 +39,24 @@
#if USE(APPKIT)
+static const void *synthesizedAutomationEventAssociatedObjectKey = &synthesizedAutomationEventAssociatedObjectKey;
+
void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArray *eventsToSend)
{
NSWindow *window = page.platformWindow();
for (NSEvent *event in eventsToSend) {
- // FIXME: <https://www.webkit.org/b/155963> Set an associated object with a per-session identifier.
- // This will allow a WebKit2 client to tell apart events synthesized on behalf of an automation command.
+ objc_setAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey, m_sessionIdentifier, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[window sendEvent:event];
}
}
+bool WebAutomationSession::wasEventSynthesizedForAutomation(NSEvent *event)
+{
+ NSString *senderSessionIdentifier = objc_getAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey);
+ return [senderSessionIdentifier isEqualToString:m_sessionIdentifier];
+}
+
void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction interaction, Inspector::Protocol::Automation::MouseButton button, WebEvent::Modifiers keyModifiers)
{
IntRect windowRect;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes