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

Side by Side Diff: mojo/shell/mojo_url_resolver.cc

Issue 713513002: Change mojo application name to {name}.mojo (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add missing library. Created 6 years, 1 month 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/services/window_manager/BUILD.gn ('k') | mojo/tools/package_manager/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "mojo/shell/mojo_url_resolver.h" 5 #include "mojo/shell/mojo_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 "base/path_service.h" 10 #include "base/path_service.h"
11 #include "mojo/shell/filename_util.h" 11 #include "mojo/shell/filename_util.h"
12 #include "url/url_util.h" 12 #include "url/url_util.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace shell { 15 namespace shell {
16 namespace { 16 namespace {
17 17
18 std::string MakeSharedLibraryName(const std::string& host_name) {
19 #if defined(OS_WIN)
20 return host_name + ".dll";
21 #elif defined(OS_LINUX) || defined(OS_ANDROID)
22 return "lib" + host_name + ".so";
23 #elif defined(OS_MACOSX)
24 return host_name + ".so";
25 #else
26 NOTREACHED() << "dynamic loading of services not supported";
27 return std::string();
28 #endif
29 }
30
31 GURL AddTrailingSlashIfNeeded(const GURL& url) { 18 GURL AddTrailingSlashIfNeeded(const GURL& url) {
32 if (!url.has_path() || *url.path().rbegin() == '/') 19 if (!url.has_path() || *url.path().rbegin() == '/')
33 return url; 20 return url;
34 21
35 std::string path(url.path() + '/'); 22 std::string path(url.path() + '/');
36 GURL::Replacements replacements; 23 GURL::Replacements replacements;
37 replacements.SetPathStr(path); 24 replacements.SetPathStr(path);
38 return url.ReplaceComponents(replacements); 25 return url.ReplaceComponents(replacements);
39 } 26 }
40 27
(...skipping 28 matching lines...) Expand all
69 local_file_set_.insert(mojo_url); 56 local_file_set_.insert(mojo_url);
70 } 57 }
71 58
72 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { 59 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
73 const GURL mapped_url(ApplyCustomMappings(mojo_url)); 60 const GURL mapped_url(ApplyCustomMappings(mojo_url));
74 61
75 // Continue resolving if the mapped url is a mojo: url. 62 // Continue resolving if the mapped url is a mojo: url.
76 if (mapped_url.scheme() != "mojo") 63 if (mapped_url.scheme() != "mojo")
77 return mapped_url; 64 return mapped_url;
78 65
79 std::string lib = MakeSharedLibraryName(mapped_url.host()); 66 std::string lib = mapped_url.host() + ".mojo";
80 67
81 if (!base_url_.is_valid() || 68 if (!base_url_.is_valid() ||
82 local_file_set_.find(mapped_url) != local_file_set_.end()) { 69 local_file_set_.find(mapped_url) != local_file_set_.end()) {
83 // Resolve to a local file URL. 70 // Resolve to a local file URL.
84 return default_base_url_.Resolve(lib); 71 return default_base_url_.Resolve(lib);
85 } 72 }
86 73
87 // Otherwise, resolve to an URL relative to base_url_. 74 // Otherwise, resolve to an URL relative to base_url_.
88 return base_url_.Resolve(lib); 75 return base_url_.Resolve(lib);
89 } 76 }
90 77
91 GURL MojoURLResolver::ApplyCustomMappings(const GURL& url) const { 78 GURL MojoURLResolver::ApplyCustomMappings(const GURL& url) const {
92 GURL mapped_url(url); 79 GURL mapped_url(url);
93 for (;;) { 80 for (;;) {
94 std::map<GURL, GURL>::const_iterator it = url_map_.find(mapped_url); 81 std::map<GURL, GURL>::const_iterator it = url_map_.find(mapped_url);
95 if (it == url_map_.end()) 82 if (it == url_map_.end())
96 break; 83 break;
97 mapped_url = it->second; 84 mapped_url = it->second;
98 } 85 }
99 return mapped_url; 86 return mapped_url;
100 } 87 }
101 88
102 } // namespace shell 89 } // namespace shell
103 } // namespace mojo 90 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/window_manager/BUILD.gn ('k') | mojo/tools/package_manager/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698