Web Inspector: Split ConsoleMessageImpl into the View and the Model
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Apr 2015 01:37:58 +0000 (01:37 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 9 Apr 2015 01:37:58 +0000 (01:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142599

Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

* UserInterface/Models/ConsoleMessage.js: Added.
(WebInspector.ConsoleMessage):
(WebInspector.ConsoleMessage.prototype.get source):
(WebInspector.ConsoleMessage.prototype.get level):
(WebInspector.ConsoleMessage.prototype.get messageText):
(WebInspector.ConsoleMessage.prototype.get type):
(WebInspector.ConsoleMessage.prototype.get url):
(WebInspector.ConsoleMessage.prototype.get line):
(WebInspector.ConsoleMessage.prototype.get column):
(WebInspector.ConsoleMessage.prototype.get repeatCount):
(WebInspector.ConsoleMessage.prototype.get parameters):
(WebInspector.ConsoleMessage.prototype.get stackTrace):
(WebInspector.ConsoleMessage.prototype.get request):
New readonly model object for console messages.

* UserInterface/Main.html:
* UserInterface/Test.html:
* UserInterface/Base/Test.js:
(WebInspector.loaded):
Load the new files in the main / test page.

* UserInterface/Views/LegacyConsoleMessage.js: Removed.
* UserInterface/Views/LegacyConsoleMessageImpl.js: Removed.
Remove Legacy versions.

* UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
* UserInterface/Controllers/JavaScriptLogViewController.js:
(WebInspector.JavaScriptLogViewController):
(WebInspector.JavaScriptLogViewController.prototype.startNewSession):
(WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult.saveResultCallback):
(WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult):
(WebInspector.JavaScriptLogViewController.prototype.appendConsoleMessage):
(WebInspector.JavaScriptLogViewController.prototype.updatePreviousMessageRepeatCount):
(WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted.printResult):
(WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted):
(WebInspector.JavaScriptLogViewController.prototype._appendConsoleMessageView):
(WebInspector.JavaScriptLogViewController.prototype._appendConsoleMessage): Deleted.
Update LogViewController to create ConsoleMessageViews from ConsoleMessages when applicable.
Also clarify when we have a view versus model object.

* UserInterface/Protocol/ConsoleObserver.js:
(WebInspector.ConsoleObserver.prototype.messageAdded):
* UserInterface/Controllers/LogManager.js:
(WebInspector.LogManager.prototype.messageWasAdded):
(WebInspector.LogManager.prototype.messagesCleared):
(WebInspector.LogManager.prototype._mainResourceDidChange):
Create model objects and issue events for the model objects.

* UserInterface/Models/DefaultDashboard.js:
(WebInspector.DefaultDashboard.prototype._consoleMessageAdded):
(WebInspector.DefaultDashboard.prototype._incrementConsoleMessageType):
Update now that the event gives us a model object.

* UserInterface/Views/ConsoleMessageView.js: Added.
(WebInspector.ConsoleMessageView):
(WebInspector.ConsoleMessageView.prototype.get element):
(WebInspector.ConsoleMessageView.prototype.get message):
(WebInspector.ConsoleMessageView.prototype.get repeatCount):
(WebInspector.ConsoleMessageView.prototype.set repeatCount):
(WebInspector.ConsoleMessageView.prototype.toClipboardString):
(WebInspector.ConsoleMessageView.prototype._appendMessageTextAndArguments):
(WebInspector.ConsoleMessageView.prototype._appendSavedResultIndex):
(WebInspector.ConsoleMessageView.prototype._appendLocationLink):
(WebInspector.ConsoleMessageView.prototype._appendParameters):
(WebInspector.ConsoleMessageView.prototype._appendStackTrace):
(WebInspector.ConsoleMessageView.prototype._appendFormattedArguments):
(WebInspector.ConsoleMessageView.prototype._formatParameter):
(WebInspector.ConsoleMessageView.prototype._formatParameterAsValue):
(WebInspector.ConsoleMessageView.prototype._formatParameterAsString):
(WebInspector.ConsoleMessageView.prototype._formatParameterAsNode):
(WebInspector.ConsoleMessageView.prototype._formatParameterAsObject):
(WebInspector.ConsoleMessageView.prototype._formatParameterAsArray):
(WebInspector.ConsoleMessageView.prototype._rootPropertyPathForObject):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.parameterFormatter):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.stringFormatter):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.floatFormatter):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.integerFormatter):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.styleFormatter):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.isWhitelistedProperty):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.append):
(WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString):
(WebInspector.ConsoleMessageView.prototype._shouldShowStackTrace):
(WebInspector.ConsoleMessageView.prototype._shouldHideURL):
(WebInspector.ConsoleMessageView.prototype._firstNonNativeCallFrame):
(WebInspector.ConsoleMessageView.prototype._linkifyLocation):
(WebInspector.ConsoleMessageView.prototype._linkifyCallFrame):
(WebInspector.ConsoleMessageView.prototype._userProvidedColumnNames):
(WebInspector.ConsoleMessageView.prototype._formatParameterAsTable):
(WebInspector.ConsoleMessageView.prototype._levelString):
(WebInspector.ConsoleMessageView.prototype._enforcesClipboardPrefixString):
(WebInspector.ConsoleMessageView.prototype._clipboardPrefixString):
New View class for a ConsoleMessage. This is a near direct port of the old code
to a view class that has a root element.

* UserInterface/Models/ConsoleCommandResultMessage.js: Renamed from Source/WebInspectorUI/UserInterface/Views/ConsoleCommandResult.js.
(WebInspector.ConsoleCommandResultMessage):
(WebInspector.ConsoleCommandResultMessage.clearMaximumSavedResultIndex):
(WebInspector.ConsoleCommandResultMessage.prototype.get savedResultIndex):
Rename, as this is a ConsoleMessage subclass with a specific type for console evaluation results.

* UserInterface/Views/ConsoleCommandView.js: Renamed from Source/WebInspectorUI/UserInterface/Views/ConsoleCommand.js.
(WebInspector.ConsoleCommandView):
(WebInspector.ConsoleCommandView.prototype.get element):
(WebInspector.ConsoleCommandView.prototype.get commandText):
(WebInspector.ConsoleCommandView.prototype.get message):
(WebInspector.ConsoleCommandView.prototype.toClipboardString):
* UserInterface/Views/ConsoleGroup.js:
(WebInspector.ConsoleGroup):
(WebInspector.ConsoleGroup.prototype.get parentGroup):
(WebInspector.ConsoleGroup.prototype.render):
(WebInspector.ConsoleGroup.prototype.addMessageView):
(WebInspector.ConsoleGroup.prototype.append):
(WebInspector.ConsoleGroup.prototype._titleMouseDown):
(WebInspector.ConsoleGroup.prototype.addMessage): Deleted.
(WebInspector.ConsoleGroup.prototype._titleClicked): Deleted.
* UserInterface/Views/ConsoleSession.js:
(WebInspector.ConsoleSession):
(WebInspector.ConsoleSession.prototype.addMessageView):
(WebInspector.ConsoleSession.prototype.append):
(WebInspector.ConsoleSession.prototype.addMessage): Deleted.
(WebInspector.ConsoleSession.prototype.hasMessages): Deleted.
Convert to classes, and clarify these deal with View objects.

* UserInterface/Views/LogContentView.css:
(.console-message .repeat-count):
(.console-message .bubble): Deleted.
Better class name for the repeat count element.

* UserInterface/Views/LogContentView.js:
(WebInspector.LogContentView.prototype.didAppendConsoleMessageView):
(WebInspector.LogContentView.prototype._formatMessagesAsData):
(WebInspector.LogContentView.prototype._messageAdded):
(WebInspector.LogContentView.prototype._updateMessagesSelection):
(WebInspector.LogContentView.prototype._selectAllMessages):
(WebInspector.LogContentView.prototype._allMessageElements):
(WebInspector.LogContentView.prototype._unfilteredMessageElements):
(WebInspector.LogContentView.prototype._visibleMessageElements):
(WebInspector.LogContentView.prototype._scopeBarSelectionDidChange):
(WebInspector.LogContentView.prototype._filterMessageElements):
(WebInspector.LogContentView.prototype._upArrowWasPressed):
(WebInspector.LogContentView.prototype._downArrowWasPressed):
(WebInspector.LogContentView.prototype._previousMessage):
(WebInspector.LogContentView.prototype._nextMessage):
(WebInspector.LogContentView.prototype._performSearch):
(WebInspector.LogContentView.prototype._highlightRanges):
(WebInspector.LogContentView.prototype._reappendProvisionalMessages):
(WebInspector.LogContentView.prototype.didAppendConsoleMessage): Deleted.
(WebInspector.LogContentView.prototype._allMessages): Deleted.
(WebInspector.LogContentView.prototype._unfilteredMessages): Deleted.
(WebInspector.LogContentView.prototype._visibleMessages): Deleted.
(WebInspector.LogContentView.prototype._filterMessages): Deleted.
Rename lots of things to make it clear when we are dealing with
elements, model objects, or view objects. This class is still heavily
dealing with elements, and needs to be cleaned up later.

LayoutTests:

* inspector/console/console-api-expected.txt: Added.
* inspector/console/console-api.html: Added.
Add a basic test for console APIs creating the new ConsoleMessage model objects.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182579 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/console/console-api-expected.txt [new file with mode: 0644]
LayoutTests/inspector/console/console-api.html [new file with mode: 0644]
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Test.js
Source/WebInspectorUI/UserInterface/Controllers/JavaScriptLogViewController.js
Source/WebInspectorUI/UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js
Source/WebInspectorUI/UserInterface/Controllers/LogManager.js
Source/WebInspectorUI/UserInterface/Main.html
Source/WebInspectorUI/UserInterface/Models/ConsoleCommandResultMessage.js [moved from Source/WebInspectorUI/UserInterface/Views/ConsoleCommandResult.js with 50% similarity]
Source/WebInspectorUI/UserInterface/Models/ConsoleMessage.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Models/DefaultDashboard.js
Source/WebInspectorUI/UserInterface/Protocol/ConsoleObserver.js
Source/WebInspectorUI/UserInterface/Test.html
Source/WebInspectorUI/UserInterface/Views/ConsoleCommandView.js [moved from Source/WebInspectorUI/UserInterface/Views/ConsoleCommand.js with 60% similarity]
Source/WebInspectorUI/UserInterface/Views/ConsoleGroup.js
Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js [new file with mode: 0644]
Source/WebInspectorUI/UserInterface/Views/ConsoleSession.js
Source/WebInspectorUI/UserInterface/Views/LegacyConsoleMessage.js [deleted file]
Source/WebInspectorUI/UserInterface/Views/LegacyConsoleMessageImpl.js [deleted file]
Source/WebInspectorUI/UserInterface/Views/LogContentView.css
Source/WebInspectorUI/UserInterface/Views/LogContentView.js

index 5d2d6081a213de9f770d64440563b393ab3e0826..300708cf9cde0dae15610a282699b5140c856103 100644 (file)
@@ -1,3 +1,14 @@
+2015-04-08  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Split ConsoleMessageImpl into the View and the Model
+        https://bugs.webkit.org/show_bug.cgi?id=142599
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/console/console-api-expected.txt: Added.
+        * inspector/console/console-api.html: Added.
+        Add a basic test for console APIs creating the new ConsoleMessage model objects.
+
 2015-04-08  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Document some test failures.
