@@ -11,50 +11,38 @@ const { XPCOMUtils } = ChromeUtils.import(
11
11
) ;
12
12
13
13
XPCOMUtils . defineLazyModuleGetters ( this , {
14
- Preferences : "resource://gre/modules/Preferences.jsm" ,
15
14
Services : "resource://gre/modules/Services.jsm" ,
16
15
17
16
CDP : "chrome://remote/content/cdp/CDP.jsm" ,
18
17
HttpServer : "chrome://remote/content/server/HTTPD.jsm" ,
19
18
Log : "chrome://remote/content/shared/Log.jsm" ,
20
- WebDriverBiDi : "chrome ://remote/content/webdriver-bidi/WebDriverBiDi .jsm" ,
19
+ Preferences : "resource ://gre/modules/Preferences .jsm" ,
21
20
} ) ;
22
21
23
22
XPCOMUtils . defineLazyGetter ( this , "logger" , ( ) => Log . get ( ) ) ;
24
23
25
- XPCOMUtils . defineLazyGetter ( this , "activeProtocols" , ( ) => {
26
- const protocols = Services . prefs . getIntPref ( "remote.active-protocols" ) ;
27
- if ( protocols < 1 || protocols > 3 ) {
28
- throw Error ( `Invalid remote protocol identifier: ${ protocols } ` ) ;
29
- }
30
-
31
- return protocols ;
32
- } ) ;
24
+ const PREF_ACTIVE_PROTOCOLS = "remote.active-protocols" ;
25
+ const PREF_FORCE_LOCAL = "remote.force-local" ;
33
26
34
- const WEBDRIVER_BIDI_ACTIVE = 0x1 ;
27
+ // const BIDI_ACTIVE = 0x1;
35
28
const CDP_ACTIVE = 0x2 ;
36
29
37
- // By default force local connections only
38
30
const LOOPBACKS = [ "localhost" , "127.0.0.1" , "[::1]" ] ;
39
- const PREF_FORCE_LOCAL = "remote.force-local" ;
40
31
41
32
class RemoteAgentClass {
42
33
constructor ( ) {
34
+ this . cdp = null ;
43
35
this . server = null ;
44
36
45
- if ( ( activeProtocols & WEBDRIVER_BIDI_ACTIVE ) === WEBDRIVER_BIDI_ACTIVE ) {
46
- this . webdriverBiDi = new WebDriverBiDi ( this ) ;
47
- logger . debug ( "WebDriver BiDi enabled" ) ;
48
- } else {
49
- this . webdriverBiDi = null ;
37
+ const protocols = Services . prefs . getIntPref ( PREF_ACTIVE_PROTOCOLS ) ;
38
+ if ( protocols < 1 || protocols > 3 ) {
39
+ throw Error ( `Invalid remote protocol identifier: ${ protocols } ` ) ;
50
40
}
41
+ this . activeProtocols = protocols ;
42
+ }
51
43
52
- if ( ( activeProtocols & CDP_ACTIVE ) === CDP_ACTIVE ) {
53
- this . cdp = new CDP ( this ) ;
54
- logger . debug ( "CDP enabled" ) ;
55
- } else {
56
- this . cdp = null ;
57
- }
44
+ get listening ( ) {
45
+ return ! ! this . server && ! this . server . isStopped ( ) ;
58
46
}
59
47
60
48
get debuggerAddress ( ) {
@@ -65,26 +53,6 @@ class RemoteAgentClass {
65
53
return `${ this . host } :${ this . port } ` ;
66
54
}
67
55
68
- get host ( ) {
69
- // Bug 1675471: When using the nsIRemoteAgent interface the HTTPd server's
70
- // primary identity ("this.server.identity.primaryHost") is lazily set.
71
- return this . server ?. _host ;
72
- }
73
-
74
- get listening ( ) {
75
- return ! ! this . server && ! this . server . isStopped ( ) ;
76
- }
77
-
78
- get port ( ) {
79
- // Bug 1675471: When using the nsIRemoteAgent interface the HTTPd server's
80
- // primary identity ("this.server.identity.primaryPort") is lazily set.
81
- return this . server ?. _port ;
82
- }
83
-
84
- get scheme ( ) {
85
- return this . server ?. identity . primaryScheme ;
86
- }
87
-
88
56
listen ( url ) {
89
57
if ( Services . appinfo . processType != Ci . nsIXULRuntime . PROCESS_TYPE_DEFAULT ) {
90
58
throw Components . Exception (
@@ -116,6 +84,10 @@ class RemoteAgentClass {
116
84
117
85
this . server = new HttpServer ( ) ;
118
86
87
+ if ( ( this . activeProtocols & CDP_ACTIVE ) === CDP_ACTIVE ) {
88
+ this . cdp = new CDP ( this . server ) ;
89
+ }
90
+
119
91
return this . asyncListen ( host , port ) ;
120
92
}
121
93
@@ -124,7 +96,6 @@ class RemoteAgentClass {
124
96
this . server . _start ( port , host ) ;
125
97
126
98
await this . cdp ?. start ( ) ;
127
- await this . webdriverBiDi ?. start ( ) ;
128
99
} catch ( e ) {
129
100
await this . close ( ) ;
130
101
logger . error ( `Unable to start remote agent: ${ e . message } ` , e ) ;
@@ -136,7 +107,6 @@ class RemoteAgentClass {
136
107
// Stop the CDP support before stopping the server.
137
108
// Otherwise the HTTP server will fail to stop.
138
109
this . cdp ?. stop ( ) ;
139
- this . webdriverBiDi ?. stop ( ) ;
140
110
141
111
if ( this . listening ) {
142
112
return this . server . stop ( ) ;
@@ -145,12 +115,40 @@ class RemoteAgentClass {
145
115
// this function must never fail
146
116
logger . error ( "unable to stop listener" , e ) ;
147
117
} finally {
118
+ this . cdp = null ;
148
119
this . server = null ;
149
120
}
150
121
151
122
return Promise . resolve ( ) ;
152
123
}
153
124
125
+ get scheme ( ) {
126
+ if ( ! this . server ) {
127
+ return null ;
128
+ }
129
+ return this . server . identity . primaryScheme ;
130
+ }
131
+
132
+ get host ( ) {
133
+ if ( ! this . server ) {
134
+ return null ;
135
+ }
136
+
137
+ // Bug 1675471: When using the nsIRemoteAgent interface the HTTPd server's
138
+ // primary identity ("this.server.identity.primaryHost") is lazily set.
139
+ return this . server . _host ;
140
+ }
141
+
142
+ get port ( ) {
143
+ if ( ! this . server ) {
144
+ return null ;
145
+ }
146
+
147
+ // Bug 1675471: When using the nsIRemoteAgent interface the HTTPd server's
148
+ // primary identity ("this.server.identity.primaryPort") is lazily set.
149
+ return this . server . _port ;
150
+ }
151
+
154
152
// XPCOM
155
153
156
154
get QueryInterface ( ) {
0 commit comments