OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "ManifestLoader.h" |
| 7 |
| 8 #include "core/FetchInitiatorTypeNames.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "core/fetch/FetchRequest.h" |
| 11 #include "core/fetch/ResourceFetcher.h" |
| 12 #include "core/html/HTMLLinkElement.h" |
| 13 #include "core/loader/FrameLoaderClient.h" |
| 14 #include "platform/network/ResourceRequest.h" |
| 15 #include "public/platform/WebManifest.h" |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 void ManifestLoader::loadManifest(PassRefPtr<LocalFrame> frame) |
| 20 { |
| 21 // The object will self-destruct when done. |
| 22 ManifestLoader* manifestLoader = new ManifestLoader(frame); |
| 23 manifestLoader->startLoading(); |
| 24 } |
| 25 |
| 26 ManifestLoader::ManifestLoader(PassRefPtr<LocalFrame> frame) |
| 27 : m_frame(frame) |
| 28 { |
| 29 ASSERT(m_frame); |
| 30 } |
| 31 |
| 32 ManifestLoader::~ManifestLoader() |
| 33 { |
| 34 } |
| 35 |
| 36 void ManifestLoader::startLoading() |
| 37 { |
| 38 // When deleted, |selfDestruction| will delete |this|. |
| 39 OwnPtr<ManifestLoader> selfDestruction = adoptPtr(this); |
| 40 |
| 41 FrameLoaderClient* client = m_frame->loader().client(); |
| 42 ASSERT(client); |
| 43 |
| 44 Document* document = m_frame->document(); |
| 45 ASSERT(document); |
| 46 |
| 47 HTMLLinkElement* linkElement = document->linkManifest(); |
| 48 if (!linkElement) { |
| 49 client->dispatchDidFailLoadManifest(WebManifestError::NoManifest); |
| 50 return; |
| 51 } |
| 52 |
| 53 KURL url(document->baseURL(), linkElement->href(), document->encoding()); |
| 54 FetchRequest request = FetchRequest(ResourceRequest(url), FetchInitiatorType
Names::manifest); |
| 55 AtomicString crossOriginMode = linkElement->fastGetAttribute(HTMLNames::cros
soriginAttr); |
| 56 if (!crossOriginMode.isNull()) |
| 57 request.setCrossOriginAccessControl(document->securityOrigin(), crossOri
ginMode); |
| 58 |
| 59 ResourcePtr<Resource> resource = document->fetcher()->fetchManifest(request)
; |
| 60 if (!resource) { |
| 61 client->dispatchDidFailLoadManifest(WebManifestError::FetchError); |
| 62 return; |
| 63 } |
| 64 |
| 65 setResource(resource); |
| 66 // Prevent |this| from being deleted. |
| 67 ManifestLoader* leakedManifestloader ALLOW_UNUSED = selfDestruction.leakPtr(
); |
| 68 } |
| 69 |
| 70 void ManifestLoader::notifyFinished(Resource* resource) |
| 71 { |
| 72 // When deleted, |selfDestruction| will delete |this|. |
| 73 OwnPtr<ManifestLoader> selfDestruction = adoptPtr(this); |
| 74 ASSERT(resource == this->resource()); |
| 75 |
| 76 FrameLoaderClient* client = m_frame->loader().client(); |
| 77 ASSERT(client); |
| 78 |
| 79 if (resource->loadFailedOrCanceled() || resource->errorOccurred()) { |
| 80 client->dispatchDidFailLoadManifest(WebManifestError::FetchError); |
| 81 } else { |
| 82 // FIXME: parse the received data. |
| 83 WebManifest manifest; |
| 84 client->dispatchDidLoadManifest(manifest); |
| 85 } |
| 86 |
| 87 clearResource(); |
| 88 } |
| 89 |
| 90 } // namespace blink |
OLD | NEW |