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 #ifndef CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ |
| 6 #define CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "content/renderer/fetchers/web_url_loader_client_impl.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 namespace blink { |
| 20 class WebFrame; |
| 21 class WebURLLoader; |
| 22 struct WebURLError; |
| 23 } |
| 24 |
| 25 namespace content { |
| 26 |
| 27 // Helper class to download a Web Manifest. When an instance is created, the |
| 28 // caller need to call Start() and wait for the passed callback to be executed. |
| 29 // If the fetch fails, the callback will be called with two empty objects. |
| 30 // |
| 31 // This class is not using ResourceFetcher because ResourceFetcherImpl is using |
| 32 // Platform::createURLLoader() instead of createAssociatedURLLoader(). The |
| 33 // former is too permissive with regards to CORS and mixed content. |
| 34 class ManifestFetcher : public WebURLLoaderClientImpl { |
| 35 public: |
| 36 // This will be called asynchronously after the URL has been fetched, |
| 37 // successfully or not. If there is a failure, response and data will both be |
| 38 // empty. |response| and |data| are both valid until the URLFetcher instance |
| 39 // is destroyed. |
| 40 typedef base::Callback<void(const blink::WebURLResponse& response, |
| 41 const std::string& data)> Callback; |
| 42 |
| 43 explicit ManifestFetcher(const GURL& url); |
| 44 virtual ~ManifestFetcher(); |
| 45 |
| 46 void Start(blink::WebFrame* frame, const Callback& callback); |
| 47 virtual void Cancel() OVERRIDE; |
| 48 |
| 49 private: |
| 50 // WebURLLoaderClientImpl methods. |
| 51 virtual void OnLoadComplete() OVERRIDE; |
| 52 |
| 53 scoped_ptr<blink::WebURLLoader> loader_; |
| 54 |
| 55 // Request to send. Released once Start() is called. |
| 56 blink::WebURLRequest request_; |
| 57 |
| 58 // Callback when we're done. |
| 59 Callback callback_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(ManifestFetcher); |
| 62 }; |
| 63 |
| 64 } // namespace content |
| 65 |
| 66 #endif // CONTENT_RENDERER_FETCHERS_MANIFEST_FETCHER_H_ |
OLD | NEW |