From 4604d1f4944206f24e864c71e29bc08b4d9500af Mon Sep 17 00:00:00 2001 From: "finnur@chromium.org" Date: Fri, 13 Mar 2009 21:52:32 +0000 Subject: RSS feed support (part 1), 2nd attempt. Part 1 is RSS feed auto-discovery. This will parse the web page header to find the feeds in the document and notify the browser to display the RSS icon in the toolbar. You can click on the icon, but it will just navigate to the first feed on the page, which (unless it has been designed to be browser friendly) will just dump XML as text on the user. For this reason I have disabled the code that makes the RSS icon appear and intend to enable it when we have a good landing page to display the XML. Review URL: http://codereview.chromium.org/46055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11672 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/webframe_impl.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'webkit/glue/webframe_impl.cc') diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc index 4f71ec3..62b27a8 100644 --- a/webkit/glue/webframe_impl.cc +++ b/webkit/glue/webframe_impl.cc @@ -135,6 +135,7 @@ MSVC_POP_WARNING(); #include "webkit/glue/alt_error_page_resource_fetcher.h" #include "webkit/glue/dom_operations.h" #include "webkit/glue/dom_operations_private.h" +#include "webkit/glue/feed.h" #include "webkit/glue/glue_serialize.h" #include "webkit/glue/glue_util.h" #include "webkit/glue/webdatasource_impl.h" @@ -485,6 +486,68 @@ GURL WebFrameImpl::GetOSDDURL() const { return GURL(); } +scoped_refptr WebFrameImpl::GetFeedList() const { + scoped_refptr feedlist = new FeedList(); + + WebCore::FrameLoader* frame_loader = frame_->loader(); + if (frame_loader->state() != WebCore::FrameStateComplete || + !frame_->document() || + !frame_->document()->head() || + frame_->tree()->parent()) + return feedlist; + + // We only consider HTML documents with tags. + // (Interestingly, isHTMLDocument() returns false for some pages -- + // perhaps an XHTML thing? It doesn't really matter because head() is + // a method on Documents anyway.) + WebCore::HTMLHeadElement* head = frame_->document()->head(); + if (!head) + return feedlist; + + // Iterate through all children of the , looking for feed links. + for (WebCore::Node* node = head->firstChild(); + node; node = node->nextSibling()) { + // Skip over all nodes except . + if (!node->isHTMLElement()) + continue; + if (!static_cast(node)->hasLocalName("link")) + continue; + + const WebCore::HTMLLinkElement* link = + static_cast(node); + + // Look at the 'rel' tag and see if we have a feed. + std::wstring rel = webkit_glue::StringToStdWString(link->rel()); + bool is_feed = false; + if (LowerCaseEqualsASCII(rel, "feed") || + LowerCaseEqualsASCII(rel, "feed alternate")) { + // rel="feed" or rel="alternate feed" always means this is a feed. + is_feed = true; + } else if (LowerCaseEqualsASCII(rel, "alternate")) { + // Otherwise, rel="alternate" may mean a feed if it has a certain mime + // type. + std::wstring link_type = webkit_glue::StringToStdWString(link->type()); + TrimWhitespace(link_type, TRIM_ALL, &link_type); + if (LowerCaseEqualsASCII(link_type, "application/atom+xml") || + LowerCaseEqualsASCII(link_type, "application/rss+xml")) { + is_feed = true; + } + } + + if (is_feed) { + FeedItem feedItem; + feedItem.title = webkit_glue::StringToStdWString(link->title()); + TrimWhitespace(feedItem.title, TRIM_ALL, &feedItem.title); + feedItem.type = webkit_glue::StringToStdWString(link->type()); + TrimWhitespace(feedItem.type, TRIM_ALL, &feedItem.type); + feedItem.url = webkit_glue::KURLToGURL(link->href()); + feedlist->Add(feedItem); + } + } + + return feedlist; +} + bool WebFrameImpl::GetPreviousHistoryState(std::string* history_state) const { // We use the previous item here because documentState (filled-out forms) // only get saved to history when it becomes the previous item. The caller -- cgit v1.1