Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: mojo/fetcher/url_resolver.cc

Issue 1563413002: Move fetchers into mojo/shell/fetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/fetcher/url_resolver.h ('k') | mojo/fetcher/url_resolver_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 url::AddStandardScheme("exe", url::SCHEME_WITHOUT_AUTHORITY);
23 }
24
25 URLResolver::~URLResolver() {
26 }
27
28 GURL URLResolver::ResolveMojoURL(const GURL& mojo_url) const {
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 {
45 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc.
46 return mojo_url;
47 }
48 }
49
50 } // namespace fetcher
51 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/fetcher/url_resolver.h ('k') | mojo/fetcher/url_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698