PageNetworkAgent.cpp [plain text]
#include "config.h"
#include "PageNetworkAgent.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "Page.h"
#include "ScriptState.h"
#include "WebSocket.h"
#include "WebSocketChannel.h"
namespace WebCore {
using namespace Inspector;
PageNetworkAgent::PageNetworkAgent(PageAgentContext& context, InspectorPageAgent* pageAgent)
: InspectorNetworkAgent(context)
, m_pageAgent(pageAgent)
{
ASSERT(m_pageAgent);
}
String PageNetworkAgent::loaderIdentifier(DocumentLoader* loader)
{
return m_pageAgent->loaderId(loader);
}
String PageNetworkAgent::frameIdentifier(DocumentLoader* loader)
{
if (!loader)
return { };
return m_pageAgent->frameId(loader->frame());
}
Vector<WebSocket*> PageNetworkAgent::activeWebSockets(const LockHolder& lock)
{
Vector<WebSocket*> webSockets;
for (WebSocket* webSocket : WebSocket::allActiveWebSockets(lock)) {
if (!is<WebSocketChannel>(webSocket->channel().get()))
continue;
auto* channel = downcast<WebSocketChannel>(webSocket->channel().get());
if (!channel)
continue;
if (!is<Document>(webSocket->scriptExecutionContext()))
continue;
auto* document = downcast<Document>(webSocket->scriptExecutionContext());
if (document->page() != &m_pageAgent->page())
continue;
webSockets.append(webSocket);
}
return webSockets;
}
void PageNetworkAgent::setResourceCachingDisabled(bool disabled)
{
m_pageAgent->page().setResourceCachingDisabledOverride(disabled);
}
ScriptExecutionContext* PageNetworkAgent::scriptExecutionContext(ErrorString& errorString, const String& frameId)
{
auto* frame = m_pageAgent->assertFrame(errorString, frameId);
if (!frame)
return nullptr;
auto* document = frame->document();
if (!document) {
errorString = "No Document instance for the specified frame"_s;
return nullptr;
}
return document;
}
}