Bug 1398169 - Use pref to disable registerContentHandler in non stable builds. r?dao draft
authorJonathan Kingston <jkt@mozilla.com>
Mon, 08 Jan 2018 02:18:31 +0000
changeset 719196 2438578f1e0704b378e14df072dc0461dc77dcd0
parent 719195 6159c8eb544245f0a3ed8766608202ee72530101
child 745713 4b6ccb4c049450d041ad16d12fbbaa5afbf5e554
push id95167
push userbmo:jkt@mozilla.com
push dateThu, 11 Jan 2018 15:54:53 +0000
reviewersdao
bugs1398169
milestone59.0a1
Bug 1398169 - Use pref to disable registerContentHandler in non stable builds. r?dao MozReview-Commit-ID: Gbo1wFr8XU6
browser/components/feeds/test/mochitest.ini
browser/components/feeds/test/test_registerHandler.html
browser/components/feeds/test/test_registerHandler_disabled.html
dom/webidl/Navigator.webidl
modules/libpref/init/all.js
testing/web-platform/meta/html/webappapis/system-state-and-capabilities/the-navigator-object/historical.window.js.ini
--- a/browser/components/feeds/test/mochitest.ini
+++ b/browser/components/feeds/test/mochitest.ini
@@ -7,8 +7,9 @@ support-files =
   bug589543-data.xml
   valid-feed.xml
   valid-unsniffable-feed.xml
 
 [test_bug436801.html]
 [test_bug494328.html]
 [test_bug589543.html]
 [test_registerHandler.html]
+[test_registerHandler_disabled.html]
--- a/browser/components/feeds/test/test_registerHandler.html
+++ b/browser/components/feeds/test/test_registerHandler.html
@@ -7,77 +7,85 @@ https://bugzilla.mozilla.org/show_bug.cg
   <title>Test for Bug 402788</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=402788">Mozilla Bug 402788</a>
 <p id="display"></p>
 <div id="content" style="display: none">
-  
+
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 402788 **/
+  SimpleTest.waitForExplicitFinish();
 
   // return false if an exception has been catched, true otherwise
   function testRegisterHandler(aIsProtocol, aTxt, aUri, aTitle) {
     try {
       if (aIsProtocol)
         navigator.registerProtocolHandler(aTxt, aUri, aTitle);
       else
         navigator.registerContentHandler(aTxt, aUri, aTitle);
     } catch (e) {
       return false;
     }
 
     return true;
   }
 
-  ok(navigator.registerProtocolHandler, "navigator.registerProtocolHandler should be defined");
-  ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined");
+  async function tests() {
+    await SpecialPowers.pushPrefEnv({
+      set: [["dom.registerContentHandler.enabled", true]]
+    });
+    ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined");
 
-  // testing a generic case
-  is(testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), true, "registering a foo protocol handler should work");
-  is(testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), true, "registering a foo content handler should work");
+    // testing a generic case
+    is(testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), true, "registering a foo protocol handler should work");
+    is(testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), true, "registering a foo content handler should work");
 
-  // testing with wrong uris
-  is(testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), false, "a protocol handler uri should contain %s");
-  is(testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), false, "a content handler uri should contain %s");
+    // testing with wrong uris
+    is(testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), false, "a protocol handler uri should contain %s");
+    is(testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), false, "a content handler uri should contain %s");
 
-  // the spec explicitly allows relative urls to be passed
-  is(testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), true, "a protocol handler uri should be valid");
-  is(testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), true, "a content handler uri should be valid");
+    // the spec explicitly allows relative urls to be passed
+    is(testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), true, "a protocol handler uri should be valid");
+    is(testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), true, "a content handler uri should be valid");
 
-  // we should only accept to register when the handler has the same host as the current page (bug 402287)
-  is(testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), false, "registering a foo protocol handler with a different host should not work");
-  is(testRegisterHandler(false, "application/rss+xml", "http://remotehost:8888/%s", "Foo handler"), false, "registering a foo content handler with a different host should not work");
+    // we should only accept to register when the handler has the same host as the current page (bug 402287)
+    is(testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), false, "registering a foo protocol handler with a different host should not work");
+    is(testRegisterHandler(false, "application/rss+xml", "http://remotehost:8888/%s", "Foo handler"), false, "registering a foo content handler with a different host should not work");
 
