OLD | NEW |
---|---|
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/file_util.h" | |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "net/base/filename_util.h" | 12 #include "net/base/filename_util.h" |
12 #include "url/url_util.h" | 13 #include "url/url_util.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace shell { | 16 namespace shell { |
16 namespace { | 17 namespace { |
17 | 18 |
18 std::string MakeSharedLibraryName(const std::string& host_name) { | 19 void MakeSharedLibraryNames(const std::string& host_name, |
20 std::vector<std::string>* names) { | |
19 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
20 return host_name + ".dll"; | 22 names->push_back(host_name + ".dll"); |
21 #elif defined(OS_LINUX) || defined(OS_ANDROID) | 23 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
22 return "lib" + host_name + ".so"; | 24 names->push_back("lib" + host_name + ".so"); |
25 #if defined(OS_ANDROID) | |
26 names->push_back("lib" + host_name + ".cr.so"); | |
qsr
2014/06/26 12:31:47
The component build on android names its library .
viettrungluu
2014/06/26 16:59:57
So I learned that we're probably doing it wrong, a
qsr
2014/06/27 11:18:18
Hum... Very nice. That also probably explain my is
| |
27 #endif | |
23 #elif defined(OS_MACOSX) | 28 #elif defined(OS_MACOSX) |
24 return "lib" + host_name + ".dylib"; | 29 names->push_back("lib" + host_name + ".dylib"); |
25 #else | 30 #else |
26 NOTREACHED() << "dynamic loading of services not supported"; | 31 NOTREACHED() << "dynamic loading of services not supported"; |
27 return std::string(); | |
28 #endif | 32 #endif |
29 } | 33 } |
30 | 34 |
31 } // namespace | 35 } // namespace |
32 | 36 |
33 MojoURLResolver::MojoURLResolver() { | 37 MojoURLResolver::MojoURLResolver() { |
34 // Needed to treat first component of mojo URLs as host, not path. | 38 // Needed to treat first component of mojo URLs as host, not path. |
35 url::AddStandardScheme("mojo"); | 39 url::AddStandardScheme("mojo"); |
36 } | 40 } |
37 | 41 |
38 MojoURLResolver::~MojoURLResolver() { | 42 MojoURLResolver::~MojoURLResolver() { |
39 } | 43 } |
40 | 44 |
41 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url, | 45 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url, |
42 const GURL& resolved_url) { | 46 const GURL& resolved_url) { |
43 url_map_[mojo_url] = resolved_url; | 47 url_map_[mojo_url] = resolved_url; |
44 } | 48 } |
45 | 49 |
46 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) { | 50 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) { |
47 local_file_set_.insert(mojo_url); | 51 local_file_set_.insert(mojo_url); |
48 } | 52 } |
49 | 53 |
50 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { | 54 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { |
51 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url); | 55 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url); |
52 if (it != url_map_.end()) | 56 if (it != url_map_.end()) |
53 return it->second; | 57 return it->second; |
54 | 58 |
55 std::string lib = MakeSharedLibraryName(mojo_url.host()); | 59 |
60 std::vector<std::string> libs; | |
61 MakeSharedLibraryNames(mojo_url.host(), &libs); | |
62 DCHECK(!libs.empty()); | |
56 | 63 |
57 if (local_file_set_.find(mojo_url) != local_file_set_.end()) { | 64 if (local_file_set_.find(mojo_url) != local_file_set_.end()) { |
58 // Resolve to a local file URL. | 65 // Resolve to a local file URL. |
59 base::FilePath path; | 66 base::FilePath base_path; |
60 #if defined(OS_ANDROID) | 67 #if defined(OS_ANDROID) |
61 // On Android, additional lib are bundled. | 68 // On Android, additional lib are bundled. |
62 PathService::Get(base::DIR_MODULE, &path); | 69 PathService::Get(base::DIR_MODULE, &base_path); |
63 #else | 70 #else |
64 PathService::Get(base::DIR_EXE, &path); | 71 PathService::Get(base::DIR_EXE, &base_path); |
65 #if !defined(OS_WIN) | 72 #if !defined(OS_WIN) |
66 path = path.Append(FILE_PATH_LITERAL("lib")); | 73 base_path = base_path.Append(FILE_PATH_LITERAL("lib")); |
67 #endif // !defined(OS_WIN) | 74 #endif // !defined(OS_WIN) |
68 #endif // defined(OS_ANDROID) | 75 #endif // defined(OS_ANDROID) |
69 path = path.Append(base::FilePath::FromUTF8Unsafe(lib)); | 76 for (std::vector<std::string>::iterator it = libs.begin(); it != libs.end(); |
70 return net::FilePathToFileURL(path); | 77 ++it) { |
78 base::FilePath path = | |
79 base_path.Append(base::FilePath::FromUTF8Unsafe(*it)); | |
80 if (base::PathExists(path)) { | |
81 return net::FilePathToFileURL(path); | |
82 } | |
83 } | |
71 } | 84 } |
72 | 85 |
73 // Otherwise, resolve to an URL relative to origin_. | 86 // Otherwise, resolve to an URL relative to origin_. |
74 return GURL(origin_ + "/" + lib); | 87 return GURL(origin_ + "/" + libs[0]); |
75 } | 88 } |
76 | 89 |
77 } // namespace shell | 90 } // namespace shell |
78 } // namespace mojo | 91 } // namespace mojo |
OLD | NEW |