Changeset 141555 in webkit


Ignore:
Timestamp:
Feb 1, 2013 12:50:19 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Add support for handling modal dialogs
https://bugs.webkit.org/show_bug.cgi?id=107883

Patch by Ken Kania <kkania@chromium.org> on 2013-02-01
Reviewed by Pavel Feldman.

Introduce support for being notified when a JavaScript modal dialog
is opening and closing, as well as a new command for accepting or
dismissing the dialog.

Source/WebCore:

Test: inspector-protocol/page/willRunJavaScriptDialog.html

  • inspector/Inspector.json:
  • inspector/InspectorClient.h:

(WebCore::InspectorClient::handleJavaScriptDialog):
(InspectorClient):

  • inspector/InspectorInstrumentation.cpp:

(WebCore):
(WebCore::InspectorInstrumentation::willRunJavaScriptDialogImpl):
(WebCore::InspectorInstrumentation::didRunJavaScriptDialogImpl):

  • inspector/InspectorInstrumentation.h:

(InspectorInstrumentation):
(WebCore::InspectorInstrumentation::willRunJavaScriptDialog):
(WebCore):
(WebCore::InspectorInstrumentation::didRunJavaScriptDialog):

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::willRunJavaScriptDialog):
(WebCore):
(WebCore::InspectorPageAgent::didRunJavaScriptDialog):
(WebCore::InspectorPageAgent::handleJavaScriptDialog):

  • inspector/InspectorPageAgent.h:
  • inspector/front-end/ResourceTreeModel.js:

(WebInspector.PageDispatcher.prototype.frameStartedLoading):
(WebInspector.PageDispatcher.prototype.frameStoppedLoading):
(WebInspector.PageDispatcher.prototype.frameScheduledNavigation):
(WebInspector.PageDispatcher.prototype.frameClearedScheduledNavigation):
(WebInspector.PageDispatcher.prototype.javascriptDialogOpening):
(WebInspector.PageDispatcher.prototype.javascriptDialogClosed):

  • page/Chrome.cpp:

(WebCore::Chrome::runBeforeUnloadConfirmPanel):
(WebCore::Chrome::runJavaScriptAlert):
(WebCore::Chrome::runJavaScriptConfirm):
(WebCore::Chrome::runJavaScriptPrompt):

Source/WebKit/chromium:

  • public/WebDevToolsAgent.h:
  • src/InspectorClientImpl.cpp:

(WebKit::InspectorClientImpl::handleJavaScriptDialog):
(WebKit):

  • src/InspectorClientImpl.h:

(InspectorClientImpl):

  • src/WebDevToolsAgentImpl.cpp:

(BrowserDataHintStringValues):
(WebKit::WebDevToolsAgentImpl::captureScreenshot):
(WebKit::WebDevToolsAgentImpl::handleJavaScriptDialog):
(WebKit):
(WebKit::browserHintToString):
(WebKit::browserHintFromString):
(WebKit::WebDevToolsAgent::patchWithBrowserData):

  • src/WebDevToolsAgentImpl.h:

(WebDevToolsAgentImpl):

LayoutTests:

  • inspector-protocol/page/javascriptDialogEvents-expected.txt: Added.
  • inspector-protocol/page/javascriptDialogEvents.html: Added.
