keep_alive.js 992 B

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