Roll src/third_party/WebKit fe3d0ed:840e60d (svn 202350:202351)
[chromium-blink-merge.git] / mojo / fetcher / url_resolver.cc
blob7028f894c0980a6bd79695050d69d03f269e8c94
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.
5 #include "mojo/fetcher/url_resolver.h"
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"
14 namespace mojo {
15 namespace fetcher {
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);
24 URLResolver::~URLResolver() {
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;
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);
40 } // namespace fetcher
41 } // namespace mojo