Bug 1348816 - Remove PageStyle collection/restoration from SessionStore r=mikedeboer
authorTim Taubert <ttaubert@mozilla.com>
Fri, 21 Jul 2017 10:35:20 +0200
changeset 369936 3ee1e97fc01b738cedc17aee1facd9e5ac0a99d3
parent 369935 479136e0a11e5b3f790ae3972960ef476e8d68bb
child 369937 d1340f39e016f763a780f70703cb4561a20a8162
push id92800
push userttaubert@mozilla.com
push dateFri, 21 Jul 2017 08:35:53 +0000
treeherdermozilla-inbound@d1340f39e016 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1348816
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1348816 - Remove PageStyle collection/restoration from SessionStore r=mikedeboer
browser/components/sessionstore/ContentRestore.jsm
browser/components/sessionstore/PageStyle.jsm
browser/components/sessionstore/SessionStore.jsm
browser/components/sessionstore/content/content-sessionStore.js
browser/components/sessionstore/moz.build
browser/components/sessionstore/test/browser.ini
browser/components/sessionstore/test/browser_pageStyle.js
browser/components/sessionstore/test/browser_pageStyle_sample.html
browser/components/sessionstore/test/browser_pageStyle_sample_nested.html
--- a/browser/components/sessionstore/ContentRestore.jsm
+++ b/browser/components/sessionstore/ContentRestore.jsm
@@ -11,18 +11,16 @@ const Ci = Components.interfaces;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 
 XPCOMUtils.defineLazyModuleGetter(this, "DocShellCapabilities",
   "resource:///modules/sessionstore/DocShellCapabilities.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FormData",
   "resource://gre/modules/FormData.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "PageStyle",
-  "resource:///modules/sessionstore/PageStyle.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ScrollPosition",
   "resource://gre/modules/ScrollPosition.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionHistory",
   "resource://gre/modules/sessionstore/SessionHistory.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionStorage",
   "resource:///modules/sessionstore/SessionStorage.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Utils",
   "resource://gre/modules/sessionstore/Utils.jsm");
