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

Side by Side Diff: shell/mojo_url_resolver.cc

Issue 868283006: Rename MojoURLResolver to URLResolver (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Fix test Created 5 years, 10 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 | « shell/mojo_url_resolver.h ('k') | shell/mojo_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 "shell/mojo_url_resolver.h"
6
7 #include "base/base_paths.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "shell/filename_util.h"
11 #include "url/url_util.h"
12
13 namespace mojo {
14 namespace shell {
15
16 MojoURLResolver::MojoURLResolver() {
17 // Needed to treat first component of mojo URLs as host, not path.
18 url::AddStandardScheme("mojo");
19 }
20
21 MojoURLResolver::~MojoURLResolver() {
22 }
23
24 void MojoURLResolver::SetBaseURL(const GURL& base_url) {
25 DCHECK(base_url.is_valid());
26 // Force a trailing slash on the base_url to simplify resolving
27 // relative files and URLs below.
28 base_url_ = AddTrailingSlashIfNeeded(base_url);
29 }
30
31 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url,
32 const GURL& resolved_url) {
33 url_map_[mojo_url] = resolved_url;
34 }
35
36 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
37 const GURL mapped_url(ApplyCustomMappings(mojo_url));
38
39 if (mapped_url.scheme() != "mojo") {
40 // The mapping has produced some sort of non-mojo: URL - file:, http:, etc.
41 return mapped_url;
42 } else {
43 // It's still a mojo: URL, use the default mapping scheme.
44 std::string lib = mapped_url.host() + ".mojo";
45 return base_url_.Resolve(lib);
46 }
47 }
48
49 GURL MojoURLResolver::ApplyCustomMappings(const GURL& url) const {
50 GURL mapped_url(url);
51 for (;;) {
52 std::map<GURL, GURL>::const_iterator it = url_map_.find(mapped_url);
53 if (it == url_map_.end())
54 break;
55 mapped_url = it->second;
56 }
57 return mapped_url;
58 }
59
60 } // namespace shell
61 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/mojo_url_resolver.h ('k') | shell/mojo_url_resolver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698