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 "MemoryInfo.h" 33 #include "PlatformString.h" 34 #include "ScriptProfile.h" 35 #include "ScriptState.h" 36 37 #include <wtf/Forward.h> 38 #include <wtf/PassRefPtr.h> 39 #include <wtf/RefCounted.h> 40 41 namespace WebCore { 42 43 class ScriptArguments; 44 45 #if ENABLE(JAVASCRIPT_DEBUGGER) 46 typedef Vector<RefPtr<ScriptProfile> > ProfilesArray; 47 #endif 48 49 class Frame; 50 class Page; 51 class ScriptCallStack; 52 53 enum MessageSource { 54 HTMLMessageSource, 55 XMLMessageSource, 56 JSMessageSource, 57 CSSMessageSource, 58 OtherMessageSource 59 }; 60 61 enum MessageType { 62 LogMessageType, 63 ObjectMessageType, 64 TraceMessageType, 65 StartGroupMessageType, 66 StartGroupCollapsedMessageType, 67 EndGroupMessageType, 68 AssertMessageType, 69 UncaughtExceptionMessageType, 70 NetworkErrorMessageType 71 }; 72 73 enum MessageLevel { 74 TipMessageLevel, 75 LogMessageLevel, 76 WarningMessageLevel, 77 ErrorMessageLevel, 78 DebugMessageLevel 79 }; 80 81 class Console : public RefCounted<Console> { 82 public: create(Frame * frame)83 static PassRefPtr<Console> create(Frame* frame) { return adoptRef(new Console(frame)); } 84 85 Frame* frame() const; 86 void disconnectFrame(); 87 88 void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL); 89 void addMessage(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL, PassRefPtr<ScriptCallStack> callStack); 90 91 void debug(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 92 void error(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 93 void info(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 94 void log(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 95 void warn(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 96 void dir(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 97 void dirxml(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 98 void trace(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 99 void assertCondition(bool condition, PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 100 void count(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 101 void markTimeline(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 102 #if ENABLE(JAVASCRIPT_DEBUGGER) profiles()103 const ProfilesArray& profiles() const { return m_profiles; } 104 void profile(const String&, ScriptState*, PassRefPtr<ScriptCallStack>); 105 void profileEnd(const String&, ScriptState*, PassRefPtr<ScriptCallStack>); 106 #endif 107 void time(const String&); 108 void timeEnd(const String&, PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 109 void group(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 110 void groupCollapsed(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>); 111 void groupEnd(); 112 113 bool shouldCaptureFullStackTrace() const; 114 115 static bool shouldPrintExceptions(); 116 static void setShouldPrintExceptions(bool); 117 118 MemoryInfo* memory() const; 119 120 private: 121 inline Page* page() const; 122 void addMessage(MessageType, MessageLevel, PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>, bool acceptNoArguments = false); 123 124 Console(Frame*); 125 126 Frame* m_frame; 127 #if ENABLE(JAVASCRIPT_DEBUGGER) 128 ProfilesArray m_profiles; 129 #endif 130 mutable RefPtr<MemoryInfo> m_memory; 131 }; 132 133 } // namespace WebCore 134 135 #endif // Console_h 136