Bug 711624 - JS prompt dialog will appear in the foreground when loading the page with the code in the background. r=wesj

This commit is contained in:
Margaret Leibovic 2012-03-06 13:56:16 -08:00
parent 9684e90244
commit dfa5ba7f5f
2 changed files with 26 additions and 0 deletions

View File

@ -594,6 +594,10 @@ var BrowserApp = {
return;
}
// There's nothing to do if the tab is already selected
if (aTab == this.selectedTab)
return;
let message = {
gecko: {
type: "Tab:Select",
@ -1569,6 +1573,7 @@ Tab.prototype = {
this.browser.addEventListener("DOMLinkAdded", this, true);
this.browser.addEventListener("DOMTitleChanged", this, true);
this.browser.addEventListener("DOMWindowClose", this, true);
this.browser.addEventListener("DOMWillOpenModalDialog", this, true);
this.browser.addEventListener("scroll", this, true);
this.browser.addEventListener("PluginClickToPlay", this, true);
this.browser.addEventListener("pagehide", this, true);
@ -1611,6 +1616,7 @@ Tab.prototype = {
this.browser.removeEventListener("DOMLinkAdded", this, true);
this.browser.removeEventListener("DOMTitleChanged", this, true);
this.browser.removeEventListener("DOMWindowClose", this, true);
this.browser.removeEventListener("DOMWillOpenModalDialog", this, true);
this.browser.removeEventListener("scroll", this, true);
this.browser.removeEventListener("PluginClickToPlay", this, true);
this.browser.removeEventListener("pagehide", this, true);
@ -1888,6 +1894,17 @@ Tab.prototype = {
break;
}
case "DOMWillOpenModalDialog": {
if (!aEvent.isTrusted)
return;
// We're about to open a modal dialog, make sure the opening
// tab is brought to the front.
let tab = BrowserApp.getTabForWindow(aEvent.target.top);
BrowserApp.selectTab(tab);
break;
}
case "scroll": {
let win = this.browser.contentWindow;
if (this.userScrollPos.x != win.scrollX || this.userScrollPos.y != win.scrollY) {

View File

@ -156,6 +156,8 @@ Prompt.prototype = {
if (aCheckMsg)
aInputs.push({ type: "checkbox", label: PromptUtils.cleanUpLabel(aCheckMsg), checked: aCheckState.value });
PromptUtils.fireDialogEvent(this._domWin, "DOMWillOpenModalDialog");
let msg = { type: "Prompt:Show" };
if (aTitle) msg.title = aTitle;
if (aText) msg.text = aText;
@ -765,9 +767,16 @@ let PromptUtils = {
}
return hostname;
},
sendMessageToJava: function(aMsg) {
let data = Cc["@mozilla.org/android/bridge;1"].getService(Ci.nsIAndroidBridge).handleGeckoMessage(JSON.stringify({ gecko: aMsg }));
return JSON.parse(data);
},
fireDialogEvent: function(aDomWin, aEventName) {
let event = aDomWin.document.createEvent("Events");
event.initEvent(aEventName, true, true);
aDomWin.dispatchEvent(event);
}
};