Changeset 251620 in webkit


Ignore:
Timestamp:
Oct 25, 2019 6:10:59 PM (4 years ago)
Author:
yurys@chromium.org
Message:

Web Inspector: support emulateUserGesture parameter in Runtime.callFunctionOn
https://bugs.webkit.org/show_bug.cgi?id=200262

Reviewed by Devin Rousso.

Source/JavaScriptCore:

  • inspector/agents/InspectorRuntimeAgent.cpp:

(Inspector::InspectorRuntimeAgent::callFunctionOn):

  • inspector/agents/InspectorRuntimeAgent.h:
  • inspector/protocol/Runtime.json:

Source/WebCore:

Support emulateUserGesture in Runtime.callFunctionOn

Tests: inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting.html

inspector/runtime/callFunctionOn-emulateUserGesture.html

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • inspector/agents/page/PageDebuggerAgent.cpp:

(WebCore::PageDebuggerAgent::evaluateOnCallFrame):

  • inspector/agents/page/PageRuntimeAgent.cpp:

(WebCore::asBool):
(WebCore::PageRuntimeAgent::evaluate):
(WebCore::PageRuntimeAgent::callFunctionOn):

  • inspector/agents/page/PageRuntimeAgent.h:
  • inspector/agents/page/UserGestureEmulationScope.cpp: Added.

(WebCore::UserGestureEmulationScope::UserGestureEmulationScope): Extracted logic
of overriding user gesture into the scope object to share it between evaluate and
callFunctionOn as well as PageDebuggerAgent::evaluateOnCallFrame.
(WebCore::UserGestureEmulationScope::~UserGestureEmulationScope):

  • inspector/agents/page/UserGestureEmulationScope.h: Added.

LayoutTests:

Supported emulateUserGesture in Runtime.callFunctionOn protocol command.

  • TestExpectations:
  • inspector/runtime/callFunctionOn-emulateUserGesture-expected.txt: Added.
  • inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting-expected.txt: Added.
  • inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting.html: Added.
  • inspector/runtime/callFunctionOn-emulateUserGesture.html: Added.
  • platform/wk2/TestExpectations:

Only enable the new test on WK2, as the user interaction state is only supported by WK2.

