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