diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | embed/ephy-embed-persist.c | 7 | ||||
-rw-r--r-- | embed/ephy-embed-persist.h | 3 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-persist.cpp | 52 |
4 files changed, 68 insertions, 2 deletions
@@ -1,3 +1,11 @@ +2004-01-14 Christian Persch <chpe@cvs.gnome.org> + + * embed/ephy-embed-persist.c: (ephy_embed_persist_to_string): + * embed/ephy-embed-persist.h: + * embed/mozilla/mozilla-embed-persist.cpp: + + Get the page content into a string. + 2004-01-13 Xan Lopez <xan@gnome.org> * embed/downloader-view.c: (status_icon_activated): diff --git a/embed/ephy-embed-persist.c b/embed/ephy-embed-persist.c index 28cddbb2b..7197fa6be 100644 --- a/embed/ephy-embed-persist.c +++ b/embed/ephy-embed-persist.c @@ -435,3 +435,10 @@ ephy_embed_persist_save (EphyEmbedPersist *persist) EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); return klass->save (persist); } +char * +ephy_embed_persist_to_string (EphyEmbedPersist *persist) +{ + EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); + return klass->to_string (persist); +} + diff --git a/embed/ephy-embed-persist.h b/embed/ephy-embed-persist.h index 403544973..1591e4d60 100644 --- a/embed/ephy-embed-persist.h +++ b/embed/ephy-embed-persist.h @@ -69,6 +69,7 @@ struct EphyEmbedPersistClass gboolean (* save) (EphyEmbedPersist *persist); void (* cancel) (EphyEmbedPersist *persist); + char * (* to_string) (EphyEmbedPersist *persist); }; GType ephy_embed_persist_get_type (void); @@ -117,6 +118,8 @@ const char *ephy_embed_persist_get_persist_key (EphyEmbedPersist *persist); const char *ephy_embed_persist_get_source (EphyEmbedPersist *persist); +char *ephy_embed_persist_to_string (EphyEmbedPersist *persist); + G_END_DECLS #endif diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 8f302d713..a7442ad03 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -36,6 +36,7 @@ #include <nsNetUtil.h> #include <nsIHistoryEntry.h> #include <nsISHEntry.h> +#include <nsIDocumentEncoder.h> static void mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass); @@ -154,10 +155,9 @@ impl_save (EphyEmbedPersist *persist) EphyBrowser *browser = NULL; if (embed) { - browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(embed)); + browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(embed)); NS_ENSURE_TRUE (browser, FALSE); } - /* we must have one of uri or browser */ g_assert (browser != NULL || uri != NULL); @@ -269,6 +269,53 @@ impl_save (EphyEmbedPersist *persist) return TRUE; } +static char * +impl_to_string (EphyEmbedPersist *persist) +{ + EphyEmbed *embed; + nsCOMPtr<nsIDOMDocument> DOMDocument; + EmbedPersistFlags flags; + EphyBrowser *browser; + nsresult rv = NS_OK; + + g_object_ref (persist); + + g_object_get (persist, + "flags", &flags, + "embed", &embed, + NULL); + g_object_unref (persist); + g_assert (embed != NULL); + + browser = (EphyBrowser *) _mozilla_embed_get_ephy_browser (MOZILLA_EMBED(embed)); + g_assert (browser != NULL); + + if (flags & EMBED_PERSIST_MAINDOC) + { + rv = browser->GetDocument (getter_AddRefs(DOMDocument)); + } + else + { + rv = browser->GetTargetDocument (getter_AddRefs(DOMDocument)); + } + if (NS_FAILED(rv) || !DOMDocument) return NULL; + + nsCOMPtr<nsIDocument> doc = do_QueryInterface(DOMDocument); + if(!doc) return NULL; + + nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/html"); + NS_ENSURE_SUCCESS(rv, NULL); + + rv = encoder->Init(doc, NS_LITERAL_STRING("text/html"), nsIDocumentEncoder::OutputAbsoluteLinks); + NS_ENSURE_SUCCESS(rv, NULL); + + nsAutoString aOutputString; + encoder->EncodeToString(aOutputString); + + return g_strdup (NS_ConvertUCS2toUTF8(aOutputString).get()); +} + + static GObject * mozilla_embed_persist_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) @@ -293,6 +340,7 @@ mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass) persist_class->save = impl_save; persist_class->cancel = impl_cancel; + persist_class->to_string = impl_to_string; g_type_class_add_private (object_class, sizeof(MozillaEmbedPersistPrivate)); } |