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

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

Issue 1472923002: Allows URL queries to be passed to contet handlers. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years 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
« no previous file with comments | « shell/application_manager/application_manager.h ('k') | shell/application_manager/identity.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "shell/application_manager/application_manager.h" 5 #include "shell/application_manager/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 13 matching lines...) Expand all
24 using mojo::Application; 24 using mojo::Application;
25 using mojo::ApplicationPtr; 25 using mojo::ApplicationPtr;
26 using mojo::InterfaceRequest; 26 using mojo::InterfaceRequest;
27 using mojo::ServiceProvider; 27 using mojo::ServiceProvider;
28 using mojo::ServiceProviderPtr; 28 using mojo::ServiceProviderPtr;
29 29
30 namespace shell { 30 namespace shell {
31 31
32 namespace { 32 namespace {
33 33
34 // Create identity that depends on the query.
35 const bool kDoNotStripQuery = false;
36
34 // Used by TestAPI. 37 // Used by TestAPI.
35 bool has_created_instance = false; 38 bool has_created_instance = false;
36 39
37 std::vector<std::string> Concatenate(const std::vector<std::string>& v1, 40 std::vector<std::string> Concatenate(const std::vector<std::string>& v1,
38 const std::vector<std::string>& v2) { 41 const std::vector<std::string>& v2) {
39 if (!v1.size()) 42 if (!v1.size())
40 return v2; 43 return v2;
41 if (!v2.size()) 44 if (!v2.size())
42 return v1; 45 return v1;
43 std::vector<std::string> result(v1); 46 std::vector<std::string> result(v1);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 96 }
94 97
95 ApplicationManager::TestAPI::~TestAPI() { 98 ApplicationManager::TestAPI::~TestAPI() {
96 } 99 }
97 100
98 bool ApplicationManager::TestAPI::HasCreatedInstance() { 101 bool ApplicationManager::TestAPI::HasCreatedInstance() {
99 return has_created_instance; 102 return has_created_instance;
100 } 103 }
101 104
102 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { 105 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const {
106 DCHECK(!url.has_query());
103 return manager_->identity_to_shell_impl_.find(Identity(url)) != 107 return manager_->identity_to_shell_impl_.find(Identity(url)) !=
104 manager_->identity_to_shell_impl_.end(); 108 manager_->identity_to_shell_impl_.end();
105 } 109 }
106 110
107 ApplicationManager::ApplicationManager(const Options& options, 111 ApplicationManager::ApplicationManager(const Options& options,
108 Delegate* delegate) 112 Delegate* delegate)
109 : options_(options), 113 : options_(options),
110 delegate_(delegate), 114 delegate_(delegate),
111 blocking_pool_(nullptr), 115 blocking_pool_(nullptr),
112 initialized_authentication_interceptor_(false), 116 initialized_authentication_interceptor_(false),
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (!loader) 263 if (!loader)
260 return false; 264 return false;
261 265
262 loader->Load( 266 loader->Load(
263 resolved_url, 267 resolved_url,
264 RegisterShell(resolved_url, requestor_url, services->Pass(), 268 RegisterShell(resolved_url, requestor_url, services->Pass(),
265 exposed_services->Pass(), on_application_end, parameters)); 269 exposed_services->Pass(), on_application_end, parameters));
266 return true; 270 return true;
267 } 271 }
268 272
269 Identity ApplicationManager::MakeApplicationIdentity(const GURL& resolved_url) { 273 Identity ApplicationManager::MakeApplicationIdentity(const GURL& resolved_url,
274 bool strip_query) {
270 static uint64_t unique_id_number = 1; 275 static uint64_t unique_id_number = 1;
276 GURL stripped_url = GetBaseURLAndQuery(resolved_url, nullptr);
277 GURL url = strip_query ? stripped_url : resolved_url;
271 bool new_process_per_connection = 278 bool new_process_per_connection =
272 GetNativeApplicationOptionsForURL( 279 GetNativeApplicationOptionsForURL(stripped_url)
273 GetBaseURLAndQuery(resolved_url, nullptr))
274 ->new_process_per_connection; 280 ->new_process_per_connection;
275 return new_process_per_connection 281 return new_process_per_connection
276 ? Identity(resolved_url, base::Uint64ToString(unique_id_number++)) 282 ? Identity(url, base::Uint64ToString(unique_id_number++))
277 : Identity(resolved_url); 283 : Identity(url);
278 } 284 }
279 285
280 InterfaceRequest<Application> ApplicationManager::RegisterShell( 286 InterfaceRequest<Application> ApplicationManager::RegisterShell(
281 const GURL& resolved_url, 287 const GURL& resolved_url,
282 const GURL& requestor_url, 288 const GURL& requestor_url,
283 InterfaceRequest<ServiceProvider> services, 289 InterfaceRequest<ServiceProvider> services,
284 ServiceProviderPtr exposed_services, 290 ServiceProviderPtr exposed_services,
285 const base::Closure& on_application_end, 291 const base::Closure& on_application_end,
286 const std::vector<std::string>& parameters) { 292 const std::vector<std::string>& parameters) {
287 Identity app_identity = MakeApplicationIdentity(resolved_url); 293 Identity app_identity = MakeApplicationIdentity(resolved_url);
288 294
289 mojo::ApplicationPtr application; 295 mojo::ApplicationPtr application;
290 InterfaceRequest<Application> application_request = 296 InterfaceRequest<Application> application_request =
291 mojo::GetProxy(&application); 297 mojo::GetProxy(&application);
292 ShellImpl* shell = 298 ShellImpl* shell =
293 new ShellImpl(application.Pass(), this, app_identity, on_application_end); 299 new ShellImpl(application.Pass(), this, app_identity, on_application_end);
294 identity_to_shell_impl_[app_identity] = make_scoped_ptr(shell); 300 identity_to_shell_impl_[app_identity] = make_scoped_ptr(shell);
295 shell->InitializeApplication(mojo::Array<mojo::String>::From(parameters)); 301 shell->InitializeApplication(mojo::Array<mojo::String>::From(parameters));
296 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), 302 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(),
297 exposed_services.Pass()); 303 exposed_services.Pass());
298 return application_request; 304 return application_request;
299 } 305 }
300 306
301 // Note: If a service was created with a unique ID, intending to be unique 307 // Note: If a service was created with a unique ID, intending to be unique
302 // (such that multiple requests for a service result in unique processes), then 308 // (such that multiple requests for a service result in unique processes), then
303 // 'GetShellImpl' should return nullptr. 309 // 'GetShellImpl' should return nullptr.
304 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) { 310 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) {
311 DCHECK(!url.has_query());
305 const auto& shell_it = identity_to_shell_impl_.find(Identity(url)); 312 const auto& shell_it = identity_to_shell_impl_.find(Identity(url));
306 if (shell_it != identity_to_shell_impl_.end()) 313 if (shell_it != identity_to_shell_impl_.end())
307 return shell_it->second.get(); 314 return shell_it->second.get();
308 return nullptr; 315 return nullptr;
309 } 316 }
310 317
311 void ApplicationManager::ConnectToClient( 318 void ApplicationManager::ConnectToClient(
312 ShellImpl* shell_impl, 319 ShellImpl* shell_impl,
313 const GURL& resolved_url, 320 const GURL& resolved_url,
314 const GURL& requestor_url, 321 const GURL& requestor_url,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 DCHECK(content_handler_url.is_valid()) 437 DCHECK(content_handler_url.is_valid())
431 << "Content handler URL is invalid for mime type " << mime_type; 438 << "Content handler URL is invalid for mime type " << mime_type;
432 mime_type_to_url_[mime_type] = content_handler_url; 439 mime_type_to_url_[mime_type] = content_handler_url;
433 } 440 }
434 441
435 void ApplicationManager::LoadWithContentHandler( 442 void ApplicationManager::LoadWithContentHandler(
436 const GURL& content_handler_url, 443 const GURL& content_handler_url,
437 InterfaceRequest<Application> application_request, 444 InterfaceRequest<Application> application_request,
438 mojo::URLResponsePtr url_response) { 445 mojo::URLResponsePtr url_response) {
439 ContentHandlerConnection* connection = nullptr; 446 ContentHandlerConnection* connection = nullptr;
440 Identity content_handler_id = MakeApplicationIdentity(content_handler_url); 447 // If two content handler urls differ by query parameter, we want to create a
448 // separate connection for each.
449 Identity content_handler_id =
450 MakeApplicationIdentity(content_handler_url, kDoNotStripQuery);
441 auto it = identity_to_content_handler_.find(content_handler_id); 451 auto it = identity_to_content_handler_.find(content_handler_id);
442 if (it != identity_to_content_handler_.end()) { 452 if (it != identity_to_content_handler_.end()) {
443 connection = it->second.get(); 453 connection = it->second.get();
444 } else { 454 } else {
445 connection = new ContentHandlerConnection(this, content_handler_id); 455 connection = new ContentHandlerConnection(this, content_handler_id);
446 identity_to_content_handler_[content_handler_id] = 456 identity_to_content_handler_[content_handler_id] =
447 make_scoped_ptr(connection); 457 make_scoped_ptr(connection);
448 } 458 }
449 459
450 connection->content_handler()->StartApplication(application_request.Pass(), 460 connection->content_handler()->StartApplication(application_request.Pass(),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 return args_it->second; 546 return args_it->second;
537 return std::vector<std::string>(); 547 return std::vector<std::string>();
538 } 548 }
539 549
540 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 550 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
541 native_runners_.erase( 551 native_runners_.erase(
542 std::find(native_runners_.begin(), native_runners_.end(), runner)); 552 std::find(native_runners_.begin(), native_runners_.end(), runner));
543 } 553 }
544 554
545 } // namespace shell 555 } // namespace shell
OLDNEW
« no previous file with comments | « shell/application_manager/application_manager.h ('k') | shell/application_manager/identity.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698