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

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

Issue 1351443004: Revert of Make CapabilityFilter be part of Identity (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.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 "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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 void ApplicationManager::TerminateShellConnections() { 70 void ApplicationManager::TerminateShellConnections() {
71 STLDeleteValues(&identity_to_instance_); 71 STLDeleteValues(&identity_to_instance_);
72 } 72 }
73 73
74 void ApplicationManager::ConnectToApplication( 74 void ApplicationManager::ConnectToApplication(
75 scoped_ptr<ConnectToApplicationParams> params) { 75 scoped_ptr<ConnectToApplicationParams> params) {
76 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication", 76 TRACE_EVENT_INSTANT1("mojo_shell", "ApplicationManager::ConnectToApplication",
77 TRACE_EVENT_SCOPE_THREAD, "original_url", 77 TRACE_EVENT_SCOPE_THREAD, "original_url",
78 params->target().url().spec()); 78 params->app_url().spec());
79 DCHECK(params->target().url().is_valid()); 79 DCHECK(params->app_url().is_valid());
80 80
81 // Connect to an existing matching instance, if possible. 81 // Connect to an existing matching instance, if possible.
82 if (ConnectToRunningApplication(&params)) 82 if (ConnectToRunningApplication(&params))
83 return; 83 return;
84 84
85 ApplicationLoader* loader = GetLoaderForURL(params->target().url()); 85 ApplicationLoader* loader = GetLoaderForURL(params->app_url());
86 if (loader) { 86 if (loader) {
87 GURL url = params->target().url(); 87 GURL url = params->app_url();
88 loader->Load(url, CreateInstance(params.Pass(), nullptr)); 88 loader->Load(url, CreateInstance(params.Pass(), nullptr));
89 return; 89 return;
90 } 90 }
91 91
92 URLRequestPtr original_url_request = params->TakeTargetURLRequest(); 92 URLRequestPtr original_url_request = params->TakeAppURLRequest();
93 auto callback = 93 auto callback =
94 base::Bind(&ApplicationManager::HandleFetchCallback, 94 base::Bind(&ApplicationManager::HandleFetchCallback,
95 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params)); 95 weak_ptr_factory_.GetWeakPtr(), base::Passed(&params));
96 package_manager_->FetchRequest(original_url_request.Pass(), callback); 96 package_manager_->FetchRequest(original_url_request.Pass(), callback);
97 } 97 }
98 98
99 bool ApplicationManager::ConnectToRunningApplication( 99 bool ApplicationManager::ConnectToRunningApplication(
100 scoped_ptr<ConnectToApplicationParams>* params) { 100 scoped_ptr<ConnectToApplicationParams>* params) {
101 ApplicationInstance* instance = GetApplicationInstance((*params)->target()); 101 ApplicationInstance* instance = GetApplicationInstance(
102 Identity((*params)->app_url(), (*params)->qualifier()));
102 if (!instance) 103 if (!instance)
103 return false; 104 return false;
104 105
105 instance->ConnectToClient(params->Pass()); 106 instance->ConnectToClient(params->Pass());
106 return true; 107 return true;
107 } 108 }
108 109
109 InterfaceRequest<Application> ApplicationManager::CreateInstance( 110 InterfaceRequest<Application> ApplicationManager::CreateInstance(
110 scoped_ptr<ConnectToApplicationParams> params, 111 scoped_ptr<ConnectToApplicationParams> params,
111 ApplicationInstance** resulting_instance) { 112 ApplicationInstance** resulting_instance) {
112 Identity target_id = params->target(); 113 Identity app_identity(params->app_url(), params->qualifier());
114
113 ApplicationPtr application; 115 ApplicationPtr application;
114 InterfaceRequest<Application> application_request = GetProxy(&application); 116 InterfaceRequest<Application> application_request = GetProxy(&application);
115 ApplicationInstance* instance = new ApplicationInstance( 117 ApplicationInstance* instance = new ApplicationInstance(
116 application.Pass(), this, target_id, Shell::kInvalidContentHandlerID, 118 application.Pass(), this, params->originator_identity(), app_identity,
119 params->filter(), Shell::kInvalidContentHandlerID,
117 params->on_application_end()); 120 params->on_application_end());
118 DCHECK(identity_to_instance_.find(target_id) == 121 DCHECK(identity_to_instance_.find(app_identity) ==
119 identity_to_instance_.end()); 122 identity_to_instance_.end());
120 identity_to_instance_[target_id] = instance; 123 identity_to_instance_[app_identity] = instance;
121 instance->InitializeApplication(); 124 instance->InitializeApplication();
122 instance->ConnectToClient(params.Pass()); 125 instance->ConnectToClient(params.Pass());
123 if (resulting_instance) 126 if (resulting_instance)
124 *resulting_instance = instance; 127 *resulting_instance = instance;
125 return application_request.Pass(); 128 return application_request.Pass();
126 } 129 }
127 130
128 ApplicationInstance* ApplicationManager::GetApplicationInstance( 131 ApplicationInstance* ApplicationManager::GetApplicationInstance(
129 const Identity& identity) const { 132 const Identity& identity) const {
130 const auto& it = identity_to_instance_.find(identity); 133 const auto& it = identity_to_instance_.find(identity);
(...skipping 12 matching lines...) Expand all
143 GURL redirect_url = fetcher->GetRedirectURL(); 146 GURL redirect_url = fetcher->GetRedirectURL();
144 if (!redirect_url.is_empty()) { 147 if (!redirect_url.is_empty()) {
145 // And around we go again... Whee! 148 // And around we go again... Whee!
146 // TODO(sky): this loses the original URL info. 149 // TODO(sky): this loses the original URL info.
147 URLRequestPtr new_request = URLRequest::New(); 150 URLRequestPtr new_request = URLRequest::New();
148 new_request->url = redirect_url.spec(); 151 new_request->url = redirect_url.spec();
149 HttpHeaderPtr header = HttpHeader::New(); 152 HttpHeaderPtr header = HttpHeader::New();
150 header->name = "Referer"; 153 header->name = "Referer";
151 header->value = fetcher->GetRedirectReferer().spec(); 154 header->value = fetcher->GetRedirectReferer().spec();
152 new_request->headers.push_back(header.Pass()); 155 new_request->headers.push_back(header.Pass());
153 params->SetTargetURLRequest(new_request.Pass()); 156 params->SetURLInfo(new_request.Pass());
154 ConnectToApplication(params.Pass()); 157 ConnectToApplication(params.Pass());
155 return; 158 return;
156 } 159 }
157 160
158 // We already checked if the application was running before we fetched it, but 161 // We already checked if the application was running before we fetched it, but
159 // it might have started while the fetch was outstanding. We don't want to 162 // it might have started while the fetch was outstanding. We don't want to
160 // have two copies of the app running, so check again. 163 // have two copies of the app running, so check again.
161 if (ConnectToRunningApplication(&params)) 164 if (ConnectToRunningApplication(&params))
162 return; 165 return;
163 166
164 Identity source = params->source(); 167 Identity originator_identity = params->originator_identity();
165 Identity target = params->target(); 168 CapabilityFilter originator_filter = params->originator_filter();
169 CapabilityFilter filter = params->filter();
170 GURL app_url = params->app_url();
171 std::string qualifier = params->qualifier();
166 Shell::ConnectToApplicationCallback connect_callback = 172 Shell::ConnectToApplicationCallback connect_callback =
167 params->connect_callback(); 173 params->connect_callback();
168 params->set_connect_callback(EmptyConnectCallback()); 174 params->set_connect_callback(EmptyConnectCallback());
169 ApplicationInstance* app = nullptr; 175 ApplicationInstance* app = nullptr;
170 InterfaceRequest<Application> request(CreateInstance(params.Pass(), &app)); 176 InterfaceRequest<Application> request(CreateInstance(params.Pass(), &app));
171 177
172 178
173 GURL content_handler_url; 179 GURL content_handler_url;
174 URLResponsePtr new_response; 180 URLResponsePtr new_response;
175 std::string qualifier;
176 if (package_manager_->HandleWithContentHandler(fetcher.get(), 181 if (package_manager_->HandleWithContentHandler(fetcher.get(),
177 target.url(), 182 app_url,
178 blocking_pool_, 183 blocking_pool_,
179 &new_response, 184 &new_response,
180 &content_handler_url, 185 &content_handler_url,
181 &qualifier)) { 186 &qualifier)) {
182 Identity content_handler(content_handler_url, qualifier, target.filter()); 187 LoadWithContentHandler(originator_identity, originator_filter,
183 LoadWithContentHandler(source, content_handler, connect_callback, app, 188 content_handler_url, qualifier, filter,
184 request.Pass(), new_response.Pass()); 189 connect_callback, app, request.Pass(),
190 new_response.Pass());
185 } else { 191 } else {
186 // TODO(erg): Have a better way of switching the sandbox on. For now, switch 192 // TODO(erg): Have a better way of switching the sandbox on. For now, switch
187 // it on hard coded when we're using some of the sandboxable core services. 193 // it on hard coded when we're using some of the sandboxable core services.
188 bool start_sandboxed = false; 194 bool start_sandboxed = false;
189 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 195 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
190 switches::kMojoNoSandbox)) { 196 switches::kMojoNoSandbox)) {
191 start_sandboxed = (target.url() == GURL("mojo://core_services/") && 197 if (app_url == GURL("mojo://core_services/") && qualifier == "Core")
192 target.qualifier() == "Core") || 198 start_sandboxed = true;
193 target.url() == GURL("mojo://html_viewer/"); 199 else if (app_url == GURL("mojo://html_viewer/"))
200 start_sandboxed = true;
194 } 201 }
195 202
196 connect_callback.Run(Shell::kInvalidContentHandlerID); 203 connect_callback.Run(Shell::kInvalidContentHandlerID);
197 204
198 fetcher->AsPath(blocking_pool_, 205 fetcher->AsPath(blocking_pool_,
199 base::Bind(&ApplicationManager::RunNativeApplication, 206 base::Bind(&ApplicationManager::RunNativeApplication,
200 weak_ptr_factory_.GetWeakPtr(), 207 weak_ptr_factory_.GetWeakPtr(),
201 base::Passed(request.Pass()), start_sandboxed, 208 base::Passed(request.Pass()), start_sandboxed,
202 base::Passed(fetcher.Pass()))); 209 base::Passed(fetcher.Pass())));
203 } 210 }
(...skipping 19 matching lines...) Expand all
223 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path", 230 TRACE_EVENT1("mojo_shell", "ApplicationManager::RunNativeApplication", "path",
224 path.AsUTF8Unsafe()); 231 path.AsUTF8Unsafe());
225 NativeRunner* runner = native_runner_factory_->Create().release(); 232 NativeRunner* runner = native_runner_factory_->Create().release();
226 native_runners_.push_back(runner); 233 native_runners_.push_back(runner);
227 runner->Start(path, start_sandboxed, application_request.Pass(), 234 runner->Start(path, start_sandboxed, application_request.Pass(),
228 base::Bind(&ApplicationManager::CleanupRunner, 235 base::Bind(&ApplicationManager::CleanupRunner,
229 weak_ptr_factory_.GetWeakPtr(), runner)); 236 weak_ptr_factory_.GetWeakPtr(), runner));
230 } 237 }
231 238
232 void ApplicationManager::LoadWithContentHandler( 239 void ApplicationManager::LoadWithContentHandler(
233 const Identity& source, 240 const Identity& originator_identity,
234 const Identity& content_handler, 241 const CapabilityFilter& originator_filter,
242 const GURL& content_handler_url,
243 const std::string& qualifier,
244 const CapabilityFilter& filter,
235 const Shell::ConnectToApplicationCallback& connect_callback, 245 const Shell::ConnectToApplicationCallback& connect_callback,
236 ApplicationInstance* app, 246 ApplicationInstance* app,
237 InterfaceRequest<Application> application_request, 247 InterfaceRequest<Application> application_request,
238 URLResponsePtr url_response) { 248 URLResponsePtr url_response) {
239 ContentHandlerConnection* connection = nullptr; 249 ContentHandlerConnection* connection = nullptr;
250 Identity content_handler_identity(content_handler_url, qualifier);
240 // TODO(beng): Figure out the extent to which capability filter should be 251 // TODO(beng): Figure out the extent to which capability filter should be
241 // factored into handler identity. 252 // factored into handler identity.
242 IdentityToContentHandlerMap::iterator iter = 253 IdentityToContentHandlerMap::iterator iter =
243 identity_to_content_handler_.find(content_handler); 254 identity_to_content_handler_.find(content_handler_identity);
244 if (iter != identity_to_content_handler_.end()) { 255 if (iter != identity_to_content_handler_.end()) {
245 connection = iter->second; 256 connection = iter->second;
246 } else { 257 } else {
247 connection = new ContentHandlerConnection( 258 connection = new ContentHandlerConnection(
248 this, source, content_handler, ++content_handler_id_counter_); 259 this, originator_identity, originator_filter, content_handler_url,
249 identity_to_content_handler_[content_handler] = connection; 260 qualifier, filter, ++content_handler_id_counter_);
261 identity_to_content_handler_[content_handler_identity] = connection;
250 } 262 }
251 263
252 app->set_requesting_content_handler_id(connection->id()); 264 app->set_requesting_content_handler_id(connection->id());
253 connection->content_handler()->StartApplication(application_request.Pass(), 265 connection->content_handler()->StartApplication(application_request.Pass(),
254 url_response.Pass()); 266 url_response.Pass());
255 connect_callback.Run(connection->id()); 267 connect_callback.Run(connection->id());
256 } 268 }
257 269
258 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader, 270 void ApplicationManager::SetLoaderForURL(scoped_ptr<ApplicationLoader> loader,
259 const GURL& url) { 271 const GURL& url) {
(...skipping 20 matching lines...) Expand all
280 DCHECK(it != identity_to_instance_.end()); 292 DCHECK(it != identity_to_instance_.end());
281 delete it->second; 293 delete it->second;
282 identity_to_instance_.erase(it); 294 identity_to_instance_.erase(it);
283 if (!on_application_end.is_null()) 295 if (!on_application_end.is_null())
284 on_application_end.Run(); 296 on_application_end.Run();
285 } 297 }
286 298
287 void ApplicationManager::OnContentHandlerConnectionClosed( 299 void ApplicationManager::OnContentHandlerConnectionClosed(
288 ContentHandlerConnection* content_handler) { 300 ContentHandlerConnection* content_handler) {
289 // Remove the mapping to the content handler. 301 // Remove the mapping to the content handler.
290 auto it = identity_to_content_handler_.find(content_handler->identity()); 302 auto it = identity_to_content_handler_.find(
303 Identity(content_handler->content_handler_url(),
304 content_handler->content_handler_qualifier()));
291 DCHECK(it != identity_to_content_handler_.end()); 305 DCHECK(it != identity_to_content_handler_.end());
292 identity_to_content_handler_.erase(it); 306 identity_to_content_handler_.erase(it);
293 } 307 }
294 308
295 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 309 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
296 native_runners_.erase( 310 native_runners_.erase(
297 std::find(native_runners_.begin(), native_runners_.end(), runner)); 311 std::find(native_runners_.begin(), native_runners_.end(), runner));
298 } 312 }
299 313
300 Shell::ConnectToApplicationCallback EmptyConnectCallback() { 314 Shell::ConnectToApplicationCallback EmptyConnectCallback() {
301 return base::Bind(&OnEmptyOnConnectCallback); 315 return base::Bind(&OnEmptyOnConnectCallback);
302 } 316 }
303 317
304 } // namespace shell 318 } // namespace shell
305 } // namespace mojo 319 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/application_manager.h ('k') | mojo/shell/application_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698