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

Side by Side Diff: shell/url_resolver.cc

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

Powered by Google App Engine
This is Rietveld 408576698