WebConsoleAgent.cpp [plain text]
#include "config.h"
#include "WebConsoleAgent.h"
#if ENABLE(INSPECTOR)
#include "CommandLineAPIHost.h"
#include "DOMWindow.h"
#include "ResourceError.h"
#include "ResourceResponse.h"
#include "ScriptState.h"
#include "WebInjectedScriptManager.h"
#include <inspector/ConsoleMessage.h>
#include <runtime/JSCInlines.h>
#include <wtf/text/StringBuilder.h>
using namespace Inspector;
namespace WebCore {
WebConsoleAgent::WebConsoleAgent(WebInjectedScriptManager* injectedScriptManager)
: InspectorConsoleAgent(injectedScriptManager)
, m_monitoringXHREnabled(false)
{
}
void WebConsoleAgent::setMonitoringXHREnabled(ErrorString*, bool enabled)
{
m_monitoringXHREnabled = enabled;
}
void WebConsoleAgent::frameWindowDiscarded(DOMWindow* window)
{
size_t messageCount = m_consoleMessages.size();
for (size_t i = 0; i < messageCount; ++i) {
JSC::ExecState* exec = m_consoleMessages[i]->scriptState();
if (!exec)
continue;
if (domWindowFromExecState(exec) != window)
continue;
m_consoleMessages[i]->clear();
}
static_cast<WebInjectedScriptManager*>(m_injectedScriptManager)->discardInjectedScriptsFor(window);
}
void WebConsoleAgent::didFinishXHRLoading(unsigned long requestIdentifier, const String& url, const String& sendURL, unsigned sendLineNumber, unsigned sendColumnNumber)
{
if (!m_injectedScriptManager->inspectorEnvironment().developerExtrasEnabled())
return;
if (m_frontendDispatcher && m_monitoringXHREnabled) {
String message = "XHR finished loading: \"" + url + "\".";
addMessageToConsole(MessageSource::Network, MessageType::Log, MessageLevel::Debug, message, sendURL, sendLineNumber, sendColumnNumber, nullptr, requestIdentifier);
}
}
void WebConsoleAgent::didReceiveResponse(unsigned long requestIdentifier, const ResourceResponse& response)
{
if (!m_injectedScriptManager->inspectorEnvironment().developerExtrasEnabled())
return;
if (response.httpStatusCode() >= 400) {
String message = "Failed to load resource: the server responded with a status of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusText() + ')';
addMessageToConsole(MessageSource::Network, MessageType::Log, MessageLevel::Error, message, response.url().string(), 0, 0, nullptr, requestIdentifier);
}
}
void WebConsoleAgent::didFailLoading(unsigned long requestIdentifier, const ResourceError& error)
{
if (!m_injectedScriptManager->inspectorEnvironment().developerExtrasEnabled())
return;
if (error.isCancellation())
return;
StringBuilder message;
message.appendLiteral("Failed to load resource");
if (!error.localizedDescription().isEmpty()) {
message.appendLiteral(": ");
message.append(error.localizedDescription());
}
addMessageToConsole(MessageSource::Network, MessageType::Log, MessageLevel::Error, message.toString(), error.failingURL(), 0, 0, nullptr, requestIdentifier);
}
}
#endif // ENABLE(INSPECTOR)