browser/modules/RemotePrompt.jsm

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* vim: set ts=2 sw=2 et tw=80: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 "use strict";
michael@0 7
michael@0 8 let Cc = Components.classes;
michael@0 9 let Ci = Components.interfaces;
michael@0 10 let Cu = Components.utils;
michael@0 11
michael@0 12 this.EXPORTED_SYMBOLS = [ "RemotePrompt" ];
michael@0 13
michael@0 14 Cu.import("resource:///modules/PlacesUIUtils.jsm");
michael@0 15 Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
michael@0 16 Cu.import("resource://gre/modules/Services.jsm");
michael@0 17 Cu.import("resource://gre/modules/SharedPromptUtils.jsm");
michael@0 18
michael@0 19 let RemotePrompt = {
michael@0 20 init: function() {
michael@0 21 let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
michael@0 22 mm.addMessageListener("Prompt:Open", this);
michael@0 23 },
michael@0 24
michael@0 25 receiveMessage: function(message) {
michael@0 26 switch (message.name) {
michael@0 27 case "Prompt:Open":
michael@0 28 if (message.data.uri) {
michael@0 29 this.openModalWindow(message.data, message.target);
michael@0 30 } else {
michael@0 31 this.openTabPrompt(message.data, message.target)
michael@0 32 }
michael@0 33 break;
michael@0 34 }
michael@0 35 },
michael@0 36
michael@0 37 openTabPrompt: function(args, browser) {
michael@0 38 let window = browser.ownerDocument.defaultView;
michael@0 39 let tabPrompt = window.gBrowser.getTabModalPromptBox(browser)
michael@0 40 let callbackInvoked = false;
michael@0 41 let newPrompt;
michael@0 42 let promptId = args._remoteId;
michael@0 43
michael@0 44 function onPromptClose(forceCleanup) {
michael@0 45 if (newPrompt)
michael@0 46 tabPrompt.removePrompt(newPrompt);
michael@0 47
michael@0 48 PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
michael@0 49 browser.messageManager.sendAsyncMessage("Prompt:Close", args);
michael@0 50 }
michael@0 51
michael@0 52 browser.messageManager.addMessageListener("Prompt:ForceClose", function listener(message) {
michael@0 53 // If this was for another prompt in the same tab, ignore it.
michael@0 54 if (message.data._remoteId !== promptId) {
michael@0 55 return;
michael@0 56 }
michael@0 57
michael@0 58 browser.messageManager.removeMessageListener("Prompt:ForceClose", listener);
michael@0 59
michael@0 60 if (newPrompt) {
michael@0 61 newPrompt.abortPrompt();
michael@0 62 }
michael@0 63 });
michael@0 64
michael@0 65 try {
michael@0 66 PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser);
michael@0 67
michael@0 68 args.promptActive = true;
michael@0 69
michael@0 70 newPrompt = tabPrompt.appendPrompt(args, onPromptClose);
michael@0 71
michael@0 72 // TODO since we don't actually open a window, need to check if
michael@0 73 // there's other stuff in nsWindowWatcher::OpenWindowInternal
michael@0 74 // that we might need to do here as well.
michael@0 75 } catch (ex) {
michael@0 76 onPromptClose(true);
michael@0 77 }
michael@0 78 },
michael@0 79
michael@0 80 openModalWindow: function(args, browser) {
michael@0 81 let window = browser.ownerDocument.defaultView;
michael@0 82 try {
michael@0 83 PromptUtils.fireDialogEvent(window, "DOMWillOpenModalDialog", browser);
michael@0 84 let bag = PromptUtils.objectToPropBag(args);
michael@0 85
michael@0 86 Services.ww.openWindow(window, args.uri, "_blank",
michael@0 87 "centerscreen,chrome,modal,titlebar", bag);
michael@0 88
michael@0 89 PromptUtils.propBagToObject(bag, args);
michael@0 90 } finally {
michael@0 91 PromptUtils.fireDialogEvent(window, "DOMModalDialogClosed", browser);
michael@0 92 browser.messageManager.sendAsyncMessage("Prompt:Close", args);
michael@0 93 }
michael@0 94 }
michael@0 95 };

mercurial