Chromium Code Reviews| 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 "content/renderer/fetchers/manifest_fetcher.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "third_party/WebKit/public/platform/WebURLError.h" | |
| 9 #include "third_party/WebKit/public/platform/WebURLLoader.h" | |
| 10 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
| 11 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 12 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 13 | |
| 14 namespace content { | |
| 15 | |
| 16 ManifestFetcher::ManifestFetcher(const GURL& url) | |
| 17 : request_(url) { | |
| 18 } | |
| 19 | |
| 20 ManifestFetcher::~ManifestFetcher() { | |
| 21 if (!completed() && loader_) | |
| 22 Cancel(); | |
| 23 } | |
| 24 | |
| 25 void ManifestFetcher::Start(blink::WebFrame* frame, const Callback& callback) { | |
| 26 DCHECK(!loader_); | |
| 27 DCHECK(!request_.isNull()); | |
| 28 DCHECK(callback_.is_null()); | |
| 29 DCHECK(!completed()); | |
| 30 if (!request_.httpBody().isNull()) | |
| 31 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; | |
| 32 | |
| 33 callback_ = callback; | |
| 34 | |
| 35 request_.setRequestContext(blink::WebURLRequest::RequestContextManifest); | |
|
Mike West
2014/09/10 14:00:12
Perhaps this could be deduped by adding ::Start me
| |
| 36 request_.setFrameType(blink::WebURLRequest::FrameTypeNone); | |
| 37 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); | |
| 38 frame->dispatchWillSendRequest(request_); | |
| 39 loader_.reset(frame->createAssociatedURLLoader()); | |
| 40 loader_->loadAsynchronously(request_, this); | |
| 41 | |
| 42 request_.reset(); | |
| 43 } | |
| 44 | |
| 45 void ManifestFetcher::Cancel() { | |
| 46 loader_->cancel(); | |
| 47 WebURLLoaderClientImpl::Cancel(); | |
| 48 } | |
| 49 | |
| 50 void ManifestFetcher::OnLoadComplete() { | |
| 51 if (callback_.is_null()) | |
| 52 return; | |
| 53 | |
| 54 Callback callback = callback_; | |
| 55 callback.Run(status() == LOAD_FAILED ? blink::WebURLResponse() : response(), | |
| 56 status() == LOAD_FAILED ? std::string() : data()); | |
| 57 } | |
| 58 | |
| 59 } // namespace content | |
| OLD | NEW |