2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
32 #include "ChromeClient.h"
34 #include "FrameLoader.h"
35 #include "FrameTree.h"
36 #include "InspectorController.h"
38 #include "PageGroup.h"
39 #include "PlatformString.h"
41 #include <profiler/Profiler.h>
47 Console::Console(Frame* frame)
52 void Console::disconnectFrame()
57 void Console::addMessage(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
62 Page* page = m_frame->page();
66 if (source == JSMessageSource)
67 page->chrome()->client()->addMessageToConsole(message, lineNumber, sourceURL);
69 page->inspectorController()->addMessageToConsole(source, level, message, lineNumber, sourceURL);
72 void Console::error(ExecState* exec, const List& arguments)
74 if (arguments.isEmpty())
80 Page* page = m_frame->page();
84 String message = arguments[0]->toString(exec);
85 String url = m_frame->loader()->url().prettyURL();
87 page->chrome()->client()->addMessageToConsole(message, 0, url);
88 page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, exec, arguments, 0, url);
91 void Console::info(ExecState* exec, const List& arguments)
93 if (arguments.isEmpty())
99 Page* page = m_frame->page();
103 String message = arguments[0]->toString(exec);
104 String url = m_frame->loader()->url().prettyURL();
106 page->chrome()->client()->addMessageToConsole(message, 0, url);
107 page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, arguments, 0, url);
110 void Console::log(ExecState* exec, const List& arguments)
112 if (arguments.isEmpty())
118 Page* page = m_frame->page();
122 String message = arguments[0]->toString(exec);
123 String url = m_frame->loader()->url().prettyURL();
125 page->chrome()->client()->addMessageToConsole(message, 0, url);
126 page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, exec, arguments, 0, url);
129 void Console::profile(const String& /*title*/) const
131 // FIXME: Figure out something to do with the title passed in so that it can
132 // be displayed by the inspector.
133 Page* page = m_frame->page();
137 Profiler::profiler()->startProfiling(page->group().identifier());
140 void Console::profileEnd() const
142 Profiler::profiler()->stopProfiling();
143 // FIXME: We need to hook into the WebInspector here so that it can process over the data
144 // that is in the profiler and display it in some new cool way, as opposed to just printing
145 // it or dumping it to the console.
148 void Console::warn(ExecState* exec, const List& arguments)
150 if (arguments.isEmpty())
156 Page* page = m_frame->page();
160 String message = arguments[0]->toString(exec);
161 String url = m_frame->loader()->url().prettyURL();
163 page->chrome()->client()->addMessageToConsole(message, 0, url);
164 page->inspectorController()->addMessageToConsole(JSMessageSource, WarningMessageLevel, exec, arguments, 0, url);
167 } // namespace WebCore