From bd16943cf1fa1bec777f62507edc1d1f708c4056 Mon Sep 17 00:00:00 2001 From: Mark Finkle Date: Mon, 26 Jul 2010 20:48:46 -0400 Subject: [PATCH] Bug 581958 - Filter web progress messages to improve performance [r=vingtetun] --- mobile/chrome/content/bindings/browser.js | 43 +++++++++++++++++++--- mobile/chrome/content/bindings/browser.xml | 8 ++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/mobile/chrome/content/bindings/browser.js b/mobile/chrome/content/bindings/browser.js index 3fd33070de6..588a86e8051 100644 --- a/mobile/chrome/content/bindings/browser.js +++ b/mobile/chrome/content/bindings/browser.js @@ -4,6 +4,17 @@ let Ci = Components.interfaces; dump("!! remote browser loaded\n") let WebProgressListener = { + _notifyFlags: [], + _calculatedNotifyFlags: 0, + + init: function() { + let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress); + webProgress.addProgressListener(this, Ci.nsIWebProgress.NOTIFY_ALL); + + addMessageListener("WebProgress:AddProgressListener", this); + addMessageListener("WebProgress:RemoveProgressListener", this); + }, + onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) { let webProgress = Ci.nsIWebProgressListener; let notifyFlags = 0; @@ -22,6 +33,7 @@ let WebProgressListener = { status: aStatus, notifyFlags: notifyFlags }; + sendAsyncMessage("WebProgress:StateChange", json); }, @@ -33,7 +45,9 @@ let WebProgressListener = { curTotal: aCurTotal, maxTotal: aMaxTotal }; - sendAsyncMessage("WebProgress:ProgressChange", json); + + if (this._calculatedNotifyFlags & Ci.nsIWebProgress.NOTIFY_PROGRESS) + sendAsyncMessage("WebProgress:ProgressChange", json); }, onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) { @@ -54,7 +68,9 @@ let WebProgressListener = { status: aStatus, message: aMessage }; - sendAsyncMessage("WebProgress:StatusChange", json); + + if (this._calculatedNotifyFlags & Ci.nsIWebProgress.NOTIFY_STATUS) + sendAsyncMessage("WebProgress:StatusChange", json); }, onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) { @@ -71,6 +87,24 @@ let WebProgressListener = { sendAsyncMessage("WebProgress:SecurityChange", json); }, + receiveMessage: function(aMessage) { + switch (aMessage.name) { + case "WebProgress:AddProgressListener": + this._notifyFlags.push(aMessage.json.notifyFlags); + this._calculatedNotifyFlags |= aMessage.json.notifyFlags; + break; + case "WebProgress.RemoveProgressListener": + let index = this._notifyFlags.indexOf(aMessage.json.notifyFlags); + if (index != -1) { + this._notifyFlags.splice(index, 1); + this._calculatedNotifyFlags = this._notifyFlags.reduce(function(a, b) { + return a | b; + }, 0); + } + break; + } + }, + QueryInterface: function QueryInterface(aIID) { if (aIID.equals(Ci.nsIWebProgressListener) || aIID.equals(Ci.nsISupportsWeakReference) || @@ -82,6 +116,8 @@ let WebProgressListener = { } }; +WebProgressListener.init(); + let SecurityUI = { /** @@ -144,9 +180,6 @@ let SecurityUI = { SecurityUI.init(); -let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress); -webProgress.addProgressListener(WebProgressListener, Ci.nsIWebProgress.NOTIFY_ALL); - let WebNavigation = { _webNavigation: docShell.QueryInterface(Ci.nsIWebNavigation), diff --git a/mobile/chrome/content/bindings/browser.xml b/mobile/chrome/content/bindings/browser.xml index 1fb4ef1b394..c736569d409 100644 --- a/mobile/chrome/content/bindings/browser.xml +++ b/mobile/chrome/content/bindings/browser.xml @@ -181,10 +181,18 @@ listener: aListener, flags: aNotifyFlags }); + + this._browser.messageManager.sendAsyncMessage("WebProgress:AddProgressListener", { + notifyFlags: aNotifyFlags, + }); }, removeProgressListener: function(aListener) { function hasFilter(item) { + if (item.listener == aListener) + this._browser.messageManager.sendAsyncMessage("WebProgress:RemoveProgressListener", { + notifyFlags: item.flags, + }); return item.listener != aListener; }