diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-13 21:52:32 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-13 21:52:32 +0000 |
commit | 4604d1f4944206f24e864c71e29bc08b4d9500af (patch) | |
tree | 8dc2637b180b5c6e8a21b1984afb1a7bfa17c10b /webkit/glue/webframe_impl.cc | |
parent | a04f125f5fe5bbc56a3feaac4121a29452becedf (diff) | |
download | chromium_src-4604d1f4944206f24e864c71e29bc08b4d9500af.zip chromium_src-4604d1f4944206f24e864c71e29bc08b4d9500af.tar.gz chromium_src-4604d1f4944206f24e864c71e29bc08b4d9500af.tar.bz2 |
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
Diffstat (limited to 'webkit/glue/webframe_impl.cc')
-rw-r--r-- | webkit/glue/webframe_impl.cc | 63 |
1 files changed, 63 insertions, 0 deletions
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<FeedList> WebFrameImpl::GetFeedList() const { + scoped_refptr<FeedList> 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 <head> 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 <head>, looking for feed links. + for (WebCore::Node* node = head->firstChild(); + node; node = node->nextSibling()) { + // Skip over all nodes except <link ...>. + if (!node->isHTMLElement()) + continue; + if (!static_cast<WebCore::Element*>(node)->hasLocalName("link")) + continue; + + const WebCore::HTMLLinkElement* link = + static_cast<WebCore::HTMLLinkElement*>(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 |