mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1165841 - Part 5: remove listener when window is destroyed. r=dimi
This commit is contained in:
parent
4bf759585c
commit
82d3354929
@ -194,6 +194,12 @@ NfcContentHelper.prototype = {
|
|||||||
cpmm.sendAsyncMessage("NFC:AddEventListener", { tabId: tabId });
|
cpmm.sendAsyncMessage("NFC:AddEventListener", { tabId: tabId });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeEventListener: function removeEventListener(tabId) {
|
||||||
|
delete this.eventListeners[tabId];
|
||||||
|
|
||||||
|
cpmm.sendAsyncMessage("NFC:RemoveEventListener", { tabId: tabId });
|
||||||
|
},
|
||||||
|
|
||||||
registerTargetForPeerReady: function registerTargetForPeerReady(appId) {
|
registerTargetForPeerReady: function registerTargetForPeerReady(appId) {
|
||||||
cpmm.sendAsyncMessage("NFC:RegisterPeerReadyTarget", { appId: appId });
|
cpmm.sendAsyncMessage("NFC:RegisterPeerReadyTarget", { appId: appId });
|
||||||
},
|
},
|
||||||
|
@ -57,6 +57,7 @@ const NFC_CID =
|
|||||||
const NFC_IPC_MSG_ENTRIES = [
|
const NFC_IPC_MSG_ENTRIES = [
|
||||||
{ permission: null,
|
{ permission: null,
|
||||||
messages: ["NFC:AddEventListener",
|
messages: ["NFC:AddEventListener",
|
||||||
|
"NFC:RemoveEventListener",
|
||||||
"NFC:QueryInfo",
|
"NFC:QueryInfo",
|
||||||
"NFC:CallDefaultFoundHandler",
|
"NFC:CallDefaultFoundHandler",
|
||||||
"NFC:CallDefaultLostHandler"] },
|
"NFC:CallDefaultLostHandler"] },
|
||||||
@ -256,12 +257,16 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
removeEventListener: function removeEventListener(target) {
|
removeEventListener: function removeEventListener(target) {
|
||||||
for (let id in this.eventListeners) {
|
for (let id in this.eventListeners) {
|
||||||
if (target == this.eventListeners[id]) {
|
if (target == this.eventListeners[id]) {
|
||||||
delete this.eventListeners[id];
|
this.removeEventListenerById(id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeEventListenerById: function removeEventListenerById(id) {
|
||||||
|
delete this.eventListeners[id];
|
||||||
|
},
|
||||||
|
|
||||||
checkP2PRegistration: function checkP2PRegistration(message) {
|
checkP2PRegistration: function checkP2PRegistration(message) {
|
||||||
let target = this.peerTargets[message.data.appId];
|
let target = this.peerTargets[message.data.appId];
|
||||||
let sessionToken = SessionHelper.getCurrentP2PToken();
|
let sessionToken = SessionHelper.getCurrentP2PToken();
|
||||||
@ -385,6 +390,9 @@ XPCOMUtils.defineLazyGetter(this, "gMessageManager", function () {
|
|||||||
case "NFC:AddEventListener":
|
case "NFC:AddEventListener":
|
||||||
this.addEventListener(message.target, message.data.tabId);
|
this.addEventListener(message.target, message.data.tabId);
|
||||||
return null;
|
return null;
|
||||||
|
case "NFC:RemoveEventListener":
|
||||||
|
this.removeEventListenerById(message.data.tabId);
|
||||||
|
return null;
|
||||||
case "NFC:RegisterPeerReadyTarget":
|
case "NFC:RegisterPeerReadyTarget":
|
||||||
this.registerPeerReadyTarget(message.target, message.data.appId);
|
this.registerPeerReadyTarget(message.target, message.data.appId);
|
||||||
return null;
|
return null;
|
||||||
|
@ -124,7 +124,7 @@ interface nsINfcBrowserAPI : nsISupports
|
|||||||
in boolean isFocus);
|
in boolean isFocus);
|
||||||
};
|
};
|
||||||
|
|
||||||
[scriptable, uuid(f098c114-b21f-43f5-9f53-0c22b4f194eb)]
|
[scriptable, uuid(75f0c8c0-2e5a-491f-a75d-4f3849c4feec)]
|
||||||
interface nsINfcContentHelper : nsISupports
|
interface nsINfcContentHelper : nsISupports
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -236,6 +236,14 @@ interface nsINfcContentHelper : nsISupports
|
|||||||
*/
|
*/
|
||||||
void addEventListener(in nsINfcEventListener listener, in uint64_t tabId);
|
void addEventListener(in nsINfcEventListener listener, in uint64_t tabId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove event listener.
|
||||||
|
*
|
||||||
|
* @param tabId
|
||||||
|
* The tabId provided in addEventListener.
|
||||||
|
*/
|
||||||
|
void removeEventListener(in uint64_t tabId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the given application id with parent process
|
* Register the given application id with parent process
|
||||||
*
|
*
|
||||||
|
@ -345,6 +345,7 @@ MozNFCImpl.prototype = {
|
|||||||
_nfcContentHelper: null,
|
_nfcContentHelper: null,
|
||||||
window: null,
|
window: null,
|
||||||
_tabId: null,
|
_tabId: null,
|
||||||
|
_innerWindowId: null,
|
||||||
_rfState: null,
|
_rfState: null,
|
||||||
_contentObj: null,
|
_contentObj: null,
|
||||||
nfcPeer: null,
|
nfcPeer: null,
|
||||||
@ -354,12 +355,19 @@ MozNFCImpl.prototype = {
|
|||||||
init: function init(aWindow) {
|
init: function init(aWindow) {
|
||||||
debug("MozNFCImpl init called");
|
debug("MozNFCImpl init called");
|
||||||
this.window = aWindow;
|
this.window = aWindow;
|
||||||
|
let util = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
this._innerWindowId = util.currentInnerWindowID;
|
||||||
|
|
||||||
this.defineEventHandlerGetterSetter("ontagfound");
|
this.defineEventHandlerGetterSetter("ontagfound");
|
||||||
this.defineEventHandlerGetterSetter("ontaglost");
|
this.defineEventHandlerGetterSetter("ontaglost");
|
||||||
this.defineEventHandlerGetterSetter("onpeerready");
|
this.defineEventHandlerGetterSetter("onpeerready");
|
||||||
this.defineEventHandlerGetterSetter("onpeerfound");
|
this.defineEventHandlerGetterSetter("onpeerfound");
|
||||||
this.defineEventHandlerGetterSetter("onpeerlost");
|
this.defineEventHandlerGetterSetter("onpeerlost");
|
||||||
|
|
||||||
|
Services.obs.addObserver(this, "inner-window-destroyed",
|
||||||
|
/* weak-ref */ false);
|
||||||
|
|
||||||
if (this._nfcContentHelper) {
|
if (this._nfcContentHelper) {
|
||||||
this._tabId = this.getTabId(aWindow);
|
this._tabId = this.getTabId(aWindow);
|
||||||
this._nfcContentHelper.addEventListener(this, this._tabId);
|
this._nfcContentHelper.addEventListener(this, this._tabId);
|
||||||
@ -441,6 +449,19 @@ MozNFCImpl.prototype = {
|
|||||||
return this._rfState != RFState.IDLE;
|
return this._rfState != RFState.IDLE;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
observe: function observe(subject, topic, data) {
|
||||||
|
if (topic !== "inner-window-destroyed") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let wId = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
|
||||||
|
if (wId != this._innerWindowId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._nfcContentHelper.removeEventListener(this._tabId);
|
||||||
|
},
|
||||||
|
|
||||||
defineEventHandlerGetterSetter: function defineEventHandlerGetterSetter(name) {
|
defineEventHandlerGetterSetter: function defineEventHandlerGetterSetter(name) {
|
||||||
Object.defineProperty(this, name, {
|
Object.defineProperty(this, name, {
|
||||||
get: function get() {
|
get: function get() {
|
||||||
@ -699,7 +720,8 @@ MozNFCImpl.prototype = {
|
|||||||
contractID: "@mozilla.org/nfc/manager;1",
|
contractID: "@mozilla.org/nfc/manager;1",
|
||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
|
||||||
Ci.nsIDOMGlobalPropertyInitializer,
|
Ci.nsIDOMGlobalPropertyInitializer,
|
||||||
Ci.nsINfcEventListener]),
|
Ci.nsINfcEventListener,
|
||||||
|
Ci.nsIObserver]),
|
||||||
};
|
};
|
||||||
|
|
||||||
function NFCSendFileWrapper() {
|
function NFCSendFileWrapper() {
|
||||||
|
Loading…
Reference in New Issue
Block a user