| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  | /* This Source Code Form is subject to the terms of the Mozilla Public | 
					
						
							|  |  |  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | 
					
						
							|  |  |  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-07 10:24:16 -07:00
										 |  |  | const {AddonManager} = ChromeUtils.import("resource://gre/modules/AddonManager.jsm"); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  | const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); | 
					
						
							|  |  |  | const {TargetRegistry} = ChromeUtils.import("chrome://juggler/content/TargetRegistry.js"); | 
					
						
							|  |  |  | const {Helper} = ChromeUtils.import('chrome://juggler/content/Helper.js'); | 
					
						
							| 
									
										
										
										
											2020-10-02 04:13:42 -07:00
										 |  |  | const {PageHandler} = ChromeUtils.import("chrome://juggler/content/protocol/PageHandler.js"); | 
					
						
							| 
									
										
										
										
											2020-11-19 08:24:17 -08:00
										 |  |  | const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm"); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | const helper = new Helper(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BrowserHandler { | 
					
						
							|  |  |  |   constructor(session, dispatcher, targetRegistry, onclose) { | 
					
						
							|  |  |  |     this._session = session; | 
					
						
							|  |  |  |     this._dispatcher = dispatcher; | 
					
						
							|  |  |  |     this._targetRegistry = targetRegistry; | 
					
						
							|  |  |  |     this._enabled = false; | 
					
						
							|  |  |  |     this._attachToDefaultContext = false; | 
					
						
							|  |  |  |     this._eventListeners = []; | 
					
						
							|  |  |  |     this._createdBrowserContextIds = new Set(); | 
					
						
							|  |  |  |     this._attachedSessions = new Map(); | 
					
						
							|  |  |  |     this._onclose = onclose; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.enable']({attachToDefaultContext}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     if (this._enabled) | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     this._enabled = true; | 
					
						
							|  |  |  |     this._attachToDefaultContext = attachToDefaultContext; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this._eventListeners = [ | 
					
						
							|  |  |  |       helper.on(this._targetRegistry, TargetRegistry.Events.TargetCreated, this._onTargetCreated.bind(this)), | 
					
						
							| 
									
										
										
										
											2020-08-25 14:50:40 -07:00
										 |  |  |       helper.on(this._targetRegistry, TargetRegistry.Events.TargetDestroyed, this._onTargetDestroyed.bind(this)), | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |       helper.on(this._targetRegistry, TargetRegistry.Events.DownloadCreated, this._onDownloadCreated.bind(this)), | 
					
						
							|  |  |  |       helper.on(this._targetRegistry, TargetRegistry.Events.DownloadFinished, this._onDownloadFinished.bind(this)), | 
					
						
							| 
									
										
										
										
											2021-05-07 18:05:26 -07:00
										 |  |  |       helper.on(this._targetRegistry, TargetRegistry.Events.ScreencastStopped, sessionId => { | 
					
						
							|  |  |  |         this._session.emitEvent('Browser.videoRecordingFinished', {screencastId: '' + sessionId}); | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2020-08-25 14:50:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-02 04:13:42 -07:00
										 |  |  |     for (const target of this._targetRegistry.targets()) | 
					
						
							|  |  |  |       this._onTargetCreated(target); | 
					
						
							| 
									
										
										
										
											2020-10-07 10:24:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Wait to complete initialization of addon manager and search
 | 
					
						
							|  |  |  |     // service before returning from this method. Failing to do so will result
 | 
					
						
							|  |  |  |     // in a broken shutdown sequence and multiple errors in browser STDERR log.
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-10-12 22:34:04 -07:00
										 |  |  |     // NOTE: we have to put this here as well as in the `Browser.close` handler
 | 
					
						
							| 
									
										
										
										
											2020-10-07 10:24:16 -07:00
										 |  |  |     // since browser shutdown can be initiated when the last tab is closed, e.g.
 | 
					
						
							|  |  |  |     // with persistent context.
 | 
					
						
							|  |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       waitForAddonManager(), | 
					
						
							|  |  |  |       waitForSearchService(), | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.createBrowserContext']({removeOnDetach}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     if (!this._enabled) | 
					
						
							|  |  |  |       throw new Error('Browser domain is not enabled'); | 
					
						
							|  |  |  |     const browserContext = this._targetRegistry.createBrowserContext(removeOnDetach); | 
					
						
							|  |  |  |     this._createdBrowserContextIds.add(browserContext.browserContextId); | 
					
						
							|  |  |  |     return {browserContextId: browserContext.browserContextId}; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.removeBrowserContext']({browserContextId}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     if (!this._enabled) | 
					
						
							|  |  |  |       throw new Error('Browser domain is not enabled'); | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).destroy(); | 
					
						
							|  |  |  |     this._createdBrowserContextIds.delete(browserContextId); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 14:50:40 -07:00
										 |  |  |   dispose() { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     helper.removeListeners(this._eventListeners); | 
					
						
							| 
									
										
										
										
											2020-10-02 04:13:42 -07:00
										 |  |  |     for (const [target, session] of this._attachedSessions) | 
					
						
							| 
									
										
										
										
											2020-08-25 14:50:40 -07:00
										 |  |  |       this._dispatcher.destroySession(session); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._attachedSessions.clear(); | 
					
						
							|  |  |  |     for (const browserContextId of this._createdBrowserContextIds) { | 
					
						
							|  |  |  |       const browserContext = this._targetRegistry.browserContextForId(browserContextId); | 
					
						
							|  |  |  |       if (browserContext.removeOnDetach) | 
					
						
							|  |  |  |         browserContext.destroy(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     this._createdBrowserContextIds.clear(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _shouldAttachToTarget(target) { | 
					
						
							|  |  |  |     if (this._createdBrowserContextIds.has(target._browserContext.browserContextId)) | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     return this._attachToDefaultContext && target._browserContext === this._targetRegistry.defaultContext(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-02 04:13:42 -07:00
										 |  |  |   _onTargetCreated(target) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     if (!this._shouldAttachToTarget(target)) | 
					
						
							|  |  |  |       return; | 
					
						
							| 
									
										
										
										
											2020-10-02 04:13:42 -07:00
										 |  |  |     const channel = target.channel(); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     const session = this._dispatcher.createSession(); | 
					
						
							|  |  |  |     this._attachedSessions.set(target, session); | 
					
						
							|  |  |  |     this._session.emitEvent('Browser.attachedToTarget', { | 
					
						
							|  |  |  |       sessionId: session.sessionId(), | 
					
						
							|  |  |  |       targetInfo: target.info() | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |     session.setHandler(new PageHandler(target, session, channel)); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 14:50:40 -07:00
										 |  |  |   _onTargetDestroyed(target) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     const session = this._attachedSessions.get(target); | 
					
						
							|  |  |  |     if (!session) | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     this._attachedSessions.delete(target); | 
					
						
							| 
									
										
										
										
											2020-08-25 14:50:40 -07:00
										 |  |  |     this._dispatcher.destroySession(session); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._session.emitEvent('Browser.detachedFromTarget', { | 
					
						
							|  |  |  |       sessionId: session.sessionId(), | 
					
						
							|  |  |  |       targetId: target.id(), | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _onDownloadCreated(downloadInfo) { | 
					
						
							|  |  |  |     this._session.emitEvent('Browser.downloadCreated', downloadInfo); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   _onDownloadFinished(downloadInfo) { | 
					
						
							|  |  |  |     this._session.emitEvent('Browser.downloadFinished', downloadInfo); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-30 01:29:58 +02:00
										 |  |  |   async ['Browser.cancelDownload']({uuid}) { | 
					
						
							|  |  |  |     await this._targetRegistry.cancelDownload({uuid}); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.newPage']({browserContextId}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     const targetId = await this._targetRegistry.newPage({browserContextId}); | 
					
						
							|  |  |  |     return {targetId}; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.close']() { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     let browserWindow = Services.wm.getMostRecentWindow( | 
					
						
							|  |  |  |       "navigator:browser" | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     if (browserWindow && browserWindow.gBrowserInit) { | 
					
						
							| 
									
										
										
										
											2021-04-23 16:05:37 -07:00
										 |  |  |       // idleTasksFinishedPromise does not resolve when the window
 | 
					
						
							|  |  |  |       // is closed early enough, so we race against window closure.
 | 
					
						
							|  |  |  |       await Promise.race([ | 
					
						
							|  |  |  |         browserWindow.gBrowserInit.idleTasksFinishedPromise, | 
					
						
							|  |  |  |         waitForWindowClosed(browserWindow), | 
					
						
							|  |  |  |       ]); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-10-12 22:34:04 -07:00
										 |  |  |     // Try to fully initialize browser before closing.
 | 
					
						
							|  |  |  |     // See comment in `Browser.enable`.
 | 
					
						
							|  |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       waitForAddonManager(), | 
					
						
							|  |  |  |       waitForSearchService(), | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2020-08-03 20:15:25 -07:00
										 |  |  |     this._onclose(); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     Services.startup.quit(Ci.nsIAppStartup.eForceQuit); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.grantPermissions']({browserContextId, origin, permissions}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).grantPermissions(origin, permissions); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.resetPermissions']({browserContextId}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).resetPermissions(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.setExtraHTTPHeaders']({browserContextId, headers}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).extraHTTPHeaders = headers; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.setHTTPCredentials']({browserContextId, credentials}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).httpCredentials = nullToUndefined(credentials); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setBrowserProxy']({type, host, port, bypass, username, password}) { | 
					
						
							| 
									
										
										
										
											2020-08-07 15:38:06 -07:00
										 |  |  |     this._targetRegistry.setBrowserProxy({ type, host, port, bypass, username, password}); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setContextProxy']({browserContextId, type, host, port, bypass, username, password}) { | 
					
						
							| 
									
										
										
										
											2020-08-07 15:38:06 -07:00
										 |  |  |     const browserContext = this._targetRegistry.browserContextForId(browserContextId); | 
					
						
							|  |  |  |     browserContext.setProxy({ type, host, port, bypass, username, password }); | 
					
						
							| 
									
										
										
										
											2020-06-04 08:52:43 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.setRequestInterception']({browserContextId, enabled}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).requestInterceptionEnabled = enabled; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.setIgnoreHTTPSErrors']({browserContextId, ignoreHTTPSErrors}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).setIgnoreHTTPSErrors(nullToUndefined(ignoreHTTPSErrors)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.setDownloadOptions']({browserContextId, downloadOptions}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).downloadOptions = nullToUndefined(downloadOptions); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setGeolocationOverride']({browserContextId, geolocation}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).applySetting('geolocation', nullToUndefined(geolocation)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setOnlineOverride']({browserContextId, override}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).applySetting('onlineOverride', nullToUndefined(override)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setColorScheme']({browserContextId, colorScheme}) { | 
					
						
							| 
									
										
										
										
											2021-03-02 18:52:19 -08:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setColorScheme(nullToUndefined(colorScheme)); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-18 21:23:12 +02:00
										 |  |  |   async ['Browser.setReducedMotion']({browserContextId, reducedMotion}) { | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setReducedMotion(nullToUndefined(reducedMotion)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-08 16:00:15 -07:00
										 |  |  |   async ['Browser.setForcedColors']({browserContextId, forcedColors}) { | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setForcedColors(nullToUndefined(forcedColors)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-12 17:17:54 -07:00
										 |  |  |   async ['Browser.setVideoRecordingOptions']({browserContextId, options}) { | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setVideoRecordingOptions(options); | 
					
						
							| 
									
										
										
										
											2020-08-19 12:43:53 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setUserAgentOverride']({browserContextId, userAgent}) { | 
					
						
							| 
									
										
										
										
											2020-09-30 08:02:22 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setDefaultUserAgent(userAgent); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-25 11:45:45 -04:00
										 |  |  |   async ['Browser.setPlatformOverride']({browserContextId, platform}) { | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setDefaultPlatform(platform); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setBypassCSP']({browserContextId, bypassCSP}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).applySetting('bypassCSP', nullToUndefined(bypassCSP)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setJavaScriptDisabled']({browserContextId, javaScriptDisabled}) { | 
					
						
							| 
									
										
										
										
											2021-08-11 03:37:57 +03:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setJavaScriptDisabled(javaScriptDisabled); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setLocaleOverride']({browserContextId, locale}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).applySetting('locale', nullToUndefined(locale)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setTimezoneOverride']({browserContextId, timezoneId}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).applySetting('timezoneId', nullToUndefined(timezoneId)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setTouchOverride']({browserContextId, hasTouch}) { | 
					
						
							| 
									
										
										
										
											2020-11-18 08:19:09 -08:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setTouchOverride(nullToUndefined(hasTouch)); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.setDefaultViewport']({browserContextId, viewport}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).setDefaultViewport(nullToUndefined(viewport)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 08:06:34 -07:00
										 |  |  |   async ['Browser.setScrollbarsHidden']({browserContextId, hidden}) { | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).applySetting('scrollbarsHidden', nullToUndefined(hidden)); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.addScriptToEvaluateOnNewDocument']({browserContextId, script}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     await this._targetRegistry.browserContextForId(browserContextId).addScriptToEvaluateOnNewDocument(script); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-11 16:27:39 +00:00
										 |  |  |   async ['Browser.addBinding']({browserContextId, worldName, name, script}) { | 
					
						
							|  |  |  |     await this._targetRegistry.browserContextForId(browserContextId).addBinding(worldName, name, script); | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.setCookies']({browserContextId, cookies}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).setCookies(cookies); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.clearCookies']({browserContextId}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     this._targetRegistry.browserContextForId(browserContextId).clearCookies(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   ['Browser.getCookies']({browserContextId}) { | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     const cookies = this._targetRegistry.browserContextForId(browserContextId).getCookies(); | 
					
						
							|  |  |  |     return {cookies}; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 00:15:24 -07:00
										 |  |  |   async ['Browser.getInfo']() { | 
					
						
							| 
									
										
										
										
											2020-11-19 08:24:17 -08:00
										 |  |  |     const version = AppConstants.MOZ_APP_VERSION_DISPLAY; | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  |     const userAgent = Components.classes["@mozilla.org/network/protocol;1?name=http"] | 
					
						
							|  |  |  |                                 .getService(Components.interfaces.nsIHttpProtocolHandler) | 
					
						
							|  |  |  |                                 .userAgent; | 
					
						
							|  |  |  |     return {version: 'Firefox/' + version, userAgent}; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-07 10:24:16 -07:00
										 |  |  | async function waitForSearchService() { | 
					
						
							|  |  |  |   const searchService = Components.classes["@mozilla.org/browser/search-service;1"].getService(Components.interfaces.nsISearchService); | 
					
						
							|  |  |  |   await searchService.init(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function waitForAddonManager() { | 
					
						
							|  |  |  |   if (AddonManager.isReady) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   await new Promise(resolve => { | 
					
						
							|  |  |  |     let listener = { | 
					
						
							|  |  |  |       onStartup() { | 
					
						
							|  |  |  |         AddonManager.removeManagerListener(listener); | 
					
						
							|  |  |  |         resolve(); | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       onShutdown() { }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     AddonManager.addManagerListener(listener); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-23 16:05:37 -07:00
										 |  |  | async function waitForWindowClosed(browserWindow) { | 
					
						
							|  |  |  |   if (browserWindow.closed) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   await new Promise((resolve => { | 
					
						
							|  |  |  |     const listener = { | 
					
						
							|  |  |  |       onCloseWindow: window => { | 
					
						
							| 
									
										
										
										
											2021-08-18 14:47:21 -07:00
										 |  |  |         let domWindow; | 
					
						
							|  |  |  |         if (window instanceof Ci.nsIAppWindow) | 
					
						
							|  |  |  |           domWindow = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           domWindow = window; | 
					
						
							|  |  |  |         if (domWindow === browserWindow) { | 
					
						
							| 
									
										
										
										
											2021-04-23 16:05:37 -07:00
										 |  |  |           Services.wm.removeListener(listener); | 
					
						
							|  |  |  |           resolve(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     Services.wm.addListener(listener); | 
					
						
							|  |  |  |   })); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-02 16:51:13 -07:00
										 |  |  | function nullToUndefined(value) { | 
					
						
							|  |  |  |   return value === null ? undefined : value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var EXPORTED_SYMBOLS = ['BrowserHandler']; | 
					
						
							|  |  |  | this.BrowserHandler = BrowserHandler; |