diff --git a/LayoutTests/inspector/console/console-api-expected.txt b/LayoutTests/inspector/console/console-api-expected.txt
new file mode 100644 (file)
index 0000000..98752b9
--- /dev/null
@@ -0,0 +1,597 @@
+CONSOLE MESSAGE: line 1: console.log
+CONSOLE MESSAGE: line 1: console.warn
+CONSOLE MESSAGE: line 1: console.error
+CONSOLE MESSAGE: line 1: console.debug
+CONSOLE MESSAGE: line 1: console.info
+CONSOLE MESSAGE: line 1: assertion message
+CONSOLE MESSAGE: line 1: string message
+CONSOLE MESSAGE: line 1: message
+CONSOLE MESSAGE: line 1: message
+CONSOLE MESSAGE: line 1: message
+CONSOLE MESSAGE: line 1: message
+CONSOLE MESSAGE: line 1: message
+CONSOLE MESSAGE: line 1: [object Object]
+CONSOLE MESSAGE: line 1: [object Object]
+CONSOLE MESSAGE: line 1: groupName
+CONSOLE MESSAGE: groupName
+CONSOLE MESSAGE: line 1: collapsedGroupName
+CONSOLE MESSAGE: collapsedGroupName
+
+STEP: console.log('console.log')
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "console.log",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 12,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "console.log",
+      "_hasChildren": false,
+      "_value": "console.log"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.warn('console.warn')
+{
+  "_source": "console-api",
+  "_level": "warning",
+  "_messageText": "console.warn",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 13,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "console.warn",
+      "_hasChildren": false,
+      "_value": "console.warn"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.error('console.error')
+{
+  "_source": "console-api",
+  "_level": "error",
+  "_messageText": "console.error",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "console.error",
+      "_hasChildren": false,
+      "_value": "console.error"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.debug('console.debug')
+{
+  "_source": "console-api",
+  "_level": "debug",
+  "_messageText": "console.debug",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "console.debug",
+      "_hasChildren": false,
+      "_value": "console.debug"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.info('console.info')
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "console.info",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 13,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "console.info",
+      "_hasChildren": false,
+      "_value": "console.info"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.assert(false, 'assertion message')
+{
+  "_source": "console-api",
+  "_level": "error",
+  "_messageText": "assertion message",
+  "_type": "assert",
+  "_url": null,
+  "_line": 1,
+  "_column": 15,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "assertion message",
+      "_hasChildren": false,
+      "_value": "assertion message"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.trace()
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "",
+  "_type": "trace",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.log('string message', string)
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "string message",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 12,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "string message",
+      "_hasChildren": false,
+      "_value": "string message"
+    },
+    {
+      "_type": "string",
+      "_description": "string",
+      "_hasChildren": false,
+      "_value": "string"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.log('message', object, object)
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "message",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 12,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "message",
+      "_hasChildren": false,
+      "_value": "message"
+    },
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    },
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.error('message', object)
+{
+  "_source": "console-api",
+  "_level": "error",
+  "_messageText": "message",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "message",
+      "_hasChildren": false,
+      "_value": "message"
+    },
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.warn('message', object)
+{
+  "_source": "console-api",
+  "_level": "warning",
+  "_messageText": "message",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 13,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "message",
+      "_hasChildren": false,
+      "_value": "message"
+    },
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.debug('message', object)
+{
+  "_source": "console-api",
+  "_level": "debug",
+  "_messageText": "message",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "message",
+      "_hasChildren": false,
+      "_value": "message"
+    },
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.info('message', object)
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "message",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 13,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "message",
+      "_hasChildren": false,
+      "_value": "message"
+    },
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.dir(object)
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "[object Object]",
+  "_type": "dir",
+  "_url": null,
+  "_line": 1,
+  "_column": 12,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.dirxml(object)
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "[object Object]",
+  "_type": "dirxml",
+  "_url": null,
+  "_line": 1,
+  "_column": 15,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "object",
+      "_objectId": "<filtered>",
+      "_description": "Object",
+      "_hasChildren": true,
+      "_preview": {
+        "_type": "object",
+        "_description": "Object",
+        "_lossless": true,
+        "_overflow": false,
+        "_properties": [
+          {
+            "_name": "a",
+            "_type": "number",
+            "_value": "1"
+          }
+        ],
+        "_entries": null
+      }
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.group('groupName')
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "groupName",
+  "_type": "startGroup",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "groupName",
+      "_hasChildren": false,
+      "_value": "groupName"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.groupEnd('groupName')
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "groupName",
+  "_type": "endGroup",
+  "_url": null,
+  "_line": 0,
+  "_column": 0,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "groupName",
+      "_hasChildren": false,
+      "_value": "groupName"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.groupCollapsed('collapsedGroupName')
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "collapsedGroupName",
+  "_type": "startGroupCollapsed",
+  "_url": null,
+  "_line": 1,
+  "_column": 23,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "collapsedGroupName",
+      "_hasChildren": false,
+      "_value": "collapsedGroupName"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.groupEnd('collapsedGroupName')
+{
+  "_source": "console-api",
+  "_level": "log",
+  "_messageText": "collapsedGroupName",
+  "_type": "endGroup",
+  "_url": null,
+  "_line": 0,
+  "_column": 0,
+  "_repeatCount": 1,
+  "_parameters": [
+    {
+      "_type": "string",
+      "_description": "collapsedGroupName",
+      "_hasChildren": false,
+      "_value": "collapsedGroupName"
+    }
+  ],
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
+STEP: console.count()
+{
+  "_source": "console-api",
+  "_level": "debug",
+  "_messageText": ": 1",
+  "_type": "log",
+  "_url": null,
+  "_line": 1,
+  "_column": 14,
+  "_repeatCount": 1,
+  "_stackTrace": "<filtered>",
+  "_request": null
+}
+
diff --git a/LayoutTests/inspector/console/console-api.html b/LayoutTests/inspector/console/console-api.html
new file mode 100644 (file)
index 0000000..37cd597
--- /dev/null
@@ -0,0 +1,61 @@
+<!doctype html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<script type="text/javascript" src="../../http/tests/inspector/inspector-test.js"></script>
+<script>
+var string = "string";
+var object = {a:1};
+
+function test()
+{
+    var currentStepIndex = 0;
+    var steps = [
+        "console.log('console.log')",
+        "console.warn('console.warn')",
+        "console.error('console.error')",
+        "console.debug('console.debug')",
+        "console.info('console.info')",
+        "console.assert(false, 'assertion message')",
+        "console.trace()",
+        "console.log('string message', string)",
+        "console.log('message', object, object)",
+        "console.error('message', object)",
+        "console.warn('message', object)",
+        "console.debug('message', object)",
+        "console.info('message', object)",
+        "console.dir(object)",
+        "console.dirxml(object)",
+        "console.group('groupName')",
+        "console.groupEnd('groupName')",
+        "console.groupCollapsed('collapsedGroupName')",
+        "console.groupEnd('collapsedGroupName')",
+        "console.count()",
+    ];
+
+    function remoteObjectJSONFilter(key, value)
+    {
+        if (key === "_objectId" || key === "_stackTrace")
+            return "<filtered>";
+
+        return value;
+    }
+
+    WebInspector.logManager.addEventListener(WebInspector.LogManager.Event.MessageAdded, function(event) {
+        var message = event.data.message;
+        InspectorTest.assert(message instanceof WebInspector.ConsoleMessage);
+        InspectorTest.log("\nSTEP: " + steps[currentStepIndex]);
+        InspectorTest.log(JSON.stringify(message, remoteObjectJSONFilter, "  "));
+
+        if (++currentStepIndex >= steps.length)
+            InspectorTest.completeTest();
+    });
+
+    for (var step of steps)
+        WebInspector.runtimeManager.evaluateInInspectedWindow(step, "test", false, true, false, true, false, function(){});
+}
+</script>
+</head>
+<body onload="runTest();">
+</body>
+</html>
index 45de5cd361058ed409dbe45c196fba76e2f9716d..530a0c15a981dd58e2144438eee25891631bd991 100644 (file)
@@ -1,3 +1,165 @@
+2015-04-08  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Split ConsoleMessageImpl into the View and the Model
+        https://bugs.webkit.org/show_bug.cgi?id=142599
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Models/ConsoleMessage.js: Added.
+        (WebInspector.ConsoleMessage):
+        (WebInspector.ConsoleMessage.prototype.get source):
+        (WebInspector.ConsoleMessage.prototype.get level):
+        (WebInspector.ConsoleMessage.prototype.get messageText):
+        (WebInspector.ConsoleMessage.prototype.get type):
+        (WebInspector.ConsoleMessage.prototype.get url):
+        (WebInspector.ConsoleMessage.prototype.get line):
+        (WebInspector.ConsoleMessage.prototype.get column):
+        (WebInspector.ConsoleMessage.prototype.get repeatCount):
+        (WebInspector.ConsoleMessage.prototype.get parameters):
+        (WebInspector.ConsoleMessage.prototype.get stackTrace):
+        (WebInspector.ConsoleMessage.prototype.get request):
+        New readonly model object for console messages.
+
+        * UserInterface/Main.html:
+        * UserInterface/Test.html:
+        * UserInterface/Base/Test.js:
+        (WebInspector.loaded):
+        Load the new files in the main / test page.
+
+        * UserInterface/Views/LegacyConsoleMessage.js: Removed.
+        * UserInterface/Views/LegacyConsoleMessageImpl.js: Removed.
+        Remove Legacy versions.
+
+        * UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
+        * UserInterface/Controllers/JavaScriptLogViewController.js:
+        (WebInspector.JavaScriptLogViewController):
+        (WebInspector.JavaScriptLogViewController.prototype.startNewSession):
+        (WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult.saveResultCallback):
+        (WebInspector.JavaScriptLogViewController.prototype.appendImmediateExecutionWithResult):
+        (WebInspector.JavaScriptLogViewController.prototype.appendConsoleMessage):
+        (WebInspector.JavaScriptLogViewController.prototype.updatePreviousMessageRepeatCount):
+        (WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted.printResult):
+        (WebInspector.JavaScriptLogViewController.prototype.consolePromptTextCommitted):
+        (WebInspector.JavaScriptLogViewController.prototype._appendConsoleMessageView):
+        (WebInspector.JavaScriptLogViewController.prototype._appendConsoleMessage): Deleted.
+        Update LogViewController to create ConsoleMessageViews from ConsoleMessages when applicable.
+        Also clarify when we have a view versus model object.
+
+        * UserInterface/Protocol/ConsoleObserver.js:
+        (WebInspector.ConsoleObserver.prototype.messageAdded):
+        * UserInterface/Controllers/LogManager.js:
+        (WebInspector.LogManager.prototype.messageWasAdded):
+        (WebInspector.LogManager.prototype.messagesCleared):
+        (WebInspector.LogManager.prototype._mainResourceDidChange):
+        Create model objects and issue events for the model objects.
+
+        * UserInterface/Models/DefaultDashboard.js:
+        (WebInspector.DefaultDashboard.prototype._consoleMessageAdded):
+        (WebInspector.DefaultDashboard.prototype._incrementConsoleMessageType):
+        Update now that the event gives us a model object.
+
+        * UserInterface/Views/ConsoleMessageView.js: Added.
+        (WebInspector.ConsoleMessageView):
+        (WebInspector.ConsoleMessageView.prototype.get element):
+        (WebInspector.ConsoleMessageView.prototype.get message):
+        (WebInspector.ConsoleMessageView.prototype.get repeatCount):
+        (WebInspector.ConsoleMessageView.prototype.set repeatCount):
+        (WebInspector.ConsoleMessageView.prototype.toClipboardString):
+        (WebInspector.ConsoleMessageView.prototype._appendMessageTextAndArguments):
+        (WebInspector.ConsoleMessageView.prototype._appendSavedResultIndex):
+        (WebInspector.ConsoleMessageView.prototype._appendLocationLink):
+        (WebInspector.ConsoleMessageView.prototype._appendParameters):
+        (WebInspector.ConsoleMessageView.prototype._appendStackTrace):
+        (WebInspector.ConsoleMessageView.prototype._appendFormattedArguments):
+        (WebInspector.ConsoleMessageView.prototype._formatParameter):
+        (WebInspector.ConsoleMessageView.prototype._formatParameterAsValue):
+        (WebInspector.ConsoleMessageView.prototype._formatParameterAsString):
+        (WebInspector.ConsoleMessageView.prototype._formatParameterAsNode):
+        (WebInspector.ConsoleMessageView.prototype._formatParameterAsObject):
+        (WebInspector.ConsoleMessageView.prototype._formatParameterAsArray):
+        (WebInspector.ConsoleMessageView.prototype._rootPropertyPathForObject):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.parameterFormatter):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.stringFormatter):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.floatFormatter):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.integerFormatter):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.styleFormatter):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.isWhitelistedProperty):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString.append):
+        (WebInspector.ConsoleMessageView.prototype._formatWithSubstitutionString):
+        (WebInspector.ConsoleMessageView.prototype._shouldShowStackTrace):
+        (WebInspector.ConsoleMessageView.prototype._shouldHideURL):
+        (WebInspector.ConsoleMessageView.prototype._firstNonNativeCallFrame):
+        (WebInspector.ConsoleMessageView.prototype._linkifyLocation):
+        (WebInspector.ConsoleMessageView.prototype._linkifyCallFrame):
+        (WebInspector.ConsoleMessageView.prototype._userProvidedColumnNames):
+        (WebInspector.ConsoleMessageView.prototype._formatParameterAsTable):
+        (WebInspector.ConsoleMessageView.prototype._levelString):
+        (WebInspector.ConsoleMessageView.prototype._enforcesClipboardPrefixString):
+        (WebInspector.ConsoleMessageView.prototype._clipboardPrefixString):
+        New View class for a ConsoleMessage. This is a near direct port of the old code
+        to a view class that has a root element.
+
+        * UserInterface/Models/ConsoleCommandResultMessage.js: Renamed from Source/WebInspectorUI/UserInterface/Views/ConsoleCommandResult.js.
+        (WebInspector.ConsoleCommandResultMessage):
+        (WebInspector.ConsoleCommandResultMessage.clearMaximumSavedResultIndex):
+        (WebInspector.ConsoleCommandResultMessage.prototype.get savedResultIndex):
+        Rename, as this is a ConsoleMessage subclass with a specific type for console evaluation results.
+
+        * UserInterface/Views/ConsoleCommandView.js: Renamed from Source/WebInspectorUI/UserInterface/Views/ConsoleCommand.js.
+        (WebInspector.ConsoleCommandView):
+        (WebInspector.ConsoleCommandView.prototype.get element):
+        (WebInspector.ConsoleCommandView.prototype.get commandText):
+        (WebInspector.ConsoleCommandView.prototype.get message):
+        (WebInspector.ConsoleCommandView.prototype.toClipboardString):
+        * UserInterface/Views/ConsoleGroup.js:
+        (WebInspector.ConsoleGroup):
+        (WebInspector.ConsoleGroup.prototype.get parentGroup):
+        (WebInspector.ConsoleGroup.prototype.render):
+        (WebInspector.ConsoleGroup.prototype.addMessageView):
+        (WebInspector.ConsoleGroup.prototype.append):
+        (WebInspector.ConsoleGroup.prototype._titleMouseDown):
+        (WebInspector.ConsoleGroup.prototype.addMessage): Deleted.
+        (WebInspector.ConsoleGroup.prototype._titleClicked): Deleted.
+        * UserInterface/Views/ConsoleSession.js:
+        (WebInspector.ConsoleSession):
+        (WebInspector.ConsoleSession.prototype.addMessageView):
+        (WebInspector.ConsoleSession.prototype.append):
+        (WebInspector.ConsoleSession.prototype.addMessage): Deleted.
+        (WebInspector.ConsoleSession.prototype.hasMessages): Deleted.
+        Convert to classes, and clarify these deal with View objects.
+
+        * UserInterface/Views/LogContentView.css:
+        (.console-message .repeat-count):
+        (.console-message .bubble): Deleted.
+        Better class name for the repeat count element.
+
+        * UserInterface/Views/LogContentView.js:
+        (WebInspector.LogContentView.prototype.didAppendConsoleMessageView):
+        (WebInspector.LogContentView.prototype._formatMessagesAsData):
+        (WebInspector.LogContentView.prototype._messageAdded):
+        (WebInspector.LogContentView.prototype._updateMessagesSelection):
+        (WebInspector.LogContentView.prototype._selectAllMessages):
+        (WebInspector.LogContentView.prototype._allMessageElements):
+        (WebInspector.LogContentView.prototype._unfilteredMessageElements):
+        (WebInspector.LogContentView.prototype._visibleMessageElements):
+        (WebInspector.LogContentView.prototype._scopeBarSelectionDidChange):
+        (WebInspector.LogContentView.prototype._filterMessageElements):
+        (WebInspector.LogContentView.prototype._upArrowWasPressed):
+        (WebInspector.LogContentView.prototype._downArrowWasPressed):
+        (WebInspector.LogContentView.prototype._previousMessage):
+        (WebInspector.LogContentView.prototype._nextMessage):
+        (WebInspector.LogContentView.prototype._performSearch):
+        (WebInspector.LogContentView.prototype._highlightRanges):
+        (WebInspector.LogContentView.prototype._reappendProvisionalMessages):
+        (WebInspector.LogContentView.prototype.didAppendConsoleMessage): Deleted.
+        (WebInspector.LogContentView.prototype._allMessages): Deleted.
+        (WebInspector.LogContentView.prototype._unfilteredMessages): Deleted.
+        (WebInspector.LogContentView.prototype._visibleMessages): Deleted.
+        (WebInspector.LogContentView.prototype._filterMessages): Deleted.
+        Rename lots of things to make it clear when we are dealing with
+        elements, model objects, or view objects. This class is still heavily
+        dealing with elements, and needs to be cleaned up later.
+
 2015-04-08  Joseph Pecoraro  <pecoraro@apple.com>
 
         Fix uncaught exception seen in Inspector.
index 273207ef9e84b1576b75f0a1241d14f851555c4d..4f5cda6847f4e84192fe95f3e1ea3c3072642d93 100644 (file)
@@ -37,6 +37,7 @@ WebInspector.loaded = function()
     // The initialization order should match the same in Main.js.
     InspectorBackend.registerInspectorDispatcher(new WebInspector.InspectorObserver);
     InspectorBackend.registerPageDispatcher(new WebInspector.PageObserver);
+    InspectorBackend.registerConsoleDispatcher(new WebInspector.ConsoleObserver);
     InspectorBackend.registerDOMDispatcher(new WebInspector.DOMObserver);
     InspectorBackend.registerNetworkDispatcher(new WebInspector.NetworkObserver);
     InspectorBackend.registerDebuggerDispatcher(new WebInspector.DebuggerObserver);
@@ -50,6 +51,8 @@ WebInspector.loaded = function()
     this.frameResourceManager = new WebInspector.FrameResourceManager;
     this.domTreeManager = new WebInspector.DOMTreeManager;
     this.cssStyleManager = new WebInspector.CSSStyleManager;
+    this.logManager = new WebInspector.LogManager;
+    this.issueManager = new WebInspector.IssueManager;
     this.runtimeManager = new WebInspector.RuntimeManager;
     this.timelineManager = new WebInspector.TimelineManager;
     this.debuggerManager = new WebInspector.DebuggerManager;
@@ -63,6 +66,7 @@ WebInspector.loaded = function()
 
     // Enable agents.
     InspectorAgent.enable();
+    ConsoleAgent.enable();
 
     // Perform one-time tasks.
     WebInspector.CSSCompletions.requestCSSNameCompletions();
index e5b406eb41122eb65c1a23896046eab26e8f58cc..15cbd7d6612c35897eb95767a7c8444a72f04616 100644 (file)
@@ -44,7 +44,7 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
         this.delegate = delegate;
 
         this._cleared = true;
