Bug 581958 - Filter web progress messages to improve performance [r=vingtetun]

This commit is contained in:
Mark Finkle 2010-07-26 20:48:46 -04:00
Родитель fd5c10500d
Коммит bd16943cf1
2 изменённых файлов: 46 добавлений и 5 удалений

Просмотреть файл

@ -4,6 +4,17 @@ let Ci = Components.interfaces;
dump("!! remote browser loaded\n") dump("!! remote browser loaded\n")
let WebProgressListener = { 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) { onStateChange: function onStateChange(aWebProgress, aRequest, aStateFlags, aStatus) {
let webProgress = Ci.nsIWebProgressListener; let webProgress = Ci.nsIWebProgressListener;
let notifyFlags = 0; let notifyFlags = 0;
@ -22,6 +33,7 @@ let WebProgressListener = {
status: aStatus, status: aStatus,
notifyFlags: notifyFlags notifyFlags: notifyFlags
}; };
sendAsyncMessage("WebProgress:StateChange", json); sendAsyncMessage("WebProgress:StateChange", json);
}, },
@ -33,7 +45,9 @@ let WebProgressListener = {
curTotal: aCurTotal, curTotal: aCurTotal,
maxTotal: aMaxTotal maxTotal: aMaxTotal
}; };
sendAsyncMessage("WebProgress:ProgressChange", json);
if (this._calculatedNotifyFlags & Ci.nsIWebProgress.NOTIFY_PROGRESS)
sendAsyncMessage("WebProgress:ProgressChange", json);
}, },
onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) { onLocationChange: function onLocationChange(aWebProgress, aRequest, aLocationURI) {
@ -54,7 +68,9 @@ let WebProgressListener = {
status: aStatus, status: aStatus,
message: aMessage message: aMessage
}; };
sendAsyncMessage("WebProgress:StatusChange", json);
if (this._calculatedNotifyFlags & Ci.nsIWebProgress.NOTIFY_STATUS)
sendAsyncMessage("WebProgress:StatusChange", json);
}, },
onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) { onSecurityChange: function onSecurityChange(aWebProgress, aRequest, aState) {
@ -71,6 +87,24 @@ let WebProgressListener = {
sendAsyncMessage("WebProgress:SecurityChange", json); 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) { QueryInterface: function QueryInterface(aIID) {
if (aIID.equals(Ci.nsIWebProgressListener) || if (aIID.equals(Ci.nsIWebProgressListener) ||
aIID.equals(Ci.nsISupportsWeakReference) || aIID.equals(Ci.nsISupportsWeakReference) ||
@ -82,6 +116,8 @@ let WebProgressListener = {
} }
}; };
WebProgressListener.init();
let SecurityUI = { let SecurityUI = {
/** /**
@ -144,9 +180,6 @@ let SecurityUI = {
SecurityUI.init(); SecurityUI.init();
let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebProgress);
webProgress.addProgressListener(WebProgressListener, Ci.nsIWebProgress.NOTIFY_ALL);
let WebNavigation = { let WebNavigation = {
_webNavigation: docShell.QueryInterface(Ci.nsIWebNavigation), _webNavigation: docShell.QueryInterface(Ci.nsIWebNavigation),

Просмотреть файл

@ -181,10 +181,18 @@
listener: aListener, listener: aListener,
flags: aNotifyFlags flags: aNotifyFlags
}); });
this._browser.messageManager.sendAsyncMessage("WebProgress:AddProgressListener", {
notifyFlags: aNotifyFlags,
});
}, },
removeProgressListener: function(aListener) { removeProgressListener: function(aListener) {
function hasFilter(item) { function hasFilter(item) {
if (item.listener == aListener)
this._browser.messageManager.sendAsyncMessage("WebProgress:RemoveProgressListener", {
notifyFlags: item.flags,
});
return item.listener != aListener; return item.listener != aListener;
} }