summaryrefslogtreecommitdiffstats
path: root/chrome/test/data
diff options
context:
space:
mode:
authorfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-25 04:01:44 +0000
committerfinnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-25 04:01:44 +0000
commit3fa06ed3962a599ff43c992e63113529e177fd6a (patch)
treee96f1f5a57e84a4963d33d3c6d3e48472151516c /chrome/test/data
parent3fcc5da92e17118a29526a82870835c3d871606b (diff)
downloadchromium_src-3fa06ed3962a599ff43c992e63113529e177fd6a.zip
chromium_src-3fa06ed3962a599ff43c992e63113529e177fd6a.tar.gz
chromium_src-3fa06ed3962a599ff43c992e63113529e177fd6a.tar.bz2
Add one remaining class of feeds for auto-detecting (feeds that show as
rss, feed, rdf tags inside the html tag) Also, since every time I debug the extension I add the same debug code so I decided to add it and turn it off by default with an enum. Reordered the manifest file (no change beside version 2.0 -> 2.0.1) BUG=None TEST=www.computerworld.com/s/feed/keyword/Gregg+Keizer did not trigger the feed auto-detection, but now it shows the subscription page. Review URL: http://codereview.chromium.org/543185 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data')
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/doc_start.js2
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/feed_finder.js44
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/manifest.json47
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/sniff_common.js33
4 files changed, 88 insertions, 38 deletions
diff --git a/chrome/test/data/extensions/subscribe_page_action/doc_start.js b/chrome/test/data/extensions/subscribe_page_action/doc_start.js
index 37cbec9..a69cbe1 100644
--- a/chrome/test/data/extensions/subscribe_page_action/doc_start.js
+++ b/chrome/test/data/extensions/subscribe_page_action/doc_start.js
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+debugMsg(logLevels.info, "Running script at document_start");
+
// See if the current document is a feed document and if so, let
// the extension know that we should show the subscribe page instead.
if (containsFeed(document))
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed_finder.js b/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
index d433c83..9a77ff2 100644
--- a/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
+++ b/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
@@ -7,8 +7,12 @@
// (<link rel="alternate" type="application/rss+xml" etc). If so, show the
// page action icon.
-if (!isPlainTextFeedDocument())
+debugMsg(logLevels.info, "Running feed finder script");
+
+if (!isFeedDocument()) {
+ debugMsg(logLevels.info, "Document is not a feed, check for <link> tags.");
findFeedLinks();
+}
// See if the document contains a <link> tag within the <head> and
// whether that points to an RSS feed.
@@ -34,23 +38,43 @@ function findFeedLinks() {
}
// Check to see if the current document is a feed delivered as plain text,
-// which Chrome does for some mime types.
-function isPlainTextFeedDocument() {
+// which Chrome does for some mime types, or a feed wrapped in an html.
+function isFeedDocument() {
var body = document.body;
+ debugMsg(logLevels.info, "Checking if document is feed");
+
+ var soleTagInBody = "";
+ if (body && body.childElementCount == 1) {
+ soleTagInBody = body.children[0].tagName;
+ debugMsg(logLevels.info, "The sole tag in the body is: " + soleTagInBody);
+ }
+
+ // Some feeds show up as feed tags within the BODY tag, for example some
+ // ComputerWorld feeds. We cannot check for this at document_start since
+ // the body tag hasn't been defined at that time (contains only HTML element
+ // with no children).
+ if (soleTagInBody == "RSS" || soleTagInBody == "FEED" ||
+ soleTagInBody == "RDF") {
+ debugMsg(logLevels.info, "Found feed: Tag is: " + soleTagInBody);
+ chrome.extension.sendRequest({msg: "feedDocument", href: location.href});
+ return true;
+ }
+
// Chrome renders some content types like application/rss+xml and
// application/atom+xml as text/plain, resulting in a body tag with one
// PRE child containing the XML. So, we attempt to parse it as XML and look
// for RSS tags within.
- if (body && body.childElementCount == 1 &&
- body.children[0].tagName == "PRE") {
+ if (soleTagInBody == "PRE") {
+ debugMsg(logLevels.info, "Found feed: Wrapped in PRE");
var domParser = new DOMParser();
var doc = domParser.parseFromString(body.textContent, "text/xml");
- // Uncomment these three lines to see the parsing error.
- // var error = docWithin.getElementsByTagName("parsererror");
- // if (error.length)
- // console.log('error: ' + doc.childNodes[0].outerHTML);
+ if (currentLogLevel >= logLevels.error) {
+ var error = doc.getElementsByTagName("parsererror");
+ if (error.length)
+ debugMsg(logLevels.error, 'error: ' + doc.childNodes[0].outerHTML);
+ }
// |doc| now contains the parsed document within the PRE tag.
if (containsFeed(doc)) {
@@ -60,5 +84,7 @@ function isPlainTextFeedDocument() {
}
}
+ debugMsg(logLevels.info, "Exiting: feed is not a feed document");
+
return false;
}
diff --git a/chrome/test/data/extensions/subscribe_page_action/manifest.json b/chrome/test/data/extensions/subscribe_page_action/manifest.json
index a0fa67a..5e28a38 100644
--- a/chrome/test/data/extensions/subscribe_page_action/manifest.json
+++ b/chrome/test/data/extensions/subscribe_page_action/manifest.json
@@ -1,29 +1,24 @@
{
- "name": "RSS Subscription Extension (by Google)",
- "description": "Adds one-click subscription to your toolbar.",
- "version": "2.0",
- "permissions": [
- "tabs",
- "http://*/*",
- "https://*/*"
- ],
- "background_page": "background.html",
- "options_page": "options.html",
- "content_scripts": [
- {
- "matches": ["http://*/*", "https://*/*"],
- "js": ["sniff_common.js", "doc_start.js"],
+ "background_page": "background.html",
+ "content_scripts": [ {
+ "js": [ "sniff_common.js", "doc_start.js" ],
+ "matches": [ "http://*/*", "https://*/*" ],
"run_at": "document_start"
- },
- {
- "matches": ["http://*/*", "https://*/*"],
- "js": ["sniff_common.js", "feed_finder.js"]
- }
- ],
- "icons": { "128": "feed-icon-128x128.png" },
- "page_action": {
- "default_title": "Subscribe to this feed",
- "default_icon": "feed-icon-16x16.png",
- "popup": "popup.html"
- }
+ }, {
+ "js": [ "sniff_common.js", "feed_finder.js" ],
+ "matches": [ "http://*/*", "https://*/*" ]
+ } ],
+ "description": "Adds one-click subscription to your toolbar.",
+ "icons": {
+ "128": "feed-icon-128x128.png"
+ },
+ "name": "RSS Subscription Extension (by Google)",
+ "options_page": "options.html",
+ "page_action": {
+ "default_icon": "feed-icon-16x16.png",
+ "default_title": "Subscribe to this feed",
+ "popup": "popup.html"
+ },
+ "permissions": [ "tabs", "http://*/*", "https://*/*" ],
+ "version": "2.0.1"
}
diff --git a/chrome/test/data/extensions/subscribe_page_action/sniff_common.js b/chrome/test/data/extensions/subscribe_page_action/sniff_common.js
index b16dae6..29e85f6 100644
--- a/chrome/test/data/extensions/subscribe_page_action/sniff_common.js
+++ b/chrome/test/data/extensions/subscribe_page_action/sniff_common.js
@@ -2,25 +2,52 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// The possible log levels.
+var logLevels = {
+ "none": 0,
+ "error": 1,
+ "info": 2
+};
+
+// Defines the current log level. Values other than "none" are for debugging
+// only and should at no point be checked in.
+var currentLogLevel = logLevels.none;
+
function containsFeed(doc) {
+ debugMsg(logLevels.info, "containsFeed called");
+
// Find all the RSS link elements.
var result = doc.evaluate(
'//*[local-name()="rss" or local-name()="feed" or local-name()="RDF"]',
doc, null, 0, null);
- if (!result)
+ if (!result) {
+ debugMsg(logLevels.info, "exiting: document.evaluate returned no results");
return false; // This is probably overly defensive, but whatever.
+ }
var node = result.iterateNext();
- if (!node)
+ if (!node) {
+ debugMsg(logLevels.info, "returning: iterateNext() returned no nodes");
return false; // No RSS tags were found.
+ }
// The feed for arab dash jokes dot net, for example, contains
// a feed that is a child of the body tag so we continue only if the
// node contains no parent or if the parent is the body tag.
- if (node.parentElement && node.parentElement.tagName != "BODY")
+ if (node.parentElement && node.parentElement.tagName != "BODY") {
+ debugMsg(logLevels.info, "exiting: parentElement that's not BODY");
return false;
+ }
+
+ debugMsg(logLevels.info, "Found feed");
return true;
}
+
+function debugMsg(loglevel, text) {
+ if (loglevel <= currentLogLevel) {
+ console.log("RSS Subscription extension: " + text);
+ }
+}