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

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

Issue 1311353005: Adds a way to determine id of content handler that created app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: separate out declaration/definition Created 5 years, 3 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
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/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 12 matching lines...) Expand all
23 #include "mojo/shell/update_fetcher.h" 23 #include "mojo/shell/update_fetcher.h"
24 24
25 namespace mojo { 25 namespace mojo {
26 namespace shell { 26 namespace shell {
27 27
28 namespace { 28 namespace {
29 29
30 // Used by TestAPI. 30 // Used by TestAPI.
31 bool has_created_instance = false; 31 bool has_created_instance = false;
32 32
33 void OnEmptyOnConnectCallback(uint32_t content_handler_id) {}
34
33 } // namespace 35 } // namespace
34 36
35 // static 37 // static
36 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) 38 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager)
37 : manager_(manager) { 39 : manager_(manager) {
38 } 40 }
39 41
40 ApplicationManager::TestAPI::~TestAPI() { 42 ApplicationManager::TestAPI::~TestAPI() {
41 } 43 }
42 44
43 bool ApplicationManager::TestAPI::HasCreatedInstance() { 45 bool ApplicationManager::TestAPI::HasCreatedInstance() {
44 return has_created_instance; 46 return has_created_instance;
45 } 47 }
46 48
47 bool ApplicationManager::TestAPI::HasRunningInstanceForURL( 49 bool ApplicationManager::TestAPI::HasRunningInstanceForURL(
48 const GURL& url) const { 50 const GURL& url) const {
49 return manager_->identity_to_instance_.find(Identity(url)) != 51 return manager_->identity_to_instance_.find(Identity(url)) !=
50 manager_->identity_to_instance_.end(); 52 manager_->identity_to_instance_.end();
51 } 53 }
52 54
55 // static
56 const uint32_t ApplicationManager::kInvalidContentHandlerID = 0u;
57
53 ApplicationManager::ApplicationManager(Delegate* delegate) 58 ApplicationManager::ApplicationManager(Delegate* delegate)
54 : delegate_(delegate), weak_ptr_factory_(this) { 59 : delegate_(delegate),
55 } 60 disable_cache_(false),
61 content_handler_id_counter_(0u),
62 weak_ptr_factory_(this) {}
56 63
57 ApplicationManager::~ApplicationManager() { 64 ApplicationManager::~ApplicationManager() {
58 URLToContentHandlerMap url_to_content_handler(url_to_content_handler_); 65 URLToContentHandlerMap url_to_content_handler(url_to_content_handler_);
59 for (auto& pair : url_to_content_handler) 66 for (auto& pair : url_to_content_handler)
60 pair.second->CloseConnection(); 67 pair.second->CloseConnection();
61 TerminateShellConnections(); 68 TerminateShellConnections();
62 STLDeleteValues(&url_to_loader_); 69 STLDeleteValues(&url_to_loader_);
63 STLDeleteValues(&scheme_to_loader_); 70 STLDeleteValues(&scheme_to_loader_);
64 } 71 }
65 72
66 void ApplicationManager::TerminateShellConnections() { 73 void ApplicationManager::TerminateShellConnections() {
67 STLDeleteValues(&identity_to_instance_); 74 STLDeleteValues(&identity_to_instance_);
68 } 75 }
69 76
70 void ApplicationManager::ConnectToApplication( 77 void ApplicationManager::ConnectToApplication(
71 ApplicationInstance* originator, 78 ApplicationInstance* originator,
72 mojo::URLRequestPtr requested_url, 79 mojo::URLRequestPtr requested_url,
73 const std::string& qualifier, 80 const std::string& qualifier,
74 const GURL& requestor_url, 81 const GURL& requestor_url,
82 uint32_t requesting_content_handler_id,
75 InterfaceRequest<ServiceProvider> services, 83 InterfaceRequest<ServiceProvider> services,
76 ServiceProviderPtr exposed_services, 84 ServiceProviderPtr exposed_services,
77 const CapabilityFilter& filter, 85 const CapabilityFilter& filter,
78 const base::Closure& on_application_end) { 86 const base::Closure& on_application_end,
87 const Shell::ConnectToApplicationCallback& connect_callback) {
79 GURL requested_gurl(requested_url->url.To<std::string>()); 88 GURL requested_gurl(requested_url->url.To<std::string>());
80 TRACE_EVENT_INSTANT1( 89 TRACE_EVENT_INSTANT1(
81 "mojo_shell", "ApplicationManager::ConnectToApplication", 90 "mojo_shell", "ApplicationManager::ConnectToApplication",
82 TRACE_EVENT_SCOPE_THREAD, "requested_url", requested_gurl.spec()); 91 TRACE_EVENT_SCOPE_THREAD, "requested_url", requested_gurl.spec());
83 DCHECK(requested_gurl.is_valid()); 92 DCHECK(requested_gurl.is_valid());
84 93
85 // We check both the mapped and resolved urls for existing instances because 94 // We check both the mapped and resolved urls for existing instances because
86 // external applications can be registered for the unresolved mojo:foo urls. 95 // external applications can be registered for the unresolved mojo:foo urls.
87 96
88 GURL mapped_url = delegate_->ResolveMappings(requested_gurl); 97 GURL mapped_url = delegate_->ResolveMappings(requested_gurl);
89 if (ConnectToRunningApplication(originator, mapped_url, qualifier, 98 if (ConnectToRunningApplication(originator, mapped_url, qualifier,
90 requestor_url, &services, 99 requestor_url, &services, &exposed_services,
91 &exposed_services, filter)) { 100 filter, connect_callback)) {
92 return; 101 return;
93 } 102 }
94 103
95 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url); 104 GURL resolved_url = delegate_->ResolveMojoURL(mapped_url);
96 if (ConnectToRunningApplication(originator, resolved_url, qualifier, 105 if (ConnectToRunningApplication(originator, resolved_url, qualifier,
97 requestor_url, &services, 106 requestor_url, &services, &exposed_services,
98 &exposed_services, filter)) { 107 filter, connect_callback)) {
99 return; 108 return;
100 } 109 }
101 110
102 // The application is not running, let's compute the parameters. 111 // The application is not running, let's compute the parameters.
103 if (ConnectToApplicationWithLoader( 112 if (ConnectToApplicationWithLoader(
104 originator, requested_gurl, qualifier, mapped_url, requestor_url, 113 originator, requested_gurl, qualifier, mapped_url, requestor_url,
105 &services, &exposed_services, filter, on_application_end, 114 requesting_content_handler_id, &services, &exposed_services, filter,
106 GetLoaderForURL(mapped_url))) { 115 on_application_end, connect_callback, GetLoaderForURL(mapped_url))) {
107 return; 116 return;
108 } 117 }
109 118
110 if (ConnectToApplicationWithLoader( 119 if (ConnectToApplicationWithLoader(
111 originator, requested_gurl, qualifier, resolved_url, requestor_url, 120 originator, requested_gurl, qualifier, resolved_url, requestor_url,
112 &services, &exposed_services, filter, on_application_end, 121 requesting_content_handler_id, &services, &exposed_services, filter,
122 on_application_end, connect_callback,
113 GetLoaderForURL(resolved_url))) { 123 GetLoaderForURL(resolved_url))) {
114 return; 124 return;
115 } 125 }
116 126
117 if (ConnectToApplicationWithLoader( 127 if (ConnectToApplicationWithLoader(
118 originator, requested_gurl, qualifier, resolved_url, requestor_url, 128 originator, requested_gurl, qualifier, resolved_url, requestor_url,
119 &services, &exposed_services, filter, on_application_end, 129 requesting_content_handler_id, &services, &exposed_services, filter,
120 default_loader_.get())) { 130 on_application_end, connect_callback, default_loader_.get())) {
121 return; 131 return;
122 } 132 }
123 133
124 auto callback = base::Bind( 134 auto callback = base::Bind(
125 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(), 135 &ApplicationManager::HandleFetchCallback, weak_ptr_factory_.GetWeakPtr(),
126 originator, requested_gurl, qualifier, requestor_url, 136 originator, requested_gurl, qualifier, requestor_url,
127 base::Passed(services.Pass()), base::Passed(exposed_services.Pass()), 137 requesting_content_handler_id, base::Passed(services.Pass()),
128 filter, on_application_end); 138 base::Passed(exposed_services.Pass()), filter, on_application_end,
139 connect_callback);
129 140
130 if (delegate_->CreateFetcher( 141 if (delegate_->CreateFetcher(
131 resolved_url, 142 resolved_url,
132 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) { 143 base::Bind(callback, NativeApplicationCleanup::DONT_DELETE))) {
133 return; 144 return;
134 } 145 }
135 146
136 if (resolved_url.SchemeIsFile()) { 147 if (resolved_url.SchemeIsFile()) {
137 // LocalFetcher uses the network service to infer MIME types from URLs. 148 // LocalFetcher uses the network service to infer MIME types from URLs.
138 // Skip this for mojo URLs to avoid recursively loading the network service. 149 // Skip this for mojo URLs to avoid recursively loading the network service.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 url_loader_factory_.get(), base::Bind(callback, cleanup)); 189 url_loader_factory_.get(), base::Bind(callback, cleanup));
179 } 190 }
180 191
181 bool ApplicationManager::ConnectToRunningApplication( 192 bool ApplicationManager::ConnectToRunningApplication(
182 ApplicationInstance* originator, 193 ApplicationInstance* originator,
183 const GURL& resolved_url, 194 const GURL& resolved_url,
184 const std::string& qualifier, 195 const std::string& qualifier,
185 const GURL& requestor_url, 196 const GURL& requestor_url,
186 InterfaceRequest<ServiceProvider>* services, 197 InterfaceRequest<ServiceProvider>* services,
187 ServiceProviderPtr* exposed_services, 198 ServiceProviderPtr* exposed_services,
188 const CapabilityFilter& filter) { 199 const CapabilityFilter& filter,
200 const Shell::ConnectToApplicationCallback& connect_callback) {
189 ApplicationInstance* instance = 201 ApplicationInstance* instance =
190 GetApplicationInstance(Identity(resolved_url, qualifier)); 202 GetApplicationInstance(Identity(resolved_url, qualifier));
191 if (!instance) 203 if (!instance)
192 return false; 204 return false;
193 205
194 instance->ConnectToClient(originator, resolved_url, requestor_url, 206 instance->ConnectToClient(originator, resolved_url, requestor_url,
195 services->Pass(), exposed_services->Pass(), 207 services->Pass(), exposed_services->Pass(), filter);
196 filter); 208 connect_callback.Run(instance->requesting_content_handler_id());
197 return true; 209 return true;
198 } 210 }
199 211
200 bool ApplicationManager::ConnectToApplicationWithLoader( 212 bool ApplicationManager::ConnectToApplicationWithLoader(
201 ApplicationInstance* originator, 213 ApplicationInstance* originator,
202 const GURL& requested_url, 214 const GURL& requested_url,
203 const std::string& qualifier, 215 const std::string& qualifier,
204 const GURL& resolved_url, 216 const GURL& resolved_url,
205 const GURL& requestor_url, 217 const GURL& requestor_url,
218 uint32_t requesting_content_handler_id,
206 InterfaceRequest<ServiceProvider>* services, 219 InterfaceRequest<ServiceProvider>* services,
207 ServiceProviderPtr* exposed_services, 220 ServiceProviderPtr* exposed_services,
208 const CapabilityFilter& filter, 221 const CapabilityFilter& filter,
209 const base::Closure& on_application_end, 222 const base::Closure& on_application_end,
223 const Shell::ConnectToApplicationCallback& connect_callback,
210 ApplicationLoader* loader) { 224 ApplicationLoader* loader) {
211 if (!loader) 225 if (!loader)
212 return false; 226 return false;
213 227
214 const GURL app_url = 228 const GURL app_url =
215 requested_url.SchemeIs("mojo") ? requested_url : resolved_url; 229 requested_url.SchemeIs("mojo") ? requested_url : resolved_url;
216 230
217 loader->Load( 231 loader->Load(resolved_url,
218 resolved_url, 232 RegisterInstance(originator, app_url, qualifier, requestor_url,
219 RegisterInstance(originator, app_url, qualifier, requestor_url, 233 requesting_content_handler_id, services->Pass(),
220 services->Pass(), exposed_services->Pass(), 234 exposed_services->Pass(), filter,
221 filter, on_application_end)); 235 on_application_end, connect_callback, nullptr));
222 return true; 236 return true;
223 } 237 }
224 238
225 InterfaceRequest<Application> ApplicationManager::RegisterInstance( 239 InterfaceRequest<Application> ApplicationManager::RegisterInstance(
226 ApplicationInstance* originator, 240 ApplicationInstance* originator,
227 const GURL& app_url, 241 const GURL& app_url,
228 const std::string& qualifier, 242 const std::string& qualifier,
229 const GURL& requestor_url, 243 const GURL& requestor_url,
244 const uint32_t requesting_content_handler_id,
230 InterfaceRequest<ServiceProvider> services, 245 InterfaceRequest<ServiceProvider> services,
231 ServiceProviderPtr exposed_services, 246 ServiceProviderPtr exposed_services,
232 const CapabilityFilter& filter, 247 const CapabilityFilter& filter,
233 const base::Closure& on_application_end) { 248 const base::Closure& on_application_end,
249 const Shell::ConnectToApplicationCallback& connect_callback,
250 ApplicationInstance** resulting_instance) {
234 Identity app_identity(app_url, qualifier); 251 Identity app_identity(app_url, qualifier);
235 252
236 ApplicationPtr application; 253 ApplicationPtr application;
237 InterfaceRequest<Application> application_request = GetProxy(&application); 254 InterfaceRequest<Application> application_request = GetProxy(&application);
238 ApplicationInstance* instance = new ApplicationInstance( 255 ApplicationInstance* instance = new ApplicationInstance(
239 application.Pass(), this, 256 application.Pass(), this,
240 originator ? originator->identity() : Identity(GURL()), app_identity, 257 originator ? originator->identity() : Identity(GURL()), app_identity,
241 filter, on_application_end); 258 filter, requesting_content_handler_id, on_application_end);
242 DCHECK(identity_to_instance_.find(app_identity) == 259 DCHECK(identity_to_instance_.find(app_identity) ==
243 identity_to_instance_.end()); 260 identity_to_instance_.end());
244 identity_to_instance_[app_identity] = instance; 261 identity_to_instance_[app_identity] = instance;
245 instance->InitializeApplication(); 262 instance->InitializeApplication();
246 instance->ConnectToClient(originator, app_url, requestor_url, services.Pass(), 263 instance->ConnectToClient(originator, app_url, requestor_url, services.Pass(),
247 exposed_services.Pass(), filter); 264 exposed_services.Pass(), filter);
265 connect_callback.Run(kInvalidContentHandlerID);
Ben Goodger (Google) 2015/08/31 17:41:07 Specifically I'm trying to understand the flow of
sky 2015/08/31 19:46:07 Ya, this code is a bit cryptic. The key places tha
266 if (resulting_instance)
267 *resulting_instance = instance;
248 return application_request.Pass(); 268 return application_request.Pass();
249 } 269 }
250 270
251 ApplicationInstance* ApplicationManager::GetApplicationInstance( 271 ApplicationInstance* ApplicationManager::GetApplicationInstance(
252 const Identity& identity) const { 272 const Identity& identity) const {
253 const auto& instance_it = identity_to_instance_.find(identity); 273 const auto& instance_it = identity_to_instance_.find(identity);
254 if (instance_it != identity_to_instance_.end()) 274 if (instance_it != identity_to_instance_.end())
255 return instance_it->second; 275 return instance_it->second;
256 return nullptr; 276 return nullptr;
257 } 277 }
258 278
259 void ApplicationManager::HandleFetchCallback( 279 void ApplicationManager::HandleFetchCallback(
260 ApplicationInstance* originator, 280 ApplicationInstance* originator,
261 const GURL& requested_url, 281 const GURL& requested_url,
262 const std::string& qualifier, 282 const std::string& qualifier,
263 const GURL& requestor_url, 283 const GURL& requestor_url,
284 uint32_t requesting_content_handler_id,
264 InterfaceRequest<ServiceProvider> services, 285 InterfaceRequest<ServiceProvider> services,
265 ServiceProviderPtr exposed_services, 286 ServiceProviderPtr exposed_services,
266 const CapabilityFilter& filter, 287 const CapabilityFilter& filter,
267 const base::Closure& on_application_end, 288 const base::Closure& on_application_end,
289 const Shell::ConnectToApplicationCallback& connect_callback,
268 NativeApplicationCleanup cleanup, 290 NativeApplicationCleanup cleanup,
269 scoped_ptr<Fetcher> fetcher) { 291 scoped_ptr<Fetcher> fetcher) {
270 if (!fetcher) { 292 if (!fetcher) {
271 // Network error. Drop |application_request| to tell requestor. 293 // Network error. Drop |application_request| to tell requestor.
294 connect_callback.Run(kInvalidContentHandlerID);
272 return; 295 return;
273 } 296 }
274 297
275 GURL redirect_url = fetcher->GetRedirectURL(); 298 GURL redirect_url = fetcher->GetRedirectURL();
276 if (!redirect_url.is_empty()) { 299 if (!redirect_url.is_empty()) {
277 // And around we go again... Whee! 300 // And around we go again... Whee!
278 // TODO(sky): this loses |requested_url|. 301 // TODO(sky): this loses |requested_url|.
279 mojo::URLRequestPtr request(mojo::URLRequest::New()); 302 mojo::URLRequestPtr request(mojo::URLRequest::New());
280 request->url = mojo::String::From(redirect_url.spec()); 303 request->url = mojo::String::From(redirect_url.spec());
281 HttpHeaderPtr header = HttpHeader::New(); 304 HttpHeaderPtr header = HttpHeader::New();
282 header->name = "Referer"; 305 header->name = "Referer";
283 header->value = fetcher->GetRedirectReferer().spec(); 306 header->value = fetcher->GetRedirectReferer().spec();
284 request->headers.push_back(header.Pass()); 307 request->headers.push_back(header.Pass());
285 ConnectToApplication(originator, request.Pass(), qualifier, requestor_url, 308 ConnectToApplication(originator, request.Pass(), qualifier, requestor_url,
286 services.Pass(), exposed_services.Pass(), filter, 309 requesting_content_handler_id, services.Pass(),
287 on_application_end); 310 exposed_services.Pass(), filter, on_application_end,
311 connect_callback);
288 return; 312 return;
289 } 313 }
290 314
291 // We already checked if the application was running before we fetched it, but 315 // We already checked if the application was running before we fetched it, but
292 // it might have started while the fetch was outstanding. We don't want to 316 // it might have started while the fetch was outstanding. We don't want to
293 // have two copies of the app running, so check again. 317 // have two copies of the app running, so check again.
294 // 318 //
295 // Also, it's possible the original URL was redirected to an app that is 319 // Also, it's possible the original URL was redirected to an app that is
296 // already running. 320 // already running.
297 if (ConnectToRunningApplication(originator, requested_url, qualifier, 321 if (ConnectToRunningApplication(originator, requested_url, qualifier,
298 requestor_url, &services, 322 requestor_url, &services, &exposed_services,
299 &exposed_services, filter)) { 323 filter, connect_callback)) {
300 return; 324 return;
301 } 325 }
302 326
303 const GURL app_url = 327 const GURL app_url =
304 requested_url.scheme() == "mojo" ? requested_url : fetcher->GetURL(); 328 requested_url.scheme() == "mojo" ? requested_url : fetcher->GetURL();
305 329
306 InterfaceRequest<Application> request( 330 ApplicationInstance* app = nullptr;
307 RegisterInstance(originator, app_url, qualifier, requestor_url, 331 InterfaceRequest<Application> request(RegisterInstance(
308 services.Pass(), exposed_services.Pass(), filter, 332 originator, app_url, qualifier, requestor_url,
309 on_application_end)); 333 requesting_content_handler_id, services.Pass(), exposed_services.Pass(),
334 filter, on_application_end, EmptyConnectCallback(), &app));
310 335
311 // For resources that are loaded with content handlers, we group app instances 336 // For resources that are loaded with content handlers, we group app instances
312 // by site. 337 // by site.
313 338
314 // If the response begins with a #!mojo <content-handler-url>, use it. 339 // If the response begins with a #!mojo <content-handler-url>, use it.
315 GURL content_handler_url; 340 GURL content_handler_url;
316 std::string shebang; 341 std::string shebang;
317 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch( 342 bool enable_multi_process = base::CommandLine::ForCurrentProcess()->HasSwitch(
318 switches::kEnableMultiprocess); 343 switches::kEnableMultiprocess);
319 344
320 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) { 345 if (fetcher->PeekContentHandler(&shebang, &content_handler_url)) {
321 URLResponsePtr response(fetcher->AsURLResponse( 346 URLResponsePtr response(fetcher->AsURLResponse(
322 blocking_pool_, static_cast<int>(shebang.size()))); 347 blocking_pool_, static_cast<int>(shebang.size())));
323 std::string site = 348 std::string site =
324 enable_multi_process ? response->site.To<std::string>() : std::string(); 349 enable_multi_process ? response->site.To<std::string>() : std::string();
325 LoadWithContentHandler(originator, content_handler_url, requestor_url, site, 350 LoadWithContentHandler(originator, content_handler_url, requestor_url, site,
326 filter, request.Pass(), response.Pass()); 351 filter, connect_callback, app, request.Pass(),
352 response.Pass());
327 return; 353 return;
328 } 354 }
329 355
330 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType()); 356 MimeTypeToURLMap::iterator iter = mime_type_to_url_.find(fetcher->MimeType());
331 if (iter != mime_type_to_url_.end()) { 357 if (iter != mime_type_to_url_.end()) {
332 URLResponsePtr response(fetcher->AsURLResponse(blocking_pool_, 0)); 358 URLResponsePtr response(fetcher->AsURLResponse(blocking_pool_, 0));
333 std::string site = 359 std::string site =
334 enable_multi_process ? response->site.To<std::string>() : std::string(); 360 enable_multi_process ? response->site.To<std::string>() : std::string();
335 LoadWithContentHandler(originator, iter->second, requestor_url, site, 361 LoadWithContentHandler(originator, iter->second, requestor_url, site,
336 filter, request.Pass(), response.Pass()); 362 filter, connect_callback, app, request.Pass(),
363 response.Pass());
337 return; 364 return;
338 } 365 }
339 366
340 auto alias_iter = application_package_alias_.find(app_url); 367 auto alias_iter = application_package_alias_.find(app_url);
341 if (alias_iter != application_package_alias_.end()) { 368 if (alias_iter != application_package_alias_.end()) {
342 // We replace the qualifier with the one our package alias requested. 369 // We replace the qualifier with the one our package alias requested.
343 URLResponsePtr response(URLResponse::New()); 370 URLResponsePtr response(URLResponse::New());
344 response->url = String::From(app_url.spec()); 371 response->url = String::From(app_url.spec());
345 372
346 std::string qualifier; 373 std::string qualifier;
347 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 374 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
348 switches::kEnableMultiprocess)) { 375 switches::kEnableMultiprocess)) {
349 // Why can't we use this in single process mode? Because of 376 // Why can't we use this in single process mode? Because of
350 // base::AtExitManager. If you link in ApplicationRunner into 377 // base::AtExitManager. If you link in ApplicationRunner into
351 // your code, and then we make initialize multiple copies of the 378 // your code, and then we make initialize multiple copies of the
352 // application, we end up with multiple AtExitManagers and will check on 379 // application, we end up with multiple AtExitManagers and will check on
353 // the second one being created. 380 // the second one being created.
354 // 381 //
355 // Why doesn't that happen when running different apps? Because 382 // Why doesn't that happen when running different apps? Because
356 // your_thing.mojo!base::AtExitManager and 383 // your_thing.mojo!base::AtExitManager and
357 // my_thing.mojo!base::AtExitManager are different symbols. 384 // my_thing.mojo!base::AtExitManager are different symbols.
358 qualifier = alias_iter->second.second; 385 qualifier = alias_iter->second.second;
359 } 386 }
360 387
361 LoadWithContentHandler(originator, alias_iter->second.first, requestor_url, 388 LoadWithContentHandler(originator, alias_iter->second.first, requestor_url,
362 qualifier, filter, request.Pass(), 389 qualifier, filter, connect_callback, app,
363 response.Pass()); 390 request.Pass(), response.Pass());
364 return; 391 return;
365 } 392 }
366 393
367 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo 394 // TODO(aa): Sanity check that the thing we got looks vaguely like a mojo
368 // application. That could either mean looking for the platform-specific dll 395 // application. That could either mean looking for the platform-specific dll
369 // header, or looking for some specific mojo signature prepended to the 396 // header, or looking for some specific mojo signature prepended to the
370 // library. 397 // library.
371 // TODO(vtl): (Maybe this should be done by the factory/runner?) 398 // TODO(vtl): (Maybe this should be done by the factory/runner?)
372 399
373 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr); 400 GURL base_resolved_url = GetBaseURLAndQuery(fetcher->GetURL(), nullptr);
374 NativeRunnerFactory::Options options; 401 NativeRunnerFactory::Options options;
375 if (url_to_native_options_.find(base_resolved_url) != 402 if (url_to_native_options_.find(base_resolved_url) !=
376 url_to_native_options_.end()) { 403 url_to_native_options_.end()) {
377 DVLOG(2) << "Applying stored native options to resolved URL " 404 DVLOG(2) << "Applying stored native options to resolved URL "
378 << fetcher->GetURL(); 405 << fetcher->GetURL();
379 options = url_to_native_options_[base_resolved_url]; 406 options = url_to_native_options_[base_resolved_url];
380 } 407 }
381 408
382 // TODO(erg): Have a better way of switching the sandbox on. For now, switch 409 // TODO(erg): Have a better way of switching the sandbox on. For now, switch
383 // it on hard coded when we're using some of the sandboxable core services. 410 // it on hard coded when we're using some of the sandboxable core services.
384 bool start_sandboxed = false; 411 bool start_sandboxed = false;
385 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 412 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
386 switches::kMojoNoSandbox)) { 413 switches::kMojoNoSandbox)) {
387 if (app_url == GURL("mojo://core_services/") && qualifier == "Core") 414 if (app_url == GURL("mojo://core_services/") && qualifier == "Core")
388 start_sandboxed = true; 415 start_sandboxed = true;
389 else if (app_url == GURL("mojo://html_viewer/")) 416 else if (app_url == GURL("mojo://html_viewer/"))
390 start_sandboxed = true; 417 start_sandboxed = true;
391 } 418 }
392 419
420 connect_callback.Run(kInvalidContentHandlerID);
421
393 fetcher->AsPath(blocking_pool_, 422 fetcher->AsPath(blocking_pool_,
394 base::Bind(&ApplicationManager::RunNativeApplication, 423 base::Bind(&ApplicationManager::RunNativeApplication,
395 weak_ptr_factory_.GetWeakPtr(), 424 weak_ptr_factory_.GetWeakPtr(),
396 base::Passed(request.Pass()), start_sandboxed, 425 base::Passed(request.Pass()), start_sandboxed,
397 options, cleanup, base::Passed(fetcher.Pass()))); 426 options, cleanup, base::Passed(fetcher.Pass())));
398 } 427 }
399 428
400 void ApplicationManager::RunNativeApplication( 429 void ApplicationManager::RunNativeApplication(
401 InterfaceRequest<Application> application_request, 430 InterfaceRequest<Application> application_request,
402 bool start_sandboxed, 431 bool start_sandboxed,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 application_package_alias_[alias] = 469 application_package_alias_[alias] =
441 std::make_pair(content_handler_package, qualifier); 470 std::make_pair(content_handler_package, qualifier);
442 } 471 }
443 472
444 void ApplicationManager::LoadWithContentHandler( 473 void ApplicationManager::LoadWithContentHandler(
445 ApplicationInstance* originator, 474 ApplicationInstance* originator,
446 const GURL& content_handler_url, 475 const GURL& content_handler_url,
447 const GURL& requestor_url, 476 const GURL& requestor_url,
448 const std::string& qualifier, 477 const std::string& qualifier,
449 const CapabilityFilter& filter, 478 const CapabilityFilter& filter,
479 const Shell::ConnectToApplicationCallback& connect_callback,
480 ApplicationInstance* app,
450 InterfaceRequest<Application> application_request, 481 InterfaceRequest<Application> application_request,
451 URLResponsePtr url_response) { 482 URLResponsePtr url_response) {
452 ContentHandlerConnection* connection = nullptr; 483 ContentHandlerConnection* connection = nullptr;
453 std::pair<GURL, std::string> key(content_handler_url, qualifier); 484 std::pair<GURL, std::string> key(content_handler_url, qualifier);
454 // TODO(beng): Figure out the extent to which capability filter should be 485 // TODO(beng): Figure out the extent to which capability filter should be
455 // factored into handler identity. 486 // factored into handler identity.
456 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key); 487 URLToContentHandlerMap::iterator iter = url_to_content_handler_.find(key);
457 if (iter != url_to_content_handler_.end()) { 488 if (iter != url_to_content_handler_.end()) {
458 connection = iter->second; 489 connection = iter->second;
459 } else { 490 } else {
460 connection = new ContentHandlerConnection( 491 connection = new ContentHandlerConnection(
461 originator, this, content_handler_url, requestor_url, qualifier, 492 originator, this, content_handler_url, requestor_url, qualifier, filter,
462 filter); 493 ++content_handler_id_counter_);
463 url_to_content_handler_[key] = connection; 494 url_to_content_handler_[key] = connection;
464 } 495 }
465 496
497 // TODO(sky): this isn't right if there is a nested content handler.
498 app->set_requesting_content_handler_id(connection->id());
466 connection->content_handler()->StartApplication(application_request.Pass(), 499 connection->content_handler()->StartApplication(application_request.Pass(),
467 url_response.Pass()); 500 url_response.Pass());
501 connection->ScheduleTargetIdCallback(connect_callback);
468 } 502 }
469 503
470 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, 504 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
471 const GURL& url) { 505 const GURL& url) {
472 URLToLoaderMap::iterator it = url_to_loader_.find(url); 506 URLToLoaderMap::iterator it = url_to_loader_.find(url);
473 if (it != url_to_loader_.end()) 507 if (it != url_to_loader_.end())
474 delete it->second; 508 delete it->second;
475 url_to_loader_[url] = loader.release(); 509 url_to_loader_[url] = loader.release();
476 } 510 }
477 511
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 std::find(native_runners_.begin(), native_runners_.end(), runner)); 572 std::find(native_runners_.begin(), native_runners_.end(), runner));
539 } 573 }
540 574
541 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( 575 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(
542 const GURL& application_url, 576 const GURL& application_url,
543 const std::string& interface_name) { 577 const std::string& interface_name) {
544 ServiceProviderPtr services; 578 ServiceProviderPtr services;
545 mojo::URLRequestPtr request(mojo::URLRequest::New()); 579 mojo::URLRequestPtr request(mojo::URLRequest::New());
546 request->url = mojo::String::From(application_url.spec()); 580 request->url = mojo::String::From(application_url.spec());
547 ConnectToApplication(nullptr, request.Pass(), std::string(), GURL(), 581 ConnectToApplication(nullptr, request.Pass(), std::string(), GURL(),
548 GetProxy(&services), nullptr, 582 kInvalidContentHandlerID, GetProxy(&services), nullptr,
549 GetPermissiveCapabilityFilter(), base::Closure()); 583 GetPermissiveCapabilityFilter(), base::Closure(),
584 EmptyConnectCallback());
550 MessagePipe pipe; 585 MessagePipe pipe;
551 services->ConnectToService(interface_name, pipe.handle1.Pass()); 586 services->ConnectToService(interface_name, pipe.handle1.Pass());
552 return pipe.handle0.Pass(); 587 return pipe.handle0.Pass();
553 } 588 }
554 589
590 Shell::ConnectToApplicationCallback EmptyConnectCallback() {
591 return base::Bind(&OnEmptyOnConnectCallback);
592 }
593
555 } // namespace shell 594 } // namespace shell
556 } // namespace mojo 595 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698