Bug 1435261 - Remove access to appcache interface OfflineResourceList over insecure contexts r?mayhemer,baku draft
authorJonathan Kingston <jkt@mozilla.com>
Fri, 02 Feb 2018 17:26:03 +0000
changeset 750971 55731abf961cca3c374aa56d8908f124ec800a1e
parent 750519 588fec4c25f558b4103de0302f41978010bbbe14
push id97806
push userbmo:jkt@mozilla.com
push dateSat, 03 Feb 2018 23:03:52 +0000
reviewersmayhemer, baku
bugs1435261
milestone60.0a1
Bug 1435261 - Remove access to appcache interface OfflineResourceList over insecure contexts r?mayhemer,baku MozReview-Commit-ID: BK7rbKOd8Yq
dom/tests/mochitest/ajax/offline/browser_disableAppcache.js
dom/tests/mochitest/ajax/offline/file_simpleManifest.html
dom/tests/mochitest/general/test_interfaces.js
dom/webidl/OfflineResourceList.webidl
js/xpconnect/tests/mochitest/test_bug790732.html
--- a/dom/tests/mochitest/ajax/offline/browser_disableAppcache.js
+++ b/dom/tests/mochitest/ajax/offline/browser_disableAppcache.js
@@ -112,23 +112,25 @@ add_task(async function test_pref_remove
     set: [
       [PREF_INSECURE_APPCACHE, true]
     ]
   });
   await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
   await ContentTask.spawn(gBrowser.selectedBrowser, null, async () => {
     // Have to use in page checking as IsSecureContextOrObjectIsFromSecureContext is true for spawn()
     is(content.document.getElementById("hasAppcache").textContent, "yes", "Appcache is enabled");
+    is(content.document.getElementById("hasOfflineResourceList").textContent, "yes", "OfflineResourceList is enabled");
   });
   gBrowser.removeCurrentTab();
 
   await SpecialPowers.pushPrefEnv({
     set: [
       [PREF_INSECURE_APPCACHE, false]
     ]
   });
   await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
   await ContentTask.spawn(gBrowser.selectedBrowser, [URL], async (URL) => {
     is(content.document.getElementById("hasAppcache").textContent, "no", "Appcache is disabled");
+    is(content.document.getElementById("hasOfflineResourceList").textContent, "no", "OfflineResourceList is disabled");
     content.window.eval("OfflineTest.clear()");
   });
   gBrowser.removeCurrentTab();
 });
--- a/dom/tests/mochitest/ajax/offline/file_simpleManifest.html
+++ b/dom/tests/mochitest/ajax/offline/file_simpleManifest.html
@@ -1,20 +1,23 @@
 <html xmlns="http://www.w3.org/1999/xhtml" manifest="http://example.com/browser/dom/tests/mochitest/ajax/offline/file_simpleManifest.cacheManifest">
 <head>
 <title>load manifest test</title>
 
 <script type="text/javascript">
   window.addEventListener("load", () => {
     const hasAppcache = document.getElementById("hasAppcache");
     hasAppcache.textContent = "applicationCache" in window ? "yes" : "no";
+    const hasOfflineResourceList = document.getElementById("hasOfflineResourceList");
+    hasOfflineResourceList.textContent = "OfflineResourceList" in window ? "yes" : "no";
   });
 </script>
 <script type="text/javascript" src="http://example.com/tests/dom/tests/mochitest/ajax/offline/offlineTests.js"></script>
 </head>
 
 <body>
 Offline testing<br />
 We have AppCache: <span id="hasAppcache"></span><br />
+We have OfflineResourceList: <span id="hasOfflineResourceList"></span><br />
 
 <iframe id="childframe" src="http://example.com/browser/dom/tests/mochitest/ajax/offline/file_testFile.sjs" ></iframe>
 </body>
 </html>
--- a/dom/tests/mochitest/general/test_interfaces.js
+++ b/dom/tests/mochitest/general/test_interfaces.js
@@ -704,17 +704,17 @@ var interfaceNamesInGlobalScope =
     {name: "Notification", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "OffscreenCanvas", insecureContext: true, disabled: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "OfflineAudioCompletionEvent", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "OfflineAudioContext", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    {name: "OfflineResourceList", insecureContext: true},
+    {name: "OfflineResourceList", insecureContext: SpecialPowers.getBoolPref("browser.cache.offline.insecure.enable")},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "Option", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "OscillatorNode", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PageTransitionEvent", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "PaintRequest", insecureContext: true},
--- a/dom/webidl/OfflineResourceList.webidl
+++ b/dom/webidl/OfflineResourceList.webidl
@@ -1,12 +1,13 @@
 /* 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/. */
 
+[Pref="browser.cache.offline.enable", Func="nsGlobalWindowInner::OfflineCacheAllowedForContext"]
 interface OfflineResourceList : EventTarget {
   /**
    * State of the application cache this object is associated with.
    */
 
   /* This object is not associated with an application cache. */
   const unsigned short UNCACHED = 0;
 
--- a/js/xpconnect/tests/mochitest/test_bug790732.html
+++ b/js/xpconnect/tests/mochitest/test_bug790732.html
@@ -28,17 +28,18 @@ https://bugzilla.mozilla.org/show_bug.cg
   is(Ci.nsIDOMKeyEvent, KeyEvent);
   is(Ci.nsIDOMMouseEvent, MouseEvent);
   is(Ci.nsIDOMMouseScrollEvent, MouseScrollEvent);
   is(Ci.nsIDOMMutationEvent, MutationEvent);
   // XXX We can't test this here because it's only exposed to chrome
   //is(Ci.nsIDOMSimpleGestureEvent, SimpleGestureEvent);
   is(Ci.nsIDOMUIEvent, UIEvent);
   is(Ci.nsIDOMHTMLMediaElement, HTMLMediaElement);
-  is(Ci.nsIDOMOfflineResourceList, OfflineResourceList);
+  // We can't test this here as it's been restricted to secure contexts in non release
+  //is(Ci.nsIDOMOfflineResourceList, OfflineResourceList);
   is(Ci.nsIDOMRange, Range);
   is(Ci.nsIDOMNodeFilter, NodeFilter);
   is(Ci.nsIDOMXPathResult, XPathResult);
   </script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=790732">Mozilla Bug 790732</a>
 <p id="display"></p>