Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | 'use strict'; |
michael@0 | 5 | |
michael@0 | 6 | const { defer } = require('../core/promise'); |
michael@0 | 7 | const events = require('../system/events'); |
michael@0 | 8 | const { open: openWindow, onFocus, getToplevelWindow, |
michael@0 | 9 | isInteractive, getOuterId } = require('./utils'); |
michael@0 | 10 | const { Ci } = require("chrome"); |
michael@0 | 11 | |
michael@0 | 12 | function open(uri, options) { |
michael@0 | 13 | return promise(openWindow.apply(null, arguments), 'load'); |
michael@0 | 14 | } |
michael@0 | 15 | exports.open = open; |
michael@0 | 16 | |
michael@0 | 17 | function close(window) { |
michael@0 | 18 | let deferred = defer(); |
michael@0 | 19 | let toplevelWindow = getToplevelWindow(window); |
michael@0 | 20 | let outerId = getOuterId(toplevelWindow); |
michael@0 | 21 | events.on("outer-window-destroyed", function onclose({subject}) { |
michael@0 | 22 | let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data; |
michael@0 | 23 | if (id == outerId) { |
michael@0 | 24 | events.off("outer-window-destroyed", onclose); |
michael@0 | 25 | deferred.resolve(); |
michael@0 | 26 | } |
michael@0 | 27 | }, true); |
michael@0 | 28 | window.close(); |
michael@0 | 29 | return deferred.promise; |
michael@0 | 30 | } |
michael@0 | 31 | exports.close = close; |
michael@0 | 32 | |
michael@0 | 33 | function focus(window) { |
michael@0 | 34 | let p = onFocus(window); |
michael@0 | 35 | window.focus(); |
michael@0 | 36 | return p; |
michael@0 | 37 | } |
michael@0 | 38 | exports.focus = focus; |
michael@0 | 39 | |
michael@0 | 40 | function ready(window) { |
michael@0 | 41 | let { promise: result, resolve } = defer(); |
michael@0 | 42 | |
michael@0 | 43 | if (isInteractive(window)) |
michael@0 | 44 | resolve(window); |
michael@0 | 45 | else |
michael@0 | 46 | resolve(promise(window, 'DOMContentLoaded')); |
michael@0 | 47 | |
michael@0 | 48 | return result; |
michael@0 | 49 | } |
michael@0 | 50 | exports.ready = ready; |
michael@0 | 51 | |
michael@0 | 52 | function promise(target, evt, capture) { |
michael@0 | 53 | let deferred = defer(); |
michael@0 | 54 | capture = !!capture; |
michael@0 | 55 | |
michael@0 | 56 | target.addEventListener(evt, function eventHandler() { |
michael@0 | 57 | target.removeEventListener(evt, eventHandler, capture); |
michael@0 | 58 | deferred.resolve(target); |
michael@0 | 59 | }, capture); |
michael@0 | 60 | |
michael@0 | 61 | return deferred.promise; |
michael@0 | 62 | } |
michael@0 | 63 | exports.promise = promise; |