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/application_manager.h" | 5 #include "mojo/shell/application_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 STLDeleteValues(&identity_to_instance_); | 71 STLDeleteValues(&identity_to_instance_); |
72 } | 72 } |
73 | 73 |
74 void ApplicationManager::ConnectToApplication( | 74 void ApplicationManager::ConnectToApplication( |
75 ApplicationInstance* originator, | 75 ApplicationInstance* originator, |
76 mojo::URLRequestPtr requested_url, | 76 mojo::URLRequestPtr requested_url, |
77 const std::string& qualifier, | 77 const std::string& qualifier, |
78 const GURL& requestor_url, | 78 const GURL& requestor_url, |
79 InterfaceRequest<ServiceProvider> services, | 79 InterfaceRequest<ServiceProvider> services, |
80 ServiceProviderPtr exposed_services, | 80 ServiceProviderPtr exposed_services, |
81 const CapabilityFilter& filter, | 81 const CapabilityFilter& capability_filter, |
82 const base::Closure& on_application_end, | 82 const base::Closure& on_application_end, |
83 const Shell::ConnectToApplicationCallback& connect_callback) { | 83 const Shell::ConnectToApplicationCallback& connect_callback) { |
84 GURL requested_gurl(requested_url->url.To<std::string>()); | 84 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
85 TRACE_EVENT_INSTANT1( | 85 params->SetOriginatorInfo(originator); |
86 "mojo_shell", "ApplicationManager::ConnectToApplication", | 86 params->SetURLInfo(requested_url.Pass()); |
87 TRACE_EVENT_SCOPE_THREAD, "requested_url", requested_gurl.spec()); | 87 params->set_qualifier(qualifier); |
88 DCHECK(requested_gurl.is_valid()); | 88 params->set_services(services.Pass()); |
| 89 params->set_exposed_services(exposed_services.Pass()); |
| 90 params->set_filter(capability_filter); |
| 91 params->set_on_application_end(on_application_end); |
| 92 params->set_connect_callback(connect_callback); |
| 93 |
| 94 ConnectToApplication(params.Pass()); |
| 95 } |
| 96 |
| 97 void ApplicationManager::ConnectToApplication( |
| 98 scoped_ptr<ConnectToApplicationParams> params) { |
| 99 GURL original_url = params->app_url(); |
| 100 URLRequestPtr original_url_request = params->TakeAppURLRequest(); |
| 101 |
| 102 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", |
| 103 TRACE_EVENT_SCOPE_THREAD, "original_url", |
| 104 original_url.spec()); |
| 105 DCHECK(original_url.is_valid()); |
| 106 DCHECK(original_url_request); |
89 | 107 |
90 // We check both the mapped and resolved urls for existing instances because | 108 // We check both the mapped and resolved urls for existing instances because |
91 // external applications can be registered for the unresolved mojo:foo urls. | 109 // external applications can be registered for the unresolved mojo:foo urls. |
92 | 110 |
93 GURL mapped_url = delegate_->ResolveMappings(requested_gurl); | 111 GURL mapped_url = delegate_->ResolveMappings(original_url); |
94 if (ConnectToRunningApplication(originator, mapped_url, qualifier, | 112 params->SetURLInfo(mapped_url); |
95 requestor_url, &services, &exposed_services, | 113 if (ConnectToRunningApplication(¶ms)) |
96 filter, connect_callback)) { | 114 return; |
| 115 |
| 116 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); |
| 117 params->SetURLInfo(resolved_url); |
| 118 if (ConnectToRunningApplication(¶ms)) |
| 119 return; |
| 120 |
| 121 // The application is not running, let's compute the parameters. |
| 122 // NOTE: Set URL info using |original_url_request| instead of |original_url| |
| 123 // because it may contain more information (e.g., it is a POST request). |
| 124 params->SetURLInfo(original_url_request.Pass()); |
| 125 if (ConnectToApplicationWithLoader(¶ms, mapped_url, |
| 126 GetLoaderForURL(mapped_url))) { |
97 return; | 127 return; |
98 } | 128 } |
99 | 129 |
100 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); | 130 if (ConnectToApplicationWithLoader(¶ms, resolved_url, |
101 if (ConnectToRunningApplication(originator, resolved_url, qualifier, | 131 GetLoaderForURL(resolved_url))) { |
102 requestor_url, &services, &exposed_services, | |
103 filter, connect_callback)) { | |
104 return; | 132 return; |
105 } | 133 } |
106 | 134 |
107 // The application is not running, let's compute the parameters. | 135 if (ConnectToApplicationWithLoader(¶ms, resolved_url, |
108 if (ConnectToApplicationWithLoader( | 136 default_loader_.get())) { |
109 originator, requested_gurl, qualifier, mapped_url, requestor_url, | |
110 &services, &exposed_services, filter, on_application_end, | |
111 connect_callback, GetLoaderForURL(mapped_url))) { | |
112 return; | 137 return; |
113 } | 138 } |
114 | 139 |
115 if (ConnectToApplicationWithLoader( | 140 original_url_request = params->TakeAppURLRequest(); |
116 originator, requested_gurl, qualifier, resolved_url, requestor_url, | 141 auto callback = |
117 &services, &exposed_services, filter, on_application_end, | 142 base::Bind(&ApplicationManager::HandleFetchCallback, |
118 connect_callback, GetLoaderForURL(resolved_url))) { | 143 weak_ptr_factory_.GetWeakPtr(), base::Passed(¶ms)); |
119 return; | |
120 } | |
121 | |
122 if (ConnectToApplicationWithLoader( | |
123 originator, requested_gurl, qualifier, resolved_url, requestor_url, | |
124 &services, &exposed_services, filter, on_application_end, | |
125 connect_callback, default_loader_.get())) { | |
126 return; | |
127 } | |
128 | |
129 auto callback = base::Bind( | |
130 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), | |
131 originator, requested_gurl, qualifier, requestor_url, | |
132 base::Passed(services.Pass()), base::Passed(exposed_services.Pass()), | |
133 filter, on_application_end, connect_callback); | |
134 | 144 |
135 if (delegate_->CreateFetcher( | 145 if (delegate_->CreateFetcher( |
136 resolved_url, | 146 resolved_url, |
137 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) { | 147 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) { |
138 return; | 148 return; |
139 } | 149 } |
140 | 150 |
141 if (resolved_url.SchemeIsFile()) { | 151 if (resolved_url.SchemeIsFile()) { |
142 // LocalFetcher uses the network service to infer MIME types from URLs. | 152 // LocalFetcher uses the network service to infer MIME types from URLs. |
143 // Skip this for mojo URLs to avoid recursively loading the network service. | 153 // Skip this for mojo URLs to avoid recursively loading the network service. |
144 if (!network_service_ && !requested_gurl.SchemeIs("mojo")) | 154 if (!network_service_ && !original_url.SchemeIs("mojo")) |
145 ConnectToService(GURL("mojo:network_service"), &network_service_); | 155 ConnectToService(GURL("mojo:network_service"), &network_service_); |
146 new LocalFetcher( | 156 new LocalFetcher( |
147 network_service_.get(), resolved_url, | 157 network_service_.get(), resolved_url, |
148 GetBaseURLAndQuery(resolved_url, nullptr), | 158 GetBaseURLAndQuery(resolved_url, nullptr), |
149 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); | 159 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); |
150 return; | 160 return; |
151 } | 161 } |
152 | 162 |
153 if (mapped_url.SchemeIs("mojo") && | 163 if (mapped_url.SchemeIs("mojo") && |
154 base::CommandLine::ForCurrentProcess()->HasSwitch( | 164 base::CommandLine::ForCurrentProcess()->HasSwitch( |
155 switches::kUseUpdater)) { | 165 switches::kUseUpdater)) { |
156 ConnectToService(GURL("mojo:updater"), &updater_); | 166 ConnectToService(GURL("mojo:updater"), &updater_); |
157 new UpdateFetcher( | 167 new UpdateFetcher( |
158 mapped_url, updater_.get(), | 168 mapped_url, updater_.get(), |
159 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); | 169 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE)); |
160 return; | 170 return; |
161 } | 171 } |
162 | 172 |
163 if (!url_loader_factory_) | 173 if (!url_loader_factory_) |
164 ConnectToService(GURL("mojo:network_service"), &url_loader_factory_); | 174 ConnectToService(GURL("mojo:network_service"), &url_loader_factory_); |
165 | 175 |
166 const NativeApplicationCleanup cleanup = | 176 const NativeApplicationCleanup cleanup = |
167 base::CommandLine::ForCurrentProcess()->HasSwitch( | 177 base::CommandLine::ForCurrentProcess()->HasSwitch( |
168 switches::kDontDeleteOnDownload) | 178 switches::kDontDeleteOnDownload) |
169 ? NativeApplicationCleanup::DONT_DELETE | 179 ? NativeApplicationCleanup::DONT_DELETE |
170 : NativeApplicationCleanup::DELETE; | 180 : NativeApplicationCleanup::DELETE; |
171 | 181 |
172 if (requested_gurl.SchemeIs("mojo")) { | 182 if (original_url.SchemeIs("mojo")) { |
173 // Use the resolved mojo URL in the request to support origin mapping, etc. | 183 // Use the resolved mojo URL in the request to support origin mapping, etc. |
174 mojo::URLRequestPtr resolved_url_request(mojo::URLRequest::New()); | 184 mojo::URLRequestPtr resolved_url_request(mojo::URLRequest::New()); |
175 resolved_url_request->url = resolved_url.spec(); | 185 resolved_url_request->url = resolved_url.spec(); |
176 new NetworkFetcher(disable_cache_, resolved_url_request.Pass(), | 186 new NetworkFetcher(disable_cache_, resolved_url_request.Pass(), |
177 url_loader_factory_.get(), | 187 url_loader_factory_.get(), |
178 base::Bind(callback, cleanup)); | 188 base::Bind(callback, cleanup)); |
179 return; | 189 return; |
180 } | 190 } |
181 | 191 |
182 new NetworkFetcher(disable_cache_, requested_url.Pass(), | 192 new NetworkFetcher(disable_cache_, original_url_request.Pass(), |
183 url_loader_factory_.get(), base::Bind(callback, cleanup)); | 193 url_loader_factory_.get(), base::Bind(callback, cleanup)); |
184 } | 194 } |
185 | 195 |
186 bool ApplicationManager::ConnectToRunningApplication( | 196 bool ApplicationManager::ConnectToRunningApplication( |
187 ApplicationInstance* originator, | 197 scoped_ptr<ConnectToApplicationParams>* params) { |
188 const GURL& resolved_url, | 198 ApplicationInstance* instance = GetApplicationInstance( |
189 const std::string& qualifier, | 199 Identity((*params)->app_url(), (*params)->qualifier())); |
190 const GURL& requestor_url, | |
191 InterfaceRequest<ServiceProvider>* services, | |
192 ServiceProviderPtr* exposed_services, | |
193 const CapabilityFilter& filter, | |
194 const Shell::ConnectToApplicationCallback& connect_callback) { | |
195 ApplicationInstance* instance = | |
196 GetApplicationInstance(Identity(resolved_url, qualifier)); | |
197 if (!instance) | 200 if (!instance) |
198 return false; | 201 return false; |
199 | 202 |
200 instance->ConnectToClient(originator, resolved_url, requestor_url, | 203 instance->ConnectToClient(params->Pass()); |
201 services->Pass(), exposed_services->Pass(), filter, | |
202 connect_callback); | |
203 return true; | 204 return true; |
204 } | 205 } |
205 | 206 |
206 bool ApplicationManager::ConnectToApplicationWithLoader( | 207 bool ApplicationManager::ConnectToApplicationWithLoader( |
207 ApplicationInstance* originator, | 208 scoped_ptr<ConnectToApplicationParams>* params, |
208 const GURL& requested_url, | |
209 const std::string& qualifier, | |
210 const GURL& resolved_url, | 209 const GURL& resolved_url, |
211 const GURL& requestor_url, | |
212 InterfaceRequest<ServiceProvider>* services, | |
213 ServiceProviderPtr* exposed_services, | |
214 const CapabilityFilter& filter, | |
215 const base::Closure& on_application_end, | |
216 const Shell::ConnectToApplicationCallback& connect_callback, | |
217 ApplicationLoader* loader) { | 210 ApplicationLoader* loader) { |
218 if (!loader) | 211 if (!loader) |
219 return false; | 212 return false; |
220 | 213 |
221 const GURL app_url = | 214 if (!(*params)->app_url().SchemeIs("mojo")) |
222 requested_url.SchemeIs("mojo") ? requested_url : resolved_url; | 215 (*params)->SetURLInfo(resolved_url); |
223 | 216 |
224 loader->Load( | 217 loader->Load(resolved_url, RegisterInstance(params->Pass(), nullptr)); |
225 resolved_url, | |
226 RegisterInstance(originator, app_url, qualifier, requestor_url, | |
227 services->Pass(), exposed_services->Pass(), filter, | |
228 on_application_end, connect_callback, nullptr)); | |
229 return true; | 218 return true; |
230 } | 219 } |
231 | 220 |
232 InterfaceRequest<Application> ApplicationManager::RegisterInstance( | 221 InterfaceRequest<Application> ApplicationManager::RegisterInstance( |
233 ApplicationInstance* originator, | 222 scoped_ptr<ConnectToApplicationParams> params, |
234 const GURL& app_url, | |
235 const std::string& qualifier, | |
236 const GURL& requestor_url, | |
237 InterfaceRequest<ServiceProvider> services, | |
238 ServiceProviderPtr exposed_services, | |
239 const CapabilityFilter& filter, | |
240 const base::Closure& on_application_end, | |
241 const Shell::ConnectToApplicationCallback& connect_callback, | |
242 ApplicationInstance** resulting_instance) { | 223 ApplicationInstance** resulting_instance) { |
243 Identity app_identity(app_url, qualifier); | 224 Identity app_identity(params->app_url(), params->qualifier()); |
244 | 225 |
245 ApplicationPtr application; | 226 ApplicationPtr application; |
246 InterfaceRequest<Application> application_request = GetProxy(&application); | 227 InterfaceRequest<Application> application_request = GetProxy(&application); |
247 ApplicationInstance* instance = new ApplicationInstance( | 228 ApplicationInstance* instance = new ApplicationInstance( |
248 application.Pass(), this, | 229 application.Pass(), this, params->originator_identity(), app_identity, |
249 originator ? originator->identity() : Identity(GURL()), app_identity, | 230 params->filter(), Shell::kInvalidContentHandlerID, |
250 filter, Shell::kInvalidContentHandlerID, on_application_end); | 231 params->on_application_end()); |
251 DCHECK(identity_to_instance_.find(app_identity) == | 232 DCHECK(identity_to_instance_.find(app_identity) == |
252 identity_to_instance_.end()); | 233 identity_to_instance_.end()); |
253 identity_to_instance_[app_identity] = instance; | 234 identity_to_instance_[app_identity] = instance; |
254 instance->InitializeApplication(); | 235 instance->InitializeApplication(); |
255 instance->ConnectToClient(originator, app_url, requestor_url, services.Pass(), | 236 instance->ConnectToClient(params.Pass()); |
256 exposed_services.Pass(), filter, connect_callback); | |
257 if (resulting_instance) | 237 if (resulting_instance) |
258 *resulting_instance = instance; | 238 *resulting_instance = instance; |
259 return application_request.Pass(); | 239 return application_request.Pass(); |
260 } | 240 } |
261 | 241 |
262 ApplicationInstance* ApplicationManager::GetApplicationInstance( | 242 ApplicationInstance* ApplicationManager::GetApplicationInstance( |
263 const Identity& identity) const { | 243 const Identity& identity) const { |
264 const auto& instance_it = identity_to_instance_.find(identity); | 244 const auto& instance_it = identity_to_instance_.find(identity); |
265 if (instance_it != identity_to_instance_.end()) | 245 if (instance_it != identity_to_instance_.end()) |
266 return instance_it->second; | 246 return instance_it->second; |
267 return nullptr; | 247 return nullptr; |
268 } | 248 } |
269 | 249 |
270 void ApplicationManager::HandleFetchCallback( | 250 void ApplicationManager::HandleFetchCallback( |
271 ApplicationInstance* originator, | 251 scoped_ptr<ConnectToApplicationParams> params, |
272 const GURL& requested_url, | |
273 const std::string& qualifier, | |
274 const GURL& requestor_url, | |
275 InterfaceRequest<ServiceProvider> services, | |
276 ServiceProviderPtr exposed_services, | |
277 const CapabilityFilter& filter, | |
278 const base::Closure& on_application_end, | |
279 const Shell::ConnectToApplicationCallback& connect_callback, | |
280 NativeApplicationCleanup cleanup, | 252 NativeApplicationCleanup cleanup, |
281 scoped_ptr<Fetcher> fetcher) { | 253 scoped_ptr<Fetcher> fetcher) { |
282 if (!fetcher) { | 254 if (!fetcher) { |
283 // Network error. Drop |application_request| to tell requestor. | 255 // Network error. Drop |params| to tell the requestor. |
284 connect_callback.Run(Shell::kInvalidContentHandlerID); | 256 params->connect_callback().Run(Shell::kInvalidContentHandlerID); |
285 return; | 257 return; |
286 } | 258 } |
287 | 259 |
288 GURL redirect_url = fetcher->GetRedirectURL(); | 260 GURL redirect_url = fetcher->GetRedirectURL(); |
289 if (!redirect_url.is_empty()) { | 261 if (!redirect_url.is_empty()) { |
290 // And around we go again... Whee! | 262 // And around we go again... Whee! |
291 // TODO(sky): this loses |requested_url|. | 263 // TODO(sky): this loses the original URL info. |
292 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 264 URLRequestPtr new_request = URLRequest::New(); |
293 request->url = mojo::String::From(redirect_url.spec()); | 265 new_request->url = redirect_url.spec(); |
294 HttpHeaderPtr header = HttpHeader::New(); | 266 HttpHeaderPtr header = HttpHeader::New(); |
295 header->name = "Referer"; | 267 header->name = "Referer"; |
296 header->value = fetcher->GetRedirectReferer().spec(); | 268 header->value = fetcher->GetRedirectReferer().spec(); |
297 request->headers.push_back(header.Pass()); | 269 new_request->headers.push_back(header.Pass()); |
298 ConnectToApplication(originator, request.Pass(), qualifier, requestor_url, | 270 params->SetURLInfo(new_request.Pass()); |
299 services.Pass(), exposed_services.Pass(), filter, | 271 ConnectToApplication(params.Pass()); |
300 on_application_end, connect_callback); | |
301 return; | 272 return; |
302 } | 273 } |
303 | 274 |
304 // We already checked if the application was running before we fetched it, but | 275 // We already checked if the application was running before we fetched it, but |
305 // it might have started while the fetch was outstanding. We don't want to | 276 // it might have started while the fetch was outstanding. We don't want to |
306 // have two copies of the app running, so check again. | 277 // have two copies of the app running, so check again. |
307 // | 278 // |
308 // Also, it's possible the original URL was redirected to an app that is | 279 // Also, it's possible the original URL was redirected to an app that is |
309 // already running. | 280 // already running. |
310 if (ConnectToRunningApplication(originator, requested_url, qualifier, | 281 if (ConnectToRunningApplication(¶ms)) |
311 requestor_url, &services, &exposed_services, | |
312 filter, connect_callback)) { | |
313 return; | 282 return; |
314 } | |
315 | 283 |
316 const GURL app_url = | 284 if (params->app_url().scheme() != "mojo") |
317 requested_url.scheme() == "mojo" ? requested_url : fetcher->GetURL(); | 285 params->SetURLInfo(fetcher->GetURL()); |
318 | 286 |
| 287 Identity originator_identity = params->originator_identity(); |
| 288 CapabilityFilter originator_filter = params->originator_filter(); |
| 289 CapabilityFilter filter = params->filter(); |
| 290 GURL app_url = params->app_url(); |
| 291 std::string qualifier = params->qualifier(); |
| 292 Shell::ConnectToApplicationCallback connect_callback = |
| 293 params->connect_callback(); |
| 294 params->set_connect_callback(EmptyConnectCallback()); |
319 ApplicationInstance* app = nullptr; | 295 ApplicationInstance* app = nullptr; |
320 InterfaceRequest<Application> request( | 296 InterfaceRequest<Application> request(RegisterInstance(params.Pass(), &app)); |
321 RegisterInstance(originator, app_url, qualifier, requestor_url, | |
322 services.Pass(), exposed_services.Pass(), filter, | |
323 on_application_end, EmptyConnectCallback(), &app)); | |
324 | 297 |
325 // For resources that are loaded with content handlers, we group app instances | 298 // For resources that are loaded with content handlers, we group app instances |
326 // by site. | 299 // by site. |
327 | 300 |
328 // If the response begins with a #!mojo <content-handler-url>, use it. | 301 // If the response begins with a #!mojo <content-handler-url>, use it. |
329 GURL content_handler_url; | 302 GURL content_handler_url; |
330 std::string shebang; | 303 std::string shebang; |
331 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( | 304 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( |
332 switches::kEnableMultiprocess); | 305 switches::kEnableMultiprocess); |
333 | 306 |
334 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { | 307 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { |
335 URLResponsePtr response(fetcher->AsURLResponse( | 308 URLResponsePtr response(fetcher->AsURLResponse( |
336 blocking_pool_, static_cast<int>(shebang.size()))); | 309 blocking_pool_, static_cast<int>(shebang.size()))); |
337 std::string site = | 310 std::string site = |
338 enable_multi_process ? response->site.To<std::string>() : std::string(); | 311 enable_multi_process ? response->site.To<std::string>() : std::string(); |
339 LoadWithContentHandler(originator, content_handler_url, requestor_url, site, | 312 LoadWithContentHandler(originator_identity, originator_filter, |
340 filter, connect_callback, app, request.Pass(), | 313 content_handler_url, site, filter, connect_callback, |
341 response.Pass()); | 314 app, request.Pass(), response.Pass()); |
342 return; | 315 return; |
343 } | 316 } |
344 | 317 |
345 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); | 318 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); |
346 if (iter != mime_type_to_url_.end()) { | 319 if (iter != mime_type_to_url_.end()) { |
347 URLResponsePtr response(fetcher->AsURLResponse(blocking_pool_, 0)); | 320 URLResponsePtr response(fetcher->AsURLResponse(blocking_pool_, 0)); |
348 std::string site = | 321 std::string site = |
349 enable_multi_process ? response->site.To<std::string>() : std::string(); | 322 enable_multi_process ? response->site.To<std::string>() : std::string(); |
350 LoadWithContentHandler(originator, iter->second, requestor_url, site, | 323 LoadWithContentHandler(originator_identity, originator_filter, iter->second, |
351 filter, connect_callback, app, request.Pass(), | 324 site, filter, connect_callback, app, request.Pass(), |
352 response.Pass()); | 325 response.Pass()); |
353 return; | 326 return; |
354 } | 327 } |
355 | 328 |
356 auto alias_iter = application_package_alias_.find(app_url); | 329 auto alias_iter = application_package_alias_.find(app_url); |
357 if (alias_iter != application_package_alias_.end()) { | 330 if (alias_iter != application_package_alias_.end()) { |
358 // We replace the qualifier with the one our package alias requested. | 331 // We replace the qualifier with the one our package alias requested. |
359 URLResponsePtr response(URLResponse::New()); | 332 URLResponsePtr response(URLResponse::New()); |
360 response->url = String::From(app_url.spec()); | 333 response->url = app_url.spec(); |
361 | 334 |
362 std::string qualifier; | 335 std::string qualifier; |
363 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 336 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
364 switches::kEnableMultiprocess)) { | 337 switches::kEnableMultiprocess)) { |
365 // Why can't we use this in single process mode? Because of | 338 // Why can't we use this in single process mode? Because of |
366 // base::AtExitManager. If you link in ApplicationRunner into | 339 // base::AtExitManager. If you link in ApplicationRunner into |
367 // your code, and then we make initialize multiple copies of the | 340 // your code, and then we make initialize multiple copies of the |
368 // application, we end up with multiple AtExitManagers and will check on | 341 // application, we end up with multiple AtExitManagers and will check on |
369 // the second one being created. | 342 // the second one being created. |
370 // | 343 // |
371 // Why doesn't that happen when running different apps? Because | 344 // Why doesn't that happen when running different apps? Because |
372 // your_thing.mojo!base::AtExitManager and | 345 // your_thing.mojo!base::AtExitManager and |
373 // my_thing.mojo!base::AtExitManager are different symbols. | 346 // my_thing.mojo!base::AtExitManager are different symbols. |
374 qualifier = alias_iter->second.second; | 347 qualifier = alias_iter->second.second; |
375 } | 348 } |
376 | 349 |
377 LoadWithContentHandler(originator, alias_iter->second.first, requestor_url, | 350 LoadWithContentHandler(originator_identity, originator_filter, |
378 qualifier, filter, connect_callback, app, | 351 alias_iter->second.first, qualifier, filter, |
379 request.Pass(), response.Pass()); | 352 connect_callback, app, request.Pass(), |
| 353 response.Pass()); |
380 return; | 354 return; |
381 } | 355 } |
382 | 356 |
383 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo | 357 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo |
384 // application. That could either mean looking for the platform-specific dll | 358 // application. That could either mean looking for the platform-specific dll |
385 // header, or looking for some specific mojo signature prepended to the | 359 // header, or looking for some specific mojo signature prepended to the |
386 // library. | 360 // library. |
387 // TODO(vtl): (Maybe this should be done by the factory/runner?) | 361 // TODO(vtl): (Maybe this should be done by the factory/runner?) |
388 | 362 |
389 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); | 363 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 | 427 |
454 void ApplicationManager::RegisterApplicationPackageAlias( | 428 void ApplicationManager::RegisterApplicationPackageAlias( |
455 const GURL& alias, | 429 const GURL& alias, |
456 const GURL& content_handler_package, | 430 const GURL& content_handler_package, |
457 const std::string& qualifier) { | 431 const std::string& qualifier) { |
458 application_package_alias_[alias] = | 432 application_package_alias_[alias] = |
459 std::make_pair(content_handler_package, qualifier); | 433 std::make_pair(content_handler_package, qualifier); |
460 } | 434 } |
461 | 435 |
462 void ApplicationManager::LoadWithContentHandler( | 436 void ApplicationManager::LoadWithContentHandler( |
463 ApplicationInstance* originator, | 437 const Identity& originator_identity, |
| 438 const CapabilityFilter& originator_filter, |
464 const GURL& content_handler_url, | 439 const GURL& content_handler_url, |
465 const GURL& requestor_url, | |
466 const std::string& qualifier, | 440 const std::string& qualifier, |
467 const CapabilityFilter& filter, | 441 const CapabilityFilter& filter, |
468 const Shell::ConnectToApplicationCallback& connect_callback, | 442 const Shell::ConnectToApplicationCallback& connect_callback, |
469 ApplicationInstance* app, | 443 ApplicationInstance* app, |
470 InterfaceRequest<Application> application_request, | 444 InterfaceRequest<Application> application_request, |
471 URLResponsePtr url_response) { | 445 URLResponsePtr url_response) { |
472 ContentHandlerConnection* connection = nullptr; | 446 ContentHandlerConnection* connection = nullptr; |
473 std::pair<GURL, std::string> key(content_handler_url, qualifier); | 447 std::pair<GURL, std::string> key(content_handler_url, qualifier); |
474 // TODO(beng): Figure out the extent to which capability filter should be | 448 // TODO(beng): Figure out the extent to which capability filter should be |
475 // factored into handler identity. | 449 // factored into handler identity. |
476 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); | 450 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); |
477 if (iter != url_to_content_handler_.end()) { | 451 if (iter != url_to_content_handler_.end()) { |
478 connection = iter->second; | 452 connection = iter->second; |
479 } else { | 453 } else { |
480 connection = new ContentHandlerConnection( | 454 connection = new ContentHandlerConnection( |
481 originator, this, content_handler_url, requestor_url, qualifier, filter, | 455 this, originator_identity, originator_filter, content_handler_url, |
482 ++content_handler_id_counter_); | 456 qualifier, filter, ++content_handler_id_counter_); |
483 url_to_content_handler_[key] = connection; | 457 url_to_content_handler_[key] = connection; |
484 } | 458 } |
485 | 459 |
486 app->set_requesting_content_handler_id(connection->id()); | 460 app->set_requesting_content_handler_id(connection->id()); |
487 connection->content_handler()->StartApplication(application_request.Pass(), | 461 connection->content_handler()->StartApplication(application_request.Pass(), |
488 url_response.Pass()); | 462 url_response.Pass()); |
489 connect_callback.Run(connection->id()); | 463 connect_callback.Run(connection->id()); |
490 } | 464 } |
491 | 465 |
492 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, | 466 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 531 |
558 void ApplicationManager::CleanupRunner(NativeRunner* runner) { | 532 void ApplicationManager::CleanupRunner(NativeRunner* runner) { |
559 native_runners_.erase( | 533 native_runners_.erase( |
560 std::find(native_runners_.begin(), native_runners_.end(), runner)); | 534 std::find(native_runners_.begin(), native_runners_.end(), runner)); |
561 } | 535 } |
562 | 536 |
563 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( | 537 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( |
564 const GURL& application_url, | 538 const GURL& application_url, |
565 const std::string& interface_name) { | 539 const std::string& interface_name) { |
566 ServiceProviderPtr services; | 540 ServiceProviderPtr services; |
567 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 541 scoped_ptr<ConnectToApplicationParams> params(new ConnectToApplicationParams); |
568 request->url = mojo::String::From(application_url.spec()); | 542 params->SetURLInfo(application_url); |
569 ConnectToApplication(nullptr, request.Pass(), std::string(), GURL(), | 543 params->set_services(GetProxy(&services)); |
570 GetProxy(&services), nullptr, | 544 params->set_filter(GetPermissiveCapabilityFilter()); |
571 GetPermissiveCapabilityFilter(), base::Closure(), | 545 ConnectToApplication(params.Pass()); |
572 EmptyConnectCallback()); | |
573 MessagePipe pipe; | 546 MessagePipe pipe; |
574 services->ConnectToService(interface_name, pipe.handle1.Pass()); | 547 services->ConnectToService(interface_name, pipe.handle1.Pass()); |
575 return pipe.handle0.Pass(); | 548 return pipe.handle0.Pass(); |
576 } | 549 } |
577 | 550 |
578 Shell::ConnectToApplicationCallback EmptyConnectCallback() { | 551 Shell::ConnectToApplicationCallback EmptyConnectCallback() { |
579 return base::Bind(&OnEmptyOnConnectCallback); | 552 return base::Bind(&OnEmptyOnConnectCallback); |
580 } | 553 } |
581 | 554 |
582 } // namespace shell | 555 } // namespace shell |
583 } // namespace mojo | 556 } // namespace mojo |
OLD | NEW |