WebConsoleAgent.cpp [plain text]
#include "config.h"
#include "WebConsoleAgent.h"
#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(AgentContext& context, InspectorHeapAgent* heapAgent)
: InspectorConsoleAgent(context, heapAgent)
{
}
void WebConsoleAgent::setMonitoringXHREnabled(ErrorString&, bool enabled)
{
m_monitoringXHREnabled = enabled;
}
void WebConsoleAgent::frameWindowDiscarded(DOMWindow* window)
{
for (auto& message : m_consoleMessages) {
JSC::ExecState* exec = message->scriptState();
if (!exec)
continue;
if (domWindowFromExecState(exec) != window)
continue;
message->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_monitoringXHREnabled) {
String message = "XHR finished loading: \"" + url + "\".";
addMessageToConsole(std::make_unique<ConsoleMessage>(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(std::make_unique<ConsoleMessage>(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(std::make_unique<ConsoleMessage>(MessageSource::Network, MessageType::Log, MessageLevel::Error, message.toString(), error.failingURL(), 0, 0, nullptr, requestIdentifier));
}
}