Bug 549223 - [E10s] MozAfterPaint events aren't activated when event listener is added to tabChildGlobal, r=bsmedberg
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 01 Mar 2010 16:47:27 +0200
changeset 46695 913e13dab60f0b0111cc2783218a753cd94f1f32
parent 46694 fb90d115401473dc4b0dc7e7a6d9fc838af1e87e
child 46696 eb3a2e3e7f265560aea28af465dbe63d720cfb5a
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg
bugs549223
milestone1.9.3a2pre
Bug 549223 - [E10s] MozAfterPaint events aren't activated when event listener is added to tabChildGlobal, r=bsmedberg
dom/base/nsPIWindowRoot.h
dom/base/nsWindowRoot.h
dom/ipc/test.xul
layout/base/nsPresContext.cpp
--- a/dom/base/nsPIWindowRoot.h
+++ b/dom/base/nsPIWindowRoot.h
@@ -43,32 +43,33 @@
 #include "nsISupports.h"
 #include "nsPIDOMEventTarget.h"
 
 class nsPIDOMWindow;
 class nsIControllers;
 class nsIController;
 struct JSContext;
 
-// a9f58a8b-55cd-47fb-aeaa-f54010ffd154
+// 2e26a297-6e40-41c1-81c9-7306571f955e
 #define NS_IWINDOWROOT_IID \
-{ 0xa9f58a8b, 0x55cd, 0x47fb, \
-  { 0xae, 0xaa, 0xf5, 0x40, 0x10, 0xff, 0xd1, 0x54 } }
+{ 0x2e26a297, 0x6e40, 0x41c1, \
+  { 0x81, 0xc9, 0x73, 0x06, 0x57, 0x1f, 0x95, 0x5e } }
 
 class nsPIWindowRoot : public nsPIDOMEventTarget {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWINDOWROOT_IID)
 
   virtual nsPIDOMWindow* GetWindow()=0;
 
   virtual void GetPopupNode(nsIDOMNode** aNode) = 0;
   virtual void SetPopupNode(nsIDOMNode* aNode) = 0;
 
   virtual nsresult GetControllerForCommand(const char *aCommand,
                                            nsIController** aResult) = 0;
   virtual nsresult GetControllers(nsIControllers** aResult) = 0;
 
   virtual void SetParentTarget(nsPIDOMEventTarget* aTarget) = 0;
+  virtual nsPIDOMEventTarget* GetParentTarget() = 0;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsPIWindowRoot, NS_IWINDOWROOT_IID)
 
 #endif // nsPIWindowRoot_h__
--- a/dom/base/nsWindowRoot.h
+++ b/dom/base/nsWindowRoot.h
@@ -97,16 +97,17 @@ public:
 
   virtual void GetPopupNode(nsIDOMNode** aNode);
   virtual void SetPopupNode(nsIDOMNode* aNode);
 
   virtual void SetParentTarget(nsPIDOMEventTarget* aTarget)
   {
     mParent = aTarget;
   }
+  virtual nsPIDOMEventTarget* GetParentTarget() { return mParent; }
 
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsWindowRoot, nsIDOMEventTarget)
 
 protected:
   // Members
   nsPIDOMWindow* mWindow; // [Weak]. The window will hold on to us and let go when it dies.
   nsCOMPtr<nsIEventListenerManager> mListenerManager; // [Strong]. We own the manager, which owns event listeners attached
                                                       // to us.
--- a/dom/ipc/test.xul
+++ b/dom/ipc/test.xul
@@ -159,28 +159,38 @@
       alert("Unexpected echo message");
     }
 
     function listenerAddRemove() {
       addRemoveTestCount = 0;
       messageManager.addMessageListener("async-echo", echoListener);
       messageManager.sendAsyncMessage("async-echo");
     }
+
+    var MozAfterPaintCount = 0;
+    function enableMozAfterPaint() {
+      messageManager.addMessageListener("MozAfterPaint",
+        function(m) {
+          document.getElementById("messageLog").value = m.name + "[" + (++MozAfterPaintCount) + "]";
+        });
+      messageManager.loadFrameScript("data:,addEventListener('MozAfterPaint', function(e) { sendAsyncMessage('MozAfterPaint'); },true);", false);
+    }
   </script>
 
   <toolbar id="controls">
     <toolbarbutton label="Back"/>
     <toolbarbutton label="Forward"/>
     <textbox onchange="loadURL(this.value)" flex="1" id="URL"/>
   </toolbar>
   <toolbar>
     <toolbarbutton onclick="restart()" label="Recover"/>
     <toolbarbutton onclick="randomClick()" label="random click"/>
     <toolbarbutton onclick="messageSpeed()" label="test message handling speed"/>
     <toolbarbutton onclick="listenerAddRemove()" label="test listener add/remove"/>
+    <toolbarbutton onclick="enableMozAfterPaint()" label="MozAfterPaint"/>
     <toolbarbutton onclick="openWindow()" label="open new window"/>
     <toolbarbutton onclick="closeWindow()" label="close this window"/>
   </toolbar>
   <toolbar><label value="Load a script (URL) to content process:"/>
     <textbox flex="1" id="script"/><button
       label="send" oncommand="document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.
                               messageManager.loadFrameScript(this.previousSibling.value, false);"/>
   </toolbar>
--- a/layout/base/nsPresContext.cpp
+++ b/layout/base/nsPresContext.cpp
@@ -100,16 +100,17 @@
 #include "nsSMILAnimationController.h"
 #endif // MOZ_SMIL
 
 #ifdef IBMBIDI
 #include "nsBidiPresUtils.h"
 #endif // IBMBIDI
 
 #include "nsContentUtils.h"
+#include "nsPIWindowRoot.h"
 
 // Needed for Start/Stop of Image Animation
 #include "imgIContainer.h"
 #include "nsIImageLoadingContent.h"
 
 //needed for resetting of image service color
 #include "nsLayoutCID.h"
 
@@ -2063,17 +2064,22 @@ MayHavePaintEventListener(nsPIDOMWindow*
   if (window)
     return MayHavePaintEventListener(window);
 
   nsIEventListenerManager* manager =
     chromeEventHandler->GetListenerManager(PR_FALSE);
   if (manager && manager->MayHavePaintEventListener())
     return PR_TRUE;
 
-  return PR_FALSE;
+  nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(chromeEventHandler);
+  nsPIDOMEventTarget* tabChildGlobal;
+  return root &&
+         (tabChildGlobal = root->GetParentTarget()) &&
+         (manager = tabChildGlobal->GetListenerManager(PR_FALSE)) &&
+         manager->MayHavePaintEventListener();
 }
 
 PRBool
 nsPresContext::MayHavePaintEventListener()
 {
   return ::MayHavePaintEventListener(mDocument->GetInnerWindow());
 }