Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: Source/core/loader/ManifestLoader.cpp

Issue 295063002: [NotLanded] Implement the fetching algorithm of the Web Manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 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|.
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
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;
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
84 client->dispatchDidLoadManifest(manifest);
85 }
86
87 clearResource();
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698