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