-        this._previousMessage = null;
+        this._previousMessageView = null;
         this._repeatCountWasInterrupted = false;
 
         this._sessions = [];
@@ -106,9 +106,9 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
             return;
         }
 
-        var consoleSession = new WebInspector.ConsoleSession();
+        var consoleSession = new WebInspector.ConsoleSession;
 
-        this._previousMessage = null;
+        this._previousMessageView = null;
         this._repeatCountWasInterrupted = false;
 
         this._sessions.push(consoleSession);
@@ -124,13 +124,14 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
     {
         console.assert(result instanceof WebInspector.RemoteObject);
 
-        var commandMessage = new WebInspector.ConsoleCommand(text);
-        this._appendConsoleMessage(commandMessage, true);
+        var commandMessageView = new WebInspector.ConsoleCommandView(text);
+        this._appendConsoleMessageView(commandMessageView, true);
 
         function saveResultCallback(savedResultIndex)
         {
-            var commandResultMessage = new WebInspector.ConsoleCommandResult(result, false, commandMessage, savedResultIndex);
-            this._appendConsoleMessage(commandResultMessage, true);
+            var commandResultMessage = new WebInspector.ConsoleCommandResultMessage(result, false, savedResultIndex);
+            var commandResultMessageView = new WebInspector.ConsoleMessageView(commandResultMessage);
+            this._appendConsoleMessageView(commandResultMessageView, true);
         }
 
         WebInspector.runtimeManager.saveResult(result, saveResultCallback.bind(this));
@@ -138,36 +139,30 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
 
     appendConsoleMessage(consoleMessage)
     {
-        // Clone the message since there might be multiple clients using the message,
-        // and since the message has a DOM element it can't be two places at once.
-        var messageClone = consoleMessage.clone();
-
-        this._appendConsoleMessage(messageClone);
-
-        return messageClone;
+        var consoleMessageView = new WebInspector.ConsoleMessageView(consoleMessage);
+        this._appendConsoleMessageView(consoleMessageView);
+        return consoleMessageView;
     }
 
     updatePreviousMessageRepeatCount(count)
     {
-        console.assert(this._previousMessage);
-        if (!this._previousMessage)
+        console.assert(this._previousMessageView);
+        if (!this._previousMessageView)
             return;
 
-        if (!this._repeatCountWasInterrupted) {
-            this._previousMessage.repeatCount = count - (this._previousMessage.ignoredCount || 0);
-            this._previousMessage.updateRepeatCount();
-        } else {
-            var newMessage = this._previousMessage.clone();
-
-            // If this message is repeated after being cloned, messageRepeatCountUpdated will be called with a
-            // count that includes the count of this message before cloning. We should ignore instances of this
-            // log that occurred before we cloned, so set a property on the message with the number of previous
-            // instances of this log that we should ignore.
-            newMessage.ignoredCount = newMessage.repeatCount + (this._previousMessage.ignoredCount || 0);
-            newMessage.repeatCount = 1;
+        var previousIgnoredCount = this._previousMessageView[WebInspector.JavaScriptLogViewController.IgnoredRepeatCount] || 0;
+        var previousVisibleCount = this._previousMessageView.repeatCount;
 
-            this._appendConsoleMessage(newMessage);
+        if (!this._repeatCountWasInterrupted) {
+            this._previousMessageView.repeatCount = count - previousIgnoredCount;
+            return;
         }
+
+        var consoleMessage = this._previousMessageView.message;
+        var duplicatedConsoleMessageView = new WebInspector.ConsoleMessageView(consoleMessage);
+        duplicatedConsoleMessageView[WebInspector.JavaScriptLogViewController.IgnoredRepeatCount] = previousIgnoredCount + previousVisibleCount;
+        duplicatedConsoleMessageView.repeatCount = 1;
+        this._appendConsoleMessageView(duplicatedConsoleMessageView);
     }
 
     isScrolledToBottom()
@@ -225,15 +220,17 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
     {
         console.assert(text);
 
-        var commandMessage = new WebInspector.ConsoleCommand(text);
-        this._appendConsoleMessage(commandMessage, true);
+        var commandMessageView = new WebInspector.ConsoleCommandView(text);
+        this._appendConsoleMessageView(commandMessageView, true);
 
         function printResult(result, wasThrown, savedResultIndex)
         {
             if (!result || this._cleared)
                 return;
 
-            this._appendConsoleMessage(new WebInspector.ConsoleCommandResult(result, wasThrown, commandMessage, savedResultIndex), true);
+            var commandResultMessage = new WebInspector.ConsoleCommandResultMessage(result, wasThrown, savedResultIndex);
+            var commandResultMessageView = new WebInspector.ConsoleMessageView(commandResultMessage);
+            this._appendConsoleMessageView(commandResultMessageView, true);
         }
 
         text += "\n//# sourceURL=__WebInspectorConsole__\n";
@@ -263,7 +260,7 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
         this.delegate.highlightPreviousSearchMatch();
     }
 
-    _appendConsoleMessage(msg, repeatCountWasInterrupted)
+    _appendConsoleMessageView(messageView, repeatCountWasInterrupted)
     {
         var wasScrolledToBottom = this.isScrolledToBottom();
 
@@ -271,28 +268,30 @@ WebInspector.JavaScriptLogViewController = class JavaScriptLogViewController ext
         this._repeatCountWasInterrupted = repeatCountWasInterrupted || false;
 
         if (!repeatCountWasInterrupted)
-            this._previousMessage = msg;
+            this._previousMessageView = messageView;
 
-        if (msg.type === WebInspector.LegacyConsoleMessage.MessageType.EndGroup) {
+        var type = messageView instanceof WebInspector.ConsoleCommandView ? null : messageView.message.type;
+        if (type === WebInspector.ConsoleMessage.MessageType.EndGroup) {
             var parentGroup = this._currentConsoleGroup.parentGroup;
             if (parentGroup)
                 this._currentConsoleGroup = parentGroup;
         } else {
-            if (msg.type === WebInspector.LegacyConsoleMessage.MessageType.StartGroup || msg.type === WebInspector.LegacyConsoleMessage.MessageType.StartGroupCollapsed) {
+            if (type === WebInspector.ConsoleMessage.MessageType.StartGroup || type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed) {
                 var group = new WebInspector.ConsoleGroup(this._currentConsoleGroup);
-                var groupElement = group.render(msg);
+                var groupElement = group.render(messageView);
                 this._currentConsoleGroup.append(groupElement);
                 this._currentConsoleGroup = group;
             } else
-                this._currentConsoleGroup.addMessage(msg);
+                this._currentConsoleGroup.addMessageView(messageView);
         }
 
-        if (msg.type === WebInspector.LegacyConsoleMessage.MessageType.Result || wasScrolledToBottom)
+        if (type === WebInspector.ConsoleMessage.MessageType.Result || wasScrolledToBottom)
             this.scrollToBottom();
 
-        if (this.delegate && typeof this.delegate.didAppendConsoleMessage === "function")
-            this.delegate.didAppendConsoleMessage(msg);
+        if (this.delegate && typeof this.delegate.didAppendConsoleMessageView === "function")
+            this.delegate.didAppendConsoleMessageView(messageView);
     }
 };
 
 WebInspector.JavaScriptLogViewController.CachedPropertiesDuration = 30000;
+WebInspector.JavaScriptLogViewController.IgnoredRepeatCount = Symbol("ignored-repeat-count");
index b0982faaf96d6239621cd57e58c9c801a7bd98c2..4c782699f6338a6f54c94619d009dd896f8420d8 100644 (file)
@@ -180,7 +180,7 @@ WebInspector.JavaScriptRuntimeCompletionProvider = class JavaScriptRuntimeComple
                     propertyNames[commandLineAPI[i]] = true;
 
                 // FIXME: Due to caching, sometimes old $n values show up as completion results even though they are not available. We should clear that proactively.
-                for (var i = 1; i <= WebInspector.ConsoleCommandResult.maximumSavedResultIndex; ++i)
+                for (var i = 1; i <= WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex; ++i)
                     propertyNames["$" + i] = true;
             }
 
index a6aab9e83f13d09b1176cce7162489ba14fee6da..1173924d26753fc4ce9ea09cad2cf91d3a56e992 100644 (file)
@@ -38,19 +38,21 @@ WebInspector.LogManager = class LogManager extends WebInspector.Object
     {
         // Called from WebInspector.ConsoleObserver.
 
-        // FIXME: Pass a request. We need a way to get it from the request ID.
-        var consoleMessage = WebInspector.LegacyConsoleMessage.create(source, level, text, type, url, line, column, repeatCount, parameters, stackTrace, null);
+        // FIXME: stackTrace should be converted to a model object.
+        // FIXME: Get a request from request ID.
 
-        this.dispatchEventToListeners(WebInspector.LogManager.Event.MessageAdded, {message: consoleMessage});
+        if (parameters)
+            parameters = parameters.map(function(x) { return WebInspector.RemoteObject.fromPayload(x); });
 
-        console.assert(!consoleMessage._element || !consoleMessage._element.parentNode, "This console message shouldn't be added to a view. To add it you need to use clone().");
+        var message = new WebInspector.ConsoleMessage(source, level, text, type, url, line, column, repeatCount, parameters, stackTrace, null);
+        this.dispatchEventToListeners(WebInspector.LogManager.Event.MessageAdded, {message});
     }
 
     messagesCleared()
     {
         // Called from WebInspector.ConsoleObserver.
 
-        WebInspector.ConsoleCommandResult.clearMaximumSavedResultIndex();
+        WebInspector.ConsoleCommandResultMessage.clearMaximumSavedResultIndex();
 
         // We don't want to clear messages on reloads. We can't determine that easily right now.
         // FIXME: <rdar://problem/13767079> Console.messagesCleared should include a reason
@@ -90,7 +92,7 @@ WebInspector.LogManager = class LogManager extends WebInspector.Object
         else
             this.dispatchEventToListeners(WebInspector.LogManager.Event.SessionStarted);
 
-        WebInspector.ConsoleCommandResult.clearMaximumSavedResultIndex();
+        WebInspector.ConsoleCommandResultMessage.clearMaximumSavedResultIndex();
 
         delete this._shouldClearMessages;
     }
index 028467f1566aa1747ecc96093ccac8dbda09e5c4..2b15aa0cf0111e26082d8511203b82870e894ed2 100644 (file)
     <script src="Protocol/TimelineObserver.js"></script>
 
     <script src="Models/BreakpointAction.js"></script>
+    <script src="Models/ConsoleMessage.js"></script>
     <script src="Models/SourceCode.js"></script>
     <script src="Models/SourceCodeLocation.js"></script>
     <script src="Models/Timeline.js"></script>
     <script src="Models/CollectionEntry.js"></script>
     <script src="Models/CollectionEntryPreview.js"></script>
     <script src="Models/Color.js"></script>
+    <script src="Models/ConsoleCommandResultMessage.js"></script>
     <script src="Models/ContentFlow.js"></script>
     <script src="Models/CookieStorageObject.js"></script>
     <script src="Models/DOMNode.js"></script>
     <script src="Models/TypeSet.js"></script>
     <script src="Models/UnitBezier.js"></script>
 
-    <script src="Views/LegacyConsoleMessage.js"></script>
+    <script src="Views/ConsoleCommandView.js"></script>
+    <script src="Views/ConsoleMessageView.js"></script>
     <script src="Views/ContentView.js"></script>
     <script src="Views/DataGrid.js"></script>
     <script src="Views/DetailsSectionRow.js"></script>
     <script src="Views/TreeOutline.js"></script>
 
     <script src="Views/ButtonNavigationItem.js"></script>
-    <script src="Views/LegacyConsoleMessageImpl.js"></script>
     <script src="Views/DOMTreeContentView.js"></script>
     <script src="Views/DetailsSidebarPanel.js"></script>
     <script src="Views/GeneralTreeElement.js"></script>
     <script src="Views/ColorWheel.js"></script>
     <script src="Views/CompletionSuggestionsView.js"></script>
     <script src="Views/ComputedStyleDetailsPanel.js"></script>
-    <script src="Views/ConsoleCommand.js"></script>
-    <script src="Views/ConsoleCommandResult.js"></script>
     <script src="Views/ConsoleGroup.js"></script>
     <script src="Views/ConsolePrompt.js"></script>
     <script src="Views/ConsoleSession.js"></script>
similarity index 50%
rename from Source/WebInspectorUI/UserInterface/Views/ConsoleCommandResult.js
rename to Source/WebInspectorUI/UserInterface/Models/ConsoleCommandResultMessage.js
index e7c0f596474d1fdfce7643623810034b273e1229..99784efa7a012ea5a3a9d89b8829a7abd8aa5de2 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ConsoleCommandResult = function(result, wasThrown, originatingCommand, savedResultIndex)
+WebInspector.ConsoleCommandResultMessage = class ConsoleCommandResult extends WebInspector.ConsoleMessage
 {
-    var level = (wasThrown ? WebInspector.LegacyConsoleMessage.MessageLevel.Error : WebInspector.LegacyConsoleMessage.MessageLevel.Log);
-    this.originatingCommand = originatingCommand;
-    this.savedResultIndex = savedResultIndex;
+    constructor(result, wasThrown, savedResultIndex)
+    {
+        var source = WebInspector.ConsoleMessage.MessageSource.JS;
+        var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
+        var type = WebInspector.ConsoleMessage.MessageType.Result;
 
-    if (this.savedResultIndex && this.savedResultIndex > WebInspector.ConsoleCommandResult.maximumSavedResultIndex)
-        WebInspector.ConsoleCommandResult.maximumSavedResultIndex = this.savedResultIndex;
+        super(source, level, "", type, undefined, undefined, undefined, 0, [result], undefined, undefined);
 
-    WebInspector.LegacyConsoleMessageImpl.call(this, WebInspector.LegacyConsoleMessage.MessageSource.JS, level, "", null, WebInspector.LegacyConsoleMessage.MessageType.Result, undefined, undefined, undefined, undefined, [result]);
-};
+        this._savedResultIndex = savedResultIndex;
 
-WebInspector.ConsoleCommandResult.maximumSavedResultIndex = 0;
+        if (this._savedResultIndex && this._savedResultIndex > WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex)
+            WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex = this._savedResultIndex;
+    }
 
-WebInspector.ConsoleCommandResult.clearMaximumSavedResultIndex = function()
-{
-    WebInspector.ConsoleCommandResult.maximumSavedResultIndex = 0;
-}
+    // Static
 
-WebInspector.ConsoleCommandResult.prototype = {
-    constructor: WebInspector.ConsoleCommandResult,
+    static clearMaximumSavedResultIndex()
+    {
+        WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex = 0;
+    }
 
     // Public
 
-    enforcesClipboardPrefixString: false,
-
-    toMessageElement: function()
-    {
-        var element = WebInspector.LegacyConsoleMessageImpl.prototype.toMessageElement.call(this);
-        element.classList.add("console-user-command-result");
-        if (!element.getAttribute("data-labelprefix"))
-            element.setAttribute("data-labelprefix", WebInspector.UIString("Output: "));
-        return element;
-    },
-
-    get clipboardPrefixString()
+    get savedResultIndex()
     {
-        return "< ";
+        return this._savedResultIndex;
     }
 };
 
-WebInspector.ConsoleCommandResult.prototype.__proto__ = WebInspector.LegacyConsoleMessageImpl.prototype;
+WebInspector.ConsoleCommandResultMessage.maximumSavedResultIndex = 0;
diff --git a/Source/WebInspectorUI/UserInterface/Models/ConsoleMessage.js b/Source/WebInspectorUI/UserInterface/Models/ConsoleMessage.js
new file mode 100644 (file)
index 0000000..aaaf14a
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.ConsoleMessage = class ConsoleMessage extends WebInspector.Object
+{
+    constructor(source, level, message, type, url, line, column, repeatCount, parameters, stackTrace, request)
+    {
+        super();
+
+        console.assert(typeof source === "string");
+        console.assert(typeof level === "string");
+        console.assert(typeof message === "string");
+        console.assert(!parameters || parameters.every(function(x) { return x instanceof WebInspector.RemoteObject; }));
+
+        this._source = source;
+        this._level = level;
+        this._messageText = message;
+        this._type = type || WebInspector.ConsoleMessage.MessageType.Log;
+        this._url = url || null;
+        this._line = line || 0;
+        this._column = column || 0;
+
+        this._repeatCount = repeatCount || 0;
+        this._parameters = parameters;
+        this._stackTrace = stackTrace;
+        this._request = request;
+    }
+
+    // Public
+
+    get source()
+    {
+        return this._source;
+    }
+
+    get level()
+    {
+        return this._level;
+    }
+
+    get messageText()
+    {
+        return this._messageText;
+    }
+
+    get type()
+    {
+        return this._type;
+    }
+
+    get url()
+    {
+        return this._url;
+    }
+
+    get line()
+    {
+        return this._line;
+    }
+
+    get column()
+    {
+        return this._column;
+    }
+
+    get repeatCount()
+    {
+        return this._repeatCount;
+    }
+
+    get parameters()
+    {
+        return this._parameters;
+    }
+
+    get stackTrace()
+    {
+        return this._stackTrace;
+    }
+
+    get request()
+    {
+        return this._request;
+    }
+};
+
+WebInspector.ConsoleMessage.MessageSource = {
+    HTML: "html",
+    XML: "xml",
+    JS: "javascript",
+    Network: "network",
+    ConsoleAPI: "console-api",
+    Storage: "storage",
+    Appcache: "appcache",
+    Rendering: "rendering",
+    CSS: "css",
+    Security: "security",
+    Other: "other",
+};
+
+WebInspector.ConsoleMessage.MessageType = {
+    Log: "log",
+    Dir: "dir",
+    DirXML: "dirxml",
+    Table: "table",
+    Trace: "trace",
+    StartGroup: "startGroup",
+    StartGroupCollapsed: "startGroupCollapsed",
+    EndGroup: "endGroup",
+    Assert: "assert",
+    Timing: "timing",
+    Profile: "profile",
+    ProfileEnd: "profileEnd",
+    Result: "result", // Frontend Only.
+};
+
+WebInspector.ConsoleMessage.MessageLevel = {
+    Tip: "tip", // COMPATIBILITY (iOS 6)
+    Log: "log",
+    Warning: "warning",
+    Error: "error",
+    Debug: "debug",
+};
index ceee6e65a68c17f2cf7889defc23160aa35c7e8d..1ecbbe4cc56e4e180d987a48287732124d4b2642 100644 (file)
@@ -233,7 +233,7 @@ WebInspector.DefaultDashboard = class DefaultDashboard extends WebInspector.Obje
     {
         var message = event.data.message;
         this._lastConsoleMessageType = message.level;
-        this._incrementConsoleMessageType(message.level, message.totalRepeatCount);
+        this._incrementConsoleMessageType(message.level, message.repeatCount);
     }
 
     _consoleMessageWasRepeated(event)
@@ -244,13 +244,13 @@ WebInspector.DefaultDashboard = class DefaultDashboard extends WebInspector.Obje
     _incrementConsoleMessageType(type, increment)
     {
         switch (type) {
-        case WebInspector.LegacyConsoleMessage.MessageLevel.Log:
+        case WebInspector.ConsoleMessage.MessageLevel.Log:
             this.logs += increment;
             break;
-        case WebInspector.LegacyConsoleMessage.MessageLevel.Warning:
+        case WebInspector.ConsoleMessage.MessageLevel.Warning:
             this.issues += increment;
             break;
-        case WebInspector.LegacyConsoleMessage.MessageLevel.Error:
+        case WebInspector.ConsoleMessage.MessageLevel.Error:
             this.errors += increment;
             break;
         }
index cfc2fc0545a4a51b53c197aa26a9ca0f558017dd..b61f721f0d12cf49c59f43dc082fa7968e6a4aab 100644 (file)
@@ -29,6 +29,8 @@ WebInspector.ConsoleObserver = class ConsoleObserver
 
     messageAdded(message)
     {
+        // FIXME: We should convert "Tip" to "Log" here immediately.
+
         if (message.type === "assert" && !message.text)
             message.text = WebInspector.UIString("Assertion");
 
index 822639918e5e02f9b9a90392a1171f02f78da77f..833ba76ae84328dac8a3a159c2154decb93a19ca 100644 (file)
@@ -50,6 +50,7 @@
 
     <script src="Protocol/InspectorObserver.js"></script>
     <script src="Protocol/CSSObserver.js"></script>
+    <script src="Protocol/ConsoleObserver.js"></script>
     <script src="Protocol/DOMObserver.js"></script>
     <script src="Protocol/DOMStorageObserver.js"></script>
     <script src="Protocol/DebuggerObserver.js"></script>
@@ -61,6 +62,7 @@
     <script src="Protocol/TimelineObserver.js"></script>
 
     <script src="Models/BreakpointAction.js"></script>
+    <script src="Models/ConsoleMessage.js"></script>
     <script src="Models/SourceCode.js"></script>
     <script src="Models/SourceCodeLocation.js"></script>
     <script src="Models/Timeline.js"></script>
@@ -90,6 +92,7 @@
     <script src="Models/IndexedDatabase.js"></script>
     <script src="Models/IndexedDatabaseObjectStore.js"></script>
     <script src="Models/IndexedDatabaseObjectStoreIndex.js"></script>
+    <script src="Models/IssueMessage.js"></script>
     <script src="Models/LayoutTimelineRecord.js"></script>
     <script src="Models/LazySourceCodeLocation.js"></script>
     <script src="Models/NetworkTimeline.js"></script>
     <script src="Controllers/DOMTreeManager.js"></script>
     <script src="Controllers/DebuggerManager.js"></script>
     <script src="Controllers/FrameResourceManager.js"></script>
+    <script src="Controllers/IssueManager.js"></script>
+    <script src="Controllers/LogManager.js"></script>
     <script src="Controllers/ProbeManager.js"></script>
     <script src="Controllers/ReplayManager.js"></script>
     <script src="Controllers/RuntimeManager.js"></script>
similarity index 60%
rename from Source/WebInspectorUI/UserInterface/Views/ConsoleCommand.js
rename to Source/WebInspectorUI/UserInterface/Views/ConsoleCommandView.js
index a9c53f8531d826a1fa30cdbdcf0014cf12f18e22..18d8009771c14aec54321e7c0a39a7c5df7dd834 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ConsoleCommand = function(command)
+WebInspector.ConsoleCommandView = class ConsoleCommandView extends WebInspector.Object
 {
-    // FIXME: Convert this to a WebInspector.Object subclass, and call super().
-    // WebInspector.Object.call(this);
-
-    this.command = command;
-};
-
-WebInspector.ConsoleCommand.prototype = {
-    constructor: WebInspector.ConsoleCommand,
-
-    // Public
+    constructor(commandText)
+    {
+        super();
 
-    decorateMessageElement: function(element) {
-        if (this._element)
-            return this._element;
+        this._commandText = commandText;
 
-        this._element = element;
-        this._element.command = this;
+        this._element = document.createElement("div");
         this._element.classList.add("console-user-command");
         this._element.setAttribute("data-labelprefix", WebInspector.UIString("Input: "));
 
-        this._formatCommand();
-        this._element.appendChild(this._formattedCommand);
-
-        return this._element;
-    },
+        this._formattedCommandElement = this._element.appendChild(document.createElement("span"));
+        this._formattedCommandElement.classList.add("console-message-text");
+        this._formattedCommandElement.textContent = this._commandText;
 
-    toMessageElement: function()
-    {
-        if (this._element)
-            return this._element;
+        // FIXME: <https://webkit.org/b/143545> Web Inspector: LogContentView should use higher level objects
+        this._element.__commandView = this;
+    }
 
-        var element = document.createElement("div");
-        return this.decorateMessageElement(element);
-    },
+    // Public
 
-    // Private
+    get element()
+    {
+        return this._element;
+    }
 
-    _formatCommand: function()
+    get commandText()
     {
-        this._formattedCommand = document.createElement("span");
-        this._formattedCommand.className = "console-message-text source-code";
-        this._formattedCommand.textContent = this.command;
-    },
+        return this._commandText;
+    }
 
-    toClipboardString: function(isPrefixOptional)
+    toClipboardString(isPrefixOptional)
     {
-        return (isPrefixOptional ? "" : "> ") + this.command;
+        return (isPrefixOptional ? "" : "> ") + this._commandText;
     }
 };
-
-WebInspector.ConsoleCommand.prototype.__proto__ = WebInspector.Object.prototype;
index 9056f5f47ab52ff2a040369e506b1b482ae79e2c..8e6210064a2aa115813fe14515c23bd85a6f4547 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ConsoleGroup = function(parentGroup)
+WebInspector.ConsoleGroup = class ConsoleGroup extends WebInspector.Object
 {
-    // FIXME: Convert this to a WebInspector.Object subclass, and call super().
-    // WebInspector.Object.call(this);
-
-    this.parentGroup = parentGroup;
-};
+    constructor(parentGroup)
+    {
+        super();
 
-WebInspector.ConsoleGroup.prototype = {
-    constructor: WebInspector.ConsoleGroup,
+        this._parentGroup = parentGroup;
+    }
 
     // Public
 
-    render: function(message)
+    get parentGroup()
+    {
+        return this._parentGroup;
+    }
+
+    render(messageView)
     {
         var groupElement = document.createElement("div");
         groupElement.className = "console-group";
         groupElement.group = this;
         this.element = groupElement;
 
-        var titleElement = message.toMessageElement();
+        var titleElement = messageView.element;
         titleElement.classList.add(WebInspector.LogContentView.ItemWrapperStyleClassName);
         titleElement.addEventListener("click", this._titleClicked.bind(this));
         titleElement.addEventListener("mousedown", this._titleMouseDown.bind(this));
-        if (groupElement && message.type === WebInspector.LegacyConsoleMessage.MessageType.StartGroupCollapsed)
+
+        if (groupElement && messageView.message.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed)
             groupElement.classList.add("collapsed");
 
         groupElement.appendChild(titleElement);
@@ -62,28 +66,28 @@ WebInspector.ConsoleGroup.prototype = {
         groupElement.appendChild(messagesElement);
 
         return groupElement;
-    },
+    }
 
-    addMessage: function(message)
+    addMessageView(messageView)
     {
-        var element = message.toMessageElement();
+        var element = messageView.element;
         element.classList.add(WebInspector.LogContentView.ItemWrapperStyleClassName);
         this.append(element);
-    },
+    }
 
-    append: function(messageElement)
+    append(messageOrGroupElement)
     {
-        this._messagesElement.appendChild(messageElement);
-    },
+        this._messagesElement.appendChild(messageOrGroupElement);
+    }
 
     // Private
 
-    _titleMouseDown: function(event)
+    _titleMouseDown(event)
     {
         event.preventDefault();
-    },
+    }
 
-    _titleClicked: function(event)
+    _titleClicked(event)
     {
         var groupTitleElement = event.target.enclosingNodeOrSelfWithClass("console-group-title");
         if (groupTitleElement) {
@@ -97,5 +101,3 @@ WebInspector.ConsoleGroup.prototype = {
         }
     }
 };
-
-WebInspector.ConsoleGroup.prototype.__proto__ = WebInspector.Object.prototype;
diff --git a/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js b/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js
new file mode 100644 (file)
index 0000000..906a803
--- /dev/null
@@ -0,0 +1,675 @@
+/*
+ * Copyright (C) 2011 Google Inc.  All rights reserved.
+ * Copyright (C) 2007, 2008, 2013-2015 Apple Inc.  All rights reserved.
+ * Copyright (C) 2009 Joseph Pecoraro
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.ConsoleMessageView = class ConsoleMessageView extends WebInspector.Object
+{
+    constructor(message)
+    {
+        super();
+
+        console.assert(message instanceof WebInspector.ConsoleMessage);
+
+        this._message = message;
+
+        this._element = document.createElement("div");
+        this._element.classList.add("console-message");
+
+        // FIXME: <https://webkit.org/b/143545> Web Inspector: LogContentView should use higher level objects
+        this._element.__message = this._message;
+        this._element.__messageView = this;
+
+        switch (this._message.level) {
+        case WebInspector.ConsoleMessage.MessageLevel.Tip: // COMPATIBILITY (iOS 6).
+        case WebInspector.ConsoleMessage.MessageLevel.Log:
+            this._element.classList.add("console-log-level");
+            this._element.setAttribute("data-labelprefix", WebInspector.UIString("Log: "));
+            break;
+        case WebInspector.ConsoleMessage.MessageLevel.Debug:
+            this._element.classList.add("console-debug-level");
+            this._element.setAttribute("data-labelprefix", WebInspector.UIString("Debug: "));
+            break;
+        case WebInspector.ConsoleMessage.MessageLevel.Warning:
+            this._element.classList.add("console-warning-level");
+            this._element.setAttribute("data-labelprefix", WebInspector.UIString("Warning: "));
+            break;
+        case WebInspector.ConsoleMessage.MessageLevel.Error:
+            this._element.classList.add("console-error-level");
+            this._element.setAttribute("data-labelprefix", WebInspector.UIString("Error: "));
+            break;
+        }
+
+        if (this._message.type === WebInspector.ConsoleMessage.MessageType.Result) {
+            this._element.classList.add("console-user-command-result");
+            if (!this._element.getAttribute("data-labelprefix"))
+                this._element.setAttribute("data-labelprefix", WebInspector.UIString("Output: "));
+        }
+
+        if (this._message.type === WebInspector.ConsoleMessage.MessageType.StartGroup || this._message.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed)
+            this._element.classList.add("console-group-title");
+
+        this._appendLocationLink();
+
+        this._messageTextElement = this._element.appendChild(document.createElement("span"));
+        this._messageTextElement.classList.add("console-message-text");
+        this._appendMessageTextAndArguments(this._messageTextElement);
+        this._appendSavedResultIndex();
+
+        this._appendParameters();
+        this._appendStackTrace();
+
+        this.repeatCount = this._message.repeatCount;
+    }
+
+    // Public
+
+    get element()
+    {
+        return this._element;
+    }
+
+    get message()
+    {
+        return this._message;
+    }
+    
+    get repeatCount()
+    {
+        return this._repeatCount;
+    }
+
+    set repeatCount(count)
+    {
+        console.assert(typeof count === "number");
+
+        if (this._repeatCount === count)
+            return;
+
+        this._repeatCount = count;
+
+        if (count <= 1) {
+            if (this._repeatCountElement) {
+                this._repeatCountElement.remove();
+                this._repeatCountElement = null;
+            }
+            return;
+        }
+
+        if (!this._repeatCountElement) {
+            this._repeatCountElement = document.createElement("span");
+            this._repeatCountElement.classList.add("repeat-count");
+            this._element.insertBefore(this._repeatCountElement, this._element.firstChild);
+        }
+
+        this._repeatCountElement.textContent = count;
+    }
+
+    toClipboardString(isPrefixOptional)
+    {
+        var clipboardString = this._messageTextElement.innerText;
+
+        if (this._message.type === WebInspector.ConsoleMessage.MessageType.Trace)
+            clipboardString = "console.trace()";
+
+        var hasStackTrace = this._shouldShowStackTrace();
+        if (hasStackTrace) {
+            this._message.stackTrace.forEach(function(frame) {
+                clipboardString += "\n\t" + (frame.functionName || WebInspector.UIString("(anonymous function)"));
+                if (frame.url)
+                    clipboardString += " (" + WebInspector.displayNameForURL(frame.url) + ", line " + frame.lineNumber + ")";
+            });
+        } else {
+            var repeatString = this.repeatCount > 1 ? "x" + this.repeatCount : "";
+            var urlLine = "";
+            if (this._message.url) {
+                var components = [WebInspector.displayNameForURL(this._message.url), "line " + this._message.line];
+                if (repeatString)
+                    components.push(repeatString);
+                urlLine = " (" + components.join(", ") + ")";
+            } else if (repeatString)
+                urlLine = " (" + repeatString + ")";
+
+            if (urlLine) {
+                var lines = clipboardString.split("\n");
+                lines[0] += urlLine;
+                clipboardString = lines.join("\n");
+            }
+        }
+
+        if (!isPrefixOptional || this._enforcesClipboardPrefixString())
+            return this._clipboardPrefixString() + clipboardString;
+        return clipboardString;
+    }
+
+    // Private
+
+    _appendMessageTextAndArguments(element)
+    {
+        if (this._message.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI) {
+            switch (this._message.type) {
+            case WebInspector.ConsoleMessage.MessageType.Trace:
+                element.appendChild(document.createTextNode("console.trace()"));
+                break;
+
+            case WebInspector.ConsoleMessage.MessageType.Assert:
+                var args = [WebInspector.UIString("Assertion failed:")];
+                if (this._message.parameters)
+                    args.concat(this._message.parameters);
+                this._appendFormattedArguments(element, args);
+                break;
+
+            case WebInspector.ConsoleMessage.MessageType.Dir:
+                var obj = this._message.parameters ? this._message.parameters[0] : undefined;
+                this._appendFormattedArguments(element, ["%O", obj]);
+                break;
+
+            case WebInspector.ConsoleMessage.MessageType.Table:
+                // FIXME: Remove messageText?
+                var args = this._message.parameters || [this._message.messageText];
+                element.appendChild(this._formatParameterAsTable(args));
+                break;
+
+            default:
+                var args = this._message.parameters || [this._message.messageText];
+                this._appendFormattedArguments(element, args);
+                break;
+            }
+            return;
+        }
+
+        // FIXME: Better handle WebInspector.ConsoleMessage.MessageSource.Network.
+
+        var args = this._message.parameters || [this._message.messageText];
+        this._appendFormattedArguments(element, args);
+    }
+
+    _appendSavedResultIndex(element)
+    {
+        if (!this._message.savedResultIndex)
+            return;
+
+        console.assert(this._message instanceof WebInspector.ConsoleCommandResultMessage);
+        console.assert(this._message.type === WebInspector.ConsoleMessage.MessageType.Result);
+
+        var savedVariableElement = document.createElement("span");
+        savedVariableElement.classList.add("console-saved-variable");
+        savedVariableElement.textContent = " = $" + this._message.savedResultIndex;
+
+        if (this._objectTree)
+            this._objectTree.appendTitleSuffix(savedVariableElement);
+        else
+            this._messageTextElement.appendChild(savedVariableElement);
+    }    
+
+    _appendLocationLink()
+    {
+        // FIXME: Better handle WebInspector.ConsoleMessage.MessageSource.Network.
+        if (this._message.source === WebInspector.ConsoleMessage.MessageSource.Network || this._message.request)
+            return;
+
+        var firstNonNativeCallFrame = this._firstNonNativeCallFrame();
+        if (firstNonNativeCallFrame) {
+            var urlElement = this._linkifyCallFrame(firstNonNativeCallFrame);
+            this._element.appendChild(urlElement);
+        } else if (this._message.url && !this._shouldHideURL(this._message.url)) {
+            var urlElement = this._linkifyLocation(this._message.url, this._message.line, this._message.column);
+            this._element.appendChild(urlElement);
+        }
+    }
+
+    _appendParameters()
+    {
+        // FIXME: To be implemented for the new Console design.
+    }
+
+    _appendStackTrace()
+    {
+        // FIXME: To be re-written in the new Console design.
+
+        if (!this._shouldShowStackTrace())
+            return;
+
+        var ol = document.createElement("ol");
+        ol.className = "outline-disclosure";
+        var treeOutline = new WebInspector.TreeOutline(ol);
+        var root = new WebInspector.TreeElement(this._messageTextElement, null, true);
+        treeOutline.appendChild(root);
+
+        if (this._message.type === WebInspector.ConsoleMessage.MessageType.Trace)
+            root.expand();
+
+        for (var i = 0; i < this._message.stackTrace.length; i++) {
+            var frame = this._message.stackTrace[i];
+
+            var content = document.createElement("div");
+            var messageTextElement = document.createElement("span");
+            messageTextElement.className = "console-message-text";
+            var functionName = frame.functionName || WebInspector.UIString("(anonymous function)");
+            messageTextElement.appendChild(document.createTextNode(functionName));
+            content.appendChild(messageTextElement);
+
+            if (frame.url && !this._shouldHideURL(frame.url)) {
+                var urlElement = this._linkifyCallFrame(frame);
+                content.appendChild(urlElement);
+            }
+
+            var treeElement = new WebInspector.TreeElement(content);
+            root.appendChild(treeElement);
+        }
+
+        this._messageTextElement = ol;
+        this._element.appendChild(this._messageTextElement);
+    }
+
+    _appendFormattedArguments(element, parameters)
+    {
+        if (!parameters.length)
+            return;
+
+        // FIXME: Only pass RemoteObjects here so we can avoid this work.
+        for (var i = 0; i < parameters.length; ++i) {
+            if (parameters[i] instanceof WebInspector.RemoteObject)
+                continue;
+
+            if (typeof parameters[i] === "object")
+                parameters[i] = WebInspector.RemoteObject.fromPayload(parameters[i]);
+            else
+                parameters[i] = WebInspector.RemoteObject.fromPrimitiveValue(parameters[i]);
+        }
+
+        var builderElement = element.appendChild(document.createElement("span"));
+
+        // Format string.
+        var shouldFormatWithStringSubstitution = WebInspector.RemoteObject.type(parameters[0]) === "string" && this._message.type !== WebInspector.ConsoleMessage.MessageType.Result;
+        if (shouldFormatWithStringSubstitution) {
+            var result = this._formatWithSubstitutionString(parameters, builderElement);
+            parameters = result.unusedSubstitutions;
+            if (parameters.length)
+                builderElement.appendChild(document.createTextNode(" "));
+        }
+
+        // Individual objects.
+        for (var i = 0; i < parameters.length; ++i) {
+            builderElement.appendChild(this._formatParameter(parameters[i], false));
+            if (i < parameters.length - 1)
+                builderElement.appendChild(document.createTextNode(" "));
+        }
+    }
+
+    _formatParameter(parameter, forceObjectFormat)
+    {
+        var type;
+        if (forceObjectFormat)
+            type = "object";
+        else if (parameter instanceof WebInspector.RemoteObject)
+            type = parameter.subtype || parameter.type;
+        else {
+            console.assert(false, "no longer reachable");
+            type = typeof parameter;
+        }
+
+        var formatters = {
+            "object": this._formatParameterAsObject,
+            "error": this._formatParameterAsObject,
+            "map": this._formatParameterAsObject,
+            "set": this._formatParameterAsObject,
+            "weakmap": this._formatParameterAsObject,
+            "iterator": this._formatParameterAsObject,
+            "class": this._formatParameterAsObject,
+            "array": this._formatParameterAsArray,
+            "node": this._formatParameterAsNode,
+            "string": this._formatParameterAsString,
+        };
+
+        var formatter = formatters[type] || this._formatParameterAsValue;
+
+        var span = document.createElement("span");
+        formatter.call(this, parameter, span, forceObjectFormat);
+        return span;
+    }
+
+    _formatParameterAsValue(value, element)
+    {
+        element.appendChild(WebInspector.FormattedValue.createElementForRemoteObject(value));
+    }
+
+    _formatParameterAsString(object, element)
+    {
+        element.appendChild(WebInspector.FormattedValue.createLinkifiedElementString(object.description));
+    }
+
+    _formatParameterAsNode(object, element)
+    {
+        element.appendChild(WebInspector.FormattedValue.createElementForNode(object));
+    }
+
+    _formatParameterAsObject(object, element, forceExpansion)
+    {
+        // FIXME: Should have a better ObjectTreeView mode for classes (static methods and methods).
+        // FIXME: Only need to assign to objectTree if this is a ConsoleMessageResult. We should assert that.
+        this._objectTree = new WebInspector.ObjectTreeView(object, null, this._rootPropertyPathForObject(object), forceExpansion);
+        element.appendChild(this._objectTree.element);
+    }
+
+    _formatParameterAsArray(array, element)
+    {
+        this._objectTree = new WebInspector.ObjectTreeView(array, WebInspector.ObjectTreeView.Mode.Properties, this._rootPropertyPathForObject(array));
+        element.appendChild(this._objectTree.element);
+    }
+
+    _rootPropertyPathForObject(object)
+    {
+        if (!this._message.savedResultIndex)
+            return null;
+
+        return new WebInspector.PropertyPath(object, "$" + this.savedResultIndex);
+    }
+
+    _formatWithSubstitutionString(parameters, formattedResult)
+    {
+        function parameterFormatter(force, obj)
+        {
+            return this._formatParameter(obj, force);
+        }
+
+        function stringFormatter(obj)
+        {
+            return obj.description;
+        }
+
+        function floatFormatter(obj)
+        {
+            if (typeof obj.value !== "number")
+                return parseFloat(obj.description);
+            return obj.value;
+        }
+
+        function integerFormatter(obj)
+        {
+            if (typeof obj.value !== "number")
+                return parseInt(obj.description);
+            return Math.floor(obj.value);
+        }
+
+        var currentStyle = null;
+        function styleFormatter(obj)
+        {
+            currentStyle = {};
+            var buffer = document.createElement("span");
+            buffer.setAttribute("style", obj.description);
+            for (var i = 0; i < buffer.style.length; i++) {
+                var property = buffer.style[i];
+                if (isWhitelistedProperty(property))
+                    currentStyle[property] = buffer.style[property];
+            }
+        }
+
+        function isWhitelistedProperty(property)
+        {
+            for (var prefix of ["background", "border", "color", "font", "line", "margin", "padding", "text"]) {
+                if (property.startsWith(prefix) || property.startsWith("-webkit-" + prefix))
+                    return true;
+            }
+            return false;
+        }
+
+        // Firebug uses %o for formatting objects.
+        var formatters = {};
+        formatters.o = parameterFormatter.bind(this, false);
+        formatters.s = stringFormatter;
+        formatters.f = floatFormatter;
+
+        // Firebug allows both %i and %d for formatting integers.
+        formatters.i = integerFormatter;
+        formatters.d = integerFormatter;
+
+        // Firebug uses %c for styling the message.
+        formatters.c = styleFormatter;
+
+        // Support %O to force object formatting, instead of the type-based %o formatting.
+        formatters.O = parameterFormatter.bind(this, true);
+
+        function append(a, b)
+        {
+            if (b instanceof Node)
+                a.appendChild(b);
+            else if (b) {
+                var toAppend = WebInspector.linkifyStringAsFragment(b.toString());
+                if (currentStyle) {
+                    var wrapper = document.createElement("span");
+                    for (var key in currentStyle)
+                        wrapper.style[key] = currentStyle[key];
+                    wrapper.appendChild(toAppend);
+                    toAppend = wrapper;
+                }
+
+                var span = document.createElement("span");
+                span.className = "type-string";
+                span.appendChild(toAppend);
+                a.appendChild(span);
+            }
+            return a;
+        }
+
+        // String.format does treat formattedResult like a Builder, result is an object.
+        return String.format(parameters[0].description, parameters.slice(1), formatters, formattedResult, append);
+    }
+
+    _shouldShowStackTrace()
+    {
+        if (!this._message.stackTrace || !this._message.stackTrace.length)
+            return false;
+
+        return this._message.source === WebInspector.ConsoleMessage.MessageSource.Network
+            || this._message.level === WebInspector.ConsoleMessage.MessageLevel.Error
+            || this._message.type === WebInspector.ConsoleMessage.MessageType.Trace;
+    }
+
+    _shouldHideURL(url)
+    {
+        return url === "undefined" || url === "[native code]";
+    }
+
+    _firstNonNativeCallFrame()
+    {
+        if (!this._message.stackTrace)
+            return null;
+
+        for (var i = 0; i < this._message.stackTrace.length; i++) {
+            var frame = this._message.stackTrace[i];
+            if (!frame.url || frame.url === "[native code]")
+                continue;
+            return frame;
+        }
+
+        return null;
+    }
+
+    _linkifyLocation(url, lineNumber, columnNumber)
+    {
+        // ConsoleMessage stack trace line numbers are one-based.
+        lineNumber = lineNumber ? lineNumber - 1 : 0;
+        columnNumber = columnNumber ? columnNumber - 1 : 0;
+        return WebInspector.linkifyLocation(url, lineNumber, columnNumber, "console-message-url");
+    }
+
+    _linkifyCallFrame(callFrame)
+    {
+        return this._linkifyLocation(callFrame.url, callFrame.lineNumber, callFrame.columnNumber);
+    }
+
+    _userProvidedColumnNames(columnNamesArgument)
+    {
+        if (!columnNamesArgument)
+            return null;
+
+        var remoteObject = WebInspector.RemoteObject.fromPayload(columnNamesArgument);
+
+        // Single primitive argument.
+        if (remoteObject.type === "string" || remoteObject.type === "number")
+            return [String(columnNamesArgument.value)];
+
+        // Ignore everything that is not an array with property previews.
+        if (remoteObject.type !== "object" || remoteObject.subtype !== "array" || !remoteObject.preview || !remoteObject.preview.propertyPreviews)
+            return null;
+
+        // Array. Look into the preview and get string values.
+        var extractedColumnNames = [];
+        for (var propertyPreview of remoteObject.preview.propertyPreviews) {
+            if (propertyPreview.type === "string" || propertyPreview.type === "number")
+                extractedColumnNames.push(String(propertyPreview.value));
+        }
+
+        return extractedColumnNames.length ? extractedColumnNames : null;
+    }
+
+    _formatParameterAsTable(parameters)
+    {
+        var element = document.createElement("span");
+        var table = parameters[0];
+        if (!table || !table.preview)
+            return element;
+
+        var rows = [];
+        var columnNames = [];
+        var flatValues = [];
+        var preview = table.preview;
+        var userProvidedColumnNames = false;
+
+        // User provided columnNames.
+        var extractedColumnNames = this._userProvidedColumnNames(parameters[1]);
+        if (extractedColumnNames) {
+            userProvidedColumnNames = true;
+            columnNames = extractedColumnNames;
+        }
+
+        // Check first for valuePreviews in the properties meaning this was an array of objects.
+        if (preview.propertyPreviews) {
+            for (var i = 0; i < preview.propertyPreviews.length; ++i) {
+                var rowProperty = preview.propertyPreviews[i];
+                var rowPreview = rowProperty.valuePreview;
+                if (!rowPreview)
+                    continue;
+
+                var rowValue = {};
+                var maxColumnsToRender = 10;
+                for (var j = 0; j < rowPreview.propertyPreviews.length; ++j) {
+                    var cellProperty = rowPreview.propertyPreviews[j];
+                    var columnRendered = columnNames.includes(cellProperty.name);
+                    if (!columnRendered) {
+                        if (userProvidedColumnNames || columnNames.length === maxColumnsToRender)
+                            continue;
+                        columnRendered = true;
+                        columnNames.push(cellProperty.name);
+                    }
+
+                    rowValue[cellProperty.name] = WebInspector.FormattedValue.createElementForPropertyPreview(cellProperty);
+                }
+                rows.push([rowProperty.name, rowValue]);
+            }
+        }
+
+        // If there were valuePreviews, convert to a flat list.
+        if (rows.length) {
+            var emDash = "\u2014";
+            columnNames.unshift(WebInspector.UIString("(Index)"));
+            for (var i = 0; i < rows.length; ++i) {
+                var rowName = rows[i][0];
+                var rowValue = rows[i][1];
+                flatValues.push(rowName);
+                for (var j = 1; j < columnNames.length; ++j) {
+                    var columnName = columnNames[j];
+                    if (!(columnName in rowValue))
+                        flatValues.push(emDash);
+                    else
+                        flatValues.push(rowValue[columnName]);
+                }
+            }
+        }
+
+        // If there were no value Previews, then check for an array of values.
+        if (!flatValues.length && preview.propertyPreviews) {
+            for (var i = 0; i < preview.propertyPreviews.length; ++i) {
+                var rowProperty = preview.propertyPreviews[i];
+                if (!("value" in rowProperty))
+                    continue;
+
+                if (!columnNames.length) {
+                    columnNames.push(WebInspector.UIString("Index"));
+                    columnNames.push(WebInspector.UIString("Value"));
+                }
+
+                flatValues.push(rowProperty.name);
+                flatValues.push(WebInspector.FormattedValue.createElementForPropertyPreview(rowProperty));
+            }
+        }
+
+        // If lossless or not table data, output the object so full data can be gotten.
+        if (!preview.lossless || !flatValues.length) {
+            element.appendChild(this._formatParameter(table));
+            if (!flatValues.length)
+                return element;
+        }
+
+        var dataGrid = WebInspector.DataGrid.createSortableDataGrid(columnNames, flatValues);
+        dataGrid.element.classList.add("inline");
+        element.appendChild(dataGrid.element);
+
+        return element;
+    }
+
+    _levelString()
+    {
+        switch (this._message.level) {
+        case WebInspector.ConsoleMessage.MessageLevel.Tip:
+            return "Tip";
+        case WebInspector.ConsoleMessage.MessageLevel.Log:
+            return "Log";
+        case WebInspector.ConsoleMessage.MessageLevel.Warning:
+            return "Warning";
+        case WebInspector.ConsoleMessage.MessageLevel.Debug:
+            return "Debug";
+        case WebInspector.ConsoleMessage.MessageLevel.Error:
+            return "Error";
+        }
+    }
+
+    _enforcesClipboardPrefixString()
+    {
+        return this._message.type !== WebInspector.ConsoleMessage.MessageType.Result;
+    }
+
+    _clipboardPrefixString()
+    {
+        if (this._message.type === WebInspector.ConsoleMessage.MessageType.Result)
+            return "< ";
+
+        return "[" + this._levelString() + "] ";
+    }
+};
index c6159e1bf62030c61a2f06662b770fef33a9b81d..2ed00c9813c23da487c56a6d3570fa325beb2198 100644 (file)
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ConsoleSession = function()
+WebInspector.ConsoleSession = class ConsoleSession extends WebInspector.Object
 {
-    // FIXME: Convert this to a WebInspector.Object subclass, and call super().
-    // WebInspector.Object.call(this);
+    constructor()
+    {
+        super();
 
-    var element = document.createElement("div");
-    element.className = "console-session";
-    this.element = element;
-    this._messagesElement = element;
-};
+        var element = document.createElement("div");
+        element.className = "console-session";
+        this.element = element;
+        this._messagesElement = element;
+    }
 
-WebInspector.ConsoleSession.prototype = {
-    constructor: WebInspector.ConsoleSession,
+    // Public
 
-    addMessage: function(message)
+    addMessageView(messageView)
     {
-        var messageElement = message.toMessageElement();
+        var messageElement = messageView.element;
         messageElement.classList.add(WebInspector.LogContentView.ItemWrapperStyleClassName);
         this._messagesElement.appendChild(messageElement);
-    },
+    }
 
-    append: function(messageElement)
+    append(messageOrGroupElement)
     {
-        this._messagesElement.appendChild(messageElement);
-    },
+        this._messagesElement.appendChild(messageOrGroupElement);
+    }
 
-    hasMessages: function()
+    hasMessages()
     {
         return !!this._messagesElement.childNodes.length;
     }
 };
-
-WebInspector.ConsoleSession.prototype.__proto__ = WebInspector.Object.prototype;
diff --git a/Source/WebInspectorUI/UserInterface/Views/LegacyConsoleMessage.js b/Source/WebInspectorUI/UserInterface/Views/LegacyConsoleMessage.js
deleted file mode 100644 (file)
index df8d712..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
- * Copyright (C) 2007, 2008, 2013 Apple Inc.  All rights reserved.
- * Copyright (C) 2009 Joseph Pecoraro
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-WebInspector.LegacyConsoleMessage = function(source, level, url, line, column, repeatCount)
-{
-    this.source = source;
-    this.level = level;
-    this.url = url || null;
-    this.line = line || 0;
-    this.column = column || 0;
-
-    repeatCount = repeatCount || 1;
-    this.repeatCount = repeatCount;
-    this.repeatDelta = repeatCount;
-    this.totalRepeatCount = repeatCount;
-};
-
-WebInspector.LegacyConsoleMessage.prototype = {
-    isErrorOrWarning: function()
-    {
-        return (this.level === WebInspector.LegacyConsoleMessage.MessageLevel.Warning || this.level === WebInspector.LegacyConsoleMessage.MessageLevel.Error);
-    },
-
-    updateRepeatCount: function()
-    {
-        // Implemented by concrete instances
-    },
-
-    clone: function()
-    {
-        // Implemented by concrete instances
-    }
-};
-
-WebInspector.LegacyConsoleMessage.create = function(source, level, message, type, url, line, column, repeatCount, parameters, stackTrace, request)
-{
-    return new WebInspector.LegacyConsoleMessageImpl(source, level, message, null, type, url, line, column, repeatCount, parameters, stackTrace, request);
-};
-
-// FIXME: Switch to ConsoleAgent.ConsoleMessageSource.
-WebInspector.LegacyConsoleMessage.MessageSource = {
-    HTML: "html",
-    XML: "xml",
-    JS: "javascript",
-    Network: "network",
-    ConsoleAPI: "console-api",
-    Other: "other"
-};
-
-// FIXME: Switch to ConsoleAgent.ConsoleMessageType.
-WebInspector.LegacyConsoleMessage.MessageType = {
-    Log: "log",
-    Dir: "dir",
-    DirXML: "dirxml",
-    Table: "table",
-    Trace: "trace",
-    StartGroup: "startGroup",
-    StartGroupCollapsed: "startGroupCollapsed",
-    EndGroup: "endGroup",
-    Assert: "assert",
-    Result: "result"
-};
-
-// FIXME: Switch to ConsoleAgent.ConsoleMessageLevel.
-WebInspector.LegacyConsoleMessage.MessageLevel = {
-    Tip: "tip",
-    Log: "log",
-    Warning: "warning",
-    Error: "error",
-    Debug: "debug"
-};
diff --git a/Source/WebInspectorUI/UserInterface/Views/LegacyConsoleMessageImpl.js b/Source/WebInspectorUI/UserInterface/Views/LegacyConsoleMessageImpl.js
deleted file mode 100644 (file)
index 80a8b45..0000000
+++ /dev/null
@@ -1,801 +0,0 @@
-/*
- * Copyright (C) 2011 Google Inc.  All rights reserved.
- * Copyright (C) 2007, 2008, 2013 Apple Inc.  All rights reserved.
- * Copyright (C) 2009 Joseph Pecoraro
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1.  Redistributions of source code must retain the above copyright
- *     notice, this list of conditions and the following disclaimer.
- * 2.  Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-WebInspector.LegacyConsoleMessageImpl = function(source, level, message, linkifier, type, url, line, column, repeatCount, parameters, stackTrace, request)
-{
-    WebInspector.LegacyConsoleMessage.call(this, source, level, url, line, column, repeatCount);
-
-    this._linkifier = linkifier;
-    this.type = type || WebInspector.LegacyConsoleMessage.MessageType.Log;
-    this._messageText = message;
-    this._parameters = parameters;
-    this._stackTrace = stackTrace;
-    this._request = request;
-
-    this._customFormatters = {
-        "object": this._formatParameterAsObject,
-        "error": this._formatParameterAsObject,
-        "map": this._formatParameterAsObject,
-        "set": this._formatParameterAsObject,
-        "weakmap": this._formatParameterAsObject,
-        "iterator": this._formatParameterAsObject,
-        "class": this._formatParameterAsObject,
-        "array":  this._formatParameterAsArray,
-        "node":   this._formatParameterAsNode,
-        "string": this._formatParameterAsString
-    };
-};
-
-WebInspector.LegacyConsoleMessageImpl.prototype = {
-
-    enforcesClipboardPrefixString: true,
-
-    _formatMessage: function()
-    {
-        this._formattedMessage = document.createElement("span");
-        this._formattedMessage.className = "console-message-text";
-
-        var messageText;
-        if (this.source === WebInspector.LegacyConsoleMessage.MessageSource.ConsoleAPI) {
-            switch (this.type) {
-                case WebInspector.LegacyConsoleMessage.MessageType.Trace:
-                    messageText = document.createTextNode("console.trace()");
-                    break;
-                case WebInspector.LegacyConsoleMessage.MessageType.Assert:
-                    var args = [WebInspector.UIString("Assertion failed:")];
-                    if (this._parameters)
-                        args = args.concat(this._parameters);
-                    messageText = this._format(args);
-                    break;
-                case WebInspector.LegacyConsoleMessage.MessageType.Dir:
-                    var obj = this._parameters ? this._parameters[0] : undefined;
-                    var args = ["%O", obj];
-                    messageText = this._format(args);
-                    break;
-                default:
-                    var args = this._parameters || [this._messageText];
-                    messageText = this._format(args);
-            }
-        } else if (this.source === WebInspector.LegacyConsoleMessage.MessageSource.Network) {
-            if (this._request) {
-                this._stackTrace = this._request.stackTrace;
-                if (this._request.initiator && this._request.initiator.url) {
-                    this.url = this._request.initiator.url;
-                    this.line = this._request.initiator.lineNumber;
-                }
-                messageText = document.createElement("span");
-                if (this.level === WebInspector.LegacyConsoleMessage.MessageLevel.Error) {
-                    messageText.appendChild(document.createTextNode(this._request.requestMethod + " "));
-                    messageText.appendChild(WebInspector.linkifyRequestAsNode(this._request));
-                    if (this._request.failed)
-                        messageText.appendChild(document.createTextNode(" " + this._request.localizedFailDescription));
-                    else
-                        messageText.appendChild(document.createTextNode(" " + this._request.statusCode + " (" + this._request.statusText + ")"));
-                } else {
-                    var fragment = WebInspector.linkifyStringAsFragmentWithCustomLinkifier(this._messageText, WebInspector.linkifyRequestAsNode.bind(null, this._request, ""));
-                    messageText.appendChild(fragment);
-                }
-            } else {
-                if (this.url) {
-                    var anchor = WebInspector.linkifyURLAsNode(this.url, this.url, "console-message-url");
-                    this._formattedMessage.appendChild(anchor);
-                }
-                messageText = this._format([this._messageText]);
-            }
-        } else {
-            var args = this._parameters || [this._messageText];
-            messageText = this._format(args);
-        }
-
-        if (this.source !== WebInspector.LegacyConsoleMessage.MessageSource.Network || this._request) {
-            var firstNonNativeCallFrame = this._firstNonNativeCallFrame();
-            if (firstNonNativeCallFrame) {
-                var urlElement = this._linkifyCallFrame(firstNonNativeCallFrame);
-                this._formattedMessage.appendChild(urlElement);
-            } else if (this.url && !this._shouldHideURL(this.url)) {
-                var urlElement = this._linkifyLocation(this.url, this.line, this.column);
-                this._formattedMessage.appendChild(urlElement);
-            }
-        }
-
-        this._formattedMessage.appendChild(messageText);
-
-        if (this.savedResultIndex) {
-            var savedVariableElement = document.createElement("span");
-            savedVariableElement.className = "console-saved-variable";
-            savedVariableElement.textContent = " = $" + this.savedResultIndex;
-            if (this._objectTree)
-                this._objectTree.appendTitleSuffix(savedVariableElement);
-            else
-                this._formattedMessage.appendChild(savedVariableElement);
-        }
-
-        if (this._shouldDumpStackTrace()) {
-            var ol = document.createElement("ol");
-            ol.className = "outline-disclosure";
-            var treeOutline = new WebInspector.TreeOutline(ol);
-
-            var content = this._formattedMessage;
-            var root = new WebInspector.TreeElement(content, null, true);
-            treeOutline.appendChild(root);
-            if (this.type === WebInspector.LegacyConsoleMessage.MessageType.Trace)
-                root.expand();
-
-            this._populateStackTraceTreeElement(root);
-            this._formattedMessage = ol;
-        }
-
-        // This is used for inline message bubbles in SourceFrames, or other plain-text representations.
-        this._message = messageText.textContent;
-    },
-
-    _shouldDumpStackTrace: function()
-    {
-        return !!this._stackTrace && this._stackTrace.length && (this.source === WebInspector.LegacyConsoleMessage.MessageSource.Network || this.level === WebInspector.LegacyConsoleMessage.MessageLevel.Error || this.type === WebInspector.LegacyConsoleMessage.MessageType.Trace);
-    },
-
-    _shouldHideURL: function(url)
-    {
-        return url === "undefined" || url === "[native code]";
-    },
-
-    _firstNonNativeCallFrame: function()
-    {
-        if (!this._stackTrace)
-            return null;
-
-        for (var i = 0; i < this._stackTrace.length; i++) {
-            var frame = this._stackTrace[i];
-            if (!frame.url || frame.url === "[native code]")
-                continue;
-            return frame;
-        }
-
-        return null;
-    },
-
-    get message()
-    {
-        // force message formatting
-        var formattedMessage = this.formattedMessage;
-        return this._message;
-    },
-
-    get formattedMessage()
-    {
-        if (!this._formattedMessage)
-            this._formatMessage();
-        return this._formattedMessage;
-    },
-
-    _linkifyLocation: function(url, lineNumber, columnNumber)
-    {
-        // ConsoleMessage stack trace line numbers are one-based.
-        lineNumber = lineNumber ? lineNumber - 1 : 0;
-        columnNumber = columnNumber ? columnNumber - 1 : 0;
-
-        return WebInspector.linkifyLocation(url, lineNumber, columnNumber, "console-message-url");
-    },
-
-    _linkifyCallFrame: function(callFrame)
-    {
-        return this._linkifyLocation(callFrame.url, callFrame.lineNumber, callFrame.columnNumber);
-    },
-
-    isErrorOrWarning: function()
-    {
-        return (this.level === WebInspector.LegacyConsoleMessage.MessageLevel.Warning || this.level === WebInspector.LegacyConsoleMessage.MessageLevel.Error);
-    },
-
-    _format: function(parameters)
-    {
-        // This node is used like a Builder. Values are continually appended onto it.
-        var formattedResult = document.createElement("span");
-        if (!parameters.length)
-            return formattedResult;
-
-        // Formatting code below assumes that parameters are all wrappers whereas frontend console
-        // API allows passing arbitrary values as messages (strings, numbers, etc.). Wrap them here.
-        for (var i = 0; i < parameters.length; ++i) {
-            // FIXME: Only pass runtime wrappers here.
-            if (parameters[i] instanceof WebInspector.RemoteObject)
-                continue;
-
-            if (typeof parameters[i] === "object")
-                parameters[i] = WebInspector.RemoteObject.fromPayload(parameters[i]);
-            else
-                parameters[i] = WebInspector.RemoteObject.fromPrimitiveValue(parameters[i]);
-        }
-
-        // There can be string log and string eval result. We distinguish between them based on message type.
-        var shouldFormatMessage = WebInspector.RemoteObject.type(parameters[0]) === "string" && this.type !== WebInspector.LegacyConsoleMessage.MessageType.Result;
-
-        if (shouldFormatMessage) {
-            // Multiple parameters with the first being a format string. Save unused substitutions.
-            var result = this._formatWithSubstitutionString(parameters, formattedResult);
-            parameters = result.unusedSubstitutions;
-            if (parameters.length)
-                formattedResult.appendChild(document.createTextNode(" "));
-        }
-
-        if (this.type === WebInspector.LegacyConsoleMessage.MessageType.Table) {
-            formattedResult.appendChild(this._formatParameterAsTable(parameters));
-            return formattedResult;
-        }
-
-        // Single parameter, or unused substitutions from above.
-        for (var i = 0; i < parameters.length; ++i) {
-            // Inline strings when formatting.
-            if (shouldFormatMessage && parameters[i].type === "string") {
-                var span = document.createElement("span");
-                span.classList.add("type-string");
-                span.textContent = parameters[i].description;
-                formattedResult.appendChild(span);
-            } else
-                formattedResult.appendChild(this._formatParameter(parameters[i], false));
-
-            if (i < parameters.length - 1 && !this._isExpandable(parameters[i]))
-                formattedResult.appendChild(document.createTextNode(" "));
-
-        }
-        return formattedResult;
-    },
-
-    _isExpandable: function(remoteObject) {
-        if (!remoteObject)
-            return false;
-
-        if (remoteObject.hasChildren && remoteObject.preview && remoteObject.preview.lossless)
-            return false;
-
-        return remoteObject.hasChildren;
-    },
-
-    _formatParameter: function(output, forceObjectFormat)
-    {
-        var type;
-        if (forceObjectFormat)
-            type = "object";
-        else if (output instanceof WebInspector.RemoteObject)
-            type = output.subtype || output.type;
-        else
-            type = typeof output;
-
-        var formatter = this._customFormatters[type];
-        if (!formatter)
-            formatter = this._formatParameterAsValue;
-
-        var span = document.createElement("span");
-
-        if (this._isExpandable(output))
-            span.classList.add("expandable");
-
-        formatter.call(this, output, span, forceObjectFormat);
-        return span;
-    },
-
-    _formatParameterAsValue: function(value, elem)
-    {
-        elem.appendChild(WebInspector.FormattedValue.createElementForRemoteObject(value));
-    },
-
-    _formatParameterAsObject: function(obj, elem, forceExpansion)
-    {
-        // FIXME: Should have a better ObjectTreeView mode for classes (static methods and methods).
-        this._objectTree = new WebInspector.ObjectTreeView(obj, null, this._rootPropertyPathForObject(obj), forceExpansion);
-        elem.appendChild(this._objectTree.element);
-    },
-
-    _formatParameterAsString: function(output, elem)
-    {
-        var span = WebInspector.FormattedValue.createLinkifiedElementString(output.description);
-        elem.appendChild(span);
-    },
-
-    _formatParameterAsNode: function(object, elem)
-    {
-        var span = WebInspector.FormattedValue.createElementForNode(object);
-        elem.appendChild(span);
-    },
-
-    _formatParameterAsArray: function(arr, elem)
-    {
-        this._objectTree = new WebInspector.ObjectTreeView(arr, WebInspector.ObjectTreeView.Mode.Properties, this._rootPropertyPathForObject(arr));
-        elem.appendChild(this._objectTree.element);
-    },
-
-    _rootPropertyPathForObject: function(object)
-    {
-        if (!this.savedResultIndex)
-            return null;
-
-        return new WebInspector.PropertyPath(object, "$" + this.savedResultIndex);
-    },
-
-    _userProvidedColumnNames: function(columnNamesArgument)
-    {
-        if (!columnNamesArgument)
-            return null;
-
-        var remoteObject = WebInspector.RemoteObject.fromPayload(columnNamesArgument);
-
-        // Single primitive argument.
-        if (remoteObject.type === "string" || remoteObject.type === "number")
-            return [String(columnNamesArgument.value)];
-
-        // Ignore everything that is not an array with property previews.
-        if (remoteObject.type !== "object" || remoteObject.subtype !== "array" || !remoteObject.preview || !remoteObject.preview.propertyPreviews)
-            return null;
-
-        // Array. Look into the preview and get string values.
-        var extractedColumnNames = [];
-        for (var propertyPreview of remoteObject.preview.propertyPreviews) {
-            if (propertyPreview.type === "string" || propertyPreview.type === "number")
-                extractedColumnNames.push(String(propertyPreview.value));
-        }
-
-        return extractedColumnNames.length ? extractedColumnNames : null;
-    },
-
-    _formatParameterAsTable: function(parameters)
-    {
-        var element = document.createElement("span");
-        var table = parameters[0];
-        if (!table || !table.preview)
-            return element;
-
-        var rows = [];
-        var columnNames = [];
-        var flatValues = [];
-        var preview = table.preview;
-        var userProvidedColumnNames = false;
-
-        // User provided columnNames.
-        var extractedColumnNames = this._userProvidedColumnNames(parameters[1]);
-        if (extractedColumnNames) {
-            userProvidedColumnNames = true;
-            columnNames = extractedColumnNames;
-        }
-
-        // Check first for valuePreviews in the properties meaning this was an array of objects.
-        if (preview.propertyPreviews) {
-            for (var i = 0; i < preview.propertyPreviews.length; ++i) {
-                var rowProperty = preview.propertyPreviews[i];
-                var rowPreview = rowProperty.valuePreview;
-                if (!rowPreview)
-                    continue;
-
-                var rowValue = {};
-                const maxColumnsToRender = 10;
-                for (var j = 0; j < rowPreview.propertyPreviews.length; ++j) {
-                    var cellProperty = rowPreview.propertyPreviews[j];
-                    var columnRendered = columnNames.includes(cellProperty.name);
-                    if (!columnRendered) {
-                        if (userProvidedColumnNames || columnNames.length === maxColumnsToRender)
-                            continue;
-                        columnRendered = true;
-                        columnNames.push(cellProperty.name);
-                    }
-
-                    rowValue[cellProperty.name] = WebInspector.FormattedValue.createElementForPropertyPreview(cellProperty);
-                }
-                rows.push([rowProperty.name, rowValue]);
-            }
-        }
-
-        // If there were valuePreviews, convert to a flat list.
-        if (rows.length) {
-            const emDash = "\u2014";
-            columnNames.unshift(WebInspector.UIString("(Index)"));
-            for (var i = 0; i < rows.length; ++i) {
-                var rowName = rows[i][0];
-                var rowValue = rows[i][1];
-                flatValues.push(rowName);
-                for (var j = 1; j < columnNames.length; ++j) {
-                    var columnName = columnNames[j];
-                    if (!(columnName in rowValue))
-                        flatValues.push(emDash);
-                    else
-                        flatValues.push(rowValue[columnName]);
-                }
-            }
-        }
-
-        // If there were no value Previews, then check for an array of values.
-        if (!flatValues.length && preview.propertyPreviews) {
-            for (var i = 0; i < preview.propertyPreviews.length; ++i) {
-                var rowProperty = preview.propertyPreviews[i];
-                if (!("value" in rowProperty))
-                    continue;
-
-                if (!columnNames.length) {
-                    columnNames.push(WebInspector.UIString("Index"));
-                    columnNames.push(WebInspector.UIString("Value"));
-                }
-
-                flatValues.push(rowProperty.name);
-                flatValues.push(WebInspector.FormattedValue.createElementForPropertyPreview(rowProperty));
-            }
-        }
-
-        // If lossless or not table data, output the object so full data can be gotten.
-        if (!preview.lossless || !flatValues.length) {
-            element.appendChild(this._formatParameter(table));
-            if (!flatValues.length)
-                return element;
-        }
-
-        var dataGrid = WebInspector.DataGrid.createSortableDataGrid(columnNames, flatValues);
-        dataGrid.element.classList.add("inline");
-        element.appendChild(dataGrid.element);
-
-        return element;
-    },
-
-    _formatWithSubstitutionString: function(parameters, formattedResult)
-    {
-        var formatters = {};
-
-        function parameterFormatter(force, obj)
-        {
-            return this._formatParameter(obj, force);
-        }
-
-        function stringFormatter(obj)
-        {
-            return obj.description;
-        }
-
-        function floatFormatter(obj)
-        {
-            if (typeof obj.value !== "number")
-                return parseFloat(obj.description);
-            return obj.value;
-        }
-
-        function integerFormatter(obj)
-        {
-            if (typeof obj.value !== "number")
-                return parseInt(obj.description);
-            return Math.floor(obj.value);
-        }
-
-        var currentStyle = null;
-        function styleFormatter(obj)
-        {
-            currentStyle = {};
-            var buffer = document.createElement("span");
-            buffer.setAttribute("style", obj.description);
-            for (var i = 0; i < buffer.style.length; i++) {
-                var property = buffer.style[i];
-                if (isWhitelistedProperty(property))
-                    currentStyle[property] = buffer.style[property];
-            }
-        }
-
-        function isWhitelistedProperty(property)
-        {
-            var prefixes = ["background", "border", "color", "font", "line", "margin", "padding", "text", "-webkit-background", "-webkit-border", "-webkit-font", "-webkit-margin", "-webkit-padding", "-webkit-text"];
-            for (var i = 0; i < prefixes.length; i++) {
-                if (property.startsWith(prefixes[i]))
-                    return true;
-            }
-            return false;
-        }
-
-        // Firebug uses %o for formatting objects.
-        formatters.o = parameterFormatter.bind(this, false);
-        formatters.s = stringFormatter;
-        formatters.f = floatFormatter;
-
-        // Firebug allows both %i and %d for formatting integers.
-        formatters.i = integerFormatter;
-        formatters.d = integerFormatter;
-
-        // Firebug uses %c for styling the message.
-        formatters.c = styleFormatter;
-
-        // Support %O to force object formatting, instead of the type-based %o formatting.
-        formatters.O = parameterFormatter.bind(this, true);
-
-        function append(a, b)
-        {
-            if (b instanceof Node)
-                a.appendChild(b);
-            else if (b) {
-                var toAppend = WebInspector.linkifyStringAsFragment(b.toString());
-                if (currentStyle) {
-                    var wrapper = document.createElement("span");
-                    for (var key in currentStyle)
-                        wrapper.style[key] = currentStyle[key];
-                    wrapper.appendChild(toAppend);
-                    toAppend = wrapper;
-                }
-                var span = document.createElement("span");
-                span.className = "type-string";
-                span.appendChild(toAppend);
-                a.appendChild(span);
-            }
-            return a;
-        }
-
-        // String.format does treat formattedResult like a Builder, result is an object.
-        return String.format(parameters[0].description, parameters.slice(1), formatters, formattedResult, append);
-    },
-
-    decorateMessageElement: function(element)
-    {
-        if (this._element)
-            return this._element;
-
-        element.message = this;
-        element.classList.add("console-message");
-
-        this._element = element;
-
-        switch (this.level) {
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Tip:
-                element.classList.add("console-tip-level");
-                element.setAttribute("data-labelprefix", WebInspector.UIString("Tip: "));
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Log:
-                element.classList.add("console-log-level");
-                element.setAttribute("data-labelprefix", WebInspector.UIString("Log: "));
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Debug:
-                element.classList.add("console-debug-level");
-                element.setAttribute("data-labelprefix", WebInspector.UIString("Debug: "));
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Warning:
-                element.classList.add("console-warning-level");
-                element.setAttribute("data-labelprefix", WebInspector.UIString("Warning: "));
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Error:
-                element.classList.add("console-error-level");
-                element.setAttribute("data-labelprefix", WebInspector.UIString("Error: "));
-                break;
-        }
-
-        if (this.type === WebInspector.LegacyConsoleMessage.MessageType.StartGroup || this.type === WebInspector.LegacyConsoleMessage.MessageType.StartGroupCollapsed)
-            element.classList.add("console-group-title");
-
-        element.appendChild(this.formattedMessage);
-
-        if (this.repeatCount > 1)
-            this.updateRepeatCount();
-
-        return element;
-    },
-
-    toMessageElement: function()
-    {
-        if (this._element)
-            return this._element;
-
-        var element = document.createElement("div");
-
-        return this.decorateMessageElement(element);
-    },
-
-    _populateStackTraceTreeElement: function(parentTreeElement)
-    {
-        for (var i = 0; i < this._stackTrace.length; i++) {
-            var frame = this._stackTrace[i];
-
-            var content = document.createElement("div");
-            var messageTextElement = document.createElement("span");
-            messageTextElement.className = "console-message-text";
-            var functionName = frame.functionName || WebInspector.UIString("(anonymous function)");
-            messageTextElement.appendChild(document.createTextNode(functionName));
-            content.appendChild(messageTextElement);
-
-            if (frame.url && !this._shouldHideURL(frame.url)) {
-                var urlElement = this._linkifyCallFrame(frame);
-                content.appendChild(urlElement);
-            }
-
-            var treeElement = new WebInspector.TreeElement(content);
-            parentTreeElement.appendChild(treeElement);
-        }
-    },
-
-    updateRepeatCount: function() {
-        if (!this.repeatCountElement) {
-            this.repeatCountElement = document.createElement("span");
-            this.repeatCountElement.className = "bubble";
-
-            this._element.insertBefore(this.repeatCountElement, this._element.firstChild);
-        }
-        this.repeatCountElement.textContent = this.repeatCount;
-    },
-
-    toString: function()
-    {
-        var sourceString;
-        switch (this.source) {
-            case WebInspector.LegacyConsoleMessage.MessageSource.HTML:
-                sourceString = "HTML";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageSource.XML:
-                sourceString = "XML";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageSource.JS:
-                sourceString = "JS";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageSource.Network:
-                sourceString = "Network";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageSource.ConsoleAPI:
-                sourceString = "ConsoleAPI";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageSource.Other:
-                sourceString = "Other";
-                break;
-        }
-
-        var typeString;
-        switch (this.type) {
-            case WebInspector.LegacyConsoleMessage.MessageType.Log:
-                typeString = "Log";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.Dir:
-                typeString = "Dir";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.DirXML:
-                typeString = "Dir XML";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.Trace:
-                typeString = "Trace";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.StartGroupCollapsed:
-            case WebInspector.LegacyConsoleMessage.MessageType.StartGroup:
-                typeString = "Start Group";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.EndGroup:
-                typeString = "End Group";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.Assert:
-                typeString = "Assert";
-                break;
-            case WebInspector.LegacyConsoleMessage.MessageType.Result:
-                typeString = "Result";
-                break;
-        }
-
-        return sourceString + " " + typeString + " " + this.levelString + ": " + this.formattedMessage.textContent + "\n" + this.url + " line " + this.line;
-    },
-
-    get text()
-    {
-        return this._messageText;
-    },
-
-    isEqual: function(msg)
-    {
-        if (!msg)
-            return false;
-
-        if (this._stackTrace) {
-            if (!msg._stackTrace)
-                return false;
-            var l = this._stackTrace;
-            var r = msg._stackTrace;
-            for (var i = 0; i < l.length; i++) {
-                if (l[i].url !== r[i].url ||
-                    l[i].functionName !== r[i].functionName ||
-                    l[i].lineNumber !== r[i].lineNumber ||
-                    l[i].columnNumber !== r[i].columnNumber)
-                    return false;
-            }
-        }
-
-        return (this.source === msg.source)
-            && (this.type === msg.type)
-            && (this.level === msg.level)
-            && (this.line === msg.line)
-            && (this.url === msg.url)
-            && (this.message === msg.message)
-            && (this._request === msg._request);
-    },
-
-    get stackTrace()
-    {
-        return this._stackTrace;
-    },
-
-    clone: function()
-    {
-        return WebInspector.LegacyConsoleMessage.create(this.source, this.level, this._messageText, this.type, this.url, this.line, this.column, this.repeatCount, this._parameters, this._stackTrace, this._request);
-    },
-
-    get levelString()
-    {
-        switch (this.level) {
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Tip:
-                return "Tip";
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Log:
-                return "Log";
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Warning:
-                return "Warning";
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Debug:
-                return "Debug";
-            case WebInspector.LegacyConsoleMessage.MessageLevel.Error:
-                return "Error";
-        }
-    },
-
-    get clipboardPrefixString()
-    {
-        return "[" + this.levelString + "] ";
-    },
-
-    toClipboardString: function(isPrefixOptional)
-    {
-        var isTrace = this._shouldDumpStackTrace();
-
-        var clipboardString = "";
-        if (this._formattedMessage && !isTrace)
-            clipboardString = this._formattedMessage.querySelector("span").innerText;
-        else
-            clipboardString = this.type === WebInspector.LegacyConsoleMessage.MessageType.Trace ? "console.trace()" : this._message || this._messageText;
-
-        if (!isPrefixOptional || this.enforcesClipboardPrefixString)
-            clipboardString = this.clipboardPrefixString + clipboardString;
-
-        if (isTrace) {
-            this._stackTrace.forEach(function(frame) {
-                clipboardString += "\n\t" + (frame.functionName || WebInspector.UIString("(anonymous function)"));
-                if (frame.url)
-                    clipboardString += " (" + WebInspector.displayNameForURL(frame.url) + ", line " + frame.lineNumber + ")";
-            });
-        } else {
-            var repeatString = this.repeatCount > 1 ? "x" + this.repeatCount : "";
-
-            var urlLine = "";
-            if (this.url) {
-                var components = [WebInspector.displayNameForURL(this.url), "line " + this.line];
-                if (repeatString)
-                    components.push(repeatString);
-                urlLine = " (" + components.join(", ") + ")";
-            } else if (repeatString)
-                urlLine = " (" + repeatString + ")";
-
-            if (urlLine) {
-                var lines = clipboardString.split("\n");
-                lines[0] += urlLine;
-                clipboardString = lines.join("\n");
-            }
-        }
-
-        return clipboardString;
-    }
-};
-
-WebInspector.LegacyConsoleMessageImpl.prototype.__proto__ = WebInspector.LegacyConsoleMessage.prototype;
index c253fd5d6764eea4c49e3b2d354220a899d971be..a63d704e14f105775b71e94aa88498fac4f1cbd3 100644 (file)
     width: 12px;
 }
 
-.console-message .bubble {
+.console-message .repeat-count {
     display: inline-block;
     height: 15px;
     background-color: rgb(128, 151, 189);
index 5801edf0eec73dabd3c3df823bf4695d69e68eaf..9d65a06773eb6de08d5c76f6eda485fdc31a50dc 100644 (file)
@@ -23,6 +23,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// FIXME: <https://webkit.org/b/143545> Web Inspector: LogContentView should use higher level objects
+
 WebInspector.LogContentView = function(representedObject)
 {
     WebInspector.ContentView.call(this, representedObject);
@@ -171,25 +173,28 @@ WebInspector.LogContentView.prototype = {
         WebInspector.logManager.requestClearMessages();
     },
 
-    didAppendConsoleMessage: function(message)
+    didAppendConsoleMessageView: function(messageView)
     {
+        console.assert(messageView instanceof WebInspector.ConsoleMessageView || messageView instanceof WebInspector.ConsoleCommandView);
+
         WebInspector.quickConsole.updateLayout();
 
         // Nest the message.
-        if (message.type !== WebInspector.LegacyConsoleMessage.MessageType.EndGroup) {
+        var type = messageView instanceof WebInspector.ConsoleCommandView ? null : messageView.message.type;
+        if (type !== WebInspector.ConsoleMessage.MessageType.EndGroup) {
             var x = 16 * this._nestingLevel;
-            var messageElement = message.toMessageElement();
+            var messageElement = messageView.element;
             messageElement.style.left = x + "px";
             messageElement.style.width = "calc(100% - " + x + "px)";
         }
 
         // Update the nesting level.
-        switch (message.type) {
-        case WebInspector.LegacyConsoleMessage.MessageType.StartGroup:
-        case WebInspector.LegacyConsoleMessage.MessageType.StartGroupCollapsed:
+        switch (type) {
+        case WebInspector.ConsoleMessage.MessageType.StartGroup:
+        case WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed:
             ++this._nestingLevel;
             break;
-        case WebInspector.LegacyConsoleMessage.MessageType.EndGroup:
+        case WebInspector.ConsoleMessage.MessageType.EndGroup:
             --this._nestingLevel;
             break;
         }
@@ -202,7 +207,7 @@ WebInspector.LogContentView.prototype = {
 
         // We only auto show the console if the message is a result.
         // This is when the user evaluated something directly in the prompt.
-        if (message.type !== WebInspector.LegacyConsoleMessage.MessageType.Result)
+        if (type !== WebInspector.ConsoleMessage.MessageType.Result)
             return;
 
         if (!WebInspector.isShowingConsoleView())
@@ -278,10 +283,10 @@ WebInspector.LogContentView.prototype = {
 
     _formatMessagesAsData: function(onlySelected)
     {
-        var messages = this._allMessages();
+        var messages = this._allMessageElements();
 
         if (onlySelected) {
-            messages = this._allMessages().filter(function(message) {
+            messages = messages.filter(function(message) {
                 return message.classList.contains(WebInspector.LogContentView.SelectedStyleClassName);
             });
         }
@@ -289,16 +294,14 @@ WebInspector.LogContentView.prototype = {
         var data = "";
 
         var isPrefixOptional = messages.length <= 1 && onlySelected;
-        messages.forEach(function (messageElement, index) {
-            var messageObject = messageElement.message;
-            if (!messageObject)
-                messageObject = messageElement.command;
-            if (!messageObject)
+        messages.forEach(function(messageElement, index) {
+            var messageView = messageElement.__messageView || messageElement.__commandView;
+            if (!messageView)
                 return;
 
             if (index > 0)
                 data += "\n";
-            data += messageObject.toClipboardString(isPrefixOptional);
+            data += messageView.toClipboardString(isPrefixOptional);
         });
 
         return data;
@@ -329,9 +332,9 @@ WebInspector.LogContentView.prototype = {
         if (this._startedProvisionalLoad)
             this._provisionalMessages.push(event.data.message);
 
-        var message = this._logViewController.appendConsoleMessage(event.data.message);
-        if (message.type !== WebInspector.LegacyConsoleMessage.MessageType.EndGroup)
-            this._filterMessages([message.toMessageElement()]);
+        var messageView = this._logViewController.appendConsoleMessage(event.data.message);
+        if (messageView.message.type !== WebInspector.ConsoleMessage.MessageType.EndGroup)
+            this._filterMessageElements([messageView.element]);
     },
 
     _previousMessageRepeatCountUpdated: function(event)
@@ -493,7 +496,7 @@ WebInspector.LogContentView.prototype = {
             this._clearMessagesSelection();
 
         if (rangeSelection) {
-            var messages = this._visibleMessages();
+            var messages = this._visibleMessageElements();
 
             var refIndex = this._referenceMessageForRangeSelection ? messages.indexOf(this._referenceMessageForRangeSelection) : 0;
             var targetIndex = messages.indexOf(message);
@@ -599,7 +602,7 @@ WebInspector.LogContentView.prototype = {
     {
         this._clearMessagesSelection();
 
-        var messages = this._visibleMessages();
+        var messages = this._visibleMessageElements();
         for (var i = 0; i < messages.length; ++i) {
             var message = messages[i];
             message.classList.add(WebInspector.LogContentView.SelectedStyleClassName);
@@ -607,21 +610,21 @@ WebInspector.LogContentView.prototype = {
         }
     },
 
-    _allMessages: function()
+    _allMessageElements: function()
     {
         return Array.from(this.messagesElement.querySelectorAll(".console-message, .console-user-command"));
     },
 
-    _unfilteredMessages: function()
+    _unfilteredMessageElements: function()
     {
-        return this._allMessages().filter(function(message) {
+        return this._allMessageElements().filter(function(message) {
             return !message.classList.contains(WebInspector.LogContentView.FilteredOutStyleClassName);
         });
     },
 
-    _visibleMessages: function()
+    _visibleMessageElements: function()
     {
-        var unfilteredMessages = this._unfilteredMessages();
+        var unfilteredMessages = this._unfilteredMessageElements();
 
         if (!this.searchInProgress)
             return unfilteredMessages;
@@ -660,38 +663,39 @@ WebInspector.LogContentView.prototype = {
 
     _scopeBarSelectionDidChange: function(event)
     {
-        this._filterMessages(this._allMessages());
+        this._filterMessageElements(this._allMessageElements());
     },
 
-    _filterMessages: function(messages)
+    _filterMessageElements: function(messageElements)
     {
         var showsAll = this._scopeBar.item(WebInspector.LogContentView.Scopes.All).selected;
         var showsErrors = this._scopeBar.item(WebInspector.LogContentView.Scopes.Errors).selected;
         var showsWarnings = this._scopeBar.item(WebInspector.LogContentView.Scopes.Warnings).selected;
         var showsLogs = this._scopeBar.item(WebInspector.LogContentView.Scopes.Logs).selected;
 
-        messages.forEach(function(message) {
-            var visible = showsAll || message.command instanceof WebInspector.ConsoleCommand || message.message instanceof WebInspector.ConsoleCommandResult;
+        messageElements.forEach(function(messageElement) {
+            var visible = showsAll || messageElement.__commandView instanceof WebInspector.ConsoleCommandView || messageElement.__message instanceof WebInspector.ConsoleCommandResultMessage;
             if (!visible) {
-                switch(message.message.level) {
-                    case WebInspector.LegacyConsoleMessage.MessageLevel.Warning:
-                        visible = showsWarnings;
-                        break;
-                    case WebInspector.LegacyConsoleMessage.MessageLevel.Error:
-                        visible = showsErrors;
-                        break;
-                    case WebInspector.LegacyConsoleMessage.MessageLevel.Log:
-                    case WebInspector.LegacyConsoleMessage.MessageLevel.Debug:
-                        visible = showsLogs;
-                        break;
+                switch(messageElement.__message.level) {
+                case WebInspector.ConsoleMessage.MessageLevel.Warning:
+                    visible = showsWarnings;
+                    break;
+                case WebInspector.ConsoleMessage.MessageLevel.Error:
+                    visible = showsErrors;
+                    break;
+                case WebInspector.ConsoleMessage.MessageLevel.Tip: // COMPATIBILITY (iOS 6): Treat Tips like Logs.
+                case WebInspector.ConsoleMessage.MessageLevel.Log:
+                case WebInspector.ConsoleMessage.MessageLevel.Debug:
+                    visible = showsLogs;
+                    break;
                 }
             }
 
-            var classList = message.classList;
+            var classList = messageElement.classList;
             if (visible)
                 classList.remove(WebInspector.LogContentView.FilteredOutStyleClassName);
             else {
-                this._selectedMessages.remove(message);
+                this._selectedMessages.remove(messageElement);
                 classList.remove(WebInspector.LogContentView.SelectedStyleClassName);
                 classList.add(WebInspector.LogContentView.FilteredOutStyleClassName);
             }
@@ -744,7 +748,7 @@ WebInspector.LogContentView.prototype = {
 
     _upArrowWasPressed: function(event)
     {
-        var messages = this._visibleMessages();
+        var messages = this._visibleMessageElements();
 
         if (!this._selectedMessages.length) {
             if (messages.length)
@@ -766,7 +770,7 @@ WebInspector.LogContentView.prototype = {
 
     _downArrowWasPressed: function(event)
     {
-        var messages = this._visibleMessages();
+        var messages = this._visibleMessageElements();
 
         if (!this._selectedMessages.length) {
             if (messages.length)
@@ -861,7 +865,7 @@ WebInspector.LogContentView.prototype = {
 
     _previousMessage: function(message)
     {
-        var messages = this._visibleMessages();
+        var messages = this._visibleMessageElements();
         for (var i = messages.indexOf(message) - 1; i >= 0; --i) {
             if (this._isMessageVisible(messages[i]))
                 return messages[i];
@@ -870,7 +874,7 @@ WebInspector.LogContentView.prototype = {
 
     _nextMessage: function(message)
     {
-        var messages = this._visibleMessages();
+        var messages = this._visibleMessageElements();
         for (var i = messages.indexOf(message) + 1; i < messages.length; ++i) {
             if (this._isMessageVisible(messages[i]))
                 return messages[i];
@@ -910,7 +914,7 @@ WebInspector.LogContentView.prototype = {
         this._selectedSearchMathIsValid = false;
 
         var searchRegex = new RegExp(searchTerms.escapeForRegExp(), "gi");
-        this._unfilteredMessages().forEach(function(message) {
+        this._unfilteredMessageElements().forEach(function(message) {
             var matchRanges = [];
             var text = message.textContent;
             var match = searchRegex.exec(text);
@@ -923,7 +927,7 @@ WebInspector.LogContentView.prototype = {
                 this._highlightRanges(message, matchRanges);
 
             var classList = message.classList;
-            if (!isEmptyObject(matchRanges) || message.command instanceof WebInspector.ConsoleCommand || message.message instanceof WebInspector.ConsoleCommandResult)
+            if (!isEmptyObject(matchRanges) || message.command instanceof WebInspector.ConsoleCommand || message.message instanceof WebInspector.ConsoleCommandResultMessage)
                 classList.remove(WebInspector.LogContentView.FilteredOutBySearchStyleClassName);
             else
                 classList.add(WebInspector.LogContentView.FilteredOutBySearchStyleClassName);
@@ -941,12 +945,8 @@ WebInspector.LogContentView.prototype = {
 
         console.assert(highlightedElements.length === matchRanges.length);
 
-        matchRanges.forEach(function (range, index) {
-            this._searchMatches.push({
-                message,
-                range,
-                highlight: highlightedElements[index]
-            });
+        matchRanges.forEach(function(range, index) {
+            this._searchMatches.push({message, range, highlight: highlightedElements[index]});
 
             if (this._selectedSearchMatch && !this._selectedSearchMathIsValid && this._selectedSearchMatch.message === message) {
                 this._selectedSearchMathIsValid = this._rangesOverlap(this._selectedSearchMatch.range, range);
@@ -992,9 +992,9 @@ WebInspector.LogContentView.prototype = {
         this._startedProvisionalLoad = false;
 
         for (var provisionalMessage of this._provisionalMessages) {
-            var message = this._logViewController.appendConsoleMessage(provisionalMessage);
-            if (message.type !== WebInspector.LegacyConsoleMessage.MessageType.EndGroup)
-                this._filterMessages([message.toMessageElement()]);
+            var messageView = this._logViewController.appendConsoleMessage(provisionalMessage);
+            if (message.type !== WebInspector.ConsoleMessage.MessageType.EndGroup)
+                this._filterMessageElements([messageView.element]);
         }
 
         this._provisionalMessages = [];