Pressing the Escape key should not be a valid user gesture to enter fullscreen
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jul 2017 17:15:31 +0000 (17:15 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Jul 2017 17:15:31 +0000 (17:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174864
<rdar://problem/33009088>

Reviewed by Geoffrey Garen.

Source/WebCore:

Pressing the Escape key should not be a valid user gesture to enter fullscreen since this
is the gesture to exit fullscreen already.

Test: fullscreen/requestFullscreen-escape-key.html

* dom/Document.cpp:
(WebCore::Document::requestFullScreenForElement):
* dom/UserGestureIndicator.cpp:
(WebCore::UserGestureIndicator::UserGestureIndicator):
* dom/UserGestureIndicator.h:
(WebCore::UserGestureToken::create):
(WebCore::UserGestureToken::gestureType):
(WebCore::UserGestureToken::UserGestureToken):
* page/EventHandler.cpp:
(WebCore::EventHandler::internalKeyEvent):

Tools:

Add support for eventSender.keyDown('escape') in DRT to match the behavior of
WKTR.

* DumpRenderTree/mac/EventSendingController.mm:
(-[EventSendingController keyDown:withModifiers:withLocation:]):

LayoutTests:

Add layout test coverage.

* fullscreen/requestFullscreen-escape-key-expected.txt: Added.
* fullscreen/requestFullscreen-escape-key.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fullscreen/requestFullscreen-escape-key-expected.txt [new file with mode: 0644]
LayoutTests/fullscreen/requestFullscreen-escape-key.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/dom/UserGestureIndicator.cpp
Source/WebCore/dom/UserGestureIndicator.h
Source/WebCore/page/EventHandler.cpp
Tools/ChangeLog
Tools/DumpRenderTree/mac/EventSendingController.mm

index 1daf364..71b5342 100644 (file)
@@ -1,3 +1,16 @@
+2017-07-26  Chris Dumez  <cdumez@apple.com>
+
+        Pressing the Escape key should not be a valid user gesture to enter fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=174864
+        <rdar://problem/33009088>
+
+        Reviewed by Geoffrey Garen.
+
+        Add layout test coverage.
+
+        * fullscreen/requestFullscreen-escape-key-expected.txt: Added.
+        * fullscreen/requestFullscreen-escape-key.html: Added.
+
 2017-07-26  Nan Wang  <n_wang@apple.com>
 
         AX: Incorrect range from index and length in contenteditable with <p> tags
diff --git a/LayoutTests/fullscreen/requestFullscreen-escape-key-expected.txt b/LayoutTests/fullscreen/requestFullscreen-escape-key-expected.txt
new file mode 100644 (file)
index 0000000..e1b6478
--- /dev/null
@@ -0,0 +1,14 @@
+CONSOLE MESSAGE: line 11: The Escape key may not be used as a user gesture to enter fullscreen
+Tests that pressing the Escape key cannot be used as user interaction to enter fullscreen.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.webkitFullscreenEnabled is true
+Pressing Escape key....
+keydown - Requesting fullscreen
+PASS document.webkitFullscreenElement is null
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fullscreen/requestFullscreen-escape-key.html b/LayoutTests/fullscreen/requestFullscreen-escape-key.html
new file mode 100644 (file)
index 0000000..7bad0bb
--- /dev/null
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../resources/js-test.js"></script>
+<script>
+description("Tests that pressing the Escape key cannot be used as user interaction to enter fullscreen.");
+jsTestIsAsync = true;
+
+window.onkeydown = function(e) {
+    debug("keydown - Requesting fullscreen");
+    document.body.webkitRequestFullscreen();
+
+    setTimeout(function() {
+        shouldBeNull("document.webkitFullscreenElement");
+        finishJSTest();
+    }, 0);
+}
+
+onload = function() {
+    shouldBeTrue("document.webkitFullscreenEnabled");
+
+    debug("Pressing Escape key....");
+    if (window.eventSender)
+        eventSender.keyDown("escape");
+};
+</script>
+</body>
+</html>
index e8873e3..082b47d 100644 (file)
@@ -1,3 +1,27 @@
+2017-07-26  Chris Dumez  <cdumez@apple.com>
+
+        Pressing the Escape key should not be a valid user gesture to enter fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=174864
+        <rdar://problem/33009088>
+
+        Reviewed by Geoffrey Garen.
+
+        Pressing the Escape key should not be a valid user gesture to enter fullscreen since this
+        is the gesture to exit fullscreen already.
+
+        Test: fullscreen/requestFullscreen-escape-key.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::requestFullScreenForElement):
+        * dom/UserGestureIndicator.cpp:
+        (WebCore::UserGestureIndicator::UserGestureIndicator):
+        * dom/UserGestureIndicator.h:
+        (WebCore::UserGestureToken::create):
+        (WebCore::UserGestureToken::gestureType):
+        (WebCore::UserGestureToken::UserGestureToken):
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::internalKeyEvent):
+
 2017-07-26  Nan Wang  <n_wang@apple.com>
 
         AX: Incorrect range from index and length in contenteditable with <p> tags
