Changeset 91839 in webkit


Ignore:
Timestamp:
Jul 27, 2011 6:37:03 AM (13 years ago)
Author:
yurys@chromium.org
Message:

Inspector should support cd(window) in the command line
https://bugs.webkit.org/show_bug.cgi?id=19872

Source/WebCore:

Added dropdown list with all iframes to allow selecting current evaluation context for console expressions.

Reviewed by Pavel Feldman.

Test: http/tests/inspector/console-cd.html

  • WebCore.gypi:
  • inspector/Inspector.json:
  • inspector/InspectorController.cpp:

(WebCore::InspectorController::InspectorController):

  • inspector/InspectorRuntimeAgent.cpp:

(WebCore::InspectorRuntimeAgent::InspectorRuntimeAgent):
(WebCore::InspectorRuntimeAgent::evaluate):

  • inspector/InspectorRuntimeAgent.h:
  • inspector/WorkerInspectorController.cpp:
  • inspector/front-end/ConsoleView.js:

(WebInspector.ConsoleView.prototype.addContext):
(WebInspector.ConsoleView.prototype.removeContext):
(WebInspector.ConsoleView.prototype._contextUpdated):
(WebInspector.ConsoleView.prototype.get _currentEvaluationContextId):
(WebInspector.ConsoleView.prototype.evalInInspectedWindow):

  • inspector/front-end/ContextManager.js: Added.

(WebInspector.ContextManager):
(WebInspector.ContextManager.prototype._frameAdded):
(WebInspector.ContextManager.prototype._frameNavigated):
(WebInspector.ContextManager.prototype._frameDetached):
(WebInspector.FrameEvaluationContext):
(WebInspector.FrameEvaluationContext.prototype._frameNavigated):
(WebInspector.FrameEvaluationContext.prototype.get id):
(WebInspector.FrameEvaluationContext.prototype.get url):
(WebInspector.FrameEvaluationContext.prototype.get displayName):

  • inspector/front-end/ResourceTreeModel.js:

(WebInspector.ResourceTreeModel.prototype._cleanupFramesAfterNavigation):
(WebInspector.ResourceTreeModel.prototype._addFramesRecursively):

  • inspector/front-end/WebKit.qrc:
  • inspector/front-end/inspector.html:
  • inspector/front-end/inspector.js:

LayoutTests:

Added a test for console evaluation in an iframe.

Reviewed by Pavel Feldman.

  • http/tests/inspector/console-cd-expected.txt: Added.
  • http/tests/inspector/console-cd.html: Added.
  • http/tests/inspector/resources/console-cd-iframe.html: Added.
