| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "net/base/filename_util.h" | 11 #include "net/base/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) { | 18 std::string MakeSharedLibraryName(const std::string& host_name) { |
| 19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 20 return host_name + ".dll"; | 20 return host_name + ".dll"; |
| 21 #elif defined(OS_LINUX) || defined(OS_ANDROID) | 21 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 22 return "lib" + host_name + ".so"; | 22 return "lib" + host_name + ".so"; |
| 23 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
| 24 return "lib" + host_name + ".dylib"; | 24 return host_name + ".so"; |
| 25 #else | 25 #else |
| 26 NOTREACHED() << "dynamic loading of services not supported"; | 26 NOTREACHED() << "dynamic loading of services not supported"; |
| 27 return std::string(); | 27 return std::string(); |
| 28 #endif | 28 #endif |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 MojoURLResolver::MojoURLResolver() { | 33 MojoURLResolver::MojoURLResolver() { |
| 34 // Needed to treat first component of mojo URLs as host, not path. | 34 // Needed to treat first component of mojo URLs as host, not path. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 50 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { | 50 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { |
| 51 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url); | 51 std::map<GURL, GURL>::const_iterator it = url_map_.find(mojo_url); |
| 52 if (it != url_map_.end()) | 52 if (it != url_map_.end()) |
| 53 return it->second; | 53 return it->second; |
| 54 | 54 |
| 55 std::string lib = MakeSharedLibraryName(mojo_url.host()); | 55 std::string lib = MakeSharedLibraryName(mojo_url.host()); |
| 56 | 56 |
| 57 if (local_file_set_.find(mojo_url) != local_file_set_.end()) { | 57 if (local_file_set_.find(mojo_url) != local_file_set_.end()) { |
| 58 // Resolve to a local file URL. | 58 // Resolve to a local file URL. |
| 59 base::FilePath path; | 59 base::FilePath path; |
| 60 #if defined(OS_ANDROID) | |
| 61 // On Android, additional lib are bundled. | |
| 62 PathService::Get(base::DIR_MODULE, &path); | 60 PathService::Get(base::DIR_MODULE, &path); |
| 63 #else | |
| 64 PathService::Get(base::DIR_EXE, &path); | |
| 65 #if !defined(OS_WIN) | |
| 66 path = path.Append(FILE_PATH_LITERAL("lib")); | |
| 67 #endif // !defined(OS_WIN) | |
| 68 #endif // defined(OS_ANDROID) | |
| 69 path = path.Append(base::FilePath::FromUTF8Unsafe(lib)); | 61 path = path.Append(base::FilePath::FromUTF8Unsafe(lib)); |
| 70 return net::FilePathToFileURL(path); | 62 return net::FilePathToFileURL(path); |
| 71 } | 63 } |
| 72 | 64 |
| 73 // Otherwise, resolve to an URL relative to origin_. | 65 // Otherwise, resolve to an URL relative to origin_. |
| 74 return GURL(origin_ + "/" + lib); | 66 return GURL(origin_ + "/" + lib); |
| 75 } | 67 } |
| 76 | 68 |
| 77 } // namespace shell | 69 } // namespace shell |
| 78 } // namespace mojo | 70 } // namespace mojo |
| OLD | NEW |