diff --git a/remote/domains/parent/target/TabManager.jsm b/remote/TabManager.jsm similarity index 94% rename from remote/domains/parent/target/TabManager.jsm rename to remote/TabManager.jsm index 6b10b8b7752e..948c7283cb67 100644 --- a/remote/domains/parent/target/TabManager.jsm +++ b/remote/TabManager.jsm @@ -19,7 +19,7 @@ var TabManager = { triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), userContextId, }); - this.gBrowser.selectedTab = tab; + this.selectTab(tab); return tab; }, @@ -27,4 +27,8 @@ var TabManager = { removeTab(tab) { this.gBrowser.removeTab(tab); }, + + selectTab(tab) { + this.gBrowser.selectedTab = tab; + }, }; diff --git a/remote/WindowManager.jsm b/remote/WindowManager.jsm new file mode 100644 index 000000000000..c22feee36f15 --- /dev/null +++ b/remote/WindowManager.jsm @@ -0,0 +1,25 @@ +/* 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"; + +var EXPORTED_SYMBOLS = ["WindowManager"]; + +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const { EventPromise } = ChromeUtils.import("chrome://remote/content/Sync.jsm"); + +var WindowManager = { + async focus(window) { + if (window != Services.focus.activeWindow) { + const promises = [ + EventPromise(window, "activate"), + EventPromise(window, "focus", { capture: true }), + ]; + + window.focus(); + + await Promise.all(promises); + } + }, +}; diff --git a/remote/domains/parent/Page.jsm b/remote/domains/parent/Page.jsm index 9315a719f817..a7618d2505c4 100644 --- a/remote/domains/parent/Page.jsm +++ b/remote/domains/parent/Page.jsm @@ -15,6 +15,12 @@ const { Domain } = ChromeUtils.import( const { UnsupportedError } = ChromeUtils.import( "chrome://remote/content/Error.jsm" ); +const { TabManager } = ChromeUtils.import( + "chrome://remote/content/TabManager.jsm" +); +const { WindowManager } = ChromeUtils.import( + "chrome://remote/content/WindowManager.jsm" +); class Page extends Domain { constructor(session) { @@ -147,16 +153,12 @@ class Page extends Domain { } } - bringToFront() { - const { browser } = this.session.target; - const navigator = browser.ownerGlobal; - const { gBrowser } = navigator; + async bringToFront() { + const { tab, window } = this.session.target; - // Focus the window responsible for this page. - navigator.focus(); - - // Select the corresponding tab - gBrowser.selectedTab = gBrowser.getTabForBrowser(browser); + // Focus the window, and select the corresponding tab + await WindowManager.focus(window); + TabManager.selectTab(tab); } /** diff --git a/remote/domains/parent/Target.jsm b/remote/domains/parent/Target.jsm index 2ef3b407b86e..3ead034da5d5 100644 --- a/remote/domains/parent/Target.jsm +++ b/remote/domains/parent/Target.jsm @@ -6,18 +6,18 @@ var EXPORTED_SYMBOLS = ["Target"]; +const { ContextualIdentityService } = ChromeUtils.import( + "resource://gre/modules/ContextualIdentityService.jsm" +); const { Domain } = ChromeUtils.import( "chrome://remote/content/domains/Domain.jsm" ); const { TabManager } = ChromeUtils.import( - "chrome://remote/content/domains/parent/target/TabManager.jsm" + "chrome://remote/content/TabManager.jsm" ); const { TabSession } = ChromeUtils.import( "chrome://remote/content/sessions/TabSession.jsm" ); -const { ContextualIdentityService } = ChromeUtils.import( - "resource://gre/modules/ContextualIdentityService.jsm" -); let sessionIds = 1; let browserContextIds = 1; diff --git a/remote/jar.mn b/remote/jar.mn index 4517e3db00a4..2959140ca88e 100644 --- a/remote/jar.mn +++ b/remote/jar.mn @@ -14,6 +14,8 @@ remote.jar: content/Protocol.jsm (Protocol.jsm) content/RecommendedPreferences.jsm (RecommendedPreferences.jsm) content/Sync.jsm (Sync.jsm) + content/TabManager.jsm (TabManager.jsm) + content/WindowManager.jsm (WindowManager.jsm) # sessions content/sessions/frame-script.js (sessions/frame-script.js) @@ -54,7 +56,6 @@ remote.jar: content/domains/parent/page/DialogHandler.jsm (domains/parent/page/DialogHandler.jsm) content/domains/parent/Security.jsm (domains/parent/Security.jsm) content/domains/parent/Target.jsm (domains/parent/Target.jsm) - content/domains/parent/target/TabManager.jsm (domains/parent/target/TabManager.jsm) # transport layer content/server/HTTPD.jsm (../netwerk/test/httpserver/httpd.js)