Index: content/renderer/fetchers/manifest_fetcher.cc |
diff --git a/content/renderer/fetchers/manifest_fetcher.cc b/content/renderer/fetchers/manifest_fetcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7d42d1798ab0f45eea1fb0c6df51bf8949f6349f |
--- /dev/null |
+++ b/content/renderer/fetchers/manifest_fetcher.cc |
@@ -0,0 +1,59 @@ |
+// 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 "content/renderer/fetchers/manifest_fetcher.h" |
+ |
+#include "base/logging.h" |
+#include "third_party/WebKit/public/platform/WebURLError.h" |
+#include "third_party/WebKit/public/platform/WebURLLoader.h" |
+#include "third_party/WebKit/public/platform/WebURLRequest.h" |
+#include "third_party/WebKit/public/web/WebDocument.h" |
+#include "third_party/WebKit/public/web/WebFrame.h" |
+ |
+namespace content { |
+ |
+ManifestFetcher::ManifestFetcher(const GURL& url) |
+ : request_(url) { |
+} |
+ |
+ManifestFetcher::~ManifestFetcher() { |
+ if (!completed() && loader_) |
+ Cancel(); |
+} |
+ |
+void ManifestFetcher::Start(blink::WebFrame* frame, const Callback& callback) { |
+ DCHECK(!loader_); |
+ DCHECK(!request_.isNull()); |
+ DCHECK(callback_.is_null()); |
+ DCHECK(!completed()); |
+ if (!request_.httpBody().isNull()) |
+ DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; |
+ |
+ callback_ = callback; |
+ |
+ request_.setRequestContext(blink::WebURLRequest::RequestContextManifest); |
Mike West
2014/09/10 14:00:12
Perhaps this could be deduped by adding ::Start me
|
+ request_.setFrameType(blink::WebURLRequest::FrameTypeNone); |
+ request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); |
+ frame->dispatchWillSendRequest(request_); |
+ loader_.reset(frame->createAssociatedURLLoader()); |
+ loader_->loadAsynchronously(request_, this); |
+ |
+ request_.reset(); |
+} |
+ |
+void ManifestFetcher::Cancel() { |
+ loader_->cancel(); |
+ WebURLLoaderClientImpl::Cancel(); |
+} |
+ |
+void ManifestFetcher::OnLoadComplete() { |
+ if (callback_.is_null()) |
+ return; |
+ |
+ Callback callback = callback_; |
+ callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), |
+ status() == LOAD_FAILED ? std::string() : data()); |
+} |
+ |
+} // namespace content |