Changeset 127412 in webkit


Ignore:
Timestamp:
Sep 3, 2012 1:54:43 AM (12 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: get rid of context execution id fallback.
https://bugs.webkit.org/show_bug.cgi?id=95567

Reviewed by Yury Semikhatsky.

Source/WebCore:

We now assign execution context id upon changes in the UI.

  • inspector/front-end/ConsoleView.js:

(WebInspector.ConsoleView.prototype.get statusBarItems):
(WebInspector.ConsoleView.prototype._contextAdded):
(WebInspector.ConsoleView.prototype._addContextList):
(WebInspector.ConsoleView.prototype._contextListRemoved):
(WebInspector.ConsoleView.prototype._updateExecutionContextSelector):
(WebInspector.ConsoleView.prototype._appendExecutionContextOption):
(WebInspector.ConsoleView.prototype._executionContextChanged):
(WebInspector.ConsoleView.prototype._contextListUpdated):
(WebInspector.ConsoleView.prototype._addedExecutionContext):
(WebInspector.ConsoleView.prototype.evalInInspectedWindow.evalCallback):
(WebInspector.ConsoleView.prototype.evalInInspectedWindow):
(WebInspector.ConsoleView.prototype._enterKeyPressed):

  • inspector/front-end/JavaScriptContextManager.js:

(WebInspector.JavaScriptContextManager):
(WebInspector.JavaScriptContextManager.prototype.contextLists):
(WebInspector.JavaScriptContextManager.prototype.contextByFrameAndSecurityOrigin):
(WebInspector.JavaScriptContextManager.prototype._frameAdded):
(WebInspector.JavaScriptContextManager.prototype._frameNavigated):
(WebInspector.JavaScriptContextManager.prototype._frameDetached):
(WebInspector.JavaScriptContextManager.prototype.isolatedContextCreated):
(WebInspector.FrameExecutionContextList):
(WebInspector.FrameExecutionContextList.prototype._frameNavigated):
(WebInspector.FrameExecutionContextList.prototype._addExecutionContext):
(WebInspector.FrameExecutionContextList.prototype.executionContexts):
(WebInspector.FrameExecutionContextList.prototype.contextBySecurityOrigin):

LayoutTests:

  • http/tests/inspector/console-cd-completions.html:
  • http/tests/inspector/console-cd.html:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r127410 r127412  
     12012-08-31  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: get rid of context execution id fallback.
     4        https://bugs.webkit.org/show_bug.cgi?id=95567
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * http/tests/inspector/console-cd-completions.html:
     9        * http/tests/inspector/console-cd.html:
     10
    1112012-09-03  Yoshifumi Inoue  <yosin@chromium.org>
    212
  • trunk/LayoutTests/http/tests/inspector/console-cd-completions.html

    r122557 r127412  
    88{
    99    InspectorTest.showConsolePanel();
    10     var selector = WebInspector.consoleView._contextSelector._selectElement;
     10    var selector = WebInspector.consoleView._frameSelector._selectElement;
    1111    var option = selector.firstChild;
    1212    while (option) {
     
    2121    }
    2222    option.selected = true;
    23 
     23    WebInspector.consoleView._frameChanged();
    2424
    2525    WebInspector.consoleView.completionsForExpression("", "myGlob", false, checkCompletions.bind(this));
  • trunk/LayoutTests/http/tests/inspector/console-cd.html

    r122557 r127412  
    99{
    1010    InspectorTest.showConsolePanel();
    11     var selector = WebInspector.consoleView._contextSelector._selectElement;
     11    var selector = WebInspector.consoleView._frameSelector._selectElement;
    1212    var option = selector.firstChild;
    1313    while (option) {
     
    2222    }
    2323    option.selected = true;
     24    WebInspector.consoleView._frameChanged();
     25
    2426    InspectorTest.evaluateInConsoleAndDump("foo", finish);
    2527    function finish()
  • trunk/Source/WebCore/ChangeLog

    r127404 r127412  
     12012-08-31  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Web Inspector: get rid of context execution id fallback.
     4        https://bugs.webkit.org/show_bug.cgi?id=95567
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        We now assign execution context id upon changes in the UI.
     9
     10        * inspector/front-end/ConsoleView.js:
     11        (WebInspector.ConsoleView.prototype.get statusBarItems):
     12        (WebInspector.ConsoleView.prototype._contextAdded):
     13        (WebInspector.ConsoleView.prototype._addContextList):
     14        (WebInspector.ConsoleView.prototype._contextListRemoved):
     15        (WebInspector.ConsoleView.prototype._updateExecutionContextSelector):
     16        (WebInspector.ConsoleView.prototype._appendExecutionContextOption):
     17        (WebInspector.ConsoleView.prototype._executionContextChanged):
     18        (WebInspector.ConsoleView.prototype._contextListUpdated):
     19        (WebInspector.ConsoleView.prototype._addedExecutionContext):
     20        (WebInspector.ConsoleView.prototype.evalInInspectedWindow.evalCallback):
     21        (WebInspector.ConsoleView.prototype.evalInInspectedWindow):
     22        (WebInspector.ConsoleView.prototype._enterKeyPressed):
     23        * inspector/front-end/JavaScriptContextManager.js:
     24        (WebInspector.JavaScriptContextManager):
     25        (WebInspector.JavaScriptContextManager.prototype.contextLists):
     26        (WebInspector.JavaScriptContextManager.prototype.contextByFrameAndSecurityOrigin):
     27        (WebInspector.JavaScriptContextManager.prototype._frameAdded):
     28        (WebInspector.JavaScriptContextManager.prototype._frameNavigated):
     29        (WebInspector.JavaScriptContextManager.prototype._frameDetached):
     30        (WebInspector.JavaScriptContextManager.prototype.isolatedContextCreated):
     31        (WebInspector.FrameExecutionContextList):
     32        (WebInspector.FrameExecutionContextList.prototype._frameNavigated):
     33        (WebInspector.FrameExecutionContextList.prototype._addExecutionContext):
     34        (WebInspector.FrameExecutionContextList.prototype.executionContexts):
     35        (WebInspector.FrameExecutionContextList.prototype.contextBySecurityOrigin):
     36
    1372012-09-03  Grzegorz Czajkowski  <g.czajkowski@samsung.com>
    238
  • trunk/Source/WebCore/inspector/front-end/ConsoleView.js

    r126709 r127412  
    4545    this._clearConsoleButton.addEventListener("click", this._requestClearMessages, this);
    4646
    47     this._contextSelector = new WebInspector.StatusBarComboBox(this._updateIsolatedWorldSelector.bind(this), "console-context");
    48     this._isolatedWorldSelector = new WebInspector.StatusBarComboBox(null, "console-context");
     47    this._frameSelector = new WebInspector.StatusBarComboBox(this._frameChanged.bind(this), "console-context");
     48    this._contextSelector = new WebInspector.StatusBarComboBox(this._contextChanged.bind(this), "console-context");
    4949
    5050    if (hideContextSelector) {
     51        this._frameSelector.element.addStyleClass("hidden");
    5152        this._contextSelector.element.addStyleClass("hidden");
    52         this._isolatedWorldSelector.element.addStyleClass("hidden");
    5353    }
    5454
     
    7474    this._filterBarElement.className = "scope-bar status-bar-item";
    7575
    76     function createDividerElement() {
     76    function createDividerElement()
     77    {
    7778        var dividerElement = document.createElement("div");
    7879        dividerElement.addStyleClass("scope-bar-divider");
     
    8182
    8283    var updateFilterHandler = this._updateFilter.bind(this);
    83     function createFilterElement(category, label) {
     84
     85    function createFilterElement(category, label)
     86    {
    8487        var categoryElement = document.createElement("li");
    8588        categoryElement.category = category;
     
    119122    this.prompt.setHistoryData(WebInspector.settings.consoleHistory.get());
    120123
    121     WebInspector.javaScriptContextManager.contexts().forEach(this._addContext, this);
    122     WebInspector.javaScriptContextManager.addEventListener(WebInspector.JavaScriptContextManager.Events.FrameContextAdded, this._contextAdded, this);
    123     WebInspector.javaScriptContextManager.addEventListener(WebInspector.JavaScriptContextManager.Events.FrameContextRemoved, this._contextRemoved, this);
     124    WebInspector.javaScriptContextManager.contextLists().forEach(this._addFrame, this);
     125    WebInspector.javaScriptContextManager.addEventListener(WebInspector.JavaScriptContextManager.Events.FrameExecutionContextListAdded, this._frameAdded, this);
     126    WebInspector.javaScriptContextManager.addEventListener(WebInspector.JavaScriptContextManager.Events.FrameExecutionContextListRemoved, this._frameRemoved, this);
    124127}
    125128
     
    132135    get statusBarItems()
    133136    {
    134         return [this._clearConsoleButton.element, this._contextSelector.element, this._isolatedWorldSelector.element, this._filterBarElement];
     137        return [this._clearConsoleButton.element, this._frameSelector.element, this._contextSelector.element, this._filterBarElement];
     138    },
     139
     140    /**
     141     * @param {WebInspector.Event} event
     142     */
     143    _frameAdded: function(event)
     144    {
     145        var contextList = /** @type {WebInspector.FrameExecutionContextList} */ event.data;
     146        this._addFrame(contextList);
     147    },
     148
     149    /**
     150     * @param {WebInspector.FrameExecutionContextList} contextList
     151     */
     152    _addFrame: function(contextList)
     153    {
     154        var option = document.createElement("option");
     155        option.text = contextList.displayName;
     156        option.title = contextList.url;
     157        option._contextList = contextList;
     158        contextList._consoleOption = option;
     159        this._frameSelector.addOption(option);
     160        contextList.addEventListener(WebInspector.FrameExecutionContextList.EventTypes.ContextsUpdated, this._frameUpdated, this);
     161        contextList.addEventListener(WebInspector.FrameExecutionContextList.EventTypes.ContextAdded, this._contextAdded, this);
     162        this._frameChanged();
     163    },
     164
     165    /**
     166     * @param {WebInspector.Event} event
     167     */
     168    _frameRemoved: function(event)
     169    {
     170        var contextList = /** @type {WebInspector.FrameExecutionContextList} */ event.data;
     171        this._frameSelector.removeOption(contextList._consoleOption);
     172        this._frameChanged();
     173    },
     174
     175    _frameChanged: function()
     176    {
     177        var context = this._currentFrame();
     178        if (!context) {
     179            delete this._currentExecutionContext;
     180            this._contextSelector.element.addStyleClass("hidden");
     181            return;
     182        }
     183
     184        var executionContexts = context.executionContexts();
     185        if (executionContexts.length)
     186            this._currentExecutionContext = executionContexts[0];
     187
     188        if (executionContexts.length === 1) {
     189            this._contextSelector.element.addStyleClass("hidden");
     190            return;
     191        }
     192        this._contextSelector.element.removeStyleClass("hidden");
     193        this._contextSelector.removeOptions();
     194        for (var i = 0; i < executionContexts.length; i++)
     195            this._appendContextOption(executionContexts[i]);
     196    },
     197
     198    /**
     199     * @param {WebInspector.ExecutionContext} executionContext
     200     */
     201    _appendContextOption: function(executionContext)
     202    {
     203        if (!this._currentExecutionContext)
     204            this._currentExecutionContext = executionContext;
     205        var option = document.createElement("option");
     206        option.text = executionContext.name;
     207        option.title = executionContext.id;
     208        option._executionContext = executionContext;
     209        this._contextSelector.addOption(option);
     210    },
     211
     212    /**
     213     * @param {Event} event
     214     */
     215    _contextChanged: function(event)
     216    {
     217        var option = this._contextSelector.selectedOption();
     218        this._currentExecutionContext = option ? option._executionContext : undefined;
     219    },
     220
     221    /**
     222     * @param {WebInspector.Event} event
     223     */
     224    _frameUpdated: function(event)
     225    {
     226        var contextList = /** {WebInspector.FrameExecutionContextList */ event.data;
     227        var option = contextList._consoleOption;
     228        option.text = contextList.displayName;
     229        option.title = contextList.url;
    135230    },
    136231
     
    140235    _contextAdded: function(event)
    141236    {
    142         var context = /** @type {WebInspector.FrameEvaluationContext} */ event.data;
    143         this._addContext(context);
     237        var contextList = /** {WebInspector.FrameExecutionContextList */ event.data;
     238        if (contextList === this._currentFrame())
     239            this._frameChanged();
    144240    },
    145241
    146242    /**
    147      * @param {WebInspector.FrameEvaluationContext} context
     243     * @return {WebInspector.FrameExecutionContextList|undefined}
    148244     */
    149     _addContext: function(context)
    150     {
    151         var option = document.createElement("option");
    152         option.text = context.displayName;
    153         option.title = context.url;
    154         option._context = context;
    155         context._consoleOption = option;
    156         this._contextSelector.addOption(option);
    157         context.addEventListener(WebInspector.FrameEvaluationContext.EventTypes.Updated, this._contextUpdated, this);
    158         context.addEventListener(WebInspector.FrameEvaluationContext.EventTypes.AddedExecutionContext, this._addedExecutionContext, this);
    159         this._updateIsolatedWorldSelector();
    160     },
    161 
    162     /**
    163      * @param {WebInspector.Event} event
    164      */
    165     _contextRemoved: function(event)
    166     {
    167         var context = /** @type {WebInspector.FrameEvaluationContext} */ event.data;
    168         this._contextSelector.removeOption(context._consoleOption);
    169         this._updateIsolatedWorldSelector();
    170     },
    171 
    172     _updateIsolatedWorldSelector: function()
    173     {
    174         var context = this._currentEvaluationContext();
    175         if (!context) {
    176             this._isolatedWorldSelector.element.addStyleClass("hidden");
    177             return;
    178         }
    179 
    180         var isolatedContexts = context.isolatedContexts();
    181         if (!isolatedContexts.length) {
    182             this._isolatedWorldSelector.element.addStyleClass("hidden");
    183             return;
    184         }
    185         this._isolatedWorldSelector.element.removeStyleClass("hidden");
    186         this._isolatedWorldSelector.removeOptions();
    187         this._appendIsolatedContextOption(context.mainWorldContext());
    188         for (var i = 0; i < isolatedContexts.length; i++)
    189             this._appendIsolatedContextOption(isolatedContexts[i]);
    190     },
    191 
    192     _appendIsolatedContextOption: function(isolatedContext)
    193     {
    194         if (!isolatedContext)
    195             return;
    196         var option = document.createElement("option");
    197         option.text = isolatedContext.name;
    198         option.title = isolatedContext.id;
    199         option._executionContextId = isolatedContext.id;
    200         this._isolatedWorldSelector.addOption(option);
    201     },
    202 
    203     _contextUpdated: function(event)
    204     {
    205         var context = event.data;
    206         var option = context._consoleOption;
    207         option.text = context.displayName;
    208         option.title = context.url;
    209     },
    210 
    211     _addedExecutionContext: function(event)
    212     {
    213         var context = event.data;
    214         if (context === this._currentEvaluationContext())
    215             this._updateIsolatedWorldSelector();
    216     },
    217 
    218     _currentEvaluationContextId: function()
    219     {
    220         var result = this._currentIsolatedContextId();
    221         if (result !== undefined)
    222             return result;
    223         var context = this._currentEvaluationContext();
    224         if (context && context.mainWorldContext())
    225             return context.mainWorldContext().id;
    226         return undefined;
    227     },
    228 
    229     _currentEvaluationContext: function()
    230     {
    231         var option = this._contextSelector.selectedOption();
    232         if (!option)
    233             return undefined;
    234         return option._context;
    235     },
    236 
    237     _currentIsolatedContextId: function()
    238     {
    239         if (this._isolatedWorldSelector.element.hasStyleClass("hidden"))
    240             return undefined;
    241         var option = this._isolatedWorldSelector.selectedOption();
    242         if (!option)
    243             return undefined;
    244         return option._executionContextId;
     245    _currentFrame: function()
     246    {
     247        var option = this._frameSelector.selectedOption();
     248        return option ? option._contextList : undefined;
    245249    },
    246250
     
    707711                callback(WebInspector.RemoteObject.fromPayload(result), !!wasThrown);
    708712        }
    709         var contextId = this._currentEvaluationContextId();
    710         RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, contextId, returnByValue, evalCallback);
     713        RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this._currentExecutionContext ? this._currentExecutionContext.id : undefined, returnByValue, evalCallback);
    711714    },
    712715
     
    733736    runScript: function(scriptId)
    734737    {
    735         var contextId = WebInspector.consoleView._currentEvaluationContextId();
    736         DebuggerAgent.runScript(scriptId, contextId, "console", false, runCallback.bind(this));
     738        DebuggerAgent.runScript(scriptId, this._currentExecutionContext ? this._currentExecutionContext.id : undefined, "console", false, runCallback.bind(this));
    737739        WebInspector.userMetrics.ConsoleEvaluated.record();
    738740
  • trunk/Source/WebCore/inspector/front-end/JavaScriptContextManager.js

    r126709 r127412  
    4040    resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
    4141    resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded, this._didLoadCachedResources, this);
    42     this._frameIdToContext = {};
     42    this._frameIdToContextList = {};
    4343}
    4444
    4545WebInspector.JavaScriptContextManager.Events = {
    46     FrameContextAdded: "FrameContextAdded",
    47     FrameContextRemoved: "FrameContextRemoved",
     46    FrameExecutionContextListAdded: "FrameExecutionContextListAdded",
     47    FrameExecutionContextListRemoved: "FrameExecutionContextListRemoved",
    4848}
    4949
    5050WebInspector.JavaScriptContextManager.prototype = {
    5151    /**
    52      * @return {Array.<WebInspector.FrameEvaluationContext>}
    53      */
    54     contexts: function()
    55     {
    56         return Object.values(this._frameIdToContext);
     52     * @return {Array.<WebInspector.FrameExecutionContextList>}
     53     */
     54    contextLists: function()
     55    {
     56        return Object.values(this._frameIdToContextList);
    5757    },
    5858
     
    6363    contextByFrameAndSecurityOrigin: function(frame, securityOrigin)
    6464    {
    65         var frameContext = this._frameIdToContext[frame.id];
     65        var frameContext = this._frameIdToContextList[frame.id];
    6666        return frameContext && frameContext.contextBySecurityOrigin(securityOrigin);
    6767    },
     
    7070    {
    7171        var frame = event.data;
    72         var context = new WebInspector.FrameEvaluationContext(frame);
    73         this._frameIdToContext[frame.id] = context;
    74         this.dispatchEventToListeners(WebInspector.JavaScriptContextManager.Events.FrameContextAdded, context);
     72        var context = new WebInspector.FrameExecutionContextList(frame);
     73        this._frameIdToContextList[frame.id] = context;
     74        this.dispatchEventToListeners(WebInspector.JavaScriptContextManager.Events.FrameExecutionContextListAdded, context);
    7575    },
    7676
     
    7878    {
    7979        var frame = event.data;
    80         var context = this._frameIdToContext[frame.id];
     80        var context = this._frameIdToContextList[frame.id];
    8181        if (context)
    8282            context._frameNavigated(frame);
     
    8686    {
    8787        var frame = event.data;
    88         var context = this._frameIdToContext[frame.id];
     88        var context = this._frameIdToContextList[frame.id];
    8989        if (!context)
    9090            return;
    91         this.dispatchEventToListeners(WebInspector.JavaScriptContextManager.Events.FrameContextRemoved, context);
    92         delete this._frameIdToContext[frame.id];
     91        this.dispatchEventToListeners(WebInspector.JavaScriptContextManager.Events.FrameExecutionContextListRemoved, context);
     92        delete this._frameIdToContextList[frame.id];
    9393    },
    9494
     
    101101    isolatedContextCreated: function(context)
    102102    {
    103         var frameEvaluationContext = this._frameIdToContext[context.frameId];
     103        var contextList = this._frameIdToContextList[context.frameId];
    104104        // FIXME(85708): this should never happen
    105         if (!frameEvaluationContext)
     105        if (!contextList)
    106106            return;
    107         frameEvaluationContext._addExecutionContext(new WebInspector.ExecutionContext(context.id, context.name, context.isPageContext));
     107        contextList._addExecutionContext(new WebInspector.ExecutionContext(context.id, context.name, context.isPageContext));
    108108    }
    109109}
     
    163163 * @extends {WebInspector.Object}
    164164 */
    165 WebInspector.FrameEvaluationContext = function(frame)
     165WebInspector.FrameExecutionContextList = function(frame)
    166166{
    167167    this._frame = frame;
    168     this._mainWorldContext = null;
    169     this._isolatedContexts = [];
    170 }
    171 
    172 WebInspector.FrameEvaluationContext.EventTypes = {
    173     Updated: "Updated",
    174     AddedExecutionContext: "AddedExecutionContext"
    175 }
    176 
    177 WebInspector.FrameEvaluationContext.prototype =
     168    this._executionContexts = [];
     169}
     170
     171WebInspector.FrameExecutionContextList.EventTypes = {
     172    ContextsUpdated: "ContextsUpdated",
     173    ContextAdded: "ContextAdded"
     174}
     175
     176WebInspector.FrameExecutionContextList.prototype =
    178177{
    179178    _frameNavigated: function(frame)
    180179    {
    181180        this._frame = frame;
    182         this._mainWorldContext = null;
    183         this._isolatedContexts = [];
    184         this.dispatchEventToListeners(WebInspector.FrameEvaluationContext.EventTypes.Updated, this);
     181        this._executionContexts = [];
     182        this.dispatchEventToListeners(WebInspector.FrameExecutionContextList.EventTypes.ContextsUpdated, this);
    185183    },
    186184
     
    190188    _addExecutionContext: function(context)
    191189    {
    192         if (context.isMainWorldContext)
    193             this._mainWorldContext = context;
    194         else {
    195             var insertAt = insertionIndexForObjectInListSortedByFunction(context, this._isolatedContexts, WebInspector.ExecutionContext.comparator);
    196             this._isolatedContexts.splice(insertAt, 0, context);
    197         }
    198         this.dispatchEventToListeners(WebInspector.FrameEvaluationContext.EventTypes.AddedExecutionContext, this);
    199     },
    200 
    201     mainWorldContext: function()
    202     {
    203         return this._mainWorldContext;
    204     },
    205 
    206     isolatedContexts: function()
    207     {
    208         return this._isolatedContexts;
     190        var insertAt = insertionIndexForObjectInListSortedByFunction(context, this._executionContexts, WebInspector.ExecutionContext.comparator);
     191        this._executionContexts.splice(insertAt, 0, context);
     192        this.dispatchEventToListeners(WebInspector.FrameExecutionContextList.EventTypes.ContextAdded, this);
     193    },
     194
     195    executionContexts: function()
     196    {
     197        return this._executionContexts;
    209198    },
    210199
     
    214203    contextBySecurityOrigin: function(securityOrigin)
    215204    {
    216         for (var i = 0; i < this._isolatedContexts.length; ++i) {
    217             var context = this._isolatedContexts[i];
     205        for (var i = 0; i < this._executionContexts.length; ++i) {
     206            var context = this._executionContexts[i];
    218207            if (!context.isMainWorldContext && context.name === securityOrigin)
    219208                return context;
     
    246235}
    247236
    248 WebInspector.FrameEvaluationContext.prototype.__proto__ = WebInspector.Object.prototype;
     237WebInspector.FrameExecutionContextList.prototype.__proto__ = WebInspector.Object.prototype;
Note: See TracChangeset for help on using the changeset viewer.