Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1421 → Rev 1422

/mozilla/nomodal/branch/001_own_dialogs/src/components/Prompt.js
0,0 → 1,227
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
// =====================================================================================================================
// FIXME
// - focus if parent tab is selected
// - 'prompt' and 'auth' dialogs
// - only for unsecure-js windows
// - customize standard/modalless dialogs via prefs
function NoModal_Prompt()
{
Components.utils.import("resource://nomodal_modules/DialogParams.jsm");
}
NoModal_Prompt.prototype = {
classDescription: "NoModal_Prompt",
classID: Components.ID("{21fa8349-62d3-406b-b042-4016469d6fe0}"),
contractID: "@mozilla.org/embedcomp/prompt-service;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIPromptService, Components.interfaces.nsIPromptService2]),
 
// -----------------------------------------------------------------------------------------------------------------
showDialog: function(aParent, params)
{
var requestor = aParent.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var docShell = requestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var parentInt = requestor.getInterface(Components.interfaces.nsIDOMWindowInternal);
 
// disable all dynamics in the window
var jsAllowed = docShell.allowJavascript;
docShell.allowJavascript = false;
docShell.suspendRefreshURIs();
 
var win;
var refocus = function(aEvent) { dump("refocus\n"); if(win) win.focus(); };
var unload = function(aEvent) { dump("unload\n"); if(win) win.close(); };
aParent.addEventListener('click', refocus, true);
aParent.addEventListener('unload', unload, true);
 
var args = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
args.SetString(0, params.text);
args.SetString(2, params.iconClass);
args.SetString(6, params.editfield1Value);
args.SetString(12, params.dialogTitle);
args.SetString(13, params.openingSound);
args.SetInt (2, params.numberButtons);
args.SetInt (3, params.numberEditfields);
args.SetInt (7, params.soundEventId);
 
var windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
win = windowWatcher.openWindow(aParent, "chrome://global/content/commonDialog.xul",
"_blank", "centerscreen,chrome,titlebar", args);
 
 
 
var winInt = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowInternal);
 
var threadManager = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager);
 
while(!winInt.closed && threadManager.currentThread.processNextEvent(true));
 
