Bug 1524665 - Add send tab to device button, r=gijs

Differential Revision: https://phabricator.services.mozilla.com//D23387

--HG--
extra : rebase_source : 2f41fc8a0f78149105b32b87017e1d9035cc5d3e
This commit is contained in:
Vijay Budhram 2019-03-13 20:31:59 +00:00
Родитель de28a9888d
Коммит b326d15f68
6 изменённых файлов: 94 добавлений и 52 удалений

Просмотреть файл

@ -1083,58 +1083,7 @@ BrowserPageActions.sendToDevice = {
},
onShowingSubview(panelViewNode) {
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
// changes.
gSync.populateSendTabToDevicesMenu(bodyNode, url, title, multiselected, (clientId, name, clientType, lastModified) => {
if (!name) {
return document.createXULElement("toolbarseparator");
}
let item = document.createXULElement("toolbarbutton");
item.classList.add("pageAction-sendToDevice-device", "subviewbutton");
if (clientId) {
item.classList.add("subviewbutton-iconic");
if (lastModified) {
item.setAttribute("tooltiptext", gSync.formatLastSyncDate(lastModified));
}
}
item.addEventListener("command", event => {
if (panelNode) {
PanelMultiView.hidePopup(panelNode);
}
// There are items in the subview that don't represent devices: "Sign
// in", "Learn about Sync", etc. Device items will be .sendtab-target.
if (event.target.classList.contains("sendtab-target")) {
let action = PageActions.actionForID("sendToDevice");
let messageId = gSync.offline && "sendToDeviceOffline";
showBrowserPageActionFeedback(action, event, messageId);
}
});
return item;
});
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");
// 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) {
this.onShowingSubview(panelViewNode);
}
});
}
gSync.populateSendTabToDevicesView(panelViewNode, this.onShowingSubview.bind(this));
},
};

Просмотреть файл

@ -196,6 +196,78 @@ var gSync = {
this.updateFxAToolbarPanel(state);
},
updateSendToDeviceTitle() {
let string = gBrowserBundle.GetStringFromName("sendTabsToDevice.label");
let title = PluralForm.get(1, string).replace("#1", 1);
if (gBrowser.selectedTab.multiselected) {
let tabCount = gBrowser.selectedTabs.length;
title = PluralForm.get(tabCount, string).replace("#1", tabCount);
}
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);
},
populateSendTabToDevicesView(panelViewNode, reloadFunc) {
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
// changes.
this.populateSendTabToDevicesMenu(bodyNode, url, title, multiselected, (clientId, name, clientType, lastModified) => {
if (!name) {
return document.createXULElement("toolbarseparator");
}
let item = document.createXULElement("toolbarbutton");
item.classList.add("pageAction-sendToDevice-device", "subviewbutton");
if (clientId) {
item.classList.add("subviewbutton-iconic");
if (lastModified) {
item.setAttribute("tooltiptext", gSync.formatLastSyncDate(lastModified));
}
}
item.addEventListener("command", event => {
if (panelNode) {
PanelMultiView.hidePopup(panelNode);
}
// There are items in the subview that don't represent devices: "Sign
// in", "Learn about Sync", etc. Device items will be .sendtab-target.
if (event.target.classList.contains("sendtab-target")) {
let action = PageActions.actionForID("sendToDevice");
let messageId = gSync.offline && "sendToDeviceOffline";
showBrowserPageActionFeedback(action, event, messageId);
}
});
return item;
});
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");
// 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);
}
});
}
},
toggleAccountPanel(viewId, aEvent) {
// Don't show the panel if the window is in customization mode.
if (document.documentElement.hasAttribute("customizing")) {

Просмотреть файл

@ -475,7 +475,10 @@ function showFxaToolbarMenu(enable) {
// if sync is enabled.
const syncEnabled = Services.prefs.getBoolPref("identity.fxaccounts.enabled", false);
const mainWindowEl = document.documentElement;
const fxaPanelEl = document.getElementById("PanelUI-fxa");
if (enable && syncEnabled) {
fxaPanelEl.addEventListener("ViewShowing", gSync.updateSendToDeviceTitle);
mainWindowEl.setAttribute("fxastatus", "not_configured");
// We have to manually update the sync state UI when toggling the FxA toolbar
// because it could show an invalid icon if the user is logged in and no sync
@ -491,6 +494,7 @@ function showFxaToolbarMenu(enable) {
}
} else {
mainWindowEl.removeAttribute("fxastatus");
fxaPanelEl.removeEventListener("ViewShowing", gSync.updateSendToDeviceTitle);
}
}

Просмотреть файл

@ -742,6 +742,10 @@
</vbox>
</hbox>
<toolbarseparator/>
<toolbarbutton id="PanelUI-fxa-menu-sendtab-button"
class="subviewbutton subviewbutton-iconic subviewbutton-nav"
closemenu="none"
oncommand="gSync.showSendToDeviceView(this);"/>
<toolbarbutton id="PanelUI-fxa-menu-remotetabs-button"
class="subviewbutton subviewbutton-iconic subviewbutton-nav"
label="&appMenuRemoteTabs.label;"
@ -764,6 +768,14 @@
</vbox>
</vbox>
</panelview>
<!-- This panelview is used to contain the dynamically created buttons for send tab to devices -->
<panelview id="PanelUI-sendTabToDevice" flex="1" class="PanelUI-subView">
<vbox class="panel-subview-body">
<toolbarbutton id="PanelUI-sendTabToDevice-syncingDevices" class="subviewbutton subviewbutton-iconic pageAction-sendToDevice-notReady"
label="&sendToDevice.syncNotReady.label;"
disabled="true"/>
</vbox>
</panelview>
<panelview id="PanelUI-bookmarkingTools" class="PanelUI-subView">
<vbox class="panel-subview-body">

Просмотреть файл

@ -761,6 +761,10 @@ panelmultiview[mainViewId="PanelUI-fxa"] #PanelUI-remotetabs-syncnow {
display: none;
}
#PanelUI-sendTabToDevice > .panel-subview-body:not([state]) > #PanelUI-sendTabToDevice-syncingDevices {
display: none;
}
.fxaChooseWhatToSyncDevices {
height: 102px;
width: 201px;

Просмотреть файл

@ -180,6 +180,7 @@
list-style-image: url("chrome://browser/skin/mail.svg");
}
#PanelUI-fxa-menu-sendtab-button,
#pageAction-panel-sendToDevice,
#pageAction-urlbar-sendToDevice {
list-style-image: url("chrome://browser/skin/send-to-device.svg");