Location:
trunk
Files:
4 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91837 r91839  
     12011-07-27  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Inspector should support cd(window) in the command line
     4        https://bugs.webkit.org/show_bug.cgi?id=19872
     5
     6        Added a test for console evaluation in an iframe.
     7
     8        Reviewed by Pavel Feldman.
     9
     10        * http/tests/inspector/console-cd-expected.txt: Added.
     11        * http/tests/inspector/console-cd.html: Added.
     12        * http/tests/inspector/resources/console-cd-iframe.html: Added.
     13
    1142011-07-27  Shinya Kawanaka  <shinyak@google.com>
    215
  • trunk/LayoutTests/http/tests/inspector/console-test.js

    r82713 r91839  
    11var initialize_ConsoleTest = function() {
     2
     3InspectorTest.showConsolePanel = function()
     4{
     5    WebInspector.showPanel("console");
     6    WebInspector.drawer.immediatelyFinishAnimation();
     7}
    28
    39InspectorTest.dumpConsoleMessages = function()
  • trunk/Source/WebCore/ChangeLog

    r91837 r91839  
     12011-07-27  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Inspector should support cd(window) in the command line
     4        https://bugs.webkit.org/show_bug.cgi?id=19872
     5
     6        Added dropdown list with all iframes to allow selecting current evaluation context for console expressions.
     7
     8        Reviewed by Pavel Feldman.
     9
     10        Test: http/tests/inspector/console-cd.html
     11
     12        * WebCore.gypi:
     13        * inspector/Inspector.json:
     14        * inspector/InspectorController.cpp:
     15        (WebCore::InspectorController::InspectorController):
     16        * inspector/InspectorRuntimeAgent.cpp:
     17        (WebCore::InspectorRuntimeAgent::InspectorRuntimeAgent):
     18        (WebCore::InspectorRuntimeAgent::evaluate):
     19        * inspector/InspectorRuntimeAgent.h:
     20        * inspector/WorkerInspectorController.cpp:
     21        * inspector/front-end/ConsoleView.js:
     22        (WebInspector.ConsoleView.prototype.addContext):
     23        (WebInspector.ConsoleView.prototype.removeContext):
     24        (WebInspector.ConsoleView.prototype._contextUpdated):
     25        (WebInspector.ConsoleView.prototype.get _currentEvaluationContextId):
     26        (WebInspector.ConsoleView.prototype.evalInInspectedWindow):
     27        * inspector/front-end/ContextManager.js: Added.
     28        (WebInspector.ContextManager):
     29        (WebInspector.ContextManager.prototype._frameAdded):
     30        (WebInspector.ContextManager.prototype._frameNavigated):
     31        (WebInspector.ContextManager.prototype._frameDetached):
     32        (WebInspector.FrameEvaluationContext):
     33        (WebInspector.FrameEvaluationContext.prototype._frameNavigated):
     34        (WebInspector.FrameEvaluationContext.prototype.get id):
     35        (WebInspector.FrameEvaluationContext.prototype.get url):
     36        (WebInspector.FrameEvaluationContext.prototype.get displayName):
     37        * inspector/front-end/ResourceTreeModel.js:
     38        (WebInspector.ResourceTreeModel.prototype._cleanupFramesAfterNavigation):
     39        (WebInspector.ResourceTreeModel.prototype._addFramesRecursively):
     40        * inspector/front-end/WebKit.qrc:
     41        * inspector/front-end/inspector.html:
     42        * inspector/front-end/inspector.js:
     43
    1442011-07-27  Shinya Kawanaka  <shinyak@google.com>
    245
  • trunk/Source/WebCore/WebCore.gypi

    r91811 r91839  
    63226322            'inspector/front-end/ConsolePanel.js',
    63236323            'inspector/front-end/ConsoleView.js',
     6324            'inspector/front-end/JavaScriptContextManager.js',
    63246325            'inspector/front-end/ContextMenu.js',
    63256326            'inspector/front-end/CookieItemsView.js',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r91811 r91839  
    6863068630                                </File>
    6863168631                                <File
     68632                                        RelativePath="..\inspector\front-end\JavaScriptContextManager.js"
     68633                                        >
     68634                                </File>
     68635                                <File
    6863268636                                        RelativePath="..\inspector\front-end\JavaScriptFormatter.js"
    6863368637                                        >
  • trunk/Source/WebCore/inspector/Inspector.json

    r91754 r91839  
    263263                    { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." },
    264264                    { "name": "includeCommandLineAPI", "type": "boolean", "optional": true, "description": "Determines whether Command Line API should be available during the evaluation." },
    265                     { "name": "doNotPauseOnExceptions", "type": "boolean", "optional": true, "description": "Specifies whether evaluation should stop on exceptions. Overrides setPauseOnException state." }
     265                    { "name": "doNotPauseOnExceptions", "type": "boolean", "optional": true, "description": "Specifies whether evaluation should stop on exceptions. Overrides setPauseOnException state." },
     266                    { "name": "frameId", "type": "string", "optional": true, "description": "Specifies in which frame to perform evaluation." }
    266267                ],
    267268                "returns": [
  • trunk/Source/WebCore/inspector/InspectorController.cpp

    r91565 r91839  
    7373class PageRuntimeAgent : public InspectorRuntimeAgent {
    7474public:
    75     PageRuntimeAgent(InjectedScriptManager* injectedScriptManager, Page* page)
     75    PageRuntimeAgent(InjectedScriptManager* injectedScriptManager, Page* page, InspectorPageAgent* pageAgent)
    7676        : InspectorRuntimeAgent(injectedScriptManager)
    77         , m_inspectedPage(page) { }
     77        , m_inspectedPage(page)
     78        , m_pageAgent(pageAgent) { }
    7879    virtual ~PageRuntimeAgent() { }
    7980
    8081private:
     82    virtual ScriptState* scriptStateForFrameId(ErrorString* errorString, const String& frameId)
     83    {
     84        Frame* frame = m_pageAgent->frameForId(frameId);
     85        if (!frame) {
     86            *errorString = "Frame not found";
     87            return 0;
     88        }
     89        return mainWorldScriptState(frame);
     90    }
    8191    virtual ScriptState* getDefaultInspectedState() { return mainWorldScriptState(m_inspectedPage->mainFrame()); }
    8292    Page* m_inspectedPage;
     93    InspectorPageAgent* m_pageAgent;
    8394};
    8495
     
    104115#endif
    105116    , m_resourceAgent(InspectorResourceAgent::create(m_instrumentingAgents.get(), m_pageAgent.get(), inspectorClient, m_state.get()))
    106     , m_runtimeAgent(adoptPtr(new PageRuntimeAgent(m_injectedScriptManager.get(), page)))
     117    , m_runtimeAgent(adoptPtr(new PageRuntimeAgent(m_injectedScriptManager.get(), page, m_pageAgent.get())))
    107118    , m_consoleAgent(adoptPtr(new InspectorConsoleAgent(m_instrumentingAgents.get(), m_inspectorAgent.get(), m_state.get(), m_injectedScriptManager.get(), m_domAgent.get())))
    108119#if ENABLE(JAVASCRIPT_DEBUGGER)
  • trunk/Source/WebCore/inspector/InspectorRuntimeAgent.cpp

    r91750 r91839  
    5858}
    5959
    60 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptions, RefPtr<InspectorObject>* result, bool* wasThrown)
     60void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptions, const String* const frameId, RefPtr<InspectorObject>* result, bool* wasThrown)
    6161{
    62     InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(getDefaultInspectedState());
     62    ScriptState* scriptState = 0;
     63    if (frameId)
     64        scriptState = scriptStateForFrameId(errorString, *frameId);
     65    else
     66        scriptState = getDefaultInspectedState();
     67    InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(scriptState);
    6368    if (injectedScript.hasNoValue()) {
    6469        *errorString = "Inspected frame has gone";
  • trunk/Source/WebCore/inspector/InspectorRuntimeAgent.h

    r91750 r91839  
    5454
    5555    // Part of the protocol.
    56     void evaluate(ErrorString*, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptions, RefPtr<InspectorObject>* result, bool* wasThrown);
     56    void evaluate(ErrorString*, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptions, const String* const frameId, RefPtr<InspectorObject>* result, bool* wasThrown);
    5757    void callFunctionOn(ErrorString*, const String& objectId, const String& expression, const RefPtr<InspectorArray>* const optionalArguments, RefPtr<InspectorObject>* result, bool* wasThrown);
    5858    void releaseObject(ErrorString*, const String& objectId);
     
    6666protected:
    6767    explicit InspectorRuntimeAgent(InjectedScriptManager*);
     68    virtual ScriptState* scriptStateForFrameId(ErrorString*, const String& frameId) = 0;
    6869    virtual ScriptState* getDefaultInspectedState() = 0;
    6970
  • trunk/Source/WebCore/inspector/WorkerInspectorController.cpp

    r91176 r91839  
    6262
    6363private:
     64    virtual ScriptState* scriptStateForFrameId(ErrorString*, const String&)
     65    {
     66        return 0;
     67    }
     68
    6469    virtual ScriptState* getDefaultInspectedState()
    6570    {
  • trunk/Source/WebCore/inspector/front-end/ConsoleView.js

    r91749 r91839  
    4141    this.clearButton.addEventListener("click", this._clearButtonClicked.bind(this), false);
    4242
     43    this._contextSelectElement = document.getElementById("console-context");
     44    if (WebInspector.WorkerManager.isWorkerFrontend())
     45        this._contextSelectElement.addStyleClass("hidden");
     46
    4347    this.messagesElement = document.getElementById("console-messages");
    4448    this.messagesElement.addEventListener("selectstart", this._messagesSelectStart.bind(this), false);
     
    165169    },
    166170
     171    addContext: function(context)
     172    {
     173        var option = document.createElement("option");
     174        option.text = context.displayName;
     175        option.title = context.url;
     176        option._context = context;
     177        context._consoleOption = option;
     178        this._contextSelectElement.appendChild(option);
     179        context.addEventListener(WebInspector.FrameEvaluationContext.EventTypes.Updated, this._contextUpdated, this);
     180    },
     181
     182    removeContext: function(context)
     183    {
     184        this._contextSelectElement.removeChild(context._consoleOption);
     185    },
     186
     187    _contextUpdated: function(event)
     188    {
     189        var context = event.data;
     190        var option= context._consoleOption;
     191        option.text = context.displayName;
     192        option.title = context.url;
     193    },
     194
     195    _currentEvaluationContextId: function()
     196    {
     197        if (this._contextSelectElement.selectedIndex === -1)
     198            return undefined;
     199        return this._contextSelectElement[this._contextSelectElement.selectedIndex]._context.frameId;
     200    },
     201
    167202    _updateFilter: function(e)
    168203    {
     
    578613                callback(WebInspector.RemoteObject.fromPayload(result), wasThrown);
    579614        }
    580         RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptions, evalCallback);
     615        RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptions, this._currentEvaluationContextId(), evalCallback);
    581616    },
    582617
  • trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js

    r90364 r91839  
    153153    _cleanupFramesAfterNavigation: function(newMainFrame)
    154154    {
    155         for (var frameId in this._frameIds) {
    156             if (frameId !== newMainFrame.id)
    157                 this._frameDetached(frameId);
    158         }
     155        if (this._currentMainFrameId)
     156            this._frameDetached(this._currentMainFrameId);
     157        this._currentMainFrameId = newMainFrame.id;
    159158    },
    160159
     
    324323        frameResource.finished = true;
    325324
    326         if (!framePayload.parentId)
     325        if (!framePayload.parentId) {
    327326            WebInspector.mainResource = frameResource;
     327            this._currentMainFrameId = framePayload.id;
     328        }
    328329        this._addFrame(framePayload);
    329330        this._addResourceToFrame(frameResource);
  • trunk/Source/WebCore/inspector/front-end/WebKit.qrc

    r91359 r91839  
    1717    <file>ConsolePanel.js</file>
    1818    <file>ConsoleView.js</file>
     19    <file>JavaScriptContextManager.js</file>
    1920    <file>ContextMenu.js</file>
    2021    <file>CookieItemsView.js</file>
  • trunk/Source/WebCore/inspector/front-end/inspector.html

    r91359 r91839  
    171171    <script type="text/javascript" src="WorkerManager.js"></script>
    172172    <script type="text/javascript" src="UserMetrics.js"></script>
     173    <script type="text/javascript" src="JavaScriptContextManager.js"></script>
    173174</head>
    174175<body class="detached">
     
    188189    <div id="drawer">
    189190        <div id="console-view"><div id="console-messages" class="monospace"><div id="console-prompt" spellcheck="false"><br></div></div></div>
    190         <div id="drawer-status-bar" class="status-bar"><div id="other-drawer-status-bar-items"><button id="clear-console-status-bar-item" class="status-bar-item clear-status-bar-item"><div class="glyph"></div><div class="glyph shadow"></div></button><div id="console-filter" class="scope-bar status-bar-item"></div></div></div>
     191        <div id="drawer-status-bar" class="status-bar"><div id="other-drawer-status-bar-items"><button id="clear-console-status-bar-item" class="status-bar-item clear-status-bar-item"><div class="glyph"></div><div class="glyph shadow"></div></button><select id="console-context" class="status-bar-item"></select><div id="console-filter" class="scope-bar status-bar-item"></div></div></div>
    191192    </div>
    192193</body>
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r91749 r91839  
    503503    this.networkLog = new WebInspector.NetworkLog();
    504504    this.domAgent = new WebInspector.DOMAgent();
     505    new WebInspector.JavaScriptContextManager(this.resourceTreeModel, this.console);
    505506
    506507    InspectorBackend.registerDomainDispatcher("Inspector", this);
Note: See TracChangeset for help on using the changeset viewer.