Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: shell/url_resolver.h

Issue 926093003: AddOriginMapping() (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 SHELL_URL_RESOLVER_H_ 5 #ifndef SHELL_URL_RESOLVER_H_
6 #define SHELL_URL_RESOLVER_H_ 6 #define SHELL_URL_RESOLVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace shell { 16 namespace shell {
17 17
18 // This class supports the mapping of URLs to other URLs. 18 // This class supports the mapping of URLs to other URLs.
19 // It's commonly used with mojo: URL, to provide a physical location (i.e. 19 // It's commonly used with mojo: URL, to provide a physical location (i.e.
20 // file: or https:) but works with any URL. 20 // file: or https:) but works with any URL.
21 // By default, "mojo:" URLs resolve to a file location, with ".mojo" appended, 21 // By default, "mojo:" URLs resolve to a file location, with ".mojo" appended,
22 // but that resolution can be customized via the AddCustomMapping method. 22 // but that resolution can be customized via the AddCustomMapping method.
23 class URLResolver { 23 class URLResolver {
24 public: 24 public:
25 URLResolver(); 25 URLResolver();
26 ~URLResolver(); 26 ~URLResolver();
27 27
28 // Add a custom mapping for a particular URL. If |resolved_url| is 28 // Used for the return value of GetOriginMappings().
29 struct OriginMapping {
30 OriginMapping(const std::string& origin, const std::string& base_url)
31 : origin(origin), base_url(base_url) {}
32
33 const std::string origin;
34 const std::string base_url;
35 };
36
37 // Returns a list of origin mappings based on command line args.
38 // The switch --map-origin can be specified multiple times. Each occurance
39 // has the format of --map-origin={origin}={base_url}
40 // For example:
41 // --map-origin=http://domokit.org=file:///source/out
42 static std::vector<OriginMapping> GetOriginMappings(
43 const std::vector<std::string> argv);
44
45 // Add a custom mapping for a particular URL. If |mapped_url| is
29 // itself a mojo url normal resolution rules apply. 46 // itself a mojo url normal resolution rules apply.
30 void AddURLMapping(const GURL& url, const GURL& resolved_url); 47 void AddURLMapping(const GURL& url, const GURL& mapped_url);
48
49 // Add a custom mapping for all urls rooted at |origin|.
50 void AddOriginMapping(const GURL& origin, const GURL& base_url);
31 51
32 // Applies all custom mappings for |url|, returning the last non-mapped url. 52 // Applies all custom mappings for |url|, returning the last non-mapped url.
33 // For example, if 'a' maps to 'b' and 'b' maps to 'c' calling this with 'a' 53 // For example, if 'a' maps to 'b' and 'b' maps to 'c' calling this with 'a'
34 // returns 'c'. 54 // returns 'c'.
35 GURL ApplyURLMappings(const GURL& url) const; 55 GURL ApplyMappings(const GURL& url) const;
36 56
37 // If specified, then "mojo:" URLs will be resolved relative to this 57 // If specified, then "mojo:" URLs will be resolved relative to this
38 // URL. That is, the portion after the colon will be appeneded to 58 // URL. That is, the portion after the colon will be appeneded to
39 // |mojo_base_url| with .mojo appended. 59 // |mojo_base_url| with .mojo appended.
40 void SetMojoBaseURL(const GURL& mojo_base_url); 60 void SetMojoBaseURL(const GURL& mojo_base_url);
41 61
42 // Resolve the given "mojo:" URL to the URL that should be used to fetch the 62 // Resolve the given "mojo:" URL to the URL that should be used to fetch the
43 // code for the corresponding Mojo App. 63 // code for the corresponding Mojo App.
44 GURL ResolveMojoURL(const GURL& mojo_url) const; 64 GURL ResolveMojoURL(const GURL& mojo_url) const;
45 65
46 private: 66 private:
47 std::map<GURL, GURL> url_map_; 67 using GURLToGURLMap = std::map<GURL, GURL>;
68 GURLToGURLMap url_map_;
69 GURLToGURLMap origin_map_;
48 GURL mojo_base_url_; 70 GURL mojo_base_url_;
49 71
50 DISALLOW_COPY_AND_ASSIGN(URLResolver); 72 DISALLOW_COPY_AND_ASSIGN(URLResolver);
51 }; 73 };
52 74
53 } // namespace shell 75 } // namespace shell
54 } // namespace mojo 76 } // namespace mojo
55 77
56 #endif // SHELL_URL_RESOLVER_H_ 78 #endif // SHELL_URL_RESOLVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698