OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_FETCHER_ABOUT_FETCHER_H_ | 5 #ifndef MOJO_FETCHER_DATA_FETCHER_H_ |
6 #define MOJO_FETCHER_ABOUT_FETCHER_H_ | 6 #define MOJO_FETCHER_DATA_FETCHER_H_ |
7 | 7 |
8 #include "mojo/shell/fetcher.h" | 8 #include "mojo/shell/fetcher.h" |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 11 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace fetcher { | 15 namespace fetcher { |
16 | 16 |
17 // Implements Fetcher for about: URLs. | 17 // Implements Fetcher for data: URLs. |
18 class AboutFetcher : public shell::Fetcher { | 18 class DataFetcher : public shell::Fetcher { |
19 public: | 19 public: |
20 static const char kAboutScheme[]; | |
21 static const char kAboutBlankURL[]; | |
22 | |
23 static void Start(const GURL& url, const FetchCallback& loader_callback); | 20 static void Start(const GURL& url, const FetchCallback& loader_callback); |
24 | 21 |
25 private: | 22 private: |
26 AboutFetcher(const GURL& url, const FetchCallback& loader_callback); | 23 DataFetcher(const GURL& url, const FetchCallback& loader_callback); |
27 ~AboutFetcher() override; | 24 ~DataFetcher() override; |
28 | 25 |
29 void BuildResponse(); | 26 void BuildAndDispatchResponse(); |
30 | |
31 // Must be called exactly once to run the loader callback (asynchrously). On | |
32 // success, the ownership of this object is passed to the loader callback; | |
33 // otherwise, the callback is run with a nullptr and this object is destroyed. | |
34 void PostToRunCallback(bool success); | |
35 | 27 |
36 // shell::Fetcher implementation. | 28 // shell::Fetcher implementation. |
37 const GURL& GetURL() const override; | 29 const GURL& GetURL() const override; |
38 GURL GetRedirectURL() const override; | 30 GURL GetRedirectURL() const override; |
39 GURL GetRedirectReferer() const override; | 31 GURL GetRedirectReferer() const override; |
40 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | 32 URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, |
41 uint32_t skip) override; | 33 uint32_t skip) override; |
42 void AsPath( | 34 void AsPath( |
43 base::TaskRunner* task_runner, | 35 base::TaskRunner* task_runner, |
44 base::Callback<void(const base::FilePath&, bool)> callback) override; | 36 base::Callback<void(const base::FilePath&, bool)> callback) override; |
45 std::string MimeType() override; | 37 std::string MimeType() override; |
46 bool HasMojoMagic() override; | 38 bool HasMojoMagic() override; |
47 bool PeekFirstLine(std::string* line) override; | 39 bool PeekFirstLine(std::string* line) override; |
48 | 40 |
49 const GURL url_; | 41 const GURL url_; |
50 URLResponsePtr response_; | 42 URLResponsePtr response_; |
51 | 43 |
52 DISALLOW_COPY_AND_ASSIGN(AboutFetcher); | 44 DISALLOW_COPY_AND_ASSIGN(DataFetcher); |
53 }; | 45 }; |
54 | 46 |
55 } // namespace fetcher | 47 } // namespace fetcher |
56 } // namespace mojo | 48 } // namespace mojo |
57 | 49 |
58 #endif // MOJO_FETCHER_ABOUT_FETCHER_H_ | 50 #endif // MOJO_FETCHER_DATA_FETCHER_H_ |
OLD | NEW |