@ -70,6 +70,7 @@ import {
generateDomainMatchPatterns ,
generateRandomChars ,
isInvalidResponseStatusCode ,
rectHasSize ,
specialCharacterToKeyMap ,
} from "../utils" ;
@ -130,6 +131,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
private currentInlineMenuCiphersCount : number = 0 ;
private currentAddNewItemData : CurrentAddNewItemData ;
private focusedFieldData : FocusedFieldData ;
private allFieldData : AutofillField [ ] ;
private isFieldCurrentlyFocused : boolean = false ;
private isFieldCurrentlyFilling : boolean = false ;
private isInlineMenuButtonVisible : boolean = false ;
@ -1367,6 +1369,71 @@ export class OverlayBackground implements OverlayBackgroundInterface {
this . isInlineMenuListVisible = false ;
}
/ * *
* Get all the totp fields for the tab and frame of the currently focused field
* /
private getTotpFields ( ) : AutofillField [ ] {
const currentTabId = this . focusedFieldData ? . tabId ;
const currentFrameId = this . focusedFieldData ? . frameId ;
const pageDetailsMap = this . pageDetailsForTab [ currentTabId ] ;
const pageDetails = pageDetailsMap ? . get ( currentFrameId ) ;
const fields = pageDetails . details . fields ;
const totpFields = fields . filter ( ( f ) = >
this . inlineMenuFieldQualificationService . isTotpField ( f ) ,
) ;
return totpFields ;
}
/ * *
* calculates the postion and width for multi - input totp field inline menu
* @param totpFieldArray - the totp fields used to evaluate the position of the menu
* /
private calculateTotpMultiInputMenuBounds ( totpFieldArray : AutofillField [ ] ) {
// Filter the fields based on the provided totpfields
const filteredObjects = this . allFieldData . filter ( ( obj ) = >
totpFieldArray . some ( ( o ) = > o . opid === obj . opid ) ,
) ;
// Return null if no matching objects are found
if ( filteredObjects . length === 0 ) {
return null ;
}
// Calculate the smallest left and largest right values to determine width
const left = Math . min (
. . . filteredObjects . filter ( ( obj ) = > rectHasSize ( obj . rect ) ) . map ( ( obj ) = > obj . rect . left ) ,
) ;
const largestRight = Math . max (
. . . filteredObjects . filter ( ( obj ) = > rectHasSize ( obj . rect ) ) . map ( ( obj ) = > obj . rect . right ) ,
) ;
const width = largestRight - left ;
return { left , width } ;
}
/ * *
* calculates the postion for multi - input totp field inline button
* @param totpFieldArray - the totp fields used to evaluate the position of the menu
* /
private calculateTotpMultiInputButtonBounds ( totpFieldArray : AutofillField [ ] ) {
const filteredObjects = this . allFieldData . filter ( ( obj ) = >
totpFieldArray . some ( ( o ) = > o . opid === obj . opid ) ,
) ;
if ( filteredObjects . length === 0 ) {
return null ;
}
const maxRight = Math . max ( . . . filteredObjects . map ( ( obj ) = > obj . rect . right ) ) ;
const maxObject = filteredObjects . find ( ( obj ) = > obj . rect . right === maxRight ) ;
const top = maxObject . rect . top - maxObject . rect . height * 0.39 ;
const left = maxRight - maxObject . rect . height * 0.3 ;
return { left , top } ;
}
/ * *
* Updates the position of either the inline menu list or button . The position
* is based on the focused field ' s position and dimensions .
@ -1472,8 +1539,17 @@ export class OverlayBackground implements OverlayBackgroundInterface {
const subFrameTopOffset = subFrameOffsets ? . top || 0 ;
const subFrameLeftOffset = subFrameOffsets ? . left || 0 ;
const { top , left , width , height } = this . focusedFieldData . focusedFieldRects ;
const { width , height } = this . focusedFieldData . focusedFieldRects ;
let { top , left } = this . focusedFieldData . focusedFieldRects ;
const { paddingRight , paddingLeft } = this . focusedFieldData . focusedFieldStyles ;
if ( this . isTotpFieldForCurrentField ( ) ) {
const totpFields = this . getTotpFields ( ) ;
if ( totpFields . length > 1 ) {
( { left , top } = this . calculateTotpMultiInputButtonBounds ( totpFields ) ) ;
}
}
let elementOffset = height * 0.37 ;
if ( height >= 35 ) {
elementOffset = height >= 50 ? height * 0.47 : height * 0.42 ;
@ -1512,7 +1588,16 @@ export class OverlayBackground implements OverlayBackgroundInterface {
const subFrameTopOffset = subFrameOffsets ? . top || 0 ;
const subFrameLeftOffset = subFrameOffsets ? . left || 0 ;
const { top , left , width , height } = this . focusedFieldData . focusedFieldRects ;
const { top , height } = this . focusedFieldData . focusedFieldRects ;
let { left , width } = this . focusedFieldData . focusedFieldRects ;
if ( this . isTotpFieldForCurrentField ( ) ) {
const totpFields = this . getTotpFields ( ) ;
if ( totpFields . length > 1 ) {
( { left , width } = this . calculateTotpMultiInputMenuBounds ( totpFields ) ) ;
}
}
this . inlineMenuPosition . list = {
top : Math.round ( top + height + subFrameTopOffset ) ,
@ -1535,7 +1620,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
* @param sender - The sender of the extension message
* /
private setFocusedFieldData (
{ focusedFieldData } : OverlayBackgroundExtensionMessage ,
{ focusedFieldData , allFieldsRect } : OverlayBackgroundExtensionMessage ,
sender : chrome.runtime.MessageSender ,
) {
if (
@ -1552,6 +1637,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
const previousFocusedFieldData = this . focusedFieldData ;
this . focusedFieldData = { . . . focusedFieldData , tabId : sender.tab.id , frameId : sender.frameId } ;
this . allFieldData = allFieldsRect ;
this . isFieldCurrentlyFocused = true ;
if ( this . shouldUpdatePasswordGeneratorMenuOnFieldFocus ( ) ) {