Bug 1339483: Fix tab frame lookup performance issues. r=mossop

MozReview-Commit-ID: Fvx1J8bpzGg

--HG--
extra : rebase_source : d7cb4390308bfce599593f753793d4c329046768
This commit is contained in:
Kris Maglione 2017-02-14 13:24:07 -08:00
Родитель 452a3b8454
Коммит 22b9022bfa
1 изменённых файлов: 30 добавлений и 24 удалений

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

@ -132,23 +132,25 @@ const Frame = Class({
extends: EventTarget, extends: EventTarget,
setup: function(contentFrame) { setup: function(contentFrame) {
// This ID should be unique for this loader across all processes // This ID should be unique for this loader across all processes
ns(this).id = runtime.processID + ":" + FRAME_ID++; let priv = ns(this);
ns(this).contentFrame = contentFrame; priv.id = runtime.processID + ":" + FRAME_ID++;
ns(this).messageManager = contentFrame;
ns(this).domListeners = []; priv.contentFrame = contentFrame;
priv.messageManager = contentFrame;
priv.domListeners = [];
tabMap.set(contentFrame.docShell, this); tabMap.set(contentFrame.docShell, this);
ns(this).messageReceived = messageReceived.bind(this); priv.messageReceived = messageReceived.bind(this);
ns(this).messageManager.addMessageListener('sdk/remote/frame/message', ns(this).messageReceived); priv.messageManager.addMessageListener('sdk/remote/frame/message', priv.messageReceived);
this.port = new EventTarget(); this.port = new EventTarget();
definePort(this, 'sdk/remote/frame/message'); definePort(this, 'sdk/remote/frame/message');
ns(this).messageManager.sendAsyncMessage('sdk/remote/frame/attach', { priv.messageManager.sendAsyncMessage('sdk/remote/frame/attach', {
loaderID, loaderID,
frameID: ns(this).id, frameID: priv.id,
processID: runtime.processID processID: runtime.processID
}); });
@ -156,14 +158,16 @@ const Frame = Class({
}, },
dispose: function() { dispose: function() {
let priv = ns(this);
emit(this, 'detach', this); emit(this, 'detach', this);
for (let listener of ns(this).domListeners) for (let listener of priv.domListeners)
ns(this).contentFrame.removeEventListener(...listener.args); priv.contentFrame.removeEventListener(...listener.args);
ns(this).messageManager.removeMessageListener('sdk/remote/frame/message', ns(this).messageReceived); priv.messageManager.removeMessageListener('sdk/remote/frame/message', priv.messageReceived);
tabMap.delete(ns(this).contentFrame.docShell); tabMap.delete(priv.contentFrame.docShell);
ns(this).contentFrame = null; priv.contentFrame = null;
}, },
get content() { get content() {
@ -191,23 +195,27 @@ const Frame = Class({
}, },
addEventListener: function(...args) { addEventListener: function(...args) {
let priv = ns(this);
let listener = listenerFor(...args); let listener = listenerFor(...args);
if (arrayContainsListener(ns(this).domListeners, listener)) if (arrayContainsListener(priv.domListeners, listener))
return; return;
listener.registeredCallback = makeFrameEventListener(this, listener.callback); listener.registeredCallback = makeFrameEventListener(this, listener.callback);
ns(this).domListeners.push(listener); priv.domListeners.push(listener);
ns(this).contentFrame.addEventListener(...listener.args); priv.contentFrame.addEventListener(...listener.args);
}, },
removeEventListener: function(...args) { removeEventListener: function(...args) {
let listener = getListenerFromArray(ns(this).domListeners, listenerFor(...args)); let priv = ns(this);
let listener = getListenerFromArray(priv.domListeners, listenerFor(...args));
if (!listener) if (!listener)
return; return;
removeListenerFromArray(ns(this).domListeners, listener); removeListenerFromArray(priv.domListeners, listener);
ns(this).contentFrame.removeEventListener(...listener.args); priv.contentFrame.removeEventListener(...listener.args);
} }
}); });
@ -233,12 +241,10 @@ const FrameList = Class({
}, },
getFrameForWindow: function(window) { getFrameForWindow: function(window) {
for (let frame of this) { let docShell = window.QueryInterface(Ci.nsIInterfaceRequestor)
if (frame.content == window) .getInterface(Ci.nsIDocShell);
return frame;
}
return null; return tabMap.get(docShell) || null;
}, },
addEventListener: function(...args) { addEventListener: function(...args) {