mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 1347791 - part4 : keep tab's block state consistent after session restore. r=dao,mikedeboer
If the tab was resumed before, it could start playing any autoplay media without user's permission after session restore. MozReview-Commit-ID: C3DHIIsLtJA --HG-- extra : rebase_source : d415d26d9ddcc9cb2949eb3215aee74f4c85912c
This commit is contained in:
parent
a3c591450b
commit
b58f62a199
@ -2162,7 +2162,7 @@
|
||||
"audioPlaybackStopped", "pauseMedia", "stopMedia",
|
||||
"blockMedia", "resumeMedia", "mute", "unmute", "blockedPopups", "lastURI",
|
||||
"purgeSessionHistory", "stopScroll", "startScroll",
|
||||
"userTypedValue", "userTypedClear"
|
||||
"userTypedValue", "userTypedClear", "mediaBlocked"
|
||||
]</field>
|
||||
|
||||
<method name="_createLazyBrowser">
|
||||
@ -2226,8 +2226,21 @@
|
||||
};
|
||||
};
|
||||
break;
|
||||
case "blockMedia":
|
||||
case "resumeMedia":
|
||||
getter = () => {
|
||||
return () => {
|
||||
// No need to insert a browser, so we just call the browser's
|
||||
// method.
|
||||
aTab.addEventListener("SSTabRestoring", () => {
|
||||
browser[name]();
|
||||
}, { once: true });
|
||||
};
|
||||
};
|
||||
break;
|
||||
case "userTypedValue":
|
||||
case "userTypedClear":
|
||||
case "mediaBlocked":
|
||||
getter = () => {
|
||||
return SessionStore.getLazyTabValue(aTab, name);
|
||||
};
|
||||
|
@ -3598,6 +3598,12 @@ var SessionStoreInternal = {
|
||||
tab.toggleMuteAudio(tabData.muteReason);
|
||||
}
|
||||
|
||||
if (tabData.mediaBlocked) {
|
||||
browser.blockMedia();
|
||||
} else {
|
||||
browser.resumeMedia();
|
||||
}
|
||||
|
||||
if (tabData.lastAccessed) {
|
||||
tab.updateLastAccessed(tabData.lastAccessed);
|
||||
}
|
||||
|
@ -14,8 +14,11 @@ this.EXPORTED_SYMBOLS = ["TabAttributes"];
|
||||
// 'pending' is used internal by sessionstore and managed accordingly.
|
||||
// 'iconLoadingPrincipal' is same as 'image' that it should be handled by
|
||||
// using the gBrowser.getIcon()/setIcon() methods.
|
||||
// 'activemedia-blocked' should not be accessed directly but handled by using
|
||||
// tab's toggleMuteAudio() or linkedBrowser's methods
|
||||
// activeMediaBlockStarted()/activeMediaBlockBlockStopped().
|
||||
const ATTRIBUTES_TO_SKIP = new Set(["image", "muted", "pending", "iconLoadingPrincipal",
|
||||
"skipbackgroundnotify"]);
|
||||
"skipbackgroundnotify", "activemedia-blocked"]);
|
||||
|
||||
// A set of tab attributes to persist. We will read a given list of tab
|
||||
// attributes when collecting tab data and will re-set those attributes when
|
||||
|
@ -102,6 +102,8 @@ var TabStateInternal = {
|
||||
tabData.muteReason = tab.muteReason;
|
||||
}
|
||||
|
||||
tabData.mediaBlocked = browser.mediaBlocked;
|
||||
|
||||
// Save tab attributes.
|
||||
tabData.attributes = TabAttributes.get(tab);
|
||||
|
||||
|
@ -4,15 +4,21 @@
|
||||
/**
|
||||
* This test makes sure that we correctly preserve tab attributes when storing
|
||||
* and restoring tabs. It also ensures that we skip special attributes like
|
||||
* 'image', 'muted' and 'pending' that need to be handled differently or internally.
|
||||
* 'image', 'muted', 'activemedia-blocked' and 'pending' that need to be
|
||||
* handled differently or internally.
|
||||
*/
|
||||
|
||||
const PREF = "browser.sessionstore.restore_on_demand";
|
||||
const PREF2 = "media.block-autoplay-until-in-foreground";
|
||||
|
||||
add_task(async function test() {
|
||||
Services.prefs.setBoolPref(PREF, true)
|
||||
registerCleanupFunction(() => Services.prefs.clearUserPref(PREF));
|
||||
|
||||
// Since we need to test 'activemedia-blocked' attribute.
|
||||
Services.prefs.setBoolPref(PREF2, true)
|
||||
registerCleanupFunction(() => Services.prefs.clearUserPref(PREF2));
|
||||
|
||||
// Add a new tab with a nice icon.
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, "about:robots");
|
||||
await promiseBrowserLoaded(tab.linkedBrowser);
|
||||
@ -25,15 +31,21 @@ add_task(async function test() {
|
||||
// Check that the tab has a 'muted' attribute.
|
||||
ok(tab.hasAttribute("muted"), "tab.muted exists");
|
||||
|
||||
// Make sure we do not persist 'image' or 'muted' attributes.
|
||||
// Pretend to start autoplay media in tab, tab should get the notification.
|
||||
tab.linkedBrowser.activeMediaBlockStarted();
|
||||
ok(tab.hasAttribute("activemedia-blocked"), "tab.activemedia-blocked exists");
|
||||
|
||||
// Make sure we do not persist 'image','muted' and 'activemedia-blocked' attributes.
|
||||
ss.persistTabAttribute("image");
|
||||
ss.persistTabAttribute("muted");
|
||||
ss.persistTabAttribute("iconLoadingPrincipal");
|
||||
ss.persistTabAttribute("activemedia-blocked");
|
||||
let {attributes} = JSON.parse(ss.getTabState(tab));
|
||||
ok(!("image" in attributes), "'image' attribute not saved");
|
||||
ok(!("iconLoadingPrincipal" in attributes), "'iconLoadingPrincipal' attribute not saved");
|
||||
ok(!("muted" in attributes), "'muted' attribute not saved");
|
||||
ok(!("custom" in attributes), "'custom' attribute not saved");
|
||||
ok(!("activemedia-blocked" in attributes), "'activemedia-blocked' attribute not saved");
|
||||
|
||||
// Test persisting a custom attribute.
|
||||
tab.setAttribute("custom", "foobar");
|
||||
|
Loading…
Reference in New Issue
Block a user