if(!parentInt.closed) {
// restore
aParent.removeEventListener('click', refocus, true);
aParent.removeEventListener('unload', unload, true);
docShell.resumeRefreshURIs();
docShell.allowJavascript = jsAllowed;
 
//NoModal_DialogParams.decode(paramsRaw, params);
params.result = args.GetInt(0);
params.editfield1Value = args.GetString(6);
 
return true;
}
else {
return false;
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alert: function(aParent, aDialogTitle, aText)
{
var params = {
dialogTitleKey: "Alert",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 1,
numberEditfields: 0,
iconClass: "alert-icon",
openingSound: "_moz_alertdialog",
soundEventId: 1,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
//return NoModal_Prompt.origin.alert(aParent, aDialogTitle, aText);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.alertCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirm: function(aParent, aDialogTitle, aText)
{
var params = {
dialogTitleKey: "Confirm",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 0,
iconClass: "question-icon",
openingSound: "_moz_confirmdialog",
soundEventId: 2,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
 
return (params.result == 0);
//return NoModal_Prompt.origin.confirm(aParent, aDialogTitle, aText);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title,
aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmEx(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title,
aButton1Title, aButton2Title, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState)
{
dump("prompt p1\n");
// note: no check msg/state
var params = {
dialogTitleKey: "Prompt",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 1,
iconClass: "question-icon",
openingSound: "_moz_promptdialog",
soundEventId: 3,
url: "chrome://global/content/commonDialog.xul",
editfield1Value: aValue.value,
};
 
dump("prompt p2\n");
this.showDialog(aParent, params);
 
dump("prompt p3\n");
var res = (params.result == 0);
if(res) {
aValue.value = params.editfield1Value;
}
 
dump("prompt p4\n");
return res;
//return NoModal_Prompt.origin.prompt(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
promptUsernameAndPassword: function(aParent, aDialogTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.promptUsernameAndPassword(aParent, aDialogTitle, aText, aUsername, aPassword,
aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
promptPassword: function(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.promptPassword(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
select: function(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection)
{
return NoModal_Prompt.origin.select(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService2
promptAuth: function(aParent, aChannel, level, authInfo, checkboxLabel, checkValue)
{
return NoModal_Prompt.origin.promptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService2
asyncPromptAuth: function(aParent, aChannel, aCallback, aContext, level, authInfo, checkboxLabel, checkValue)
{
return NoModal_Prompt.origin.asyncPromptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
},
};
 
// =====================================================================================================================
function NSGetModule(compMgr, fileSpec)
{
dump("Prompt.js p3\n");
 
NoModal_Prompt.origin = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
 
return XPCOMUtils.generateModule([NoModal_Prompt]);
}
dump("Prompt.js p2\n");
/mozilla/nomodal/branch/001_own_dialogs/src/modules/DialogParams.jsm
0,0 → 1,42
var EXPORTED_SYMBOLS = ["NoModal_DialogParams"];
 
// =====================================================================================================================
var NoModal_DialogParams = {
MAX_VALUES: 8,
 
// -----------------------------------------------------------------------------------------------------------------
create: function()
{
return Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
},
 
// -----------------------------------------------------------------------------------------------------------------
encode: function(obj, params)
{
params.QueryInterface(Components.interfaces.nsIDialogParamBlock);
 
var i = 0;
for(var a in obj) {
params.SetString(i++, a);
params.SetString(i++, obj[a]);
}
 
for(; i < NoModal_DialogParams.MAX_VALUES * 2; ++i) {
params.SetString(i, null);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
decode: function(params, obj)
{
params.QueryInterface(Components.interfaces.nsIDialogParamBlock);
 
for(var i = 0; i < NoModal_DialogParams.MAX_VALUES; ++i) {
var k = params.GetString(i*2);
var v = params.GetString(i*2+1);
 
if(k != "") obj[k] = v;
}
},
}
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/dialog.css
0,0 → 1,2
@import url("chrome://communicator/skin/");
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Confirm.js
0,0 → 1,18
// =====================================================================================================================
NoModal.Dialog_Alert = function()
{
NoModal.Dialog.call(this);
}
NoModal.Dialog_Alert.prototype = {
// -----------------------------------------------------------------------------------------------------------------
onLoad: function()
{
NoModal.Dialog.prototype.onLoad.call(this);
 
return true;
},
}
NoModal.inherit(NoModal.Dialog_Alert, NoModal.Dialog);
 
// == REGISTER =========================================================================================================
NoModal.DialogClass = NoModal.Dialog_Alert;
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Dialog.js
0,0 → 1,77
// =====================================================================================================================
NoModal.onDialogLoad = function()
{
var dialogController = new NoModal.DialogClass();
 
dialogController.paramsRaw = window.arguments[0];
dialogController.params = {};
NoModal_DialogParams.decode(dialogController.paramsRaw, dialogController.params);
 
if(!dialogController.onLoad()) {
window.close();
}
 
window.addEventListener('dialogaccept', function(aEvent)
{
if(!dialogController.onDialogAccept()) {
aEvent.preventDefault();
aEvent.stopPropagation();
}
return true;
 
}, false);
window.addEventListener('dialogcancel', function(aEvent)
{
if(!dialogController.onDialogCancel()) {
aEvent.preventDefault();
aEvent.stopPropagation();
}
 
return true;
}, false);
}
 
// =====================================================================================================================
NoModal.Dialog = function()
{
}
NoModal.Dialog.prototype = {
// -----------------------------------------------------------------------------------------------------------------
onLoad: function()
{
// title
var dialogs = document.getElementsByTagName("dialog");
if(dialogs && dialogs.length > 0) {
dialogs[0].setAttribute('title', this.params.title);
}
 
// text
document.getElementById("text").value = this.params.text;
 
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
onDialogAccept: function()
{
this.setDialogResult(true);
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
onDialogCancel: function()
{
this.setDialogResult(false);
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
setDialogResult: function(result)
{
this.params.result = result;
NoModal_DialogParams.encode(this.params, this.paramsRaw);
},
}
 
// == BOOTSTRAP ========================================================================================================
window.addEventListener('load', NoModal.onDialogLoad, false);
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/browser.xul
0,0 → 1,13
<?xml version="1.0"?>
 
<overlay id="movelayer"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
<script type="application/x-javascript" src="chrome://nomodal/content/browser.js" />
 
<menupopup id="menu_EditPopup">
<menuseparator/>
<menuitem id="context-nomodal" label="NoModal" oncommand="NoModal.onCommand(this)" />
</menupopup>
 
</overlay>
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Alert.xul
0,0 → 1,16
<?xml version="1.0"?>
 
<?xml-stylesheet href="chrome://nomodal/content/dialog.css" type="text/css"?>
 
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
title="Alert"
buttons="accept"
>
 
<script type="application/x-javascript" src="chrome://nomodal/content/Common.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Dialog.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Alert.js" />
 
<label id="text" />
</dialog>
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/browser.js
0,0 → 1,16
// =====================================================================================================================
var NoModal = {
// -----------------------------------------------------------------------------------------------------------------
init: function()
{
},
 
// -----------------------------------------------------------------------------------------------------------------
onCommand: function(menuitem)
{
alert("NoModal.onCommand");
},
};
 
// == BOOTSTRAP ========================================================================================================
window.addEventListener('load', NoModal.init, false);
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Alert.js
0,0 → 1,18
// =====================================================================================================================
NoModal.Dialog_Alert = function()
{
NoModal.Dialog.call(this);
}
NoModal.Dialog_Alert.prototype = {
// -----------------------------------------------------------------------------------------------------------------
onLoad: function()
{
NoModal.Dialog.prototype.onLoad.call(this);
 
return true;
},
}
NoModal.inherit(NoModal.Dialog_Alert, NoModal.Dialog);
 
// == REGISTER =========================================================================================================
NoModal.DialogClass = NoModal.Dialog_Alert;
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Common.js
0,0 → 1,17
// =====================================================================================================================
var NoModal = {
// -----------------------------------------------------------------------------------------------------------------
inherit: function(child, supertype)
{
child.prototype.__proto__ = supertype.prototype;
},
 
// -----------------------------------------------------------------------------------------------------------------
startup: function()
{
Components.utils.import("resource://nomodal_modules/DialogParams.jsm");
},
}
 
// == BOOTSTRAP ========================================================================================================
NoModal.startup();
/mozilla/nomodal/branch/001_own_dialogs/src/chrome/content/Confirm.xul
0,0 → 1,16
<?xml version="1.0"?>
 
<?xml-stylesheet href="chrome://nomodal/content/dialog.css" type="text/css"?>
 
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
title="Confirm"
buttons="accept,cancel"
>
 
<script type="application/x-javascript" src="chrome://nomodal/content/Common.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Dialog.js" />
<script type="application/x-javascript" src="chrome://nomodal/content/Confirm.js" />
 
<label id="text" />
</dialog>
/mozilla/nomodal/branch/001_own_dialogs/src/install.rdf
0,0 → 1,27
<?xml version="1.0"?>
 
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
<Description about="urn:mozilla:install-manifest">
<em:id>{f4b488a5-3c73-4e28-b0c9-e03c9a71af65}</em:id>
<em:version>1.0</em:version>
<em:type>2</em:type>
 
<!-- firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.5.0</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
 
<em:name>NoModal</em:name>
<em:description></em:description>
<em:creator>Anatoli Klassen</em:creator>
<em:homepageURL></em:homepageURL>
<em:updateURL></em:updateURL>
<em:updateKey></em:updateKey>
</Description>
</RDF>
/mozilla/nomodal/branch/001_own_dialogs/src/chrome.manifest
0,0 → 1,4
content nomodal chrome/content/
resource nomodal_modules modules/
overlay chrome://browser/content/browser.xul chrome://nomodal/content/browser.xul
 
/mozilla/nomodal/trunk/meta.xml
0,0 → 1,4
<meta>
<xpiName>nomodal.xpi</xpiName>
</meta>
 
/mozilla/nomodal/trunk/src/install.rdf
0,0 → 1,27
<?xml version="1.0"?>
 
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
<Description about="urn:mozilla:install-manifest">
<em:id>{f4b488a5-3c73-4e28-b0c9-e03c9a71af65}</em:id>
<em:version>1.0</em:version>
<em:type>2</em:type>
 
<!-- firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.5.0</em:minVersion>
<em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
 
<em:name>NoModal</em:name>
<em:description></em:description>
<em:creator>Anatoli Klassen</em:creator>
<em:homepageURL></em:homepageURL>
<em:updateURL></em:updateURL>
<em:updateKey></em:updateKey>
</Description>
</RDF>
/mozilla/nomodal/trunk/src/chrome.manifest
0,0 → 1,0
content nomodal chrome/content/
/mozilla/nomodal/trunk/src/components/Prompt.js
0,0 → 1,509
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
// =====================================================================================================================
// FIXME
// - don't show the dialog in the task bar
// - if some other dialog is open, lower our zLevel
// - options and about dialogs
// - customize standard/modeless dialogs via prefs
function NoModal_Prompt()
{
this.windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
this.windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
this.threadManager = Components.classes["@mozilla.org/thread-manager;1"]
.getService(Components.interfaces.nsIThreadManager);
 
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
this.commonBundle = stringBundleService.createBundle("chrome://global/locale/commonDialogs.properties");
this.promptBundle = stringBundleService.createBundle("chrome://global/locale/prompts.properties");
}
NoModal_Prompt.prototype = {
classDescription: "NoModal_Prompt",
classID: Components.ID("{21fa8349-62d3-406b-b042-4016469d6fe0}"),
contractID: "@mozilla.org/embedcomp/prompt-service;1",
QueryInterface: XPCOMUtils.generateQI( [
Components.interfaces.nsIPromptService,
Components.interfaces.nsIPromptService2,
] ),
 
// -----------------------------------------------------------------------------------------------------------------
isEnabled: function(aParent, dialogName)
{
// replace dialogs for for js-windows only
if(("" + aParent) != "[object XPCNativeWrapper [object Window]]") { // FIXME a better method to detect js-window?
return false;
}
 
return true;
},
 
// -----------------------------------------------------------------------------------------------------------------
showDialog: function(aParent, params)
{
// parent interfaces
var parentRequestor = aParent.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var parentDocShell = parentRequestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var parentInt = parentRequestor.getInterface(Components.interfaces.nsIDOMWindowInternal);
var parentDom = parentRequestor.getInterface(Components.interfaces.nsIDOMWindow);
var mainWin = this.windowMediator.getMostRecentWindow("navigator:browser");
var tabBrowser = mainWin.gBrowser;
 
var parentTab;
for(var i = 0, l = tabBrowser.browsers.length; i < l; ++i) {
var b = tabBrowser.getBrowserAtIndex(i);
if(b.contentWindow == aParent) {
parentTab = tabBrowser.tabContainer.childNodes[i];
}
}
 
// disable all dynamics in the window
var jsAllowed = parentDocShell.allowJavascript;
parentDocShell.allowJavascript = false;
parentDocShell.suspendRefreshURIs();
 
// params
if(!params.dialogTitle) {
params.dialogTitle = this.commonBundle.GetStringFromName(params.dialogTitleKey);
}
 
var args = Components.classes["@mozilla.org/embedcomp/dialogparam;1"]
.createInstance(Components.interfaces.nsIDialogParamBlock);
args.SetString(0, params.text);
args.SetString(1, params.checkboxMsg);
args.SetString(2, params.iconClass);
args.SetString(3, params.titleMessage);
args.SetString(4, params.editfield1Msg);
args.SetString(5, params.editfield2Msg);
args.SetString(6, params.editfield1Value);
args.SetString(7, params.editfield2Value);
args.SetString(8, params.button0Text);
args.SetString(9, params.button1Text);
args.SetString(10, params.button2Text);
args.SetString(11, params.button3Text);
args.SetString(12, params.dialogTitle);
args.SetString(13, params.openingSound);
args.SetInt (1, params.checkboxState);
args.SetInt (2, params.numberButtons);
args.SetInt (3, params.numberEditfields);
args.SetInt (4, params.editField1Password);
args.SetInt (5, params.defaultButton);
args.SetInt (6, params.delayButtonEnable);
args.SetInt (7, params.soundEventId);
 
// show the dialog
var win = this.windowWatcher.openWindow(aParent, "chrome://global/content/commonDialog.xul",
"_blank", "centerscreen,chrome,titlebar" /*,dependent*/, args);
win.openInProgress = true;
 
var winRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var winDocShell = winRequestor.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShell);
var winInt = winRequestor.getInterface(Components.interfaces.nsIDOMWindowInternal);
 
var winXul;
var xulEnum = this.windowMediator.getXULWindowEnumerator(null);
while(xulEnum.hasMoreElements()) {
var xulWindow = xulEnum.getNext();
xulWindow.QueryInterface(Components.interfaces.nsIXULWindow);
if(xulWindow.docShell == winDocShell) {
winXul = xulWindow;
}
}
winXul.zLevel = Components.interfaces.nsIXULWindow.raisedZ;
 
// listeners
var parentClick = function(aEvent) {
if(win) {
win.focus();
}
};
var parentUnload = function(aEvent) {
if(win) {
win.close();
}
};
var winFocus = function(aEvent) {
if(aEvent.target == win) {
if(win.openInProgress) {
win.openInProgress = false;
}
else if(win.focusInProgress) {
win.focusInProgress = false;
}
else {
tabBrowser.selectedTab = parentTab;
mainWin.focus();
win.focusInProgress = true;
win.focus();
}
}
};
var parentTabSelect = function(aEvent) {
if(tabBrowser.selectedTab == parentTab) {
winXul.zLevel = Components.interfaces.nsIXULWindow.raisedZ;
win.focusInProgress = true;
win.focus();
}
else {
winXul.zLevel = Components.interfaces.nsIXULWindow.loweredZ;
}
};
 
aParent.addEventListener('click', parentClick, true);
aParent.addEventListener('unload', parentUnload, true);
win.addEventListener('focus', winFocus, false);
tabBrowser.tabContainer.addEventListener('TabSelect', parentTabSelect, false);
 
// wait until the dialog is closed
while(!winInt.closed && this.threadManager.currentThread.processNextEvent(true));
 
if(!parentInt.closed) {
// restore
aParent.removeEventListener('click', parentClick, true);
aParent.removeEventListener('unload', parentUnload, true);
win.removeEventListener('focus', winFocus, false);
tabBrowser.tabContainer.removeEventListener('TabSelect', parentTabSelect, false);
 
parentDocShell.resumeRefreshURIs();
parentDocShell.allowJavascript = jsAllowed;
 
// eval the answer
params.buttonPressed = args.GetInt(0);
params.checkboxState = args.GetInt(1);
params.editfield1Value = args.GetString(6);
params.editfield2Value = args.GetString(7);
 
return true;
}
else {
return false;
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alert: function(aParent, aDialogTitle, aText)
{
if(this.isEnabled(aParent, 'alert')) {
var params = {
dialogTitleKey: "Alert",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 1,
numberEditfields: 0,
iconClass: "alert-icon",
openingSound: "_moz_alertdialog",
soundEventId: 1,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
}
else {
NoModal_Prompt.origin.alert(aParent, aDialogTitle, aText);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
alertCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.alertCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirm: function(aParent, aDialogTitle, aText)
{
if(this.isEnabled(aParent, 'confirm')) {
var params = {
dialogTitleKey: "Confirm",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 0,
iconClass: "question-icon",
openingSound: "_moz_confirmdialog",
soundEventId: 2,
url: "chrome://global/content/commonDialog.xul",
};
 
this.showDialog(aParent, params);
 
return (params.buttonPressed == 0);
}
else {
return NoModal_Prompt.origin.confirm(aParent, aDialogTitle, aText);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmCheck: function(aParent, aDialogTitle, aText, aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmCheck(aParent, aDialogTitle, aText, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
confirmEx: function(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title,
aCheckMsg, aCheckState)
{
return NoModal_Prompt.origin.confirmEx(aParent, aDialogTitle, aText, aButtonFlags, aButton0Title,
aButton1Title, aButton2Title, aCheckMsg, aCheckState);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
prompt: function(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'confirm')) {
var params = {
dialogTitleKey: "Prompt",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 1,
iconClass: "question-icon",
openingSound: "_moz_promptdialog",
soundEventId: 3,
url: "chrome://global/content/commonDialog.xul",
editfield1Value: aValue.value,
};
 
if(aCheckMsg && aCheckState) {
params.checkboxMsg = aCheckMsg;
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
aValue.value = params.editfield1Value;
 
if(aCheckState) {
aCheckState.value = (params.checkboxState == 1);
}
}
 
return res;
}
else {
return NoModal_Prompt.origin.prompt(aParent, aDialogTitle, aText, aValue, aCheckMsg, aCheckState);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
promptUsernameAndPassword: function(aParent, aDialogTitle, aText, aUsername, aPassword, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'promptUsernameAndPassword')) {
var params = {
dialogTitleKey: "PromptUsernameAndPassword2",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 2,
iconClass: "authentication-icon question-icon",
openingSound: "_moz_promptdialog",
soundEventId: 3,
url: "chrome://global/content/commonDialog.xul",
editfield1Value: aUsername.value,
editfield2Value: aPassword.value,
};
 
if(aCheckMsg && aCheckState) {
params.checkboxMsg = aCheckMsg;
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
aUsername.value = params.editfield1Value;
aPassword.value = params.editfield2Value;
 
if(aCheckState) {
aCheckState.value = (params.checkboxState == 1);
}
}
 
return res;
}
else {
return NoModal_Prompt.origin.promptUsernameAndPassword(aParent, aDialogTitle, aText, aUsername, aPassword,
aCheckMsg, aCheckState);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
promptPassword: function(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState)
{
if(this.isEnabled(aParent, 'promptPassword')) {
var params = {
dialogTitleKey: "PromptPassword2",
dialogTitle: aDialogTitle,
text: aText,
numberButtons: 2,
numberEditfields: 1,
editField1Password: 1,
iconClass: "authentication-icon question-icon",
openingSound: "_moz_promptdialog",
soundEventId: 3,
url: "chrome://global/content/commonDialog.xul",
editfield1Value: aPassword.value,
};
 
if(aCheckMsg && aCheckState) {
params.checkboxMsg = aCheckMsg;
params.checkboxState = (aCheckState.value ? 1 : 0);
}
 
this.showDialog(aParent, params);
 
var res = (params.buttonPressed == 0);
if(res) {
aPassword.value = params.editfield1Value;
 
if(aCheckState) {
aCheckState.value = (params.checkboxState == 1);
}
}
 
return res;
}
else {
return NoModal_Prompt.origin.promptPassword(aParent, aDialogTitle, aText, aPassword, aCheckMsg, aCheckState);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService
select: function(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection)
{
return NoModal_Prompt.origin.select(aParent, aDialogTitle, aText, aCount, aSelectList, aOutSelection);
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService2
promptAuth: function(aParent, aChannel, level, authInfo, checkboxLabel, checkValue)
{
if(this.isEnabled(aParent, 'promptAuth')) {
return this.promptPasswordAdapter(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
}
else {
return NoModal_Prompt.origin.promptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
}
},
 
// -----------------------------------------------------------------------------------------------------------------
// interface nsIPromptService2
asyncPromptAuth: function(aParent, aChannel, aCallback, aContext, level, authInfo, checkboxLabel, checkValue)
{
return NoModal_Prompt.origin.asyncPromptAuth(aParent, aChannel, level, authInfo, checkboxLabel, checkValue);
},
 
// -----------------------------------------------------------------------------------------------------------------
// reimplement nsPrompt.cpp because it has no js-interface
promptPasswordAdapter: function(aParent, aChannel, level, authInfo, checkboxLabel, checkValue)
{
var msg = this.makeAuthDialogText(aChannel, authInfo);
 
var user = { value: authInfo.username };
var pass = { value: authInfo.password };
 
if((authInfo.flags & Components.interfaces.nsIAuthInformation.NEED_DOMAIN) && authInfo.domain) {
user.value = authInfo.domain + "\\" + user.value;
}
 
var res;
if(authInfo.flags & Components.interfaces.nsIAuthInformation.ONLY_PASSWORD) {
res = this.promptPassword(aParent, null, msg, pass, checkboxLabel, checkValue);
}
else {
res = this.promptUsernameAndPassword(aParent, null, msg, user, pass, checkboxLabel, checkValue);
}
 
authInfo.username = user.value;
authInfo.password = pass.value;
 
return res;
},
 
// -----------------------------------------------------------------------------------------------------------------
makeAuthDialogText: function(aChannel, authInfo)
{
var host;
var port;
if((authInfo.flags & Components.interfaces.nsIAuthInformation.AUTH_PROXY) != 0) {
aChannel.QueryInterface(Components.interfaces.nsIProxiedChannel);
host = aChannel.proxyInfo.host;
port = aChannel.proxyInfo.port;
}
else {
host = aChannel.URI.host;
port = aChannel.URI.port;
}
 
if(port != -1) {
host += ':' + port;
}
 
var proxyAuth = ((authInfo.flags & Components.interfaces.nsIAuthInformation.AUTH_PROXY) != 0);
 
var realm = authInfo.realm;
if(realm.length > 150) {
realm = realm.substring(0, 150);
 
var ellipsis;
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
var prefBranch = prefService.getBranch("intl.");
var prefValue = prefBranch.getComplexValue("ellipsis", Components.interfaces.nsIPrefLocalizedString);
 
ellipsis = prefValue.toString();
 
if(!ellipsis) ellipsis = "...";
realm += ellipsis;
}
 
var msg;
if(proxyAuth) {
msg = "EnterLoginForProxy";
}
else {
msg = "EnterLoginForRealm";
host = aChannel.URI.scheme + "://" + host;
}
 
var args = [ realm, host ];
 
if((authInfo.flags & Components.interfaces.nsIAuthInformation.ONLY_PASSWORD) != 0) {
msg = "EnterPasswordFor";
args[0] = authInfo.username;
}
else if(!proxyAuth && !realm) {
msg = "EnterUserPasswordFor";
args = [ host ];
}
 
return this.promptBundle.formatStringFromName(msg, args, args.length);
},
};
 
// =====================================================================================================================
function NSGetModule(compMgr, fileSpec)
{
NoModal_Prompt.origin = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
NoModal_Prompt.origin.QueryInterface(Components.interfaces.nsIPromptService2);
 
return XPCOMUtils.generateModule([NoModal_Prompt]);
}
/mozilla/nomodal/trunk/bin/deploy.sh
0,0 → 1,13
#!/bin/sh
 
project_dir=$(dirname $0)"/.."
project_dir=$(cd "$project_dir"; pwd)
common_dir="$project_dir/../../common/deploy"
 
if [ ! -d "$common_dir" ] ; then
echo "Common dir '$common_dir' not found" >> /dev/stderr
exit 1
fi
 
. "$common_dir/deploy_subr"
 
/mozilla/nomodal/trunk/test/index.html
0,0 → 1,32
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body onclick="dump('body.onclick\n')">
 
<script>
setInterval(function() {
dump((new Date()) + "\n");
}, 1000);
 
/*dump("before alert\n");
alert("here");
dump("after alert\n");*/
 
/*dump("window.alert " + (window.alert != null) + "\n");
dump("window.alertCheck " + (window.alertCheck != null) + "\n");
dump("window.confirm " + (window.confirm != null) + "\n");
dump("window.confirmCheck " + (window.confirmCheck != null) + "\n");
dump("window.confirmEx " + (window.confirmEx != null) + "\n");
dump("window.prompt " + (window.prompt != null) + "\n");
dump("window.promptUsernameAndPassword " + (window.promptUsernameAndPassword != null) + "\n");
dump("window.promptPassword " + (window.promptPassword != null) + "\n");
dump("window.select " + (window.select != null) + "\n");*/
</script>
 
<button onclick="dump('before alert\n'); alert('again'); dump('after alert\n');">alert</button><br>
<button onclick="dump('before confirm\n'); dump('confirm: ' + confirm('yes?') + '\n'); dump('after confirm\n');">confirm</button>
<button onclick="dump('before prompt\n'); dump('prompt: ' + prompt('hmmm?', 'aaa') + '\n'); dump('after prompt\n');">prompt</button>
 
</body>
</html>