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 completed_(false) { | |
| 19 } | |
| 20 | |
| 21 ManifestFetcher::~ManifestFetcher() { | |
| 22 if (!completed_ && loader_) | |
| 23 loader_->cancel(); | |
| 24 } | |
| 25 | |
| 26 void ManifestFetcher::Start(blink::WebFrame* frame, const Callback& callback) { | |
| 27 DCHECK(!loader_); | |
| 28 DCHECK(!request_.isNull()); | |
| 29 DCHECK(callback_.is_null()); | |
| 30 DCHECK(!completed_); | |
| 31 if (!request_.httpBody().isNull()) | |
| 32 DCHECK_NE("GET", request_.httpMethod().utf8()) << "GETs can't have bodies."; | |
| 33 | |
| 34 callback_ = callback; | |
| 35 | |
| 36 request_.setRequestContext(blink::WebURLRequest::RequestContextManifest); | |
| 37 request_.setFrameType(blink::WebURLRequest::FrameTypeNone); | |
|
Mike West
2014/09/10 07:45:30
The only difference between ResourceFetcherImpl an
mlamouri (slow - plz ping)
2014/09/10 11:16:05
Not really. I'm using frame->createAssociatedURLLo
Mike West
2014/09/10 11:49:55
You're right. I missed the difference in line #40.
| |
| 38 request_.setFirstPartyForCookies(frame->document().firstPartyForCookies()); | |
| 39 frame->dispatchWillSendRequest(request_); | |
| 40 loader_.reset(frame->createAssociatedURLLoader()); | |
| 41 loader_->loadAsynchronously(request_, this); | |
| 42 | |
| 43 request_.reset(); | |
| 44 } | |
| 45 | |
| 46 void ManifestFetcher::Cancel() { | |
| 47 DCHECK(!completed_ && loader_); | |
| 48 | |
| 49 loader_->cancel(); | |
| 50 RunCallback(blink::WebURLResponse(), std::string()); | |
| 51 } | |
| 52 | |
| 53 void ManifestFetcher::RunCallback(const blink::WebURLResponse& response, | |
| 54 const std::string& data) { | |
| 55 completed_ = true; | |
|
Mike West
2014/09/10 07:45:30
The only difference here is the timeout.
| |
| 56 if (callback_.is_null()) | |
| 57 return; | |
| 58 | |
| 59 Callback callback = callback_; | |
| 60 callback.Run(response, data); | |
| 61 } | |
| 62 | |
| 63 void ManifestFetcher::didReceiveResponse( | |
|
Mike West
2014/09/10 07:45:30
The implementation of these four methods is exactl
| |
| 64 blink::WebURLLoader* loader, const blink::WebURLResponse& response) { | |
| 65 DCHECK(!completed_); | |
| 66 response_ = response; | |
| 67 } | |
| 68 | |
| 69 void ManifestFetcher::didReceiveData( | |
| 70 blink::WebURLLoader* loader, | |
| 71 const char* data, | |
| 72 int data_length, | |
| 73 int encoded_data_length) { | |
| 74 DCHECK(!completed_); | |
| 75 DCHECK(data_length > 0); | |
| 76 | |
| 77 data_.append(data, data_length); | |
| 78 } | |
| 79 | |
| 80 void ManifestFetcher::didFinishLoading( | |
| 81 blink::WebURLLoader* loader, | |
| 82 double finishTime, | |
| 83 int64_t total_encoded_data_length) { | |
| 84 DCHECK(!completed_); | |
| 85 | |
| 86 RunCallback(response_, data_); | |
| 87 } | |
| 88 | |
| 89 void ManifestFetcher::didFail(blink::WebURLLoader* loader, | |
| 90 const blink::WebURLError& error) { | |
| 91 DCHECK(!completed_); | |
| 92 | |
| 93 RunCallback(blink::WebURLResponse(), std::string()); | |
| 94 } | |
| 95 | |
| 96 } // namespace content | |
| OLD | NEW |