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