11import ContentFeature from '../content-feature' ;
22import { isBeingFramed , withExponentialBackoff } from '../utils' ;
33import { execute } from './broker-protection/execute' ;
4- import { Steps } from './autofill-bookmark-steps' ;
54import { DEFAULT_RETRY_CONFIG , retry } from '../timer-utils' ;
65
76export const ANIMATION_DURATION_MS = 1000 ;
@@ -10,7 +9,6 @@ export const BACKGROUND_COLOR_START = 'rgba(85, 127, 243, 0.10)';
109export const BACKGROUND_COLOR_END = 'rgba(85, 127, 243, 0.25)' ;
1110export const OVERLAY_ID = 'ddg-password-import-overlay' ;
1211export const DELAY_BEFORE_ANIMATION = 300 ;
13- const BOOKMARK_IMPORT_DOMAIN = 'takeout.google.com' ;
1412const TAKEOUT_DOWNLOAD_URL_BASE = '/takeout/download' ;
1513
1614/**
@@ -65,7 +63,8 @@ export default class AutofillImport extends ContentFeature {
6563 /** @type {WeakSet<Element> } */
6664 #tappedElements = new WeakSet ( ) ;
6765
68- // #bookmarkImportActions;
66+ #bookmarkImportActions;
67+ #bookmarkImportSelectors;
6968
7069 /**
7170 * @returns {ButtonAnimationStyle }
@@ -425,7 +424,7 @@ export default class AutofillImport extends ContentFeature {
425424 }
426425
427426 async handlePasswordManagerPath ( pathname ) {
428- console . log ( 'DEEP DEBUG autofill-password- import: handlePasswordManagerPath' , pathname ) ;
427+ console . log ( 'DEEP DEBUG autofill-import: handlePasswordManagerPath' , pathname ) ;
429428 this . removeOverlayIfNeeded ( ) ;
430429 if ( this . isSupportedPath ( pathname ) ) {
431430 try {
@@ -447,15 +446,18 @@ export default class AutofillImport extends ContentFeature {
447446 *
448447 */
449448 async handleLocation ( location ) {
450- const { pathname, hostname } = location ;
451- if ( hostname === BOOKMARK_IMPORT_DOMAIN ) {
449+ const { pathname } = location ;
450+ if ( this . getFeatureSettingEnabled ( 'canImportFromGoogleTakeout' ) ) {
452451 if ( this . #processingBookmark) {
453452 return ;
454453 }
455454 this . #processingBookmark = true ;
456455 this . handleBookmarkImportPath ( pathname ) ;
457- } else {
456+ } else if ( this . getFeatureSettingEnabled ( 'canImportFromGooglePasswordManager' ) ) {
458457 await this . handlePasswordManagerPath ( pathname ) ;
458+ } else {
459+ // Unknown feature, we bail out
460+ return ;
459461 }
460462 }
461463
@@ -524,15 +526,10 @@ export default class AutofillImport extends ContentFeature {
524526 }
525527
526528 /** Bookmark import code */
527-
528- get userIdSelector ( ) {
529- return 'a[href*="&user="]' ;
530- }
531-
532529 async downloadData ( ) {
533- const userId = document . querySelector ( this . userIdSelector ) ?. getAttribute ( 'href' ) ?. split ( '&user=' ) [ 1 ] ;
534- console . log ( 'DEEP DEBUG autofill-password- import: userId' , userId ) ;
535- await this . runWithRetry ( ( ) => document . querySelector ( `a[href="./manage/archive/ ${ this . #exportId} "] ` ) , 8 ) ;
530+ const userId = document . querySelector ( this . #bookmarkImportSelectors . userIdLink ) ?. getAttribute ( 'href' ) ?. split ( '&user=' ) [ 1 ] ;
531+ console . log ( 'DEEP DEBUG autofill-import: userId' , userId ) ;
532+ await this . runWithRetry ( ( ) => document . querySelector ( `${ this . #bookmarkImportSelectors . downloadLink } / ${ this . #exportId} ` ) , 8 ) ;
536533 const downloadURL = `${ TAKEOUT_DOWNLOAD_URL_BASE } ?j=${ this . #exportId} &i=0&user=${ userId } ` ;
537534 window . location . href = downloadURL ;
538535 }
@@ -548,13 +545,12 @@ export default class AutofillImport extends ContentFeature {
548545 }
549546
550547 async handleBookmarkImportPath ( pathname ) {
551- console . log ( 'DEEP DEBUG autofill-password- import: handleBookmarkImportPath' , pathname ) ;
548+ console . log ( 'DEEP DEBUG autofill-import: handleBookmarkImportPath' , pathname ) ;
552549 if ( pathname === '/' && ! this . #isBookmarkModalVisible) {
553- const bookmarkSteps = new Steps ( ) ;
554- for ( const action of bookmarkSteps . actions ) {
550+ for ( const action of this . #bookmarkImportActions) {
555551 if ( action . id === 'chrome-data-button-click' ) {
556552 await this . runWithRetry ( ( ) => {
557- const element = document . querySelector ( this . chromeDataButtonSelector ) ;
553+ const element = document . querySelector ( this . #bookmarkImportSelectors . chromeDataButton ) ;
558554 return element ?. checkVisibility ( ) ;
559555 } ) ;
560556 }
@@ -571,50 +567,43 @@ export default class AutofillImport extends ContentFeature {
571567 }
572568 }
573569
574- setButtonSettings ( ) {
570+ setPasswordImportSettings ( ) {
575571 this . #exportButtonSettings = this . getFeatureSetting ( 'exportButton' ) ;
576572 this . #signInButtonSettings = this . getFeatureSetting ( 'signInButton' ) ;
577573 this . #settingsButtonSettings = this . getFeatureSetting ( 'settingsButton' ) ;
578574 }
579575
580- setDBPActions ( ) {
581- // this.#bookmarkImportActions = actions;
582- }
583-
584- get tabPanelSelector ( ) {
585- return 'div[role="tabpanel"]' ;
586- }
587-
588- get chromeDataButtonSelector ( ) {
589- return `${ this . tabPanelSelector } div:nth-child(10) > div:nth-child(2) > div:nth-child(2) button` ;
576+ setBookmarkImportSettings ( ) {
577+ this . #bookmarkImportActions = this . getFeatureSetting ( 'actions' ) ;
578+ this . #bookmarkImportSelectors = this . getFeatureSetting ( 'selectors' ) ;
590579 }
591580
592581 async findExportId ( ) {
593- const panels = document . querySelectorAll ( this . tabPanelSelector ) ;
582+ const panels = document . querySelectorAll ( this . #bookmarkImportSelectors . tabPanel ) ;
594583 const exportPanel = panels [ panels . length - 1 ] ;
595584 return await this . runWithRetry ( ( ) => exportPanel . querySelector ( 'div[data-archive-id]' ) ?. getAttribute ( 'data-archive-id' ) , 8 , 100 ) ;
596585 }
597586
598587 async storeExportId ( ) {
599588 this . #exportId = await this . findExportId ( ) ;
600- console . log ( 'DEEP DEBUG autofill-password- import: stored export id' , this . #exportId) ;
589+ console . log ( 'DEEP DEBUG autofill-import: stored export id' , this . #exportId) ;
601590 }
602591
603592 urlChanged ( navigationType ) {
604- console . log ( 'DEEP DEBUG autofill-password- import: urlChanged' , window . location . pathname , navigationType ) ;
593+ console . log ( 'DEEP DEBUG autofill-import: urlChanged' , window . location . pathname , navigationType ) ;
605594 this . handleLocation ( window . location ) ;
606595 }
607596
608597 init ( ) {
609- console . log ( 'DEEP DEBUG autofill-password- import: init' ) ;
598+ console . log ( 'DEEP DEBUG autofill-import: init' ) ;
610599 if ( isBeingFramed ( ) ) {
611600 return ;
612601 }
613602
614603 if ( this . getFeatureSettingEnabled ( 'canImportFromGoogleTakeout' ) ) {
615- // this.setDBPActions(this.getFeatureSetting('bookmarkImport') );
604+ this . setBookmarkImportSettings ( ) ;
616605 } else if ( this . getFeatureSettingEnabled ( 'canImportFromGooglePasswordManager' ) ) {
617- this . setButtonSettings ( ) ;
606+ this . setPasswordImportSettings ( ) ;
618607 } else {
619608 // bail out
620609 return ;
0 commit comments