| OLD | NEW |
| 1 #!mojo mojo:js_content_handler | 1 #!mojo mojo:js_content_handler |
| 2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 define("main", [ | 6 define("main", [ |
| 7 "mojo/services/public/js/application", | 7 "mojo/services/public/js/application", |
| 8 "services/js/test/echo_service.mojom", | 8 "services/js/test/echo_service.mojom", |
| 9 ], function(application, echoServiceMojom) { | 9 ], function(application, echoServiceMojom) { |
| 10 | 10 |
| 11 const Application = application.Application; | 11 const Application = application.Application; |
| 12 const EchoService = echoServiceMojom.EchoService; | 12 const EchoService = echoServiceMojom.EchoService; |
| 13 var echoApp; | 13 var echoApp; |
| 14 | 14 |
| 15 class EchoServiceImpl { | 15 class EchoServiceImpl { |
| 16 echoString(s) { | 16 echoString(s) { |
| 17 return Promise.resolve({value: s}); | 17 return Promise.resolve({value: s}); |
| 18 } | 18 } |
| 19 | 19 |
| 20 // This method is only used by the ShareEchoService test. | |
| 21 shareEchoService() { | |
| 22 var echoTargetURL = echoApp.url.replace("echo.js", "echo_target.js"); | |
| 23 var targetSP = echoApp.shell.connectToApplication(echoTargetURL); | |
| 24 // This Promise resolves after echo_target.js has called the echoString() | |
| 25 // method defined on the local EchoService implementation. For its part, | |
| 26 // the target application quits after one successful call to echoString(). | |
| 27 return new Promise(function(resolve) { | |
| 28 targetSP.provideService(EchoService, function() { | |
| 29 this.echoString = function(s) { | |
| 30 resolve({ok: true}); | |
| 31 return Promise.resolve({value: s}); | |
| 32 } | |
| 33 }); | |
| 34 }); | |
| 35 } | |
| 36 | |
| 37 quit() { | 20 quit() { |
| 38 echoApp.quit(); | 21 echoApp.quit(); |
| 39 } | 22 } |
| 40 } | 23 } |
| 41 | 24 |
| 42 class Echo extends Application { | 25 class Echo extends Application { |
| 43 acceptConnection(url, serviceExchange) { | 26 acceptConnection(url, serviceExchange) { |
| 44 echoApp = this; | 27 echoApp = this; |
| 45 serviceExchange.provideService(EchoService, EchoServiceImpl); | 28 serviceExchange.provideService(EchoService, EchoServiceImpl); |
| 46 } | 29 } |
| 47 } | 30 } |
| 48 | 31 |
| 49 return Echo; | 32 return Echo; |
| 50 }); | 33 }); |
| OLD | NEW |