Changeset 116957 in webkit


Ignore:
Timestamp:
May 14, 2012 9:34:15 AM (12 years ago)
Author:
caseq@chromium.org
Message:

Web Inspector: [Extensions API] allow extensions to evaluate in the context of their content scripts
https://bugs.webkit.org/show_bug.cgi?id=86361

Reviewed by Yury Semikhatsky.

Source/WebCore:

Test: inspector/extensions/extensions-eval-content-script.html

  • inspector/front-end/ExtensionAPI.js:

(injectedExtensionAPI.ExtensionSidebarPaneImpl.prototype.setExpression): Added evaluateOptions optional parameter.
(injectedExtensionAPI.InspectedWindow.prototype.eval):
(injectedExtensionAPI.extractCallbackArgument): A helper to extract callback function from last argument.

  • inspector/front-end/ExtensionPanel.js:

(WebInspector.ExtensionSidebarPane.prototype.setExpression): Added evaluateOptions optional parameter.

  • inspector/front-end/ExtensionServer.js:

(WebInspector.ExtensionServer.prototype._onSetSidebarContent): Use ExtensionServer.evaluate() wrapper.
(WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage): Ditto.
(WebInspector.ExtensionServer.prototype._normalizePath):
(WebInspector.ExtensionServer.prototype.evaluate): A wrapper for PageAgent.evaluate() that handles evaluateOptions.

  • inspector/front-end/JavaScriptContextManager.js:

(WebInspector.JavaScriptContextManager.prototype.contextByFrameAndSecurityOrigin): Expose interface to locate context id by frame and content script security origin.
(WebInspector.FrameEvaluationContext.prototype._addExecutionContext): Maintain contexts sorted by name.
(WebInspector.FrameEvaluationContext.prototype.isolatedContexts): ditto (skip sorting when returning contexts)
(WebInspector.FrameEvaluationContext.prototype.contextBySecurityOrigin):

  • inspector/front-end/inspector.js: Hold/expose javaScriptContextManager.

