| 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/fetcher/url_resolver.h" | 5 #include "mojo/fetcher/url_resolver.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "mojo/shell/query_util.h" | 10 #include "mojo/shell/query_util.h" |
| 11 #include "mojo/util/filename_util.h" | 11 #include "mojo/util/filename_util.h" |
| 12 #include "url/url_util.h" | 12 #include "url/url_util.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace fetcher { | 15 namespace fetcher { |
| 16 | 16 |
| 17 URLResolver::URLResolver(const GURL& mojo_base_url) | 17 URLResolver::URLResolver(const GURL& mojo_base_url) |
| 18 : mojo_base_url_(util::AddTrailingSlashIfNeeded(mojo_base_url)) { | 18 : mojo_base_url_(util::AddTrailingSlashIfNeeded(mojo_base_url)) { |
| 19 DCHECK(mojo_base_url_.is_valid()); | 19 DCHECK(mojo_base_url_.is_valid()); |
| 20 // Needed to treat first component of mojo URLs as host, not path. | 20 // Needed to treat first component of mojo URLs as host, not path. |
| 21 url::AddStandardScheme("mojo", url::SCHEME_WITHOUT_AUTHORITY); | 21 url::AddStandardScheme("mojo", url::SCHEME_WITHOUT_AUTHORITY); |
| 22 url::AddStandardScheme("exe", url::SCHEME_WITHOUT_AUTHORITY); |
| 22 } | 23 } |
| 23 | 24 |
| 24 URLResolver::~URLResolver() { | 25 URLResolver::~URLResolver() { |
| 25 } | 26 } |
| 26 | 27 |
| 27 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { | 28 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { |
| 28 if (mojo_url.scheme() != "mojo") { | 29 if (mojo_url.SchemeIs("mojo")) { |
| 30 // It's still a mojo: URL, use the default mapping scheme. |
| 31 std::string query; |
| 32 GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query); |
| 33 const std::string host = base_url.host(); |
| 34 return mojo_base_url_.Resolve(host + "/" + host + ".mojo" + query); |
| 35 } else if (mojo_url.SchemeIs("exe")) { |
| 36 #if defined OS_WIN |
| 37 std::string extension = ".exe"; |
| 38 #else |
| 39 std::string extension; |
| 40 #endif |
| 41 std::string query; |
| 42 GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query); |
| 43 return mojo_base_url_.Resolve(base_url.host() + extension); |
| 44 } else { |
| 29 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc. | 45 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc. |
| 30 return mojo_url; | 46 return mojo_url; |
| 31 } | 47 } |
| 32 | |
| 33 // It's still a mojo: URL, use the default mapping scheme. | |
| 34 std::string query; | |
| 35 GURL base_url = shell::GetBaseURLAndQuery(mojo_url, &query); | |
| 36 const std::string host = base_url.host(); | |
| 37 return mojo_base_url_.Resolve(host + "/" + host + ".mojo" + query); | |
| 38 } | 48 } |
| 39 | 49 |
| 40 } // namespace fetcher | 50 } // namespace fetcher |
| 41 } // namespace mojo | 51 } // namespace mojo |
| OLD | NEW |