Refactoring

This commit is contained in:
Maxim Baz
2019-03-31 01:28:15 +01:00
parent 9431e46f9e
commit 64a8cdd497

View File

@@ -183,33 +183,33 @@ function saveRecent(settings, login, remove = false) {
* Call injected code to fill the form * Call injected code to fill the form
* *
* @param object settings Settings object * @param object settings Settings object
* @param object fillRequest Fill request details * @param object request Request details
* @param boolean allFrames Dispatch to all frames * @param boolean allFrames Dispatch to all frames
* @param boolean allowForeign Allow foreign-origin iframes * @param boolean allowForeign Allow foreign-origin iframes
* @param boolean allowNoSecret Allow forms that don't contain a password field * @param boolean allowNoSecret Allow forms that don't contain a password field
* @return array list of filled fields * @return array list of filled fields
*/ */
async function dispatchFill(settings, fillRequest, allFrames, allowForeign, allowNoSecret) { async function dispatchFill(settings, request, allFrames, allowForeign, allowNoSecret) {
fillRequest = Object.assign(deepCopy(fillRequest), { request = Object.assign(deepCopy(request), {
allowForeign: allowForeign, allowForeign: allowForeign,
allowNoSecret: allowNoSecret, allowNoSecret: allowNoSecret,
foreignFills: settings.foreignFills[settings.host] || {} foreignFills: settings.foreignFills[settings.host] || {}
}); });
var perFrameFillResults = await chrome.tabs.executeScript(settings.tab.id, { let perFrameResults = await chrome.tabs.executeScript(settings.tab.id, {
allFrames: allFrames, allFrames: allFrames,
code: `window.browserpass.fillLogin(${JSON.stringify(fillRequest)});` code: `window.browserpass.fillLogin(${JSON.stringify(request)});`
}); });
// merge filled fields into a single array // merge filled fields into a single array
var filledFields = perFrameFillResults let filledFields = perFrameResults
.reduce((merged, frameResult) => merged.concat(frameResult.filledFields), []) .reduce((merged, frameResult) => merged.concat(frameResult.filledFields), [])
.filter((val, i, merged) => merged.indexOf(val) === i); .filter((val, i, merged) => merged.indexOf(val) === i);
// if user answered a foreign-origin confirmation, // if user answered a foreign-origin confirmation,
// store the answers in the settings // store the answers in the settings
var foreignFillsChanged = false; let foreignFillsChanged = false;
for (var frame of perFrameFillResults) { for (let frame of perFrameResults) {
if (typeof frame.foreignFill !== "undefined") { if (typeof frame.foreignFill !== "undefined") {
if (typeof settings.foreignFills[settings.host] === "undefined") { if (typeof settings.foreignFills[settings.host] === "undefined") {
settings.foreignFills[settings.host] = {}; settings.foreignFills[settings.host] = {};
@@ -228,21 +228,21 @@ async function dispatchFill(settings, fillRequest, allFrames, allowForeign, allo
/** /**
* Call injected code to focus or submit the form * Call injected code to focus or submit the form
* *
* @param object settings Settings object * @param object settings Settings object
* @param object focusOrSubmitRequest Focus or submit request details * @param object request Request details
* @param boolean allFrames Dispatch to all frames * @param boolean allFrames Dispatch to all frames
* @param boolean allowForeign Allow foreign-origin iframes * @param boolean allowForeign Allow foreign-origin iframes
* @return void * @return void
*/ */
async function dispatchFocusOrSubmit(settings, focusOrSubmitRequest, allFrames, allowForeign) { async function dispatchFocusOrSubmit(settings, request, allFrames, allowForeign) {
focusOrSubmitRequest = Object.assign(deepCopy(focusOrSubmitRequest), { request = Object.assign(deepCopy(request), {
allowForeign: allowForeign, allowForeign: allowForeign,
foreignFills: settings.foreignFills[settings.host] || {} foreignFills: settings.foreignFills[settings.host] || {}
}); });
await chrome.tabs.executeScript(settings.tab.id, { await chrome.tabs.executeScript(settings.tab.id, {
allFrames: allFrames, allFrames: allFrames,
code: `window.browserpass.focusOrSubmit(${JSON.stringify(focusOrSubmitRequest)});` code: `window.browserpass.focusOrSubmit(${JSON.stringify(request)});`
}); });
} }