Bug 1329401 - Rollup updates for FeedConverter.js sync with Firefox as at 20161231 r=IanN a=IanN a=comm-aurora a=comm-beta
authorPhilip Chee <philip.chee@gmail.com>
Sun, 22 Jan 2017 23:47:01 +0800
changeset 31386 1a420d3ee2c640a9688e75ddafd858c6551611e0
parent 31385 6e77a42c18277d218188fee419a2c6ec832822eb
child 31387 025a17fc08a02f40efff11502a465be159ace252
push id1
push userclokep@gmail.com
push dateMon, 07 May 2018 22:45:56 +0000
treeherdercomm-esr60@57eacde5ef40 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN, comm-aurora, comm-beta
bugs1329401, 20161231, 1277685, 1277698, 1165272, 1233899, 1314918, 1199239
Bug 1329401 - Rollup updates for FeedConverter.js sync with Firefox as at 20161231 r=IanN a=IanN a=comm-aurora a=comm-beta (Port Bug 1277685, Bug 1277698, Bug 1165272 Part 2, and Bug 1233899) [sg bugs] Bug 1277685 - Nested feed: URIs should only allow http/https as inner URIs Bug 1277698 - Consider making feed: DANGEROUS_TO_LOAD [normal bugs] Bug 1233899 - fix the feeds converter to use default user context origin attributes Bug 1165272 - Part 2: Replace getNoAppCodebasePrincipal with createCodebasePrincipal. [minor tweaks] Bug 1314918 - Fix most of the remaining no-unused-vars issues. Bug 1199239, remove cpow usage from bookmark this page.
suite/feeds/src/FeedConverter.js
--- a/suite/feeds/src/FeedConverter.js
+++ b/suite/feeds/src/FeedConverter.js
@@ -249,18 +249,20 @@ FeedConverter.prototype = {
 
         // Store the result in the result service so that the display
         // page can access it.
         feedService.addFeedResult(result);
 
         // Now load the actual XUL document.
         var chromeURI = Services.io.newURI(FEEDHANDLER_URI, null, null);
         chromeChannel = Services.io.newChannelFromURIWithLoadInfo(chromeURI, loadInfo);
+        // carry the origin attributes from the channel that loaded the feed.
         chromeChannel.owner = Services.scriptSecurityManager
-                                      .getNoAppCodebasePrincipal(chromeURI);
+                                      .createCodebasePrincipal(chromeURI,
+                                                               loadInfo.originAttributes);
         chromeChannel.originalURI = result.uri;
       }
       else
         chromeChannel = Services.io.newChannelFromURIWithLoadInfo(result.uri, loadInfo);
 
       chromeChannel.loadGroup = this._request.loadGroup;
       chromeChannel.asyncOpen(this._listener, null);
     }
@@ -291,17 +293,18 @@ FeedConverter.prototype = {
       var httpChannel = channel.QueryInterface(Components.interfaces.nsIHttpChannel);
       // Make sure to check requestSucceeded before the potentially-throwing
       // getResponseHeader.
       if (!httpChannel.requestSucceeded) {
         // Just give up, but don't forget to cancel the channel first!
         request.cancel(Components.results.NS_BINDING_ABORTED);
         return;
       }
-      var noSniff = httpChannel.getResponseHeader("X-Moz-Is-Feed");
+      // Note: this throws if the header is not set.
+      httpChannel.getResponseHeader("X-Moz-Is-Feed");
     }
     catch (ex) {
       this._sniffed = true;
     }
 
     this._request = request;
 
     // Save and reset the forced state bit early, in case there's some kind of
@@ -394,17 +397,18 @@ FeedResultService.prototype = {
       break;
 
     default:
       // "web" should have been handled elsewhere
       LOG("unexpected handler: " + handler);
       // fall through
     case "bookmarks":
       var topWindow = Services.wm.getMostRecentWindow("navigator:browser");
-      topWindow.PlacesCommandHook.addLiveBookmark(spec, title, subtitle);
+      topWindow.PlacesCommandHook.addLiveBookmark(spec, title, subtitle)
+                                 .catch(Components.utils.reportError);
       break;
     case "messenger":
       Components.classes["@mozilla.org/newsblog-feed-downloader;1"]
                 .getService(Components.interfaces.nsINewsBlogFeedDownloader)
                 .subscribeToFeed("feed:" + spec, null, null);
       break;
 
     }
@@ -472,17 +476,25 @@ FeedResultService.prototype = {
 function GenericProtocolHandler(scheme, classID) {
   this._http = Services.io.getProtocolHandler("http");
   this.scheme = scheme;
   this.classID = classID;
 }
 
 GenericProtocolHandler.prototype = {
   get protocolFlags() {
-    return this._http.protocolFlags;
+    var httpPref = "browser.feeds.feeds_like_http"
+    if (Services.prefs.getPrefType(httpPref) == Services.prefs.PREF_BOOL &&
+        Services.prefs.getBoolPref(httpPref)) {
+      return this._http.protocolFlags;
+    }
+
+    return this._http.URI_DANGEROUS_TO_LOAD |
+           this._http.ALLOWS_PROXY |
+           this._http.ALLOWS_PROXY_HTTP;
   },
 
   get defaultPort() {
     return this._http.defaultPort;
   },
 
   allowPort: function allowPort(port, scheme) {
     return this._http.allowPort(port, scheme);
@@ -495,23 +507,22 @@ GenericProtocolHandler.prototype = {
 
     spec = spec.replace(/^\s+|[\r\n\t]+|\s+$/g, "");
     if (!/^feed:/.test(spec))
       throw Components.results.NS_ERROR_MALFORMED_URI;
 
     var prefix = /^feed:\/\//.test(spec) ? "http:" : "";
     var inner = Services.io.newURI(spec.replace("feed:", prefix),
                                    originalCharset, baseURI);
-    var netutil = Components.classes["@mozilla.org/network/util;1"]
-                            .getService(Components.interfaces.nsINetUtil);
-    if (netutil.URIChainHasFlags(inner,
-        Components.interfaces.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT))
+
+    if (! /^https?/.test(inner.scheme))
       throw Components.results.NS_ERROR_MALFORMED_URI;
 
-    var uri = netutil.newSimpleNestedURI(inner);
+    var uri = Services.io.QueryInterface(Components.interfaces.nsINetUtil)
+                         .newSimpleNestedURI(inner);
     uri.spec = inner.spec.replace(prefix, "feed:");
     return uri;
   },
 
   newChannel: function newChannel(aUri) {
     return this.newChannel2(aUri, null);
   },