From 7dbc543b13c632acf9d18f322c44908ef94123c9 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Tue, 17 Mar 2020 22:01:43 +0000 Subject: [PATCH] Bug 1621491 fix activityLog api by passing alreadyLogged where necessary r=rpl Differential Revision: https://phabricator.services.mozilla.com/D66349 --HG-- extra : moz-landing-system : lando --- .../components/extensions/ExtensionChild.jsm | 11 ++- .../components/extensions/ExtensionCommon.jsm | 3 + .../components/extensions/ExtensionParent.jsm | 29 ++++-- .../test/mochitest/test_ext_activityLog.html | 91 +++++++++++++++---- 4 files changed, 107 insertions(+), 27 deletions(-) diff --git a/toolkit/components/extensions/ExtensionChild.jsm b/toolkit/components/extensions/ExtensionChild.jsm index 9fab72bec7df..4e62980f67df 100644 --- a/toolkit/components/extensions/ExtensionChild.jsm +++ b/toolkit/components/extensions/ExtensionChild.jsm @@ -1064,11 +1064,13 @@ class ProxyAPIImplementation extends SchemaAPIInterface { * `name` member. This may contain dots, e.g. "storage.local". * @param {string} name The name of the method or property. * @param {ChildAPIManager} childApiManager The owner of this implementation. + * @param {boolean} alreadyLogged Whether the child already logged the event. */ - constructor(namespace, name, childApiManager) { + constructor(namespace, name, childApiManager, alreadyLogged = false) { super(); this.path = `${namespace}.${name}`; this.childApiManager = childApiManager; + this.alreadyLogged = alreadyLogged; } revoke() { @@ -1098,7 +1100,8 @@ class ProxyAPIImplementation extends SchemaAPIInterface { return this.childApiManager.callParentAsyncFunction( this.path, args, - callback + callback, + { alreadyLogged: this.alreadyLogged } ); } @@ -1120,6 +1123,7 @@ class ProxyAPIImplementation extends SchemaAPIInterface { listenerId: id, path: this.path, args, + alreadyLogged: this.alreadyLogged, }); } @@ -1139,6 +1143,7 @@ class ProxyAPIImplementation extends SchemaAPIInterface { childId: this.childApiManager.id, listenerId: id, path: this.path, + alreadyLogged: this.alreadyLogged, }); } @@ -1353,7 +1358,7 @@ class ChildAPIManager { let name = path.pop(); let namespace = path.join("."); - let impl = new ProxyAPIImplementation(namespace, name, this); + let impl = new ProxyAPIImplementation(namespace, name, this, true); return { addListener: (listener, ...args) => impl.addListener(listener, args), removeListener: listener => impl.removeListener(listener), diff --git a/toolkit/components/extensions/ExtensionCommon.jsm b/toolkit/components/extensions/ExtensionCommon.jsm index 7b664063023f..de6c46e4d4f2 100644 --- a/toolkit/components/extensions/ExtensionCommon.jsm +++ b/toolkit/components/extensions/ExtensionCommon.jsm @@ -2535,6 +2535,9 @@ class EventManager { if (!this.unregister.has(callback)) { return; } + this.context.logActivity("api_call", `${this.name}.removeListener`, { + args: [], + }); let unregister = this.unregister.get(callback); this.unregister.delete(callback); diff --git a/toolkit/components/extensions/ExtensionParent.jsm b/toolkit/components/extensions/ExtensionParent.jsm index 37b3cde3ce31..00024d406b6f 100644 --- a/toolkit/components/extensions/ExtensionParent.jsm +++ b/toolkit/components/extensions/ExtensionParent.jsm @@ -1142,7 +1142,7 @@ ParentAPIManager = { throw new Error("Got message on unexpected message manager"); } - let { childId } = data; + let { childId, alreadyLogged = false } = data; let handlingUserInput = false; let listener = async (...listenerArgs) => { @@ -1187,13 +1187,15 @@ ParentAPIManager = { handlingUserInput = true; } handler.addListener(listener, ...args); - ExtensionActivityLog.log( - context.extension.id, - context.viewType, - "api_call", - `${data.path}.addListener`, - { args } - ); + if (!alreadyLogged) { + ExtensionActivityLog.log( + context.extension.id, + context.viewType, + "api_call", + `${data.path}.addListener`, + { args } + ); + } }, async recvRemoveListener(data) { @@ -1202,6 +1204,17 @@ ParentAPIManager = { let handler = await context.apiCan.asyncFindAPIPath(data.path); handler.removeListener(listener); + + let { alreadyLogged = false } = data; + if (!alreadyLogged) { + ExtensionActivityLog.log( + context.extension.id, + context.viewType, + "api_call", + `${data.path}.removeListener`, + { args: [] } + ); + } }, getContextById(childId) { diff --git a/toolkit/components/extensions/test/mochitest/test_ext_activityLog.html b/toolkit/components/extensions/test/mochitest/test_ext_activityLog.html index fd661094b8d5..c9039381e9ae 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_activityLog.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_activityLog.html @@ -12,9 +12,9 @@