@@ -16,22 +16,22 @@ ChromeUtils.defineModuleGetter(this, "UIState",
1616ChromeUtils . defineModuleGetter ( this , "ObjectUtils" ,
1717 "resource://gre/modules/ObjectUtils.jsm" ) ;
1818
19+ // STATUS_LOGIN_FAILED means the password was changed on another device, and the
20+ // user needs to log in again.
21+ // STATUS_NOT_VERIFIED means the user has logged in with an unverified email.
22+ // In both cases, the user needs to take action elsewhere in Firefox.
23+ const FxAErrors = [ UIState . STATUS_LOGIN_FAILED , UIState . STATUS_NOT_VERIFIED ] ;
24+
1925const getProfileInfo = async ( ) => {
2026 const uiState = UIState . get ( ) ;
21- // STATUS_LOGIN_FAILED means the password was changed on another device, and the
22- // user needs to log in again.
23- // STATUS_NOT_VERIFIED means the user has logged in with an unverified email.
24- // In both cases, the user needs to take action elsewhere in Firefox.
25- const errors = [ UIState . STATUS_LOGIN_FAILED , UIState . STATUS_NOT_VERIFIED ] ;
26-
2727 let profileInfo ;
2828
2929 // STATUS_NOT_CONFIGURED means the user is not logged in.
3030 if ( uiState . status === UIState . STATUS_NOT_CONFIGURED ) {
3131 profileInfo = null ;
3232 } else { // UIState.STATUS_SIGNED_IN, the user is logged in and verified.
3333 const fxa = await UIState . _internal . fxAccounts . getSignedInUser ( ) ;
34- const isErrorStatus = errors . includes ( uiState . status ) ;
34+ const isErrorStatus = FxAErrors . includes ( uiState . status ) ;
3535
3636 profileInfo = {
3737 id : fxa && fxa . uid ,
@@ -45,6 +45,16 @@ const getProfileInfo = async () => {
4545 return profileInfo ;
4646} ;
4747
48+ const openPrefs = async ( origin , entrypoint ) => {
49+ const win = Services . wm . getMostRecentWindow ( "navigator:browser" ) ;
50+
51+ win . openPreferences ( "paneSync" , { origin, urlParams : { entrypoint } } ) ;
52+ } ;
53+ const openSignIn = async ( entrypoint ) => {
54+ // TODO: be smarter like browser?
55+ return openPrefs ( "fxaError" , entrypoint ) ;
56+ } ;
57+
4858this . sync = class extends ExtensionAPI {
4959 getAPI ( context ) {
5060 const EventManager = ExtensionCommon . EventManager ;
@@ -58,6 +68,21 @@ this.sync = class extends ExtensionAPI {
5868 const profileInfo = await getProfileInfo ( ) ;
5969 return profileInfo ;
6070 } ,
71+
72+ async openPreferences ( entrypoint ) {
73+ const uiState = UIState . get ( ) ;
74+
75+ switch ( uiState . status ) {
76+ case UIState . STATUS_SIGNED_IN :
77+ return openPrefs ( "fxaSignedin" , entrypoint ) ;
78+ case UIState . STATUS_NOT_VERIFIED :
79+ return openPrefs ( "fxaError" , entrypoint ) ;
80+ case UIState . STATUS_LOGIN_FAILED :
81+ return openSignIn ( entrypoint ) ;
82+ }
83+
84+ return openPrefs ( "fxa" , entrypoint ) ;
85+ } ,
6186 onUserProfileChanged : new EventManager ( context , "sync.onUserProfileChanged" , async ( fire ) => {
6287 let oldValue = await getProfileInfo ( ) ;
6388 const callback = ( value ) => {
0 commit comments