From d15125ffaad46f8d55abb5e0f0918b180a0e28e3 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 28 Jul 2010 17:37:24 -0400 Subject: [PATCH] Bug 573635 - e10s: resolve changes to prompt code from m-c merge [r=mfinkle] --- mobile/chrome/content/bindings/browser.js | 59 ++++++++++++++++++++++ mobile/chrome/content/bindings/browser.xml | 15 ++++++ 2 files changed, 74 insertions(+) diff --git a/mobile/chrome/content/bindings/browser.js b/mobile/chrome/content/bindings/browser.js index 588a86e80518..cc347491f3a3 100644 --- a/mobile/chrome/content/bindings/browser.js +++ b/mobile/chrome/content/bindings/browser.js @@ -356,3 +356,62 @@ let ContentScroll = { }; ContentScroll.init(); + + +function PromptRemoter() { + addEventListener("DOMWindowCreated", this, false); +} + +PromptRemoter.prototype = { + handleEvent: function handleEvent(aEvent) { + var window = aEvent.originalTarget.defaultView.content; + // Need to make sure we are called on what we care about - + // content windows. DOMWindowCreated is called on *all* HTMLDocuments, + // some of which belong to ChromeWindows or lack defaultView.content + // altogether. + // + // Note about the syntax used here: |"wrappedJSObject" in window| + // will silently fail, without even letting us catch it as an + // exception, and checking in the way that we do check in some + // cases still throws an exception; see bug 582108 about both. + try { + if (!window || !window.wrappedJSObject) { + return; + } + } + catch(e) { + return; + } + + function bringTabToFront() { + let event = window.document.createEvent("Events"); + event.initEvent("DOMWillOpenModalDialog", true, false); + window.dispatchEvent(event); + } + + window.wrappedJSObject.alert = function(aMessage) { + bringTabToFront(); + sendAsyncMessage("Prompt:Alert", { + message: aMessage + }); + } + + window.wrappedJSObject.confirm = function(aMessage) { + bringTabToFront(); + return sendSyncMessage("Prompt:Confirm", { + message: aMessage + }); + } + + window.wrappedJSObject.prompt = function(aText, aValue) { + bringTabToFront(); + return sendSyncMessage("Prompt:Prompt", { + text: aText, + value: aValue + }); + } + }, +}; + +new PromptRemoter(); + diff --git a/mobile/chrome/content/bindings/browser.xml b/mobile/chrome/content/bindings/browser.xml index 4cccf818e8e2..a86f0acfbf1a 100644 --- a/mobile/chrome/content/bindings/browser.xml +++ b/mobile/chrome/content/bindings/browser.xml @@ -134,6 +134,16 @@ break; } break; + + case "Prompt:Alert": + alert(aMessage.json.message); + break; + + case "Prompt:Confirm": + return confirm(aMessage.json.message); + + case "Prompt:Prompt": + return prompt(aMessage.json.text, aMessage.json.value); } ]]> @@ -373,6 +383,11 @@ messageManager.addMessageListener("pagehide", this); messageManager.addMessageListener("DOMPopupBlocked", this); + // Prompt remoting + ["Alert", "Confirm", "Prompt"].forEach(function(name) { + messageManager.addMessageListener("Prompt:" + name, this); + }, this); + this._webProgress._init(); ]]>