Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / common / Console.js
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6  * @constructor
7  * @extends {WebInspector.Object}
8  */
9 WebInspector.Console = function()
10 {
11     /** @type {!Array.<!WebInspector.Console.Message>} */
12     this._messages = [];
13 }
14
15 /**
16  * @enum {string}
17  */
18 WebInspector.Console.Events = {
19     MessageAdded: "messageAdded"
20 }
21
22 /**
23  * @enum {string}
24  */
25 WebInspector.Console.MessageLevel = {
26     Log: "log",
27     Warning: "warning",
28     Error: "error"
29 }
30
31 /**
32  * @constructor
33  * @param {string} text
34  * @param {!WebInspector.Console.MessageLevel} level
35  * @param {number} timestamp
36  * @param {boolean} show
37  */
38 WebInspector.Console.Message = function(text, level, timestamp, show)
39 {
40     this.text = text;
41     this.level = level;
42     this.timestamp = (typeof timestamp === "number") ? timestamp : Date.now();
43     this.show = show;
44 }
45
46 /**
47  * @interface
48  */
49 WebInspector.Console.UIDelegate = function()
50 {
51 }
52
53 WebInspector.Console.UIDelegate.prototype = {
54     /**
55      * @return {!Promise.<undefined>}
56      */
57     showConsole: function() { }
58 }
59
60 WebInspector.Console.prototype = {
61     /**
62      * @param {!WebInspector.Console.UIDelegate} uiDelegate
63      */
64     setUIDelegate: function(uiDelegate)
65     {
66         this._uiDelegate = uiDelegate;
67     },
68
69     /**
70      * @param {string} text
71      * @param {!WebInspector.Console.MessageLevel} level
72      * @param {boolean=} show
73      */
74     addMessage: function(text, level, show)
75     {
76         var message = new WebInspector.Console.Message(text, level || WebInspector.Console.MessageLevel.Log, Date.now(), show || false);
77         this._messages.push(message);
78         this.dispatchEventToListeners(WebInspector.Console.Events.MessageAdded, message);
79     },
80
81     /**
82      * @param {string} text
83      */
84     log: function(text)
85     {
86         this.addMessage(text, WebInspector.Console.MessageLevel.Log);
87     },
88
89     /**
90      * @param {string} text
91      */
92     warn: function(text)
93     {
94         this.addMessage(text, WebInspector.Console.MessageLevel.Warning);
95     },
96
97     /**
98      * @param {string} text
99      */
100     error: function(text)
101     {
102         this.addMessage(text, WebInspector.Console.MessageLevel.Error, true);
103     },
104
105     /**
106      * @return {!Array.<!WebInspector.Console.Message>}
107      */
108     messages: function()
109     {
110         return this._messages;
111     },
112
113     show: function()
114     {
115         this.showPromise().done();
116     },
117
118     /**
119      * @return {!Promise.<undefined>}
120      */
121     showPromise: function()
122     {
123         if (this._uiDelegate)
124             return this._uiDelegate.showConsole();
125         return Promise.reject();
126     },
127
128     __proto__: WebInspector.Object.prototype
129 }
130
131 WebInspector.console = new WebInspector.Console();