From bc1a4b904c934fdcc2ba6de52b4adf8fde725ff5 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Wed, 14 Jan 2004 11:39:31 +0000 Subject: Get the page content into a string. 2004-01-14 Christian Persch * 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. --- embed/mozilla/mozilla-embed-persist.cpp | 52 +++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'embed/mozilla') 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 #include #include +#include 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 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 doc = do_QueryInterface(DOMDocument); + if(!doc) return NULL; + + nsCOMPtr 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)); } -- cgit v1.2.3