michael@0: /* vim: set ts=2 sw=2 et tw=80: */ 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: "use strict"; michael@0: michael@0: let Cc = Components.classes; michael@0: let Ci = Components.interfaces; michael@0: let Cu = Components.utils; michael@0: michael@0: this.EXPORTED_SYMBOLS = [ "RemotePrompt" ]; michael@0: michael@0: Cu.import("resource:///modules/PlacesUIUtils.jsm"); michael@0: Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm"); michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/SharedPromptUtils.jsm"); michael@0: michael@0: let RemotePrompt = { michael@0: init: function() { michael@0: let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager); michael@0: mm.addMessageListener("Prompt:Open", this); michael@0: }, michael@0: michael@0: receiveMessage: function(message) { michael@0: switch (message.name) { michael@0: case "Prompt:Open": michael@0: if (message.data.uri) { michael@0: this.openModalWindow(message.data, message.target); michael@0: } else { michael@0: this.openTabPrompt(message.data, message.target) michael@0: } michael@0: break; michael@0: } michael@0: }, michael@0: michael@0: openTabPrompt: function(args, browser) { michael@0: let window = browser.ownerDocument.defaultView; michael@0: let tabPrompt = window.gBrowser.getTabModalPromptBox(browser) michael@0: let callbackInvoked = false; michael@0: let newPrompt; michael@0: let promptId = args._remoteId; michael@0: michael@0: function onPromptClose(forceCleanup) { michael@0: if (newPrompt) michael@0: tabPrompt.removePrompt(newPrompt); michael@0: michael@0: PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser); michael@0: browser.messageManager.sendAsyncMessage("Prompt:Close", args); michael@0: } michael@0: michael@0: browser.messageManager.addMessageListener("Prompt:ForceClose", function listener(message) { michael@0: // If this was for another prompt in the same tab, ignore it. michael@0: if (message.data._remoteId !== promptId) { michael@0: return; michael@0: } michael@0: michael@0: browser.messageManager.removeMessageListener("Prompt:ForceClose", listener); michael@0: michael@0: if (newPrompt) { michael@0: newPrompt.abortPrompt(); michael@0: } michael@0: }); michael@0: michael@0: try { michael@0: PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser); michael@0: michael@0: args.promptActive = true; michael@0: michael@0: newPrompt = tabPrompt.appendPrompt(args, onPromptClose); michael@0: michael@0: // TODO since we don't actually open a window, need to check if michael@0: // there's other stuff in nsWindowWatcher::OpenWindowInternal michael@0: // that we might need to do here as well. michael@0: } catch (ex) { michael@0: onPromptClose(true); michael@0: } michael@0: }, michael@0: michael@0: openModalWindow: function(args, browser) { michael@0: let window = browser.ownerDocument.defaultView; michael@0: try { michael@0: PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser); michael@0: let bag = PromptUtils.objectToPropBag(args); michael@0: michael@0: Services.ww.openWindow(window, args.uri, "_blank", michael@0: "centerscreen,chrome,modal,titlebar", bag); michael@0: michael@0: PromptUtils.propBagToObject(bag, args); michael@0: } finally { michael@0: PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser); michael@0: browser.messageManager.sendAsyncMessage("Prompt:Close", args); michael@0: } michael@0: } michael@0: };