@@ -450,6 +450,7 @@ export class CoreFormatTextDirective implements OnChanges {
450450 const div = document . createElement ( 'div' ) ,
451451 canTreatVimeo = site && site . isVersionGreaterEqualThan ( [ '3.3.4' , '3.4' ] ) ,
452452 navCtrl = this . svComponent ? this . svComponent . getMasterNav ( ) : this . navCtrl ;
453+ const promises = [ ] ;
453454
454455 div . innerHTML = formatted ;
455456
@@ -504,7 +505,7 @@ export class CoreFormatTextDirective implements OnChanges {
504505 } ) ;
505506
506507 iframes . forEach ( ( iframe ) => {
507- this . treatIframe ( iframe , site , canTreatVimeo , navCtrl ) ;
508+ promises . push ( this . treatIframe ( iframe , site , canTreatVimeo , navCtrl ) ) ;
508509 } ) ;
509510
510511 svgImages . forEach ( ( image ) => {
@@ -543,10 +544,9 @@ export class CoreFormatTextDirective implements OnChanges {
543544 this . domUtils . handleBootstrapTooltips ( div ) ;
544545
545546 // Wait for images to load.
546- let promise : Promise < any > = null ;
547547 if ( externalImages . length ) {
548548 // Automatically reject the promise after 5 seconds to prevent blocking the user forever.
549- promise = this . utils . timeoutPromise ( this . utils . allPromises ( externalImages . map ( ( externalImage ) : any => {
549+ promises . push ( this . utils . timeoutPromise ( this . utils . allPromises ( externalImages . map ( ( externalImage ) : any => {
550550 if ( externalImage . loaded ) {
551551 // Image has already been loaded, no need to wait.
552552 return Promise . resolve ( ) ;
@@ -558,12 +558,10 @@ export class CoreFormatTextDirective implements OnChanges {
558558 resolve ( ) ;
559559 } ) ;
560560 } ) ;
561- } ) ) , 5000 ) ;
562- } else {
563- promise = Promise . resolve ( ) ;
561+ } ) ) , 5000 ) ) ;
564562 }
565563
566- return promise . catch ( ( ) => {
564+ return Promise . all ( promises ) . catch ( ( ) => {
567565 // Ignore errors. So content gets always shown.
568566 } ) . then ( ( ) => {
569567 result . div = div ;
@@ -665,23 +663,28 @@ export class CoreFormatTextDirective implements OnChanges {
665663 * @param canTreatVimeo Whether Vimeo videos can be treated in the site.
666664 * @param navCtrl NavController to use.
667665 */
668- protected treatIframe ( iframe : HTMLIFrameElement , site : CoreSite , canTreatVimeo : boolean , navCtrl : NavController ) : void {
666+ protected async treatIframe ( iframe : HTMLIFrameElement , site : CoreSite , canTreatVimeo : boolean , navCtrl : NavController )
667+ : Promise < void > {
669668 const src = iframe . src ,
670669 currentSite = this . sitesProvider . getCurrentSite ( ) ;
671670
672671 this . addMediaAdaptClass ( iframe ) ;
673672
674673 if ( currentSite && currentSite . containsUrl ( src ) ) {
675674 // URL points to current site, try to use auto-login.
676- currentSite . getAutoLoginUrl ( src , false ) . then ( ( finalUrl ) => {
677- iframe . src = finalUrl ;
675+ const finalUrl = await currentSite . getAutoLoginUrl ( src , false ) ;
678676
679- this . iframeUtils . treatFrame ( iframe , false , navCtrl ) ;
680- } ) ;
677+ await this . iframeUtils . fixIframeCookies ( finalUrl ) ;
678+
679+ iframe . src = finalUrl ;
680+
681+ this . iframeUtils . treatFrame ( iframe , false , navCtrl ) ;
681682
682683 return ;
683684 }
684685
686+ await this . iframeUtils . fixIframeCookies ( src ) ;
687+
685688 if ( src && canTreatVimeo ) {
686689 // Check if it's a Vimeo video. If it is, use the wsplayer script instead to make restricted videos work.
687690 const matches = iframe . src . match ( / h t t p s ? : \/ \/ p l a y e r \. v i m e o \. c o m \/ v i d e o \/ ( [ 0 - 9 ] + ) / ) ;
@@ -714,6 +717,9 @@ export class CoreFormatTextDirective implements OnChanges {
714717 if ( site && ! site . isVersionGreaterEqualThan ( '3.7' ) ) {
715718 newUrl += '&width=' + width + '&height=' + height ;
716719 }
720+
721+ await this . iframeUtils . fixIframeCookies ( newUrl ) ;
722+
717723 iframe . src = newUrl ;
718724
719725 if ( ! iframe . width ) {
0 commit comments