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

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

Issue 327523004: Introduce very beginning of navigation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 | Annotate | Revision Log
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 "net/base/filename_util.h" 11 #include "net/base/filename_util.h"
12 #include "url/url_util.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 namespace shell { 15 namespace shell {
15 namespace { 16 namespace {
16 17
17 std::string MakeSharedLibraryName(const std::string& file_name) { 18 std::string MakeSharedLibraryName(const std::string& host_name) {
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 return file_name + ".dll"; 20 return host_name + ".dll";
20 #elif defined(OS_LINUX) 21 #elif defined(OS_LINUX)
21 return "lib" + file_name + ".so"; 22 return "lib" + host_name + ".so";
22 #elif defined(OS_MACOSX) 23 #elif defined(OS_MACOSX)
23 return "lib" + file_name + ".dylib"; 24 return "lib" + host_name + ".dylib";
24 #else 25 #else
25 NOTREACHED() << "dynamic loading of services not supported"; 26 NOTREACHED() << "dynamic loading of services not supported";
26 return std::string(); 27 return std::string();
27 #endif 28 #endif
28 } 29 }
29 30
30 } // namespace 31 } // namespace
31 32
32 MojoURLResolver::MojoURLResolver() { 33 MojoURLResolver::MojoURLResolver() {
34 // Needed to treat first component of mojo URLs as host, not path.
35 url::AddStandardScheme("mojo");
33 } 36 }
34 37
35 MojoURLResolver::~MojoURLResolver() { 38 MojoURLResolver::~MojoURLResolver() {
36 } 39 }
37 40
38 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url, 41 void MojoURLResolver::AddCustomMapping(const GURL& mojo_url,
39 const GURL& resolved_url) { 42 const GURL& resolved_url) {
40 url_map_[mojo_url] = resolved_url; 43 url_map_[mojo_url] = resolved_url;
41 } 44 }
42 45
43 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) { 46 void MojoURLResolver::AddLocalFileMapping(const GURL& mojo_url) {
44 local_file_set_.insert(mojo_url); 47 local_file_set_.insert(mojo_url);
45 } 48 }
46 49
47 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const { 50 GURL MojoURLResolver::Resolve(const GURL& mojo_url) const {
48 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);
49 if (it != url_map_.end()) 52 if (it != url_map_.end())
50 return it->second; 53 return it->second;
51 54
52 std::string lib = MakeSharedLibraryName(mojo_url.ExtractFileName()); 55 std::string lib = MakeSharedLibraryName(mojo_url.host());
53 56
54 if (local_file_set_.find(mojo_url) != local_file_set_.end()) { 57 if (local_file_set_.find(mojo_url) != local_file_set_.end()) {
55 // Resolve to a local file URL. 58 // Resolve to a local file URL.
56 base::FilePath path; 59 base::FilePath path;
57 PathService::Get(base::DIR_EXE, &path); 60 PathService::Get(base::DIR_EXE, &path);
58 #if !defined(OS_WIN) 61 #if !defined(OS_WIN)
59 path = path.Append(FILE_PATH_LITERAL("lib")); 62 path = path.Append(FILE_PATH_LITERAL("lib"));
60 #endif 63 #endif
61 path = path.Append(base::FilePath::FromUTF8Unsafe(lib)); 64 path = path.Append(base::FilePath::FromUTF8Unsafe(lib));
62 return net::FilePathToFileURL(path); 65 return net::FilePathToFileURL(path);
63 } 66 }
64 67
65 // Otherwise, resolve to an URL relative to origin_. 68 // Otherwise, resolve to an URL relative to origin_.
66 return GURL(origin_ + "/" + lib); 69 return GURL(origin_ + "/" + lib);
67 } 70 }
68 71
69 } // namespace shell 72 } // namespace shell
70 } // namespace mojo 73 } // namespace mojo
OLDNEW
« mojo/services/navigation/navigation.mojom ('K') | « mojo/services/navigation/navigation.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698