Bug 1347791 - part5 : keep tab's block state consistent after session restore. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 14 Apr 2017 16:05:09 +0800
changeset 562710 b03555232483a478cc6c0b3c100f4de9417c2e88
parent 562709 600f133e23fd8b642236bbce0b89a4e22859d6bb
child 562711 841f47471bf938ec55fca6d6a264cd2353056b55
push id54104
push useralwu@mozilla.com
push dateFri, 14 Apr 2017 08:30:06 +0000
bugs1347791
milestone55.0a1
Bug 1347791 - part5 : keep tab's block state consistent after session restore. We should keep tab state consistent after session restore. If the tab was blocked/resumed before and then we should also block/resume it. MozReview-Commit-ID: FTeVOCUOMKt
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/TabAttributes.jsm
browser/components/sessionstore/TabState.jsm
browser/components/sessionstore/test/browser_attributes.js
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -3631,16 +3631,22 @@ var SessionStoreInternal = {
     } else {
       tabbrowser.showTab(tab);
     }
 
     if (!!tabData.muted != browser.audioMuted) {
       tab.toggleMuteAudio(tabData.muteReason);
     }
 
+    if (tabData.blocked) {
+      browser.blockMedia()
+    } else {
+      browser.resumeMedia();
+    }
+
     if (tabData.lastAccessed) {
       tab.updateLastAccessed(tabData.lastAccessed);
     }
 
     if ("attributes" in tabData) {
       // Ensure that we persist tab attributes restored from previous sessions.
       Object.keys(tabData.attributes).forEach(a => TabAttributes.persist(a));
     }
--- a/browser/components/sessionstore/TabAttributes.jsm
+++ b/browser/components/sessionstore/TabAttributes.jsm
@@ -9,18 +9,20 @@ this.EXPORTED_SYMBOLS = ["TabAttributes"
 // We never want to directly read or write these attributes.
 // 'image' should not be accessed directly but handled by using the
 //         gBrowser.getIcon()/setIcon() methods.
 // 'muted' should not be accessed directly but handled by using the
 //         tab.linkedBrowser.audioMuted/toggleMuteAudio methods.
 // '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.
+// 'blocked' should not be accessed directly but handled by using the
+//           tab.linkedBrowser.mediaBlocked, setMediaBlock methods.
 const ATTRIBUTES_TO_SKIP = new Set(["image", "muted", "pending", "iconLoadingPrincipal",
-                                    "skipbackgroundnotify"]);
+                                    "skipbackgroundnotify", "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
 // the given tab data is restored to a new tab.
 this.TabAttributes = Object.freeze({
   persist(name) {
     return TabAttributesInternal.persist(name);
   },
--- a/browser/components/sessionstore/TabState.jsm
+++ b/browser/components/sessionstore/TabState.jsm
@@ -97,16 +97,20 @@ var TabStateInternal = {
 
     tabData.hidden = tab.hidden;
 
     if (browser.audioMuted) {
       tabData.muted = true;
       tabData.muteReason = tab.muteReason;
     }
 
+    if (browser.mediaBlocked) {
+      tabData.blocked = true;
+    }
+
     // Save tab attributes.
     tabData.attributes = TabAttributes.get(tab);
 
     if (tab.__SS_extdata) {
       tabData.extData = tab.__SS_extdata;
     }
 
     // Copy data from the tab state cache only if the tab has fully finished
--- a/browser/components/sessionstore/test/browser_attributes.js
+++ b/browser/components/sessionstore/test/browser_attributes.js
@@ -20,25 +20,31 @@ add_task(function* test() {
   // Check that the tab has 'image' and 'iconLoadingPrincipal' attributes.
   ok(tab.hasAttribute("image"), "tab.image exists");
   ok(tab.hasAttribute("iconLoadingPrincipal"), "tab.iconLoadingPrincipal exists");
 
   tab.toggleMuteAudio();
   // Check that the tab has a 'muted' attribute.
   ok(tab.hasAttribute("muted"), "tab.muted exists");
 
+  tab.setMediaBlock(true /* block */);
+  // Check that the tab has a 'blocked' attribute.
+  ok(tab.hasAttribute("blocked"), "tab.blocked exists");
+
   // Make sure we do not persist 'image' or 'muted' attributes.
   ss.persistTabAttribute("image");
   ss.persistTabAttribute("muted");
   ss.persistTabAttribute("iconLoadingPrincipal");
+  ss.persistTabAttribute("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(!("blocked" in attributes), "'blocked' attribute not saved");
 
   // Test persisting a custom attribute.
   tab.setAttribute("custom", "foobar");
   ss.persistTabAttribute("custom");
 
   ({attributes} = JSON.parse(ss.getTabState(tab)));
   is(attributes.custom, "foobar", "'custom' attribute is correct");