| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/fetchers/manifest_fetcher.h" | 5 #include "content/renderer/fetchers/manifest_fetcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/public/renderer/associated_resource_fetcher.h" | 9 #include "content/public/renderer/associated_resource_fetcher.h" |
| 10 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 10 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 11 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderOptions.h" | 11 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderOptions.h" |
| 12 #include "third_party/WebKit/public/web/WebFrame.h" | 12 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 ManifestFetcher::ManifestFetcher(const GURL& url) | 16 ManifestFetcher::ManifestFetcher(const GURL& url) |
| 17 : completed_(false) { | 17 : completed_(false) { |
| 18 fetcher_.reset(AssociatedResourceFetcher::Create(url)); | 18 fetcher_.reset(AssociatedResourceFetcher::Create(url)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 ManifestFetcher::~ManifestFetcher() { | 21 ManifestFetcher::~ManifestFetcher() { |
| 22 if (!completed_) | 22 if (!completed_) |
| 23 Cancel(); | 23 Cancel(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void ManifestFetcher::Start(blink::WebFrame* frame, | 26 void ManifestFetcher::Start(blink::WebLocalFrame* frame, |
| 27 bool use_credentials, | 27 bool use_credentials, |
| 28 const Callback& callback) { | 28 const Callback& callback) { |
| 29 callback_ = callback; | 29 callback_ = callback; |
| 30 | 30 |
| 31 blink::WebAssociatedURLLoaderOptions options; | 31 blink::WebAssociatedURLLoaderOptions options; |
| 32 options.allow_credentials = use_credentials; | 32 options.allow_credentials = use_credentials; |
| 33 options.fetch_request_mode = blink::WebURLRequest::kFetchRequestModeCORS; | 33 options.fetch_request_mode = blink::WebURLRequest::kFetchRequestModeCORS; |
| 34 fetcher_->SetLoaderOptions(options); | 34 fetcher_->SetLoaderOptions(options); |
| 35 | 35 |
| 36 fetcher_->Start( | 36 fetcher_->Start( |
| 37 frame, blink::WebURLRequest::kRequestContextManifest, | 37 frame, blink::WebURLRequest::kRequestContextManifest, |
| 38 blink::WebURLRequest::kFrameTypeNone, | 38 blink::WebURLRequest::kFrameTypeNone, |
| 39 base::Bind(&ManifestFetcher::OnLoadComplete, base::Unretained(this))); | 39 base::Bind(&ManifestFetcher::OnLoadComplete, base::Unretained(this))); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ManifestFetcher::Cancel() { | 42 void ManifestFetcher::Cancel() { |
| 43 DCHECK(!completed_); | 43 DCHECK(!completed_); |
| 44 fetcher_->Cancel(); | 44 fetcher_->Cancel(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void ManifestFetcher::OnLoadComplete(const blink::WebURLResponse& response, | 47 void ManifestFetcher::OnLoadComplete(const blink::WebURLResponse& response, |
| 48 const std::string& data) { | 48 const std::string& data) { |
| 49 DCHECK(!completed_); | 49 DCHECK(!completed_); |
| 50 completed_ = true; | 50 completed_ = true; |
| 51 | 51 |
| 52 Callback callback = callback_; | 52 Callback callback = callback_; |
| 53 callback.Run(response, data); | 53 callback.Run(response, data); |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // namespace content | 56 } // namespace content |
| OLD | NEW |