@@ -588,19 +588,31 @@ class Frame extends ImmutableComponent {
588
588
589
589
addEventListeners ( ) {
590
590
this . webview . addEventListener ( 'content-blocked' , ( e ) => {
591
+ if ( this . frame . isEmpty ( ) ) {
592
+ return
593
+ }
591
594
if ( e . details [ 0 ] === 'javascript' && e . details [ 1 ] ) {
592
595
windowActions . setBlockedBy ( this . frame , 'noScript' , e . details [ 1 ] )
593
596
}
594
597
} )
595
598
this . webview . addEventListener ( 'did-block-run-insecure-content' , ( e ) => {
599
+ if ( this . frame . isEmpty ( ) ) {
600
+ return
601
+ }
596
602
windowActions . setBlockedRunInsecureContent ( this . frame , e . details [ 0 ] )
597
603
} )
598
604
this . webview . addEventListener ( 'enable-pepper-menu' , ( e ) => {
605
+ if ( this . frame . isEmpty ( ) ) {
606
+ return
607
+ }
599
608
contextMenus . onFlashContextMenu ( e . params , this . frame )
600
609
e . preventDefault ( )
601
610
e . stopPropagation ( )
602
611
} )
603
612
this . webview . addEventListener ( 'context-menu' , ( e ) => {
613
+ if ( this . frame . isEmpty ( ) ) {
614
+ return
615
+ }
604
616
contextMenus . onMainContextMenu ( e . params , this . frame )
605
617
e . preventDefault ( )
606
618
e . stopPropagation ( )
@@ -616,6 +628,9 @@ class Frame extends ImmutableComponent {
616
628
windowActions . setLinkHoverPreview ( e . url , showOnRight )
617
629
} )
618
630
this . webview . addEventListener ( 'set-active' , ( e ) => {
631
+ if ( this . frame . isEmpty ( ) ) {
632
+ return
633
+ }
619
634
if ( e . active && currentWindow . isFocused ( ) ) {
620
635
windowActions . setFocusedFrame ( this . frame )
621
636
}
@@ -631,31 +646,49 @@ class Frame extends ImmutableComponent {
631
646
currentWindow . webContents . send ( messages . DISABLE_SWIPE_GESTURE )
632
647
} )
633
648
this . webview . addEventListener ( 'did-attach' , ( e ) => {
649
+ if ( this . frame . isEmpty ( ) ) {
650
+ return
651
+ }
634
652
let tabId = this . webview . getId ( )
635
653
if ( this . props . tabId !== tabId ) {
636
654
windowActions . setFrameTabId ( this . frame , tabId )
637
655
}
638
656
} )
639
657
this . webview . addEventListener ( 'destroyed' , ( e ) => {
658
+ if ( this . frame . isEmpty ( ) ) {
659
+ return
660
+ }
640
661
this . props . onCloseFrame ( this . frame )
641
662
} )
642
663
this . webview . addEventListener ( 'close' , ( ) => {
664
+ if ( this . frame . isEmpty ( ) ) {
665
+ return
666
+ }
643
667
this . props . onCloseFrame ( this . frame )
644
668
} )
645
669
this . webview . addEventListener ( 'page-favicon-updated' , ( e ) => {
670
+ if ( this . frame . isEmpty ( ) ) {
671
+ return
672
+ }
646
673
if ( e . favicons && e . favicons . length > 0 ) {
647
674
imageUtil . getWorkingImageUrl ( e . favicons [ 0 ] , ( imageFound ) => {
648
675
windowActions . setFavicon ( this . frame , imageFound ? e . favicons [ 0 ] : null )
649
676
} )
650
677
}
651
678
} )
652
679
this . webview . addEventListener ( 'page-title-updated' , ( { title} ) => {
680
+ if ( this . frame . isEmpty ( ) ) {
681
+ return
682
+ }
653
683
windowActions . setFrameTitle ( this . frame , title )
654
684
} )
655
685
this . webview . addEventListener ( 'show-autofill-settings' , ( e ) => {
656
686
windowActions . newFrame ( { location : 'about:autofill' } , true )
657
687
} )
658
688
this . webview . addEventListener ( 'show-autofill-popup' , ( e ) => {
689
+ if ( this . frame . isEmpty ( ) ) {
690
+ return
691
+ }
659
692
contextMenus . onShowAutofillMenu ( e . suggestions , e . rect , this . frame )
660
693
} )
661
694
this . webview . addEventListener ( 'hide-autofill-popup' , ( e ) => {
@@ -670,16 +703,25 @@ class Frame extends ImmutableComponent {
670
703
this . updateAboutDetails ( )
671
704
break
672
705
case messages . GOT_CANVAS_FINGERPRINTING :
706
+ if ( this . frame . isEmpty ( ) ) {
707
+ return
708
+ }
673
709
method = ( detail ) => {
674
710
const description = [ detail . type , detail . scriptUrl || this . props . provisionalLocation ] . join ( ': ' )
675
711
windowActions . setBlockedBy ( this . frame , 'fingerprintingProtection' , description )
676
712
}
677
713
break
678
714
case messages . THEME_COLOR_COMPUTED :
715
+ if ( this . frame . isEmpty ( ) ) {
716
+ return
717
+ }
679
718
method = ( computedThemeColor ) =>
680
719
windowActions . setThemeColor ( this . frame , undefined , computedThemeColor || null )
681
720
break
682
721
case messages . CONTEXT_MENU_OPENED :
722
+ if ( this . frame . isEmpty ( ) ) {
723
+ return
724
+ }
683
725
method = ( nodeProps , contextMenuType ) => {
684
726
contextMenus . onMainContextMenu ( nodeProps , this . frame , contextMenuType )
685
727
}
@@ -719,6 +761,9 @@ class Frame extends ImmutableComponent {
719
761
} )
720
762
721
763
const loadStart = ( e ) => {
764
+ if ( this . frame . isEmpty ( ) ) {
765
+ return
766
+ }
722
767
if ( e . isMainFrame && ! e . isErrorPage && ! e . isFrameSrcDoc ) {
723
768
windowActions . onWebviewLoadStart ( this . frame , e . url )
724
769
// Clear security state
@@ -731,6 +776,9 @@ class Frame extends ImmutableComponent {
731
776
}
732
777
733
778
const loadEnd = ( savePage ) => {
779
+ if ( this . frame . isEmpty ( ) ) {
780
+ return
781
+ }
734
782
windowActions . onWebviewLoadEnd (
735
783
this . frame ,
736
784
this . webview . getURL ( ) )
@@ -764,6 +812,9 @@ class Frame extends ImmutableComponent {
764
812
}
765
813
766
814
const loadFail = ( e , provisionLoadFailure = false ) => {
815
+ if ( this . frame . isEmpty ( ) ) {
816
+ return
817
+ }
767
818
if ( isFrameError ( e . errorCode ) ) {
768
819
// temporary workaround for https://github.com/brave/browser-laptop/issues/1817
769
820
if ( e . validatedURL === aboutUrls . get ( 'about:newtab' ) ||
@@ -794,6 +845,9 @@ class Frame extends ImmutableComponent {
794
845
}
795
846
}
796
847
this . webview . addEventListener ( 'security-style-changed' , ( e ) => {
848
+ if ( this . frame . isEmpty ( ) ) {
849
+ return
850
+ }
797
851
let isSecure = null
798
852
let runInsecureContent = this . runInsecureContent ( )
799
853
// 'warning' and 'passive mixed content' should never upgrade the
@@ -835,18 +889,25 @@ class Frame extends ImmutableComponent {
835
889
if ( this . props . isActive && ! isNewTabPage && document . activeElement !== this . webview ) {
836
890
this . webview . focus ( )
837
891
}
838
- windowActions . setNavigated ( e . url , this . props . frameKey , false , this . frame . get ( 'tabId' ) )
892
+ if ( ! this . frame . isEmpty ( ) ) {
893
+ windowActions . setNavigated ( e . url , this . props . frameKey , false , this . frame . get ( 'tabId' ) )
894
+ }
839
895
// force temporary url display for tabnapping protection
840
896
windowActions . setMouseInTitlebar ( true )
841
897
842
898
// After navigating to the URL via back/forward buttons, set correct frame title
843
899
if ( ! e . isRendererInitiated ) {
844
900
let index = this . webview . getCurrentEntryIndex ( )
845
901
let title = this . webview . getTitleAtIndex ( index )
846
- windowActions . setFrameTitle ( this . frame , title )
902
+ if ( ! this . frame . isEmpty ( ) ) {
903
+ windowActions . setFrameTitle ( this . frame , title )
904
+ }
847
905
}
848
906
} )
849
907
this . webview . addEventListener ( 'crashed' , ( e ) => {
908
+ if ( this . frame . isEmpty ( ) ) {
909
+ return
910
+ }
850
911
windowActions . setFrameError ( this . frame , {
851
912
event_type : 'crashed' ,
852
913
title : 'unexpectedError' ,
@@ -874,33 +935,54 @@ class Frame extends ImmutableComponent {
874
935
}
875
936
} )
876
937
this . webview . addEventListener ( 'did-navigate-in-page' , ( e ) => {
938
+ if ( this . frame . isEmpty ( ) ) {
939
+ return
940
+ }
877
941
if ( e . isMainFrame ) {
878
942
windowActions . setNavigated ( e . url , this . props . frameKey , true , this . frame . get ( 'tabId' ) )
879
943
loadEnd ( true )
880
944
}
881
945
} )
882
946
this . webview . addEventListener ( 'enter-html-full-screen' , ( ) => {
947
+ if ( this . frame . isEmpty ( ) ) {
948
+ return
949
+ }
883
950
windowActions . setFullScreen ( this . frame , true , true )
884
951
// disable the fullscreen warning after 5 seconds
885
952
setTimeout ( windowActions . setFullScreen . bind ( this , this . frame , undefined , false ) , 5000 )
886
953
} )
887
954
this . webview . addEventListener ( 'leave-html-full-screen' , ( ) => {
955
+ if ( this . frame . isEmpty ( ) ) {
956
+ return
957
+ }
888
958
windowActions . setFullScreen ( this . frame , false )
889
959
} )
890
960
this . webview . addEventListener ( 'media-started-playing' , ( { title} ) => {
961
+ if ( this . frame . isEmpty ( ) ) {
962
+ return
963
+ }
891
964
windowActions . setAudioPlaybackActive ( this . frame , true )
892
965
} )
893
966
this . webview . addEventListener ( 'media-paused' , ( { title} ) => {
967
+ if ( this . frame . isEmpty ( ) ) {
968
+ return
969
+ }
894
970
windowActions . setAudioPlaybackActive ( this . frame , false )
895
971
} )
896
972
this . webview . addEventListener ( 'did-change-theme-color' , ( { themeColor} ) => {
973
+ if ( this . frame . isEmpty ( ) ) {
974
+ return
975
+ }
897
976
// Due to a bug in Electron, after navigating to a page with a theme color
898
977
// to a page without a theme color, the background is sent to us as black
899
978
// even know there is no background. To work around this we just ignore
900
979
// the theme color in that case and let the computed theme color take over.
901
980
windowActions . setThemeColor ( this . frame , themeColor !== '#000000' ? themeColor : null )
902
981
} )
903
982
this . webview . addEventListener ( 'found-in-page' , ( e ) => {
983
+ if ( this . frame . isEmpty ( ) ) {
984
+ return
985
+ }
904
986
if ( e . result !== undefined && ( e . result . matches !== undefined || e . result . activeMatchOrdinal !== undefined ) ) {
905
987
if ( e . result . matches === 0 ) {
906
988
windowActions . setFindDetail ( this . frame , Immutable . fromJS ( {
@@ -916,6 +998,9 @@ class Frame extends ImmutableComponent {
916
998
}
917
999
} )
918
1000
this . webview . addEventListener ( 'did-get-response-details' , ( details ) => {
1001
+ if ( this . frame . isEmpty ( ) ) {
1002
+ return
1003
+ }
919
1004
windowActions . gotResponseDetails ( this . frame . get ( 'tabId' ) , details )
920
1005
} )
921
1006
// Handle zoom using Ctrl/Cmd and the mouse wheel.
@@ -982,7 +1067,9 @@ class Frame extends ImmutableComponent {
982
1067
}
983
1068
984
1069
onFocus ( ) {
985
- windowActions . setTabPageIndexByFrame ( this . frame )
1070
+ if ( ! this . frame . isEmpty ( ) ) {
1071
+ windowActions . setTabPageIndexByFrame ( this . frame )
1072
+ }
986
1073
987
1074
// Make sure urlBar focused state is updated so that on tab
988
1075
// changes the focus state doesn't go back to the urlBar
0 commit comments