Commit 377f2797 authored by aroben's avatar aroben

Made Chrome::addMessageToConsole more flexible

addMessageToConsole now takes two additional parameters to specify the
message source (HTML, JS, CSS, XML) and level (error, warning, log). To
maintain our old behavior, all current messages were given
JSMessageSource and ErrorMessageLevel parameters. Messages matching
these characteristics are passed up to the ChromeClient.

Reviewed by Hyatt.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21706 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent ec064cb5
2007-05-24 Adam Roben <aroben@apple.com>
Made Chrome::addMessageToConsole more flexible
addMessageToConsole now takes two additional parameters to specify the
message source (HTML, JS, CSS, XML) and level (error, warning, log). To
maintain our old behavior, all current messages were given
JSMessageSource and ErrorMessageLevel parameters. Messages matching
these characteristics are passed up to the ChromeClient.
Reviewed by Hyatt.
* bindings/js/JSCustomXPathNSResolver.cpp:
(WebCore::JSCustomXPathNSResolver::lookupNamespaceURI):
* bindings/js/kjs_events.cpp:
(KJS::JSAbstractEventListener::handleEvent):
* bindings/js/kjs_proxy.cpp:
(WebCore::KJSProxy::evaluate):
* bindings/js/kjs_window.cpp:
(KJS::Window::isSafeScript):
(KJS::ScheduledAction::execute):
* html/HTMLParser.cpp:
(WebCore::HTMLParser::reportErrorToConsole):
* ksvg2/misc/SVGDocumentExtensions.cpp:
(WebCore::SVGDocumentExtensions::reportWarning):
(WebCore::SVGDocumentExtensions::reportError):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::reportLocalLoadFailed):
* page/Chrome.cpp:
(WebCore::Chrome::addMessageToConsole):
* page/Chrome.h:
(WebCore::):
* xml/xmlhttprequest.cpp:
(WebCore::XMLHttpRequest::setRequestHeader):
2007-05-24 David Hyatt <hyatt@apple.com>
Rework how HTML handles line numbering so that it is not fooled by
......@@ -92,7 +92,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("XPathNSResolver does not have a lookupNamespaceURI method.", 0, String());
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String());
return String();
}
......@@ -118,7 +118,7 @@ String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
if (Interpreter::shouldPrintExceptions())
printf("XPathNSResolver: %s\n", message.utf8().data());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(message, lineNumber, sourceURL);
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
} else {
if (!retval->isUndefinedOrNull())
......
......@@ -139,7 +139,7 @@ void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
if (Interpreter::shouldPrintExceptions())
printf("(event handler):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(message, lineNumber, sourceURL);
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
exec->clearException();
} else {
if (!retval->isUndefinedOrNull() && event->storesResultAsString())
......
......@@ -86,7 +86,7 @@ JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String&
int lineNumber = comp.value()->toObject(m_script->globalExec())->get(m_script->globalExec(), "line")->toInt32(m_script->globalExec());
UString sourceURL = comp.value()->toObject(m_script->globalExec())->get(m_script->globalExec(), "sourceURL")->toString(m_script->globalExec());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(errorMessage, lineNumber, sourceURL);
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
}
return 0;
......
......@@ -1262,7 +1262,7 @@ bool Window::isSafeScript(const ScriptInterpreter *origin, const ScriptInterpret
String message = String::format("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
targetDocument->URL().latin1(), originDocument->URL().latin1());
if (Page* page = targetFrame->page())
page->chrome()->addMessageToConsole(message, 1, String()); // FIXME: provide a real line number and source URL.
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, 1, String()); // FIXME: provide a real line number and source URL.
return false;
}
......@@ -1323,7 +1323,7 @@ bool Window::isSafeScript(ExecState *exec) const
String message = String::format("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
thisDocument->URL().latin1(), actDocument->URL().latin1());
if (Page* page = m_frame->page())
page->chrome()->addMessageToConsole(message, 1, String());
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, 1, String());
return false;
}
......@@ -1907,7 +1907,7 @@ void ScheduledAction::execute(Window* window)
if (Interpreter::shouldPrintExceptions())
printf("(timer):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(message, lineNumber, String());
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
}
}
} else
......
......@@ -1443,7 +1443,7 @@ void HTMLParser::reportErrorToConsole(HTMLParserErrorCode errorCode, const Atomi
message.replace("%tag1", tag1);
message.replace("%tag2", tag2);
page->chrome()->addMessageToConsole(message, lineNumber, document->URL());
page->chrome()->addMessageToConsole(HTMLMessageSource, ErrorMessageLevel, message, lineNumber, document->URL());
}
}
......@@ -98,14 +98,14 @@ void SVGDocumentExtensions::reportWarning(const String& message)
{
if (Frame* frame = m_doc->frame())
if (Page* page = frame->page())
page->chrome()->addMessageToConsole("Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
}
void SVGDocumentExtensions::reportError(const String& message)
{
if (Frame* frame = m_doc->frame())
if (Page* page = frame->page())
page->chrome()->addMessageToConsole("Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
}
void SVGDocumentExtensions::addPendingResource(const AtomicString& id, SVGStyledElement* obj)
......
......@@ -2013,7 +2013,7 @@ void FrameLoader::reportLocalLoadFailed(const Page* page, const String& url)
{
ASSERT(!url.isEmpty());
if(page)
page->chrome()->addMessageToConsole("Not allowed to load local resource: " + url, 0, String());
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Not allowed to load local resource: " + url, 0, String());
}
bool FrameLoader::shouldHideReferrer(const KURL& url, const String& referrer)
......
......@@ -25,6 +25,7 @@
#include "ChromeClient.h"
#include "FloatRect.h"
#include "Frame.h"
#include "InspectorController.h"
#include "Page.h"
#include "ResourceHandle.h"
#include <wtf/PassRefPtr.h>
......@@ -187,9 +188,10 @@ void Chrome::setResizable(bool b) const
m_client->setResizable(b);
}
void Chrome::addMessageToConsole(const String &message, unsigned lineNumber, const String &sourceURL)
void Chrome::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID)
{
m_client->addMessageToConsole(message, lineNumber, sourceURL);
if (source == JSMessageSource && level == ErrorMessageLevel)
m_client->addMessageToConsole(message, lineNumber, sourceID);
}
bool Chrome::canRunBeforeUnloadConfirmPanel()
......
......@@ -43,6 +43,19 @@ namespace WebCore {
struct FrameLoadRequest;
enum MessageSource {
HTMLMessageSource,
XMLMessageSource,
JSMessageSource,
CSSMessageSource
};
enum MessageLevel {
LogMessageLevel,
WarningMessageLevel,
ErrorMessageLevel
};
class Chrome {
public:
Chrome(Page*, ChromeClient*);
......@@ -85,7 +98,7 @@ namespace WebCore {
void setResizable(bool) const;
void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID);
void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID);
bool canRunBeforeUnloadConfirmPanel();
bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame);
......
......@@ -499,7 +499,7 @@ void XMLHttpRequest::setRequestHeader(const String& name, const String& value, E
if (!canSetRequestHeader(name)) {
if (m_doc && m_doc->frame() && m_doc->frame()->page())
m_doc->frame()->page()->chrome()->addMessageToConsole("Refused to set unsafe header " + name, 1, String());
m_doc->frame()->page()->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Refused to set unsafe header " + name, 1, String());
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment