2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 WebInspector.JavaScriptContextManager = function(resourceTreeModel, consoleView)
33 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
34 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
35 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
36 this._consoleView = consoleView;
37 this._frameIdToContext = {};
40 WebInspector.JavaScriptContextManager.prototype = {
41 _frameAdded: function(event)
43 var frame = event.data;
44 var parentFrameId = frame.parentId;
45 var context = new WebInspector.FrameEvaluationContext(frame);
46 this._frameIdToContext[frame.id] = context;
47 this._consoleView.addContext(context);
50 _frameNavigated: function(event)
52 var frame = event.data.frame;
53 var context = this._frameIdToContext[frame.id];
55 context._frameNavigated(frame);
58 _frameDetached: function(event)
60 var frameId = event.data;
61 var context = this._frameIdToContext[frameId];
64 this._consoleView.removeContext(context);
65 delete this._frameIdToContext[frameId];
69 WebInspector.JavaScriptContextManager.prototype.__proto__ = WebInspector.Object.prototype;
71 WebInspector.FrameEvaluationContext = function(frame)
76 WebInspector.FrameEvaluationContext.EventTypes = {
80 WebInspector.FrameEvaluationContext.prototype =
82 _frameNavigated: function(frame)
85 this.dispatchEventToListeners(WebInspector.FrameEvaluationContext.EventTypes.Updated, this);
95 return this._frame.url;
100 if (!this._frame.parentId)
101 return "<top frame>";
102 var name = this._frame.name || "";
103 var subtitle = new WebInspector.Resource(null, this._frame.url).displayName;
107 return name + "( " + subtitle + " )";
113 WebInspector.FrameEvaluationContext.prototype.__proto__ = WebInspector.Object.prototype;