From 74dd775f9854165c0adaed3ae52ee417296c0fd6 Mon Sep 17 00:00:00 2001 From: Jay Satiro Date: Sat, 6 Dec 2014 22:38:07 -0500 Subject: [PATCH] Show caller when asking for readout permission Get stack and show the caller when asking for readout API permission. Related to enhancement request to show source where canvas is nested. https://github.com/kkapsner/CanvasBlocker/issues/8 --- data/inject.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/data/inject.js b/data/inject.js index fbb1099..da3bf6b 100644 --- a/data/inject.js +++ b/data/inject.js @@ -101,10 +101,27 @@ status = askStatus.answer; } else { - // console.log("asking"); - status = window.confirm(_(changedFunction.mode.askText))? "allow": "block"; + //unsafeWindow.console.log("asking"); + var callers = new Error().stack.split('\n'); + var findme = callers.shift(); // Remove us from the stack + findme = findme.replace(/(:[0-9]+){1,2}$/, ""); // rm line & column + // Eliminate squashed stack. stack may contain 2+ stacks, but why... + for (var i = 0; callers[i]; i++){ + if (callers[i].search(findme) == 0){ + callers.splice(i, callers.length - i); + break; + } + } + var msg = _(changedFunction.mode.askText); + if (changedFunction.mode.askText === "askForReadoutPermission"){ + msg += "\n\nCaller: " + callers[0]; + // maybe show full stack here if some pref + //msg += "\n\nFull stack: \n" + callers.join('\n'); + } + status = window.confirm(msg) ? "allow": "block"; askStatus.alreadyAsked = true; askStatus.answer = status; + //unsafeWindow.console.log("asking (done)"); } } switch (status){