[Kazehakase-devel 2165] [PATCH] kz_embed_get_nav_link(KZ_EMBED(widget), KZ_EMBED_LINK_RSS) is available

アーカイブの一覧に戻る

Kouhei Sutou kou****@cozmi*****
2005年 5月 12日 (木) 12:15:18 JST


須藤です.

  kz_embed_get_nav_link(KZ_EMBED(widget), KZ_EMBED_LINK_RSS)

で

  <link rel="alternate" type="application/rss+xml" href="XXX">

の「XXX」を取得できるようにするパッチです.

# nav_linksのキーであるnav_namesをkz-mozembedと
# kz-mozeventlistenerで共有した方がステキな気がする...
-------------- next part --------------
Index: src/mozilla/kz-mozembed.cpp
===================================================================
RCS file: /cvsroot/kazehakase/kazehakase/src/mozilla/kz-mozembed.cpp,v
retrieving revision 1.185
diff -u -p -r1.185 kz-mozembed.cpp
--- src/mozilla/kz-mozembed.cpp	10 May 2005 07:43:11 -0000	1.185
+++ src/mozilla/kz-mozembed.cpp	12 May 2005 03:11:34 -0000
@@ -89,11 +89,11 @@
 #include <nsILocalFile.h>
 #include <nsIDOM3Node.h>
 
-#define N_LINKS 6
+#define N_LINKS 7
 
 static gchar *nav_names[N_LINKS] =
 {
- "NEXT", "PREV", "INDEX", "CONTENTS", "START", "ALTERNATE"
+ "NEXT", "PREV", "INDEX", "CONTENTS", "START", "RSS", "ALTERNATE"
 };
 
 typedef struct _KzMozEmbedPrivate	KzMozEmbedPrivate;
@@ -1013,7 +1013,7 @@ kz_moz_embed_net_stop (GtkMozEmbed *embe
 		parent_class->net_stop(embed);
 
 	/* First free previous link */
-	kz_moz_embed_navigation_link_free(kzembed);
+	// kz_moz_embed_navigation_link_free(kzembed);
 
 	net_stop_proccess(kzembed);
 
Index: src/mozilla/kz-mozeventlistener.cpp
===================================================================
RCS file: /cvsroot/kazehakase/kazehakase/src/mozilla/kz-mozeventlistener.cpp,v
retrieving revision 1.13
diff -u -p -r1.13 kz-mozeventlistener.cpp
--- src/mozilla/kz-mozeventlistener.cpp	24 Mar 2005 06:06:05 -0000	1.13
+++ src/mozilla/kz-mozeventlistener.cpp	12 May 2005 03:11:34 -0000
@@ -23,12 +23,7 @@
 
 #include "kz-mozeventlistener.h"
 
-#include <nsCOMPtr.h>
 #include <nsIDOMNode.h>
-#include <nsIDOMElement.h>
-#define MOZILLA_STRICT_API
-#include <nsEmbedString.h>
-#undef MOZILLA_STRICT_API
 #include <nsIDOMDocument.h>
 #include <nsIURI.h>
 #include <nsIDOMEventTarget.h>
@@ -67,20 +62,11 @@ KzMozEventListener::HandleLink (nsIDOMNo
 	if (!linkElement) return NS_ERROR_FAILURE;
 
 	nsEmbedString name;
-
-	nsEmbedCString crel("rel");
-	nsEmbedString rel;
-	NS_CStringToUTF16(crel, NS_CSTRING_ENCODING_UTF8, rel);
-
-	result = linkElement->GetAttribute (rel, name);
+	result = GetLinkAttribute(linkElement, "rel", &name);
 	if (NS_FAILED(result)) return NS_ERROR_FAILURE;
 
 	nsEmbedString link;
-	nsEmbedCString chref("href");
-	nsEmbedString href;
-	NS_CStringToUTF16(chref, NS_CSTRING_ENCODING_UTF8, href);
-
-	result = linkElement->GetAttribute (href, link);
+	result = GetLinkAttribute(linkElement, "href", &link);
 	if (NS_FAILED (result) || !link.Length()) return NS_ERROR_FAILURE;
 
 	nsCOMPtr<nsIDOMDocument> domDoc;
@@ -106,6 +92,13 @@ KzMozEventListener::HandleLink (nsIDOMNo
 	result = baseURI->Resolve (linkstring, url);
 	if (NS_FAILED (result)) return NS_ERROR_FAILURE;
 
+	nsEmbedString type;
+	result = GetLinkAttribute(linkElement, "type", &type);
+	if (NS_FAILED(result)) return NS_ERROR_FAILURE;
+        
+	nsEmbedCString cType;
+	NS_UTF16ToCString(type, NS_CSTRING_ENCODING_UTF8, cType);
+        
 	nsEmbedCString cName;
 	NS_UTF16ToCString(name, NS_CSTRING_ENCODING_UTF8, cName);
 	if (!g_ascii_strcasecmp(cName.get(),"SHORTCUT ICON") ||
@@ -118,6 +111,11 @@ KzMozEventListener::HandleLink (nsIDOMNo
 		g_free (favicon_uri);
 		g_object_unref(kzfav);
 	}
+	else if (!g_ascii_strcasecmp(cName.get(), "ALTERNATE") &&
+		 !g_ascii_strcasecmp(cType.get(), "application/rss+xml"))
+	{
+		kz_embed_set_nav_link(KZ_EMBED(mOwner), "RSS", url.get());
+	}
 	else //if (link.EqualsIgnoreCase("ALTERNATE"))
 	{
 		kz_embed_set_nav_link(KZ_EMBED(mOwner),
@@ -143,3 +141,15 @@ KzMozEventListener::HandleEvent(nsIDOMEv
 
 	return NS_OK;
 }
+
+nsresult
+KzMozEventListener::GetLinkAttribute (nsCOMPtr<nsIDOMElement>& linkElement,
+				      const char *name,
+				      nsEmbedString *value)
+{
+	nsEmbedString n_name;
+	nsEmbedCString c_name(name);
+	NS_CStringToUTF16(c_name, NS_CSTRING_ENCODING_UTF8, n_name);
+	
+	return linkElement->GetAttribute(n_name, *value);
+}
Index: src/mozilla/kz-mozeventlistener.h
===================================================================
RCS file: /cvsroot/kazehakase/kazehakase/src/mozilla/kz-mozeventlistener.h,v
retrieving revision 1.4
diff -u -p -r1.4 kz-mozeventlistener.h
--- src/mozilla/kz-mozeventlistener.h	18 Oct 2004 02:09:06 -0000	1.4
+++ src/mozilla/kz-mozeventlistener.h	12 May 2005 03:11:34 -0000
@@ -27,6 +27,11 @@
 #include "kz-mozembed.h"
 
 #include <nsIDOMEventListener.h>
+#include <nsCOMPtr.h>
+#include <nsIDOMElement.h>
+#define MOZILLA_STRICT_API
+#include <nsEmbedString.h>
+#undef MOZILLA_STRICT_API
 
 class KzMozEventListener : public nsIDOMEventListener
 {
@@ -43,6 +48,9 @@ class KzMozEventListener : public nsIDOM
 	KzMozEmbed *mOwner;
 
 	nsresult HandleLink        (nsIDOMNode *node);
+	nsresult GetLinkAttribute  (nsCOMPtr<nsIDOMElement>& linkElement,
+				    const char *name,
+				    nsEmbedString *value);
 };
 
 #endif /* __KZ_MOZ_EVENT_LISTENER_H__ */


Kazehakase-devel メーリングリストの案内
アーカイブの一覧に戻る