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..711830155c4e2fb29702d2ced259c2fed30fb03e |
| --- /dev/null |
| +++ b/Source/core/loader/ManifestLoader.cpp |
| @@ -0,0 +1,87 @@ |
| +// 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/dom/Document.h" |
| +#include "core/FetchInitiatorTypeNames.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|. |
| + OwnPtr<ManifestLoader> selfDestruction = adoptPtr(this); |
| + FrameLoaderClient* client = m_frame->loader().client(); |
|
Nate Chapin
2014/08/25 20:43:12
Is this case possible at load start time?
mlamouri (slow - plz ping)
2014/08/26 17:25:22
Done.
|
| + if (!client) |
| + return; |
| + |
| + Document* document = m_frame->document(); |
|
Nate Chapin
2014/08/25 20:43:12
I don't think this can't be null if there is a non
mlamouri (slow - plz ping)
2014/08/26 17:25:23
Done.
|
| + HTMLLinkElement* linkElement = document ? document->linkManifest() : 0; |
| + 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(); |
|
Nate Chapin
2014/08/25 20:43:12
I don't think loads can complete when FrameLoaderC
mlamouri (slow - plz ping)
2014/08/26 17:25:23
Done.
|
| + if (!client) |
| + return; |
| + |
| + if (resource->loadFailedOrCanceled() || resource->errorOccurred()) { |
| + client->dispatchDidFailLoadManifest(WebManifestError::FetchError); |
| + } else { |
| + // FIXME: parse the received data. |
| + WebManifest manifest; |
| + client->dispatchDidLoadManifest(manifest); |
| + } |
| + |
| + clearResource(); |
| +} |