@@ -78,17 +76,17 @@ function ContentRestoreInternal(chromeGl
 
   // The following fields are only valid during certain phases of the restore
   // process.
 
   // The tabData for the restore. Set in restoreHistory and removed in
   // restoreTabContent.
   this._tabData = null;
 
-  // Contains {entry, pageStyle, scrollPositions, formdata}, where entry is a
+  // Contains {entry, scrollPositions, formdata}, where entry is a
   // single entry from the tabData.entries array. Set in
   // restoreTabContent and removed in restoreDocument.
   this._restoringDocument = null;
 
   // This listener is used to detect reloads on restoring tabs. Set in
   // restoreHistory and removed in restoreTabContent.
   this._historyListener = null;
 
@@ -225,17 +223,16 @@ ContentRestoreInternal.prototype = {
                               Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP,
                               null, null, null,
                               Services.scriptSecurityManager.getSystemPrincipal());
       } else if (tabData.entries.length) {
         // Stash away the data we need for restoreDocument.
         let activeIndex = tabData.index - 1;
         this._restoringDocument = {entry: tabData.entries[activeIndex] || {},
                                    formdata: tabData.formdata || {},
-                                   pageStyle: tabData.pageStyle || {},
                                    scrollPositions: tabData.scroll || {}};
 
         // In order to work around certain issues in session history, we need to
         // force session history to update its internal index and call reload
         // instead of gotoIndex. See bug 597315.
         history.reloadCurrentEntry();
       } else {
         // If there's nothing to restore, we should still blank the page.
@@ -286,23 +283,22 @@ ContentRestoreInternal.prototype = {
    * Finish restoring the tab by filling in form data and setting the scroll
    * position. The restore is complete when this function exits. It should be
    * called when the "load" event fires for the restoring tab.
    */
   restoreDocument() {
     if (!this._restoringDocument) {
       return;
     }
-    let {pageStyle, formdata, scrollPositions} = this._restoringDocument;
+    let {formdata, scrollPositions} = this._restoringDocument;
     this._restoringDocument = null;
 
     let window = this.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
                                .getInterface(Ci.nsIDOMWindow);
 
-    PageStyle.restoreTree(this.docShell, pageStyle);
     FormData.restoreTree(window, formdata);
     ScrollPosition.restoreTree(window, scrollPositions);
   },
 
   /**
    * Cancel an ongoing restore. This function can be called any time between
    * restoreHistory and restoreDocument.
    *
deleted file mode 100644
--- a/browser/components/sessionstore/PageStyle.jsm
+++ /dev/null
@@ -1,100 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this file,
-* You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-"use strict";
-
-this.EXPORTED_SYMBOLS = ["PageStyle"];
-
-const Ci = Components.interfaces;
-
-/**
- * The external API exported by this module.
- */
-this.PageStyle = Object.freeze({
-  collect(docShell, frameTree) {
-    return PageStyleInternal.collect(docShell, frameTree);
-  },
-
-  restoreTree(docShell, data) {
-    PageStyleInternal.restoreTree(docShell, data);
-  }
-});
-
-// Signifies that author style level is disabled for the page.
-const NO_STYLE = "_nostyle";
-
-var PageStyleInternal = {
-  /**
-   * Collects the selected style sheet sets for all reachable frames.
-   */
-  collect(docShell, frameTree) {
-    let result = frameTree.map(({document: doc}) => {
-      let style;
-
-      if (doc) {
-        // http://dev.w3.org/csswg/cssom/#persisting-the-selected-css-style-sheet-set
-        style = doc.selectedStyleSheetSet || doc.lastStyleSheetSet;
-      }
-
-      return style ? {pageStyle: style} : null;
-    });
-
-    let markupDocumentViewer =
-      docShell.contentViewer;
-
-    if (markupDocumentViewer.authorStyleDisabled) {
-      result = result || {};
-      result.disabled = true;
-    }
-
-    return result && Object.keys(result).length ? result : null;
-  },
-
-  /**
-   * Restores pageStyle data for the current frame hierarchy starting at the
-   * |docShell's| current DOMWindow using the given pageStyle |data|.
-   *
-   * Warning: If the current frame hierarchy doesn't match that of the given
-   * |data| object we will silently discard data for unreachable frames. We may
-   * as well assign page styles to the wrong frames if some were reordered or
-   * removed.
-   *
-   * @param docShell (nsIDocShell)
-   * @param data (object)
-   *        {
-   *          disabled: true, // when true, author styles will be disabled
-   *          pageStyle: "Dusk",
-   *          children: [
-   *            null,
-   *            {pageStyle: "Mozilla", children: [ ... ]}
-   *          ]
-   *        }
-   */
-  restoreTree(docShell, data) {
-    let disabled = data.disabled || false;
-    let markupDocumentViewer =
-      docShell.contentViewer;
-    markupDocumentViewer.authorStyleDisabled = disabled;
-
-    function restoreFrame(root, frameData) {
-      if (frameData.hasOwnProperty("pageStyle")) {
-        root.document.selectedStyleSheetSet = frameData.pageStyle;
-      }
-
-      if (!frameData.hasOwnProperty("children")) {
-        return;
-      }
-
-      let frames = root.frames;
-      frameData.children.forEach((child, index) => {
-        if (child && index < frames.length) {
-          restoreFrame(frames[index], child);
-        }
-      });
-    }
-
-    let ifreq = docShell.QueryInterface(Ci.nsIInterfaceRequestor);
-    restoreFrame(ifreq.getInterface(Ci.nsIDOMWindow), data);
-  }
-};
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -3642,17 +3642,16 @@ var SessionStoreInternal = {
     TabStateCache.update(browser, {
       // NOTE: Copy the entries array shallowly, so as to not screw with the
       // original tabData's history when getting history updates.
       history: {entries: [...tabData.entries], index: tabData.index},
       scroll: tabData.scroll || null,
       storage: tabData.storage || null,
       formdata: tabData.formdata || null,
       disallow: tabData.disallow || null,
-      pageStyle: tabData.pageStyle || null,
       userContextId: tabData.userContextId || 0,
 
       // This information is only needed until the tab has finished restoring.
       // When that's done it will be removed from the cache and we always
       // collect it in TabState._collectBaseTabData().
       image: tabData.image || "",
       iconLoadingPrincipal: tabData.iconLoadingPrincipal || null,
       userTypedValue: tabData.userTypedValue || "",
--- a/browser/components/sessionstore/content/content-sessionStore.js
+++ b/browser/components/sessionstore/content/content-sessionStore.js
@@ -24,18 +24,16 @@ function debug(msg) {
 
 XPCOMUtils.defineLazyModuleGetter(this, "FormData",
   "resource://gre/modules/FormData.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
   "resource://gre/modules/Preferences.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "DocShellCapabilities",
   "resource:///modules/sessionstore/DocShellCapabilities.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "PageStyle",
-  "resource:///modules/sessionstore/PageStyle.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ScrollPosition",
   "resource://gre/modules/ScrollPosition.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionHistory",
   "resource://gre/modules/sessionstore/SessionHistory.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SessionStorage",
   "resource:///modules/sessionstore/SessionStorage.jsm");
 
 Cu.import("resource:///modules/sessionstore/FrameTree.jsm", this);
@@ -472,60 +470,16 @@ var FormDataListener = {
   },
 
   collect() {
     return gFrameTree.map(FormData.collect);
   }
 };
 
 /**
- * Listens for changes to the page style. Whenever a different page style is
- * selected or author styles are enabled/disabled we send a message with the
- * currently applied style to the chrome process.
- *
- * Causes a SessionStore:update message to be sent that contains the currently
- * selected pageStyle for all reachable frames.
- *
- * Example:
- *   {pageStyle: "Dusk", children: [null, {pageStyle: "Mozilla"}]}
- */
-var PageStyleListener = {
-  init() {
-    Services.obs.addObserver(this, "author-style-disabled-changed");
-    Services.obs.addObserver(this, "style-sheet-applicable-state-changed");
-    gFrameTree.addObserver(this);
-  },
-
-  uninit() {
-    Services.obs.removeObserver(this, "author-style-disabled-changed");
-    Services.obs.removeObserver(this, "style-sheet-applicable-state-changed");
-  },
-
-  observe(subject, topic) {
-    let frame = subject.defaultView;
-
-    if (frame && gFrameTree.contains(frame)) {
-      MessageQueue.push("pageStyle", () => this.collect());
-    }
-  },
-
-  collect() {
-    return PageStyle.collect(docShell, gFrameTree);
-  },
-
-  onFrameTreeCollected() {
-    MessageQueue.push("pageStyle", () => this.collect());
-  },
-
-  onFrameTreeReset() {
-    MessageQueue.push("pageStyle", () => null);
-  }
-};
-
-/**
  * Listens for changes to docShell capabilities. Whenever a new load is started
  * we need to re-check the list of capabilities and send message when it has
  * changed.
  *
  * Causes a SessionStore:update message to be sent that contains the currently
  * disabled docShell capabilities (all nsIDocShell.allow* properties set to
  * false) as a string - i.e. capability names separate by commas.
  */
@@ -842,17 +796,16 @@ var MessageQueue = {
       }
     }
   },
 };
 
 EventListener.init();
 MessageListener.init();
 FormDataListener.init();
-PageStyleListener.init();
 SessionHistoryListener.init();
 SessionStorageListener.init();
 ScrollPositionListener.init();
 DocShellCapabilitiesListener.init();
 PrivacyListener.init();
 MessageQueue.init();
 
 function handleRevivedTab() {
@@ -887,17 +840,16 @@ addEventListener("unload", () => {
   // If we're browsing from the tab crashed UI to a URI that causes the tab
   // to go remote again, we catch this in the unload event handler, because
   // swapping out the non-remote browser for a remote one in
   // tabbrowser.xml's updateBrowserRemoteness doesn't cause the pagehide
   // event to be fired.
   handleRevivedTab();
 
   // Remove all registered nsIObservers.
-  PageStyleListener.uninit();
   SessionStorageListener.uninit();
   SessionHistoryListener.uninit();
   MessageQueue.uninit();
 
   // Remove progress listeners.
   gContentRestore.resetRestore();
 
   // We don't need to take care of any gFrameTree observers as the gFrameTree
--- a/browser/components/sessionstore/moz.build
+++ b/browser/components/sessionstore/moz.build
@@ -22,17 +22,16 @@ EXTRA_COMPONENTS += [
     'nsSessionStore.manifest',
 ]
 
 EXTRA_JS_MODULES.sessionstore = [
     'ContentRestore.jsm',
     'DocShellCapabilities.jsm',
     'FrameTree.jsm',
     'GlobalState.jsm',
-    'PageStyle.jsm',
     'PrivacyFilter.jsm',
     'RecentlyClosedTabsAndWindowsMenuUtils.jsm',
     'RunState.jsm',
     'SessionCookies.jsm',
     'SessionFile.jsm',
     'SessionMigration.jsm',
     'SessionSaver.jsm',
     'SessionStorage.jsm',
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -22,18 +22,16 @@ support-files =
   browser_frame_history_index_blank.html
   browser_frame_history_a.html
   browser_frame_history_b.html
   browser_frame_history_c.html
   browser_frame_history_c1.html
   browser_frame_history_c2.html
   browser_form_restore_events_sample.html
   browser_formdata_format_sample.html
-  browser_pageStyle_sample.html
-  browser_pageStyle_sample_nested.html
   browser_sessionHistory_slow.sjs
   browser_scrollPositions_sample.html
   browser_scrollPositions_sample2.html
   browser_scrollPositions_sample_frameset.html
   browser_scrollPositions_readerModeArticle.html
   browser_sessionStorage.html
   browser_248970_b_sample.html
   browser_339445_sample.html
@@ -96,17 +94,16 @@ skip-if = (os == 'win') # bug 1331853
 [browser_formdata_xpath.js]
 [browser_frametree.js]
 [browser_frame_history.js]
 [browser_global_store.js]
 [browser_history_persist.js]
 [browser_label_and_icon.js]
 [browser_merge_closed_tabs.js]
 [browser_page_title.js]
-[browser_pageStyle.js]
 [browser_pending_tabs.js]
 [browser_privatetabs.js]
 [browser_purge_shistory.js]
 skip-if = e10s # Bug 1271024
 [browser_replace_load.js]
 [browser_restore_redirect.js]
 [browser_restore_cookies_noOriginAttributes.js]
 [browser_scrollPositions.js]
deleted file mode 100644
--- a/browser/components/sessionstore/test/browser_pageStyle.js
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-"use strict";
-
-const URL = getRootDirectory(gTestPath) + "browser_pageStyle_sample.html";
-const URL_NESTED = getRootDirectory(gTestPath) + "browser_pageStyle_sample_nested.html";
-
-/**
- * This test ensures that page style information is correctly persisted.
- */
-add_task(async function page_style() {
-  let tab = BrowserTestUtils.addTab(gBrowser, URL);
-  let browser = tab.linkedBrowser;
-  await promiseBrowserLoaded(browser);
-  let sheets = await getStyleSheets(browser);
-
-  // Enable all style sheets one by one.
-  for (let [title, /*disabled */] of sheets) {
-    await enableStyleSheetsForSet(browser, title);
-
-    let tab2 = gBrowser.duplicateTab(tab);
-    await promiseTabRestored(tab2);
-
-    let tab2Sheets = await getStyleSheets(tab2.linkedBrowser);
-    let enabled = tab2Sheets.filter(([, disabled]) => !disabled);
-
-    if (title.startsWith("fail_")) {
-      ok(!enabled.length, "didn't restore " + title);
-    } else {
-      is(enabled.length, 1, "restored one style sheet");
-      is(enabled[0][0], title, "restored correct sheet");
-    }
-
-    gBrowser.removeTab(tab2);
-  }
-
-  // Disable all styles and verify that this is correctly persisted.
-  await setAuthorStyleDisabled(browser, true);
-
-  let tab2 = gBrowser.duplicateTab(tab);
-  await promiseTabRestored(tab2);
-
-  let authorStyleDisabled = await getAuthorStyleDisabled(tab2.linkedBrowser);
-  ok(authorStyleDisabled, "disabled all stylesheets");
-
-  // Clean up.
-  gBrowser.removeTab(tab);
-  gBrowser.removeTab(tab2);
-});
-
-/**
- * This test ensures that page style notification from nested documents are
- * received and the page style is persisted correctly.
- */
-add_task(async function nested_page_style() {
-  let tab = BrowserTestUtils.addTab(gBrowser, URL_NESTED);
-  let browser = tab.linkedBrowser;
-  await promiseBrowserLoaded(browser);
-
-  await enableSubDocumentStyleSheetsForSet(browser, "alternate");
-  await promiseRemoveTab(tab);
-
-  let [{state: {pageStyle}}] = JSON.parse(ss.getClosedTabData(window));
-  let expected = JSON.stringify({children: [{pageStyle: "alternate"}]});
-  is(JSON.stringify(pageStyle), expected, "correct pageStyle persisted");
-});
-
-function getStyleSheets(browser) {
-  return sendMessage(browser, "ss-test:getStyleSheets");
-}
-
-function enableStyleSheetsForSet(browser, name) {
-  return sendMessage(browser, "ss-test:enableStyleSheetsForSet", name);
-}
-
-function enableSubDocumentStyleSheetsForSet(browser, name) {
-  return sendMessage(browser, "ss-test:enableSubDocumentStyleSheetsForSet", {
-    id: "iframe", set: name
-  });
-}
-
-function getAuthorStyleDisabled(browser) {
-  return sendMessage(browser, "ss-test:getAuthorStyleDisabled");
-}
-
-function setAuthorStyleDisabled(browser, val) {
-  return sendMessage(browser, "ss-test:setAuthorStyleDisabled", val)
-}
deleted file mode 100644
--- a/browser/components/sessionstore/test/browser_pageStyle_sample.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<html>
-<head>
-  <meta charset="utf-8">
-  <title>pageStyle sample</title>
-
-  <link href="404.css" title="default" rel="stylesheet">
-  <link href="404.css" title="alternate" rel="alternate stylesheet">
-  <link href="404.css" title="altERnate" rel=" styLEsheet altERnate ">
-  <link href="404.css" title="media_empty" rel="alternate stylesheet" media="">
-  <link href="404.css" title="media_all" rel="alternate stylesheet" media="all">
-  <link href="404.css" title="media_ALL" rel="alternate stylesheet" media=" ALL ">
-  <link href="404.css" title="media_screen" rel="alternate stylesheet" media="screen">
-  <link href="404.css" title="media_print_screen" rel="alternate stylesheet" media="print,screen">
-</head>
-<body></body>
-</html>
deleted file mode 100644
--- a/browser/components/sessionstore/test/browser_pageStyle_sample_nested.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<html>
-<head>
-  <meta charset="utf-8">
-  <title>pageStyle sample (nested)</title>
-</head>
-<body>
-  <iframe id="iframe" src="browser_pageStyle_sample.html"/>
-</body>
-</html>