| OLD | NEW |
| 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 resolved_url): |
| 31 service_provider = ServiceProviderImpl(services) | 31 service_provider = ServiceProviderImpl(services) |
| 32 if self._delegate.OnAcceptConnection(service_provider, requestor_url, | 32 if self._delegate.OnAcceptConnection(requestor_url, resolved_url, |
| 33 exposed_services): | 33 service_provider, exposed_services): |
| 34 # We keep a reference to ServiceProviderImpl to ensure neither it nor | 34 # We keep a reference to ServiceProviderImpl to ensure neither it nor |
| 35 # |services| gets garbage collected. | 35 # |services| gets garbage collected. |
| 36 services.Bind(service_provider) | 36 services.Bind(service_provider) |
| 37 self._providers.append(service_provider) | 37 self._providers.append(service_provider) |
| 38 | 38 |
| 39 def removeServiceProvider(): | 39 def removeServiceProvider(): |
| 40 self._providers.remove(service_provider) | 40 self._providers.remove(service_provider) |
| 41 service_provider.manager.AddOnErrorCallback(removeServiceProvider) | 41 service_provider.manager.AddOnErrorCallback(removeServiceProvider) |
| 42 | 42 |
| 43 def ConnectToService(self, application_url, service_class): | 43 def ConnectToService(self, application_url, service_class): |
| 44 """ | 44 """ |
| 45 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 |
| 46 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 |
| 47 service to be connected to. Returns a proxy to the service. | 47 service to be connected to. Returns a proxy to the service. |
| 48 """ | 48 """ |
| 49 application_proxy, request = ( | 49 application_proxy, request = ( |
| 50 service_provider_mojom.ServiceProvider.manager.NewRequest()) | 50 service_provider_mojom.ServiceProvider.manager.NewRequest()) |
| 51 self.shell.ConnectToApplication(application_url, request, None) | 51 self.shell.ConnectToApplication(application_url, request, None) |
| 52 | 52 |
| 53 service_proxy, request = service_class.manager.NewRequest() | 53 service_proxy, request = service_class.manager.NewRequest() |
| 54 application_proxy.ConnectToService(service_class.manager.name, | 54 application_proxy.ConnectToService(service_class.manager.name, |
| 55 request.PassMessagePipe()) | 55 request.PassMessagePipe()) |
| 56 | 56 |
| 57 return service_proxy | 57 return service_proxy |
| OLD | NEW |