Bug 1579445 - Refresh the FxA device list on Send Tab menu open. a=lizzard
authorEdouard Oger <eoger@fastmail.com>
Fri, 13 Sep 2019 01:42:31 +0300
changeset 552313 23bf5f0fdb544ad77ee16ecd4eb1c5d3cbe89157
parent 552312 91ac17bc71eaec127fa155ece81c89ecad2b4fdf
child 552314 286cdf5bc9f35f1d70aa56dcffd289a292925d7e
push id12143
push usershindli@mozilla.com
push dateWed, 09 Oct 2019 08:42:51 +0000
treeherdermozilla-beta@ce231a76c7bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslizzard
bugs1579445
milestone70.0
Bug 1579445 - Refresh the FxA device list on Send Tab menu open. a=lizzard 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"),