Bug 1579445 - Refresh the FxA device list on Send Tab menu open. r=markh
authorEdouard Oger <eoger@fastmail.com>
Thu, 12 Sep 2019 22:42:31 +0000
changeset 492978 9a3b2a7742fb620c3caca4f7fa4891804b08053a
parent 492977 5a021b9f8790b0f6d39aefb29d9c65c2bc8f0ba3
child 492979 f3b282debb4d7ffd9a2315dbf0c3f4d6b55bd18d
push id95241
push usereoger@mozilla.com
push dateThu, 12 Sep 2019 22:49:00 +0000
treeherderautoland@9a3b2a7742fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1579445
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1579445 - Refresh the FxA device list on Send Tab menu open. r=markh Differential Revision: https://phabricator.services.mozilla.com/D45189
browser/base/content/browser-pageActions.js
browser/base/content/browser-sync.js
--- a/browser/base/content/browser-pageActions.js
+++ b/browser/base/content/browser-pageActions.js
@@ -1157,20 +1157,17 @@ BrowserPageActions.sendToDevice = {
   onLocationChange() {
     let action = PageActions.actionForID("sendToDevice");
     let browser = gBrowser.selectedBrowser;
     let url = browser.currentURI.spec;
     action.setDisabled(!gSync.isSendableURI(url), window);
   },
 
   onShowingSubview(panelViewNode) {
-    gSync.populateSendTabToDevicesView(
-      panelViewNode,
-      this.onShowingSubview.bind(this)
-    );
+    gSync.populateSendTabToDevicesView(panelViewNode);
   },
 };
 
 // add search engine
 BrowserPageActions.addSearchEngine = {
   get action() {
     return PageActions.actionForID("addSearchEngine");
   },
--- a/browser/base/content/browser-sync.js
+++ b/browser/base/content/browser-sync.js
@@ -241,20 +241,17 @@ var gSync = {
     document
       .getElementById("PanelUI-fxa-menu-sendtab-button")
       .setAttribute("label", title);
   },
 
   showSendToDeviceView(anchor) {
     PanelUI.showSubView("PanelUI-sendTabToDevice", anchor);
     let panelViewNode = document.getElementById("PanelUI-sendTabToDevice");
-    this.populateSendTabToDevicesView(
-      panelViewNode,
-      this.populateSendTabToDevicesView.bind(this)
-    );
+    this.populateSendTabToDevicesView(panelViewNode);
   },
 
   showSendToDeviceViewFromFxaMenu(anchor) {
     const { status } = UIState.get();
     if (status === UIState.STATUS_NOT_CONFIGURED) {
       PanelUI.showSubView("PanelUI-fxa-menu-sendtab-not-configured", anchor);
       return;
     }
@@ -273,17 +270,17 @@ var gSync = {
     this.emitFxaToolbarTelemetry("sync_tabs", panel);
   },
 
   showSidebarFromFxaMenu(panel) {
     SidebarUI.toggle("viewTabsSidebar");
     this.emitFxaToolbarTelemetry("sync_tabs_sidebar", panel);
   },
 
-  populateSendTabToDevicesView(panelViewNode, reloadFunc) {
+  populateSendTabToDevicesView(panelViewNode, reloadDevices = true) {
     let bodyNode = panelViewNode.querySelector(".panel-subview-body");
     let panelNode = panelViewNode.closest("panel");
     let browser = gBrowser.selectedBrowser;
     let url = browser.currentURI.spec;
     let title = browser.contentTitle;
     let multiselected = gBrowser.selectedTab.multiselected;
 
     // This is on top because it also clears the device list between state
@@ -325,23 +322,24 @@ var gSync = {
       }
     );
 
     bodyNode.removeAttribute("state");
     // In the first ~10 sec after startup, Sync may not be loaded and the list
     // of devices will be empty.
     if (gSync.sendTabConfiguredAndLoading) {
       bodyNode.setAttribute("state", "notready");
+    }
+    if (reloadDevices) {
       // Force a background Sync
       Services.tm.dispatchToMainThread(async () => {
-        await Weave.Service.sync({ why: "pageactions", engines: [] }); // [] = clients engine only
-        // There's no way Sync is still syncing at this point, but we check
-        // anyway to avoid infinite looping.
-        if (!window.closed && !gSync.sendTabConfiguredAndLoading) {
-          reloadFunc(panelViewNode);
+        // `engines: []` = clients engine only + refresh FxA Devices.
+        await Weave.Service.sync({ why: "pageactions", engines: [] });
+        if (!window.closed) {
+          this.populateSendTabToDevicesView(panelViewNode, false);
         }
       });
     }
   },
 
   toggleAccountPanel(
     viewId,
     anchor = document.getElementById("fxa-toolbar-menu-button"),