PageNetworkAgent.cpp [plain text]
#include "config.h"
#include "PageNetworkAgent.h"
#include "CustomHeaderFields.h"
#include "Document.h"
#include "DocumentLoader.h"
#include "Frame.h"
#include "InstrumentingAgents.h"
#include "Page.h"
#include "ScriptState.h"
#include "WebSocket.h"
#include "WebSocketChannel.h"
namespace WebCore {
using namespace Inspector;
PageNetworkAgent::PageNetworkAgent(PageAgentContext& context)
: InspectorNetworkAgent(context)
, m_inspectedPage(context.inspectedPage)
{
}
PageNetworkAgent::~PageNetworkAgent() = default;
String PageNetworkAgent::loaderIdentifier(DocumentLoader* loader)
{
if (loader) {
if (auto* pageAgent = m_instrumentingAgents.inspectorPageAgent())
return pageAgent->loaderId(loader);
}
return { };
}
String PageNetworkAgent::frameIdentifier(DocumentLoader* loader)
{
if (loader) {
if (auto* pageAgent = m_instrumentingAgents.inspectorPageAgent())
return pageAgent->frameId(loader->frame());
}
return { };
}
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 (!channel->hasCreatedHandshake())
continue;
if (!is<Document>(webSocket->scriptExecutionContext()))
continue;
auto* document = downcast<Document>(webSocket->scriptExecutionContext());
if (document->page() != &m_inspectedPage)
continue;
webSockets.append(webSocket);
}
return webSockets;
}
void PageNetworkAgent::setResourceCachingDisabled(bool disabled)
{
m_inspectedPage.setResourceCachingDisabledByWebInspector(disabled);
}
ScriptExecutionContext* PageNetworkAgent::scriptExecutionContext(ErrorString& errorString, const String& frameId)
{
auto* pageAgent = m_instrumentingAgents.inspectorPageAgent();
if (!pageAgent) {
errorString = "Page domain must be enabled"_s;
return nullptr;
}
auto* frame = pageAgent->assertFrame(errorString, frameId);
if (!frame)
return nullptr;
auto* document = frame->document();
if (!document) {
errorString = "Missing frame of docuemnt for given frameId"_s;
return nullptr;
}
return document;
}
}