From dd60a74e3fbadf555c39783eb1039859e0a8baf7 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 7 Apr 2015 19:34:22 -0400 Subject: [PATCH] code review --- platform/chromium/vapi-client.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/platform/chromium/vapi-client.js b/platform/chromium/vapi-client.js index 86b9797..5e0d842 100644 --- a/platform/chromium/vapi-client.js +++ b/platform/chromium/vapi-client.js @@ -46,6 +46,29 @@ vAPI.chrome = true; /******************************************************************************/ +vAPI.shutdown = (function() { + var jobs = []; + + var add = function(job) { + jobs.push(job); + }; + + var exec = function() { + //console.debug('Shutting down...'); + var job; + while ( job = jobs.pop() ) { + job(); + } + }; + + return { + add: add, + exec: exec + }; +})(); + +/******************************************************************************/ + var messagingConnector = function(response) { if ( !response ) { return; @@ -144,6 +167,15 @@ vAPI.messaging = { } }; +// No need to have vAPI client linger around after shutdown if +// we are not a top window (because element picker can still +// be injected in top window). +if ( window !== window.top ) { + vAPI.shutdown.add(function() { + vAPI = null; + }); +} + /******************************************************************************/ })(this);