index 67b36a8..31af776 100644 (file)
@@ -5785,9 +5785,16 @@ void Document::requestFullScreenForElement(Element* element, FullScreenCheckType
         //   An algorithm is allowed to show a pop-up if, in the task in which the algorithm is running, either:
         //   - an activation behavior is currently being processed whose click event was trusted, or
         //   - the event listener for a trusted click event is being handled.
-        if (!ScriptController::processingUserGesture())
+        if (!UserGestureIndicator::processingUserGesture())
             break;
 
+        // We do not allow pressing the Escape key as a user gesture to enter fullscreen since this is the key
+        // to exit fullscreen.
+        if (UserGestureIndicator::currentUserGesture()->gestureType() == UserGestureType::EscapeKey) {
+            addConsoleMessage(MessageSource::Security, MessageLevel::Error, ASCIILiteral("The Escape key may not be used as a user gesture to enter fullscreen"));
+            break;
+        }
+
         // There is a previously-established user preference, security risk, or platform limitation.
         if (!page() || !page()->settings().fullScreenEnabled())
             break;
index 0e0ab9e..4a5940d 100644 (file)
@@ -46,7 +46,7 @@ UserGestureToken::~UserGestureToken()
         observer(*this);
 }
 
-UserGestureIndicator::UserGestureIndicator(std::optional<ProcessingUserGestureState> state, Document* document)
+UserGestureIndicator::UserGestureIndicator(std::optional<ProcessingUserGestureState> state, Document* document, UserGestureType gestureType)
     : m_previousToken(currentToken())
 {
     // Silently ignore UserGestureIndicators on non main threads.
@@ -54,7 +54,7 @@ UserGestureIndicator::UserGestureIndicator(std::optional<ProcessingUserGestureSt
         return;
 
     if (state)
-        currentToken() = UserGestureToken::create(state.value());
+        currentToken() = UserGestureToken::create(state.value(), gestureType);
 
     if (document && currentToken()->processingUserGesture()) {
         document->updateLastHandledUserGestureTimestamp(MonotonicTime::now());
index f044f65..98bc0f0 100644 (file)
@@ -42,11 +42,13 @@ enum ProcessingUserGestureState {
     NotProcessingUserGesture
 };
 
+enum class UserGestureType { EscapeKey, Other };
+
 class UserGestureToken : public RefCounted<UserGestureToken> {
 public:
-    static RefPtr<UserGestureToken> create(ProcessingUserGestureState state)
+    static RefPtr<UserGestureToken> create(ProcessingUserGestureState state, UserGestureType gestureType)
     {
-        return adoptRef(new UserGestureToken(state));
+        return adoptRef(new UserGestureToken(state, gestureType));
     }
 
     WEBCORE_EXPORT ~UserGestureToken();
@@ -54,6 +56,7 @@ public:
     ProcessingUserGestureState state() const { return m_state; }
     bool processingUserGesture() const { return m_state == ProcessingUserGesture; }
     bool processingUserGestureForMedia() const { return m_state == ProcessingUserGesture || m_state == ProcessingPotentialUserGesture; }
+    UserGestureType gestureType() const { return m_gestureType; }
 
     void addDestructionObserver(WTF::Function<void (UserGestureToken&)>&& observer)
     {
@@ -61,13 +64,15 @@ public:
     }
 
 private:
-    UserGestureToken(ProcessingUserGestureState state)
+    UserGestureToken(ProcessingUserGestureState state, UserGestureType gestureType)
         : m_state(state)
+        , m_gestureType(gestureType)
     {
     }
 
     ProcessingUserGestureState m_state = NotProcessingUserGesture;
     Vector<WTF::Function<void (UserGestureToken&)>> m_destructionObservers;
+    UserGestureType m_gestureType;
 };
 
 class UserGestureIndicator {
@@ -79,7 +84,7 @@ public:
     WEBCORE_EXPORT static bool processingUserGestureForMedia();
 
     // If a document is provided, its last known user gesture timestamp is updated.
-    WEBCORE_EXPORT explicit UserGestureIndicator(std::optional<ProcessingUserGestureState>, Document* = nullptr);
+    WEBCORE_EXPORT explicit UserGestureIndicator(std::optional<ProcessingUserGestureState>, Document* = nullptr, UserGestureType = UserGestureType::Other);
     WEBCORE_EXPORT explicit UserGestureIndicator(RefPtr<UserGestureToken>);
     WEBCORE_EXPORT ~UserGestureIndicator();
 
index 617b325..7ef0bfa 100644 (file)
@@ -3170,7 +3170,11 @@ bool EventHandler::internalKeyEvent(const PlatformKeyboardEvent& initialKeyEvent
     if (!element)
         return false;
 
-    UserGestureIndicator gestureIndicator(ProcessingUserGesture, m_frame.document());
+    UserGestureType gestureType = UserGestureType::Other;
+    if (initialKeyEvent.windowsVirtualKeyCode() == VK_ESCAPE)
+        gestureType = UserGestureType::EscapeKey;
+
+    UserGestureIndicator gestureIndicator(ProcessingUserGesture, m_frame.document(), gestureType);
     UserTypingGestureIndicator typingGestureIndicator(m_frame);
 
     if (FrameView* view = m_frame.view())
index cfb8f2d..34dead2 100644 (file)
@@ -1,3 +1,17 @@
+2017-07-26  Chris Dumez  <cdumez@apple.com>
+
+        Pressing the Escape key should not be a valid user gesture to enter fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=174864
+        <rdar://problem/33009088>
+
+        Reviewed by Geoffrey Garen.
+
+        Add support for eventSender.keyDown('escape') in DRT to match the behavior of
+        WKTR.
+
+        * DumpRenderTree/mac/EventSendingController.mm:
+        (-[EventSendingController keyDown:withModifiers:withLocation:]):
+
 2017-07-26  Romain Bellessort  <romain.bellessort@crf.canon.fr>
 
         Unreviewed, added Romain Bellessort to contributors.json.
index a550970..38a6780 100644 (file)
@@ -934,6 +934,10 @@ static int buildModifierFlags(const WebScriptObject* modifiers)
         const unichar ch = NSDeleteFunctionKey;
         eventCharacter = [NSString stringWithCharacters:&ch length:1];
         keyCode = 0x75;
+    } else if ([character isEqualToString:@"escape"]) {
+        const unichar ch = 0x1B;
+        eventCharacter = [NSString stringWithCharacters:&ch length:1];
+        keyCode = 0x35;
     } else if ([character isEqualToString:@"printScreen"]) {
         const unichar ch = NSPrintScreenFunctionKey;
         eventCharacter = [NSString stringWithCharacters:&ch length:1];