diff options
author | Pale Moon <git-repo@palemoon.org> | 2016-10-05 13:11:54 +0200 |
---|---|---|
committer | Pale Moon <git-repo@palemoon.org> | 2016-10-05 13:11:54 +0200 |
commit | da4d192f8b6d8582483e313e6103c8a3715d83c8 (patch) | |
tree | b5049c33f380b1ceb444923c9dc6a1ba2957be55 | |
parent | fd408e7e1bbd4ebf0ee44233db2e26eaa97f4752 (diff) | |
download | palemoon-gre-da4d192f8b6d8582483e313e6103c8a3715d83c8.tar.gz |
Convert feedwriter to WebIDL and fix access to anonymous content.
Also fix a few small nits/sanity checks while at it.
This resolves #554.
-rw-r--r-- | browser/components/feeds/BrowserFeeds.manifest | 1 | ||||
-rw-r--r-- | browser/components/feeds/FeedConverter.js | 20 | ||||
-rw-r--r-- | browser/components/feeds/FeedWriter.js | 54 | ||||
-rw-r--r-- | browser/components/feeds/WebContentConverter.js | 59 | ||||
-rw-r--r-- | browser/components/feeds/content/subscribe.js | 7 | ||||
-rw-r--r-- | browser/components/feeds/moz.build | 5 | ||||
-rw-r--r-- | browser/components/feeds/nsFeedSniffer.cpp | 6 | ||||
-rw-r--r-- | browser/components/feeds/nsIFeedWriter.idl | 35 |
8 files changed, 87 insertions, 100 deletions
diff --git a/browser/components/feeds/BrowserFeeds.manifest b/browser/components/feeds/BrowserFeeds.manifest index cde5a3f34..a584323f6 100644 --- a/browser/components/feeds/BrowserFeeds.manifest +++ b/browser/components/feeds/BrowserFeeds.manifest @@ -23,7 +23,6 @@ component {1c31ed79-accd-4b94-b517-06e0c81999d5} FeedConverter.js contract @mozilla.org/network/protocol;1?name=pcast {1c31ed79-accd-4b94-b517-06e0c81999d5} component {49bb6593-3aff-4eb3-a068-2712c28bd58e} FeedWriter.js contract @mozilla.org/browser/feeds/result-writer;1 {49bb6593-3aff-4eb3-a068-2712c28bd58e} -category JavaScript-global-constructor BrowserFeedWriter @mozilla.org/browser/feeds/result-writer;1 component {792a7e82-06a0-437c-af63-b2d12e808acc} WebContentConverter.js contract @mozilla.org/embeddor.implemented/web-content-handler-registrar;1 {792a7e82-06a0-437c-af63-b2d12e808acc} category app-startup WebContentConverter service,@mozilla.org/embeddor.implemented/web-content-handler-registrar;1 application={3c2e2abc-06d4-11e1-ac3b-374f68613e61} application={8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4} application={aa3c5121-dab2-40e2-81ca-7ea25febc110} application={a23983c0-fd0e-11dc-95ff-0800200c9a66} diff --git a/browser/components/feeds/FeedConverter.js b/browser/components/feeds/FeedConverter.js index d3c0576b4..75115cc94 100644 --- a/browser/components/feeds/FeedConverter.js +++ b/browser/components/feeds/FeedConverter.js @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* 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/. */ @@ -187,7 +187,7 @@ FeedConverter.prototype = { // types. // // If this is just a feed, not some kind of specialized application, then - // auto-handlers can be set and we should obey them. + // auto-handlers can be set and we should obey them. try { var feedService = Cc["@mozilla.org/browser/feeds/result-service;1"]. @@ -235,6 +235,11 @@ FeedConverter.prototype = { getService(Ci.nsIIOService); var chromeChannel; + // handling a redirect, hence forwarding the loadInfo from the old channel + // to the newchannel. + var oldChannel = this._request.QueryInterface(Ci.nsIChannel); + var loadInfo = oldChannel.loadInfo; + // If there was no automatic handler, or this was a podcast, // photostream or some other kind of application, show the preview page // if the parser returned a document. @@ -246,12 +251,12 @@ FeedConverter.prototype = { // Now load the actual XUL document. var aboutFeedsURI = ios.newURI("about:feeds", null, null); - chromeChannel = ios.newChannelFromURI(aboutFeedsURI, null); + chromeChannel = ios.newChannelFromURIWithLoadInfo(aboutFeedsURI, loadInfo); chromeChannel.originalURI = result.uri; chromeChannel.owner = Services.scriptSecurityManager.getNoAppCodebasePrincipal(aboutFeedsURI); } else { - chromeChannel = ios.newChannelFromURI(result.uri, null); + chromeChannel = ios.newChannelFromURIWithLoadInfo(result.uri, loadInfo); } chromeChannel.loadGroup = this._request.loadGroup; @@ -543,10 +548,12 @@ GenericProtocolHandler.prototype = { return uri; }, - newChannel: function GPH_newChannel(aUri) { + newChannel2: function GPH_newChannel(aUri, aLoadInfo) { var inner = aUri.QueryInterface(Ci.nsINestedURI).innerURI; var channel = Cc["@mozilla.org/network/io-service;1"]. - getService(Ci.nsIIOService).newChannelFromURI(inner, null); + getService(Ci.nsIIOService). + newChannelFromURIWithLoadInfo(inner, aLoadInfo); + if (channel instanceof Components.interfaces.nsIHttpChannel) // Set this so we know this is supposed to be a feed channel.setRequestHeader("X-Moz-Is-Feed", "1", false); @@ -554,6 +561,7 @@ GenericProtocolHandler.prototype = { return channel; }, + QueryInterface: function GPH_QueryInterface(iid) { if (iid.equals(Ci.nsIProtocolHandler) || iid.equals(Ci.nsISupports)) diff --git a/browser/components/feeds/FeedWriter.js b/browser/components/feeds/FeedWriter.js index 7b385b8b4..18de7a7e5 100644 --- a/browser/components/feeds/FeedWriter.js +++ b/browser/components/feeds/FeedWriter.js @@ -1,4 +1,4 @@ -# -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +# -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ # 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/. @@ -221,8 +221,20 @@ FeedWriter.prototype = { */ __contentSandbox: null, get _contentSandbox() { + // This whole sandbox setup is totally archaic. It was introduced in bug + // 360529, presumably before the existence of a solid security membrane, + // since all of the manipulation of content here should be made safe by + // Xrays. + // Now that anonymous content is no longer content-accessible, manipulating + // the xml stylesheet content can't be done from content anymore. + // + // The right solution would be to rip out all of this sandbox junk and + // manipulate the DOM directly, but that would require a lot of rewriting. + // So, for now, we just give the sandbox an nsExpandedPrincipal with []. + // This has the effect of giving it Xrays, and making it same-origin with + // the XBL scope, thereby letting it manipulate anonymous content. if (!this.__contentSandbox) - this.__contentSandbox = new Cu.Sandbox(this._window, + this.__contentSandbox = new Cu.Sandbox([this._window], {sandboxName: 'FeedWriter'}); return this.__contentSandbox; @@ -302,7 +314,7 @@ FeedWriter.prototype = { }, /** - * Returns a date suitable for displaying in the feed preview. + * Returns a date suitable for displaying in the feed preview. * If the date cannot be parsed, the return value is "false". * @param dateString * A date as extracted from a feed entry. (entry.updated) @@ -876,7 +888,13 @@ FeedWriter.prototype = { switch (handler) { case "web": { if (this._handlersMenuList) { - var url = prefs.getComplexValue(getPrefWebForType(feedType), Ci.nsISupportsString).data; + var url; + try { + url = prefs.getComplexValue(getPrefWebForType(feedType), Ci.nsISupportsString).data; + } catch (ex) { + LOG("FeedWriter._setSelectedHandler: invalid or no handler in prefs"); + return; + } var handlers = this._handlersMenuList.getElementsByAttribute("webhandlerurl", url); if (handlers.length == 0) { @@ -1026,6 +1044,10 @@ FeedWriter.prototype = { var handlers = wccr.getContentHandlers(this._getMimeTypeForFeedType(feedType)); if (handlers.length != 0) { for (var i = 0; i < handlers.length; ++i) { + if (!handlers[i].uri) { + LOG("Handler with name " + handlers[i].name + " has no URI!? Skipping..."); + continue; + } menuItem = liveBookmarksMenuItem.cloneNode(false); menuItem.removeAttribute("selected"); menuItem.className = "menuitem-iconic"; @@ -1106,9 +1128,19 @@ FeedWriter.prototype = { getInterface(Ci.nsIWebNavigation). QueryInterface(Ci.nsIDocShell).currentDocumentChannel; + var nullPrincipal = Cc["@mozilla.org/nullprincipal;1"]. + createInstance(Ci.nsIPrincipal); + var resolvedURI = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService). - newChannel("about:feeds", null, null).URI; + newChannel2("about:feeds", + null, + null, + null, // aLoadingNode + nullPrincipal, + null, // aTriggeringPrincipal + Ci.nsILoadInfo.SEC_NORMAL, + Ci.nsIContentPolicy.TYPE_OTHER).URI; if (resolvedURI.equals(chan.URI)) return chan.originalURI; @@ -1122,7 +1154,7 @@ FeedWriter.prototype = { _feedPrincipal: null, _handlersMenuList: null, - // nsIFeedWriter + // BrowserFeedWriter WebIDL methods init: function FW_init(aWindow) { var window = aWindow; this._feedURI = this._getOriginalURI(window); @@ -1375,13 +1407,9 @@ FeedWriter.prototype = { }, classID: FEEDWRITER_CID, - classInfo: XPCOMUtils.generateCI({classID: FEEDWRITER_CID, - contractID: FEEDWRITER_CONTRACTID, - interfaces: [Ci.nsIFeedWriter], - flags: Ci.nsIClassInfo.DOM_OBJECT}), - QueryInterface: XPCOMUtils.generateQI([Ci.nsIFeedWriter, - Ci.nsIDOMEventListener, Ci.nsIObserver, - Ci.nsINavHistoryObserver]) + QueryInterface: XPCOMUtils.generateQI([Ci.nsIDOMEventListener, Ci.nsIObserver, + Ci.nsINavHistoryObserver, + Ci.nsIDOMGlobalPropertyInitializer]) }; this.NSGetFactory = XPCOMUtils.generateNSGetFactory([FeedWriter]); diff --git a/browser/components/feeds/WebContentConverter.js b/browser/components/feeds/WebContentConverter.js index ecdbb7590..56bed08b1 100644 --- a/browser/components/feeds/WebContentConverter.js +++ b/browser/components/feeds/WebContentConverter.js @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* 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/. */ @@ -308,7 +308,8 @@ WebContentConverterRegistrar.prototype = { function WCCR_checkAndGetURI(aURIString, aContentWindow) { try { - var uri = this._makeURI(aURIString); + let baseURI = aContentWindow.document.baseURIObject; + var uri = this._makeURI(aURIString, null, baseURI); } catch (ex) { // not supposed to throw according to spec return; @@ -369,6 +370,13 @@ WebContentConverterRegistrar.prototype = { function WCCR_registerProtocolHandler(aProtocol, aURIString, aTitle, aContentWindow) { LOG("registerProtocolHandler(" + aProtocol + "," + aURIString + "," + aTitle + ")"); + var uri = this._checkAndGetURI(aURIString, aContentWindow); + + // If the protocol handler is already registered, just return early. + if (this._protocolHandlerRegistered(aProtocol, uri.spec)) { + return; + } + var browserWindow = this._getBrowserWindowForContentWindow(aContentWindow); if (PrivateBrowsingUtils.isWindowPrivate(browserWindow)) { // Inside the private browsing mode, we don't want to alert the user to save @@ -406,25 +414,18 @@ WebContentConverterRegistrar.prototype = { throw("Not allowed to register a protocol handler for " + aProtocol); } - var uri = this._checkAndGetURI(aURIString, aContentWindow); - - var buttons, message; - if (this._protocolHandlerRegistered(aProtocol, uri.spec)) - message = this._getFormattedString("protocolHandlerRegistered", - [aTitle, aProtocol]); - else { - // Now Ask the user and provide the proper callback - message = this._getFormattedString("addProtocolHandler", - [aTitle, uri.host, aProtocol]); + // Now Ask the user and provide the proper callback + var message = this._getFormattedString("addProtocolHandler", + [aTitle, uri.host, aProtocol]); - var notificationIcon = uri.prePath + "/favicon.ico"; - var notificationValue = "Protocol Registration: " + aProtocol; - var addButton = { - label: this._getString("addProtocolHandlerAddButton"), - accessKey: this._getString("addHandlerAddButtonAccesskey"), - protocolInfo: { protocol: aProtocol, uri: uri.spec, name: aTitle }, + var notificationIcon = uri.prePath + "/favicon.ico"; + var notificationValue = "Protocol Registration: " + aProtocol; + var addButton = { + label: this._getString("addProtocolHandlerAddButton"), + accessKey: this._getString("addHandlerAddButtonAccesskey"), + protocolInfo: { protocol: aProtocol, uri: uri.spec, name: aTitle }, - callback: + callback: function WCCR_addProtocolHandlerButtonCallback(aNotification, aButtonInfo) { var protocol = aButtonInfo.protocolInfo.protocol; var uri = aButtonInfo.protocolInfo.uri; @@ -450,18 +451,14 @@ WebContentConverterRegistrar.prototype = { getService(Ci.nsIHandlerService); hs.store(handlerInfo); } - }; - buttons = [addButton]; - } - - + }; var browserElement = this._getBrowserForContentWindow(browserWindow, aContentWindow); - var notificationBox = browserWindow.getBrowser().getNotificationBox(browserElement); + var notificationBox = browserWindow.gBrowser.getNotificationBox(browserElement); notificationBox.appendNotification(message, notificationValue, notificationIcon, notificationBox.PRIORITY_INFO_LOW, - buttons); + [addButton]); }, /** @@ -485,7 +482,7 @@ WebContentConverterRegistrar.prototype = { var browserWindow = this._getBrowserWindowForContentWindow(aContentWindow); var browserElement = this._getBrowserForContentWindow(browserWindow, aContentWindow); - var notificationBox = browserWindow.getBrowser().getNotificationBox(browserElement); + var notificationBox = browserWindow.gBrowser.getNotificationBox(browserElement); this._appendFeedReaderNotification(uri, aTitle, notificationBox); } else @@ -520,7 +517,7 @@ WebContentConverterRegistrar.prototype = { function WCCR__getBrowserForContentWindow(aBrowserWindow, aContentWindow) { // This depends on pseudo APIs of browser.js and tabbrowser.xml aContentWindow = aContentWindow.top; - var browsers = aBrowserWindow.getBrowser().browsers; + var browsers = aBrowserWindow.gBrowser.browsers; for (var i = 0; i < browsers.length; ++i) { if (browsers[i].contentWindow == aContentWindow) return browsers[i]; @@ -878,12 +875,6 @@ WebContentConverterRegistrar.prototype = { }, classID: WCCR_CLASSID, - classInfo: XPCOMUtils.generateCI({classID: WCCR_CLASSID, - contractID: WCCR_CONTRACTID, - interfaces: [Ci.nsIWebContentConverterService, - Ci.nsIWebContentHandlerRegistrar, - Ci.nsIObserver, Ci.nsIFactory], - flags: Ci.nsIClassInfo.DOM_OBJECT}), /** * See nsISupports diff --git a/browser/components/feeds/content/subscribe.js b/browser/components/feeds/content/subscribe.js index c8cb3a03a..ab2eac4eb 100644 --- a/browser/components/feeds/content/subscribe.js +++ b/browser/components/feeds/content/subscribe.js @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ /* 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/. */ @@ -11,7 +11,6 @@ var SubscribeHandler = { init: function SH_init() { this._feedWriter = new BrowserFeedWriter(); - this._feedWriter.init(window); }, writeContent: function SH_writeContent() { @@ -20,9 +19,5 @@ var SubscribeHandler = { uninit: function SH_uninit() { this._feedWriter.close(); - }, - - subscribe: function SH_subscribe() { - this._feedWriter.subscribe(); } }; diff --git a/browser/components/feeds/moz.build b/browser/components/feeds/moz.build index e17d104e2..9c5e83902 100644 --- a/browser/components/feeds/moz.build +++ b/browser/components/feeds/moz.build @@ -8,7 +8,6 @@ JAR_MANIFESTS += ['jar.mn'] XPIDL_SOURCES += [ 'nsIFeedResultService.idl', - 'nsIFeedWriter.idl', 'nsIWebContentConverterRegistrar.idl', ] @@ -35,4 +34,6 @@ for var in ('MOZ_APP_NAME', 'MOZ_MACBUNDLE_NAME'): LOCAL_INCLUDES += [ '../build', -]
\ No newline at end of file +] + +FAIL_ON_WARNINGS = True diff --git a/browser/components/feeds/nsFeedSniffer.cpp b/browser/components/feeds/nsFeedSniffer.cpp index 487acf6b1..61cc77bdd 100644 --- a/browser/components/feeds/nsFeedSniffer.cpp +++ b/browser/components/feeds/nsFeedSniffer.cpp @@ -40,9 +40,9 @@ #define MAX_BYTES 512u NS_IMPL_ISUPPORTS(nsFeedSniffer, - nsIContentSniffer, - nsIStreamListener, - nsIRequestObserver) + nsIContentSniffer, + nsIStreamListener, + nsIRequestObserver) nsresult nsFeedSniffer::ConvertEncodedData(nsIRequest* request, diff --git a/browser/components/feeds/nsIFeedWriter.idl b/browser/components/feeds/nsIFeedWriter.idl deleted file mode 100644 index 4018067a9..000000000 --- a/browser/components/feeds/nsIFeedWriter.idl +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -#include "nsISupports.idl" - -interface nsIDOMWindow; - -/** - * Instances of this component write UI into the display page. This component - * is trusted so can access preferences etc, but page content isn't and so - * cannot. - */ -[scriptable, uuid(67003393-018c-4e96-af10-c6c51a049fad)] -interface nsIFeedWriter : nsISupports -{ - /** - * Initializes the feed writer and loads the feed subscription UI. - * @param aWindow - * The DOMWindow of the preview page. - * window.location.href == the URI of the feed. - */ - void init(in nsIDOMWindow aWindow); - - /** - * Writes the feed content, assumes that the feed writer is initialized. - */ - void writeContent(); - - /** - * Uninitialize the feed writer. - */ - void close(); -}; |