| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/fetcher/url_resolver.h" | |
| 6 | |
| 7 #include "base/base_paths.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "mojo/shell/query_util.h" | |
| 11 #include "mojo/util/filename_util.h" | |
| 12 #include "url/url_util.h" | |
| 13 | |
| 14 namespace mojo { | |
| 15 namespace fetcher { | |
| 16 | |
| 17 URLResolver::URLResolver(const GURL& mojo_base_url) | |
| 18 : mojo_base_url_(util::AddTrailingSlashIfNeeded(mojo_base_url)) { | |
| 19 DCHECK(mojo_base_url_.is_valid()); | |
| 20 // Needed to treat first component of mojo URLs as host, not path. | |
| 21 url::AddStandardScheme("mojo", url::SCHEME_WITHOUT_AUTHORITY); | |
| 22 } | |
| 23 | |
| 24 URLResolver::~URLResolver() { | |
| 25 } | |
| 26 | |
| 27 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const { | |
| 28 if (mojo_url.scheme() != "mojo") { | |
| 29 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc. | |
| 30 return mojo_url; | |
| 31 } | |
| 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 } | |
| 39 | |
| 40 } // namespace fetcher | |
| 41 } // namespace mojo | |
| OLD | NEW |