зеркало из https://github.com/mozilla/gecko-dev.git
did not mean to check this in yet
This commit is contained in:
Родитель
af3de284f7
Коммит
a312aea7b0
|
@ -451,13 +451,16 @@ pref("browser.send_pings", true);
|
|||
#ifdef MOZ_FEEDS
|
||||
// XXXben This is just here for demo purposes until web registration works!
|
||||
// XXXben Needs Localization!
|
||||
pref("browser.contentHandlers.types.0.title", "Bloglines");
|
||||
pref("browser.contentHandlers.types.0.uri", "http://www.bloglines.com/login?r=/sub/%s");
|
||||
pref("browser.contentHandlers.types.0.title", "Netvibes");
|
||||
pref("browser.contentHandlers.types.0.uri", "http://www.netvibes.com/subscribe.php?url=%s");
|
||||
pref("browser.contentHandlers.types.0.type", "application/vnd.mozilla.maybe.feed");
|
||||
pref("browser.contentHandlers.types.1.title", "iGoogle/Google Reader");
|
||||
pref("browser.contentHandlers.types.1.uri", "http://fusion.google.com/add?feedurl=%s");
|
||||
pref("browser.contentHandlers.types.1.title", "My Yahoo");
|
||||
pref("browser.contentHandlers.types.1.uri", "http://add.my.yahoo.com/rss?url=%s");
|
||||
pref("browser.contentHandlers.types.1.type", "application/vnd.mozilla.maybe.feed");
|
||||
pref("browser.contentHandlers.types.2.title", "My Yahoo");
|
||||
pref("browser.contentHandlers.types.2.uri", "http://add.my.yahoo.com/rss?url=%s");
|
||||
pref("browser.contentHandlers.types.2.title", "Bloglines");
|
||||
pref("browser.contentHandlers.types.2.uri", "http://www.bloglines.com/login?r=/sub/%s");
|
||||
pref("browser.contentHandlers.types.2.type", "application/vnd.mozilla.maybe.feed");
|
||||
pref("browser.contentHandlers.types.3.title", "iGoogle/Google Reader");
|
||||
pref("browser.contentHandlers.types.3.uri", "http://fusion.google.com/add?feedurl=%s");
|
||||
pref("browser.contentHandlers.types.3.type", "application/vnd.mozilla.maybe.feed");
|
||||
#endif
|
||||
|
|
|
@ -110,84 +110,6 @@ nsFeedSniffer::ConvertEncodedData(nsIRequest* request,
|
|||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Determine if a substring is the "documentElement" in the document.
|
||||
*
|
||||
* All of our sniffed substrings: <rss, <feed, <rdf:RDF must be the "document"
|
||||
* element within the XML DOM, i.e. the root container element. Otherwise,
|
||||
* it's possible that someone embedded one of these tags inside a document of
|
||||
* another type, e.g. a HTML document, and we don't want to show the preview
|
||||
* page if the document isn't actually a feed.
|
||||
*
|
||||
* @param dataString
|
||||
* The data being sniffed
|
||||
* @param substring
|
||||
* The substring being tested for document-element-ness
|
||||
* @param indicator
|
||||
* An iterator initialized to the end of |substring|, located in
|
||||
* |dataString|
|
||||
* @returns PR_TRUE if the substring is the documentElement, PR_FALSE
|
||||
* otherwise.
|
||||
*/
|
||||
static PRBool
|
||||
IsDocumentElement(nsACString& dataString, const nsACString& substring,
|
||||
nsACString::const_iterator& indicator)
|
||||
{
|
||||
nsACString::const_iterator start, end, endOfString;
|
||||
|
||||
dataString.BeginReading(start);
|
||||
endOfString = end = indicator;
|
||||
|
||||
// For every tag in the buffer, check to see if it's a PI, Doctype or
|
||||
// comment, our desired substring or something invalid.
|
||||
while (FindCharInReadable('<', start, end)) {
|
||||
++start;
|
||||
if (start == endOfString)
|
||||
return PR_FALSE;
|
||||
|
||||
// Check to see if the character following the '<' is either '?' or '!'
|
||||
// (processing instruction or doctype or comment)... these are valid nodes
|
||||
// to have in the prologue.
|
||||
if (*start != '?' && *start != '!') {
|
||||
// Check to see if the string following the '<' is our indicator substring.
|
||||
// If it's not, it's an indication that the indicator substring was
|
||||
// embedded in some other kind of document, e.g. HTML.
|
||||
return substring.Equals(Substring(--start, indicator));
|
||||
}
|
||||
// Now advance the iterator until the '>' (We do this because we don't want
|
||||
// to sniff indicator substrings that are embedded within other nodes, e.g.
|
||||
// comments: <!-- <rdf:RDF .. > -->
|
||||
if (!FindCharInReadable('>', start, end))
|
||||
return PR_FALSE;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not a string exists as the root element in an XML data
|
||||
* string buffer.
|
||||
* @param dataString
|
||||
* The data being sniffed
|
||||
* @param substring
|
||||
* The substring being tested for existence and root-ness.
|
||||
* @returns PR_TRUE if the substring exists and is the documentElement, PR_FALSE
|
||||
* otherwise.
|
||||
*/
|
||||
static PRBool
|
||||
ContainsTopLevelSubstring(nsACString& dataString, const nsACString& substring)
|
||||
{
|
||||
nsACString::const_iterator start, end;
|
||||
|
||||
dataString.BeginReading(start);
|
||||
dataString.EndReading(end);
|
||||
|
||||
PRBool isFeed = FindInReadable(substring, start, end);
|
||||
|
||||
// Only do the validation when we find the substring.
|
||||
return isFeed ? IsDocumentElement(dataString, substring, end) : isFeed;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFeedSniffer::GetMIMETypeFromContent(nsIRequest* request,
|
||||
const PRUint8* data,
|
||||
|
@ -252,15 +174,23 @@ nsFeedSniffer::GetMIMETypeFromContent(nsIRequest* request,
|
|||
PRBool isFeed = PR_FALSE;
|
||||
|
||||
// RSS 0.91/0.92/2.0
|
||||
isFeed = ContainsTopLevelSubstring(dataString, NS_LITERAL_CSTRING("<rss"));
|
||||
dataString.BeginReading(start_iter);
|
||||
dataString.EndReading(end_iter);
|
||||
|
||||
isFeed = FindInReadable(NS_LITERAL_CSTRING("<rss"), start_iter, end_iter);
|
||||
|
||||
// Atom 1.0
|
||||
if (!isFeed)
|
||||
isFeed = ContainsTopLevelSubstring(dataString, NS_LITERAL_CSTRING("<feed"));
|
||||
if (!isFeed) {
|
||||
dataString.BeginReading(start_iter);
|
||||
dataString.EndReading(end_iter);
|
||||
isFeed = FindInReadable(NS_LITERAL_CSTRING("<feed"), start_iter, end_iter);
|
||||
}
|
||||
|
||||
// RSS 1.0
|
||||
if (!isFeed) {
|
||||
isFeed = ContainsTopLevelSubstring(dataString, NS_LITERAL_CSTRING("<rdf:RDF"));
|
||||
dataString.BeginReading(start_iter);
|
||||
dataString.EndReading(end_iter);
|
||||
isFeed = FindInReadable(NS_LITERAL_CSTRING("<rdf:RDF"), start_iter, end_iter);
|
||||
if (isFeed) {
|
||||
dataString.BeginReading(start_iter);
|
||||
dataString.EndReading(end_iter);
|
||||
|
|
Загрузка…
Ссылка в новой задаче