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

Unified 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: review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/loader/ManifestLoader.h ('k') | Source/web/FrameLoaderClientImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..160b7856eaa4c9e2954a3045753e531ed76291db
--- /dev/null
+++ b/Source/core/loader/ManifestLoader.cpp
@@ -0,0 +1,90 @@
+// 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"
+
+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();
+ 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;
+ client->dispatchDidLoadManifest(manifest);
+ }
+
+ clearResource();
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/loader/ManifestLoader.h ('k') | Source/web/FrameLoaderClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698