@@ -49,65 +49,6 @@ class WorkerData {
49
49
}
50
50
}
51
51
52
- class FrameData {
53
- constructor ( agent , runtime , frame ) {
54
- this . _agent = agent ;
55
- this . _runtime = runtime ;
56
- this . _frame = frame ;
57
- this . _isolatedWorlds = new Map ( ) ;
58
- this . _initialNavigationDone = false ;
59
- this . reset ( ) ;
60
- }
61
-
62
- reset ( ) {
63
- for ( const world of this . _isolatedWorlds . values ( ) )
64
- this . _runtime . destroyExecutionContext ( world ) ;
65
- this . _isolatedWorlds . clear ( ) ;
66
-
67
- for ( const { script, worldName} of this . _agent . _isolatedWorlds . values ( ) ) {
68
- const context = worldName ? this . createIsolatedWorld ( worldName ) : this . _frame . executionContext ( ) ;
69
- try {
70
- let result = context . evaluateScript ( script ) ;
71
- if ( result && result . objectId )
72
- context . disposeObject ( result . objectId ) ;
73
- } catch ( e ) {
74
- }
75
- }
76
- }
77
-
78
- createIsolatedWorld ( name ) {
79
- const principal = [ this . _frame . domWindow ( ) ] ; // extended principal
80
- const sandbox = Cu . Sandbox ( principal , {
81
- sandboxPrototype : this . _frame . domWindow ( ) ,
82
- wantComponents : false ,
83
- wantExportHelpers : false ,
84
- wantXrays : true ,
85
- } ) ;
86
- const world = this . _runtime . createExecutionContext ( this . _frame . domWindow ( ) , sandbox , {
87
- frameId : this . _frame . id ( ) ,
88
- name,
89
- } ) ;
90
- this . _isolatedWorlds . set ( world . id ( ) , world ) ;
91
- return world ;
92
- }
93
-
94
- unsafeObject ( objectId ) {
95
- const contexts = [ this . _frame . executionContext ( ) , ...this . _isolatedWorlds . values ( ) ] ;
96
- for ( const context of contexts ) {
97
- const result = context . unsafeObject ( objectId ) ;
98
- if ( result )
99
- return result . object ;
100
- }
101
- throw new Error ( 'Cannot find object with id = ' + objectId ) ;
102
- }
103
-
104
- dispose ( ) {
105
- for ( const world of this . _isolatedWorlds . values ( ) )
106
- this . _runtime . destroyExecutionContext ( world ) ;
107
- this . _isolatedWorlds . clear ( ) ;
108
- }
109
- }
110
-
111
52
class PageAgent {
112
53
constructor ( messageManager , browserChannel , frameTree ) {
113
54
this . _messageManager = messageManager ;
@@ -116,10 +57,7 @@ class PageAgent {
116
57
this . _frameTree = frameTree ;
117
58
this . _runtime = frameTree . runtime ( ) ;
118
59
119
- this . _frameData = new Map ( ) ;
120
60
this . _workerData = new Map ( ) ;
121
- this . _scriptsToEvaluateOnNewDocument = new Map ( ) ;
122
- this . _isolatedWorlds = new Map ( ) ;
123
61
124
62
const docShell = frameTree . mainFrame ( ) . docShell ( ) ;
125
63
this . _docShell = docShell ;
@@ -169,7 +107,6 @@ class PageAgent {
169
107
helper . on ( this . _frameTree , 'bindingcalled' , this . _onBindingCalled . bind ( this ) ) ,
170
108
helper . on ( this . _frameTree , 'frameattached' , this . _onFrameAttached . bind ( this ) ) ,
171
109
helper . on ( this . _frameTree , 'framedetached' , this . _onFrameDetached . bind ( this ) ) ,
172
- helper . on ( this . _frameTree , 'globalobjectcreated' , this . _onGlobalObjectCreated . bind ( this ) ) ,
173
110
helper . on ( this . _frameTree , 'navigationstarted' , this . _onNavigationStarted . bind ( this ) ) ,
174
111
helper . on ( this . _frameTree , 'navigationcommitted' , this . _onNavigationCommitted . bind ( this ) ) ,
175
112
helper . on ( this . _frameTree , 'navigationaborted' , this . _onNavigationAborted . bind ( this ) ) ,
@@ -198,7 +135,7 @@ class PageAgent {
198
135
this . _runtime . events . onExecutionContextDestroyed ( this . _onExecutionContextDestroyed . bind ( this ) ) ,
199
136
browserChannel . register ( 'page' , {
200
137
addBinding : ( { name, script } ) => this . _frameTree . addBinding ( name , script ) ,
201
- addScriptToEvaluateOnNewDocument : this . _addScriptToEvaluateOnNewDocument . bind ( this ) ,
138
+ addScriptToEvaluateOnNewDocument : ( { script , worldName } ) => this . _frameTree . addScriptToEvaluateOnNewDocument ( script , worldName ) ,
202
139
adoptNode : this . _adoptNode . bind ( this ) ,
203
140
crash : this . _crash . bind ( this ) ,
204
141
describeNode : this . _describeNode . bind ( this ) ,
@@ -213,7 +150,7 @@ class PageAgent {
213
150
insertText : this . _insertText . bind ( this ) ,
214
151
navigate : this . _navigate . bind ( this ) ,
215
152
reload : this . _reload . bind ( this ) ,
216
- removeScriptToEvaluateOnNewDocument : this . _removeScriptToEvaluateOnNewDocument . bind ( this ) ,
153
+ removeScriptToEvaluateOnNewDocument : ( { scriptId } ) => this . _frameTree . removeScriptToEvaluateOnNewDocument ( scriptId ) ,
217
154
screenshot : this . _screenshot . bind ( this ) ,
218
155
scrollIntoViewIfNeeded : this . _scrollIntoViewIfNeeded . bind ( this ) ,
219
156
setCacheDisabled : this . _setCacheDisabled . bind ( this ) ,
@@ -227,27 +164,6 @@ class PageAgent {
227
164
] ;
228
165
}
229
166
230
- _addScriptToEvaluateOnNewDocument ( { script, worldName} ) {
231
- if ( worldName )
232
- return this . _createIsolatedWorld ( { script, worldName} ) ;
233
- return { scriptId : this . _frameTree . addScriptToEvaluateOnNewDocument ( script ) } ;
234
- }
235
-
236
- _createIsolatedWorld ( { script, worldName} ) {
237
- const scriptId = helper . generateId ( ) ;
238
- this . _isolatedWorlds . set ( scriptId , { script, worldName} ) ;
239
- for ( const frameData of this . _frameData . values ( ) )
240
- frameData . createIsolatedWorld ( worldName ) ;
241
- return { scriptId} ;
242
- }
243
-
244
- _removeScriptToEvaluateOnNewDocument ( { scriptId} ) {
245
- if ( this . _isolatedWorlds . has ( scriptId ) )
246
- this . _isolatedWorlds . delete ( scriptId ) ;
247
- else
248
- this . _frameTree . removeScriptToEvaluateOnNewDocument ( scriptId ) ;
249
- }
250
-
251
167
_setCacheDisabled ( { cacheDisabled} ) {
252
168
const enable = Ci . nsIRequest . LOAD_NORMAL ;
253
169
const disable = Ci . nsIRequest . LOAD_BYPASS_CACHE |
@@ -333,16 +249,16 @@ class PageAgent {
333
249
_filePickerShown ( inputElement ) {
334
250
if ( inputElement . ownerGlobal . docShell !== this . _docShell )
335
251
return ;
336
- const frameData = this . _findFrameForNode ( inputElement ) ;
252
+ const frame = this . _findFrameForNode ( inputElement ) ;
337
253
this . _browserPage . emit ( 'pageFileChooserOpened' , {
338
- executionContextId : frameData . _frame . executionContext ( ) . id ( ) ,
339
- element : frameData . _frame . executionContext ( ) . rawValueToRemoteObject ( inputElement )
254
+ executionContextId : frame . executionContext ( ) . id ( ) ,
255
+ element : frame . executionContext ( ) . rawValueToRemoteObject ( inputElement )
340
256
} ) ;
341
257
}
342
258
343
259
_findFrameForNode ( node ) {
344
- return Array . from ( this . _frameData . values ( ) ) . find ( data => {
345
- const doc = data . _frame . domWindow ( ) . document ;
260
+ return this . _frameTree . frames ( ) . find ( frame => {
261
+ const doc = frame . domWindow ( ) . document ;
346
262
return node === doc || node . ownerDocument === doc ;
347
263
} ) ;
348
264
}
@@ -404,10 +320,9 @@ class PageAgent {
404
320
navigationId,
405
321
errorText,
406
322
} ) ;
407
- const frameData = this . _frameData . get ( frame ) ;
408
- if ( ! frameData . _initialNavigationDone && frame !== this . _frameTree . mainFrame ( ) )
323
+ if ( ! frame . _initialNavigationDone && frame !== this . _frameTree . mainFrame ( ) )
409
324
this . _emitAllEvents ( frame ) ;
410
- frameData . _initialNavigationDone = true ;
325
+ frame . _initialNavigationDone = true ;
411
326
}
412
327
413
328
_onSameDocumentNavigation ( frame ) {
@@ -424,23 +339,17 @@ class PageAgent {
424
339
url : frame . url ( ) ,
425
340
name : frame . name ( ) ,
426
341
} ) ;
427
- this . _frameData . get ( frame ) . _initialNavigationDone = true ;
428
- }
429
-
430
- _onGlobalObjectCreated ( { frame } ) {
431
- this . _frameData . get ( frame ) . reset ( ) ;
342
+ frame . _initialNavigationDone = true ;
432
343
}
433
344
434
345
_onFrameAttached ( frame ) {
435
346
this . _browserPage . emit ( 'pageFrameAttached' , {
436
347
frameId : frame . id ( ) ,
437
348
parentFrameId : frame . parentFrame ( ) ? frame . parentFrame ( ) . id ( ) : undefined ,
438
349
} ) ;
439
- this . _frameData . set ( frame , new FrameData ( this , this . _runtime , frame ) ) ;
440
350
}
441
351
442
352
_onFrameDetached ( frame ) {
443
- this . _frameData . delete ( frame ) ;
444
353
this . _browserPage . emit ( 'pageFrameDetached' , {
445
354
frameId : frame . id ( ) ,
446
355
} ) ;
@@ -458,9 +367,6 @@ class PageAgent {
458
367
for ( const workerData of this . _workerData . values ( ) )
459
368
workerData . dispose ( ) ;
460
369
this . _workerData . clear ( ) ;
461
- for ( const frameData of this . _frameData . values ( ) )
462
- frameData . dispose ( ) ;
463
- this . _frameData . clear ( ) ;
464
370
helper . removeListeners ( this . _eventListeners ) ;
465
371
}
466
372
@@ -525,7 +431,7 @@ class PageAgent {
525
431
const frame = this . _frameTree . frame ( frameId ) ;
526
432
if ( ! frame )
527
433
throw new Error ( 'Failed to find frame with id = ' + frameId ) ;
528
- const unsafeObject = this . _frameData . get ( frame ) . unsafeObject ( objectId ) ;
434
+ const unsafeObject = frame . unsafeObject ( objectId ) ;
529
435
const context = this . _runtime . findExecutionContext ( executionContextId ) ;
530
436
const fromPrincipal = unsafeObject . nodePrincipal ;
531
437
const toFrame = this . _frameTree . frame ( context . auxData ( ) . frameId ) ;
@@ -539,7 +445,7 @@ class PageAgent {
539
445
const frame = this . _frameTree . frame ( frameId ) ;
540
446
if ( ! frame )
541
447
throw new Error ( 'Failed to find frame with id = ' + frameId ) ;
542
- const unsafeObject = this . _frameData . get ( frame ) . unsafeObject ( objectId ) ;
448
+ const unsafeObject = frame . unsafeObject ( objectId ) ;
543
449
if ( ! unsafeObject )
544
450
throw new Error ( 'Object is not input!' ) ;
545
451
const nsFiles = await Promise . all ( files . map ( filePath => File . createFromFileName ( filePath ) ) ) ;
@@ -550,7 +456,7 @@ class PageAgent {
550
456
const frame = this . _frameTree . frame ( frameId ) ;
551
457
if ( ! frame )
552
458
throw new Error ( 'Failed to find frame with id = ' + frameId ) ;
553
- const unsafeObject = this . _frameData . get ( frame ) . unsafeObject ( objectId ) ;
459
+ const unsafeObject = frame . unsafeObject ( objectId ) ;
554
460
if ( ! unsafeObject . getBoxQuads )
555
461
throw new Error ( 'RemoteObject is not a node' ) ;
556
462
const quads = unsafeObject . getBoxQuads ( { relativeTo : this . _frameTree . mainFrame ( ) . domWindow ( ) . document } ) . map ( quad => {
@@ -568,7 +474,7 @@ class PageAgent {
568
474
const frame = this . _frameTree . frame ( frameId ) ;
569
475
if ( ! frame )
570
476
throw new Error ( 'Failed to find frame with id = ' + frameId ) ;
571
- const unsafeObject = this . _frameData . get ( frame ) . unsafeObject ( objectId ) ;
477
+ const unsafeObject = frame . unsafeObject ( objectId ) ;
572
478
const browsingContextGroup = frame . docShell ( ) . browsingContext . group ;
573
479
const frames = this . _frameTree . allFramesInBrowsingContextGroup ( browsingContextGroup ) ;
574
480
let contentFrame ;
@@ -590,7 +496,7 @@ class PageAgent {
590
496
const frame = this . _frameTree . frame ( frameId ) ;
591
497
if ( ! frame )
592
498
throw new Error ( 'Failed to find frame with id = ' + frameId ) ;
593
- const unsafeObject = this . _frameData . get ( frame ) . unsafeObject ( objectId ) ;
499
+ const unsafeObject = frame . unsafeObject ( objectId ) ;
594
500
if ( ! unsafeObject . isConnected )
595
501
throw new Error ( 'Node is detached from document' ) ;
596
502
if ( ! rect )
@@ -877,7 +783,7 @@ class PageAgent {
877
783
async _getFullAXTree ( { objectId} ) {
878
784
let unsafeObject = null ;
879
785
if ( objectId ) {
880
- unsafeObject = this . _frameData . get ( this . _frameTree . mainFrame ( ) ) . unsafeObject ( objectId ) ;
786
+ unsafeObject = this . _frameTree . mainFrame ( ) . unsafeObject ( objectId ) ;
881
787
if ( ! unsafeObject )
882
788
throw new Error ( `No object found for id "${ objectId } "` ) ;
883
789
}
0 commit comments