Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / renderer / fetchers / manifest_fetcher.cc
blob8a39d26bb921adeb3288ae0f998444d5f9f4e809
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.
5 #include "content/renderer/fetchers/manifest_fetcher.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "content/public/renderer/resource_fetcher.h"
10 #include "third_party/WebKit/public/platform/WebURLRequest.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
13 namespace content {
15 ManifestFetcher::ManifestFetcher(const GURL& url)
16 : completed_(false) {
17 fetcher_.reset(ResourceFetcher::Create(url));
20 ManifestFetcher::~ManifestFetcher() {
21 if (!completed_)
22 Cancel();
25 void ManifestFetcher::Start(blink::WebFrame* frame,
26 bool use_credentials,
27 const Callback& callback) {
28 callback_ = callback;
30 blink::WebURLLoaderOptions options;
31 options.allowCredentials = use_credentials;
32 options.crossOriginRequestPolicy =
33 blink::WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl;
34 fetcher_->SetLoaderOptions(options);
36 fetcher_->Start(frame,
37 blink::WebURLRequest::RequestContextManifest,
38 blink::WebURLRequest::FrameTypeNone,
39 ResourceFetcher::FRAME_ASSOCIATED_LOADER,
40 base::Bind(&ManifestFetcher::OnLoadComplete,
41 base::Unretained(this)));
44 void ManifestFetcher::Cancel() {
45 DCHECK(!completed_);
46 fetcher_->Cancel();
49 void ManifestFetcher::OnLoadComplete(const blink::WebURLResponse& response,
50 const std::string& data) {
51 DCHECK(!completed_);
52 completed_ = true;
54 Callback callback = callback_;
55 callback.Run(response, data);
58 } // namespace content