• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef Console_h
30 #define Console_h
31 
32 #include "PlatformString.h"
33 
34 #include "ScriptProfile.h"
35 
36 #include <wtf/PassRefPtr.h>
37 #include <wtf/RefCounted.h>
38 
39 namespace WebCore {
40 
41 #if ENABLE(JAVASCRIPT_DEBUGGER)
42 typedef Vector<RefPtr<ScriptProfile> > ProfilesArray;
43 #endif
44 
45 class Frame;
46 class Page;
47 class String;
48 class ScriptCallStack;
49 
50 // Keep in sync with inspector/front-end/Console.js
51 enum MessageSource {
52     HTMLMessageSource,
53     WMLMessageSource,
54     XMLMessageSource,
55     JSMessageSource,
56     CSSMessageSource,
57     OtherMessageSource
58 };
59 
60 enum MessageType {
61     LogMessageType,
62     ObjectMessageType,
63     TraceMessageType,
64     StartGroupMessageType,
65     EndGroupMessageType,
66     AssertMessageType
67 };
68 
69 enum MessageLevel {
70     TipMessageLevel,
71     LogMessageLevel,
72     WarningMessageLevel,
73     ErrorMessageLevel,
74     DebugMessageLevel
75 };
76 
77 class Console : public RefCounted<Console> {
78 public:
create(Frame * frame)79     static PassRefPtr<Console> create(Frame* frame) { return adoptRef(new Console(frame)); }
80 
81     Frame* frame() const;
82     void disconnectFrame();
83 
84     void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
85 
86     void debug(ScriptCallStack*);
87     void error(ScriptCallStack*);
88     void info(ScriptCallStack*);
89     void log(ScriptCallStack*);
90     void warn(ScriptCallStack*);
91     void dir(ScriptCallStack*);
92     void dirxml(ScriptCallStack*);
93     void trace(ScriptCallStack*);
94     void assertCondition(bool condition, ScriptCallStack*);
95     void count(ScriptCallStack*);
96     void markTimeline(ScriptCallStack*);
97 #if ENABLE(WML)
98     String lastWMLErrorMessage() const;
99 #endif
100 #if ENABLE(JAVASCRIPT_DEBUGGER)
101     void profile(const String&, ScriptCallStack*);
102     void profileEnd(const String&, ScriptCallStack*);
103 #endif
104     void time(const String&);
105     void timeEnd(const String&, ScriptCallStack*);
106     void group(ScriptCallStack*);
107     void groupEnd();
108 
109     static bool shouldPrintExceptions();
110     static void setShouldPrintExceptions(bool);
111 
112 #if ENABLE(JAVASCRIPT_DEBUGGER)
profiles()113     const ProfilesArray& profiles() const { return m_profiles; }
114 #endif
115 
116 private:
117     inline Page* page() const;
118     void addMessage(MessageType, MessageLevel, ScriptCallStack*, bool acceptNoArguments = false);
119 
120     Console(Frame*);
121 
122     Frame* m_frame;
123 #if ENABLE(JAVASCRIPT_DEBUGGER)
124     ProfilesArray m_profiles;
125 #endif
126 };
127 
128 } // namespace WebCore
129 
130 #endif // Console_h
131