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/dom/Document.h" | |
9 #include "core/FetchInitiatorTypeNames.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 using 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 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.
| |
41 if (!client) | |
42 return; | |
43 | |
44 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.
| |
45 HTMLLinkElement* linkElement = document ? document->linkManifest() : 0; | |
46 if (!linkElement) { | |
47 client->dispatchDidFailLoadManifest(WebManifestError::NoManifest); | |
48 return; | |
49 } | |
50 | |
51 KURL url(document->baseURL(), linkElement->href(), document->encoding()); | |
52 FetchRequest request = FetchRequest(ResourceRequest(url), FetchInitiatorType Names::manifest); | |
53 AtomicString crossOriginMode = linkElement->fastGetAttribute(HTMLNames::cros soriginAttr); | |
54 if (!crossOriginMode.isNull()) | |
55 request.setCrossOriginAccessControl(document->securityOrigin(), crossOri ginMode); | |
56 | |
57 ResourcePtr<Resource> resource = document->fetcher()->fetchManifest(request) ; | |
58 if (!resource) { | |
59 client->dispatchDidFailLoadManifest(WebManifestError::FetchError); | |
60 return; | |
61 } | |
62 | |
63 setResource(resource); | |
64 // Prevent |this| from being deleted. | |
65 ManifestLoader* leakedManifestloader ALLOW_UNUSED = selfDestruction.leakPtr( ); | |
66 } | |
67 | |
68 void ManifestLoader::notifyFinished(Resource* resource) | |
69 { | |
70 // When deleted, |selfDestruction| will delete |this|. | |
71 OwnPtr<ManifestLoader> selfDestruction = adoptPtr(this); | |
72 ASSERT(resource == this->resource()); | |
73 | |
74 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.
| |
75 if (!client) | |
76 return; | |
77 | |
78 if (resource->loadFailedOrCanceled() || resource->errorOccurred()) { | |
79 client->dispatchDidFailLoadManifest(WebManifestError::FetchError); | |
80 } else { | |
81 // FIXME: parse the received data. | |
82 WebManifest manifest; | |
83 client->dispatchDidLoadManifest(manifest); | |
84 } | |
85 | |
86 clearResource(); | |
87 } | |
OLD | NEW |