Display translationbar when the tab is detached (#440)
This commit is contained in:
Родитель
b6fd7ded48
Коммит
dc520dd839
|
@ -498,6 +498,15 @@ browser.tabs.onRemoved.addListener(tabId => {
|
|||
submitPing(tabId);
|
||||
});
|
||||
|
||||
browser.tabs.onDetached.addListener(tabId => {
|
||||
translateAsBrowseMap.delete(tabId);
|
||||
browser.experiments.translationbar.onDetached(tabId);
|
||||
browser.tabs.sendMessage(
|
||||
tabId,
|
||||
{ command: "onDetached" }
|
||||
);
|
||||
});
|
||||
|
||||
browser.webNavigation.onCommitted.addListener(details => {
|
||||
// only send pings if the top frame navigates.
|
||||
if (details.frameId === 0) submitPing(details.tabId);
|
||||
|
|
|
@ -195,6 +195,9 @@ const translationNotificationManagers = new Map();
|
|||
const isMochitest = Services.prefs.getBoolPref("fxtranslations.running.mochitest", false);
|
||||
return isMochitest;
|
||||
},
|
||||
onDetached: function onDetached(tabId) {
|
||||
translationNotificationManagers.delete(tabId);
|
||||
},
|
||||
onTranslationRequest: new ExtensionCommon.EventManager({
|
||||
context,
|
||||
name: "experiments.translationbar.onTranslationRequest",
|
||||
|
|
|
@ -87,6 +87,19 @@
|
|||
"description": "Returns if we are running a mochitest.",
|
||||
"async": true,
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "onDetached",
|
||||
"type": "function",
|
||||
"description": "Raised when the tab holding the translatedbar is detached.",
|
||||
"async": true,
|
||||
"parameters": [
|
||||
{
|
||||
"name": "tabId",
|
||||
"type": "integer",
|
||||
"description": "id of the detached tab"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"events": [
|
||||
|
|
|
@ -357,6 +357,19 @@ class Mediator {
|
|||
this.localizedPageLanguage = message.localizedPageLanguage;
|
||||
this.localizedNavigatorLanguage = message.localizedNavigatorLanguage;
|
||||
break;
|
||||
case "onDetached":
|
||||
|
||||
/*
|
||||
* whenever we receive an event that our tab was detached, we
|
||||
* should call detectPageLanguage in order to
|
||||
* have the infobar re-displayed.
|
||||
*/
|
||||
this.translationBarDisplayed = false;
|
||||
browser.runtime.sendMessage({
|
||||
command: "detectPageLanguage",
|
||||
languageDetection: this.languageDetection.extractPageContent(),
|
||||
});
|
||||
break;
|
||||
default:
|
||||
// ignore
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче