summaryrefslogtreecommitdiff
path: root/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp')
-rw-r--r--Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp145
1 files changed, 64 insertions, 81 deletions
diff --git a/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp b/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp
index 2a7a6917b..6e39bcdad 100644
--- a/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp
+++ b/Source/WebCore/inspector/InspectorApplicationCacheAgent.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010, 2015 Apple Inc. All rights reserved.
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,9 +24,6 @@
*/
#include "config.h"
-
-#if ENABLE(INSPECTOR)
-
#include "InspectorApplicationCacheAgent.h"
#include "ApplicationCacheHost.h"
@@ -34,40 +31,36 @@
#include "Frame.h"
#include "FrameLoader.h"
#include "InspectorPageAgent.h"
-#include "InspectorWebFrontendDispatchers.h"
#include "InstrumentingAgents.h"
+#include "MainFrame.h"
#include "NetworkStateNotifier.h"
-#include "Page.h"
-#include "ResourceResponse.h"
#include <inspector/InspectorValues.h>
+#include <wtf/text/StringBuilder.h>
using namespace Inspector;
namespace WebCore {
-InspectorApplicationCacheAgent::InspectorApplicationCacheAgent(InstrumentingAgents* instrumentingAgents, InspectorPageAgent* pageAgent)
- : InspectorAgentBase(ASCIILiteral("ApplicationCache"), instrumentingAgents)
+InspectorApplicationCacheAgent::InspectorApplicationCacheAgent(WebAgentContext& context, InspectorPageAgent* pageAgent)
+ : InspectorAgentBase(ASCIILiteral("ApplicationCache"), context)
+ , m_frontendDispatcher(std::make_unique<Inspector::ApplicationCacheFrontendDispatcher>(context.frontendRouter))
+ , m_backendDispatcher(Inspector::ApplicationCacheBackendDispatcher::create(context.backendDispatcher, this))
, m_pageAgent(pageAgent)
{
}
-void InspectorApplicationCacheAgent::didCreateFrontendAndBackend(Inspector::InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher)
+void InspectorApplicationCacheAgent::didCreateFrontendAndBackend(FrontendRouter*, BackendDispatcher*)
{
- m_frontendDispatcher = std::make_unique<InspectorApplicationCacheFrontendDispatcher>(frontendChannel);
- m_backendDispatcher = InspectorApplicationCacheBackendDispatcher::create(backendDispatcher, this);
}
-void InspectorApplicationCacheAgent::willDestroyFrontendAndBackend(InspectorDisconnectReason)
+void InspectorApplicationCacheAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason)
{
- m_frontendDispatcher = nullptr;
- m_backendDispatcher.clear();
-
- m_instrumentingAgents->setInspectorApplicationCacheAgent(nullptr);
+ m_instrumentingAgents.setInspectorApplicationCacheAgent(nullptr);
}
-void InspectorApplicationCacheAgent::enable(ErrorString*)
+void InspectorApplicationCacheAgent::enable(ErrorString&)
{
- m_instrumentingAgents->setInspectorApplicationCacheAgent(this);
+ m_instrumentingAgents.setInspectorApplicationCacheAgent(this);
// We need to pass initial navigator.onOnline.
networkStateChanged();
@@ -75,16 +68,17 @@ void InspectorApplicationCacheAgent::enable(ErrorString*)
void InspectorApplicationCacheAgent::updateApplicationCacheStatus(Frame* frame)
{
- DocumentLoader* documentLoader = frame->loader().documentLoader();
+ if (!frame)
+ return;
+ auto* documentLoader = frame->loader().documentLoader();
if (!documentLoader)
return;
- ApplicationCacheHost* host = documentLoader->applicationCacheHost();
- ApplicationCacheHost::Status status = host->status();
- ApplicationCacheHost::CacheInfo info = host->applicationCacheInfo();
+ auto& host = documentLoader->applicationCacheHost();
+ int status = host.status();
+ auto manifestURL = host.applicationCacheInfo().manifest.string();
- String manifestURL = info.m_manifest.string();
- m_frontendDispatcher->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, static_cast<int>(status));
+ m_frontendDispatcher->applicationCacheStatusUpdated(m_pageAgent->frameId(frame), manifestURL, status);
}
void InspectorApplicationCacheAgent::networkStateChanged()
@@ -93,30 +87,28 @@ void InspectorApplicationCacheAgent::networkStateChanged()
m_frontendDispatcher->networkStateUpdated(isNowOnline);
}
-void InspectorApplicationCacheAgent::getFramesWithManifests(ErrorString*, RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::ApplicationCache::FrameWithManifest>>& result)
+void InspectorApplicationCacheAgent::getFramesWithManifests(ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::ApplicationCache::FrameWithManifest>>& result)
{
- result = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::ApplicationCache::FrameWithManifest>::create();
+ result = Inspector::Protocol::Array<Inspector::Protocol::ApplicationCache::FrameWithManifest>::create();
- Frame* mainFrame = m_pageAgent->mainFrame();
- for (Frame* frame = mainFrame; frame; frame = frame->tree().traverseNext(mainFrame)) {
- DocumentLoader* documentLoader = frame->loader().documentLoader();
+ for (Frame* frame = &m_pageAgent->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ auto* documentLoader = frame->loader().documentLoader();
if (!documentLoader)
continue;
- ApplicationCacheHost* host = documentLoader->applicationCacheHost();
- ApplicationCacheHost::CacheInfo info = host->applicationCacheInfo();
- String manifestURL = info.m_manifest.string();
+ auto& host = documentLoader->applicationCacheHost();
+ String manifestURL = host.applicationCacheInfo().manifest.string();
if (!manifestURL.isEmpty()) {
- RefPtr<Inspector::TypeBuilder::ApplicationCache::FrameWithManifest> value = Inspector::TypeBuilder::ApplicationCache::FrameWithManifest::create()
+ result->addItem(Inspector::Protocol::ApplicationCache::FrameWithManifest::create()
.setFrameId(m_pageAgent->frameId(frame))
.setManifestURL(manifestURL)
- .setStatus(static_cast<int>(host->status()));
- result->addItem(value);
+ .setStatus(static_cast<int>(host.status()))
+ .release());
}
}
}
-DocumentLoader* InspectorApplicationCacheAgent::assertFrameWithDocumentLoader(ErrorString* errorString, String frameId)
+DocumentLoader* InspectorApplicationCacheAgent::assertFrameWithDocumentLoader(ErrorString& errorString, const String& frameId)
{
Frame* frame = m_pageAgent->assertFrame(errorString, frameId);
if (!frame)
@@ -125,77 +117,68 @@ DocumentLoader* InspectorApplicationCacheAgent::assertFrameWithDocumentLoader(Er
return InspectorPageAgent::assertDocumentLoader(errorString, frame);
}
-void InspectorApplicationCacheAgent::getManifestForFrame(ErrorString* errorString, const String& frameId, String* manifestURL)
+void InspectorApplicationCacheAgent::getManifestForFrame(ErrorString& errorString, const String& frameId, String* manifestURL)
{
DocumentLoader* documentLoader = assertFrameWithDocumentLoader(errorString, frameId);
if (!documentLoader)
return;
- ApplicationCacheHost::CacheInfo info = documentLoader->applicationCacheHost()->applicationCacheInfo();
- *manifestURL = info.m_manifest.string();
+ *manifestURL = documentLoader->applicationCacheHost().applicationCacheInfo().manifest.string();
}
-void InspectorApplicationCacheAgent::getApplicationCacheForFrame(ErrorString* errorString, const String& frameId, RefPtr<Inspector::TypeBuilder::ApplicationCache::ApplicationCache>& applicationCache)
+void InspectorApplicationCacheAgent::getApplicationCacheForFrame(ErrorString& errorString, const String& frameId, RefPtr<Inspector::Protocol::ApplicationCache::ApplicationCache>& applicationCache)
{
- DocumentLoader* documentLoader = assertFrameWithDocumentLoader(errorString, frameId);
+ auto* documentLoader = assertFrameWithDocumentLoader(errorString, frameId);
if (!documentLoader)
return;
- ApplicationCacheHost* host = documentLoader->applicationCacheHost();
- ApplicationCacheHost::CacheInfo info = host->applicationCacheInfo();
-
- ApplicationCacheHost::ResourceInfoList resources;
- host->fillResourceList(&resources);
-
- applicationCache = buildObjectForApplicationCache(resources, info);
+ auto& host = documentLoader->applicationCacheHost();
+ applicationCache = buildObjectForApplicationCache(host.resourceList(), host.applicationCacheInfo());
}
-PassRefPtr<Inspector::TypeBuilder::ApplicationCache::ApplicationCache> InspectorApplicationCacheAgent::buildObjectForApplicationCache(const ApplicationCacheHost::ResourceInfoList& applicationCacheResources, const ApplicationCacheHost::CacheInfo& applicationCacheInfo)
+Ref<Inspector::Protocol::ApplicationCache::ApplicationCache> InspectorApplicationCacheAgent::buildObjectForApplicationCache(const Vector<ApplicationCacheHost::ResourceInfo>& applicationCacheResources, const ApplicationCacheHost::CacheInfo& applicationCacheInfo)
{
- return Inspector::TypeBuilder::ApplicationCache::ApplicationCache::create()
- .setManifestURL(applicationCacheInfo.m_manifest.string())
- .setSize(applicationCacheInfo.m_size)
- .setCreationTime(applicationCacheInfo.m_creationTime)
- .setUpdateTime(applicationCacheInfo.m_updateTime)
+ return Inspector::Protocol::ApplicationCache::ApplicationCache::create()
+ .setManifestURL(applicationCacheInfo.manifest.string())
+ .setSize(applicationCacheInfo.size)
+ .setCreationTime(applicationCacheInfo.creationTime)
+ .setUpdateTime(applicationCacheInfo.updateTime)
.setResources(buildArrayForApplicationCacheResources(applicationCacheResources))
.release();
}
-PassRefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::ApplicationCache::ApplicationCacheResource>> InspectorApplicationCacheAgent::buildArrayForApplicationCacheResources(const ApplicationCacheHost::ResourceInfoList& applicationCacheResources)
+Ref<Inspector::Protocol::Array<Inspector::Protocol::ApplicationCache::ApplicationCacheResource>> InspectorApplicationCacheAgent::buildArrayForApplicationCacheResources(const Vector<ApplicationCacheHost::ResourceInfo>& applicationCacheResources)
{
- RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::ApplicationCache::ApplicationCacheResource>> resources = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::ApplicationCache::ApplicationCacheResource>::create();
-
- for (const auto& resourceInfo : applicationCacheResources)
- resources->addItem(buildObjectForApplicationCacheResource(resourceInfo));
-
- return resources;
+ auto result = Inspector::Protocol::Array<Inspector::Protocol::ApplicationCache::ApplicationCacheResource>::create();
+ for (auto& info : applicationCacheResources)
+ result->addItem(buildObjectForApplicationCacheResource(info));
+ return result;
}
-PassRefPtr<Inspector::TypeBuilder::ApplicationCache::ApplicationCacheResource> InspectorApplicationCacheAgent::buildObjectForApplicationCacheResource(const ApplicationCacheHost::ResourceInfo& resourceInfo)
+Ref<Inspector::Protocol::ApplicationCache::ApplicationCacheResource> InspectorApplicationCacheAgent::buildObjectForApplicationCacheResource(const ApplicationCacheHost::ResourceInfo& resourceInfo)
{
- String types;
- if (resourceInfo.m_isMaster)
- types.append("Master ");
+ StringBuilder types;
- if (resourceInfo.m_isManifest)
- types.append("Manifest ");
+ if (resourceInfo.isMaster)
+ types.appendLiteral("Master ");
- if (resourceInfo.m_isFallback)
- types.append("Fallback ");
+ if (resourceInfo.isManifest)
+ types.appendLiteral("Manifest ");
- if (resourceInfo.m_isForeign)
- types.append("Foreign ");
+ if (resourceInfo.isFallback)
+ types.appendLiteral("Fallback ");
- if (resourceInfo.m_isExplicit)
- types.append("Explicit ");
+ if (resourceInfo.isForeign)
+ types.appendLiteral("Foreign ");
- RefPtr<Inspector::TypeBuilder::ApplicationCache::ApplicationCacheResource> value = Inspector::TypeBuilder::ApplicationCache::ApplicationCacheResource::create()
- .setUrl(resourceInfo.m_resource.string())
- .setSize(static_cast<int>(resourceInfo.m_size))
- .setType(types);
- return value;
+ if (resourceInfo.isExplicit)
+ types.appendLiteral("Explicit ");
+
+ return Inspector::Protocol::ApplicationCache::ApplicationCacheResource::create()
+ .setUrl(resourceInfo.resource.string())
+ .setSize(static_cast<int>(resourceInfo.size))
+ .setType(types.toString())
+ .release();
}
} // namespace WebCore
-
-#endif // ENABLE(INSPECTOR)