Bug 515213: Need to handle DOMWillOpenModalDialog, r=mfinkle
authorBenjamin Stover <bstover@mozilla.com>
Wed, 30 Sep 2009 15:14:06 -0400
changeset 65617 80f5930de5bc628aede6d71c5974bd5167e4da5a
parent 65616 3062d6e242c220efb0c3576539fe91e92d816be7
child 65618 02af623ec8d46893bbafe8e5436871ce72283c71
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs515213
Bug 515213: Need to handle DOMWillOpenModalDialog, r=mfinkle
mobile/chrome/content/browser-ui.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -73,16 +73,31 @@ const kDefaultFavIconURL = "chrome://bro
 
 var BrowserUI = {
   _edit : null,
   _throbber : null,
   _favicon : null,
   _faviconLink : null,
   _dialogs: [],
 
+  _domWillOpenModalDialog: function(e) {
+    if (!e.isTrusted)
+      return;
+
+    // We're about to open a modal dialog, make sure the opening
+    // tab is brought to the front.
+
+    let aWindow = e.target.top;
+    for (let i = 0; i <= Browser._tabs.length; i++) {
+      if (Browser._tabs[i].browser.contentWindow == aWindow) {
+        Browser.selectedTab = Browser._tabs[i];
+      }
+    }
+  },
+
   _titleChanged : function(aDocument) {
     var browser = Browser.selectedBrowser;
     if (browser && aDocument != browser.contentDocument)
       return;
 
     var caption = aDocument.title;
     if (!caption) {
       caption = this.getDisplayURI(browser);
@@ -382,16 +397,17 @@ var BrowserUI = {
 
     let browsers = document.getElementById("browsers");
     browsers.addEventListener("DOMWindowClose", this, true);
     browsers.addEventListener("UIShowSelect", this, false, true);
 
     // XXX these really want to listen to only the current browser
     browsers.addEventListener("DOMTitleChanged", this, true);
     browsers.addEventListener("DOMLinkAdded", this, true);
+    browsers.addEventListener("DOMWillOpenModalDialog", this, true);
     
     // listening mousedown for automatically dismiss some popups (e.g. larry)
     window.addEventListener("mousedown", this, true);
 
     // listening escape to dismiss dialog on VK_ESCAPE
     window.addEventListener("keypress", this, true);
 
     ExtensionsView.init();
@@ -608,16 +624,19 @@ var BrowserUI = {
       let phone = Cc["@mozilla.org/phone/support;1"].createInstance(Ci.nsIPhoneSupport);
       phone.switchTask();
     } catch(e) { }
   },
   
   handleEvent: function (aEvent) {
     switch (aEvent.type) {
       // Browser events
+      case "DOMWillOpenModalDialog":
+        this._domWillOpenModalDialog(aEvent);
+        break;
       case "DOMTitleChanged":
         this._titleChanged(aEvent.target);
         break;
       case "DOMLinkAdded":
         this._linkAdded(aEvent);
         break;
       case "DOMWindowClose":
         this._domWindowClose(aEvent);