diff --git a/bootstrap.js b/bootstrap.js index 31b870f..bb76cdd 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -46,7 +46,7 @@ const core = { modules: 'chrome://chrome-store-foxified/content/modules/', workers: 'chrome://chrome-store-foxified/content/modules/workers/', }, - cache_key: Math.random() // set to version on release + cache_key: 'v1.7' // set to version on release }, os: { name: OS.Constants.Sys.Name.toLowerCase(), @@ -236,7 +236,7 @@ var AB = { // AB stands for attention bar if (winAB) { if (aInstId in winAB.Insts) { // unmount this - console.error('aInstId:', aInstId, 'notificationbox-' + aInstId + '--' + AB.domIdPrefix); + var cNotificationBox = aDOMWindow.document.getElementById('notificationbox-' + aInstId + '--' + AB.domIdPrefix); aDOMWindow.ReactDOM.unmountComponentAtNode(cNotificationBox); cNotificationBox.parentNode.removeChild(cNotificationBox); @@ -369,7 +369,7 @@ var AB = { // AB stands for attention bar aDOMWindow[core.addon.id + '-AB'].Insts[aInstState.aId].state = aDOMWindow.JSON.parse(aDOMWindow.JSON.stringify(aInstState)); var cDeck = aDOMWindow.document.getElementById('content-deck'); var cNotificationBox = aDOMWindow.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'notificationbox'); - console.error('inserting', 'notificationbox-' + aInstState.aId + '--' + AB.domIdPrefix); + cNotificationBox.setAttribute('id', 'notificationbox-' + aInstState.aId + '--' + AB.domIdPrefix); if (!aInstState.aPos) { cDeck.parentNode.appendChild(cNotificationBox); @@ -434,19 +434,19 @@ var AB = { // AB stands for attention bar if (!aDOMWindow[core.addon.id + '-AB']) { return; } - console.error('doing uninit from window'); + // start - original block link77728110 var winAB = aDOMWindow[core.addon.id + '-AB']; for (var aInstsId in winAB.Insts) { // unmount this - console.error('aInstsId:', aInstsId, 'notificationbox-' + aInstsId + '--' + AB.domIdPrefix); + var cNotificationBox = aDOMWindow.document.getElementById('notificationbox-' + aInstsId + '--' + AB.domIdPrefix); aDOMWindow.ReactDOM.unmountComponentAtNode(cNotificationBox); cNotificationBox.parentNode.removeChild(cNotificationBox); } // end - original block link77728110 delete aDOMWindow[core.addon.id + '-AB']; - console.error('done uninit'); + }, ensureInitedIntoWindow: function(aDOMWindow) { // dont run this yoruself, ensureInstancesToWindow runs this. so if you want to run yourself, then run ensureInstancesToWindow(aDOMWindow) @@ -456,11 +456,11 @@ var AB = { // AB stands for attention bar domIdPrefix: AB.domIdPrefix }; // ab stands for attention bar if (!aDOMWindow.React) { - console.error('WILL NOW LOAD IN REACT'); + Services.scriptloader.loadSubScript(core.addon.path.scripts + 'react.js?' + core.addon.cache_key, aDOMWindow); // even if i load it into aDOMWindow.blah and .blah is an object, it goes into global, so i just do aDOMWindow now } if (!aDOMWindow.ReactDOM) { - console.error('WILL NOW LOAD IN REACTDOM'); + Services.scriptloader.loadSubScript(core.addon.path.scripts + 'react-dom.js?' + core.addon.cache_key, aDOMWindow); } Services.scriptloader.loadSubScript(core.addon.path.scripts + 'ab-react-components.js?' + core.addon.cache_key, aDOMWindow); @@ -492,7 +492,7 @@ var AB = { // AB stands for attention bar msgListener: { receiveMessage: function(aMsgEvent) { var aMsgEventData = aMsgEvent.data; - console.error('getting aMsgEvent, data:', aMsgEventData); + // this means trigger a callback with id aMsgEventData var cCallbackId = aMsgEventData; var cBrowser = aMsgEvent.target; @@ -527,7 +527,7 @@ var AB = { // AB stands for attention bar for (var aInstId in AB.Insts) { var aInstState = AB.Insts[aInstId].state; if (aInstState.aId in aDOMWindow[core.addon.id + '-AB'].Insts) { - console.error('this is really weird, it should never happen, as i only call this function when a new window opens'); + aDOMWindow[core.addon.id + '-AB'].Insts[aInstState.aId].state = aDOMWindow.JSON.parse(aDOMWindow.JSON.stringify(aInstState)); aDOMWindow[core.addon.id + '-AB'].Insts[aInstState.aId].setState(JSON.parse(JSON.stringify(aInstState))); } else { @@ -536,7 +536,7 @@ var AB = { // AB stands for attention bar aDOMWindow[core.addon.id + '-AB'].Insts[aInstState.aId].state = aDOMWindow.JSON.parse(aDOMWindow.JSON.stringify(aInstState)); var cDeck = aDOMWindow.document.getElementById('content-deck'); var cNotificationBox = aDOMWindow.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'notificationbox'); - console.error('inserting', 'notificationbox-' + aInstState.aId + '--' + AB.domIdPrefix); + cNotificationBox.setAttribute('id', 'notificationbox-' + aInstState.aId + '--' + AB.domIdPrefix); if (!aInstState.aPos) { cDeck.parentNode.appendChild(cNotificationBox); @@ -614,7 +614,7 @@ function startup(aData, aReason) { var aTimer = Cc['@mozilla.org/timer;1'].createInstance(Ci.nsITimer); aTimer.initWithCallback({ notify: function() { - console.error('ok starting up adding'); + // register framescript listener Services.mm.addMessageListener(core.addon.id, fsMsgListener); @@ -628,7 +628,7 @@ function startup(aData, aReason) { var promise_initMainWorker = SIPWorker('MainWorker', core.addon.path.modules + 'MainWorker/MainWorker.js?' + core.addon.cache_key, core, MainWorkerMainThreadFuncs); promise_initMainWorker.then( function(aInitObj) { - console.log('Fullfilled - promise_initMainWorker - ', aInitObj); + // start - do stuff here - promise_initMainWorker setupMainWorkerCustomErrors(); afterWorker(aInitObj); @@ -639,7 +639,7 @@ function startup(aData, aReason) { name: 'promise_initMainWorker', aReason: aReason }; - console.warn('Rejected - promise_initMainWorker - ', rejObj); + } ).catch( function(aCaught) { @@ -647,7 +647,7 @@ function startup(aData, aReason) { name: 'promise_initMainWorker', aCaught: aCaught }; - console.error('Caught - promise_initMainWorker - ', rejObj); + } ); @@ -670,7 +670,7 @@ function shutdown(aData, aReason) { // terminate worker if (typeof(MainWorker) != 'undefined') { MainWorker._worker.terminate(); - console.log('ok terminated worker'); + } } @@ -680,7 +680,7 @@ var fsFuncs = { // can use whatever, but by default its setup to use this requestInit: function(aMsgEvent) { // start - l10n injection into fs - console.error('in requestinit server side'); + return [{ aCore: core, @@ -731,7 +731,7 @@ var fsFuncs = { // can use whatever, but by default its setup to use this var rez_pwcall = MainWorker.post(aArrOfWorker_FuncnameThenArgs.shift(), aArrOfWorker_FuncnameThenArgs); rez_pwcall.then( function(aVal) { - console.log('Fullfilled - rez_pwcall - ', aVal); + if (returnToFramescript) { if (Array.isArray(aVal)) { mainDeferred_callInPromiseWorker.resolve(aVal); @@ -745,7 +745,7 @@ var fsFuncs = { // can use whatever, but by default its setup to use this name: 'rez_pwcall', aReason: aReason }; - console.error('Rejected - rez_pwcall - ', rejObj); + if (returnToFramescript) { mainDeferred_callInPromiseWorker.resolve([rejObj]); } @@ -756,7 +756,7 @@ var fsFuncs = { // can use whatever, but by default its setup to use this name: 'rez_pwcall', aCaught: aCaught }; - console.error('Caught - rez_pwcall - ', rejObj); + if (returnToFramescript) { mainDeferred_callInPromiseWorker.resolve([rejObj]); } @@ -772,7 +772,7 @@ var fsMsgListener = { funcScope: fsFuncs, receiveMessage: function(aMsgEvent) { var aMsgEventData = aMsgEvent.data; - console.log('fsMsgListener getting aMsgEventData:', aMsgEventData, 'aMsgEvent:', aMsgEvent); + // aMsgEvent.data should be an array, with first item being the unfction name in bootstrapCallbacks var callbackPendingId; @@ -795,23 +795,23 @@ var fsMsgListener = { aMsgEvent.target.messageManager.sendAsyncMessage(core.addon.id, [callbackPendingId, aVal]); }, function(aReason) { - console.error('aReject:', aReason); + aMsgEvent.target.messageManager.sendAsyncMessage(core.addon.id, [callbackPendingId, ['promise_rejected', aReason]]); } ).catch( function(aCatch) { - console.error('aCatch:', aCatch); + aMsgEvent.target.messageManager.sendAsyncMessage(core.addon.id, [callbackPendingId, ['promise_rejected', aCatch]]); } ); } else { // assume array - console.warn('ok responding to callback id:', callbackPendingId, aMsgEvent.target); + aMsgEvent.target.messageManager.sendAsyncMessage(core.addon.id, [callbackPendingId, rez_parentscript_call]); } } } - else { console.warn('funcName', funcName, 'not in scope of this.funcScope') } // else is intentionally on same line with console. so on finde replace all console. lines on release it will take this out + } }; @@ -905,7 +905,7 @@ function validateOptionsObj(aOptions, aOptionsDefaults) { // ensures no invalid keys are found in aOptions, any key found in aOptions not having a key in aOptionsDefaults causes throw new Error as invalid option for (var aOptKey in aOptions) { if (!(aOptKey in aOptionsDefaults)) { - console.error('aOptKey of ' + aOptKey + ' is an invalid key, as it has no default value, aOptionsDefaults:', aOptionsDefaults, 'aOptions:', aOptions); + throw new Error('aOptKey of ' + aOptKey + ' is an invalid key, as it has no default value'); } } @@ -960,7 +960,7 @@ function genericReject(aPromiseName, aPromiseToReject, aReason) { name: aPromiseName, aReason: aReason }; - console.error('Rejected - ' + aPromiseName + ' - ', rejObj); + if (aPromiseToReject) { aPromiseToReject.reject(rejObj); } @@ -970,7 +970,7 @@ function genericCatch(aPromiseName, aPromiseToReject, aCaught) { name: aPromiseName, aCaught: aCaught }; - console.error('Caught - ' + aPromiseName + ' - ', rejObj); + if (aPromiseToReject) { aPromiseToReject.reject(rejObj); } @@ -1003,10 +1003,10 @@ function SIPWorker(workerScopeName, aPath, aCore=core, aFuncExecScope) { bootstrap[workerScopeName]._worker.onmessage = function(aMsgEvent) { ////// start - my custom stuff var aMsgEventData = aMsgEvent.data; - console.log('promiseworker receiving msg:', aMsgEventData); + if (Array.isArray(aMsgEventData)) { // my custom stuff, PromiseWorker did self.postMessage to call a function from here - console.log('promsieworker is trying to execute function in mainthread'); + var callbackPendingId; if (typeof aMsgEventData[aMsgEventData.length-1] == 'string' && aMsgEventData[aMsgEventData.length-1].indexOf(SIP_CB_PREFIX) == 0) { @@ -1023,7 +1023,7 @@ function SIPWorker(workerScopeName, aPath, aCore=core, aFuncExecScope) { function(aVal) { if (aVal.length >= 2 && aVal[aVal.length-1] == SIP_TRANS_WORD && Array.isArray(aVal[aVal.length-2])) { // to transfer in callback, set last element in arr to SIP_TRANS_WORD and 2nd to last element an array of the transferables // cannot transfer on promise reject, well can, but i didnt set it up as probably makes sense not to - console.error('doing transferrrrr'); + aVal.pop(); bootstrap[workerScopeName]._worker.postMessage([callbackPendingId, aVal], aVal.pop()); } else { @@ -1031,12 +1031,12 @@ function SIPWorker(workerScopeName, aPath, aCore=core, aFuncExecScope) { } }, function(aReason) { - console.error('aReject:', aReason); + bootstrap[workerScopeName]._worker.postMessage([callbackPendingId, ['promise_rejected', aReason]]); } ).catch( function(aCatch) { - console.error('aCatch:', aCatch); + bootstrap[workerScopeName]._worker.postMessage([callbackPendingId, ['promise_rejected', aCatch]]); } ); @@ -1052,7 +1052,7 @@ function SIPWorker(workerScopeName, aPath, aCore=core, aFuncExecScope) { } } } - else { console.error('funcName', funcName, 'not in scope of aFuncExecScope') } // else is intentionally on same line with console. so on finde replace all console. lines on release it will take this out + ////// end - my custom stuff } else { origOnmessage(aMsgEvent); @@ -1068,20 +1068,20 @@ function SIPWorker(workerScopeName, aPath, aCore=core, aFuncExecScope) { var promise_initWorker = bootstrap[workerScopeName].post('init', [aCore]); promise_initWorker.then( function(aVal) { - console.log('Fullfilled - promise_initWorker - ', aVal); + // start - do stuff here - promise_initWorker deferredMain_SIPWorker.resolve(aVal); // end - do stuff here - promise_initWorker }, function(aReason) { var rejObj = {name:'promise_initWorker', aReason:aReason}; - console.warn('Rejected - promise_initWorker - ', rejObj); + deferredMain_SIPWorker.reject(rejObj); } ).catch( function(aCaught) { var rejObj = {name:'promise_initWorker', aCaught:aCaught}; - console.error('Caught - promise_initWorker - ', rejObj); + deferredMain_SIPWorker.reject(rejObj); } ); diff --git a/install.rdf b/install.rdf index d5d3f93..9810d72 100644 --- a/install.rdf +++ b/install.rdf @@ -5,7 +5,7 @@ Chrome-Store-Foxified@jetpack - 1.6 + 1.7 2 true diff --git a/modules/MainWorker/MainWorker.js b/modules/MainWorker/MainWorker.js index b9ef3e9..ce60e3f 100644 --- a/modules/MainWorker/MainWorker.js +++ b/modules/MainWorker/MainWorker.js @@ -58,14 +58,14 @@ var WORKER = this; self.addEventListener('message', function(aMsgEvent) { // this is what you do if you want SIPWorker mainthread calling ability var aMsgEventData = aMsgEvent.data; if (Array.isArray(aMsgEventData)) { - console.error('worker got response for main thread calling SIPWorker functionality:', aMsgEventData) + var funcName = aMsgEventData.shift(); if (funcName in WORKER) { var rez_worker_call = WORKER[funcName].apply(null, aMsgEventData); } - else { console.error('funcName', funcName, 'not in scope of WORKER') } // else is intentionally on same line with console. so on finde replace all console. lines on release it will take this out + } else { - console.error('no this is just regular promise worker message'); + worker.handleMessage(aMsgEvent) } }); @@ -80,7 +80,7 @@ self.postMessageWithCallback = function(aPostMessageArr, aCB, aPostMessageTransf var thisCallbackId = SIP_CB_PREFIX + sip_last_cb_id; aFuncExecScope[thisCallbackId] = function() { delete aFuncExecScope[thisCallbackId]; - console.log('in worker callback trigger wrap, will apply aCB with these arguments:', arguments); + aCB.apply(null, arguments[0]); }; aPostMessageArr.push(thisCallbackId); @@ -103,7 +103,7 @@ MainWorkerError.prototype.toMsg = function() { ////// end of imports and definitions function init(objCore) { // function name init required for SIPWorker - //console.log('in worker init'); + // merge objCore into core // core and objCore is object with main keys, the sub props @@ -132,7 +132,7 @@ function init(objCore) { // function name init required for SIPWorker var rezInit = {}; rezInit.l10n = _cache_formatStringFromName_packages; - console.log('MainWorker init success'); + return rezInit; // required for SIPWorker } @@ -160,7 +160,7 @@ function jpmSign(aPathOrBlobToXpi, aAddonVersionInXpi, aAddonIdInXpi, aPlatofrmP // assume its blob fileXpi = new File([aPathOrBlobToXpi], aOptions.filename + ' -- unsigned.xpi'); // doing = new File(aBlob) is not working, the xhr response is coming from amo saying "key of `upload` is missing" } - console.log('fileXpi:', fileXpi); + // create form data var formData = new FormData(); // Cc['@mozilla.org/files/formdata;1'].createInstance(Ci.nsIDOMFormData); // http://stackoverflow.com/q/25038292/1828637 @@ -212,7 +212,7 @@ function jpmSign(aPathOrBlobToXpi, aAddonVersionInXpi, aAddonIdInXpi, aPlatofrmP try { OS.File.writeAtomic(downloadSignedToPlatPath, new Uint8Array(request_downloadSigned.response)); } catch(ex) { - console.error('Failed writing signed XPI to disk:', ex); + throw new MainWorkerError('Failed writing signed XPI to disk', ex); } @@ -241,17 +241,17 @@ function jpmSign(aPathOrBlobToXpi, aAddonVersionInXpi, aAddonIdInXpi, aPlatofrmP } }); - console.log('request_fetchExisting.status:', request_fetchExisting.status); - console.log('request_fetchExisting.response:', request_fetchExisting.response); + + if (request_fetchExisting.status == 200) { if (request_fetchExisting.response.files && request_fetchExisting.response.files.length == 1) { return downloadIt(request_fetchExisting.response.files[0].download_url); } else { - console.error('addon existing, and successfully got exiswting status check, but files are not yet ready! not yet handled :todo:'); + // throw new Error('addon existing, and successfully got exiswting status check, but files are not yet ready! not yet handled :todo:'); // wait 5 seconds then try again - console.log('wait 5 seconds then try again as it has not been signed yet'); + // if (request_fetchExisting.response) if (Array.isArray(request_fetchExisting.response.files) && request_fetchExisting.response.processed && !request_fetchExisting.response.passed_review) { @@ -276,7 +276,7 @@ function jpmSign(aPathOrBlobToXpi, aAddonVersionInXpi, aAddonIdInXpi, aPlatofrmP } }; } - console.log('cumulativeCheckCount:', cumulativeCheckCount); + for (var i=10; i>=1; i--) { if (aOptions.aAttnBarInstState) { aOptions.aAttnBarInstState.aTxt = formatStringFromName('attn-signing-check-waiting', 'bootstrap', [aOptions.aExtName, i]); @@ -298,15 +298,15 @@ function jpmSign(aPathOrBlobToXpi, aAddonVersionInXpi, aAddonIdInXpi, aPlatofrmP } }; - console.log('request_amoSubmit.status:', request_amoSubmit.status, 'request_amoSubmit.response:', request_amoSubmit.response); + if (request_amoSubmit.status == 409) { // the version already exists - console.log('version already exists'); + return waitForReview(); } else { if (request_amoSubmit.status == 201 || request_amoSubmit.status == 202) { // ok new submission went through - console.log('ok new submission went through'); + return waitForReview(); } else { throw { @@ -327,30 +327,30 @@ function getNowDateFromServer() { var requestDuration = Date.now() - requestStartDate; - console.log('request took:', requestDuration, 'ms'); + if (requestUnixNow.status != 200) { - console.log('response status was bad, will wait 5 sec then try again'); + setTimeoutSync(5000); - console.log('ok waitied, will now try'); + return getNowDateFromServer(); } - console.log('requestUnixNow.status:', requestUnixNow.status); - // console.log('requestUnixNow.response:', requestUnixNow.response); + + var nowDateServerMatch = /current_time = (\d+);/.exec(requestUnixNow.response); if (!nowDateServerMatch) { throw new Error('failed to get now date from server'); } - console.log('nowDateServerMatch:', nowDateServerMatch); + var nowDateServerUncompensated = parseInt(nowDateServerMatch[1]) * 1000; - console.log('nowDateServerUncompensated:', nowDateServerUncompensated); + var nowDateServer = nowDateServerUncompensated - requestDuration; - console.log('nowDateServer:', nowDateServer); + return nowDateServer; } @@ -362,7 +362,7 @@ function setTimeoutSync(aMilliseconds) { function doit(aExtId, aExtName, aPrefs, aAttnBarInstState) { try { - console.log('in doit:', aExtId, aExtName); + // step - download crx aAttnBarInstState.aTxt = formatStringFromName('attn-downloading', 'bootstrap', [aExtName]); @@ -371,7 +371,7 @@ function doit(aExtId, aExtName, aPrefs, aAttnBarInstState) { var requestGoogle = xhr('https://clients2.google.com/service/update2/crx?response=redirect&prodversion=38.0&x=id%3D' + aExtId + '%26installsource%3Dondemand%26uc', { responseType: 'arraybuffer' }); - console.log('requestGoogle:', requestGoogle); + var crxArrBuf = requestGoogle.response; // step - make crx a zip @@ -380,13 +380,13 @@ function doit(aExtId, aExtName, aPrefs, aAttnBarInstState) { // var crxBlob = new Blob([new Uint8Array(requestGoogle.response)], {type: 'application/octet-binary'}); var locOfPk = new Uint8Array(crxArrBuf.slice(0, 1000)); - // console.log('locOfPk:', locOfPk); + for (var i=0; i div:nth-of-type(3) > div:nth-of-type(1)').textContent; - console.log('query selector string:', ('a[href="' + theHref + '"]')); + var aWithHref = domEl_withHref.parentNode.querySelectorAll('a[href="' + theHref + '"]'); - console.log('aWithHref:', aWithHref); + var extName = aWithHref[1].textContent.trim(); aContentWindow.alert('extName: ' + extName); actOnExt(extId, extName); @@ -163,7 +163,7 @@ function domInsert(aContentWindow) { */ if (aContentDocument.getElementById('chrome-store-foxified_stylesheet')) { - console.warn('already inserted into this document, so dont insert again'); + return; } @@ -178,7 +178,7 @@ function domInsert(aContentWindow) { return; } else { firstNonFind = true; - console.error('warning, could not find download gchrome link!'); + throw new Error('warning, could not find download gchrome link!'); } } @@ -250,21 +250,21 @@ function bodyOnDOMContentLoaded(aContentWindow) { // check if got error loading page: var webnav = content.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation); var docuri = webnav.document.documentURI; - // console.info('docuri:', docuri); + if (docuri.indexOf('about:') == 0) { // twitter didnt really load, it was an error page - console.log('twitter hostname page ready, but an error page loaded, so like offline or something:', content.location, 'docuri:', docuri); + // unregReason = 'error-loading'; return; } else { // twitter actually loaded // twitterReady = true; - console.error('ok twitter page ready, lets ensure page loaded finished'); + domInsert(content); // ensureLoaded(content); // :note: commented out as not needing content script right now } } else { - // console.log('page ready, but its not twitter so do nothing:', uneval(content.location)); + return; } } @@ -277,10 +277,10 @@ function bodyOnDOMContentLoaded(aContentWindow) { var bootstrapCallbacks = { // can use whatever, but by default it uses this // put functions you want called by bootstrap/server here destroySelf: function() { - // console.log('content.location.hostname:', content.location.hostname); - console.error('doing destroySelf'); + + doPageUnloaders(); - console.error('doing fs unloaders'); + for (var i=0; i