Changeset 146202 in webkit


Ignore:
Timestamp:
Mar 19, 2013 7:13:05 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Add iframe option to inspectedWindow.eval() extension API
https://bugs.webkit.org/show_bug.cgi?id=106811

Patch by John J. Barton <johnjbarton@chromium.org> on 2013-03-19
Reviewed by Vsevolod Vlasov.

Source/WebCore:

Add a new case to the options processing in inspectedWindow.eval(), look
for option.frameURL <string> and/or option.scriptExecutionContext: <string>, find the
matching JS context in the runtimeModel, and call evaluate() in that
context; or error if the context is not found.

Test: http/tests/inspector/extensions-iframe-eval.html

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage):
(WebInspector.ExtensionServer.prototype.):
(WebInspector.ExtensionServer.prototype.evaluate):

  • inspector/front-end/ResourceTreeModel.js:

(WebInspector.ResourceTreeModel.prototype.frames):

Added read access to _frames

  • inspector/front-end/RuntimeModel.js:

(WebInspector.RuntimeModel.prototype.contextListByFrame):

Added access to a frame's contextList, removed contextByFrameAndSecurityOrigin()

(WebInspector.FrameExecutionContextList.prototype.mainWorldContext):

Added access to frame's mainWorldContext, rather than implicit first context.
Now we can go from ResourceTreeModel -> frame -> contextList then either
mainWorldContext() or contextBySecurityOrigin() to access contexts.

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer.prototype.):
(WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage):
(WebInspector.ExtensionServer.prototype.evaluate):

  • inspector/front-end/ResourceTreeModel.js:
  • inspector/front-end/RuntimeModel.js:

(WebInspector.RuntimeModel.prototype.contextListByFrame):
(WebInspector.FrameExecutionContextList.prototype.mainWorldContext):

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer.prototype._onReload):
(WebInspector.ExtensionServer.prototype.resolveURLToFrame.hasMatchingURL):
(WebInspector.ExtensionServer.prototype.):
(WebInspector.ExtensionServer.prototype.evaluate):

  • inspector/front-end/ResourceTreeModel.js:

(WebInspector.ResourceTreeModel.prototype.frames):

  • inspector/front-end/RuntimeModel.js:

(WebInspector.RuntimeModel.prototype.contextListByFrame):
(WebInspector.FrameExecutionContextList.prototype.mainWorldContext):

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer.prototype.resolveURLToFrame.hasMatchingURL):
(WebInspector.ExtensionServer.prototype.):
(WebInspector.ExtensionServer.prototype.evaluate):

  • inspector/front-end/ResourceTreeModel.js:

(WebInspector.ResourceTreeModel.prototype.frames):

  • inspector/front-end/RuntimeModel.js:

(WebInspector.RuntimeModel.prototype.contextListByFrame):
(WebInspector.FrameExecutionContextList.prototype.mainWorldContext):

LayoutTests:

