Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2306)

Unified Diff: Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js

Issue 472353002: DevTools: Get rid of WebInspector.PresentationMessage interface (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js
diff --git a/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js b/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js
index cb4e509a28fdde460c882c6aea37a6864c3177a7..5cbb1b412f7517ecd54430dc6024a2e52aa964eb 100644
--- a/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js
+++ b/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js
@@ -34,12 +34,19 @@
*/
WebInspector.PresentationConsoleMessageHelper = function(workspace)
{
- /**
- * @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>}
- */
+ this._workspace = workspace;
+
+ /** @type {!Object.<string, !Array.<!WebInspector.ConsoleMessage>>} */
this._pendingConsoleMessages = {};
+
+ /** @type {!Array.<!WebInspector.PresentationConsoleMessage>} */
this._presentationConsoleMessages = [];
- this._workspace = workspace;
+
+ /** @type {!Map.<!WebInspector.UISourceCode, !Array.<!WebInspector.PresentationConsoleMessage>>} */
+ this._uiSourceCodeToMessages = new Map();
+
+ /** @type {!Map.<!WebInspector.UISourceCode, !WebInspector.Object>} */
+ this._uiSourceCodeToEventTarget = new Map();
apavlov 2014/08/17 21:32:05 This thing is never cleared.
vsevik 2014/08/18 05:53:07 It should be!
WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdded, this);
@@ -49,8 +56,69 @@ WebInspector.PresentationConsoleMessageHelper = function(workspace)
WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
}
+/**
+ * @enum {string}
+ */
+WebInspector.PresentationConsoleMessageHelper.Events = {
+ ConsoleMessageAdded: "ConsoleMessageAdded",
+ ConsoleMessageRemoved: "ConsoleMessageRemoved",
+ ConsoleMessagesCleared: "ConsoleMessagesCleared",
+}
+
WebInspector.PresentationConsoleMessageHelper.prototype = {
/**
+ * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
+ * @param {!WebInspector.UISourceCode} uiSourceCode
+ * @param {function(!WebInspector.Event)} listener
+ * @param {!Object=} thisObject
+ */
+ addConsoleMessageEventListener: function(eventType, uiSourceCode, listener, thisObject)
+ {
+ var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
+ if (!target) {
+ target = new WebInspector.Object();
+ this._uiSourceCodeToEventTarget.put(uiSourceCode, target);
+ }
+ target.addEventListener(eventType, listener, thisObject);
+ },
+
+ /**
+ * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
+ * @param {!WebInspector.UISourceCode} uiSourceCode
+ * @param {function(!WebInspector.Event)} listener
+ * @param {!Object=} thisObject
+ */
+ removeConsoleMessageEventListener: function(eventType, uiSourceCode, listener, thisObject)
+ {
+ var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
+ if (!target)
+ return;
+ target.removeEventListener(eventType, listener, thisObject);
+ },
+
+ /**
+ * @param {!WebInspector.UISourceCode} uiSourceCode
+ * @return {!Array.<!WebInspector.PresentationConsoleMessage>}
+ */
+ consoleMessages: function(uiSourceCode)
+ {
+ return this._uiSourceCodeToMessages.get(uiSourceCode) || [];
+ },
+
+ /**
+ * @param {!WebInspector.PresentationConsoleMessageHelper.Events} eventType
+ * @param {!WebInspector.UISourceCode} uiSourceCode
+ * @param {!WebInspector.PresentationConsoleMessage=} message
+ */
+ _dispatchConsoleEvent: function(eventType, uiSourceCode, message)
+ {
+ var target = this._uiSourceCodeToEventTarget.get(uiSourceCode);
+ if (!target)
+ return;
+ target.dispatchEventToListeners(eventType, message);
+ },
+
+ /**
* @param {!WebInspector.Event} event
*/
_onConsoleMessageAdded: function(event)
@@ -134,15 +202,44 @@ WebInspector.PresentationConsoleMessageHelper.prototype = {
delete this._pendingConsoleMessages[script.sourceURL];
},
+ /**
+ * @param {!WebInspector.PresentationConsoleMessage} message
+ */
+ _presentationConsoleMessageAdded: function(message)
+ {
+ var uiSourceCode = message._uiLocation.uiSourceCode;
+ var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
+ if (!messages) {
+ messages = [];
+ this._uiSourceCodeToMessages.put(uiSourceCode, messages);
+ }
+ messages.push(message);
+ this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper.Events.ConsoleMessageAdded, uiSourceCode, message);
+ },
+
+ /**
+ * @param {!WebInspector.PresentationConsoleMessage} message
+ */
+ _presentationConsoleMessageRemoved: function(message)
+ {
+ var uiSourceCode = message._uiLocation.uiSourceCode;
+ var messages = this._uiSourceCodeToMessages.get(uiSourceCode);
+ if (!messages)
+ return;
+ messages.remove(message);
+ this._dispatchConsoleEvent(WebInspector.PresentationConsoleMessageHelper.Events.ConsoleMessageRemoved, uiSourceCode, message);
+ },
+
_consoleCleared: function()
{
this._pendingConsoleMessages = {};
for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
this._presentationConsoleMessages[i].dispose();
this._presentationConsoleMessages = [];
- var uiSourceCodes = this._workspace.uiSourceCodes();
- for (var i = 0; i < uiSourceCodes.length; ++i)
- uiSourceCodes[i].consoleMessagesCleared();
+ var targets = this._uiSourceCodeToEventTarget.values();
+ for (var i = 0; i < targets.length; ++i)
+ targets[i].dispatchEventToListeners(WebInspector.PresentationConsoleMessageHelper.Events.ConsoleMessagesCleared);
+ this._uiSourceCodeToMessages.clear();
},
_debuggerReset: function()
@@ -154,7 +251,6 @@ WebInspector.PresentationConsoleMessageHelper.prototype = {
/**
* @constructor
- * @implements {WebInspector.PresentationMessage}
* @param {!WebInspector.ConsoleMessage} message
* @param {!WebInspector.DebuggerModel.Location} rawLocation
*/
@@ -171,9 +267,9 @@ WebInspector.PresentationConsoleMessage.prototype = {
_updateLocation: function(uiLocation)
{
if (this._uiLocation)
- this._uiLocation.uiSourceCode.consoleMessageRemoved(this);
+ WebInspector.presentationConsoleMessageHelper._presentationConsoleMessageRemoved(this);
this._uiLocation = uiLocation;
- this._uiLocation.uiSourceCode.consoleMessageAdded(this);
+ WebInspector.presentationConsoleMessageHelper._presentationConsoleMessageAdded(this);
},
get lineNumber()
@@ -186,3 +282,6 @@ WebInspector.PresentationConsoleMessage.prototype = {
this._liveLocation.dispose();
}
}
+
+/** @type {!WebInspector.PresentationConsoleMessageHelper} */
+WebInspector.presentationConsoleMessageHelper;
« no previous file with comments | « no previous file | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698