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

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

Issue 861293002: Allow external applications to register for mojo: urls (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Merge / nits Created 5 years, 11 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 "shell/application_manager/application_manager.h" 5 #include "shell/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 STLDeleteValues(&url_to_shell_impl_); 100 STLDeleteValues(&url_to_shell_impl_);
101 } 101 }
102 102
103 void ApplicationManager::ConnectToApplication( 103 void ApplicationManager::ConnectToApplication(
104 const GURL& requested_url, 104 const GURL& requested_url,
105 const GURL& requestor_url, 105 const GURL& requestor_url,
106 InterfaceRequest<ServiceProvider> services, 106 InterfaceRequest<ServiceProvider> services,
107 ServiceProviderPtr exposed_services) { 107 ServiceProviderPtr exposed_services) {
108 DCHECK(requested_url.is_valid()); 108 DCHECK(requested_url.is_valid());
109 GURL mapped_url = delegate_->ResolveMappings(requested_url); 109 GURL mapped_url = delegate_->ResolveMappings(requested_url);
110
111 // We check both the mapped and resolved urls for existing shell_impls because
112 // external applications can be registered for the unresolved mojo:foo urls.
113 ShellImpl* shell_impl = GetShellImpl(mapped_url);
114 if (shell_impl) {
115 ConnectToClient(shell_impl, mapped_url, requestor_url, services.Pass(),
116 exposed_services.Pass());
117 return;
118 }
119
120 GURL resolved_url = delegate_->ResolveURL(mapped_url);
121 shell_impl = GetShellImpl(resolved_url);
122 if (shell_impl) {
123 ConnectToClient(shell_impl, resolved_url, requestor_url, services.Pass(),
124 exposed_services.Pass());
125 return;
126 }
127
110 ApplicationLoader* loader = 128 ApplicationLoader* loader =
111 GetLoaderForURL(mapped_url, DONT_INCLUDE_DEFAULT_LOADER); 129 GetLoaderForURL(mapped_url, DONT_INCLUDE_DEFAULT_LOADER);
112 if (loader) { 130 if (loader) {
113 ConnectToApplicationImpl(requested_url, mapped_url, requestor_url, 131 ConnectToApplicationImpl(requested_url, mapped_url, requestor_url,
114 services.Pass(), exposed_services.Pass(), loader); 132 services.Pass(), exposed_services.Pass(), loader);
115 return; 133 return;
116 } 134 }
117 135
118 GURL resolved_url = delegate_->ResolveURL(mapped_url);
119 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER); 136 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER);
120 if (loader) { 137 if (loader) {
121 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, 138 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url,
122 services.Pass(), exposed_services.Pass(), loader); 139 services.Pass(), exposed_services.Pass(), loader);
123 return; 140 return;
124 } 141 }
125 142
126 LOG(WARNING) << "Could not find loader to load application: " 143 LOG(WARNING) << "Could not find loader to load application: "
127 << requested_url.spec(); 144 << requested_url.spec();
128 } 145 }
129 146
130 void ApplicationManager::ConnectToApplicationImpl( 147 void ApplicationManager::ConnectToApplicationImpl(
131 const GURL& requested_url, 148 const GURL& requested_url,
132 const GURL& resolved_url, 149 const GURL& resolved_url,
133 const GURL& requestor_url, 150 const GURL& requestor_url,
134 InterfaceRequest<ServiceProvider> services, 151 InterfaceRequest<ServiceProvider> services,
135 ServiceProviderPtr exposed_services, 152 ServiceProviderPtr exposed_services,
136 ApplicationLoader* loader) { 153 ApplicationLoader* loader) {
137 ShellImpl* shell = nullptr; 154 ShellPtr shell_ptr;
138 URLToShellImplMap::const_iterator shell_it = 155 ShellImpl* shell =
139 url_to_shell_impl_.find(resolved_url); 156 new ShellImpl(GetProxy(&shell_ptr), this, requested_url, resolved_url);
140 if (shell_it != url_to_shell_impl_.end()) { 157 url_to_shell_impl_[resolved_url] = shell;
141 shell = shell_it->second; 158 shell->client()->Initialize(GetArgsForURL(requested_url));
142 } else {
143 ShellPtr shell_ptr;
144 shell =
145 new ShellImpl(GetProxy(&shell_ptr), this, requested_url, resolved_url);
146 url_to_shell_impl_[resolved_url] = shell;
147 shell->client()->Initialize(GetArgsForURL(requested_url));
148 159
149 loader->Load(this, resolved_url, shell_ptr.Pass(), 160 loader->Load(this, resolved_url, shell_ptr.Pass(),
150 base::Bind(&ApplicationManager::LoadWithContentHandler, 161 base::Bind(&ApplicationManager::LoadWithContentHandler,
151 weak_ptr_factory_.GetWeakPtr())); 162 weak_ptr_factory_.GetWeakPtr()));
152 }
153 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), 163 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(),
154 exposed_services.Pass()); 164 exposed_services.Pass());
155 } 165 }
156 166
167 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) {
168 const auto& shell_it = url_to_shell_impl_.find(url);
169 if (shell_it != url_to_shell_impl_.end())
170 return shell_it->second;
171 return nullptr;
172 }
173
157 void ApplicationManager::ConnectToClient( 174 void ApplicationManager::ConnectToClient(
158 ShellImpl* shell_impl, 175 ShellImpl* shell_impl,
159 const GURL& url, 176 const GURL& url,
160 const GURL& requestor_url, 177 const GURL& requestor_url,
161 InterfaceRequest<ServiceProvider> services, 178 InterfaceRequest<ServiceProvider> services,
162 ServiceProviderPtr exposed_services) { 179 ServiceProviderPtr exposed_services) {
163 shell_impl->ConnectToClient(requestor_url, services.Pass(), 180 shell_impl->ConnectToClient(requestor_url, services.Pass(),
164 exposed_services.Pass()); 181 exposed_services.Pass());
165 } 182 }
166 183
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return pipe.handle0.Pass(); 279 return pipe.handle0.Pass();
263 } 280 }
264 281
265 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { 282 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) {
266 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); 283 URLToArgsMap::const_iterator args_it = url_to_args_.find(url);
267 if (args_it != url_to_args_.end()) 284 if (args_it != url_to_args_.end())
268 return Array<String>::From(args_it->second); 285 return Array<String>::From(args_it->second);
269 return Array<String>(); 286 return Array<String>();
270 } 287 }
271 } // namespace mojo 288 } // namespace mojo
OLDNEW
« no previous file with comments | « shell/application_manager/application_manager.h ('k') | shell/application_manager/application_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698