Initial import of feed processor
This imports Mozilla's feed processor which has been removed upstream as part of Firefox 66. Some changes are likely needed before this will actually run in Zotero.
This commit is contained in:
parent
65369ebb47
commit
48a6e90b4f
11 changed files with 2291 additions and 0 deletions
1735
resource/feeds/FeedProcessor.js
Normal file
1735
resource/feeds/FeedProcessor.js
Normal file
File diff suppressed because it is too large
Load diff
86
resource/feeds/nsIFeed.idl
Normal file
86
resource/feeds/nsIFeed.idl
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* -*- 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 "nsIFeedContainer.idl"
|
||||
|
||||
interface nsIArray;
|
||||
interface nsIFeedGenerator;
|
||||
|
||||
/**
|
||||
* An nsIFeed represents a single Atom or RSS feed.
|
||||
*/
|
||||
[scriptable, uuid(3b8aae33-80e2-4efa-99c8-a6c5b99f76ea)]
|
||||
interface nsIFeed : nsIFeedContainer
|
||||
{
|
||||
/**
|
||||
* Uses description, subtitle, and extensions
|
||||
* to generate a summary.
|
||||
*/
|
||||
attribute nsIFeedTextConstruct subtitle;
|
||||
|
||||
// All content classifies as a "feed" - it is the transport.
|
||||
const unsigned long TYPE_FEED = 0;
|
||||
const unsigned long TYPE_AUDIO = 1;
|
||||
const unsigned long TYPE_IMAGE = 2;
|
||||
const unsigned long TYPE_VIDEO = 4;
|
||||
|
||||
/**
|
||||
* The type of feed. For example, a podcast would be TYPE_AUDIO.
|
||||
*/
|
||||
readonly attribute unsigned long type;
|
||||
|
||||
/**
|
||||
* The total number of enclosures found in the feed.
|
||||
*/
|
||||
attribute long enclosureCount;
|
||||
|
||||
/**
|
||||
* The items or entries in feed.
|
||||
*/
|
||||
attribute nsIArray items;
|
||||
|
||||
/**
|
||||
* No one really knows what cloud is for.
|
||||
*
|
||||
* It supposedly enables some sort of interaction with an XML-RPC or
|
||||
* SOAP service.
|
||||
*/
|
||||
attribute nsIWritablePropertyBag2 cloud;
|
||||
|
||||
/**
|
||||
* Information about the software that produced the feed.
|
||||
*/
|
||||
attribute nsIFeedGenerator generator;
|
||||
|
||||
/**
|
||||
* An image url and some metadata (as defined by RSS2).
|
||||
*
|
||||
*/
|
||||
attribute nsIWritablePropertyBag2 image;
|
||||
|
||||
/**
|
||||
* No one really knows what textInput is for.
|
||||
*
|
||||
* See
|
||||
* <http://www.cadenhead.org/workbench/news/2894/rss-joy-textinput>
|
||||
* for more details.
|
||||
*/
|
||||
attribute nsIWritablePropertyBag2 textInput;
|
||||
|
||||
/**
|
||||
* Days to skip fetching. This field was supposed to designate
|
||||
* intervals for feed fetching. It's not generally implemented. For
|
||||
* example, if this array contained "Monday", aggregators should not
|
||||
* fetch the feed on Mondays.
|
||||
*/
|
||||
attribute nsIArray skipDays;
|
||||
|
||||
/**
|
||||
* Hours to skip fetching. This field was supposed to designate
|
||||
* intervals for feed fetching. It's not generally implemented. See
|
||||
* <http://blogs.law.harvard.edu/tech/rss> for more information.
|
||||
*/
|
||||
attribute nsIArray skipHours;
|
||||
};
|
85
resource/feeds/nsIFeedContainer.idl
Normal file
85
resource/feeds/nsIFeedContainer.idl
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* -*- 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 "nsIFeedElementBase.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIWritablePropertyBag2;
|
||||
interface nsIArray;
|
||||
interface nsIFeedTextConstruct;
|
||||
|
||||
/**
|
||||
* A shared base for feeds and items, which are pretty similar,
|
||||
* but they have some divergent attributes and require
|
||||
* different convenience methods.
|
||||
*/
|
||||
[scriptable, uuid(577a1b4c-b3d4-4c76-9cf8-753e6606114f)]
|
||||
interface nsIFeedContainer : nsIFeedElementBase
|
||||
{
|
||||
/**
|
||||
* Many feeds contain an ID distinct from their URI, and
|
||||
* entries have standard fields for this in all major formats.
|
||||
*/
|
||||
attribute AString id;
|
||||
|
||||
/**
|
||||
* The fields found in the document. Common Atom
|
||||
* and RSS fields are normalized. This includes some namespaced
|
||||
* extensions such as dc:subject and content:encoded.
|
||||
* Consumers can avoid normalization by checking the feed type
|
||||
* and accessing specific fields.
|
||||
*
|
||||
* Common namespaces are accessed using prefixes, like get("dc:subject");.
|
||||
* See nsIFeedResult::registerExtensionPrefix.
|
||||
*/
|
||||
attribute nsIWritablePropertyBag2 fields;
|
||||
|
||||
/**
|
||||
* Sometimes there's no title, or the title contains markup, so take
|
||||
* care in decoding the attribute.
|
||||
*/
|
||||
attribute nsIFeedTextConstruct title;
|
||||
|
||||
/**
|
||||
* Returns the primary link for the feed or entry.
|
||||
*/
|
||||
attribute nsIURI link;
|
||||
|
||||
/**
|
||||
* Returns all links for a feed or entry.
|
||||
*/
|
||||
attribute nsIArray links;
|
||||
|
||||
/**
|
||||
* Returns the categories found in a feed or entry.
|
||||
*/
|
||||
attribute nsIArray categories;
|
||||
|
||||
/**
|
||||
* The rights or license associated with a feed or entry.
|
||||
*/
|
||||
attribute nsIFeedTextConstruct rights;
|
||||
|
||||
/**
|
||||
* A list of nsIFeedPersons that authored the feed.
|
||||
*/
|
||||
attribute nsIArray authors;
|
||||
|
||||
/**
|
||||
* A list of nsIFeedPersons that contributed to the feed.
|
||||
*/
|
||||
attribute nsIArray contributors;
|
||||
|
||||
/**
|
||||
* The date the feed was updated, in RFC822 form. Parsable by JS
|
||||
* and mail code.
|
||||
*/
|
||||
attribute AString updated;
|
||||
|
||||
/**
|
||||
* Syncs a container's fields with its convenience attributes.
|
||||
*/
|
||||
void normalize();
|
||||
};
|
28
resource/feeds/nsIFeedElementBase.idl
Normal file
28
resource/feeds/nsIFeedElementBase.idl
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* -*- 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 nsISAXAttributes;
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* An nsIFeedGenerator represents the software used to create a feed.
|
||||
*/
|
||||
[scriptable, uuid(5215291e-fa0a-40c2-8ce7-e86cd1a1d3fa)]
|
||||
interface nsIFeedElementBase : nsISupports
|
||||
{
|
||||
/**
|
||||
* The attributes found on the element. Most interfaces provide convenience
|
||||
* accessors for their standard fields, so this useful only when looking for
|
||||
* an extension.
|
||||
*/
|
||||
attribute nsISAXAttributes attributes;
|
||||
|
||||
/**
|
||||
* The baseURI for the Entry or Feed.
|
||||
*/
|
||||
attribute nsIURI baseURI;
|
||||
};
|
46
resource/feeds/nsIFeedEntry.idl
Normal file
46
resource/feeds/nsIFeedEntry.idl
Normal file
|
@ -0,0 +1,46 @@
|
|||
/* -*- 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 "nsIFeedContainer.idl"
|
||||
interface nsIArray;
|
||||
|
||||
/**
|
||||
* An nsIFeedEntry represents an Atom or RSS entry/item. Summary
|
||||
* and/or full-text content may be available, but callers will have to
|
||||
* check both.
|
||||
*/
|
||||
[scriptable, uuid(31bfd5b4-8ff5-4bfd-a8cb-b3dfbd4f0a5b)]
|
||||
interface nsIFeedEntry : nsIFeedContainer {
|
||||
|
||||
/**
|
||||
* Uses description, subtitle, summary, content and extensions
|
||||
* to generate a summary.
|
||||
*
|
||||
*/
|
||||
attribute nsIFeedTextConstruct summary;
|
||||
|
||||
/**
|
||||
* The date the entry was published, in RFC822 form. Parsable by JS
|
||||
* and mail code.
|
||||
*/
|
||||
attribute AString published;
|
||||
|
||||
/**
|
||||
* Uses atom:content and content:encoded to provide
|
||||
* a 'full text' view of an entry.
|
||||
*
|
||||
*/
|
||||
attribute nsIFeedTextConstruct content;
|
||||
|
||||
/**
|
||||
* Enclosures are podcasts, photocasts, etc.
|
||||
*/
|
||||
attribute nsIArray enclosures;
|
||||
|
||||
/**
|
||||
* Enclosures, etc. that might be displayed inline.
|
||||
*/
|
||||
attribute nsIArray mediaContent;
|
||||
};
|
30
resource/feeds/nsIFeedGenerator.idl
Normal file
30
resource/feeds/nsIFeedGenerator.idl
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* -*- 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 "nsIFeedElementBase.idl"
|
||||
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* An nsIFeedGenerator represents the software used to create a feed.
|
||||
*/
|
||||
[scriptable, uuid(0fecd56b-bd92-481b-a486-b8d489cdd385)]
|
||||
interface nsIFeedGenerator : nsIFeedElementBase
|
||||
{
|
||||
/**
|
||||
* The name of the software.
|
||||
*/
|
||||
attribute AString agent;
|
||||
|
||||
/**
|
||||
* The version of the software.
|
||||
*/
|
||||
attribute AString version;
|
||||
|
||||
/**
|
||||
* A URI associated with the software.
|
||||
*/
|
||||
attribute nsIURI uri;
|
||||
};
|
87
resource/feeds/nsIFeedListener.idl
Normal file
87
resource/feeds/nsIFeedListener.idl
Normal file
|
@ -0,0 +1,87 @@
|
|||
/* -*- 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 nsIFeedResult;
|
||||
interface nsIFeedEntry;
|
||||
|
||||
/**
|
||||
* nsIFeedResultListener defines a callback used when feed processing
|
||||
* completes.
|
||||
*/
|
||||
[scriptable, uuid(4d2ebe88-36eb-4e20-bcd1-997b3c1f24ce)]
|
||||
interface nsIFeedResultListener : nsISupports
|
||||
{
|
||||
/**
|
||||
* Always called, even after an error. There could be new feed-level
|
||||
* data available at this point, if it followed or was interspersed
|
||||
* with the items. Fire-and-Forget implementations only need this.
|
||||
*
|
||||
* @param result
|
||||
* An object implementing nsIFeedResult representing the feed
|
||||
* and its metadata.
|
||||
*/
|
||||
void handleResult(in nsIFeedResult result);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* nsIFeedProgressListener defines callbacks used during feed
|
||||
* processing.
|
||||
*/
|
||||
[scriptable, uuid(ebfd5de5-713c-40c0-ad7c-f095117fa580)]
|
||||
interface nsIFeedProgressListener : nsIFeedResultListener {
|
||||
|
||||
/**
|
||||
* ReportError will be called in the event of fatal
|
||||
* XML errors, or if the document is not a feed. The bozo
|
||||
* bit will be set if the error was due to a fatal error.
|
||||
*
|
||||
* @param errorText
|
||||
* A short description of the error.
|
||||
* @param lineNumber
|
||||
* The line on which the error occurred.
|
||||
*/
|
||||
void reportError(in AString errorText, in long lineNumber,
|
||||
in boolean bozo);
|
||||
|
||||
/**
|
||||
* StartFeed will be called as soon as a reasonable start to
|
||||
* a feed is detected.
|
||||
*
|
||||
* @param result
|
||||
* An object implementing nsIFeedResult representing the feed
|
||||
* and its metadata. At this point, the result has version
|
||||
* information.
|
||||
*/
|
||||
void handleStartFeed(in nsIFeedResult result);
|
||||
|
||||
/**
|
||||
* Called when the first entry/item is encountered. In Atom, all
|
||||
* feed data is required to preceed the entries. In RSS, the data
|
||||
* usually does. If the type is one of the entry/item-only types,
|
||||
* this event will not be called.
|
||||
*
|
||||
* @param result
|
||||
* An object implementing nsIFeedResult representing the feed
|
||||
* and its metadata. At this point, the result will likely have
|
||||
* most of its feed-level metadata.
|
||||
*/
|
||||
void handleFeedAtFirstEntry(in nsIFeedResult result);
|
||||
|
||||
/**
|
||||
* Called after each entry/item. If the document is a standalone
|
||||
* item or entry, this HandleFeedAtFirstEntry will not have been
|
||||
* called. Also, this entry's parent field will be null.
|
||||
*
|
||||
* @param entry
|
||||
* An object implementing nsIFeedEntry that represents the latest
|
||||
* entry encountered.
|
||||
* @param result
|
||||
* An object implementing nsIFeedResult representing the feed
|
||||
* and its metadata.
|
||||
*/
|
||||
void handleEntry(in nsIFeedEntry entry, in nsIFeedResult result);
|
||||
};
|
30
resource/feeds/nsIFeedPerson.idl
Normal file
30
resource/feeds/nsIFeedPerson.idl
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* -*- 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 "nsIFeedElementBase.idl"
|
||||
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* An nsIFeedPerson represents an author or contributor of a feed.
|
||||
*/
|
||||
[scriptable, uuid(29cbd45f-f2d3-4b28-b557-3ab7a61ecde4)]
|
||||
interface nsIFeedPerson : nsIFeedElementBase
|
||||
{
|
||||
/**
|
||||
* The name of the person.
|
||||
*/
|
||||
attribute AString name;
|
||||
|
||||
/**
|
||||
* An email address associated with the person.
|
||||
*/
|
||||
attribute AString email;
|
||||
|
||||
/**
|
||||
* A URI associated with the person (e.g. a homepage).
|
||||
*/
|
||||
attribute nsIURI uri;
|
||||
};
|
41
resource/feeds/nsIFeedProcessor.idl
Normal file
41
resource/feeds/nsIFeedProcessor.idl
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* -*- 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 "nsIStreamListener.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIFeedResultListener;
|
||||
interface nsIInputStream;
|
||||
|
||||
/**
|
||||
* An nsIFeedProcessor parses feeds, triggering callbacks based on
|
||||
* their contents.
|
||||
*/
|
||||
[scriptable, uuid(8a0b2908-21b0-45d7-b14d-30df0f92afc7)]
|
||||
interface nsIFeedProcessor : nsIStreamListener {
|
||||
|
||||
/**
|
||||
* The listener that will respond to feed events.
|
||||
*/
|
||||
attribute nsIFeedResultListener listener;
|
||||
|
||||
// Level is where to listen for the extension, a constant: FEED,
|
||||
// ENTRY, BOTH.
|
||||
//
|
||||
// XXX todo void registerExtensionHandler(in
|
||||
// nsIFeedExtensionHandler, in long level);
|
||||
|
||||
/**
|
||||
* Parse a feed asynchronously. The caller must then call the
|
||||
* nsIFeedProcessor's nsIStreamListener methods to drive the
|
||||
* parse. Do not call the other parse methods during an asynchronous
|
||||
* parse.
|
||||
*
|
||||
* @param requestObserver The observer to notify on start/stop. This
|
||||
* argument can be null.
|
||||
* @param uri The base URI.
|
||||
*/
|
||||
void parseAsync(in nsIRequestObserver requestObserver, in nsIURI uri);
|
||||
};
|
65
resource/feeds/nsIFeedResult.idl
Normal file
65
resource/feeds/nsIFeedResult.idl
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* -*- 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 nsIFeedContainer;
|
||||
interface nsIProperties;
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* The nsIFeedResult interface provides access to HTTP and parsing
|
||||
* metadata for a feed or entry.
|
||||
*/
|
||||
[scriptable, uuid(7a180b78-0f46-4569-8c22-f3d720ea1c57)]
|
||||
interface nsIFeedResult : nsISupports {
|
||||
|
||||
/**
|
||||
* The Feed parser will set the bozo bit when a feed triggers a fatal
|
||||
* error during XML parsing. There may be entries and feed metadata
|
||||
* that were parsed before the error. Thanks to Tim Bray for
|
||||
* suggesting this terminology.
|
||||
* <http://www.tbray.org/ongoing/When/200x/2004/01/11/PostelPilgrim>
|
||||
*/
|
||||
attribute boolean bozo;
|
||||
|
||||
/**
|
||||
* The parsed feed or entry.
|
||||
*
|
||||
* Will be null if a non-feed is processed.
|
||||
*/
|
||||
attribute nsIFeedContainer doc;
|
||||
|
||||
/**
|
||||
* The address from which the feed was fetched.
|
||||
*/
|
||||
attribute nsIURI uri;
|
||||
|
||||
/**
|
||||
* Feed Version:
|
||||
* atom, rss2, rss09, rss091, rss091userland, rss092, rss1, atom03,
|
||||
* atomEntry, rssItem
|
||||
*
|
||||
* Will be null if a non-feed is processed.
|
||||
*/
|
||||
attribute AString version;
|
||||
|
||||
/**
|
||||
* An XSLT stylesheet available to transform the source of the
|
||||
* feed. Some feeds include this information in a processing
|
||||
* instruction. It's generally intended for clients with specific
|
||||
* feed capabilities.
|
||||
*/
|
||||
attribute nsIURI stylesheet;
|
||||
|
||||
/**
|
||||
* HTTP response headers that accompanied the feed.
|
||||
*/
|
||||
attribute nsIProperties headers;
|
||||
|
||||
/**
|
||||
* Registers a prefix used to access an extension in the feed/entry
|
||||
*/
|
||||
void registerExtensionPrefix(in AString aNamespace, in AString aPrefix);
|
||||
};
|
58
resource/feeds/nsIFeedTextConstruct.idl
Normal file
58
resource/feeds/nsIFeedTextConstruct.idl
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* -*- 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 nsIURI;
|
||||
|
||||
webidl DocumentFragment;
|
||||
webidl Element;
|
||||
|
||||
/**
|
||||
* nsIFeedTextConstructs represent feed text fields that can contain
|
||||
* one of text, HTML, or XHTML. Some extension elements also have "type"
|
||||
* parameters, and this interface could be used there as well.
|
||||
*/
|
||||
[scriptable, uuid(fc97a2a9-d649-4494-931e-db81a156c873)]
|
||||
interface nsIFeedTextConstruct : nsISupports
|
||||
{
|
||||
/**
|
||||
* If the text construct contains (X)HTML, relative references in
|
||||
* the content should be resolved against this base URI.
|
||||
*/
|
||||
attribute nsIURI base;
|
||||
|
||||
/**
|
||||
* The language of the text. For example, "en-US" for US English.
|
||||
*/
|
||||
attribute AString lang;
|
||||
|
||||
/**
|
||||
* One of "text", "html", or "xhtml". If the type is (x)html, a '<'
|
||||
* character represents markup. To display that character, an escape
|
||||
* such as < must be used. If the type is "text", the '<'
|
||||
* character represents the character itself, and such text should
|
||||
* not be embedded in markup without escaping it first.
|
||||
*/
|
||||
attribute AString type;
|
||||
|
||||
/**
|
||||
* The content of the text construct.
|
||||
*/
|
||||
attribute AString text;
|
||||
|
||||
/**
|
||||
* Returns the text of the text construct, with all markup stripped
|
||||
* and all entities decoded. If the type attribute's value is "text",
|
||||
* this function returns the value of the text attribute unchanged.
|
||||
*/
|
||||
AString plainText();
|
||||
|
||||
/**
|
||||
* Return an nsIDocumentFragment containing the text and markup.
|
||||
*/
|
||||
DocumentFragment createDocumentFragment(in Element element);
|
||||
};
|
||||
|
Loading…
Reference in a new issue