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

Side by Side Diff: mojo/public/python/mojo_application/application_impl.py

Issue 943053003: Simple multi-url support for mojo apps (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: hate Created 5 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 """Python implementation of the Application interface.""" 5 """Python implementation of the Application interface."""
6 6
7 import application_mojom 7 import application_mojom
8 import service_provider_mojom 8 import service_provider_mojom
9 import shell_mojom 9 import shell_mojom
10 from mojo_application.service_provider_impl import ServiceProviderImpl 10 from mojo_application.service_provider_impl import ServiceProviderImpl
11 11
12 import mojo_system 12 import mojo_system
13 13
14 class ApplicationImpl(application_mojom.Application): 14 class ApplicationImpl(application_mojom.Application):
15 def __init__(self, delegate, app_request_handle): 15 def __init__(self, delegate, app_request_handle):
16 self.shell = None 16 self.shell = None
17 self.url = None 17 self.url = None
18 self.args = None 18 self.args = None
19 self._delegate = delegate 19 self._delegate = delegate
20 self._providers = [] 20 self._providers = []
21 application_mojom.Application.manager.Bind(self, app_request_handle) 21 application_mojom.Application.manager.Bind(self, app_request_handle)
22 22
23 def Initialize(self, shell, url, args): 23 def Initialize(self, shell, url, args):
24 self.shell = shell 24 self.shell = shell
25 self.url = url 25 self.url = url
26 self.args = args 26 self.args = args
27 self._delegate.Initialize(shell, self) 27 self._delegate.Initialize(shell, self)
28 28
29 def AcceptConnection(self, requestor_url, services, exposed_services): 29 def AcceptConnection(self, requestor_url, services, exposed_services,
30 resolved_url):
30 service_provider = ServiceProviderImpl(services) 31 service_provider = ServiceProviderImpl(services)
31 if self._delegate.OnAcceptConnection(service_provider, requestor_url, 32 if self._delegate.OnAcceptConnection(service_provider, requestor_url,
32 exposed_services): 33 exposed_services, resolved_url):
33 # We keep a reference to ServiceProviderImpl to ensure neither it nor 34 # We keep a reference to ServiceProviderImpl to ensure neither it nor
34 # |services| gets garbage collected. 35 # |services| gets garbage collected.
35 services.Bind(service_provider) 36 services.Bind(service_provider)
36 self._providers.append(service_provider) 37 self._providers.append(service_provider)
37 38
38 def removeServiceProvider(): 39 def removeServiceProvider():
39 self._providers.remove(service_provider) 40 self._providers.remove(service_provider)
40 service_provider.manager.AddOnErrorCallback(removeServiceProvider) 41 service_provider.manager.AddOnErrorCallback(removeServiceProvider)
41 42
42 def ConnectToService(self, application_url, service_class): 43 def ConnectToService(self, application_url, service_class):
43 """ 44 """
44 Helper method to connect to a service. |application_url| is the URL of the 45 Helper method to connect to a service. |application_url| is the URL of the
45 application to be connected to, and |service_class| is the class of the 46 application to be connected to, and |service_class| is the class of the
46 service to be connected to. Returns a proxy to the service. 47 service to be connected to. Returns a proxy to the service.
47 """ 48 """
48 application_proxy, request = ( 49 application_proxy, request = (
49 service_provider_mojom.ServiceProvider.manager.NewRequest()) 50 service_provider_mojom.ServiceProvider.manager.NewRequest())
50 self.shell.ConnectToApplication(application_url, request, None) 51 self.shell.ConnectToApplication(application_url, request, None)
51 52
52 service_proxy, request = service_class.manager.NewRequest() 53 service_proxy, request = service_class.manager.NewRequest()
53 application_proxy.ConnectToService(service_class.manager.name, 54 application_proxy.ConnectToService(service_class.manager.name,
54 request.PassMessagePipe()) 55 request.PassMessagePipe())
55 56
56 return service_proxy 57 return service_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698