1 /* vim: set ts=2 sw=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 let Cc = Components.classes;
9 let Ci = Components.interfaces;
10 let Cu = Components.utils;
12 this.EXPORTED_SYMBOLS = [ "RemotePrompt" ];
14 Cu.import("resource:///modules/PlacesUIUtils.jsm");
15 Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
16 Cu.import("resource://gre/modules/Services.jsm");
17 Cu.import("resource://gre/modules/SharedPromptUtils.jsm");
21 let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
22 mm.addMessageListener("Prompt:Open", this);
25 receiveMessage: function(message) {
26 switch (message.name) {
28 if (message.data.uri) {
29 this.openModalWindow(message.data, message.target);
31 this.openTabPrompt(message.data, message.target)
37 openTabPrompt: function(args, browser) {
38 let window = browser.ownerDocument.defaultView;
39 let tabPrompt = window.gBrowser.getTabModalPromptBox(browser)
40 let callbackInvoked = false;
42 let promptId = args._remoteId;
44 function onPromptClose(forceCleanup) {
46 tabPrompt.removePrompt(newPrompt);
48 PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
49 browser.messageManager.sendAsyncMessage("Prompt:Close", args);
52 browser.messageManager.addMessageListener("Prompt:ForceClose", function listener(message) {
53 // If this was for another prompt in the same tab, ignore it.
54 if (message.data._remoteId !== promptId) {
58 browser.messageManager.removeMessageListener("Prompt:ForceClose", listener);
61 newPrompt.abortPrompt();
66 PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser);
68 args.promptActive = true;
70 newPrompt = tabPrompt.appendPrompt(args, onPromptClose);
72 // TODO since we don't actually open a window, need to check if
73 // there's other stuff in nsWindowWatcher::OpenWindowInternal
74 // that we might need to do here as well.
80 openModalWindow: function(args, browser) {
81 let window = browser.ownerDocument.defaultView;
83 PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser);
84 let bag = PromptUtils.objectToPropBag(args);
86 Services.ww.openWindow(window, args.uri, "_blank",
87 "centerscreen,chrome,modal,titlebar", bag);
89 PromptUtils.propBagToObject(bag, args);
91 PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
92 browser.messageManager.sendAsyncMessage("Prompt:Close", args);