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 #if ENABLE(JAVASCRIPT_DEBUGGER) 35 #include <profiler/Profile.h> 36 #endif 37 38 #include <wtf/RefCounted.h> 39 #include <wtf/PassRefPtr.h> 40 41 namespace WebCore { 42 43 #if ENABLE(JAVASCRIPT_DEBUGGER) 44 typedef Vector<RefPtr<JSC::Profile> > ProfilesArray; 45 #endif 46 47 class Frame; 48 class Page; 49 class String; 50 class ScriptCallStack; 51 52 // Keep in sync with inspector/front-end/Console.js 53 enum MessageSource { 54 HTMLMessageSource, 55 WMLMessageSource, 56 XMLMessageSource, 57 JSMessageSource, 58 CSSMessageSource, 59 OtherMessageSource 60 }; 61 62 enum MessageType { 63 LogMessageType, 64 ObjectMessageType, 65 TraceMessageType, 66 StartGroupMessageType, 67 EndGroupMessageType 68 }; 69 70 enum MessageLevel { 71 TipMessageLevel, 72 LogMessageLevel, 73 WarningMessageLevel, 74 ErrorMessageLevel 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 #if ENABLE(WML) 97 String lastWMLErrorMessage() const; 98 #endif 99 #if ENABLE(JAVASCRIPT_DEBUGGER) 100 void profile(const JSC::UString&, ScriptCallStack*); 101 void profileEnd(const JSC::UString&, ScriptCallStack*); 102 #endif 103 void time(const String&); 104 void timeEnd(const String&, ScriptCallStack*); 105 void group(ScriptCallStack*); 106 void groupEnd(); 107 108 static bool shouldPrintExceptions(); 109 static void setShouldPrintExceptions(bool); 110 111 #if ENABLE(JAVASCRIPT_DEBUGGER) profiles()112 const ProfilesArray& profiles() const { return m_profiles; } 113 #endif 114 115 private: 116 inline Page* page() const; 117 void addMessage(MessageType, MessageLevel, ScriptCallStack*, bool acceptNoArguments = false); 118 119 Console(Frame*); 120 121 Frame* m_frame; 122 #if ENABLE(JAVASCRIPT_DEBUGGER) 123 ProfilesArray m_profiles; 124 #endif 125 }; 126 127 } // namespace WebCore 128 129 #endif // Console_h 130