Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Side by Side Diff: chrome/test/data/extensions/subscribe_page_action/feed_finder.js

Issue 12843037: Convert the RSS extension to event pages to avoid a dedicated background process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // First check to see if this document is a feed. If so, it will redirect. 5 // First check to see if this document is a feed. If so, it will redirect.
6 // Otherwise, check if it has embedded feed links, such as: 6 // Otherwise, check if it has embedded feed links, such as:
7 // (<link rel="alternate" type="application/rss+xml" etc). If so, show the 7 // (<link rel="alternate" type="application/rss+xml" etc). If so, show the
8 // page action icon. 8 // page action icon.
9 9
10 debugMsg(logLevels.info, "Running feed finder script"); 10 debugMsg(logLevels.info, "Running feed finder script");
(...skipping 15 matching lines...) Expand all
26 var feeds = []; 26 var feeds = [];
27 var item; 27 var item;
28 var count = 0; 28 var count = 0;
29 while (item = result.iterateNext()) { 29 while (item = result.iterateNext()) {
30 feeds.push({"href": item.href, "title": item.title}); 30 feeds.push({"href": item.href, "title": item.title});
31 ++count; 31 ++count;
32 } 32 }
33 33
34 if (count > 0) { 34 if (count > 0) {
35 // Notify the extension needs to show the RSS page action icon. 35 // Notify the extension needs to show the RSS page action icon.
36 chrome.extension.sendRequest({msg: "feedIcon", feeds: feeds}); 36 chrome.extension.sendMessage({msg: "feedIcon", feeds: feeds});
37 } 37 }
38 } 38 }
39 39
40 // Check to see if the current document is a feed delivered as plain text, 40 // Check to see if the current document is a feed delivered as plain text,
41 // which Chrome does for some mime types, or a feed wrapped in an html. 41 // which Chrome does for some mime types, or a feed wrapped in an html.
42 function isFeedDocument() { 42 function isFeedDocument() {
43 var body = document.body; 43 var body = document.body;
44 44
45 debugMsg(logLevels.info, "Checking if document is feed"); 45 debugMsg(logLevels.info, "Checking if document is feed");
46 46
47 var soleTagInBody = ""; 47 var soleTagInBody = "";
48 if (body && body.childElementCount == 1) { 48 if (body && body.childElementCount == 1) {
49 soleTagInBody = body.children[0].tagName; 49 soleTagInBody = body.children[0].tagName;
50 debugMsg(logLevels.info, "The sole tag in the body is: " + soleTagInBody); 50 debugMsg(logLevels.info, "The sole tag in the body is: " + soleTagInBody);
51 } 51 }
52 52
53 // Some feeds show up as feed tags within the BODY tag, for example some 53 // Some feeds show up as feed tags within the BODY tag, for example some
54 // ComputerWorld feeds. We cannot check for this at document_start since 54 // ComputerWorld feeds. We cannot check for this at document_start since
55 // the body tag hasn't been defined at that time (contains only HTML element 55 // the body tag hasn't been defined at that time (contains only HTML element
56 // with no children). 56 // with no children).
57 if (soleTagInBody == "RSS" || soleTagInBody == "FEED" || 57 if (soleTagInBody == "RSS" || soleTagInBody == "FEED" ||
58 soleTagInBody == "RDF") { 58 soleTagInBody == "RDF") {
59 debugMsg(logLevels.info, "Found feed: Tag is: " + soleTagInBody); 59 debugMsg(logLevels.info, "Found feed: Tag is: " + soleTagInBody);
60 chrome.extension.sendRequest({msg: "feedDocument", href: location.href}); 60 chrome.extension.sendMessage({msg: "feedDocument", href: location.href});
61 return true; 61 return true;
62 } 62 }
63 63
64 // Chrome renders some content types like application/rss+xml and 64 // Chrome renders some content types like application/rss+xml and
65 // application/atom+xml as text/plain, resulting in a body tag with one 65 // application/atom+xml as text/plain, resulting in a body tag with one
66 // PRE child containing the XML. So, we attempt to parse it as XML and look 66 // PRE child containing the XML. So, we attempt to parse it as XML and look
67 // for RSS tags within. 67 // for RSS tags within.
68 if (soleTagInBody == "PRE") { 68 if (soleTagInBody == "PRE") {
69 debugMsg(logLevels.info, "Found feed: Wrapped in PRE"); 69 debugMsg(logLevels.info, "Found feed: Wrapped in PRE");
70 var domParser = new DOMParser(); 70 var domParser = new DOMParser();
71 var doc = domParser.parseFromString(body.textContent, "text/xml"); 71 var doc = domParser.parseFromString(body.textContent, "text/xml");
72 72
73 if (currentLogLevel >= logLevels.error) { 73 if (currentLogLevel >= logLevels.error) {
74 var error = doc.getElementsByTagName("parsererror"); 74 var error = doc.getElementsByTagName("parsererror");
75 if (error.length) 75 if (error.length)
76 debugMsg(logLevels.error, 'error: ' + doc.childNodes[0].outerHTML); 76 debugMsg(logLevels.error, 'error: ' + doc.childNodes[0].outerHTML);
77 } 77 }
78 78
79 // |doc| now contains the parsed document within the PRE tag. 79 // |doc| now contains the parsed document within the PRE tag.
80 if (containsFeed(doc)) { 80 if (containsFeed(doc)) {
81 // Let the extension know that we should show the subscribe page. 81 // Let the extension know that we should show the subscribe page.
82 chrome.extension.sendRequest({msg: "feedDocument", href: location.href}); 82 chrome.extension.sendMessage({msg: "feedDocument", href: location.href});
83 return true; 83 return true;
84 } 84 }
85 } 85 }
86 86
87 debugMsg(logLevels.info, "Exiting: feed is not a feed document"); 87 debugMsg(logLevels.info, "Exiting: feed is not a feed document");
88 88
89 return false; 89 return false;
90 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698