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/runner/url_resolver.h" | 5 #include "mojo/runner/url_resolver.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
10 #include "mojo/runner/switches.h" | 12 #include "mojo/runner/switches.h" |
11 #include "mojo/shell/query_util.h" | 13 #include "mojo/shell/query_util.h" |
12 #include "mojo/util/filename_util.h" | 14 #include "mojo/util/filename_util.h" |
13 #include "url/url_util.h" | 15 #include "url/url_util.h" |
14 | 16 |
15 namespace mojo { | 17 namespace mojo { |
16 namespace runner { | 18 namespace runner { |
17 | 19 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 104 |
103 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { | 105 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { |
104 if (mojo_url.scheme() != "mojo") { | 106 if (mojo_url.scheme() != "mojo") { |
105 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc. | 107 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc. |
106 return mojo_url; | 108 return mojo_url; |
107 } | 109 } |
108 | 110 |
109 // It's still a mojo: URL, use the default mapping scheme. | 111 // It's still a mojo: URL, use the default mapping scheme. |
110 std::string query; | 112 std::string query; |
111 GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query); | 113 GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query); |
112 const std::string host = base_url.host(); | 114 if (mojo_base_url_.SchemeIsFile()) { |
113 return mojo_base_url_.Resolve(host + "/" + host + ".mojo" + query); | 115 const GURL url_with_directory( |
| 116 mojo_base_url_.Resolve(base_url.host() + "/")); |
| 117 const base::FilePath dir(util::UrlToFilePath(url_with_directory)); |
| 118 if (base::DirectoryExists(dir)) { |
| 119 const std::string mojo_file_name(base_url.host() + ".mojo"); |
| 120 const base::FilePath mojo_path = |
| 121 dir.Append(base::FilePath::FromUTF8Unsafe(mojo_file_name)); |
| 122 // Only use the directory if the .mojo exists in the directory. |
| 123 if (base::PathExists(mojo_path)) |
| 124 return url_with_directory.Resolve(base_url.host() + ".mojo" + query); |
| 125 } |
| 126 } |
| 127 return mojo_base_url_.Resolve(base_url.host() + ".mojo" + query); |
114 } | 128 } |
115 | 129 |
116 } // namespace runner | 130 } // namespace runner |
117 } // namespace mojo | 131 } // namespace mojo |
OLD | NEW |