-  // restriction to http(s) for the uri of the handler (bug 401343)
-  // https should work (http already tested in the generic case)
-  is(testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), true, "registering a foo protocol handler with https scheme should work");
-  is(testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), true, "registering a foo content handler with https scheme should work");
-  // ftp should not work
-  is(testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), false, "registering a foo protocol handler with ftp scheme should not work");
-  is(testRegisterHandler(false, "application/rss+xml", "ftp://mochi.test:8888/%s", "Foo handler"), false, "registering a foo content handler with ftp scheme should not work");
-  // chrome should not work
-  is(testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), false, "registering a foo protocol handler with chrome scheme should not work");
-  is(testRegisterHandler(false, "application/rss+xml", "chrome://mochi.test:8888/%s", "Foo handler"), false, "registering a foo content handler with chrome scheme should not work");
-  // foo should not work
-  is(testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), false, "registering a foo protocol handler with foo scheme should not work");
-  is(testRegisterHandler(false, "application/rss+xml", "foo://mochi.test:8888/%s", "Foo handler"), false, "registering a foo content handler with foo scheme should not work");
+    // restriction to http(s) for the uri of the handler (bug 401343)
+    // https should work (http already tested in the generic case)
+    is(testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), true, "registering a foo protocol handler with https scheme should work");
+    is(testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), true, "registering a foo content handler with https scheme should work");
+    // ftp should not work
+    is(testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), false, "registering a foo protocol handler with ftp scheme should not work");
+    is(testRegisterHandler(false, "application/rss+xml", "ftp://mochi.test:8888/%s", "Foo handler"), false, "registering a foo content handler with ftp scheme should not work");
+    // chrome should not work
+    is(testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), false, "registering a foo protocol handler with chrome scheme should not work");
+    is(testRegisterHandler(false, "application/rss+xml", "chrome://mochi.test:8888/%s", "Foo handler"), false, "registering a foo content handler with chrome scheme should not work");
+    // foo should not work
+    is(testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), false, "registering a foo protocol handler with foo scheme should not work");
+    is(testRegisterHandler(false, "application/rss+xml", "foo://mochi.test:8888/%s", "Foo handler"), false, "registering a foo content handler with foo scheme should not work");
 
-  // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788)
-  is(testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), false, "registering a chrome protocol handler should not work");
-  is(testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), false, "registering a vbscript protocol handler should not work");
-  is(testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), false, "registering a javascript protocol handler should not work");
-  is(testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), false, "registering a moz-icon protocol handler should not work");
+    // for security reasons, protocol handlers should never be registered for some schemes (chrome, vbscript, ...) (bug 402788)
+    is(testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), false, "registering a chrome protocol handler should not work");
+    is(testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), false, "registering a vbscript protocol handler should not work");
+    is(testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), false, "registering a javascript protocol handler should not work");
+    is(testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), false, "registering a moz-icon protocol handler should not work");
 
-  // for security reasons, content handlers should never be registered for some types (html, ...)
-  is(testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), true, "registering rss content handlers should work");
-  is(testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), true, "registering atom content handlers should work");
-  todo_is(testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), false, "registering html content handlers should not work"); // bug 403798
+    // for security reasons, content handlers should never be registered for some types (html, ...)
+    is(testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), true, "registering rss content handlers should work");
+    is(testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), true, "registering atom content handlers should work");
+    todo_is(testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), false, "registering html content handlers should not work"); // bug 403798
+    SimpleTest.finish();
+  }
+
+  tests();
 
 </script>
 </pre>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/browser/components/feeds/test/test_registerHandler_disabled.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=402788
+-->
+<head>
+  <title>Test for Bug 1398169</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1398169">Mozilla Bug 1398169</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+  SimpleTest.waitForExplicitFinish();
+
+  async function tests() {
+    await SpecialPowers.pushPrefEnv({
+      set: [["dom.registerContentHandler.enabled", true]]
+    });
+    ok(navigator.registerContentHandler, "navigator.registerContentHandler should be defined");
+    SimpleTest.finish();
+  }
+
+  tests();
+
+</script>
+</pre>
+</body>
+</html>
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -73,17 +73,17 @@ interface NavigatorOnLine {
   readonly attribute boolean onLine;
 };
 
 [NoInterfaceObject]
 interface NavigatorContentUtils {
   // content handler registration
   [Throws]
   void registerProtocolHandler(DOMString scheme, DOMString url, DOMString title);
-  [Throws]
+  [Pref="dom.registerContentHandler.enabled", Throws]
   void registerContentHandler(DOMString mimeType, DOMString url, DOMString title);
   // NOT IMPLEMENTED
   //DOMString isProtocolHandlerRegistered(DOMString scheme, DOMString url);
   //DOMString isContentHandlerRegistered(DOMString mimeType, DOMString url);
   //void unregisterProtocolHandler(DOMString scheme, DOMString url);
   //void unregisterContentHandler(DOMString mimeType, DOMString url);
 };
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -103,16 +103,23 @@ pref("offline-apps.quota.warn",        5
 // 1 => best speed
 // 9 => best compression
 // cache compression turned off for now - see bug #715198
 pref("browser.cache.compression_level", 0);
 
 // Don't show "Open with" option on download dialog if true.
 pref("browser.download.forbid_open_with", false);
 
+// Remove navigator.registerContentHandler
+#ifdef EARLY_BETA_OR_EARLIER
+pref("dom.registerContentHandler.enabled", false);
+#else
+pref("dom.registerContentHandler.enabled", true);
+#endif
+
 // Whether or not testing features are enabled.
 pref("dom.quotaManager.testing", false);
 
 // Whether or not indexedDB is enabled.
 pref("dom.indexedDB.enabled", true);
 // Whether or not indexedDB experimental features are enabled.
 pref("dom.indexedDB.experimental", false);
 // Enable indexedDB logging.
--- a/testing/web-platform/meta/html/webappapis/system-state-and-capabilities/the-navigator-object/historical.window.js.ini
+++ b/testing/web-platform/meta/html/webappapis/system-state-and-capabilities/the-navigator-object/historical.window.js.ini
@@ -1,4 +1,4 @@
 [historical.window.html]
-  [registerContentHandler() is removed]
-    expected: FAIL
+  prefs: [dom.registerContentHandler.enabled:false]
 
+