Location:
trunk
Files:
2 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r141552 r141555  
     12013-02-01  Ken Kania  <kkania@chromium.org>
     2
     3        Web Inspector: Add support for handling modal dialogs
     4        https://bugs.webkit.org/show_bug.cgi?id=107883
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Introduce support for being notified when a JavaScript modal dialog
     9        is opening and closing, as well as a new command for accepting or
     10        dismissing the dialog.
     11
     12        * inspector-protocol/page/javascriptDialogEvents-expected.txt: Added.
     13        * inspector-protocol/page/javascriptDialogEvents.html: Added.
     14
    1152013-02-01  Hajime Morrita  <morrita@google.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r141554 r141555  
     12013-02-01  Ken Kania  <kkania@chromium.org>
     2
     3        Web Inspector: Add support for handling modal dialogs
     4        https://bugs.webkit.org/show_bug.cgi?id=107883
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Introduce support for being notified when a JavaScript modal dialog
     9        is opening and closing, as well as a new command for accepting or
     10        dismissing the dialog.
     11
     12        Test: inspector-protocol/page/willRunJavaScriptDialog.html
     13
     14        * inspector/Inspector.json:
     15        * inspector/InspectorClient.h:
     16        (WebCore::InspectorClient::handleJavaScriptDialog):
     17        (InspectorClient):
     18        * inspector/InspectorInstrumentation.cpp:
     19        (WebCore):
     20        (WebCore::InspectorInstrumentation::willRunJavaScriptDialogImpl):
     21        (WebCore::InspectorInstrumentation::didRunJavaScriptDialogImpl):
     22        * inspector/InspectorInstrumentation.h:
     23        (InspectorInstrumentation):
     24        (WebCore::InspectorInstrumentation::willRunJavaScriptDialog):
     25        (WebCore):
     26        (WebCore::InspectorInstrumentation::didRunJavaScriptDialog):
     27        * inspector/InspectorPageAgent.cpp:
     28        (WebCore::InspectorPageAgent::willRunJavaScriptDialog):
     29        (WebCore):
     30        (WebCore::InspectorPageAgent::didRunJavaScriptDialog):
     31        (WebCore::InspectorPageAgent::handleJavaScriptDialog):
     32        * inspector/InspectorPageAgent.h:
     33        * inspector/front-end/ResourceTreeModel.js:
     34        (WebInspector.PageDispatcher.prototype.frameStartedLoading):
     35        (WebInspector.PageDispatcher.prototype.frameStoppedLoading):
     36        (WebInspector.PageDispatcher.prototype.frameScheduledNavigation):
     37        (WebInspector.PageDispatcher.prototype.frameClearedScheduledNavigation):
     38        (WebInspector.PageDispatcher.prototype.javascriptDialogOpening):
     39        (WebInspector.PageDispatcher.prototype.javascriptDialogClosed):
     40        * page/Chrome.cpp:
     41        (WebCore::Chrome::runBeforeUnloadConfirmPanel):
     42        (WebCore::Chrome::runJavaScriptAlert):
     43        (WebCore::Chrome::runJavaScriptConfirm):
     44        (WebCore::Chrome::runJavaScriptPrompt):
     45
    1462013-02-01  Dan Alcantara  <dfalcantara@chromium.org>
    247
  • trunk/Source/WebCore/inspector/Inspector.json

    r141403 r141555  
    481481                ],
    482482                "hidden": true
     483            },
     484            {
     485                "name": "handleJavaScriptDialog",
     486                "description": "Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).",
     487                "parameters": [
     488                    { "name": "accept", "type": "boolean", "description": "Whether to accept or dismiss the dialog." }
     489                ],
     490                "hidden": true
    483491            }
    484492        ],
     
    543551                    { "name": "frameId", "$ref": "Network.FrameId", "description": "Id of the frame that has cleared its scheduled navigation." }
    544552                ],
     553                "hidden": true
     554            },
     555            {
     556                "name": "javascriptDialogOpening",
     557                "description": "Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) is about to open.",
     558                "parameters": [
     559                    { "name": "message", "type": "string", "description": "Message that will be displayed by the dialog." }
     560                ],
     561                "hidden": true
     562            },
     563            {
     564                "name": "javascriptDialogClosed",
     565                "description": "Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) has been closed.",
    545566                "hidden": true
    546567            }
  • trunk/Source/WebCore/inspector/InspectorClient.h

    r140798 r141555  
    8787    virtual bool captureScreenshot(String*) { return false; }
    8888
     89    virtual bool handleJavaScriptDialog(bool) { return false; }
     90
    8991    static bool doDispatchMessageOnFrontendPage(Page* frontendPage, const String& message);
    9092};
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r141098 r141555  
    978978}
    979979
     980InspectorInstrumentationCookie InspectorInstrumentation::willRunJavaScriptDialogImpl(InstrumentingAgents* instrumentingAgents, const String& message)
     981{
     982    if (InspectorPageAgent* inspectorPageAgent = instrumentingAgents->inspectorPageAgent())
     983        inspectorPageAgent->willRunJavaScriptDialog(message);
     984    return InspectorInstrumentationCookie(instrumentingAgents, 0);
     985}
     986
     987void InspectorInstrumentation::didRunJavaScriptDialogImpl(const InspectorInstrumentationCookie& cookie)
     988{
     989    if (InspectorPageAgent* inspectorPageAgent = cookie.instrumentingAgents()->inspectorPageAgent())
     990        inspectorPageAgent->didRunJavaScriptDialog();
     991}
     992
    980993void InspectorInstrumentation::willDestroyCachedResourceImpl(CachedResource* cachedResource)
    981994{
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r140649 r141555  
    216216    static void frameScheduledNavigation(Frame*, double delay);
    217217    static void frameClearedScheduledNavigation(Frame*);
     218    static InspectorInstrumentationCookie willRunJavaScriptDialog(Page*, const String& message);
     219    static void didRunJavaScriptDialog(const InspectorInstrumentationCookie&);
    218220    static void willDestroyCachedResource(CachedResource*);
    219221
     
    419421    static void frameScheduledNavigationImpl(InstrumentingAgents*, Frame*, double delay);
    420422    static void frameClearedScheduledNavigationImpl(InstrumentingAgents*, Frame*);
     423    static InspectorInstrumentationCookie willRunJavaScriptDialogImpl(InstrumentingAgents*, const String& message);
     424    static void didRunJavaScriptDialogImpl(const InspectorInstrumentationCookie&);
    421425    static void willDestroyCachedResourceImpl(CachedResource*);
    422426
     
    17131717}
    17141718
     1719inline InspectorInstrumentationCookie InspectorInstrumentation::willRunJavaScriptDialog(Page* page, const String& message)
     1720{
     1721#if ENABLE(INSPECTOR)
     1722    FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
     1723    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForPage(page))
     1724        return willRunJavaScriptDialogImpl(instrumentingAgents, message);
     1725#else
     1726    UNUSED_PARAM(page);
     1727    UNUSED_PARAM(message);
     1728#endif
     1729    return InspectorInstrumentationCookie();
     1730}
     1731
     1732inline void InspectorInstrumentation::didRunJavaScriptDialog(const InspectorInstrumentationCookie& cookie)
     1733{
     1734#if ENABLE(INSPECTOR)
     1735    FAST_RETURN_IF_NO_FRONTENDS(void());
     1736    if (cookie.isValid())
     1737        didRunJavaScriptDialogImpl(cookie);
     1738#else
     1739    UNUSED_PARAM(cookie);
     1740#endif
     1741}
     1742
    17151743inline void InspectorInstrumentation::willDestroyCachedResource(CachedResource* cachedResource)
    17161744{
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r141403 r141555  
    942942}
    943943
     944void InspectorPageAgent::willRunJavaScriptDialog(const String& message)
     945{
     946    m_frontend->javascriptDialogOpening(message);
     947}
     948
     949void InspectorPageAgent::didRunJavaScriptDialog()
     950{
     951    m_frontend->javascriptDialogClosed();
     952}
     953
    944954void InspectorPageAgent::applyScreenWidthOverride(long* width)
    945955{
     
    12411251}
    12421252
     1253void InspectorPageAgent::handleJavaScriptDialog(ErrorString* errorString, bool accept)
     1254{
     1255    if (!m_client->handleJavaScriptDialog(accept))
     1256        *errorString = "Could not handle JavaScript dialog";
     1257}
     1258
    12431259} // namespace WebCore
    12441260
  • trunk/Source/WebCore/inspector/InspectorPageAgent.h

    r141403 r141555  
    127127    virtual void setCompositingBordersVisible(ErrorString*, bool);
    128128    virtual void captureScreenshot(ErrorString*, String* data);
     129    virtual void handleJavaScriptDialog(ErrorString*, bool accept);
    129130
    130131    // Geolocation override helpers.
     
    145146    void frameScheduledNavigation(Frame*, double delay);
    146147    void frameClearedScheduledNavigation(Frame*);
     148    void willRunJavaScriptDialog(const String& message);
     149    void didRunJavaScriptDialog();
    147150    void applyScreenWidthOverride(long*);
    148151    void applyScreenHeightOverride(long*);
  • trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js

    r140649 r141555  
    604604    },
    605605
    606     frameStartedLoading: function(frameId) {
    607     },
    608 
    609     frameStoppedLoading: function(frameId) {
    610     },
    611 
    612     frameScheduledNavigation: function(frameId, delay) {
    613     },
    614 
    615     frameClearedScheduledNavigation: function(frameId) {
     606    frameStartedLoading: function(frameId)
     607    {
     608    },
     609
     610    frameStoppedLoading: function(frameId)
     611    {
     612    },
     613
     614    frameScheduledNavigation: function(frameId, delay)
     615    {
     616    },
     617
     618    frameClearedScheduledNavigation: function(frameId)
     619    {
     620    },
     621
     622    javascriptDialogOpening: function(message)
     623    {
     624    },
     625
     626    javascriptDialogClosed: function()
     627    {
    616628    }
    617629}
  • trunk/Source/WebCore/page/Chrome.cpp

    r134886 r141555  
    294294    PageGroupLoadDeferrer deferrer(m_page, true);
    295295
    296     return m_client->runBeforeUnloadConfirmPanel(message, frame);
     296    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, message);
     297    bool ok = m_client->runBeforeUnloadConfirmPanel(message, frame);
     298    InspectorInstrumentation::didRunJavaScriptDialog(cookie);
     299    return ok;
    297300}
    298301
     
    313316    ASSERT(frame);
    314317    notifyPopupOpeningObservers();
    315     m_client->runJavaScriptAlert(frame, frame->displayStringModifiedByEncoding(message));
     318    String displayMessage = frame->displayStringModifiedByEncoding(message);
     319
     320    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, displayMessage);
     321    m_client->runJavaScriptAlert(frame, displayMessage);
     322    InspectorInstrumentation::didRunJavaScriptDialog(cookie);
    316323}
    317324
     
    327334    ASSERT(frame);
    328335    notifyPopupOpeningObservers();
    329     return m_client->runJavaScriptConfirm(frame, frame->displayStringModifiedByEncoding(message));
     336    String displayMessage = frame->displayStringModifiedByEncoding(message);
     337
     338    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, displayMessage);
     339    bool ok = m_client->runJavaScriptConfirm(frame, displayMessage);
     340    InspectorInstrumentation::didRunJavaScriptDialog(cookie);
     341    return ok;
    330342}
    331343
     
    341353    ASSERT(frame);
    342354    notifyPopupOpeningObservers();
    343     bool ok = m_client->runJavaScriptPrompt(frame, frame->displayStringModifiedByEncoding(prompt), frame->displayStringModifiedByEncoding(defaultValue), result);
     355    String displayPrompt = frame->displayStringModifiedByEncoding(prompt);
     356
     357    InspectorInstrumentationCookie cookie = InspectorInstrumentation::willRunJavaScriptDialog(m_page, displayPrompt);
     358    bool ok = m_client->runJavaScriptPrompt(frame, displayPrompt, frame->displayStringModifiedByEncoding(defaultValue), result);
     359    InspectorInstrumentation::didRunJavaScriptDialog(cookie);
    344360
    345361    if (ok)
  • trunk/Source/WebKit/chromium/ChangeLog

    r141554 r141555  
     12013-02-01  Ken Kania  <kkania@chromium.org>
     2
     3        Web Inspector: Add support for handling modal dialogs
     4        https://bugs.webkit.org/show_bug.cgi?id=107883
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Introduce support for being notified when a JavaScript modal dialog
     9        is opening and closing, as well as a new command for accepting or
     10        dismissing the dialog.
     11
     12        * public/WebDevToolsAgent.h:
     13        * src/InspectorClientImpl.cpp:
     14        (WebKit::InspectorClientImpl::handleJavaScriptDialog):
     15        (WebKit):
     16        * src/InspectorClientImpl.h:
     17        (InspectorClientImpl):
     18        * src/WebDevToolsAgentImpl.cpp:
     19        (BrowserDataHintStringValues):
     20        (WebKit::WebDevToolsAgentImpl::captureScreenshot):
     21        (WebKit::WebDevToolsAgentImpl::handleJavaScriptDialog):
     22        (WebKit):
     23        (WebKit::browserHintToString):
     24        (WebKit::browserHintFromString):
     25        (WebKit::WebDevToolsAgent::patchWithBrowserData):
     26        * src/WebDevToolsAgentImpl.h:
     27        (WebDevToolsAgentImpl):
     28
    1292013-02-01  Dan Alcantara  <dfalcantara@chromium.org>
    230
  • trunk/Source/WebKit/chromium/public/WebDevToolsAgent.h

    r140951 r141555  
    5252    // Hint for the browser on the data it should prepare for message patching.
    5353    enum BrowserDataHint {
    54         BrowserDataHintNone = 0,
    55         BrowserDataHintScreenshot = 1,
     54        BrowserDataHintNone,
     55        BrowserDataHintScreenshot,
     56        BrowserDataHintAcceptJavaScriptDialog,
     57        BrowserDataHintDismissJavaScriptDialog,
    5658    };
    5759
  • trunk/Source/WebKit/chromium/src/InspectorClientImpl.cpp

    r141550 r141555  
    212212}
    213213
     214bool InspectorClientImpl::handleJavaScriptDialog(bool accept)
     215{
     216    if (WebDevToolsAgentImpl* agent = devToolsAgent())
     217        return agent->handleJavaScriptDialog(accept);
     218    return false;
     219}
     220
    214221WebDevToolsAgentImpl* InspectorClientImpl::devToolsAgent()
    215222{
  • trunk/Source/WebKit/chromium/src/InspectorClientImpl.h

    r140798 r141555  
    9090    virtual bool captureScreenshot(WTF::String* data);
    9191
     92    virtual bool handleJavaScriptDialog(bool accept);
     93
    9294private:
    9395    WebDevToolsAgentImpl* devToolsAgent();
  • trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.cpp

    r140951 r141555  
    8484namespace BrowserDataHintStringValues {
    8585static const char screenshot[] = "screenshot";
     86static const char acceptJavaScriptDialog[] = "acceptJavaScriptDialog";
     87static const char dismissJavaScriptDialog[] = "dismissJavaScriptDialog";
    8688}
    8789
     
    575577}
    576578
    577 bool WebDevToolsAgentImpl::captureScreenshot(WTF::String* data)
    578 {
    579     // Value is going to be substituted with the actual data on the browser level.
     579bool WebDevToolsAgentImpl::captureScreenshot(String* data)
     580{
     581    // Value is going to be substituted with the actual data in the browser process.
    580582    *data = "{screenshot-placeholder}";
    581583    m_sendWithBrowserDataHint = BrowserDataHintScreenshot;
     584    return true;
     585}
     586
     587bool WebDevToolsAgentImpl::handleJavaScriptDialog(bool accept)
     588{
     589    // Operation is going to be performed in the browser process.
     590    m_sendWithBrowserDataHint = accept ? BrowserDataHintAcceptJavaScriptDialog : BrowserDataHintDismissJavaScriptDialog;
    582591    return true;
    583592}
     
    662671    case WebDevToolsAgent::BrowserDataHintScreenshot:
    663672        return BrowserDataHintStringValues::screenshot;
     673    case WebDevToolsAgent::BrowserDataHintAcceptJavaScriptDialog:
     674        return BrowserDataHintStringValues::acceptJavaScriptDialog;
     675    case WebDevToolsAgent::BrowserDataHintDismissJavaScriptDialog:
     676        return BrowserDataHintStringValues::dismissJavaScriptDialog;
    664677    case WebDevToolsAgent::BrowserDataHintNone:
    665678    default:
     
    673686    if (value == BrowserDataHintStringValues::screenshot)
    674687        return WebDevToolsAgent::BrowserDataHintScreenshot;
     688    if (value == BrowserDataHintStringValues::acceptJavaScriptDialog)
     689        return WebDevToolsAgent::BrowserDataHintAcceptJavaScriptDialog;
     690    if (value == BrowserDataHintStringValues::dismissJavaScriptDialog)
     691        return WebDevToolsAgent::BrowserDataHintDismissJavaScriptDialog;
    675692    ASSERT_NOT_REACHED();
    676693    return WebDevToolsAgent::BrowserDataHintNone;
     
    828845        resultObject->setString("data", hintData);
    829846        break;
     847    case BrowserDataHintAcceptJavaScriptDialog:
     848        break;
     849    case BrowserDataHintDismissJavaScriptDialog:
     850        break;
    830851    case BrowserDataHintNone:
    831852    default:
  • trunk/Source/WebKit/chromium/src/WebDevToolsAgentImpl.h

    r140951 r141555  
    114114    virtual bool captureScreenshot(WTF::String* data);
    115115
     116    virtual bool handleJavaScriptDialog(bool accept);
     117
    116118    int hostId() { return m_hostId; }
    117119
Note: See TracChangeset for help on using the changeset viewer.