Chromium Code Reviews| Index: Source/core/loader/ManifestLoader.cpp |
| diff --git a/Source/core/loader/ManifestLoader.cpp b/Source/core/loader/ManifestLoader.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a85b24f88a3ca3b58d6da0715590e71f597936e |
| --- /dev/null |
| +++ b/Source/core/loader/ManifestLoader.cpp |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "ManifestLoader.h" |
| + |
| +#include "core/FetchInitiatorTypeNames.h" |
| +#include "core/dom/Document.h" |
| +#include "core/fetch/FetchRequest.h" |
| +#include "core/fetch/ResourceFetcher.h" |
| +#include "core/html/HTMLLinkElement.h" |
| +#include "core/loader/FrameLoaderClient.h" |
| +#include "platform/network/ResourceRequest.h" |
| +#include "public/platform/WebManifest.h" |
| + |
| +using namespace blink; |
| + |
| +void ManifestLoader::loadManifest(PassRefPtr<LocalFrame> frame) |
| +{ |
| + // The object will self-destruct when done. |
| + ManifestLoader* manifestLoader = new ManifestLoader(frame); |
| + manifestLoader->startLoading(); |
| +} |
| + |
| +ManifestLoader::ManifestLoader(PassRefPtr<LocalFrame> frame) |
| + : m_frame(frame) |
| +{ |
| + ASSERT(m_frame); |
| +} |
| + |
| +ManifestLoader::~ManifestLoader() |
| +{ |
| +} |
| + |
| +void ManifestLoader::startLoading() |
| +{ |
| + // When deleted, |selfDestruction| will delete |this|. |
|
kenneth.christiansen
2014/08/27 14:49:37
Should be clearResource() here or when a new manif
mlamouri (slow - plz ping)
2014/09/01 19:23:50
Calling clearResource() is taken care of in the ba
|
| + OwnPtr<ManifestLoader> selfDestruction = adoptPtr(this); |
| + |
| + FrameLoaderClient* client = m_frame->loader().client(); |
| + ASSERT(client); |
| + |
| + Document* document = m_frame->document(); |
| + ASSERT(document); |
| + |
| + HTMLLinkElement* linkElement = document->linkManifest(); |
| + if (!linkElement) { |
| + client->dispatchDidFailLoadManifest(WebManifestError::NoManifest); |
| + return; |
| + } |
| + |
| + KURL url(document->baseURL(), linkElement->href(), document->encoding()); |
| + FetchRequest request = FetchRequest(ResourceRequest(url), FetchInitiatorTypeNames::manifest); |
| + AtomicString crossOriginMode = linkElement->fastGetAttribute(HTMLNames::crossoriginAttr); |
| + if (!crossOriginMode.isNull()) |
| + request.setCrossOriginAccessControl(document->securityOrigin(), crossOriginMode); |
| + |
| + ResourcePtr<Resource> resource = document->fetcher()->fetchManifest(request); |
| + if (!resource) { |
| + client->dispatchDidFailLoadManifest(WebManifestError::FetchError); |
| + return; |
| + } |
| + |
| + setResource(resource); |
| + // Prevent |this| from being deleted. |
| + ManifestLoader* leakedManifestloader ALLOW_UNUSED = selfDestruction.leakPtr(); |
| +} |
| + |
| +void ManifestLoader::notifyFinished(Resource* resource) |
| +{ |
| + // When deleted, |selfDestruction| will delete |this|. |
| + OwnPtr<ManifestLoader> selfDestruction = adoptPtr(this); |
| + ASSERT(resource == this->resource()); |
| + |
| + FrameLoaderClient* client = m_frame->loader().client(); |
| + ASSERT(client); |
| + |
| + if (resource->loadFailedOrCanceled() || resource->errorOccurred()) { |
| + client->dispatchDidFailLoadManifest(WebManifestError::FetchError); |
| + } else { |
| + // FIXME: parse the received data. |
| + WebManifest manifest; |
|
kenneth.christiansen
2014/08/27 14:49:37
To make sure it actually loaded the right content
mlamouri (slow - plz ping)
2014/09/01 19:23:50
Did you meant ScriptResource instead of LinkScript
|
| + client->dispatchDidLoadManifest(manifest); |
| + } |
| + |
| + clearResource(); |
| +} |