Bug 693261 registerContentHandler() fails in SeaMonkey's WebContentConverter.js r=IanN a=Callek.
authorPhilip Chee <philip.chee@gmail.com>
Mon, 07 Nov 2011 12:53:31 +0800
changeset 9349 6e6c1c75d7b0359a2dd63e76bb1a6ce6ced4986c
parent 9348 9127c7406dcdfe16926705b02739cec7fd97c87e
child 9350 931721d54ec9e38282edddc56e920ecfbdfc6673
push idunknown
push userunknown
push dateunknown
reviewersIanN, Callek
bugs693261
Bug 693261 registerContentHandler() fails in SeaMonkey's WebContentConverter.js r=IanN a=Callek.
suite/browser/test/Makefile.in
suite/browser/test/mochitest/test_registerHandler.html
suite/feeds/src/WebContentConverter.js
--- a/suite/browser/test/Makefile.in
+++ b/suite/browser/test/Makefile.in
@@ -49,16 +49,17 @@ include $(topsrcdir)/config/rules.mk
 		bug395533-data.txt \
 		test_contextmenu.html \
 		subtst_contextmenu.html \
 		ctxmenu-image.png \
 		video.ogg \
 		test_bug364677.html \
 		bug364677-data.xml \
 		bug364677-data.xml^headers^ \
+		test_registerHandler.html \
 		$(NULL)
 
 _BROWSER_FILES = browser_bug413915.js \
                  browser_bug427559.js \
                  browser_bug561636.js \
                  browser_bug562649.js \
                  browser_bug585511.js \
                  browser_bug595507.js \
new file mode 100644
--- /dev/null
+++ b/suite/browser/test/mochitest/test_registerHandler.html
@@ -0,0 +1,85 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=402788
+-->
+<head>
+  <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 **/
+
+  // 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");
+
+  // testing a generic case
+  is(true, testRegisterHandler(true, "foo", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler should work");
+  is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler should work");
+
+  // testing with wrong uris
+  is(false, testRegisterHandler(true, "foo", "http://mochi.test:8888/", "Foo handler"), "a protocol handler uri should contain %s");
+  is(false, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/", "Foo handler"), "a content handler uri should contain %s");
+
+  // the spec says we should not throw here, but it probably needs to be changed
+  is(false, testRegisterHandler(true, "foo", "foo/%s", "Foo handler"), "a protocol handler uri should be valid");
+  is(false, testRegisterHandler(false, "application/rss+xml", "foo/%s", "Foo handler"), "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(false, testRegisterHandler(true, "foo", "http://remotehost:8888/%s", "Foo handler"), "registering a foo protocol handler with a different host should not work");
+  is(false, testRegisterHandler(false, "application/rss+xml", "http://remotehost:8888/%s", "Foo handler"), "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(true, testRegisterHandler(true, "foo", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with https scheme should work");
+  is(true, testRegisterHandler(false, "application/rss+xml", "https://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with https scheme should work");
+  // ftp should not work
+  is(false, testRegisterHandler(true, "foo", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with ftp scheme should not work");
+  is(false, testRegisterHandler(false, "application/rss+xml", "ftp://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with ftp scheme should not work");
+  // chrome should not work 
+  is(false, testRegisterHandler(true, "foo", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with chrome scheme should not work");
+  is(false, testRegisterHandler(false, "application/rss+xml", "chrome://mochi.test:8888/%s", "Foo handler"), "registering a foo content handler with chrome scheme should not work");
+  // foo should not work 
+  is(false, testRegisterHandler(true, "foo", "foo://mochi.test:8888/%s", "Foo handler"), "registering a foo protocol handler with foo scheme should not work");
+  is(false, testRegisterHandler(false, "application/rss+xml", "foo://mochi.test:8888/%s", "Foo handler"), "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(false, testRegisterHandler(true, "chrome", "http://mochi.test:8888/%s", "chrome handler"), "registering a chrome protocol handler should not work");
+  is(false, testRegisterHandler(true, "vbscript", "http://mochi.test:8888/%s", "vbscript handler"), "registering a vbscript protocol handler should not work");
+  is(false, testRegisterHandler(true, "javascript", "http://mochi.test:8888/%s", "javascript handler"), "registering a javascript protocol handler should not work");
+  is(false, testRegisterHandler(true, "moz-icon", "http://mochi.test:8888/%s", "moz-icon handler"), "registering a moz-icon protocol handler should not work");
+
+  // for security reasons, content handlers should never be registered for some types (html, ...)
+  is(true, testRegisterHandler(false, "application/rss+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering rss content handlers should work");
+  is(true, testRegisterHandler(false, "application/atom+xml", "http://mochi.test:8888/%s", "Foo handler"), "registering atom content handlers should work");
+  todo(false, testRegisterHandler(false, "text/html", "http://mochi.test:8888/%s", "Foo handler"), "registering html content handlers should not work"); // bug 403798
+
+</script>
+</pre>
+</body>
+</html>
--- a/suite/feeds/src/WebContentConverter.js
+++ b/suite/feeds/src/WebContentConverter.js
@@ -476,17 +476,17 @@ WebContentConverterRegistrar.prototype =
           var hs = Components.classes["@mozilla.org/uriloader/handler-service;1"]
                              .getService(Components.interfaces.nsIHandlerService);
           hs.store(handlerInfo);
         }
       };
       buttons = [addButton];
     }
 
-    var notificationBox = getNotificationBox(browserElement);
+    var notificationBox = getNotificationBox(aContentWindow);
     notificationBox.appendNotification(message,
                                        notificationValue,
                                        notificationIcon,
                                        notificationBox.PRIORITY_INFO_LOW,
                                        buttons);
   },
 
   /**
@@ -503,17 +503,17 @@ WebContentConverterRegistrar.prototype =
     // isn't defined yet.
     var contentType = this._resolveContentType(aContentType);
     if (contentType != TYPE_MAYBE_FEED)
       return;
 
     if (aContentWindow) {
       var uri = this._checkAndGetURI(aURIString, aContentWindow);
 
-      this._appendFeedReaderNotification(uri, aTitle, getNotificationBox(browserElement));
+      this._appendFeedReaderNotification(uri, aTitle, getNotificationBox(aContentWindow));
     }
     else
       this._registerContentHandler(contentType, aURIString, aTitle);
   },
 
   /**
    * Appends a notifcation for the given feed reader details.
    *