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 "third_party/WebKit/public/platform/WebURLError.h" | |
| 8 #include "third_party/WebKit/public/platform/WebURLLoader.h" | |
| 9 #include "third_party/WebKit/public/platform/WebURLRequest.h" | |
| 10 #include "third_party/WebKit/public/web/WebDocument.h" | |
| 11 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 ManifestFetcher::ManifestFetcher(const GURL& url) | |
| 16 : request_(url), | |
| 17 completed_(false) { | |
| 18 } | |
| 19 | |
| 20 ManifestFetcher::~ManifestFetcher() { | |
| 21 if (!completed_ && loader_) | |
| 22 loader_->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); | |
|
kenneth.christiansen
2014/09/05 13:13:44
So it keeps part of your former patch?
mlamouri (slow - plz ping)
2014/09/05 14:10:41
No, WebURLRequest already has that. It's part of t
| |
| 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::RunCallback(const blink::WebURLResponse& response, | |
| 46 const std::string& data) { | |
| 47 completed_ = true; | |
| 48 if (callback_.is_null()) | |
| 49 return; | |
| 50 | |
| 51 Callback callback = callback_; | |
| 52 callback.Run(response, data); | |
| 53 } | |
| 54 | |
| 55 void ManifestFetcher::didReceiveResponse( | |
| 56 blink::WebURLLoader* loader, const blink::WebURLResponse& response) { | |
| 57 DCHECK(!completed_); | |
| 58 response_ = response; | |
| 59 } | |
| 60 | |
| 61 void ManifestFetcher::didReceiveData( | |
| 62 blink::WebURLLoader* loader, | |
| 63 const char* data, | |
| 64 int data_length, | |
| 65 int encoded_data_length) { | |
| 66 DCHECK(!completed_); | |
| 67 DCHECK(data_length > 0); | |
| 68 | |
| 69 data_.append(data, data_length); | |
| 70 } | |
| 71 | |
| 72 void ManifestFetcher::didFinishLoading( | |
| 73 blink::WebURLLoader* loader, | |
| 74 double finishTime, | |
| 75 int64_t total_encoded_data_length) { | |
| 76 DCHECK(!completed_); | |
| 77 | |
| 78 RunCallback(response_, data_); | |
| 79 } | |
| 80 | |
| 81 void ManifestFetcher::didFail(blink::WebURLLoader* loader, | |
| 82 const blink::WebURLError& error) { | |
| 83 DCHECK(!completed_); | |
| 84 | |
| 85 RunCallback(blink::WebURLResponse(), std::string()); | |
| 86 } | |
| 87 | |
| 88 } // namespace content | |
| OLD | NEW |