~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/webkit/WebCore/page/Console.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include "config.h"
30
30
#include "Console.h"
31
31
 
 
32
#include "CString.h"
32
33
#include "ChromeClient.h"
33
 
#include "CString.h"
 
34
#include "ConsoleMessage.h"
34
35
#include "Frame.h"
35
36
#include "FrameLoader.h"
36
37
#include "FrameTree.h"
39
40
#include "PageGroup.h"
40
41
#include "PlatformString.h"
41
42
 
42
 
#if USE(JSC)
 
43
#if ENABLE(JAVASCRIPT_DEBUGGER)
43
44
#include <profiler/Profiler.h>
44
45
#endif
45
46
 
53
54
{
54
55
}
55
56
 
 
57
Frame* Console::frame() const
 
58
{
 
59
    return m_frame;
 
60
}
 
61
 
56
62
void Console::disconnectFrame()
57
63
{
58
64
    m_frame = 0;
68
74
    }
69
75
}
70
76
 
71
 
static bool getFirstArgumentAsString(const ScriptCallFrame& callFrame, String& result, bool checkForNullOrUndefined = false)
 
77
static bool getFirstArgumentAsString(ScriptState* scriptState, const ScriptCallFrame& callFrame, String& result, bool checkForNullOrUndefined = false)
72
78
{
73
79
    if (!callFrame.argumentCount())
74
80
        return false;
77
83
    if (checkForNullOrUndefined && (value.isNull() || value.isUndefined()))
78
84
        return false;
79
85
 
80
 
    return value.getString(result);
 
86
    result = value.toString(scriptState);
 
87
    return true;
81
88
}
82
89
 
83
90
static void printMessageSourceAndLevelPrefix(MessageSource source, MessageLevel level)
84
91
{
85
92
    const char* sourceString;
86
93
    switch (source) {
87
 
        case HTMLMessageSource:
88
 
            sourceString = "HTML";
89
 
            break;
90
 
        case WMLMessageSource:
91
 
            sourceString = "WML";
92
 
            break;
93
 
        case XMLMessageSource:
94
 
            sourceString = "XML";
95
 
            break;
96
 
        case JSMessageSource:
97
 
            sourceString = "JS";
98
 
            break;
99
 
        case CSSMessageSource:
100
 
            sourceString = "CSS";
101
 
            break;
102
 
        default:
103
 
            ASSERT_NOT_REACHED();
104
 
            // Fall thru.
105
 
        case OtherMessageSource:
106
 
            sourceString = "OTHER";
107
 
            break;
 
94
    case HTMLMessageSource:
 
95
        sourceString = "HTML";
 
96
        break;
 
97
    case WMLMessageSource:
 
98
        sourceString = "WML";
 
99
        break;
 
100
    case XMLMessageSource:
 
101
        sourceString = "XML";
 
102
        break;
 
103
    case JSMessageSource:
 
104
        sourceString = "JS";
 
105
        break;
 
106
    case CSSMessageSource:
 
107
        sourceString = "CSS";
 
108
        break;
 
109
    case OtherMessageSource:
 
110
        sourceString = "OTHER";
 
111
        break;
 
112
    default:
 
113
        ASSERT_NOT_REACHED();
 
114
        sourceString = "UNKNOWN";
 
115
        break;
108
116
    }
109
117
 
110
118
    const char* levelString;
111
119
    switch (level) {
112
 
        case TipMessageLevel:
113
 
            levelString = "TIP";
114
 
            break;
115
 
        default:
116
 
            ASSERT_NOT_REACHED();
117
 
            // Fall thru.
118
 
        case LogMessageLevel:
119
 
            levelString = "LOG";
120
 
            break;
121
 
        case WarningMessageLevel:
122
 
            levelString = "WARN";
123
 
            break;
124
 
        case ErrorMessageLevel:
125
 
            levelString = "ERROR";
126
 
            break;
 
120
    case TipMessageLevel:
 
121
        levelString = "TIP";
 
122
        break;
 
123
    case LogMessageLevel:
 
124
        levelString = "LOG";
 
125
        break;
 
126
    case WarningMessageLevel:
 
127
        levelString = "WARN";
 
128
        break;
 
129
    case ErrorMessageLevel:
 
130
        levelString = "ERROR";
 
131
        break;
 
132
    case DebugMessageLevel:
 
133
        levelString = "DEBUG";
 
134
        break;
 
135
    default:
 
136
        ASSERT_NOT_REACHED();
 
137
        levelString = "UNKNOWN";
 
138
        break;
127
139
    }
128
140
 
129
141
    printf("%s %s:", sourceString, levelString);
130
142
}
131
143
 
