| 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 #include "mojo/shell/mojo_url_resolver.h" | 5 #include "mojo/shell/mojo_url_resolver.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url, | 63 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url, |
| 64 const GURL& resolved_url) { | 64 const GURL& resolved_url) { |
| 65 url_map_[mojo_url] = resolved_url; | 65 url_map_[mojo_url] = resolved_url; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) { | 68 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) { |
| 69 local_file_set_.insert(mojo_url); | 69 local_file_set_.insert(mojo_url); |
| 70 } | 70 } |
| 71 | 71 |
| 72 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { | 72 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { |
| 73 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url); | 73 const GURL mapped_url(ApplyCustomMappings(mojo_url)); |
| 74 if (it != url_map_.end()) | |
| 75 return it->second; | |
| 76 | 74 |
| 77 std::string lib = MakeSharedLibraryName(mojo_url.host()); | 75 // Continue resolving if the mapped url is a mojo: url. |
| 76 if (mapped_url.scheme() != "mojo") |
| 77 return mapped_url; |
| 78 |
| 79 std::string lib = MakeSharedLibraryName(mapped_url.host()); |
| 78 | 80 |
| 79 if (!base_url_.is_valid() || | 81 if (!base_url_.is_valid() || |
| 80 local_file_set_.find(mojo_url) != local_file_set_.end()) { | 82 local_file_set_.find(mapped_url) != local_file_set_.end()) { |
| 81 // Resolve to a local file URL. | 83 // Resolve to a local file URL. |
| 82 return default_base_url_.Resolve(lib); | 84 return default_base_url_.Resolve(lib); |
| 83 } | 85 } |
| 84 | 86 |
| 85 // Otherwise, resolve to an URL relative to base_url_. | 87 // Otherwise, resolve to an URL relative to base_url_. |
| 86 return base_url_.Resolve(lib); | 88 return base_url_.Resolve(lib); |
| 87 } | 89 } |
| 88 | 90 |
| 91 GURL MojoURLResolver::ApplyCustomMappings(const GURL& url) const { |
| 92 GURL mapped_url(url); |
| 93 for (;;) { |
| 94 std::map<GURL, GURL>::const_iterator it = url_map_.find(mapped_url); |
| 95 if (it == url_map_.end()) |
| 96 return mapped_url; |
| 97 mapped_url = it->second; |
| 98 } |
| 99 return mapped_url; |
| 100 } |
| 101 |
| 89 } // namespace shell | 102 } // namespace shell |
| 90 } // namespace mojo | 103 } // namespace mojo |
| OLD | NEW |