| Index: content/renderer/fetchers/manifest_fetcher.h
|
| diff --git a/content/renderer/fetchers/manifest_fetcher.h b/content/renderer/fetchers/manifest_fetcher.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b9252c2ee2f1e682609801b7e2c433e03eda5bb5
|
| --- /dev/null
|
| +++ b/content/renderer/fetchers/manifest_fetcher.h
|
| @@ -0,0 +1,87 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_
|
| +#define CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/callback.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
|
| +#include "third_party/WebKit/public/platform/WebURLRequest.h"
|
| +#include "third_party/WebKit/public/platform/WebURLResponse.h"
|
| +
|
| +class GURL;
|
| +
|
| +namespace blink {
|
| +class WebFrame;
|
| +class WebURLLoader;
|
| +struct WebURLError;
|
| +}
|
| +
|
| +namespace content {
|
| +
|
| +// Helper class to download a Web Manifest. When an instance is created, the
|
| +// caller need to call Start() and wait for the passed callback to be executed.
|
| +// If the fetch fails, the callback will be called with two empty objects.
|
| +//
|
| +// This class is not using ResourceFetcher because ResourceFetcherImpl is using
|
| +// Platform::createURLLoader() instead of createAssociatedURLLoader(). The
|
| +// former is too permissive with regards to CORS and mixed content.
|
| +class ManifestFetcher : public blink::WebURLLoaderClient {
|
| + public:
|
| + // This will be called asynchronously after the URL has been fetched,
|
| + // successfully or not. If there is a failure, response and data will both be
|
| + // empty. |response| and |data| are both valid until the URLFetcher instance
|
| + // is destroyed.
|
| + typedef base::Callback<void(const blink::WebURLResponse& response,
|
| + const std::string& data)> Callback;
|
| +
|
| + explicit ManifestFetcher(const GURL& url);
|
| + virtual ~ManifestFetcher();
|
| +
|
| + void Start(blink::WebFrame* frame, const Callback& callback);
|
| + void Cancel();
|
| +
|
| + private:
|
| + void RunCallback(const blink::WebURLResponse& response,
|
| + const std::string& data);
|
| +
|
| + // WebURLLoaderClient implementation.
|
| + virtual void didReceiveResponse(
|
| + blink::WebURLLoader* loader, const blink::WebURLResponse& response);
|
| + virtual void didReceiveData(
|
| + blink::WebURLLoader* loader, const char* data, int data_length,
|
| + int encoded_data_length);
|
| + virtual void didFinishLoading(
|
| + blink::WebURLLoader* loader, double finishTime,
|
| + int64_t total_encoded_data_length);
|
| + virtual void didFail(
|
| + blink::WebURLLoader* loader, const blink::WebURLError& error);
|
| +
|
| + scoped_ptr<blink::WebURLLoader> loader_;
|
| +
|
| + // Request to send. Released once Start() is called.
|
| + blink::WebURLRequest request_;
|
| +
|
| + // Set to true once the request is complete.
|
| + bool completed_;
|
| +
|
| + // Buffer to hold the content from the server.
|
| + std::string data_;
|
| +
|
| + // A copy of the original resource response.
|
| + blink::WebURLResponse response_;
|
| +
|
| + // Callback when we're done.
|
| + Callback callback_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ManifestFetcher);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_
|
|
|