| 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" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "mojo/runner/switches.h" | 12 #include "mojo/runner/switches.h" |
| 13 #include "mojo/shell/query_util.h" | 13 #include "mojo/shell/query_util.h" |
| 14 #include "mojo/util/filename_util.h" | 14 #include "mojo/util/filename_util.h" |
| 15 #include "url/url_util.h" | 15 #include "url/url_util.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 namespace shell { | 18 namespace runner { |
| 19 | 19 |
| 20 URLResolver::URLResolver() { | 20 URLResolver::URLResolver() { |
| 21 // Needed to treat first component of mojo URLs as host, not path. | 21 // Needed to treat first component of mojo URLs as host, not path. |
| 22 url::AddStandardScheme("mojo"); | 22 url::AddStandardScheme("mojo"); |
| 23 } | 23 } |
| 24 | 24 |
| 25 URLResolver::~URLResolver() { | 25 URLResolver::~URLResolver() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 // static | 28 // static |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // Disallow invalid mappings. | 67 // Disallow invalid mappings. |
| 68 LOG(ERROR) << "Invalid origin for mapping: " << origin; | 68 LOG(ERROR) << "Invalid origin for mapping: " << origin; |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 // Force both origin and base_url to have trailing slashes. | 71 // Force both origin and base_url to have trailing slashes. |
| 72 origin_map_[origin] = util::AddTrailingSlashIfNeeded(base_url); | 72 origin_map_[origin] = util::AddTrailingSlashIfNeeded(base_url); |
| 73 } | 73 } |
| 74 | 74 |
| 75 GURL URLResolver::ApplyMappings(const GURL& url) const { | 75 GURL URLResolver::ApplyMappings(const GURL& url) const { |
| 76 std::string query; | 76 std::string query; |
| 77 GURL mapped_url = GetBaseURLAndQuery(url, &query); | 77 GURL mapped_url = shell::GetBaseURLAndQuery(url, &query); |
| 78 for (;;) { | 78 for (;;) { |
| 79 const auto& url_it = url_map_.find(mapped_url); | 79 const auto& url_it = url_map_.find(mapped_url); |
| 80 if (url_it != url_map_.end()) { | 80 if (url_it != url_map_.end()) { |
| 81 mapped_url = url_it->second; | 81 mapped_url = url_it->second; |
| 82 continue; | 82 continue; |
| 83 } | 83 } |
| 84 | 84 |
| 85 GURL origin = mapped_url.GetOrigin(); | 85 GURL origin = mapped_url.GetOrigin(); |
| 86 const auto& origin_it = origin_map_.find(origin); | 86 const auto& origin_it = origin_map_.find(origin); |
| 87 if (origin_it == origin_map_.end()) | 87 if (origin_it == origin_map_.end()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { | 105 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { |
| 106 if (mojo_url.scheme() != "mojo") { | 106 if (mojo_url.scheme() != "mojo") { |
| 107 // 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. |
| 108 return mojo_url; | 108 return mojo_url; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // It's still a mojo: URL, use the default mapping scheme. | 111 // It's still a mojo: URL, use the default mapping scheme. |
| 112 std::string query; | 112 std::string query; |
| 113 GURL base_url = GetBaseURLAndQuery(mojo_url, &query); | 113 GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query); |
| 114 if (mojo_base_url_.SchemeIsFile()) { | 114 if (mojo_base_url_.SchemeIsFile()) { |
| 115 const GURL url_with_directory( | 115 const GURL url_with_directory( |
| 116 mojo_base_url_.Resolve(base_url.host() + "/")); | 116 mojo_base_url_.Resolve(base_url.host() + "/")); |
| 117 const base::FilePath file_path(util::UrlToFilePath(url_with_directory)); | 117 const base::FilePath file_path(util::UrlToFilePath(url_with_directory)); |
| 118 if (base::DirectoryExists(file_path)) | 118 if (base::DirectoryExists(file_path)) |
| 119 return url_with_directory.Resolve(base_url.host() + ".mojo" + query); | 119 return url_with_directory.Resolve(base_url.host() + ".mojo" + query); |
| 120 } | 120 } |
| 121 return mojo_base_url_.Resolve(base_url.host() + ".mojo" + query); | 121 return mojo_base_url_.Resolve(base_url.host() + ".mojo" + query); |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace shell | 124 } // namespace runner |
| 125 } // namespace mojo | 125 } // namespace mojo |
| OLD | NEW |