LayoutTests:

  • inspector/extensions/extensions-eval-content-script-expected.txt: Added.
  • inspector/extensions/extensions-eval-content-script.html: Added.
  • platform/gtk/test_expectations.txt:
  • platform/mac/Skipped:
  • platform/qt/Skipped:
  • platform/win/Skipped:
  • platform/wk2/Skipped:
Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r116955 r116957  
     12012-05-14  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Web Inspector: [Extensions API] allow extensions to evaluate in the context of their content scripts
     4        https://bugs.webkit.org/show_bug.cgi?id=86361
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * inspector/extensions/extensions-eval-content-script-expected.txt: Added.
     9        * inspector/extensions/extensions-eval-content-script.html: Added.
     10        * platform/gtk/test_expectations.txt:
     11        * platform/mac/Skipped:
     12        * platform/qt/Skipped:
     13        * platform/win/Skipped:
     14        * platform/wk2/Skipped:
     15
    1162012-05-14  Mihnea Ovidenie  <mihnea@adobe.com>
    217
  • trunk/LayoutTests/platform/gtk/test_expectations.txt

    r116928 r116957  
    784784BUGWK50868 SKIP : inspector/debugger/debugger-step-out.html = FAIL
    785785BUGWK50868 SKIP : inspector/styles/styles-source-lines-inline.html = FAIL
     786BUGWK85709 SKIP : inspector/extensions/extensions-eval-content-script.html = FAIL
    786787
    787788// These inspector tests fell out of the radar after the transition to NRWT
  • trunk/LayoutTests/platform/mac/Skipped

    r116847 r116957  
    840840# Hits assert https://bugs.webkit.org/show_bug.cgi?id=86208
    841841ietestcenter/css3/valuesandunits/units-000.htm
     842
     843# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
     844inspector/extensions/extensions-eval-content-script.html
  • trunk/LayoutTests/platform/qt/Skipped

    r116940 r116957  
    25622562fast/frames/seamless/seamless-inherited-document-style.html
    25632563
     2564# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
     2565inspector/extensions/extensions-eval-content-script.html
  • trunk/LayoutTests/platform/win/Skipped

    r116847 r116957  
    17451745# https://bugs.webkit.org/show_bug.cgi?id=86000
    17461746http/tests/security/referrer-policy-redirect-link.html
     1747
     1748# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
     1749inspector/extensions/extensions-eval-content-script.html
     1750
  • trunk/LayoutTests/platform/wk2/Skipped

    r116563 r116957  
    7171http/tests/inspector/extensions-headers.html
    7272http/tests/inspector/extensions-network-redirect.html
     73
     74# Inspector only supports evaluation in content script world with v8, see https://bugs.webkit.org/show_bug.cgi?id=85709
     75inspector/extensions/extensions-eval-content-script.html
    7376
    7477# A bunch of inspector tests time out on Lion Intel Debug WebKit2 testers.
  • trunk/Source/WebCore/ChangeLog

    r116954 r116957  
     12012-05-14  Andrey Kosyakov  <caseq@chromium.org>
     2
     3        Web Inspector: [Extensions API] allow extensions to evaluate in the context of their content scripts
     4        https://bugs.webkit.org/show_bug.cgi?id=86361
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        Test: inspector/extensions/extensions-eval-content-script.html
     9
     10        * inspector/front-end/ExtensionAPI.js:
     11        (injectedExtensionAPI.ExtensionSidebarPaneImpl.prototype.setExpression): Added evaluateOptions optional parameter.
     12        (injectedExtensionAPI.InspectedWindow.prototype.eval):
     13        (injectedExtensionAPI.extractCallbackArgument): A helper to extract callback function from last argument.
     14        * inspector/front-end/ExtensionPanel.js:
     15        (WebInspector.ExtensionSidebarPane.prototype.setExpression): Added evaluateOptions optional parameter.
     16        * inspector/front-end/ExtensionServer.js:
     17        (WebInspector.ExtensionServer.prototype._onSetSidebarContent): Use ExtensionServer.evaluate() wrapper.
     18        (WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage): Ditto.
     19        (WebInspector.ExtensionServer.prototype._normalizePath):
     20        (WebInspector.ExtensionServer.prototype.evaluate): A wrapper for PageAgent.evaluate() that handles evaluateOptions.
     21        * inspector/front-end/JavaScriptContextManager.js:
     22        (WebInspector.JavaScriptContextManager.prototype.contextByFrameAndSecurityOrigin): Expose interface to locate context id by frame and content script security origin.
     23        (WebInspector.FrameEvaluationContext.prototype._addExecutionContext): Maintain contexts sorted by name.
     24        (WebInspector.FrameEvaluationContext.prototype.isolatedContexts): ditto (skip sorting when returning contexts)
     25        (WebInspector.FrameEvaluationContext.prototype.contextBySecurityOrigin):
     26        * inspector/front-end/inspector.js: Hold/expose javaScriptContextManager.
     27
    1282012-05-14  Pavel Feldman  <pfeldman@chromium.org>
    229
  • trunk/Source/WebCore/inspector/front-end/ExtensionAPI.js

    r116739 r116957  
    415415    },
    416416
    417     setExpression: function(expression, rootTitle, callback)
    418     {
    419         extensionServer.sendRequest({ command: commands.SetSidebarContent, id: this._id, expression: expression, rootTitle: rootTitle, evaluateOnPage: true }, callback);
     417    setExpression: function(expression, rootTitle, evaluateOptions)
     418    {
     419        var callback = extractCallbackArgument(arguments);
     420        var request = {
     421            command: commands.SetSidebarContent,
     422            id: this._id,
     423            expression: expression,
     424            rootTitle: rootTitle,
     425            evaluateOnPage: true,
     426        };
     427        if (typeof evaluateOptions === "object")
     428            request.evaluateOptions = evaluateOptions;
     429        extensionServer.sendRequest(request, callback);
    420430    },
    421431
     
    603613    },
    604614
    605     eval: function(expression, callback)
    606     {
     615    eval: function(expression, evaluateOptions)
     616    {
     617        var callback = extractCallbackArgument(arguments);
    607618        function callbackWrapper(result)
    608619        {
    609620            callback(result.value, result.isException);
    610621        }
    611         return extensionServer.sendRequest({ command: commands.EvaluateOnInspectedPage, expression: expression }, callback && callbackWrapper);
     622        var request = {
     623            command: commands.EvaluateOnInspectedPage,
     624            expression: expression
     625        };
     626        if (typeof evaluateOptions === "object")
     627            request.evaluateOptions = evaluateOptions;
     628        return extensionServer.sendRequest(request, callback && callbackWrapper);
    612629    },
    613630
     
    787804}
    788805
     806function extractCallbackArgument(args)
     807{
     808    var lastArgument = args[args.length - 1];
     809    return typeof lastArgument === "function" ? lastArgument : undefined;
     810}
     811
    789812var AuditCategory = declareInterfaceClass(AuditCategoryImpl);
    790813var AuditResult = declareInterfaceClass(AuditResultImpl);
  • trunk/Source/WebCore/inspector/front-end/ExtensionPanel.js

    r114740 r116957  
    246246     * @param {function(?string=)} callback
    247247     */
    248     setExpression: function(expression, title, callback)
     248    setExpression: function(expression, title, evaluateOptions, securityOrigin, callback)
    249249    {
    250250        this._createObjectPropertiesView();
    251         RuntimeAgent.evaluate(expression, "extension-watch", true, undefined, undefined, undefined, this._onEvaluate.bind(this, title, callback));
     251        return WebInspector.extensionServer.evaluate(expression, true, false, evaluateOptions, securityOrigin, this._onEvaluate.bind(this, title, callback));
    252252    },
    253253
  • trunk/Source/WebCore/inspector/front-end/ExtensionServer.js

    r114241 r116957  
    261261        }
    262262        if (message.evaluateOnPage)
    263             sidebar.setExpression(message.expression, message.rootTitle, callback.bind(this));
    264         else
    265             sidebar.setObject(message.expression, message.rootTitle, callback.bind(this));
     263            return sidebar.setExpression(message.expression, message.rootTitle, message.evaluateOptions, port._extensionOrigin, callback.bind(this));
     264        sidebar.setObject(message.expression, message.rootTitle, callback.bind(this));
    266265    },
    267266
     
    339338            this._dispatchCallback(message.requestId, port, result);
    340339        }
    341         RuntimeAgent.evaluate(message.expression, "", true, undefined, undefined, true, callback.bind(this));
     340        return this.evaluate(message.expression, true, true, message.evaluateOptions, port._extensionOrigin, callback.bind(this));
    342341    },
    343342
     
    724723        }
    725724        return "/" + result.join("/");
     725    },
     726
     727    /**
     728     * @param {string} expression
     729     * @param {boolean} exposeCommandLineAPI
     730     * @param {boolean} returnByValue
     731     * @param {Object} options
     732     * @param {string} securityOrigin
     733     * @param {function(?string, ?RuntimeAgent.RemoteObject, boolean=)} callback
     734     */
     735    evaluate: function(expression, exposeCommandLineAPI, returnByValue, options, securityOrigin, callback)
     736    {
     737        var contextId;
     738        if (typeof options === "object" && options["useContentScriptContext"]) {
     739            var mainFrame = WebInspector.resourceTreeModel.mainFrame;
     740            if (!mainFrame)
     741                return this._status.E_FAILED("main frame not available yet");
     742            var context = WebInspector.javaScriptContextManager.contextByFrameAndSecurityOrigin(mainFrame, securityOrigin);
     743            if (!context)
     744                return this._status.E_NOTFOUND(securityOrigin);
     745            contextId = context.id;
     746        }
     747        RuntimeAgent.evaluate(expression, "extension", exposeCommandLineAPI, true, contextId, returnByValue, callback);
    726748    }
    727749}
  • trunk/Source/WebCore/inspector/front-end/JavaScriptContextManager.js

    r116744 r116957  
    11/*
    2  * Copyright (C) 2011 Google Inc. All rights reserved.
     2 * Copyright (C) 2012 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4444
    4545WebInspector.JavaScriptContextManager.prototype = {
     46    /**
     47     * @param {WebInspector.ResourceTreeFrame} frame
     48     * @param {string} securityOrigin
     49     */
     50    contextByFrameAndSecurityOrigin: function(frame, securityOrigin)
     51    {
     52        var frameContext = this._frameIdToContext[frame.id];
     53        return frameContext && frameContext.contextBySecurityOrigin(securityOrigin);
     54    },
     55
    4656    _frameAdded: function(event)
    4757    {
     
    8898WebInspector.JavaScriptContextManager.prototype.__proto__ = WebInspector.Object.prototype;
    8999
     100/**
     101 * @type {WebInspector.JavaScriptContextManager}
     102 */
     103WebInspector.javaScriptContextManager = null;
    90104
    91105/**
     
    118132
    119133/**
    120  * @param {WebInspector.ExecutionContext} a
    121  * @param {WebInspector.ExecutionContext} b
     134 * @param {*} a
     135 * @param {*} b
     136 * @return {number}
    122137 */
    123138WebInspector.ExecutionContext.comparator = function(a, b)
     
    164179        if (context.isMainWorldContext)
    165180            this._mainWorldContext = context;
    166         else
    167             this._isolatedContexts.push(context);
     181        else {
     182            var insertAt = insertionIndexForObjectInListSortedByFunction(context, this._isolatedContexts, WebInspector.ExecutionContext.comparator);
     183            this._isolatedContexts.splice(insertAt, 0, context);
     184        }
    168185        this.dispatchEventToListeners(WebInspector.FrameEvaluationContext.EventTypes.AddedExecutionContext, this);
    169186    },
     
    176193    isolatedContexts: function()
    177194    {
    178         if (this._isolatedContexts.length)
    179             this._isolatedContexts.sort(WebInspector.ExecutionContext.comparator);
    180195        return this._isolatedContexts;
     196    },
     197
     198    /**
     199     * @param {string} securityOrigin
     200     */
     201    contextBySecurityOrigin: function(securityOrigin)
     202    {
     203        for (var i = 0; i < this._isolatedContexts.length; ++i) {
     204            var context = this._isolatedContexts[i];
     205            if (!context.isMainWorldContext && context.name === securityOrigin)
     206                return context;
     207        }
    181208    },
    182209
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r116854 r116957  
    393393    this.networkLog = new WebInspector.NetworkLog();
    394394    this.domAgent = new WebInspector.DOMAgent();
    395     new WebInspector.JavaScriptContextManager(this.resourceTreeModel, this.consoleView);
     395    this.javaScriptContextManager = new WebInspector.JavaScriptContextManager(this.resourceTreeModel, this.consoleView);
    396396
    397397    InspectorBackend.registerInspectorDispatcher(this);
Note: See TracChangeset for help on using the changeset viewer.