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 SHELL_MOJO_URL_RESOLVER_H_ | |
6 #define SHELL_MOJO_URL_RESOLVER_H_ | |
7 | |
8 #include <map> | |
9 #include <set> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/files/file_path.h" | |
13 #include "url/gurl.h" | |
14 | |
15 namespace mojo { | |
16 namespace shell { | |
17 | |
18 // This class resolves "mojo:" URLs to physical URLs (e.g., "file:" and | |
19 // "https:" URLs). By default, "mojo:" URLs resolve to a file location, but | |
20 // that resolution can be customized via the AddCustomMapping method. | |
21 class MojoURLResolver { | |
22 public: | |
23 MojoURLResolver(); | |
24 ~MojoURLResolver(); | |
25 | |
26 // If specified, then unknown "mojo:" URLs will be resolved relative to this | |
27 // base URL. That is, the portion after the colon will be appeneded to | |
28 // |base_url| with platform-specific shared library prefix and suffix | |
29 // inserted. | |
30 void SetBaseURL(const GURL& base_url); | |
31 | |
32 // Add a custom mapping for a particular "mojo:" URL. If |resolved_url| is | |
33 // itself a mojo url normal resolution rules apply. | |
34 void AddCustomMapping(const GURL& mojo_url, const GURL& resolved_url); | |
35 | |
36 // Resolve the given "mojo:" URL to the URL that should be used to fetch the | |
37 // code for the corresponding Mojo App. | |
38 GURL Resolve(const GURL& mojo_url) const; | |
39 | |
40 // Applies all custom mappings for |url|, returning the last non-mapped url. | |
41 // For example, if 'a' maps to 'b' and 'b' maps to 'c' calling this with 'a' | |
42 // returns 'c'. | |
43 GURL ApplyCustomMappings(const GURL& url) const; | |
44 | |
45 private: | |
46 std::map<GURL, GURL> url_map_; | |
47 GURL base_url_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(MojoURLResolver); | |
50 }; | |
51 | |
52 } // namespace shell | |
53 } // namespace mojo | |
54 | |
55 #endif // SHELL_MOJO_URL_RESOLVER_H_ | |
OLD | NEW |