michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cr = Components.results; michael@0: const Cc = Components.classes; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/CommonDialog.jsm"); michael@0: michael@0: let propBag, args, Dialog; michael@0: michael@0: function commonDialogOnLoad() { michael@0: propBag = window.arguments[0].QueryInterface(Ci.nsIWritablePropertyBag2) michael@0: .QueryInterface(Ci.nsIWritablePropertyBag); michael@0: // Convert to a JS object michael@0: args = {}; michael@0: let propEnum = propBag.enumerator; michael@0: while (propEnum.hasMoreElements()) { michael@0: let prop = propEnum.getNext().QueryInterface(Ci.nsIProperty); michael@0: args[prop.name] = prop.value; michael@0: } michael@0: michael@0: let dialog = document.documentElement; michael@0: michael@0: let ui = { michael@0: prompt : window, michael@0: loginContainer : document.getElementById("loginContainer"), michael@0: loginTextbox : document.getElementById("loginTextbox"), michael@0: loginLabel : document.getElementById("loginLabel"), michael@0: password1Container : document.getElementById("password1Container"), michael@0: password1Textbox : document.getElementById("password1Textbox"), michael@0: password1Label : document.getElementById("password1Label"), michael@0: infoBody : document.getElementById("info.body"), michael@0: infoTitle : document.getElementById("info.title"), michael@0: infoIcon : document.getElementById("info.icon"), michael@0: checkbox : document.getElementById("checkbox"), michael@0: checkboxContainer : document.getElementById("checkboxContainer"), michael@0: button3 : dialog.getButton("extra2"), michael@0: button2 : dialog.getButton("extra1"), michael@0: button1 : dialog.getButton("cancel"), michael@0: button0 : dialog.getButton("accept"), michael@0: focusTarget : window, michael@0: }; michael@0: michael@0: // limit the dialog to the screen width michael@0: document.getElementById("filler").maxWidth = screen.availWidth; michael@0: Services.obs.addObserver(softkbObserver, "softkb-change", false); michael@0: michael@0: Dialog = new CommonDialog(args, ui); michael@0: Dialog.onLoad(dialog); michael@0: window.getAttention(); michael@0: } michael@0: michael@0: function commonDialogOnUnload() { michael@0: Services.obs.removeObserver(softkbObserver, "softkb-change"); michael@0: // Convert args back into property bag michael@0: for (let propName in args) michael@0: propBag.setProperty(propName, args[propName]); michael@0: } michael@0: michael@0: function softkbObserver(subject, topic, data) { michael@0: let rect = JSON.parse(data); michael@0: if (rect) { michael@0: let height = rect.bottom - rect.top; michael@0: let width = rect.right - rect.left; michael@0: let top = (rect.top + (height - window.innerHeight) / 2); michael@0: let left = (rect.left + (width - window.innerWidth) / 2); michael@0: window.moveTo(left, top); michael@0: } michael@0: }