1616using Newtonsoft . Json ;
1717using Newtonsoft . Json . Linq ;
1818using passbolt . Exceptions ;
19- using passbolt . Models . Authentication ;
19+ using passbolt . Models . Authentication ;
2020using passbolt . Models . Cookies ;
2121using passbolt . Models . CredentialLocker ;
2222using passbolt . Models . Messaging . Topics ;
3030using passbolt . Utils ;
3131using System ;
3232using System . Collections . Generic ;
33- using System . Threading . Tasks ;
33+ using System . Threading . Tasks ;
3434using Windows . ApplicationModel . DataTransfer ;
3535
3636namespace passbolt . Models . Messaging
3737{
3838 public class BackgroundTopic : WebviewTopic
3939 {
4040 private CredentialLockerService credentialLockerService ;
41- private string currentIndexBackground = "index-auth.html" ;
41+ private string currentIndexBackground = "index-auth.html" ;
4242 private string currentIndexRendered = "index-auth.html" ;
4343 private string passphrase ;
4444 private string pendingRequestId ;
4545 private RbacService rbacService ;
4646 private CookiesManager cookiesManager ;
47- private List < IPC > pendingMessages ;
47+ private List < IPC > pendingMessages ;
4848
4949 public BackgroundTopic ( WebView2 background , WebView2 rendered , LocalFolderService localFolderService , BackgroundWebviewService backgroundWebviewService ) : base ( background , rendered , localFolderService , backgroundWebviewService )
5050 {
@@ -67,67 +67,67 @@ public async override void ProceedMessage(IPC ipc)
6767 {
6868 case AllowedTopics . BACKGROUND_READY :
6969 //It means we have a single navigation of the Background webview
70- if ( this . pendingRequestId != null )
71- {
72- this . proceedPendingRequest ( ) ;
73- }
74- else
75- {
70+ if ( this . pendingRequestId != null )
71+ {
72+ this . proceedPendingRequest ( ) ;
73+ }
74+ else
75+ {
7676 WebviewOrchestratorService . Instance . SetBackgroundStatus ( true ) ;
7777 if ( WebviewOrchestratorService . Instance . AreAllReady ( ) )
7878 {
7979 rendered . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( new IPC ( AllowedTopics . BACKGROUND_READY ) ) ) ;
8080 background . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( new IPC ( AllowedTopics . RENDERED_READY ) ) ) ;
81- }
82- if ( passphrase != null )
83- {
84- background . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( new IPC ( AllowedTopics . BACKGROUND_STORE_PASSPHRASE , passphrase ) ) ) ;
81+ }
82+ if ( passphrase != null )
83+ {
84+ background . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( new IPC ( AllowedTopics . BACKGROUND_STORE_PASSPHRASE , passphrase ) ) ) ;
8585 rendered . Source = new Uri ( UriBuilderHelper . BuildHostUri ( RenderedNavigationService . Instance . trustedUrl , "/Rendered/index-workspace.html" ) ) ;
86- passphrase = null ;
87- }
88- }
86+ passphrase = null ;
87+ }
88+ }
8989 break ;
9090 case AllowedTopics . BACKGROUND_GET_COOKIE :
9191 string cookie = cookiesManager . getCookie ( ( string ) ipc . message ) ;
9292 var response = new IPC ( ) ;
9393 response . message = cookie ;
9494 response . status = "SUCCESS" ;
9595 response . topic = ipc . requestId ;
96- background . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( response ) ) ;
96+ background . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( response ) ) ;
9797 break ;
9898 case AllowedTopics . BACKGROUND_SET_THEME :
9999 accountMetaData . theme = ( string ) ipc . message ;
100- await this . credentialLockerService . Create ( "account-metadata" , JsonConvert . SerializeObject ( accountMetaData ) ) ;
100+ await this . credentialLockerService . Create ( "account-metadata" , JsonConvert . SerializeObject ( accountMetaData ) ) ;
101101 break ;
102102 case AllowedTopics . BACKGROUND_SET_LOCALE :
103103 accountMetaData . locale = ( string ) ipc . message ;
104- await this . credentialLockerService . Create ( "account-metadata" , JsonConvert . SerializeObject ( accountMetaData ) ) ;
104+ await this . credentialLockerService . Create ( "account-metadata" , JsonConvert . SerializeObject ( accountMetaData ) ) ;
105105 break ;
106106 case AllowedTopics . BACKGROUND_SET_SECURITY_TOKEN :
107107 accountMetaData . securityToken = SerializationHelper . DeserializeFromJson < SecurityToken > ( ( ( JObject ) ipc . message ) . ToString ( ) ) ;
108- await this . credentialLockerService . Create ( "account-metadata" , JsonConvert . SerializeObject ( accountMetaData ) ) ;
108+ await this . credentialLockerService . Create ( "account-metadata" , JsonConvert . SerializeObject ( accountMetaData ) ) ;
109109 break ;
110110 case AllowedTopics . BACKGROUND_ROTATE_KEY :
111111 var accountSecret = await this . credentialLockerService . GetAccountSecret ( ) ;
112112 accountSecret . userPrivateArmoredKey = ( string ) ipc . message ;
113113 await this . credentialLockerService . Create ( "account-secret" , JsonConvert . SerializeObject ( accountSecret ) ) ;
114- break ;
115- case AuthenticationTopics . REQUIRE_MFA :
116- var message = SerializationHelper . DeserializeFromJson < MfaAuthentication > ( ( ( JObject ) ipc . message ) . ToString ( ) ) ;
114+ break ;
115+ case AuthenticationTopics . REQUIRE_MFA :
116+ var message = SerializationHelper . DeserializeFromJson < MfaAuthentication > ( ( ( JObject ) ipc . message ) . ToString ( ) ) ;
117117 passphrase = message . passphrase ;
118118
119119 // Allow navigation for MFA authentication
120120 RenderedNavigationService . Instance . AllowMfaUrls ( accountMetaData . domain ) ;
121- rendered . Source = new Uri ( accountMetaData . domain + $ "/mfa/verify/{ message . provider } ?redirect=/") ;
121+ rendered . Source = new Uri ( accountMetaData . domain + $ "/mfa/verify/{ message . provider } ?redirect=/") ;
122122 break ;
123123 case AuthImportTopics . SAVE_ACCOUNT :
124- this . currentIndexBackground = "index-auth.html" ;
125- this . currentIndexRendered = "index-import.html" ;
126- pendingRequestId = SerializationHelper . DeserializeFromJson < RequestId > ( ( ( JObject ) ipc . message ) . ToString ( ) ) . requestId ;
124+ this . currentIndexBackground = "index-auth.html" ;
125+ this . currentIndexRendered = "index-import.html" ;
126+ pendingRequestId = SerializationHelper . DeserializeFromJson < RequestId > ( ( ( JObject ) ipc . message ) . ToString ( ) ) . requestId ;
127127 var metaData = SerializationHelper . DeserializeFromJson < AccountMetaData > ( ( ( JObject ) ipc . message ) . ToString ( ) ) ;
128128 var secrets = SerializationHelper . DeserializeFromJson < AccountSecret > ( ( ( JObject ) ipc . message ) . ToString ( ) ) ;
129129 await this . credentialLockerService . CreateAccount ( metaData , secrets ) ;
130- //We remove previous virtualhost and create a new one based on trusted domain
130+ //We remove previous virtualhost and create a new one based on trusted domain
131131 var backgroundUrl = await this . webviewService . SetVirtualHost ( ) ;
132132 await localFolderService . CreateBackgroundIndex ( this . currentIndexBackground , "background-auth" , metaData . domain ) ;
133133 background . Source = new Uri ( UriBuilderHelper . BuildHostUri ( backgroundUrl , "/index-auth.html" ) ) ;
@@ -166,14 +166,14 @@ public async override void ProceedMessage(IPC ipc)
166166 }
167167 break ;
168168 case AuthenticationTopics . LOG_OUT :
169- this . currentIndexBackground = "index-auth.html" ;
170- this . currentIndexRendered = "index-auth.html" ;
169+ this . currentIndexBackground = "index-auth.html" ;
170+ this . currentIndexRendered = "index-auth.html" ;
171171 await localFolderService . RemoveFile ( "Rendered" , "index-workspace.html" ) ;
172172 await localFolderService . RemoveFile ( "Background" , "index-workspace.html" ) ;
173- await localFolderService . CreateRenderedIndex ( this . currentIndexRendered , "rendered-auth" , "ext_authentication.min.css" , accountMetaData . domain ) ;
174- await localFolderService . CreateBackgroundIndex ( this . currentIndexBackground , "background-auth" , accountMetaData . domain ) ;
175- background . Source = new Uri ( UriBuilderHelper . BuildHostUri ( BackgroundNavigationService . Instance . trustedUrl , "/Background/index-auth.html" ) ) ;
176- rendered . Source = new Uri ( UriBuilderHelper . BuildHostUri ( RenderedNavigationService . Instance . trustedUrl , "/Rendered/index-auth.html" ) ) ;
173+ await localFolderService . CreateRenderedIndex ( this . currentIndexRendered , "rendered-auth" , "ext_authentication.min.css" , accountMetaData . domain ) ;
174+ await localFolderService . CreateBackgroundIndex ( this . currentIndexBackground , "background-auth" , accountMetaData . domain ) ;
175+ background . Source = new Uri ( UriBuilderHelper . BuildHostUri ( BackgroundNavigationService . Instance . trustedUrl , "/Background/index-auth.html" ) ) ;
176+ rendered . Source = new Uri ( UriBuilderHelper . BuildHostUri ( RenderedNavigationService . Instance . trustedUrl , "/Rendered/index-auth.html" ) ) ;
177177 break ;
178178 case AuthenticationTopics . AFTER_LOGIN :
179179 passphrase = ( string ) ipc . message ;
@@ -214,68 +214,68 @@ public async override void ProceedMessage(IPC ipc)
214214
215215 break ;
216216 }
217- }
218-
219- /// <summary>
220- /// Create folder for workspace and redirect user to workspace
221- /// </summary>
217+ }
218+
219+ /// <summary>
220+ /// Create folder for workspace and redirect user to workspace
221+ /// </summary>
222222 /// <param name="accountMeta"></param>
223- public async Task RedirectToWorkspace ( )
224- {
223+ public async Task RedirectToWorkspace ( )
224+ {
225225 var accountMetaData = await this . credentialLockerService . GetAccountMetadata ( ) ;
226-
227- await localFolderService . RemoveFile ( "Rendered" , this . currentIndexRendered ) ;
228- await localFolderService . RemoveFile ( "Background" , this . currentIndexBackground ) ;
229- await localFolderService . CreateRenderedIndex ( "index-workspace.html" , "rendered-workspace" , "ext_app.min.css" , accountMetaData . domain ) ;
226+
227+ await localFolderService . RemoveFile ( "Rendered" , this . currentIndexRendered ) ;
228+ await localFolderService . RemoveFile ( "Background" , this . currentIndexBackground ) ;
229+ await localFolderService . CreateRenderedIndex ( "index-workspace.html" , "rendered-workspace" , "ext_app.min.css" , accountMetaData . domain ) ;
230230 await localFolderService . CreateBackgroundIndex ( "index-workspace.html" , "background-workspace" , accountMetaData . domain ) ;
231- var configuration = await credentialLockerService . GetApplicationConfiguration ( ) ;
232- background . Source = new Uri ( UriBuilderHelper . BuildHostUri ( configuration . backgroundUrl , "/Background/index-workspace.html" ) ) ;
231+ var configuration = await credentialLockerService . GetApplicationConfiguration ( ) ;
232+ background . Source = new Uri ( UriBuilderHelper . BuildHostUri ( configuration . backgroundUrl , "/Background/index-workspace.html" ) ) ;
233233 }
234234
235- /// <summary>
236- /// Process all pending messages when Rendered webview becomes ready
237- /// </summary>
238- public void ProcessPendingMessages ( )
239- {
240- if ( pendingMessages . Count > 0 )
241- {
242- var messages = new List < IPC > ( pendingMessages ) ;
235+ /// <summary>
236+ /// Process all pending messages when Rendered webview becomes ready
237+ /// </summary>
238+ public void ProcessPendingMessages ( )
239+ {
240+ if ( pendingMessages . Count > 0 )
241+ {
242+ var messages = new List < IPC > ( pendingMessages ) ;
243243
244- foreach ( var message in messages )
245- {
246- ProceedMessage ( message ) ;
244+ foreach ( var message in messages )
245+ {
246+ ProceedMessage ( message ) ;
247247 }
248248
249- pendingMessages . Clear ( ) ;
250- }
249+ pendingMessages . Clear ( ) ;
250+ }
251251 }
252252
253- /// <summary>
254- /// Proceed a pending request Id
253+ /// <summary>
254+ /// Proceed a pending request Id
255255 /// </summary>
256- public void proceedPendingRequest ( )
257- {
258- AllowedTopics . proceedRequestId ( this . pendingRequestId ) ;
259- var icpMessage = new IPC ( ) ;
260- icpMessage . status = "SUCCESS" ;
261- icpMessage . topic = this . pendingRequestId ;
262- rendered . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( icpMessage ) ) ;
263- this . pendingRequestId = null ;
256+ public void proceedPendingRequest ( )
257+ {
258+ AllowedTopics . proceedRequestId ( this . pendingRequestId ) ;
259+ var icpMessage = new IPC ( ) ;
260+ icpMessage . status = "SUCCESS" ;
261+ icpMessage . topic = this . pendingRequestId ;
262+ rendered . CoreWebView2 . PostWebMessageAsJson ( SerializationHelper . SerializeToJson ( icpMessage ) ) ;
263+ this . pendingRequestId = null ;
264264 }
265265
266- /// <summary>
267- /// Map the response from the background webview
268- /// </summary>
269- /// <param name="ipc"></param>
270- /// <returns></returns>
271- public void mapResponse ( IPC ipc , string topic )
272- {
273- if ( topic == RbacTopics . FIND_ME )
266+ /// <summary>
267+ /// Map the response from the background webview
268+ /// </summary>
269+ /// <param name="ipc"></param>
270+ /// <returns></returns>
271+ public void mapResponse ( IPC ipc , string topic )
272+ {
273+ if ( topic == RbacTopics . FIND_ME )
274274 {
275275 var controls = SerializationHelper . DeserializeFromJson < List < ControlFunction > > ( ( ( JArray ) ipc . message ) . ToString ( ) ) ;
276276 this . rbacService . AddDesktopRbac ( controls ) ;
277- ipc . message = controls ;
278- }
277+ ipc . message = controls ;
278+ }
279279 }
280280
281281 /// <summary>
@@ -286,10 +286,9 @@ public void mapResponse(IPC ipc, string topic)
286286 /// <returns bool></returns>
287287 private bool canProceedMessage ( IPC ipc )
288288 {
289- if ( ! WebviewOrchestratorService . Instance . IsRenderedReady ( ) && ipc . topic != AllowedTopics . BACKGROUND_READY )
290- {
289+ if ( ! WebviewOrchestratorService . Instance . IsRenderedReady ( ) && ipc . topic != AllowedTopics . BACKGROUND_READY )
290+ {
291291 pendingMessages . Add ( ipc ) ;
292- return false ;
293292 }
294293
295294 return true ;
0 commit comments