2014-04-05 01:50:42 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cu = Components.utils;
|
2014-04-05 01:50:42 +04:00
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = [ "RemotePrompt" ];
|
|
|
|
|
|
|
|
Cu.import("resource:///modules/PlacesUIUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/SharedPromptUtils.jsm");
|
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var RemotePrompt = {
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2014-04-05 01:50:42 +04:00
|
|
|
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
|
|
|
|
mm.addMessageListener("Prompt:Open", this);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
receiveMessage(message) {
|
2014-04-05 01:50:42 +04:00
|
|
|
switch (message.name) {
|
|
|
|
case "Prompt:Open":
|
|
|
|
if (message.data.uri) {
|
|
|
|
this.openModalWindow(message.data, message.target);
|
|
|
|
} else {
|
|
|
|
this.openTabPrompt(message.data, message.target)
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
openTabPrompt(args, browser) {
|
2016-07-16 11:20:04 +03:00
|
|
|
let window = browser.ownerGlobal;
|
2014-04-05 01:50:42 +04:00
|
|
|
let tabPrompt = window.gBrowser.getTabModalPromptBox(browser)
|
|
|
|
let newPrompt;
|
2015-09-30 01:46:23 +03:00
|
|
|
let needRemove = false;
|
2014-04-05 01:50:42 +04:00
|
|
|
let promptId = args._remoteId;
|
|
|
|
|
|
|
|
function onPromptClose(forceCleanup) {
|
2015-09-30 01:46:23 +03:00
|
|
|
// It's possible that we removed the prompt during the
|
|
|
|
// appendPrompt call below. In that case, newPrompt will be
|
|
|
|
// undefined. We set the needRemove flag to remember to remove
|
|
|
|
// it right after we've finished adding it.
|
2014-04-05 01:50:42 +04:00
|
|
|
if (newPrompt)
|
|
|
|
tabPrompt.removePrompt(newPrompt);
|
2015-09-30 01:46:23 +03:00
|
|
|
else
|
|
|
|
needRemove = true;
|
2014-04-05 01:50:42 +04:00
|
|
|
|
|
|
|
PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
|
|
|
|
browser.messageManager.sendAsyncMessage("Prompt:Close", args);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.messageManager.addMessageListener("Prompt:ForceClose", function listener(message) {
|
|
|
|
// If this was for another prompt in the same tab, ignore it.
|
|
|
|
if (message.data._remoteId !== promptId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.messageManager.removeMessageListener("Prompt:ForceClose", listener);
|
|
|
|
|
|
|
|
if (newPrompt) {
|
|
|
|
newPrompt.abortPrompt();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
2015-10-26 16:17:16 +03:00
|
|
|
let eventDetail = {
|
|
|
|
tabPrompt: true,
|
|
|
|
promptPrincipal: args.promptPrincipal,
|
|
|
|
inPermitUnload: args.inPermitUnload,
|
|
|
|
};
|
2015-10-12 20:10:44 +03:00
|
|
|
PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser, eventDetail);
|
2014-04-05 01:50:42 +04:00
|
|
|
|
|
|
|
args.promptActive = true;
|
|
|
|
|
|
|
|
newPrompt = tabPrompt.appendPrompt(args, onPromptClose);
|
|
|
|
|
2015-09-30 01:46:23 +03:00
|
|
|
if (needRemove) {
|
|
|
|
tabPrompt.removePrompt(newPrompt);
|
|
|
|
}
|
|
|
|
|
2014-04-05 01:50:42 +04:00
|
|
|
// TODO since we don't actually open a window, need to check if
|
|
|
|
// there's other stuff in nsWindowWatcher::OpenWindowInternal
|
|
|
|
// that we might need to do here as well.
|
|
|
|
} catch (ex) {
|
|
|
|
onPromptClose(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
openModalWindow(args, browser) {
|
2016-07-16 11:20:04 +03:00
|
|
|
let window = browser.ownerGlobal;
|
2014-04-05 01:50:42 +04:00
|
|
|
try {
|
|
|
|
PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser);
|
|
|
|
let bag = PromptUtils.objectToPropBag(args);
|
|
|
|
|
|
|
|
Services.ww.openWindow(window, args.uri, "_blank",
|
|
|
|
"centerscreen,chrome,modal,titlebar", bag);
|
|
|
|
|
|
|
|
PromptUtils.propBagToObject(bag, args);
|
|
|
|
} finally {
|
|
|
|
PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
|
|
|
|
browser.messageManager.sendAsyncMessage("Prompt:Close", args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|