sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Yuzhu Shen | d91c0f1 | 2017-11-20 22:51:17 | [diff] [blame] | 5 | if ((typeof mojo === 'undefined') || !mojo.bindingsLibraryInitialized) { |
| 6 | loadScript('mojo_bindings'); |
| 7 | } |
| 8 | loadScript('extensions/common/mojo/keep_alive.mojom'); |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 9 | |
Yuzhu Shen | d91c0f1 | 2017-11-20 22:51:17 | [diff] [blame] | 10 | /** |
| 11 | * An object that keeps the background page alive until closed. |
| 12 | * @constructor |
| 13 | * @alias module:keep_alive~KeepAlive |
| 14 | */ |
| 15 | function KeepAlive() { |
| 16 | var pipe = Mojo.createMessagePipe(); |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 17 | /** |
Yuzhu Shen | d91c0f1 | 2017-11-20 22:51:17 | [diff] [blame] | 18 | * The handle to the keep-alive object in the browser. |
| 19 | * @type {!MojoHandle} |
| 20 | * @private |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 21 | */ |
Yuzhu Shen | d91c0f1 | 2017-11-20 22:51:17 | [diff] [blame] | 22 | this.handle_ = pipe.handle0; |
| 23 | Mojo.bindInterface(extensions.KeepAlive.name, pipe.handle1); |
| 24 | } |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 25 | |
Yuzhu Shen | d91c0f1 | 2017-11-20 22:51:17 | [diff] [blame] | 26 | /** |
| 27 | * Removes this keep-alive. |
| 28 | */ |
| 29 | KeepAlive.prototype.close = function() { |
| 30 | this.handle_.close(); |
| 31 | }; |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 32 | |
Yuzhu Shen | d91c0f1 | 2017-11-20 22:51:17 | [diff] [blame] | 33 | /** |
| 34 | * Creates a keep-alive. |
| 35 | * @return {!module:keep_alive~KeepAlive} A new keep-alive. |
| 36 | */ |
| 37 | exports.$set('createKeepAlive', function() { return new KeepAlive(); }); |