@@ -84,6 +84,12 @@ const NetFilteringResultCache = class {
84
84
this . hash = now ;
85
85
}
86
86
87
+ forgetResult ( fctxt ) {
88
+ const key = `${ fctxt . getDocHostname ( ) } ${ fctxt . type } ${ fctxt . url } ` ;
89
+ this . results . delete ( key ) ;
90
+ this . blocked . delete ( key ) ;
91
+ }
92
+
87
93
empty ( ) {
88
94
this . blocked . clear ( ) ;
89
95
this . results . clear ( ) ;
@@ -165,6 +171,7 @@ const FrameStore = class {
165
171
init ( frameURL ) {
166
172
this . t0 = Date . now ( ) ;
167
173
this . exceptCname = undefined ;
174
+ this . clickToLoad = 0 ;
168
175
this . rawURL = frameURL ;
169
176
if ( frameURL !== undefined ) {
170
177
this . hostname = vAPI . hostnameFromURI ( frameURL ) ;
@@ -253,7 +260,7 @@ const PageStore = class {
253
260
254
261
this . frameAddCount = 0 ;
255
262
this . frames = new Map ( ) ;
256
- this . setFrame ( 0 , tabContext . rawURL ) ;
263
+ this . setFrameURL ( 0 , tabContext . rawURL ) ;
257
264
258
265
// The current filtering context is cloned because:
259
266
// - We may be called with or without the current context having been
@@ -308,7 +315,7 @@ const PageStore = class {
308
315
// As part of https://github.com/chrisaljoudi/uBlock/issues/405
309
316
// URL changed, force a re-evaluation of filtering switch
310
317
this . rawURL = tabContext . rawURL ;
311
- this . setFrame ( 0 , this . rawURL ) ;
318
+ this . setFrameURL ( 0 , this . rawURL ) ;
312
319
return this ;
313
320
}
314
321
@@ -353,20 +360,23 @@ const PageStore = class {
353
360
this . frames . clear ( ) ;
354
361
}
355
362
356
- getFrame ( frameId ) {
363
+ getFrameStore ( frameId ) {
357
364
return this . frames . get ( frameId ) || null ;
358
365
}
359
366
360
- setFrame ( frameId , frameURL ) {
361
- const frameStore = this . frames . get ( frameId ) ;
367
+ setFrameURL ( frameId , frameURL ) {
368
+ let frameStore = this . frames . get ( frameId ) ;
362
369
if ( frameStore !== undefined ) {
363
370
frameStore . init ( frameURL ) ;
364
- return ;
371
+ } else {
372
+ frameStore = FrameStore . factory ( frameURL ) ;
373
+ this . frames . set ( frameId , frameStore ) ;
374
+ this . frameAddCount += 1 ;
375
+ if ( ( this . frameAddCount & 0b111111 ) === 0 ) {
376
+ this . pruneFrames ( ) ;
377
+ }
365
378
}
366
- this . frames . set ( frameId , FrameStore . factory ( frameURL ) ) ;
367
- this . frameAddCount += 1 ;
368
- if ( ( this . frameAddCount & 0b111111 ) !== 0 ) { return ; }
369
- this . pruneFrames ( ) ;
379
+ return frameStore ;
370
380
}
371
381
372
382
// There is no event to tell us a specific subframe has been removed from
@@ -597,6 +607,22 @@ const PageStore = class {
597
607
}
598
608
}
599
609
610
+ // Click-to-load:
611
+ // When frameId is not -1, the resource is always sub_frame.
612
+ if ( result === 1 && fctxt . frameId !== - 1 ) {
613
+ const docStore = this . getFrameStore ( fctxt . frameId ) ;
614
+ if ( docStore !== null && docStore . clickToLoad !== 0 ) {
615
+ result = 2 ;
616
+ if ( µb . logger . enabled ) {
617
+ fctxt . setFilter ( {
618
+ result,
619
+ source : 'network' ,
620
+ raw : 'click-to-load' ,
621
+ } ) ;
622
+ }
623
+ }
624
+ }
625
+
600
626
if ( cacheableResult ) {
601
627
this . netFilteringCache . rememberResult ( fctxt , result ) ;
602
628
} else if (
@@ -696,11 +722,19 @@ const PageStore = class {
696
722
return 1 ;
697
723
}
698
724
725
+ clickToLoad ( frameId , frameURL ) {
726
+ let frameStore = this . getFrameStore ( frameId ) ;
727
+ if ( frameStore === null ) {
728
+ frameStore = this . setFrameURL ( frameId , frameURL ) ;
729
+ }
730
+ frameStore . clickToLoad = Date . now ( ) ;
731
+ }
732
+
699
733
shouldExceptCname ( fctxt ) {
700
734
let exceptCname ;
701
735
let frameStore ;
702
736
if ( fctxt . docId !== undefined ) {
703
- frameStore = this . getFrame ( fctxt . docId ) ;
737
+ frameStore = this . getFrameStore ( fctxt . docId ) ;
704
738
if ( frameStore instanceof Object ) {
705
739
exceptCname = frameStore . exceptCname ;
706
740
}
@@ -742,17 +776,24 @@ const PageStore = class {
742
776
// content script-side (i.e. `iframes` -- unlike `img`).
743
777
if ( Array . isArray ( resources ) && resources . length !== 0 ) {
744
778
for ( const resource of resources ) {
745
- this . filterRequest (
746
- fctxt . setType ( resource . type )
747
- . setURL ( resource . url )
779
+ const result = this . filterRequest (
780
+ fctxt . setType ( resource . type ) . setURL ( resource . url )
748
781
) ;
782
+ if ( result === 1 && µb . redirectEngine . toURL ( fctxt ) ) {
783
+ this . forgetBlockedResource ( fctxt ) ;
784
+ }
749
785
}
750
786
}
751
787
if ( this . netFilteringCache . hash === response . hash ) { return ; }
752
788
response . hash = this . netFilteringCache . hash ;
753
789
response . blockedResources =
754
790
this . netFilteringCache . lookupAllBlocked ( fctxt . getDocHostname ( ) ) ;
755
791
}
792
+
793
+ forgetBlockedResource ( fctxt ) {
794
+ if ( this . collapsibleResources . has ( fctxt . type ) === false ) { return ; }
795
+ this . netFilteringCache . forgetResult ( fctxt ) ;
796
+ }
756
797
} ;
757
798
758
799
PageStore . prototype . cacheableResults = new Set ( [
0 commit comments