OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/context.h" | 5 #include "shell/context.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (command_line->HasSwitch(switches::kURLMappings)) { | 130 if (command_line->HasSwitch(switches::kURLMappings)) { |
131 const std::string mappings = | 131 const std::string mappings = |
132 command_line->GetSwitchValueASCII(switches::kURLMappings); | 132 command_line->GetSwitchValueASCII(switches::kURLMappings); |
133 | 133 |
134 base::StringPairs pairs; | 134 base::StringPairs pairs; |
135 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) | 135 if (!base::SplitStringIntoKeyValuePairs(mappings, '=', ',', &pairs)) |
136 return false; | 136 return false; |
137 using StringPair = std::pair<std::string, std::string>; | 137 using StringPair = std::pair<std::string, std::string>; |
138 for (const StringPair& pair : pairs) { | 138 for (const StringPair& pair : pairs) { |
139 const GURL from(pair.first); | 139 const GURL from(pair.first); |
140 const GURL to(pair.second); | 140 const GURL to = context->ResolveCommandLineURL(pair.second); |
141 if (!from.is_valid() || !to.is_valid()) | 141 if (!from.is_valid() || !to.is_valid()) |
142 return false; | 142 return false; |
143 resolver->AddCustomMapping(from, to); | 143 resolver->AddCustomMapping(from, to); |
144 } | 144 } |
145 } | 145 } |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 } // namespace | 149 } // namespace |
150 | 150 |
151 Context::Context() : application_manager_(this) { | 151 Context::Context() : application_manager_(this) { |
152 DCHECK(!base::MessageLoop::current()); | 152 DCHECK(!base::MessageLoop::current()); |
153 | 153 |
154 // By default assume that the local apps reside alongside the shell. | 154 // By default assume that the local apps reside alongside the shell. |
155 // TODO(ncbray): really, this should be passed in rather than defaulting. | 155 // TODO(ncbray): really, this should be passed in rather than defaulting. |
156 // This default makes sense for desktop but not Android. | 156 // This default makes sense for desktop but not Android. |
157 base::FilePath shell_dir; | 157 base::FilePath shell_dir; |
158 PathService::Get(base::DIR_MODULE, &shell_dir); | 158 PathService::Get(base::DIR_MODULE, &shell_dir); |
159 SetShellFileRoot(shell_dir); | 159 SetShellFileRoot(shell_dir); |
| 160 |
| 161 base::FilePath cwd; |
| 162 PathService::Get(base::DIR_CURRENT, &cwd); |
| 163 SetCommandLineCWD(cwd); |
160 } | 164 } |
161 | 165 |
162 Context::~Context() { | 166 Context::~Context() { |
163 DCHECK(!base::MessageLoop::current()); | 167 DCHECK(!base::MessageLoop::current()); |
164 } | 168 } |
165 | 169 |
166 void Context::EnsureEmbedderIsInitialized() { | 170 void Context::EnsureEmbedderIsInitialized() { |
167 setup.Get(); | 171 setup.Get(); |
168 } | 172 } |
169 | 173 |
170 void Context::SetShellFileRoot(const base::FilePath& path) { | 174 void Context::SetShellFileRoot(const base::FilePath& path) { |
171 shell_file_root_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path)); | 175 shell_file_root_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path)); |
172 } | 176 } |
173 | 177 |
174 GURL Context::ResolveShellFileURL(const std::string& path) { | 178 GURL Context::ResolveShellFileURL(const std::string& path) { |
175 return shell_file_root_.Resolve(path); | 179 return shell_file_root_.Resolve(path); |
176 } | 180 } |
177 | 181 |
| 182 void Context::SetCommandLineCWD(const base::FilePath& path) { |
| 183 command_line_cwd_ = AddTrailingSlashIfNeeded(FilePathToFileURL(path)); |
| 184 } |
| 185 |
| 186 GURL Context::ResolveCommandLineURL(const std::string& path) { |
| 187 return command_line_cwd_.Resolve(path); |
| 188 } |
| 189 |
178 bool Context::Init() { | 190 bool Context::Init() { |
179 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 191 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
180 | 192 |
181 if (command_line->HasSwitch(switches::kWaitForDebugger)) | 193 if (command_line->HasSwitch(switches::kWaitForDebugger)) |
182 base::debug::WaitForDebugger(60, true); | 194 base::debug::WaitForDebugger(60, true); |
183 | 195 |
184 EnsureEmbedderIsInitialized(); | 196 EnsureEmbedderIsInitialized(); |
185 task_runners_.reset( | 197 task_runners_.reset( |
186 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); | 198 new TaskRunners(base::MessageLoop::current()->message_loop_proxy())); |
187 | 199 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 ScopedMessagePipeHandle Context::ConnectToServiceByName( | 268 ScopedMessagePipeHandle Context::ConnectToServiceByName( |
257 const GURL& application_url, | 269 const GURL& application_url, |
258 const std::string& service_name) { | 270 const std::string& service_name) { |
259 app_urls_.insert(application_url); | 271 app_urls_.insert(application_url); |
260 return application_manager_.ConnectToServiceByName(application_url, | 272 return application_manager_.ConnectToServiceByName(application_url, |
261 service_name).Pass(); | 273 service_name).Pass(); |
262 } | 274 } |
263 | 275 |
264 } // namespace shell | 276 } // namespace shell |
265 } // namespace mojo | 277 } // namespace mojo |
OLD | NEW |