- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / subscribe_page_action / sniff_common.js
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
3 // found in the LICENSE file.
4
5 // The possible log levels.
6 var logLevels = {
7     "none": 0,
8     "error": 1,
9     "info": 2
10 };
11
12 // Defines the current log level. Values other than "none" are for debugging
13 // only and should at no point be checked in.
14 var currentLogLevel = logLevels.none;
15
16 function containsFeed(doc) {
17   debugMsg(logLevels.info, "containsFeed called");
18
19   // Find all the RSS link elements.
20   var result = doc.evaluate(
21       '//*[local-name()="rss" or local-name()="feed" or local-name()="RDF"]',
22       doc, null, 0, null);
23
24   if (!result) {
25     debugMsg(logLevels.info, "exiting: document.evaluate returned no results");
26     return false;  // This is probably overly defensive, but whatever.
27   }
28
29   var node = result.iterateNext();
30
31   if (!node) {
32     debugMsg(logLevels.info, "returning: iterateNext() returned no nodes");
33     return false;  // No RSS tags were found.
34   }
35
36   // The feed for arab dash jokes dot net, for example, contains
37   // a feed that is a child of the body tag so we continue only if the
38   // node contains no parent or if the parent is the body tag.
39   if (node.parentElement && node.parentElement.tagName != "BODY") {
40     debugMsg(logLevels.info, "exiting: parentElement that's not BODY");
41     return false;
42   }
43
44   debugMsg(logLevels.info, "Found feed");
45
46   return true;
47 }
48
49 function debugMsg(loglevel, text) {
50   if (loglevel <= currentLogLevel) {
51     console.log("RSS Subscription extension: " + text);
52   }
53 }