| Index: loader/appcache2/ApplicationCacheFrontend.cpp
|
| ===================================================================
|
| --- loader/appcache2/ApplicationCacheFrontend.cpp (revision 0)
|
| +++ loader/appcache2/ApplicationCacheFrontend.cpp (revision 0)
|
| @@ -0,0 +1,237 @@
|
| +/*
|
| + * Copyright (c) 2009, Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "config.h"
|
| +#include "ApplicationCacheFrontend.h"
|
| +
|
| +#if ENABLE(APPLICATION_CACHE)
|
| +
|
| +#include "ApplicationCacheBridge.h"
|
| +#include "DOMApplicationCache.h"
|
| +#include "Frame.h"
|
| +#include "ResourceRequest.h"
|
| +#include <wtf/HashMap.h>
|
| +#include <wtf/StdLibExtras.h>
|
| +#include <wtf/Threading.h>
|
| +
|
| +namespace WebCore {
|
| +
|
| +// We keep a collection of all frontend instances for lookup by contextID.
|
| +
|
| +typedef HashMap<int, ApplicationCacheFrontend*> FrontendsMap;
|
| +
|
| +static FrontendsMap& frontends()
|
| +{
|
| + DEFINE_STATIC_LOCAL(FrontendsMap, staticFrontends, ());
|
| + return staticFrontends;
|
| +}
|
| +
|
| +
|
| +// static
|
| +void ApplicationCacheFrontend::addToMap(ApplicationCacheFrontend* frontend)
|
| +{
|
| + frontends().add(frontend->contextID().m_contextID, frontend);
|
| +}
|
| +
|
| +// static
|
| +void ApplicationCacheFrontend::removeFromMap(ApplicationCacheFrontend* frontend)
|
| +{
|
| + frontends().remove(frontend->contextID().m_contextID);
|
| +}
|
| +
|
| +// static
|
| +ApplicationCacheFrontend* ApplicationCacheFrontend::fromContextID(const GlobalApplicationCacheContextID &contextID)
|
| +{
|
| + ApplicationCacheFrontend* frontend = frontends().get(contextID.m_contextID);
|
| + return frontend;
|
| +}
|
| +
|
| +ApplicationCacheFrontend::ApplicationCacheFrontend()
|
| + : m_contextType(MainFrameContext)
|
| + , m_DOMApplicationCache(0)
|
| + , m_canCacheInPageCache(false)
|
| + , m_isSelectInProgress(false)
|
| + , m_cacheSequenceNumber(0)
|
| + , m_hasCachedStatus(false)
|
| + , m_cachedStatus(APPCACHE_UNCACHED)
|
| + , m_bridge(ApplicationCacheBridge::instance())
|
| +{
|
| + ASSERT(m_bridge);
|
| +}
|
| +
|
| +ApplicationCacheFrontend::~ApplicationCacheFrontend()
|
| +{
|
| + if (isInitialized()) {
|
| + m_bridge->uninitializeContextAsync(contextID());
|
| + removeFromMap(this);
|
| + }
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::initializeForFrame(Frame* frame)
|
| +{
|
| + ASSERT(frame);
|
| + ApplicationCacheContextType contextType = MainFrameContext;
|
| + GlobalApplicationCacheContextID parentContextID = GlobalApplicationCacheContextID::none();
|
| + if (Frame* parentFrame = frame->parentFrame()) {
|
| + contextType = SubFrameContext;
|
| + parentContextID = parentFrame->loader()->appcacheFrontend()->contextID();
|
| + }
|
| + initialize(contextType, parentContextID);
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::initialize(ApplicationCacheContextType contextType,
|
| + const GlobalApplicationCacheContextID& parentContextID)
|
| +{
|
| + ASSERT(!isInitialized());
|
| + DEFINE_STATIC_LOCAL(int, nextID, (1));
|
| + // FIXME: set the processID data member of GlobalApplicationCacheContextID
|
| + m_contextID = GlobalApplicationCacheContextID(nextID++, 0);
|
| + m_contextType = contextType;
|
| + addToMap(this);
|
| + m_bridge->initializeContextAsync(contextID(), contextType, parentContextID);
|
| +}
|
| +
|
| +int ApplicationCacheFrontend::prepareForSelectCall()
|
| +{
|
| + m_isSelectInProgress = true;
|
| + m_hasCachedStatus = false;
|
| + return ++m_cacheSequenceNumber;
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::selectInitialCache(const KURL& documentURL,
|
| + ApplicationCacheID cacheDocumentWasLoadedFrom)
|
| +{
|
| + if (!isInitialized())
|
| + return;
|
| + m_canCacheInPageCache = cacheDocumentWasLoadedFrom == NoApplicationCacheID;
|
| + m_bridge->selectInitialCacheAsync(contextID(),
|
| + prepareForSelectCall(),
|
| + documentURL,
|
| + cacheDocumentWasLoadedFrom);
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::selectCacheWithoutManifest(
|
| + const KURL& documentURL,
|
| + ApplicationCacheID cacheDocumentWasLoadedFrom)
|
| +{
|
| + if (!isInitialized())
|
| + return;
|
| + m_canCacheInPageCache = cacheDocumentWasLoadedFrom == NoApplicationCacheID;
|
| + m_bridge->selectCacheWithoutManifestAsync(contextID(),
|
| + prepareForSelectCall(),
|
| + documentURL,
|
| + cacheDocumentWasLoadedFrom);
|
| +}
|
| +
|
| +bool ApplicationCacheFrontend::selectCacheWithManifest(
|
| + const KURL& documentURL,
|
| + ApplicationCacheID cacheDocumentWasLoadedFrom,
|
| + const KURL& manifestURLofCacheDocumentWasLoadedFrom,
|
| + const KURL& manifestURL)
|
| +{
|
| + if (!isInitialized())
|
| + return true;
|
| +
|
| + m_canCacheInPageCache = false;
|
| + m_bridge->selectCacheWithManifestAsync(contextID(),
|
| + prepareForSelectCall(),
|
| + documentURL,
|
| + cacheDocumentWasLoadedFrom,
|
| + manifestURLofCacheDocumentWasLoadedFrom,
|
| + manifestURL);
|
| +
|
| + // Check for a foreign entriy and restart the current navigation if detected,
|
| + // the foreign entry will not be picked up on reload.
|
| + if ((cacheDocumentWasLoadedFrom != NoApplicationCacheID)
|
| + && (manifestURL != manifestURLofCacheDocumentWasLoadedFrom))
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::addExtraFieldsToRequest(ResourceRequest& request, bool mainResource)
|
| +{
|
| + ASSERT(isInitialized());
|
| + request.setApplicationCacheContextID(contextID());
|
| +}
|
| +
|
| +bool ApplicationCacheFrontend::canCacheCurrentDocumentInPageCache() const
|
| +{
|
| + return m_canCacheInPageCache;
|
| +}
|
| +
|
| +ApplicationCacheStatus ApplicationCacheFrontend::status() const
|
| +{
|
| + ASSERT(isInitialized());
|
| + if (!m_hasCachedStatus) {
|
| + ASSERT(m_isSelectInProgress);
|
| + m_cachedStatus = m_bridge->status(contextID());
|
| + m_hasCachedStatus = true;
|
| + }
|
| + return m_cachedStatus;
|
| +}
|
| +
|
| +bool ApplicationCacheFrontend::update()
|
| +{
|
| + ASSERT(isInitialized());
|
| + return m_bridge->startUpdate(contextID());
|
| +}
|
| +
|
| +bool ApplicationCacheFrontend::swapCache()
|
| +{
|
| + ASSERT(isInitialized());
|
| + return m_bridge->swapCache(contextID());
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::notifySelectComplete(ApplicationCacheStatus status)
|
| +{
|
| + ASSERT(m_isSelectInProgress);
|
| + m_isSelectInProgress = false;
|
| + if (!m_hasCachedStatus) {
|
| + m_cachedStatus = status;
|
| + m_hasCachedStatus = true;
|
| + }
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::notifyStatusChanged(ApplicationCacheStatus status)
|
| +{
|
| + ASSERT(m_hasCachedStatus);
|
| + m_cachedStatus = status;
|
| +}
|
| +
|
| +void ApplicationCacheFrontend::notifyEventListener(ApplicationCacheEventType eventType)
|
| +{
|
| + if (!m_isSelectInProgress && m_DOMApplicationCache)
|
| + m_DOMApplicationCache->callEventListener(eventType);
|
| +}
|
| +
|
| +} // namespace WebCore
|
| +
|
| +#endif // ENABLE(APPLICATION_CACHE)
|
|
|
| Property changes on: loader\appcache2\ApplicationCacheFrontend.cpp
|
| ___________________________________________________________________
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|