Changeset 200702 in webkit


Ignore:
Timestamp:
May 11, 2016 1:57:08 PM (8 years ago)
Author:
BJ Burg
Message:

Web Automation: add command to asynchronously load the Web Inspector frontend in the background
https://bugs.webkit.org/show_bug.cgi?id=157509

Reviewed by Timothy Hatcher and Joseph Pecoraro.

In order to make it easier to debug code that executes as a result of an automation
command, this patch adds a new Automation command to asynchronously load the debugger
and Inspector frontend. It is designed for use by automation clients to implement an
auto-inspection feature to aid in debugging automation scripts.

  • UIProcess/Automation/Automation.json: Add new command.
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::inspectBrowsingContext): Added.
(WebKit::WebAutomationSession::inspectorFrontendLoaded): Added.
This message is forwarded by WebInspectorProxy to the inspected page's session.

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/Cocoa/WebAutomationSessionCocoa.mm:

(WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
Force the active automation window to become key and bring to front prior to
sending each NSEvent. This way, if the Inspector pauses while a command executes,
the automation window will get back focus when the Inspector unpauses just before
the next synthesized mouse or keyboard NSEvent is sent to its NSWindow.

  • UIProcess/WebInspectorProxy.cpp:

(WebKit::WebInspectorProxy::frontendLoaded):
Forward to the inspected page's session.

  • UIProcess/WebInspectorProxy.h:
  • UIProcess/WebInspectorProxy.messages.in: Add notification of the frontend's load.
  • WebProcess/WebPage/WebInspectorUI.cpp:

(WebKit::WebInspectorUI::frontendLoaded):
Kick off notifying the automation session in UIProcess that the inspector loaded.

(WebKit::WebInspectorUI::closeWindow):
In some circumstances, the Web Inspector can be loaded without showing
the window. If this hidden page closes, make sure the frontend host gets
a chance to disconnect its InspectorFrontendClient. Normally this happens
when the window closes, but unshown Inspectors do not get window instances.

Location:
trunk/Source/WebKit2
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r200696 r200702  
     12016-05-10  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: add command to asynchronously load the Web Inspector frontend in the background
     4        https://bugs.webkit.org/show_bug.cgi?id=157509
     5
     6        Reviewed by Timothy Hatcher and Joseph Pecoraro.
     7
     8        In order to make it easier to debug code that executes as a result of an automation
     9        command, this patch adds a new Automation command to asynchronously load the debugger
     10        and Inspector frontend. It is designed for use by automation clients to implement an
     11        auto-inspection feature to aid in debugging automation scripts.
     12
     13        * UIProcess/Automation/Automation.json: Add new command.
     14        * UIProcess/Automation/WebAutomationSession.cpp:
     15        (WebKit::WebAutomationSession::inspectBrowsingContext): Added.
     16        (WebKit::WebAutomationSession::inspectorFrontendLoaded): Added.
     17        This message is forwarded by WebInspectorProxy to the inspected page's session.
     18
     19        * UIProcess/Automation/WebAutomationSession.h:
     20        * UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
     21        (WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
     22        Force the active automation window to become key and bring to front prior to
     23        sending each NSEvent. This way, if the Inspector pauses while a command executes,
     24        the automation window will get back focus when the Inspector unpauses just before
     25        the next synthesized mouse or keyboard NSEvent is sent to its NSWindow.
     26
     27        * UIProcess/WebInspectorProxy.cpp:
     28        (WebKit::WebInspectorProxy::frontendLoaded):
     29        Forward to the inspected page's session.
     30
     31        * UIProcess/WebInspectorProxy.h:
     32        * UIProcess/WebInspectorProxy.messages.in: Add notification of the frontend's load.
     33
     34        * WebProcess/WebPage/WebInspectorUI.cpp:
     35        (WebKit::WebInspectorUI::frontendLoaded):
     36        Kick off notifying the automation session in UIProcess that the inspector loaded.
     37
     38        (WebKit::WebInspectorUI::closeWindow):
     39        In some circumstances, the Web Inspector can be loaded without showing
     40        the window. If this hidden page closes, make sure the frontend host gets
     41        a chance to disconnect its InspectorFrontendClient. Normally this happens
     42        when the window closes, but unshown Inspectors do not get window instances.
     43
    1442016-05-11  Chris Dumez  <cdumez@apple.com>
    245
  • trunk/Source/WebKit2/UIProcess/Automation/Automation.json

    r199197 r200702  
    295295        },
    296296        {
     297            "name": "inspectBrowsingContext",
     298            "description": "Inspect the specified browsing context using Web Inspector.",
     299            "parameters": [
     300                { "name": "handle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context that should be inspected." }
     301            ],
     302            "async": true
     303        },
     304        {
    297305            "name": "evaluateJavaScriptFunction",
    298306            "description": "Evaluates a script function in a browsing context and calls it with the supplied arguments.",
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r200274 r200702  
    3232#include "WebAutomationSessionProxyMessages.h"
    3333#include "WebCookieManagerProxy.h"
     34#include "WebInspectorProxy.h"
    3435#include "WebProcessPool.h"
    3536#include <JavaScriptCore/InspectorBackendDispatcher.h>
     
    433434}
    434435
     436void WebAutomationSession::inspectBrowsingContext(Inspector::ErrorString& errorString, const String& handle, Ref<InspectBrowsingContextCallback>&& callback)
     437{
     438    WebPageProxy* page = webPageProxyForHandle(handle);
     439    if (!page)
     440        FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
     441
     442    if (auto callback = m_pendingInspectorCallbacksPerPage.take(page->pageID()))
     443        callback->sendFailure(STRING_FOR_PREDEFINED_ERROR_NAME(Timeout));
     444    m_pendingInspectorCallbacksPerPage.set(page->pageID(), WTFMove(callback));
     445
     446    // Don't bring the inspector to front since this may be done automatically.
     447    // We just want it loaded so it can pause if a breakpoint is hit during a command.
     448    if (page->inspector())
     449        page->inspector()->connect();
     450}
     451
    435452void WebAutomationSession::navigationOccurredForPage(const WebPageProxy& page)
    436453{
    437454    if (auto callback = m_pendingNavigationInBrowsingContextCallbacksPerPage.take(page.pageID()))
     455        callback->sendSuccess(InspectorObject::create());
     456}
     457
     458void WebAutomationSession::inspectorFrontendLoaded(const WebPageProxy& page)
     459{
     460    if (auto callback = m_pendingInspectorCallbacksPerPage.take(page.pageID()))
    438461        callback->sendSuccess(InspectorObject::create());
    439462}
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r200280 r200702  
    8484
    8585    void navigationOccurredForPage(const WebPageProxy&);
     86    void inspectorFrontendLoaded(const WebPageProxy&);
    8687
    8788#if ENABLE(REMOTE_INSPECTOR)
     
    105106    void goForwardInBrowsingContext(Inspector::ErrorString&, const String&, Ref<GoForwardInBrowsingContextCallback>&&) override;
    106107    void reloadBrowsingContext(Inspector::ErrorString&, const String&, Ref<ReloadBrowsingContextCallback>&&) override;
     108    void inspectBrowsingContext(Inspector::ErrorString&, const String&, Ref<InspectBrowsingContextCallback>&&) override;
    107109    void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, const bool* optionalExpectsImplicitCallbackArgument, const int* optionalCallbackTimeout, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
    108110    void performMouseInteraction(Inspector::ErrorString&, const String& handle, const Inspector::InspectorObject& requestedPosition, const String& mouseButton, const String& mouseInteraction, const Inspector::InspectorArray& keyModifiers, RefPtr<Inspector::Protocol::Automation::Point>& updatedPosition) override;
     
    177179    HashMap<uint64_t, RefPtr<Inspector::BackendDispatcher::CallbackBase>> m_pendingNavigationInBrowsingContextCallbacksPerPage;
    178180
     181    HashMap<uint64_t, RefPtr<Inspector::BackendDispatcher::CallbackBase>> m_pendingInspectorCallbacksPerPage;
     182
    179183    uint64_t m_nextEvaluateJavaScriptCallbackID { 1 };
    180184    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>> m_evaluateJavaScriptFunctionCallbacks;
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm

    r200280 r200702  
    5252
    5353    for (NSEvent *event in eventsToSend) {
     54        // Take focus back in case the Inspector became focused while the prior command or
     55        // NSEvent was delivered to the window.
     56        [window makeKeyAndOrderFront:nil];
     57
    5458        markEventAsSynthesizedForAutomation(event);
    5559        [window sendEvent:event];
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.cpp

    r199380 r200702  
    3333#include "WKContextMenuItem.h"
    3434#include "WKMutableArray.h"
     35#include "WebAutomationSession.h"
    3536#include "WebFramePolicyListenerProxy.h"
    3637#include "WebFrameProxy.h"
     
    602603}
    603604
     605void WebInspectorProxy::frontendLoaded()
     606{
     607    if (auto* automationSession = m_inspectedPage->process().processPool().automationSession())
     608        automationSession->inspectorFrontendLoaded(*m_inspectedPage);
     609}
     610
    604611void WebInspectorProxy::bringToFront()
    605612{
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.h

    r199380 r200702  
    191191    // Called by WebInspectorProxy messages
    192192    void createInspectorPage(IPC::Attachment, bool canAttach, bool underTest);
     193    void frontendLoaded();
    193194    void didClose();
    194195    void bringToFront();
  • trunk/Source/WebKit2/UIProcess/WebInspectorProxy.messages.in

    r199380 r200702  
    2424    CreateInspectorPage(IPC::Attachment connectionIdentifier, bool canAttach, bool underTest)
    2525
     26    FrontendLoaded()
    2627    DidClose()
    2728    BringToFront()
  • trunk/Source/WebKit2/WebProcess/WebPage/WebInspectorUI.cpp

    r200276 r200702  
    9797    setDockSide(m_dockSide);
    9898
     99    WebProcess::singleton().parentProcessConnection()->send(Messages::WebInspectorProxy::FrontendLoaded(), m_inspectedPageIdentifier);
     100
    99101    bringToFront();
    100102}
     
    128130        m_frontendController->setInspectorFrontendClient(nullptr);
    129131    m_frontendController = nullptr;
     132
     133    if (m_frontendHost)
     134        m_frontendHost->disconnectClient();
    130135
    131136    m_inspectedPageIdentifier = 0;
Note: See TracChangeset for help on using the changeset viewer.