Commit 92cfa90a authored by aroben@apple.com's avatar aroben@apple.com

Change calls to Chrome::addMessageToConsole to use Console::addMessage

        Part of Bug 17228: console.{log,warn,info,error} should support format
        strings, variable arguments
        <http://bugs.webkit.org/show_bug.cgi?id=17228>
        <rdar://problem/5732828>

        Console now takes care of calling ChromeClient::addMessageToConsole
        for the appropriate messages (i.e., just messages from JavaScript). If
        you ever want to add a message to the console, Console is the place to
        do it.

        Reviewed by Darin Adler.

        * WebCore.xcodeproj/project.pbxproj: Mark Console.h Private.
        * page/Chrome.cpp: Removed addMessageToConsole
        * page/Chrome.h: Moved MessageSource/MessageLevel to Console.h.
        * page/Console.cpp:
        (WebCore::Console::addMessage): Added. Calls
        ChromeClient::addMessageToConsole for JS messages, and calls
        InspectorController::addMessageToConsole for all messages.
        (WebCore::Console::error): Changed to call directly to
        InspectorController in addition to ChromeClient.
        (WebCore::Console::info): Ditto.
        (WebCore::Console::log): Ditto.
        (WebCore::Console::warn): Ditto.
        * page/Console.h: Added MessageSource/MessageLevel enums from Chrome.h.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31951 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent a63db323
