From c3bb4fc3383c3dc82f15080af12910f21bab4ddb Mon Sep 17 00:00:00 2001 From: Noitidart Date: Tue, 21 Jun 2016 05:34:27 -0700 Subject: [PATCH] 2.1 RELEASE add e10s compat flag to rdf too --- bootstrap.js | 76 +++++++-------- install.rdf | 3 +- resources/scripts/MainContentscript.js | 40 ++++---- resources/scripts/MainFramescript.js | 52 +++++----- resources/scripts/MainWorker.js | 126 ++++++++++++------------- 5 files changed, 149 insertions(+), 148 deletions(-) diff --git a/bootstrap.js b/bootstrap.js index acd1436..c57e865 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -39,7 +39,7 @@ var core = { // storage: OS.Path.join(OS.Constants.Path.profileDir, 'jetpack', core.addon.id, 'simple-storage') }, pref_branch: 'extensions.Chrome-Store-Foxified@jetpack.', - cache_key: Math.random() // set to version on release + cache_key: '2.1' // set to version on release }, os: { // // name: added by worker @@ -83,10 +83,10 @@ var gInstallListener = { // succesfully installed reason = reasons.SUCCESS; } - console.log('addon install ended', 'name:', aAddon.name, 'id:', aAddon.id, 'reason:', reason); + }, onInstallStarted: function(aInstall) { - console.log('addon install started', 'name:', aInstall.name, 'id:', aInstall.addon.id); + } }; @@ -117,7 +117,7 @@ function uninstall(aData, aReason) { } catch(ignore) {} Cu.import('resource://gre/modules/osfile.jsm'); - console.log('removing dir'); + OS.File.removeDir(OS.Path.join(OS.Constants.Path.profileDir, 'jetpack', core.addon.id), {ignorePermissions:true, ignoreAbsent:true}); } } @@ -146,7 +146,7 @@ function startup(aData, aReason) { getDownloadsDir().then( function(os_path_downloads) { core.addon.path.downloads = os_path_downloads; - console.log('core.addon.path.downloads:', core.addon.path.downloads); + startWorker(); } ); @@ -217,7 +217,7 @@ function callInWorker(aArg, aMessageManager, aBrowser, aComm) { // its dead cmm.splice(i, 1); i--; - console.error('browser in position', i, 'is dead! removed!'); + } else { if (cbrowser == aBrowser) { cbrowser_found = true; @@ -230,7 +230,7 @@ function callInWorker(aArg, aMessageManager, aBrowser, aComm) { } if (!cbrowser_found) { mm_for_extid[extid].push(Cu.getWeakReference(aBrowser)); - console.log('ok pushed aBrowser'); + } } @@ -268,15 +268,15 @@ function dispatchInContent(aArg, aComm) { // its dead cmm.splice(i, 1); i--; - console.error('browser in position', i, 'is dead! removed!'); + } else { - console.error('ok sending to browser in position', i, 'messageManager:', cbrowser.messageManager); + gFsComm.transcribeMessage(cbrowser.messageManager, 'callInContent', { method: 'dispatchInContent', arg: aArg, wait: false // i just want to know if return is `undefined` or `NO_WIN_COMM` }, function(aArg, aComm) { - console.log('in callback of dispatchInContent in bootstrap, aArg:', aArg); + }); } } @@ -364,7 +364,7 @@ function browseFile(aArg, aComm) { }// else { // cancelled } if (aOptions.async) { - console.error('async resolving'); + mainDeferred_browseFile.resolve(retFP); } else { return retFP; @@ -410,7 +410,7 @@ function downloadFile(aArg, aComm) { } }) - .then(null, console.error); + } function installAddonAsTemp(aArg, aComm) { @@ -425,7 +425,7 @@ function installAddonAsTemp(aArg, aComm) { var promise_uninstall = uninstallAddonsByPartial(partial_id); promise_uninstall.then( function(aVal) { - console.log('Fullfilled - promise_uninstall - ', aVal); + install(); }, genericReject.bind(null, 'promise_uninstall', mainDeferred_installAddonAsTemp) @@ -463,7 +463,7 @@ function installAddonAsNormal(aArg, aComm) { var promise_uninstall = uninstallAddonsByPartial(partial_id); promise_uninstall.then( function(aVal) { - console.log('Fullfilled - promise_uninstall - ', aVal); + install(); }, genericReject.bind(null, 'promise_uninstall', mainDeferred_installAddonAsNormal) @@ -525,7 +525,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'); } } @@ -552,7 +552,7 @@ function genericReject(aPromiseName, aPromiseToReject, aReason) { name: aPromiseName, aReason: aReason }; - console.error('Rejected - ' + aPromiseName + ' - ', rejObj); + if (aPromiseToReject) { aPromiseToReject.reject(rejObj); } @@ -562,7 +562,7 @@ function genericCatch(aPromiseName, aPromiseToReject, aCaught) { name: aPromiseName, aCaught: aCaught }; - console.error('Caught - ' + aPromiseName + ' - ', rejObj); + if (aPromiseToReject) { aPromiseToReject.reject(rejObj); } @@ -611,28 +611,28 @@ function crossprocComm(aChannelId) { receiveMessage: function(e) { var messageManager = e.target.messageManager; if (!messageManager) { - console.error('bootstrap crossprocComm - ignoring this received message as no messageManager for the one i am getting message from, e.target:', e.target, 'messageManager:', messageManager); + return; } var browser = e.target; var payload = e.data; - console.log('bootstrap crossprocComm - incoming, payload:', payload, 'messageManager:', messageManager, 'browser:', browser, 'e:', e); - // console.log('this in receiveMessage bootstrap:', this); + + if (payload.method) { - if (!(payload.method in scope)) { console.error('method of "' + payload.method + '" not in scope'); throw new Error('method of "' + payload.method + '" not in scope') } // dev line remove on prod + var rez_bs_call = scope[payload.method](payload.arg, messageManager, browser, this); // only on bootstrap side, they get extra 2 args if (payload.cbid) { if (rez_bs_call && rez_bs_call.constructor.name == 'Promise') { rez_bs_call.then( function(aVal) { - console.log('Fullfilled - rez_bs_call - ', aVal); + this.transcribeMessage(messageManager, payload.cbid, aVal); }.bind(this), genericReject.bind(null, 'rez_bs_call', 0) ).catch(genericCatch.bind(null, 'rez_bs_call', 0)); } else { - console.log('bootstrap crossprocComm - calling transcribeMessage for callbck with args:', payload.cbid, rez_bs_call); + this.transcribeMessage(messageManager, payload.cbid, rez_bs_call); } } @@ -641,16 +641,16 @@ function crossprocComm(aChannelId) { this.callbackReceptacle[payload.cbid](payload.arg, messageManager, browser, this); delete this.callbackReceptacle[payload.cbid]; } else { - console.error('bootstrap crossprocComm - invalid combination - method:', payload.method, 'cbid:', payload.cbid, 'payload:', payload); + } }.bind(this) }; this.nextcbid = 1; //next callback id this.transcribeMessage = function(aMessageManager, aMethod, aArg, aCallback) { - // console.log('bootstrap sending message to framescript', aMethod, aArg); + // aMethod is a string - the method to call in framescript // aCallback is a function - optional - it will be triggered when aMethod is done calling - console.log('bootstrap crossprocComm - in transcribeMessage:', aMessageManager, aMethod, aArg, aCallback) + var cbid = null; if (typeof(aMethod) == 'number') { // this is a response to a callack waiting in framescript @@ -665,7 +665,7 @@ function crossprocComm(aChannelId) { // return; if (!aMessageManager) { - console.error('bootstrap crossprocComm - how on earth, im in transcribeMessage but no aMessageManager? arguments:', aMessageManager, aMethod, aArg, aCallback); + } aMessageManager.sendAsyncMessage(aChannelId, { method: aMethod, @@ -697,7 +697,7 @@ function contentComm(aContentWindow, aPort1, aPort2, onHandshakeComplete) { this.listener = function(e) { var payload = e.data; - console.log('bootstrap contentComm - incoming, payload:', payload); //, 'e:', e); + if (payload.method) { if (payload.method == 'contentComm_handshake_finalized') { @@ -707,20 +707,20 @@ function contentComm(aContentWindow, aPort1, aPort2, onHandshakeComplete) { } return; } - if (!(payload.method in scope)) { console.error('method of "' + payload.method + '" not in scope'); throw new Error('method of "' + payload.method + '" not in scope') } // dev line remove on prod + var rez_bs_call_for_win = scope[payload.method](payload.arg, this); - console.log('rez_bs_call_for_win:', rez_bs_call_for_win); + if (payload.cbid) { if (rez_bs_call_for_win && rez_bs_call_for_win.constructor.name == 'Promise') { rez_bs_call_for_win.then( function(aVal) { - console.log('Fullfilled - rez_bs_call_for_win - ', aVal); + this.postMessage(payload.cbid, aVal); }.bind(this), genericReject.bind(null, 'rez_bs_call_for_win', 0) ).catch(genericCatch.bind(null, 'rez_bs_call_for_win', 0)); } else { - console.log('calling postMessage for callback with rez_bs_call_for_win:', rez_bs_call_for_win, 'this:', this); + this.postMessage(payload.cbid, rez_bs_call_for_win); } } @@ -892,7 +892,7 @@ function workerComm(aWorkerPath, onBeforeInit, onAfterInit, aWebWorker) { }; this.listener = function(e) { var payload = e.data; - console.log('bootstrap workerComm - incoming, payload:', payload); //, 'e:', e); + if (payload.method) { if (payload.method == 'triggerOnAfterInit') { @@ -901,20 +901,20 @@ function workerComm(aWorkerPath, onBeforeInit, onAfterInit, aWebWorker) { } return; } - if (!(payload.method in scope)) { console.error('method of "' + payload.method + '" not in scope'); throw new Error('method of "' + payload.method + '" not in scope') } // dev line remove on prod + var rez_bs_call_for_worker = scope[payload.method](payload.arg, this); - console.log('rez_bs_call_for_worker:', rez_bs_call_for_worker); + if (payload.cbid) { if (rez_bs_call_for_worker && rez_bs_call_for_worker.constructor.name == 'Promise') { rez_bs_call_for_worker.then( function(aVal) { - console.log('Fullfilled - rez_bs_call_for_worker - ', aVal); + this.postMessage(payload.cbid, aVal); }.bind(this), genericReject.bind(null, 'rez_bs_call_for_worker', 0) ).catch(genericCatch.bind(null, 'rez_bs_call_for_worker', 0)); } else { - console.log('calling postMessage for callback with rez_bs_call_for_worker:', rez_bs_call_for_worker, 'this:', this); + this.postMessage(payload.cbid, rez_bs_call_for_worker); } } @@ -923,7 +923,7 @@ function workerComm(aWorkerPath, onBeforeInit, onAfterInit, aWebWorker) { this.callbackReceptacle[payload.cbid](payload.arg, this); delete this.callbackReceptacle[payload.cbid]; } else { - console.error('bootstrap workerComm - invalid combination'); + throw new Error('bootstrap workerComm - invalid combination'); } }.bind(this); diff --git a/install.rdf b/install.rdf index b69d5bc..447e67b 100644 --- a/install.rdf +++ b/install.rdf @@ -5,9 +5,10 @@ Chrome-Store-Foxified@jetpack - 2.1b + 2.1 2 true + true diff --git a/resources/scripts/MainContentscript.js b/resources/scripts/MainContentscript.js index 9572d16..5fbaed5 100644 --- a/resources/scripts/MainContentscript.js +++ b/resources/scripts/MainContentscript.js @@ -5,7 +5,7 @@ var gFsComm; function init() { gFsComm.postMessage('callInBootstrap', {method:'fetchCore',wait:true}, null, function(aCore) { - console.log('core:', aCore); + core = aCore; window.addEventListener('click', genericClick, true); @@ -76,7 +76,7 @@ function uninit() { function genericClick(e) { var targetEl = e.target; - // console.log('clicked, targetEl:', targetEl.innerHTML); + if (targetEl) { var isTestBtn = targetEl.classList.contains('webstore-test-button-label'); @@ -85,7 +85,7 @@ function genericClick(e) { try { containsTestBtn = targetEl.querySelector('.webstore-test-button-label'); } catch(ignore) {} - // console.log('isTestBtn:', isTestBtn, 'isRoleBtn:', isRoleBtn, 'containsTestBtn:', containsTestBtn); + if (isTestBtn || (isRoleBtn && containsTestBtn)) { var ariaLabel; @@ -98,7 +98,7 @@ function genericClick(e) { btnText = targetEl.textContent.trim(); } - console.log('ariaLabel:', ariaLabel, 'btnText:', btnText); + if (/(?:CHROM|Chrom)/.test(ariaLabel) || /(?:CHROM|Chrom)/.test(btnText)) { // alert('ok trigger'); installClick(e); @@ -199,7 +199,7 @@ function downloadCrx(extid) { arg: extid } }, undefined, function(aArg, aComm) { - console.log('back in content after triggering downloadCrx, got back aArg:', aArg); + var { request, ok, reason } = aArg; // reason only available when ok==false store.dispatch(updateStatus(extid, { downloading_crx: false, @@ -226,7 +226,7 @@ function convertXpi(extid) { arg: extid } }, undefined, function(aArg, aComm) { - console.log('back in content after triggering downloadCrx, got back aArg:', aArg); + var { request, ok, reason, version } = aArg; // reason only available when ok==false store.dispatch(updateStatus(extid, { converting_xpi: false, @@ -255,7 +255,7 @@ function signXpi(extid, install_normal) { arg: extid } }, undefined, function(aArg, aComm) { - console.log('back in content after triggering downloadCrx, got back aArg:', aArg); + var { request, ok, reason, reason_details } = aArg; // reason only available when ok==false store.dispatch(updateStatus(extid, { signing_xpi: undefined, @@ -287,7 +287,7 @@ function installXpi(extid, temp) { arg: { extid, temp } } }, undefined, function(aArg, aComm) { - console.log('back in content after installing, aArg:', aArg); + var { request, ok, reason } = aArg; // reason only available when ok==false store.dispatch(updateStatus(extid, { [temp ? 'unsigned_installing' : 'signed_installing']: undefined, @@ -467,7 +467,7 @@ const foxifiedApp = Redux.combineReducers({ // STORE var store = Redux.createStore(foxifiedApp); -var unsubscribe = store.subscribe(() => console.log(store.getState()) ); + // REACT COMPONENTS - PRESENTATIONAL var App = React.createClass({ @@ -542,7 +542,7 @@ var ExtActions = React.createClass({ } } }, undefined, function(aArg, aComm) { - console.log('back in content after triggering saveToFile, got back aArg:', aArg); + var { ok, reason } = aArg; // reason only available when ok==false if (!ok) { switch (reason) { @@ -815,7 +815,7 @@ var Page = React.createClass({ // status is only available if pageid is extid var cChildren = []; - console.error('pageid:', pageid); + switch (pageid) { case 'PAGE_PREFS': @@ -905,10 +905,10 @@ function formatStringFromNameCore(aLocalizableStr, aLoalizedKeyInCoreAddonL10n, // try { // var cLocalizedStr = core.addon.l10n[aLoalizedKeyInCoreAddonL10n]; // } catch (ex) { - // console.error('formatStringFromNameCore error:', ex, 'args:', aLocalizableStr, aLoalizedKeyInCoreAddonL10n, aReplacements); + // } var cLocalizedStr = core.addon.l10n[aLoalizedKeyInCoreAddonL10n][aLocalizableStr]; - // console.log('cLocalizedStr:', cLocalizedStr, 'args:', aLocalizableStr, aLoalizedKeyInCoreAddonL10n, aReplacements); + if (aReplacements) { for (var i=0; i]+/i.exec(html); var fieldSecretHtml = /input[^<]+jwtsecret[^>]+/i.exec(html); - console.log('fieldKeyHtml:', fieldKeyHtml); - console.log('fieldSecretHtml:', fieldSecretHtml); + + if (!fieldKeyHtml || !fieldSecretHtml) { if (didGenerate) { @@ -341,7 +341,7 @@ function signXpi(extid) { } else { // keys are not there, need to generate var fieldTokenHtml = /input[^<]+csrfmiddlewaretoken[^>]+/i.exec(html); - console.log('fieldTokenHtml:', fieldTokenHtml); + if (!fieldTokenHtml) { rezMain.ok = false; rezMain.reason = 'missing_field'; @@ -403,9 +403,9 @@ function signXpi(extid) { xpiversion = manifest_json.version; xpiid = extid + '@chrome-store-foxified-' + HashString(amo_user.key); - console.log('index of unsigned id:', manifest_txt.indexOf(extid + '@chrome-store-foxified-unsigned')); + manifest_txt = manifest_txt.replace(extid + '@chrome-store-foxified-unsigned', xpiid); - console.log('index of unsigned id afte replace:', manifest_txt.indexOf(extid + '@chrome-store-foxified-unsigned')); + // TODO: error points here? JSZip failing? maybe think about it, if there are then handle it unsigned_jszip.file('manifest.json', manifest_txt); @@ -455,15 +455,15 @@ function signXpi(extid) { if (!nowDateServerMatch) { onFail(); } - console.log('nowDateServerMatch:', nowDateServerMatch); + var nowDateServerUncompensated = parseInt(nowDateServerMatch[1]) * 1000; - console.log('nowDateServerUncompensated:', nowDateServerUncompensated); + var nowDateServer = nowDateServerUncompensated - requestDuration; - console.log('nowDateServer:', nowDateServer); - console.log('systemNow:', (new Date(requestStart)).toLocaleString(), 'serverNow:', (new Date(nowDateServer)).toLocaleString(), 'requestDuration seconds:', (requestDuration / 1000)) + + systemTimeOffset = requestStart - nowDateServer; gLastSystemTimeOffset = systemTimeOffset; // end - calc sys offset @@ -503,15 +503,15 @@ function signXpi(extid) { if (!nowDateServerMatch) { onFail(); } - console.log('nowDateServerMatch:', nowDateServerMatch); + var nowDateServerUncompensated = parseInt(nowDateServerMatch[1]) * 1000; - console.log('nowDateServerUncompensated:', nowDateServerUncompensated); + var nowDateServer = nowDateServerUncompensated - requestDuration; - console.log('nowDateServer:', nowDateServer); - console.log('systemNow:', (new Date(requestStart)).toLocaleString(), 'serverNow:', (new Date(nowDateServer)).toLocaleString(), 'requestDuration seconds:', (requestDuration / 1000)) + + systemTimeOffset = requestStart - nowDateServer; gLastSystemTimeOffset = systemTimeOffset; // end - calc sys offset @@ -528,7 +528,7 @@ function signXpi(extid) { var afterSystemTimeOffsetGot = function() { // go through signing on amo - its errors including especially time not in sync - console.log('systemTimeOffset:', systemTimeOffset); + updateStatus(extid, { signing_xpi: formatStringFromName('signing_xpi_uploading', 'main') }); @@ -549,7 +549,7 @@ function signXpi(extid) { data.append('Content-Type', 'multipart/form-data'); data.append('upload', presigned_zip_file); // http://stackoverflow.com/a/24746459/1828637 - console.error('doing submit'); + xhrAsync(AMODOMAIN + '/api/v3/addons/' + encodeURIComponent(xpiid) + '/versions/' + xpiversion + '/', { // only on first time upload, the aAddonVersionInXpi can be anything method: 'PUT', @@ -567,7 +567,7 @@ function signXpi(extid) { var possible_uploadFailedDueToTooLong_if404onCheck = false; var validation_url; // on upload it gets the url, and it presents it to user on error so they can do inspection var verifyUploaded = function(xhrArg) { - console.error('doing verifyUploaded'); + var { request, ok, reason } = xhrArg; if (!ok && (request.status != 409)) { // link3922222 // TODO: detail why it failed here, so it tells user, it would failed to upload, maybe bad status token etc @@ -605,7 +605,7 @@ function signXpi(extid) { // requestReviewStatus(); } else { // wait for review to complete - console.error('ok good uploaded, status:', request.status, request.response, request.statusText); + validation_url = request.response.validation_url; requestReviewStatus(); } @@ -628,8 +628,8 @@ function signXpi(extid) { }); } - console.error('doing requestReviewStatus, request_status_cnt:',request_status_cnt); - console.log('url:', AMODOMAIN + '/api/v3/addons/' + encodeURIComponent(xpiid) + '/versions/' + xpiversion + '/'); + + xhrAsync(AMODOMAIN + '/api/v3/addons/' + encodeURIComponent(xpiid) + '/versions/' + xpiversion + '/', { responseType: 'json', headers: { @@ -639,9 +639,9 @@ function signXpi(extid) { }; var callbackReviewStatus = function(xhrArg) { - console.error('doing callbackReviewStatus'); + var { request, ok, reason } = xhrArg; - console.error('response on status review check:', { status: request.status, statusText: request.statusText, url: request.responseURL, response: request.response }); + if (!ok) { // TODO: detail why it failed here, so it tells user, failed checking status // xhr failed @@ -666,7 +666,7 @@ function signXpi(extid) { // TODO: state changes of reponse.jon for eventual rejected // TODO: state changes of reponse.jon for eventual other non-approved (like error) - console.error('review status check, xhr details:', request.status, request.response, request.statusText); + if (request.status == 200) { // if (request.response.files) { if (request.response.files.length === 1) { @@ -694,7 +694,7 @@ function signXpi(extid) { onprogress }, callbackDownloadSigned); } else if (request.response.files.length === 0) { - console.error('addon not yet signed, wait, then check again') + if (request.response.reviewed && !request.response.passed_review) { // i was using .response.processed however it was not right, as it gets processed before reviewed. so updated to .response.reviewed. as with fullscreenshot thing i got that warning for binary - https://chrome.google.com/webstore/detail/full-page-screen-capture/fdpohaocaechififmbbbbbknoalclacl // throw new Error('failed validation of the signing process'); @@ -707,7 +707,7 @@ function signXpi(extid) { deferredMain_signXpi.resolve(rezMain); } else { // review is in process, check again after waiting - console.error('review is in process, check after waiting'); + if (request_status_cnt == request_status_max) { rezMain.ok = false; @@ -776,11 +776,11 @@ function signXpi(extid) { } else { // save to disk - console.error('ok downloaded data, saving to disk'); + try { writeThenDir(OS.Path.join(core.addon.path.storage_signed, extid + '.xpi'), new Uint8Array(request.response), OS.Constants.Path.profileDir); } catch(ex) { - console.error('ex:', ex, uneval(ex), ex.toString()); + throw ex; } @@ -950,18 +950,18 @@ function installAddon(aArg, aComm) { try { OS.File.copy(copy_path, install_path); } catch(ex) { - console.error('ex when copying 1 - ', ex); + if (ex.becauseNoSuchFile) { try { OS.File.makeDir(core.addon.path.storage_installations, {from:OS.Constants.Path.profileDir}); } catch (ex) { mainRez.reason = 'filesystem_dir'; - console.error('ex when make dir - ', ex); + } try { OS.File.copy(copy_path, install_path); } catch(ex) { - console.error('ex when copying 2 - ', ex); + mainRez.reason = 'no_src_file'; } } else { @@ -975,7 +975,7 @@ function installAddon(aArg, aComm) { } else { if (!temp) { install_path = OS.Path.toFileURI(install_path); - console.log('file uri of install_path:', install_path); + } var install_method = temp ? 'installAddonAsTemp' : 'installAddonAsNormal'; @@ -991,7 +991,7 @@ function installAddon(aArg, aComm) { } self.onclose = function() { - console.log('ok ready to terminate'); + } // End - Addon Functionality @@ -1180,7 +1180,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'); } } @@ -1195,7 +1195,7 @@ function validateOptionsObj(aOptions, aOptionsDefaults) { // rev1 - https://gist.github.com/Noitidart/ec1e6b9a593ec7e3efed function xhr(aUrlOrFileUri, aOptions={}) { - // console.error('in xhr!!! aUrlOrFileUri:', aUrlOrFileUri); + // all requests are sync - as this is in a worker var aOptionsDefaults = { @@ -1220,9 +1220,9 @@ function xhr(aUrlOrFileUri, aOptions={}) { cRequest.responseType = aOptions.responseType; cRequest.send(aOptions.data); - // console.log('response:', cRequest.response); - // console.error('done xhr!!!'); + + return cRequest; } @@ -1259,7 +1259,7 @@ function formatStringFromName(aKey, aLocalizedPackageName, aReplacements) { _cache_formatStringFromName_packages[packageName] = packageJson; - console.log('packageJson:', packageJson); + } var cLocalizedStr = _cache_formatStringFromName_packages[packageName][aKey]; @@ -1276,7 +1276,7 @@ function formatStringFromName(aKey, aLocalizedPackageName, aReplacements) { } function xhrAsync(aUrlOrFileUri, aOptions={}, aCallback) { // 052716 - added timeout support - // console.error('in xhr!!! aUrlOrFileUri:', aUrlOrFileUri); + // all requests are sync - as this is in a worker var aOptionsDefaults = { @@ -1373,9 +1373,9 @@ function xhrAsync(aUrlOrFileUri, aOptions={}, aCallback) { // 052716 - added tim request.responseType = aOptions.responseType; request.send(aOptions.data); - // console.log('response:', request.response); - // console.error('done xhr!!!'); + + } @@ -1393,7 +1393,7 @@ function genericReject(aPromiseName, aPromiseToReject, aReason) { name: aPromiseName, aReason: aReason }; - console.error('Rejected - ' + aPromiseName + ' - ', rejObj); + if (aPromiseToReject) { aPromiseToReject.reject(rejObj); } @@ -1403,7 +1403,7 @@ function genericCatch(aPromiseName, aPromiseToReject, aCaught) { name: aPromiseName, aCaught: aCaught }; - console.error('Caught - ' + aPromiseName + ' - ', rejObj); + if (aPromiseToReject) { aPromiseToReject.reject(rejObj); } @@ -1453,7 +1453,7 @@ function workerComm() { }; this.listener = function(e) { var payload = e.data; - console.log('worker workerComm - incoming, payload:', payload); //, 'e:', e); + if (payload.method) { if (!firstMethodCalled) { @@ -1462,21 +1462,21 @@ function workerComm() { this.postMessage('triggerOnAfterInit', scope.init(undefined, this)); } } - console.log('scope:', scope); - if (!(payload.method in scope)) { console.error('method of "' + payload.method + '" not in scope'); throw new Error('method of "' + payload.method + '" not in scope') } // dev line remove on prod + + var rez_worker_call_for_bs = scope[payload.method](payload.arg, this); - console.log('rez_worker_call_for_bs:', rez_worker_call_for_bs); + if (payload.cbid) { if (rez_worker_call_for_bs && rez_worker_call_for_bs.constructor.name == 'Promise') { rez_worker_call_for_bs.then( function(aVal) { - console.log('Fullfilled - rez_worker_call_for_bs - ', aVal); + this.postMessage(payload.cbid, aVal); }.bind(this), genericReject.bind(null, 'rez_worker_call_for_bs', 0) ).catch(genericCatch.bind(null, 'rez_worker_call_for_bs', 0)); } else { - console.log('calling postMessage for callback with rez_worker_call_for_bs:', rez_worker_call_for_bs, 'this:', this); + this.postMessage(payload.cbid, rez_worker_call_for_bs); } } @@ -1489,7 +1489,7 @@ function workerComm() { this.callbackReceptacle[payload.cbid](payload.arg, this); delete this.callbackReceptacle[payload.cbid]; } else { - console.error('worker workerComm - invalid combination'); + throw new Error('worker workerComm - invalid combination'); } }.bind(this);