This source file includes following definitions.
- m_defersEvents
- willStartLoadingMainResource
- selectCacheWithoutManifest
- selectCacheWithManifest
- didReceiveResponseForMainResource
- mainResourceDataReceived
- failedLoadingMainResource
- finishedLoadingMainResource
- willStartLoadingResource
- setApplicationCache
- notifyApplicationCache
- applicationCacheInfo
- fillResourceList
- stopDeferringEvents
- dispatchDOMEvent
- status
- update
- swapCache
- abort
- isApplicationCacheEnabled
- didChangeCacheAssociation
- notifyEventListener
- notifyProgressEventListener
- notifyErrorEventListener
#include "config.h"
#include "core/loader/appcache/ApplicationCacheHost.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/events/ApplicationCacheErrorEvent.h"
#include "core/events/ProgressEvent.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/inspector/InspectorApplicationCacheAgent.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoader.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/loader/appcache/ApplicationCache.h"
#include "core/page/FrameTree.h"
#include "core/page/Page.h"
#include "platform/exported/WrappedResourceRequest.h"
#include "platform/exported/WrappedResourceResponse.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/WebURL.h"
#include "public/platform/WebURLError.h"
#include "public/platform/WebURLResponse.h"
#include "public/platform/WebVector.h"
using namespace blink;
namespace WebCore {
ApplicationCacheHost::ApplicationCacheHost(DocumentLoader* documentLoader)
: m_domApplicationCache(0)
, m_documentLoader(documentLoader)
, m_defersEvents(true)
{
ASSERT(m_documentLoader);
}
ApplicationCacheHost::~ApplicationCacheHost()
{
}
void ApplicationCacheHost::willStartLoadingMainResource(ResourceRequest& request)
{
if (!isApplicationCacheEnabled())
return;
ASSERT(m_documentLoader->frame());
LocalFrame& frame = *m_documentLoader->frame();
m_host = frame.loader().client()->createApplicationCacheHost(this);
if (m_host) {
WrappedResourceRequest wrapped(request);
const WebApplicationCacheHost* spawningHost = 0;
LocalFrame* spawningFrame = frame.tree().parent();
if (!spawningFrame)
spawningFrame = frame.loader().opener();
if (!spawningFrame)
spawningFrame = &frame;
if (DocumentLoader* spawningDocLoader = spawningFrame->loader().documentLoader())
spawningHost = spawningDocLoader->applicationCacheHost() ? spawningDocLoader->applicationCacheHost()->m_host.get() : 0;
m_host->willStartMainResourceRequest(wrapped, spawningHost);
}
}
void ApplicationCacheHost::selectCacheWithoutManifest()
{
if (m_host)
m_host->selectCacheWithoutManifest();
}
void ApplicationCacheHost::selectCacheWithManifest(const KURL& manifestURL)
{
if (m_host && !m_host->selectCacheWithManifest(manifestURL)) {
LocalFrame* frame = m_documentLoader->frame();
frame->navigationScheduler().scheduleLocationChange(frame->document(), frame->document()->url(), Referrer(frame->document()->referrer(), frame->document()->referrerPolicy()));
}
}
void ApplicationCacheHost::didReceiveResponseForMainResource(const ResourceResponse& response)
{
if (m_host) {
WrappedResourceResponse wrapped(response);
m_host->didReceiveResponseForMainResource(wrapped);
}
}
void ApplicationCacheHost::mainResourceDataReceived(const char* data, int length)
{
if (m_host)
m_host->didReceiveDataForMainResource(data, length);
}
void ApplicationCacheHost::failedLoadingMainResource()
{
if (m_host)
m_host->didFinishLoadingMainResource(false);
}
void ApplicationCacheHost::finishedLoadingMainResource()
{
if (m_host)
m_host->didFinishLoadingMainResource(true);
}
void ApplicationCacheHost::willStartLoadingResource(ResourceRequest& request)
{
if (m_host) {
WrappedResourceRequest wrapped(request);
m_host->willStartSubResourceRequest(wrapped);
}
}
void ApplicationCacheHost::setApplicationCache(ApplicationCache* domApplicationCache)
{
ASSERT(!m_domApplicationCache || !domApplicationCache);
m_domApplicationCache = domApplicationCache;
}
void ApplicationCacheHost::notifyApplicationCache(EventID id, int progressTotal, int progressDone, blink::WebApplicationCacheHost::ErrorReason errorReason, const String& errorURL, int errorStatus, const String& errorMessage)
{
if (id != PROGRESS_EVENT)
InspectorInstrumentation::updateApplicationCacheStatus(m_documentLoader->frame());
if (m_defersEvents) {
m_deferredEvents.append(DeferredEvent(id, progressTotal, progressDone, errorReason, errorURL, errorStatus, errorMessage));
return;
}
dispatchDOMEvent(id, progressTotal, progressDone, errorReason, errorURL, errorStatus, errorMessage);
}
ApplicationCacheHost::CacheInfo ApplicationCacheHost::applicationCacheInfo()
{
if (!m_host)
return CacheInfo(KURL(), 0, 0, 0);
blink::WebApplicationCacheHost::CacheInfo webInfo;
m_host->getAssociatedCacheInfo(&webInfo);
return CacheInfo(webInfo.manifestURL, webInfo.creationTime, webInfo.updateTime, webInfo.totalSize);
}
void ApplicationCacheHost::fillResourceList(ResourceInfoList* resources)
{
if (!m_host)
return;
blink::WebVector<blink::WebApplicationCacheHost::ResourceInfo> webResources;
m_host->getResourceList(&webResources);
for (size_t i = 0; i < webResources.size(); ++i) {
resources->append(ResourceInfo(
webResources[i].url, webResources[i].isMaster, webResources[i].isManifest, webResources[i].isFallback,
webResources[i].isForeign, webResources[i].isExplicit, webResources[i].size));
}
}
void ApplicationCacheHost::stopDeferringEvents()
{
RefPtr<DocumentLoader> protect(documentLoader());
for (unsigned i = 0; i < m_deferredEvents.size(); ++i) {
const DeferredEvent& deferred = m_deferredEvents[i];
dispatchDOMEvent(deferred.eventID, deferred.progressTotal, deferred.progressDone, deferred.errorReason, deferred.errorURL, deferred.errorStatus, deferred.errorMessage);
}
m_deferredEvents.clear();
m_defersEvents = false;
}
void ApplicationCacheHost::dispatchDOMEvent(EventID id, int progressTotal, int progressDone, blink::WebApplicationCacheHost::ErrorReason errorReason, const String& errorURL, int errorStatus, const String& errorMessage)
{
if (m_domApplicationCache) {
const AtomicString& eventType = ApplicationCache::toEventType(id);
RefPtrWillBeRawPtr<Event> event = nullptr;
if (id == PROGRESS_EVENT)
event = ProgressEvent::create(eventType, true, progressDone, progressTotal);
else if (id == ERROR_EVENT)
event = ApplicationCacheErrorEvent::create(errorReason, errorURL, errorStatus, errorMessage);
else
event = Event::create(eventType);
m_domApplicationCache->dispatchEvent(event, ASSERT_NO_EXCEPTION);
}
}
ApplicationCacheHost::Status ApplicationCacheHost::status() const
{
return m_host ? static_cast<Status>(m_host->status()) : UNCACHED;
}
bool ApplicationCacheHost::update()
{
return m_host ? m_host->startUpdate() : false;
}
bool ApplicationCacheHost::swapCache()
{
bool success = m_host ? m_host->swapCache() : false;
if (success)
InspectorInstrumentation::updateApplicationCacheStatus(m_documentLoader->frame());
return success;
}
void ApplicationCacheHost::abort()
{
if (m_host)
m_host->abort();
}
bool ApplicationCacheHost::isApplicationCacheEnabled()
{
ASSERT(m_documentLoader->frame());
return m_documentLoader->frame()->settings() && m_documentLoader->frame()->settings()->offlineWebApplicationCacheEnabled();
}
void ApplicationCacheHost::didChangeCacheAssociation()
{
}
void ApplicationCacheHost::notifyEventListener(blink::WebApplicationCacheHost::EventID eventID)
{
notifyApplicationCache(static_cast<ApplicationCacheHost::EventID>(eventID), 0, 0, blink::WebApplicationCacheHost::UnknownError, String(), 0, String());
}
void ApplicationCacheHost::notifyProgressEventListener(const blink::WebURL&, int progressTotal, int progressDone)
{
notifyApplicationCache(PROGRESS_EVENT, progressTotal, progressDone, blink::WebApplicationCacheHost::UnknownError, String(), 0, String());
}
void ApplicationCacheHost::notifyErrorEventListener(blink::WebApplicationCacheHost::ErrorReason reason, const blink::WebURL& url, int status, const blink::WebString& message)
{
notifyApplicationCache(ERROR_EVENT, 0, 0, reason, url.string(), status, message);
}
}