Location:
trunk
Files:
6 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r251619 r251620  
     12019-10-25  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: support emulateUserGesture parameter in Runtime.callFunctionOn
     4        https://bugs.webkit.org/show_bug.cgi?id=200262
     5
     6        Reviewed by Devin Rousso.
     7
     8        Supported emulateUserGesture in Runtime.callFunctionOn protocol command.
     9
     10        * TestExpectations:
     11        * inspector/runtime/callFunctionOn-emulateUserGesture-expected.txt: Added.
     12        * inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting-expected.txt: Added.
     13        * inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting.html: Added.
     14        * inspector/runtime/callFunctionOn-emulateUserGesture.html: Added.
     15        * platform/wk2/TestExpectations:
     16        Only enable the new test on WK2, as the user interaction state is only supported by WK2.
     17
    1182019-10-25  Megan Gardner  <megan_gardner@apple.com>
    219
  • trunk/LayoutTests/TestExpectations

    r251594 r251620  
    915915inspector/debugger/evaluateOnCallFrame-emulateUserGesture-userIsInteracting.html [ Skip ]
    916916inspector/runtime/evaluate-emulateUserGesture-userIsInteracting.html [ Skip ]
     917inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting.html [ Skip ]
    917918
    918919# Target domain is only present in WK2.
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r251606 r251620  
    22462246
    22472247webkit.org/b/149916 http/tests/inspector/dom/disconnect-dom-tree-after-main-frame-navigation.html [ Pass Slow ]
    2248 webkit.org/b/149916 inspector/codemirror/prettyprinting-css.html [ Pass Slow ]
    2249 webkit.org/b/149916 inspector/codemirror/prettyprinting-javascript.html [ Pass Slow ]
    22502248webkit.org/b/149916 inspector/console/clearMessages.html [ Pass Slow ]
    22512249webkit.org/b/149916 inspector/console/command-line-api.html [ Pass Slow ]
  • trunk/LayoutTests/platform/wk2/TestExpectations

    r251494 r251620  
    764764inspector/debugger/evaluateOnCallFrame-emulateUserGesture-userIsInteracting.html [ Pass ]
    765765inspector/runtime/evaluate-emulateUserGesture-userIsInteracting.html [ Pass ]
     766inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting.html [ Pass ]
    766767
    767768# Target domain is only present in WebKit2.
  • trunk/Source/JavaScriptCore/ChangeLog

    r251584 r251620  
     12019-10-25  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: support emulateUserGesture parameter in Runtime.callFunctionOn
     4        https://bugs.webkit.org/show_bug.cgi?id=200262
     5
     6        Reviewed by Devin Rousso.
     7
     8        * inspector/agents/InspectorRuntimeAgent.cpp:
     9        (Inspector::InspectorRuntimeAgent::callFunctionOn):
     10        * inspector/agents/InspectorRuntimeAgent.h:
     11        * inspector/protocol/Runtime.json:
     12
    1132019-10-24  Mark Lam  <mark.lam@apple.com>
    214
  • trunk/Source/JavaScriptCore/inspector/agents/InspectorRuntimeAgent.cpp

    r250087 r251620  
    156156}
    157157
    158 void InspectorRuntimeAgent::callFunctionOn(ErrorString& errorString, const String& objectId, const String& expression, const JSON::Array* optionalArguments, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, RefPtr<Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown)
     158void InspectorRuntimeAgent::callFunctionOn(ErrorString& errorString, const String& objectId, const String& expression, const JSON::Array* optionalArguments, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, const bool* /* emulateUserGesture */, RefPtr<Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown)
    159159{
    160160    InjectedScript injectedScript = m_injectedScriptManager.injectedScriptForObjectId(objectId);
  • trunk/Source/JavaScriptCore/inspector/agents/InspectorRuntimeAgent.h

    r250996 r251620  
    6464    void evaluate(ErrorString&, const String& expression, const String* objectGroup, const bool* includeCommandLineAPI, const bool* doNotPauseOnExceptionsAndMuteConsole, const int* executionContextId, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, const bool* emulateUserGesture, RefPtr<Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown, Optional<int>& savedResultIndex) override;
    6565    void awaitPromise(const String& promiseObjectId, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, Ref<AwaitPromiseCallback>&&) final;
    66     void callFunctionOn(ErrorString&, const String& objectId, const String& expression, const JSON::Array* optionalArguments, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, RefPtr<Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown) final;
     66    void callFunctionOn(ErrorString&, const String& objectId, const String& expression, const JSON::Array* optionalArguments, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, const bool* emulateUserGesture, RefPtr<Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown) override;
    6767    void releaseObject(ErrorString&, const ErrorString& objectId) final;
    6868    void getPreview(ErrorString&, const String& objectId, RefPtr<Protocol::Runtime::ObjectPreview>&) final;
  • trunk/Source/JavaScriptCore/inspector/protocol/Runtime.json

    r251227 r251620  
    254254                { "name": "doNotPauseOnExceptionsAndMuteConsole", "type": "boolean", "optional": true, "description": "Specifies whether function call should stop on exceptions and mute console. Overrides setPauseOnException state." },
    255255                { "name": "returnByValue", "type": "boolean", "optional": true, "description": "Whether the result is expected to be a JSON object which should be sent by value." },
    256                 { "name": "generatePreview", "type": "boolean", "optional": true, "description": "Whether preview should be generated for the result." }
     256                { "name": "generatePreview", "type": "boolean", "optional": true, "description": "Whether preview should be generated for the result." },
     257                { "name": "emulateUserGesture", "type": "boolean", "optional": true, "description": "Whether the expression should be considered to be in a user gesture or not." }
    257258            ],
    258259            "returns": [
  • trunk/Source/WebCore/ChangeLog

    r251617 r251620  
     12019-10-25  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Web Inspector: support emulateUserGesture parameter in Runtime.callFunctionOn
     4        https://bugs.webkit.org/show_bug.cgi?id=200262
     5
     6        Reviewed by Devin Rousso.
     7
     8        Support emulateUserGesture in Runtime.callFunctionOn
     9
     10        Tests: inspector/runtime/callFunctionOn-emulateUserGesture-userIsInteracting.html
     11               inspector/runtime/callFunctionOn-emulateUserGesture.html
     12
     13        * Sources.txt:
     14        * WebCore.xcodeproj/project.pbxproj:
     15        * inspector/agents/page/PageDebuggerAgent.cpp:
     16        (WebCore::PageDebuggerAgent::evaluateOnCallFrame):
     17        * inspector/agents/page/PageRuntimeAgent.cpp:
     18        (WebCore::asBool):
     19        (WebCore::PageRuntimeAgent::evaluate):
     20        (WebCore::PageRuntimeAgent::callFunctionOn):
     21        * inspector/agents/page/PageRuntimeAgent.h:
     22        * inspector/agents/page/UserGestureEmulationScope.cpp: Added.
     23        (WebCore::UserGestureEmulationScope::UserGestureEmulationScope): Extracted logic
     24        of overriding user gesture into the scope object to share it between evaluate and
     25        callFunctionOn as well as PageDebuggerAgent::evaluateOnCallFrame.
     26        (WebCore::UserGestureEmulationScope::~UserGestureEmulationScope):
     27        * inspector/agents/page/UserGestureEmulationScope.h: Added.
     28
    1292019-10-25  Zalan Bujtas  <zalan@apple.com>
    230
  • trunk/Source/WebCore/Sources.txt

    r251590 r251620  
    14051405inspector/agents/page/PageNetworkAgent.cpp
    14061406inspector/agents/page/PageRuntimeAgent.cpp
     1407inspector/agents/page/UserGestureEmulationScope.cpp
    14071408
    14081409inspector/agents/worker/ServiceWorkerAgent.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r251590 r251620  
    48824882                F12171F516A8CED2000053CA /* WebVTTElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F12171F316A8BC63000053CA /* WebVTTElement.cpp */; };
    48834883                F12171F616A8CF0B000053CA /* WebVTTElement.h in Headers */ = {isa = PBXBuildFile; fileRef = F12171F416A8BC63000053CA /* WebVTTElement.h */; };
     4884                F32BDCD92363AACA0073B6AE /* UserGestureEmulationScope.h in Headers */ = {isa = PBXBuildFile; fileRef = F32BDCD72363AACA0073B6AE /* UserGestureEmulationScope.h */; };
    48844885                F344C7141125B82C00F26EEE /* InspectorFrontendClient.h in Headers */ = {isa = PBXBuildFile; fileRef = F344C7121125B82C00F26EEE /* InspectorFrontendClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
    48854886                F344C75311294D9D00F26EEE /* InspectorFrontendClientLocal.h in Headers */ = {isa = PBXBuildFile; fileRef = F344C75211294D9D00F26EEE /* InspectorFrontendClientLocal.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1524115242                F12171F316A8BC63000053CA /* WebVTTElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebVTTElement.cpp; sourceTree = "<group>"; };
    1524215243                F12171F416A8BC63000053CA /* WebVTTElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVTTElement.h; sourceTree = "<group>"; };
     15244                F32BDCD52363AAC90073B6AE /* UserGestureEmulationScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UserGestureEmulationScope.cpp; sourceTree = "<group>"; };
     15245                F32BDCD72363AACA0073B6AE /* UserGestureEmulationScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserGestureEmulationScope.h; sourceTree = "<group>"; };
    1524315246                F344C7121125B82C00F26EEE /* InspectorFrontendClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendClient.h; sourceTree = "<group>"; };
    1524415247                F344C75211294D9D00F26EEE /* InspectorFrontendClientLocal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendClientLocal.h; sourceTree = "<group>"; };
     
    2278022783                                A5B81CC11FAA44B70037D1E6 /* PageRuntimeAgent.cpp */,
    2278122784                                A5B81CBF1FAA44B70037D1E6 /* PageRuntimeAgent.h */,
     22785                                F32BDCD52363AAC90073B6AE /* UserGestureEmulationScope.cpp */,
     22786                                F32BDCD72363AACA0073B6AE /* UserGestureEmulationScope.h */,
    2278222787                        );
    2278322788                        path = page;
     
    3246632471                                003F1FEA11E6AB43008258D9 /* UserContentTypes.h in Headers */,
    3246732472                                BCACF3BD1072921A00C0C8A3 /* UserContentURLPattern.h in Headers */,
     32473                                F32BDCD92363AACA0073B6AE /* UserGestureEmulationScope.h in Headers */,
    3246832474                                2542F4DB1166C25A00E89A86 /* UserGestureIndicator.h in Headers */,
    3246932475                                9920398318B95BC600B39AF9 /* UserInputBridge.h in Headers */,
  • trunk/Source/WebCore/inspector/agents/page/PageDebuggerAgent.cpp

    r251531 r251620  
    3434
    3535#include "CachedResource.h"
    36 #include "Chrome.h"
    37 #include "ChromeClient.h"
    3836#include "Document.h"
    3937#include "Frame.h"
     
    4543#include "ScriptExecutionContext.h"
    4644#include "ScriptState.h"
    47 #include "UserGestureIndicator.h"
     45#include "UserGestureEmulationScope.h"
    4846#include <JavaScriptCore/InjectedScript.h>
    4947#include <JavaScriptCore/InjectedScriptManager.h>
     
    7270void PageDebuggerAgent::evaluateOnCallFrame(ErrorString& errorString, const String& callFrameId, const String& expression, const String* objectGroup, const bool* includeCommandLineAPI, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, const bool* emulateUserGesture, RefPtr<Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown, Optional<int>& savedResultIndex)
    7371{
    74     auto& pageChromeClient = m_inspectedPage.chrome().client();
    75 
    7672    auto shouldEmulateUserGesture = emulateUserGesture && *emulateUserGesture;
    77 
    78     Optional<ProcessingUserGestureState> userGestureState = shouldEmulateUserGesture ? Optional<ProcessingUserGestureState>(ProcessingUserGesture) : WTF::nullopt;
    79     UserGestureIndicator gestureIndicator(userGestureState);
    80 
    81     bool userWasInteracting = false;
    82     if (shouldEmulateUserGesture) {
    83         userWasInteracting = pageChromeClient.userIsInteracting();
    84         if (!userWasInteracting)
    85             pageChromeClient.setUserIsInteracting(true);
    86     }
     73    UserGestureEmulationScope userGestureScope(m_inspectedPage, shouldEmulateUserGesture);
    8774
    8875    WebDebuggerAgent::evaluateOnCallFrame(errorString, callFrameId, expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, saveResult, emulateUserGesture, result, wasThrown, savedResultIndex);
    89 
    90     if (shouldEmulateUserGesture && !userWasInteracting && pageChromeClient.userIsInteracting())
    91         pageChromeClient.setUserIsInteracting(false);
    9276}
    9377
  • trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.cpp

    r251531 r251620  
    3333#include "PageRuntimeAgent.h"
    3434
    35 #include "Chrome.h"
    36 #include "ChromeClient.h"
    3735#include "Document.h"
    3836#include "Frame.h"
     
    4543#include "ScriptState.h"
    4644#include "SecurityOrigin.h"
    47 #include "UserGestureIndicator.h"
     45#include "UserGestureEmulationScope.h"
    4846#include <JavaScriptCore/InjectedScript.h>
    4947#include <JavaScriptCore/InjectedScriptManager.h>
     
    5149using Inspector::Protocol::Runtime::ExecutionContextDescription;
    5250
    53 
    5451namespace WebCore {
    5552
    5653using namespace Inspector;
     54
     55static bool asBool(const bool* b)
     56{
     57    return b && *b;
     58}
    5759
    5860PageRuntimeAgent::PageRuntimeAgent(PageAgentContext& context)
     
    167169void PageRuntimeAgent::evaluate(ErrorString& errorString, const String& expression, const String* objectGroup, const bool* includeCommandLineAPI, const bool* doNotPauseOnExceptionsAndMuteConsole, const int* executionContextId, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, const bool* emulateUserGesture, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown, Optional<int>& savedResultIndex)
    168170{
    169     auto& pageChromeClient = m_inspectedPage.chrome().client();
     171    UserGestureEmulationScope userGestureScope(m_inspectedPage, asBool(emulateUserGesture));
     172    InspectorRuntimeAgent::evaluate(errorString, expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, executionContextId, returnByValue, generatePreview, saveResult, emulateUserGesture, result, wasThrown, savedResultIndex);
     173}
    170174
    171     auto shouldEmulateUserGesture = emulateUserGesture && *emulateUserGesture;
    172 
    173     Optional<ProcessingUserGestureState> userGestureState = shouldEmulateUserGesture ? Optional<ProcessingUserGestureState>(ProcessingUserGesture) : WTF::nullopt;
    174     UserGestureIndicator gestureIndicator(userGestureState);
    175 
    176     bool userWasInteracting = false;
    177     if (shouldEmulateUserGesture) {
    178         userWasInteracting = pageChromeClient.userIsInteracting();
    179         if (!userWasInteracting)
    180             pageChromeClient.setUserIsInteracting(true);
    181     }
    182 
    183     InspectorRuntimeAgent::evaluate(errorString, expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, executionContextId, returnByValue, generatePreview, saveResult, emulateUserGesture, result, wasThrown, savedResultIndex);
    184 
    185     if (shouldEmulateUserGesture && !userWasInteracting && pageChromeClient.userIsInteracting())
    186         pageChromeClient.setUserIsInteracting(false);
     175void PageRuntimeAgent::callFunctionOn(ErrorString& errorString, const String& objectId, const String& expression, const JSON::Array* optionalArguments, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, const bool* emulateUserGesture, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown)
     176{
     177    UserGestureEmulationScope userGestureScope(m_inspectedPage, asBool(emulateUserGesture));
     178    InspectorRuntimeAgent::callFunctionOn(errorString, objectId, expression, optionalArguments, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, emulateUserGesture, result, wasThrown);
    187179}
    188180
  • trunk/Source/WebCore/inspector/agents/page/PageRuntimeAgent.h

    r251531 r251620  
    5858    void disable(ErrorString&) override;
    5959    void evaluate(ErrorString&, const String& expression, const String* objectGroup, const bool* includeCommandLineAPI, const bool* doNotPauseOnExceptionsAndMuteConsole, const int* executionContextId, const bool* returnByValue, const bool* generatePreview, const bool* saveResult, const bool* emulateUserGesture, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown, Optional<int>& savedResultIndex) override;
     60    void callFunctionOn(ErrorString&, const String& objectId, const String& expression, const JSON::Array* optionalArguments, const bool* doNotPauseOnExceptionsAndMuteConsole, const bool* returnByValue, const bool* generatePreview, const bool* emulateUserGesture, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result, Optional<bool>& wasThrown) override;
    6061
    6162    // InspectorInstrumentation
Note: See TracChangeset for help on using the changeset viewer.