2008-04-15 Adam Roben <aroben@apple.com>
Change calls to Chrome::addMessageToConsole to use Console::addMessage
Part of Bug 17228: console.{log,warn,info,error} should support format
strings, variable arguments
<http://bugs.webkit.org/show_bug.cgi?id=17228>
<rdar://problem/5732828>
Console now takes care of calling ChromeClient::addMessageToConsole
for the appropriate messages (i.e., just messages from JavaScript). If
you ever want to add a message to the console, Console is the place to
do it.
Reviewed by Darin Adler.
* WebCore.xcodeproj/project.pbxproj: Mark Console.h Private.
* page/Chrome.cpp: Removed addMessageToConsole
* page/Chrome.h: Moved MessageSource/MessageLevel to Console.h.
* page/Console.cpp:
(WebCore::Console::addMessage): Added. Calls
ChromeClient::addMessageToConsole for JS messages, and calls
InspectorController::addMessageToConsole for all messages.
(WebCore::Console::error): Changed to call directly to
InspectorController in addition to ChromeClient.
(WebCore::Console::info): Ditto.
(WebCore::Console::log): Ditto.
(WebCore::Console::warn): Ditto.
* page/Console.h: Added MessageSource/MessageLevel enums from Chrome.h.
2008-04-15 Adam Roben <aroben@apple.com>
Pass JSConsole's arguments unmodified to Console
......@@ -3531,7 +3531,7 @@
BC06EE050BFD71AA00856E9D /* JSHTMLTableElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BC06EE030BFD71AA00856E9D /* JSHTMLTableElement.h */; };
BC073BAA0C399B1F000F5979 /* FloatConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = BC073BA90C399B1F000F5979 /* FloatConversion.h */; };
BC0B36A40CD3C67C00AC7EB5 /* Console.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC0B36A10CD3C67C00AC7EB5 /* Console.cpp */; };
BC0B36A50CD3C67C00AC7EB5 /* Console.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0B36A20CD3C67C00AC7EB5 /* Console.h */; };
BC0B36A50CD3C67C00AC7EB5 /* Console.h in Headers */ = {isa = PBXBuildFile; fileRef = BC0B36A20CD3C67C00AC7EB5 /* Console.h */; settings = {ATTRIBUTES = (Private, ); }; };
BC124EE70C2641CD009E2349 /* BarInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC124EE40C2641CD009E2349 /* BarInfo.cpp */; };
BC124EE80C2641CD009E2349 /* BarInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = BC124EE50C2641CD009E2349 /* BarInfo.h */; };
BC124EFF0C26447A009E2349 /* JSBarInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC124EFD0C26447A009E2349 /* JSBarInfo.cpp */; };
......@@ -30,11 +30,12 @@
#include "JSCustomSQLStatementCallback.h"
#include "CString.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "kjs_proxy.h"
#include "JSSQLResultSet.h"
#include "JSSQLTransaction.h"
#include "Page.h"
namespace WebCore {
......@@ -92,8 +93,7 @@ void JSCustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLR
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("SQLStatementCallback: %s\n", message.utf8().data());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
raisedException = true;
......
......@@ -30,11 +30,12 @@
#include "JSCustomSQLStatementErrorCallback.h"
#include "CString.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "kjs_proxy.h"
#include "JSSQLError.h"
#include "JSSQLTransaction.h"
#include "Page.h"
namespace WebCore {
......@@ -93,8 +94,7 @@ bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction,
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("SQLStatementErrorCallback: %s\n", message.utf8().data());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
// The spec says:
......
......@@ -30,6 +30,8 @@
#include "JSCustomSQLTransactionCallback.h"
#include "CString.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "Logging.h"
#include "kjs_proxy.h"
......@@ -144,8 +146,7 @@ void JSCustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bo
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("SQLTransactionCallback: %s\n", message.utf8().data());
if (Page* page = m_data->frame()->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
m_data->frame()->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
raisedException = true;
......
......@@ -30,10 +30,11 @@
#include "JSCustomSQLTransactionErrorCallback.h"
#include "CString.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "kjs_proxy.h"
#include "JSSQLError.h"
#include "Page.h"
namespace WebCore {
......@@ -91,8 +92,7 @@ bool JSCustomSQLTransactionErrorCallback::handleEvent(SQLError* error)
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("SQLTransactionErrorCallback: %s\n", message.utf8().data());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
}
......
......@@ -30,10 +30,10 @@
#include "JSCustomVoidCallback.h"
#include "CString.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Frame.h"
#include "JSDOMWindow.h"
#include "Page.h"
#include "kjs_binding.h"
#include "kjs_proxy.h"
......@@ -91,8 +91,7 @@ void JSCustomVoidCallback::handleEvent()
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("VoidCallback: %s\n", message.utf8().data());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
}
......
......@@ -29,12 +29,12 @@
#if ENABLE(XPATH)
#include "CString.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Document.h"
#include "ExceptionCode.h"
#include "Frame.h"
#include "JSDOMWindow.h"
#include "Page.h"
#include "kjs_binding.h"
#include "kjs_proxy.h"
......@@ -90,8 +90,7 @@ String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
if (!lookupNamespaceURIFunc && !m_customResolver->implementsCall()) {
// FIXME: pass actual line number and source URL.
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String());
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String());
return String();
}
......@@ -116,8 +115,7 @@ String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("XPathNSResolver: %s\n", message.utf8().data());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
} else {
if (!retval->isUndefinedOrNull())
......
......@@ -25,7 +25,7 @@
#include "Base64.h"
#include "CString.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Element.h"
#include "EventListener.h"
......@@ -843,8 +843,7 @@ void JSDOMWindowBase::printErrorMessage(const String& message) const
if (Interpreter::shouldPrintExceptions())
printf("%s", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, 1, String()); // FIXME: provide a real line number and source URL.
frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, 1, String()); // FIXME: provide a real line number and source URL.
}
ExecState* JSDOMWindowBase::globalExec()
......
......@@ -24,13 +24,12 @@
#include "ScheduledAction.h"
#include "CString.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "JSDOMWindow.h"
#include "Page.h"
#include "kjs_proxy.h"
using namespace KJS;
......@@ -81,8 +80,7 @@ void ScheduledAction::execute(JSDOMWindowWrapper* windowWrapper)
int lineNumber = exception->get(exec, "line")->toInt32(exec);
if (Interpreter::shouldPrintExceptions())
printf("(timer):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
}
}
} else
......
......@@ -21,7 +21,7 @@
#include "kjs_events.h"
#include "CString.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Event.h"
......@@ -31,7 +31,6 @@
#include "JSDOMWindow.h"
#include "JSEvent.h"
#include "JSEventTargetNode.h"
#include "Page.h"
#include "kjs_proxy.h"
#include <kjs/function_object.h>
......@@ -110,8 +109,7 @@ void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
if (Interpreter::shouldPrintExceptions())
printf("(event handler):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
} else {
if (!retval->isUndefinedOrNull() && event->storesResultAsString())
......
......@@ -21,7 +21,8 @@
#include "config.h"
#include "kjs_proxy.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Event.h"
#include "EventNames.h"
......@@ -95,8 +96,7 @@ JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String&
UString errorMessage = comp.value()->toString(exec);
int lineNumber = comp.value()->toObject(exec)->get(exec, "line")->toInt32(exec);
UString sourceURL = comp.value()->toObject(exec)->get(exec, "sourceURL")->toString(exec);
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
m_frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
}
m_processingInlineCode = false;
......
......@@ -28,6 +28,8 @@
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
#include "Comment.h"
#include "Console.h"
#include "DOMWindow.h"
#include "DocumentFragment.h"
#include "DocumentType.h"
#include "Frame.h"
......@@ -48,7 +50,6 @@
#include "HTMLTableSectionElement.h"
#include "HTMLTokenizer.h"
#include "LocalizedStrings.h"
#include "Page.h"
#include "Settings.h"
#include "Text.h"
......@@ -1454,10 +1455,6 @@ void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const Atomi
if (!frame)
return;
Page* page = frame->page();
if (!page)
return;
HTMLTokenizer* htmlTokenizer = static_cast<HTMLTokenizer*>(document->tokenizer());
int lineNumber = htmlTokenizer->lineNumber() + 1;
......@@ -1491,7 +1488,7 @@ void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const Atomi
message.replace("%tag1", tag1);
message.replace("%tag2", tag2);
page->chrome()->addMessageToConsole(HTMLMessageSource,
frame->domWindow()->console()->addMessage(HTMLMessageSource,
isWarning(errorCode) ? WarningMessageLevel : ErrorMessageLevel,
message, lineNumber, document->url().string());
}
......
......@@ -104,14 +104,14 @@ CachedResource* Cache::requestResource(DocLoader* docLoader, CachedResource::Typ
if (FrameLoader::restrictAccessToLocal() && !FrameLoader::canLoad(*resource, docLoader->doc())) {
Document* doc = docLoader->doc();
if(doc && !isPreload)
FrameLoader::reportLocalLoadFailed(doc->page(), resource->url());
FrameLoader::reportLocalLoadFailed(doc->frame(), resource->url());
return 0;
}
} else {
if (FrameLoader::restrictAccessToLocal() && !FrameLoader::canLoad(url, docLoader->doc())) {
Document* doc = docLoader->doc();
if(doc && !isPreload)
FrameLoader::reportLocalLoadFailed(doc->page(), url.string());
FrameLoader::reportLocalLoadFailed(doc->frame(), url.string());
return 0;
}
......
......@@ -37,6 +37,7 @@
#include "CachedPage.h"
#include "Chrome.h"
#include "DOMImplementation.h"
#include "DOMWindow.h"
#include "DocLoader.h"
#include "Document.h"
#include "DocumentLoader.h"
......@@ -461,7 +462,7 @@ Frame* FrameLoader::loadSubframe(HTMLFrameOwnerElement* ownerElement, const KURL
}
if (!canLoad(url, referrer)) {
FrameLoader::reportLocalLoadFailed(m_frame->page(), url.string());
FrameLoader::reportLocalLoadFailed(m_frame, url.string());
return 0;
}
......@@ -1711,7 +1712,7 @@ bool FrameLoader::loadPlugin(RenderPart* renderer, const KURL& url, const String
pluginElement = static_cast<Element*>(renderer->node());
if (!canLoad(url, frame()->document())) {
FrameLoader::reportLocalLoadFailed(m_frame->page(), url.string());
FrameLoader::reportLocalLoadFailed(m_frame, url.string());
return false;
}
......@@ -2035,7 +2036,7 @@ void FrameLoader::load(const FrameLoadRequest& request, bool lockHistory, bool u
ASSERT(frame()->document());
if (url.protocolIs("file")) {
if (!canLoad(url, frame()->document()) && !canLoad(url, referrer)) {
FrameLoader::reportLocalLoadFailed(m_frame->page(), url.string());
FrameLoader::reportLocalLoadFailed(m_frame, url.string());
return;
}
}
......@@ -2250,11 +2251,13 @@ bool FrameLoader::canLoad(const CachedResource& resource, const Document* doc)
return doc && doc->isAllowedToLoadLocalResources();
}
void FrameLoader::reportLocalLoadFailed(const Page* page, const String& url)
void FrameLoader::reportLocalLoadFailed(Frame* frame, const String& url)
{
ASSERT(!url.isEmpty());
if (page)
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Not allowed to load local resource: " + url, 0, String());
if (!frame)
return;
frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "Not allowed to load local resource: " + url, 0, String());
}
bool FrameLoader::shouldHideReferrer(const KURL& url, const String& referrer)
......@@ -2447,8 +2450,7 @@ bool FrameLoader::shouldAllowNavigation(Frame* targetFrame) const
printf("%s", message.utf8().data());
// FIXME: should we print to the console of the activeFrame as well?
if (Page* page = targetFrame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, 1, String());
targetFrame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, 1, String());
}
return false;
......
......@@ -165,7 +165,7 @@ namespace WebCore {
static bool canLoad(const KURL&, const String& referrer);
static bool canLoad(const KURL&, const Document*);
static bool canLoad(const CachedResource&, const Document*);
static void reportLocalLoadFailed(const Page*, const String& url);
static void reportLocalLoadFailed(Frame*, const String& url);
static bool shouldHideReferrer(const KURL& url, const String& referrer);
......
......@@ -96,7 +96,7 @@ PassRefPtr<SubresourceLoader> SubresourceLoader::create(Frame* frame, Subresourc
if (!skipCanLoadCheck
&& FrameLoader::restrictAccessToLocal()
&& !FrameLoader::canLoad(request.url(), frame->document())) {
FrameLoader::reportLocalLoadFailed(frame->page(), request.url().string());
FrameLoader::reportLocalLoadFailed(frame, request.url().string());
return 0;
}
......
......@@ -30,7 +30,6 @@
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "InspectorController.h"
#include "JSDOMWindow.h"
#include "Page.h"
#include "PageGroup.h"
......@@ -193,14 +192,6 @@ void Chrome::setResizable(bool b) const
m_client->setResizable(b);
}
void Chrome::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID)
{
if (source == JSMessageSource)
m_client->addMessageToConsole(message, lineNumber, sourceID);
m_page->inspectorController()->addMessageToConsole(source, level, message, lineNumber, sourceID);
}
bool Chrome::canRunBeforeUnloadConfirmPanel()
{
return m_client->canRunBeforeUnloadConfirmPanel();
......
......@@ -46,21 +46,6 @@ namespace WebCore {
struct FrameLoadRequest;
struct WindowFeatures;
enum MessageSource {
HTMLMessageSource,
XMLMessageSource,
JSMessageSource,
CSSMessageSource,
OtherMessageSource
};
enum MessageLevel {
TipMessageLevel,
LogMessageLevel,
WarningMessageLevel,
ErrorMessageLevel
};
class Chrome : Noncopyable {
public:
Chrome(Page*, ChromeClient*);
......@@ -102,8 +87,6 @@ namespace WebCore {
void setResizable(bool) const;
void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID);
bool canRunBeforeUnloadConfirmPanel();
bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame);
......
......@@ -29,9 +29,10 @@
#include "config.h"
#include "Console.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "InspectorController.h"
#include "Page.h"
#include "PlatformString.h"
#include <kjs/list.h>
......@@ -50,6 +51,21 @@ void Console::disconnectFrame()
m_frame = 0;
}
void Console::addMessage(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceURL)
{
if (!m_frame)
return;
Page* page = m_frame->page();
if (!page)
return;
if (source == JSMessageSource)
page->chrome()->client()->addMessageToConsole(message, lineNumber, sourceURL);
page->inspectorController()->addMessageToConsole(source, level, message, lineNumber, sourceURL);
}
void Console::error(ExecState* exec, const List& arguments)
{
if (arguments.isEmpty())
......@@ -62,7 +78,11 @@ void Console::error(ExecState* exec, const List& arguments)
if (!page)
return;
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, arguments[0]->toString(exec), 0, m_frame->loader()->url().prettyURL());
String message = arguments[0]->toString(exec);
String url = m_frame->loader()->url().prettyURL();
page->chrome()->client()->addMessageToConsole(message, 0, url);
page->inspectorController()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, 0, url);
}
void Console::info(ExecState* exec, const List& arguments)
......@@ -77,7 +97,11 @@ void Console::info(ExecState* exec, const List& arguments)
if (!page)
return;
page->chrome()->addMessageToConsole(JSMessageSource, LogMessageLevel, arguments[0]->toString(exec), 0, m_frame->loader()->url().prettyURL());
String message = arguments[0]->toString(exec);
String url = m_frame->loader()->url().prettyURL();
page->chrome()->client()->addMessageToConsole(message, 0, url);
page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, message, 0, url);
}
void Console::log(ExecState* exec, const List& arguments)
......@@ -92,7 +116,11 @@ void Console::log(ExecState* exec, const List& arguments)
if (!page)
return;
page->chrome()->addMessageToConsole(JSMessageSource, LogMessageLevel, arguments[0]->toString(exec), 0, m_frame->loader()->url().prettyURL());
String message = arguments[0]->toString(exec);
String url = m_frame->loader()->url().prettyURL();
page->chrome()->client()->addMessageToConsole(message, 0, url);
page->inspectorController()->addMessageToConsole(JSMessageSource, LogMessageLevel, message, 0, url);
}
void Console::warn(ExecState* exec, const List& arguments)
......@@ -107,7 +135,11 @@ void Console::warn(ExecState* exec, const List& arguments)
if (!page)
return;
page->chrome()->addMessageToConsole(JSMessageSource, WarningMessageLevel, arguments[0]->toString(exec), 0, m_frame->loader()->url().prettyURL());
String message = arguments[0]->toString(exec);
String url = m_frame->loader()->url().prettyURL();
page->chrome()->client()->addMessageToConsole(message, 0, url);
page->inspectorController()->addMessageToConsole(JSMessageSource, WarningMessageLevel, message, 0, url);
}
} // namespace WebCore
......@@ -41,6 +41,22 @@ namespace KJS {
namespace WebCore {
class Frame;
class String;
enum MessageSource {
HTMLMessageSource,
XMLMessageSource,
JSMessageSource,
CSSMessageSource,
OtherMessageSource
};
enum MessageLevel {
TipMessageLevel,
LogMessageLevel,
WarningMessageLevel,
ErrorMessageLevel
};
class Console : public RefCounted<Console> {
public:
......@@ -48,6 +64,8 @@ namespace WebCore {
void disconnectFrame();
void addMessage(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceURL);
void error(KJS::ExecState*, const KJS::List& arguments);
void info(KJS::ExecState*, const KJS::List& arguments);
void log(KJS::ExecState*, const KJS::List& arguments);
......
......@@ -31,6 +31,8 @@
#include "CString.h"
#include "CachedResource.h"
#include "Console.h"
#include "DOMWindow.h"
#include "DocLoader.h"
#include "Document.h"
#include "DocumentLoader.h"
......@@ -1982,7 +1984,7 @@ bool InspectorController::handleException(JSValueRef exception, unsigned lineNum
JSRetainPtr<JSStringRef> messageString(Adopt, JSValueToStringCopy(m_scriptContext, exception, 0));
String message(JSStringGetCharactersPtr(messageString.get()), JSStringGetLength(messageString.get()));
m_page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, __FILE__);
m_page->mainFrame()->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, lineNumber, __FILE__);
return true;
}
......
......@@ -29,7 +29,7 @@
#ifndef InspectorController_h
#define InspectorController_h
#include "Chrome.h"
#include "Console.h"
#include <JavaScriptCore/JSContextRef.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
......@@ -46,6 +46,7 @@ class DocumentLoader;
class GraphicsContext;
class InspectorClient;
class Node;
class Page;
class ResourceResponse;
class ResourceError;
class SharedBuffer;
......
......@@ -27,7 +27,8 @@
#include "SVGDocumentExtensions.h"
#include "AtomicString.h"
#include "Chrome.h"
#include "Console.h"
#include "DOMWindow.h"
#include "Document.h"