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 | |
| 5 | define('keep_alive', [ |
ben | 55d10efd | 2016-08-02 20:46:31 | [diff] [blame] | 6 | 'content/public/renderer/frame_interfaces', |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 7 | 'extensions/common/mojo/keep_alive.mojom', |
jamesr | 60a7dbf | 2014-11-07 01:24:51 | [diff] [blame] | 8 | 'mojo/public/js/core', |
ben | 55d10efd | 2016-08-02 20:46:31 | [diff] [blame] | 9 | ], function(frameInterfaces, mojom, core) { |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 10 | |
| 11 | /** |
| 12 | * An object that keeps the background page alive until closed. |
| 13 | * @constructor |
| 14 | * @alias module:keep_alive~KeepAlive |
| 15 | */ |
| 16 | function KeepAlive() { |
| 17 | /** |
| 18 | * The handle to the keep-alive object in the browser. |
| 19 | * @type {!MojoHandle} |
| 20 | * @private |
| 21 | */ |
ben | 55d10efd | 2016-08-02 20:46:31 | [diff] [blame] | 22 | this.handle_ = frameInterfaces.getInterface(mojom.KeepAlive.name); |
sammc | d9fddbc | 2014-10-28 01:07:00 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Removes this keep-alive. |
| 27 | */ |
| 28 | KeepAlive.prototype.close = function() { |
| 29 | core.close(this.handle_); |
| 30 | }; |
| 31 | |
| 32 | var exports = {}; |
| 33 | |
| 34 | return { |
| 35 | /** |
| 36 | * Creates a keep-alive. |
| 37 | * @return {!module:keep_alive~KeepAlive} A new keep-alive. |
| 38 | */ |
| 39 | createKeepAlive: function() { return new KeepAlive(); } |
| 40 | }; |
| 41 | }); |