132
 
void Console::addMessage(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
 
144
void Console::addMessage(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
133
145
{
134
146
    Page* page = this->page();
135
147
    if (!page)
136
148
        return;
137
149
 
138
 
    if (source == JSMessageSource || source == WMLMessageSource)
139
 
        page->chrome()->client()->addMessageToConsole(message, lineNumber, sourceURL);
 
150
    if (source == JSMessageSource)
 
151
        page->chrome()->client()->addMessageToConsole(source, type, level, message, lineNumber, sourceURL);
140
152
 
141
 
    page->inspectorController()->addMessageToConsole(source, level, message, lineNumber, sourceURL);
 
153
#if ENABLE(INSPECTOR)
 
154
    page->inspectorController()->addMessageToConsole(source, type, level, message, lineNumber, sourceURL);
 
155
#endif
142
156
 
143
157
    if (!Console::shouldPrintExceptions())
144
158
        return;
149
163
    printf(" %s\n", message.utf8().data());
150
164
}
151
165
 
152
 
void Console::addMessage(MessageLevel level, ScriptCallStack* callStack, bool acceptNoArguments) {
 
166
void Console::addMessage(MessageType type, MessageLevel level, ScriptCallStack* callStack, bool acceptNoArguments)
 
167
{
153
168
    Page* page = this->page();
154
169
    if (!page)
155
170
        return;
160
175
        return;
161
176
 
162
177
    String message;
163
 
    if (getFirstArgumentAsString(lastCaller, message))
164
 
        page->chrome()->client()->addMessageToConsole(message, lastCaller.lineNumber(), lastCaller.sourceURL().prettyURL());
 
178
    if (getFirstArgumentAsString(callStack->state(), lastCaller, message))
 
179
        page->chrome()->client()->addMessageToConsole(JSMessageSource, type, level, message, lastCaller.lineNumber(), lastCaller.sourceURL().prettyURL());
165
180
 
166
 
    page->inspectorController()->addMessageToConsole(JSMessageSource, level, callStack);
 
181
#if ENABLE(INSPECTOR)
 
182
    page->inspectorController()->addMessageToConsole(JSMessageSource, type, level, callStack);
 
183
#endif
167
184
 
168
185
    if (!Console::shouldPrintExceptions())
169
186
        return;
187
204
 
188
205
void Console::error(ScriptCallStack* callStack)
189
206
{
190
 
    addMessage(ErrorMessageLevel, callStack);
 
207
    addMessage(LogMessageType, ErrorMessageLevel, callStack);
191
208
}
192
209
 
193
210
void Console::info(ScriptCallStack* callStack)
197
214
 
198
215
void Console::log(ScriptCallStack* callStack)
199
216
{
200
 
    addMessage(LogMessageLevel, callStack);
 
217
    addMessage(LogMessageType, LogMessageLevel, callStack);
201
218
}
202
219
 
203
220
void Console::dir(ScriptCallStack* callStack)
204
221
{
205
 
    addMessage(ObjectMessageLevel, callStack);
 
222
    addMessage(ObjectMessageType, LogMessageLevel, callStack);
206
223
}
207
224
 
208
225
void Console::dirxml(ScriptCallStack* callStack)
209
226
{
210
 
    addMessage(NodeMessageLevel, callStack);
 
227
    // The standard behavior of our console.log will print the DOM tree for nodes.
 
228
    log(callStack);
211
229
}
212
230
 
213
231
void Console::trace(ScriptCallStack* callStack)
214
232
{
215
 
    addMessage(TraceMessageLevel, callStack, true);
 
233
    addMessage(TraceMessageType, LogMessageLevel, callStack, true);
216
234
 
217
235
    if (!shouldPrintExceptions())
218
236
        return;
230
248
        return;
231
249
 
232
250
    // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=19135> It would be nice to prefix assertion failures with a message like "Assertion failed: ".
233
 
    addMessage(ErrorMessageLevel, callStack, true);
 
251
    addMessage(LogMessageType, ErrorMessageLevel, callStack, true);
234
252
}
235
253
 
236
254
void Console::count(ScriptCallStack* callStack)
237
255
{
 
256
#if ENABLE(INSPECTOR)
238
257
    Page* page = this->page();
239
258
    if (!page)
240
259
        return;
243
262
    // Follow Firebug's behavior of counting with null and undefined title in
244
263
    // the same bucket as no argument
245
264
    String title;
246
 
    getFirstArgumentAsString(lastCaller, title);
 
265
    getFirstArgumentAsString(callStack->state(), lastCaller, title);
247
266
 
248
267
    page->inspectorController()->count(title, lastCaller.lineNumber(), lastCaller.sourceURL().string());
249
 
}
250
 
 
251
 
#if USE(JSC)
 
268
#else
 
269
    UNUSED_PARAM(callStack);
 
270
#endif
 
271
}
 
272
 
 
273
#if ENABLE(WML)
 
274
String Console::lastWMLErrorMessage() const
 
275
{
 
276
    Page* page = this->page();
 
277
    if (!page)
 
278
        return String();
 
279
 
 
280
    const Vector<ConsoleMessage*>& consoleMessages = page->inspectorController()->consoleMessages();
 
281
    if (consoleMessages.isEmpty())
 
282
        return String();
 
283
 
 
284
    Vector<ConsoleMessage*>::const_iterator it = consoleMessages.begin();
 
285
    const Vector<ConsoleMessage*>::const_iterator end = consoleMessages.end();
 
286
 
 
287
    for (; it != end; ++it) {
 
288
        ConsoleMessage* message = *it;
 
289
        if (message->source() != WMLMessageSource)
 
290
            continue;
 
291
 
 
292
        return message->message();
 
293
    }
 
294
 
 
295
    return String();
 
296
}
 
297
#endif
 
298
 
 
299
#if ENABLE(JAVASCRIPT_DEBUGGER)
252
300
 
253
301
void Console::profile(const JSC::UString& title, ScriptCallStack* callStack)
254
302
{
256
304
    if (!page)
257
305
        return;
258
306
 
259
 
    if (title.isNull())
260
 
        return;
261
 
 
 
307
#if ENABLE(INSPECTOR)
 
308
    InspectorController* controller = page->inspectorController();
262
309
    // FIXME: log a console message when profiling is disabled.
263
 
    if (!page->inspectorController()->profilerEnabled())
 
310
    if (!controller->profilerEnabled())
264
311
        return;
265
 
 
266
 
    JSC::Profiler::profiler()->startProfiling(callStack->state(), title);
 
312
#endif
 
313
 
 
314
    JSC::UString resolvedTitle = title;
 
315
    if (title.isNull())   // no title so give it the next user initiated profile title.
 
316
#if ENABLE(INSPECTOR)
 
317
        resolvedTitle = controller->getCurrentUserInitiatedProfileName(true);
 
318
#else
 
319
        resolvedTitle = "";
 
320
#endif
 
321
 
 
322
    JSC::Profiler::profiler()->startProfiling(callStack->state(), resolvedTitle);
 
323
 
 
324
#if ENABLE(INSPECTOR)
 
325
    const ScriptCallFrame& lastCaller = callStack->at(0);
 
326
    controller->addStartProfilingMessageToConsole(resolvedTitle, lastCaller.lineNumber(), lastCaller.sourceURL());
 
327
#endif
267
328
}
268
329
 
269
330
void Console::profileEnd(const JSC::UString& title, ScriptCallStack* callStack)
272
333
    if (!page)
273
334
        return;
274
335
 
275
 
    if (!page->inspectorController()->profilerEnabled())
276
 
        return;
 
336
    if (!this->page())
 
337
        return;
 
338
 
 
339
#if ENABLE(INSPECTOR)
 
340
    InspectorController* controller = page->inspectorController();
 
341
    if (!controller->profilerEnabled())
 
342
        return;
 
343
#endif
277
344
 
278
345
    RefPtr<JSC::Profile> profile = JSC::Profiler::profiler()->stopProfiling(callStack->state(), title);
279
346
    if (!profile)
281
348
 
282
349
    m_profiles.append(profile);
283
350
 
284
 
    if (Page* page = this->page()) {
285
 
        const ScriptCallFrame& lastCaller = callStack->at(0);
286
 
        page->inspectorController()->addProfile(profile, lastCaller.lineNumber(), lastCaller.sourceURL());
287
 
    }
 
351
#if ENABLE(INSPECTOR)
 
352
    const ScriptCallFrame& lastCaller = callStack->at(0);
 
353
    controller->addProfile(profile, lastCaller.lineNumber(), lastCaller.sourceURL());
 
354
#endif
288
355
}
289
356
 
290
357
#endif
291
 
    
 
358
 
292
359
void Console::time(const String& title)
293
360
{
 
361
#if ENABLE(INSPECTOR)
294
362
    Page* page = this->page();
295
363
    if (!page)
296
364
        return;
299
367
    // undefined for timing functions
300
368
    if (title.isNull())
301
369
        return;
302
 
    
 
370
 
303
371
    page->inspectorController()->startTiming(title);
 
372
#else
 
373
    UNUSED_PARAM(title);
 
374
#endif
304
375
}
305
376
 
306
377
void Console::timeEnd(const String& title, ScriptCallStack* callStack)
307
378
{
 
379
#if ENABLE(INSPECTOR)
308
380
    Page* page = this->page();
309
381
    if (!page)
310
382
        return;
321
393
    String message = title + String::format(": %.0fms", elapsed);
322
394
 
323
395
    const ScriptCallFrame& lastCaller = callStack->at(0);
324
 
    page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, message, lastCaller.lineNumber(), lastCaller.sourceURL().string());
 
396
    page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageType, LogMessageLevel, message, lastCaller.lineNumber(), lastCaller.sourceURL().string());
 
397
#else
 
398
    UNUSED_PARAM(title);
 
399
    UNUSED_PARAM(callStack);
 
400
#endif
325
401
}
326
402
 
327
403
void Console::group(ScriptCallStack* callStack)
328
404
{
 
405
#if ENABLE(INSPECTOR)
329
406
    Page* page = this->page();
330
407
    if (!page)
331
408
        return;
332
409
 
333
410
    page->inspectorController()->startGroup(JSMessageSource, callStack);
 
411
#else
 
412
    UNUSED_PARAM(callStack);
 
413
#endif
334
414
}
335
415
 
336
416
void Console::groupEnd()
337
417
{
 
418
#if ENABLE(INSPECTOR)
338
419
    Page* page = this->page();
339
420
    if (!page)
340
421
        return;
341
422
 
342
423
    page->inspectorController()->endGroup(JSMessageSource, 0, String());
 
424
#endif
343
425
}
344
426
 
345
427
void Console::warn(ScriptCallStack* callStack)
346
428
{
347
 
    addMessage(WarningMessageLevel, callStack);
 
429
    addMessage(LogMessageType, WarningMessageLevel, callStack);
348
430
}
349
431
 
350
432
static bool printExceptions = false;