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 | |
michael@0 | 5 | const Ci = Components.interfaces; |
michael@0 | 6 | const Cr = Components.results; |
michael@0 | 7 | const Cc = Components.classes; |
michael@0 | 8 | const Cu = Components.utils; |
michael@0 | 9 | |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/CommonDialog.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | let propBag, args, Dialog; |
michael@0 | 14 | |
michael@0 | 15 | function commonDialogOnLoad() { |
michael@0 | 16 | propBag = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2) |
michael@0 | 17 | .QueryInterface(Ci.nsIWritablePropertyBag); |
michael@0 | 18 | // Convert to a JS object |
michael@0 | 19 | args = {}; |
michael@0 | 20 | let propEnum = propBag.enumerator; |
michael@0 | 21 | while (propEnum.hasMoreElements()) { |
michael@0 | 22 | let prop = propEnum.getNext().QueryInterface(Ci.nsIProperty); |
michael@0 | 23 | args[prop.name] = prop.value; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | let dialog = document.documentElement; |
michael@0 | 27 | |
michael@0 | 28 | let ui = { |
michael@0 | 29 | prompt : window, |
michael@0 | 30 | loginContainer : document.getElementById("loginContainer"), |
michael@0 | 31 | loginTextbox : document.getElementById("loginTextbox"), |
michael@0 | 32 | loginLabel : document.getElementById("loginLabel"), |
michael@0 | 33 | password1Container : document.getElementById("password1Container"), |
michael@0 | 34 | password1Textbox : document.getElementById("password1Textbox"), |
michael@0 | 35 | password1Label : document.getElementById("password1Label"), |
michael@0 | 36 | infoBody : document.getElementById("info.body"), |
michael@0 | 37 | infoTitle : document.getElementById("info.title"), |
michael@0 | 38 | infoIcon : document.getElementById("info.icon"), |
michael@0 | 39 | checkbox : document.getElementById("checkbox"), |
michael@0 | 40 | checkboxContainer : document.getElementById("checkboxContainer"), |
michael@0 | 41 | button3 : dialog.getButton("extra2"), |
michael@0 | 42 | button2 : dialog.getButton("extra1"), |
michael@0 | 43 | button1 : dialog.getButton("cancel"), |
michael@0 | 44 | button0 : dialog.getButton("accept"), |
michael@0 | 45 | focusTarget : window, |
michael@0 | 46 | }; |
michael@0 | 47 | |
michael@0 | 48 | // limit the dialog to the screen width |
michael@0 | 49 | document.getElementById("filler").maxWidth = screen.availWidth; |
michael@0 | 50 | Services.obs.addObserver(softkbObserver, "softkb-change", false); |
michael@0 | 51 | |
michael@0 | 52 | Dialog = new CommonDialog(args, ui); |
michael@0 | 53 | Dialog.onLoad(dialog); |
michael@0 | 54 | window.getAttention(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function commonDialogOnUnload() { |
michael@0 | 58 | Services.obs.removeObserver(softkbObserver, "softkb-change"); |
michael@0 | 59 | // Convert args back into property bag |
michael@0 | 60 | for (let propName in args) |
michael@0 | 61 | propBag.setProperty(propName, args[propName]); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function softkbObserver(subject, topic, data) { |
michael@0 | 65 | let rect = JSON.parse(data); |
michael@0 | 66 | if (rect) { |
michael@0 | 67 | let height = rect.bottom - rect.top; |
michael@0 | 68 | let width = rect.right - rect.left; |
michael@0 | 69 | let top = (rect.top + (height - window.innerHeight) / 2); |
michael@0 | 70 | let left = (rect.left + (width - window.innerWidth) / 2); |
michael@0 | 71 | window.moveTo(left, top); |
michael@0 | 72 | } |
michael@0 | 73 | } |