New tests for evaluate in iframe options in extension API

  • http/tests/inspector/extensions-iframe-eval-expected.txt: Added.
  • http/tests/inspector/extensions-iframe-eval.html: Added.
  • http/tests/inspector/resources/extensions-frame-eval.html: Added.
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r146201 r146202  
     12013-03-19  John J. Barton  <johnjbarton@chromium.org>
     2
     3        Web Inspector: Add iframe option to inspectedWindow.eval() extension API
     4        https://bugs.webkit.org/show_bug.cgi?id=106811
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        New tests for evaluate in iframe options in extension API
     9
     10        * http/tests/inspector/extensions-iframe-eval-expected.txt: Added.
     11        * http/tests/inspector/extensions-iframe-eval.html: Added.
     12        * http/tests/inspector/resources/extensions-frame-eval.html: Added.
     13
    1142013-03-19  Ádám Kallai  <kadam@inf.u-szeged.hu>
    215
  • trunk/Source/WebCore/ChangeLog

    r146200 r146202  
     12013-03-19  John J. Barton  <johnjbarton@chromium.org>
     2
     3        Web Inspector: Add iframe option to inspectedWindow.eval() extension API
     4        https://bugs.webkit.org/show_bug.cgi?id=106811
     5
     6        Reviewed by Vsevolod Vlasov.
     7
     8        Add a new case to the options processing in inspectedWindow.eval(), look
     9        for option.frameURL <string> and/or option.scriptExecutionContext: <string>, find the
     10        matching JS context in the runtimeModel, and call evaluate() in that
     11        context; or error if the context is not found.
     12
     13        Test: http/tests/inspector/extensions-iframe-eval.html
     14
     15        * inspector/front-end/ExtensionServer.js:
     16        (WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage):
     17        (WebInspector.ExtensionServer.prototype.):
     18        (WebInspector.ExtensionServer.prototype.evaluate):
     19        * inspector/front-end/ResourceTreeModel.js:
     20        (WebInspector.ResourceTreeModel.prototype.frames):
     21           Added read access to _frames
     22       * inspector/front-end/RuntimeModel.js:
     23        (WebInspector.RuntimeModel.prototype.contextListByFrame):
     24           Added access to a frame's contextList, removed contextByFrameAndSecurityOrigin()
     25        (WebInspector.FrameExecutionContextList.prototype.mainWorldContext):
     26           Added access to frame's mainWorldContext, rather than implicit first context.
     27           Now we can go from ResourceTreeModel -> frame -> contextList then either
     28           mainWorldContext() or contextBySecurityOrigin() to access contexts.
     29
     30        * inspector/front-end/ExtensionServer.js:
     31        (WebInspector.ExtensionServer.prototype.):
     32        (WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage):
     33        (WebInspector.ExtensionServer.prototype.evaluate):
     34        * inspector/front-end/ResourceTreeModel.js:
     35        * inspector/front-end/RuntimeModel.js:
     36        (WebInspector.RuntimeModel.prototype.contextListByFrame):
     37        (WebInspector.FrameExecutionContextList.prototype.mainWorldContext):
     38
     39        * inspector/front-end/ExtensionServer.js:
     40        (WebInspector.ExtensionServer.prototype._onReload):
     41        (WebInspector.ExtensionServer.prototype.resolveURLToFrame.hasMatchingURL):
     42        (WebInspector.ExtensionServer.prototype.):
     43        (WebInspector.ExtensionServer.prototype.evaluate):
     44        * inspector/front-end/ResourceTreeModel.js:
     45        (WebInspector.ResourceTreeModel.prototype.frames):
     46        * inspector/front-end/RuntimeModel.js:
     47        (WebInspector.RuntimeModel.prototype.contextListByFrame):
     48        (WebInspector.FrameExecutionContextList.prototype.mainWorldContext):
     49
     50        * inspector/front-end/ExtensionServer.js:
     51        (WebInspector.ExtensionServer.prototype.resolveURLToFrame.hasMatchingURL):
     52        (WebInspector.ExtensionServer.prototype.):
     53        (WebInspector.ExtensionServer.prototype.evaluate):
     54        * inspector/front-end/ResourceTreeModel.js:
     55        (WebInspector.ResourceTreeModel.prototype.frames):
     56        * inspector/front-end/RuntimeModel.js:
     57        (WebInspector.RuntimeModel.prototype.contextListByFrame):
     58        (WebInspector.FrameExecutionContextList.prototype.mainWorldContext):
     59
    1602013-03-19  Ilya Tikhonovsky  <loislo@chromium.org>
    261
  • trunk/Source/WebCore/inspector/front-end/ExtensionServer.js

    r144916 r146202  
    778778    {
    779779        var contextId;
    780         if (typeof options === "object" && options["useContentScriptContext"]) {
    781             var mainFrame = WebInspector.resourceTreeModel.mainFrame;
    782             if (!mainFrame)
    783                 return this._status.E_FAILED("main frame not available yet");
    784             var context = WebInspector.runtimeModel.contextByFrameAndSecurityOrigin(mainFrame, securityOrigin);
    785             if (!context)
    786                 return this._status.E_NOTFOUND(securityOrigin);
     780        if (typeof options === "object") {
     781
     782            function resolveURLToFrame(url)
     783            {
     784                var found;
     785                function hasMatchingURL(frame)
     786                {
     787                    found = (frame.url === url) ? frame : null;
     788                    return found;
     789                }
     790                WebInspector.resourceTreeModel.frames().some(hasMatchingURL);
     791                return found;
     792            }
     793
     794            var frame = options.frameURL ? resolveURLToFrame(options.frameURL) : WebInspector.resourceTreeModel.mainFrame;
     795            if (!frame) {
     796                if (options.frameURL)
     797                    console.warn("evaluate: there is no frame with URL " + options.frameURL);
     798                else
     799                    console.warn("evaluate: the main frame is not yet available");
     800                return this._status.E_NOTFOUND(options.frameURL || "<top>");
     801            }
     802
     803            var contextSecurityOrigin;
     804            if (options.useContentScriptContext)
     805                contextSecurityOrigin = securityOrigin;
     806            else if (options.scriptExecutionContext)
     807                contextSecurityOrigin = options.scriptExecutionContext;
     808
     809            var frameContextList = WebInspector.runtimeModel.contextListByFrame(frame);
     810            var context;
     811            if (contextSecurityOrigin) {
     812                context = frameContextList.contextBySecurityOrigin(contextSecurityOrigin);
     813                if (!context) {
     814                    console.warn("The JS context " + contextSecurityOrigin + " was not found in the frame " + frame.url)
     815                    return this._status.E_NOTFOUND(contextSecurityOrigin)
     816                }
     817            } else {
     818                context = frameContextList.mainWorldContext();
     819                if (!context)
     820                    return this._status.E_FAILED(frame.url + " has no execution context");
     821            }
     822
    787823            contextId = context.id;
    788824        }
  • trunk/Source/WebCore/inspector/front-end/ResourceTreeModel.js

    r144600 r146202  
    302302
    303303    /**
     304     * @return {Array.<WebInspector.ResourceTreeFrame>}
     305     */
     306    frames: function()
     307    {
     308        return Object.values(this._frames);
     309    },
     310
     311    /**
    304312     * @param {WebInspector.Event} event
    305313     */
  • trunk/Source/WebCore/inspector/front-end/RuntimeModel.js

    r145054 r146202  
    7575    /**
    7676     * @param {WebInspector.ResourceTreeFrame} frame
    77      * @param {string} securityOrigin
    78      */
    79     contextByFrameAndSecurityOrigin: function(frame, securityOrigin)
    80     {
    81         var frameContext = this._frameIdToContextList[frame.id];
    82         return frameContext && frameContext.contextBySecurityOrigin(securityOrigin);
     77     * @return {WebInspector.FrameExecutionContextList}
     78     */
     79    contextListByFrame: function(frame)
     80    {
     81        return this._frameIdToContextList[frame.id];
    8382    },
    8483
     
    414413    },
    415414
     415    mainWorldContext: function()
     416    {
     417        return this._executionContexts[0];
     418    },
     419
    416420    /**
    417421     * @param {string} securityOrigin
Note: See TracChangeset for help on using the changeset viewer.