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

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: Cleanup 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 STLDeleteValues(&url_to_shell_impl_); 110 STLDeleteValues(&url_to_shell_impl_);
111 } 111 }
112 112
113 void ApplicationManager::ConnectToApplication( 113 void ApplicationManager::ConnectToApplication(
114 const GURL& requested_url, 114 const GURL& requested_url,
115 const GURL& requestor_url, 115 const GURL& requestor_url,
116 InterfaceRequest<ServiceProvider> services, 116 InterfaceRequest<ServiceProvider> services,
117 ServiceProviderPtr exposed_services) { 117 ServiceProviderPtr exposed_services) {
118 DCHECK(requested_url.is_valid()); 118 DCHECK(requested_url.is_valid());
119 GURL mapped_url = delegate_->ResolveMappings(requested_url); 119 GURL mapped_url = delegate_->ResolveMappings(requested_url);
120
121 // We check both the mapped and resolved urls for existing shell_impls because
122 // external applications can be registered for the unresolved mojo:foo urls.
123 ShellImpl* shell_impl = GetShellImpl(mapped_url);
124 if (shell_impl) {
125 ConnectToClient(shell_impl, mapped_url, requestor_url, services.Pass(),
126 exposed_services.Pass());
127 return;
128 }
129
130 GURL resolved_url = delegate_->ResolveURL(mapped_url);
131 shell_impl = GetShellImpl(resolved_url);
132 if (shell_impl) {
133 ConnectToClient(shell_impl, resolved_url, requestor_url, services.Pass(),
134 exposed_services.Pass());
135 return;
136 }
137
120 ApplicationLoader* loader = 138 ApplicationLoader* loader =
121 GetLoaderForURL(mapped_url, DONT_INCLUDE_DEFAULT_LOADER); 139 GetLoaderForURL(mapped_url, DONT_INCLUDE_DEFAULT_LOADER);
122 if (loader) { 140 if (loader) {
123 ConnectToApplicationImpl(requested_url, mapped_url, requestor_url, 141 ConnectToApplicationImpl(requested_url, mapped_url, requestor_url,
124 services.Pass(), exposed_services.Pass(), loader); 142 services.Pass(), exposed_services.Pass(), loader);
125 return; 143 return;
126 } 144 }
127 145
128 GURL resolved_url = delegate_->ResolveURL(mapped_url);
129 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER); 146 loader = GetLoaderForURL(resolved_url, INCLUDE_DEFAULT_LOADER);
130 if (loader) { 147 if (loader) {
131 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url, 148 ConnectToApplicationImpl(requested_url, resolved_url, requestor_url,
132 services.Pass(), exposed_services.Pass(), loader); 149 services.Pass(), exposed_services.Pass(), loader);
133 return; 150 return;
134 } 151 }
135 152
136 LOG(WARNING) << "Could not find loader to load application: " 153 LOG(WARNING) << "Could not find loader to load application: "
137 << requested_url.spec(); 154 << requested_url.spec();
138 } 155 }
139 156
140 void ApplicationManager::ConnectToApplicationImpl( 157 void ApplicationManager::ConnectToApplicationImpl(
141 const GURL& requested_url, 158 const GURL& requested_url,
142 const GURL& resolved_url, 159 const GURL& resolved_url,
143 const GURL& requestor_url, 160 const GURL& requestor_url,
144 InterfaceRequest<ServiceProvider> services, 161 InterfaceRequest<ServiceProvider> services,
145 ServiceProviderPtr exposed_services, 162 ServiceProviderPtr exposed_services,
146 ApplicationLoader* loader) { 163 ApplicationLoader* loader) {
147 ShellImpl* shell = nullptr; 164 MessagePipe pipe;
148 URLToShellImplMap::const_iterator shell_it = 165 ShellImpl* shell =
149 url_to_shell_impl_.find(resolved_url); 166 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url);
150 if (shell_it != url_to_shell_impl_.end()) { 167 url_to_shell_impl_[resolved_url] = shell;
151 shell = shell_it->second; 168 shell->client()->Initialize(GetArgsForURL(requested_url));
152 } else {
153 MessagePipe pipe;
154 shell =
155 new ShellImpl(pipe.handle0.Pass(), this, requested_url, resolved_url);
156 url_to_shell_impl_[resolved_url] = shell;
157 shell->client()->Initialize(GetArgsForURL(requested_url));
158 169
159 loader->Load(this, resolved_url, pipe.handle1.Pass(), 170 loader->Load(this, resolved_url, pipe.handle1.Pass(),
160 base::Bind(&ApplicationManager::LoadWithContentHandler, 171 base::Bind(&ApplicationManager::LoadWithContentHandler,
161 weak_ptr_factory_.GetWeakPtr())); 172 weak_ptr_factory_.GetWeakPtr()));
162 }
163 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(), 173 ConnectToClient(shell, resolved_url, requestor_url, services.Pass(),
164 exposed_services.Pass()); 174 exposed_services.Pass());
165 } 175 }
166 176
177 ShellImpl* ApplicationManager::GetShellImpl(const GURL& url) {
178 const auto& shell_it = url_to_shell_impl_.find(url);
179 if (shell_it != url_to_shell_impl_.end())
180 return shell_it->second;
181 return nullptr;
182 }
183
167 void ApplicationManager::ConnectToClient( 184 void ApplicationManager::ConnectToClient(
168 ShellImpl* shell_impl, 185 ShellImpl* shell_impl,
169 const GURL& url, 186 const GURL& url,
170 const GURL& requestor_url, 187 const GURL& requestor_url,
171 InterfaceRequest<ServiceProvider> services, 188 InterfaceRequest<ServiceProvider> services,
172 ServiceProviderPtr exposed_services) { 189 ServiceProviderPtr exposed_services) {
173 shell_impl->ConnectToClient(requestor_url, services.Pass(), 190 shell_impl->ConnectToClient(requestor_url, services.Pass(),
174 exposed_services.Pass()); 191 exposed_services.Pass());
175 } 192 }
176 193
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return pipe.handle0.Pass(); 288 return pipe.handle0.Pass();
272 } 289 }
273 290
274 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { 291 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) {
275 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); 292 URLToArgsMap::const_iterator args_it = url_to_args_.find(url);
276 if (args_it != url_to_args_.end()) 293 if (args_it != url_to_args_.end())
277 return Array<String>::From(args_it->second); 294 return Array<String>::From(args_it->second);
278 return Array<String>(); 295 return Array<String>();
279 } 296 }
280 } // namespace mojo 297 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698