Bug 580230 - Cannot submit forms [r=mfinkle]
authorJeremias Bosch <jeremias.bosch@gmail.com>
Wed, 28 Jul 2010 15:43:14 -0400
changeset 66405 32aaa661b24f600c576a3885e0f23389512e3576
parent 66404 01859d900b88e37e2cc72d35b1ffe66148a189e8
child 66406 0f33bc3650ae1c5b6af070e08cfb252685ebc663
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
bugs580230
Bug 580230 - Cannot submit forms [r=mfinkle]
mobile/chrome/content/browser.js
mobile/chrome/content/content.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -748,16 +748,17 @@ var Browser = {
     this._tabs.push(newTab);
 
     if (bringFront)
       this.selectedTab = newTab;
 
     let event = document.createEvent("Events");
     event.initEvent("TabOpen", true, false);
     newTab.chromeTab.dispatchEvent(event);
+    newTab.browser.messageManager.sendAsyncMessage("Browser:TabOpen");
 
     return newTab;
   },
 
   closeTab: function(tab) {
     if (tab instanceof XULElement)
       tab = this.getTabFromChrome(tab);
 
@@ -779,16 +780,17 @@ var Browser = {
     this._tabs.forEach(function(aTab, aIndex, aArray) {
       if (aTab.owner == tab)
         aTab.owner = null;
     });
 
     let event = document.createEvent("Events");
     event.initEvent("TabClose", true, false);
     tab.chromeTab.dispatchEvent(event);
+    tab.browser.messageManager.sendAsyncMessage("Browser:TabClose");
 
     this.selectedTab = nextTab;
 
     tab.destroy();
     this._tabs.splice(tabIndex, 1);
   },
 
   get selectedTab() {
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -811,23 +811,39 @@ var ContextHandler = {
     sendAsyncMessage("Browser:ContextMenu", state);
   }
 };
 
 ContextHandler.init();
 
 
 var FormSubmitObserver = {
-  init: function init() {
-    Services.obs.addObserver(this, "formsubmit", false);
+  
+  init: function init(){
+    addMessageListener("Browser:TabOpen", this);
+    addMessageListener("Browser:TabClose", this);
+  },
+
+  receiveMessage: function findHandlerReceiveMessage(aMessage) {
+    let json = aMessage.json;
+    switch (aMessage.name) {
+      case "Browser:TabOpen":
+        Services.obs.addObserver(this, "formsubmit", false);
+        break;
+      case "Browser:TabClose":
+        Services.obs.removeObserver(this, "formsubmit", false);
+        break;
+    }
   },
 
   notify: function notify(aFormElement, aWindow, aActionURI, aCancelSubmit) {
-    // We don't need to send any data along
-    sendAsyncMessage("Browser:FormSubmit", {});
+    // Do not notify unless this is the window where the submit occurred
+    if (aWindow == content)
+      // We don't need to send any data along
+      sendAsyncMessage("Browser:FormSubmit", {});
   },
 
   QueryInterface : function(aIID) {
     if (!aIID.equals(Ci.nsIFormSubmitObserver) &&
         !aIID.equals(Ci.nsISupportsWeakReference) &&
         !aIID.equals(Ci.nsISupports))
       throw Components.results.NS_ERROR_NO_INTERFACE;
     return this;