Hiroyuki Ikezoe
ikezo****@users*****
Tue Sep 12 08:12:23 JST 2006
Index: kazehakase/src/mozilla/Makefile.am diff -u kazehakase/src/mozilla/Makefile.am:1.47 kazehakase/src/mozilla/Makefile.am:1.48 --- kazehakase/src/mozilla/Makefile.am:1.47 Sun Apr 30 19:22:09 2006 +++ kazehakase/src/mozilla/Makefile.am Tue Sep 12 08:12:23 2006 @@ -21,6 +21,7 @@ -I$(MOZILLA_INCLUDE_ROOT)/gfx \ -I$(MOZILLA_INCLUDE_ROOT)/helperAppDlg \ -I$(MOZILLA_INCLUDE_ROOT)/intl \ + -I$(MOZILLA_INCLUDE_ROOT)/imglib2 \ -I$(MOZILLA_INCLUDE_ROOT)/java \ -I$(MOZILLA_INCLUDE_ROOT)/jsconsole \ -I$(MOZILLA_INCLUDE_ROOT)/layout \ @@ -88,6 +89,10 @@ $(PROFILEDIRSERVICE_SOURCES) endif +LIBGSTHUMBNAIL_SOURCES= \ + kz-mozthumbnailcreator.cpp kz-mozthumbnailcreator.h \ + kz-mozthumbnailprogress.cpp kz-mozthumbnailprogress.h + libkzmozilla_la_SOURCES = \ GtkNSSDialogs.cpp GtkNSSDialogs.h \ GtkPromptService.cpp GtkPromptService.h \ @@ -101,12 +106,11 @@ kz-mozeventlistener.cpp kz-mozeventlistener.h \ kz-mozprintingpromptservice.cpp kz-mozprintingpromptservice.h \ kz-mozprogresslistener.cpp kz-mozprogresslistener.h \ - kz-mozthumbnailcreator.cpp kz-mozthumbnailcreator.h \ - kz-mozthumbnailprogress.cpp kz-mozthumbnailprogress.h \ kz-mozutils.cpp kz-mozutils.h \ kz-mozwrapper.cpp kz-mozwrapper.h \ kz-mozhistorysearch.cpp kz-mozhistorysearch.h \ $(LIBGTKMOZEMBED_SOURCES) \ + $(LIBGSTHUMBNAIL_SOURCES) \ MozillaPrivate.cpp MozillaPrivate.h \ MozillaEmbedPrivate.cpp MozillaEmbedPrivate.h Index: kazehakase/src/mozilla/MozillaPrivate.cpp diff -u kazehakase/src/mozilla/MozillaPrivate.cpp:1.11 kazehakase/src/mozilla/MozillaPrivate.cpp:1.12 --- kazehakase/src/mozilla/MozillaPrivate.cpp:1.11 Mon Oct 24 21:27:05 2005 +++ kazehakase/src/mozilla/MozillaPrivate.cpp Tue Sep 12 08:12:23 2006 @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Id: MozillaPrivate.cpp,v 1.11 2005/10/24 12:27:05 ikezoe Exp $ + * $Id: MozillaPrivate.cpp,v 1.12 2006/09/11 23:12:23 ikezoe Exp $ */ /* @@ -26,6 +26,7 @@ #include "mozilla-config.h" #include "config.h" +#include "kazehakase.h" #include "MozillaPrivate.h" @@ -38,12 +39,17 @@ #include <nsPromiseFlatString.h> #include <nsEscape.h> #include <nsIDocument.h> +#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ +#include <nsICanvasRenderingContextInternal.h> +#include <nsIDOMCanvasRenderingContext2D.h> +#endif #undef MOZILLA_INTERNAL_API #include <nsISimpleEnumerator.h> #include <nsISupportsPrimitives.h> #include <nsIContent.h> #include <nsIDOMHTMLDocument.h> #include <nsIDOMHTMLElement.h> +#include <nsIDOMHTMLImageElement.h> #include <nsIWidget.h> #include <nsPIDOMWindow.h> #include <nsIChromeEventHandler.h> @@ -311,3 +317,82 @@ { return (const char*)nsUnescape((char*)text); } + +#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ +#include "egg-pixbuf-thumbnail.h" +#define KZ_CANVAS_WIDTH 1024 +#define KZ_CANVAS_HEIGHT 800 +gboolean +MozillaPrivate::CreateThumbnail(nsIDOMWindow *domWindow, const gchar *uri) +{ + nsresult rv; + nsCOMPtr<nsIDOMDocument> domDoc; + domWindow->GetDocument(getter_AddRefs(domDoc)); + + nsCOMPtr<nsICanvasRenderingContextInternal> context; + + nsCString ctxString("@mozilla.org/content/canvas-rendering-context;1?id=2d"); + context = do_CreateInstance(nsPromiseFlatCString(ctxString).get(), &rv); + + if (NS_FAILED(rv) || !context) return FALSE; + + context->SetDimensions(EGG_PIXBUF_THUMB_LARGE, KZ_THUMB_HEIGHT); + + nsCOMPtr<nsIDOMElement> element; + domDoc->CreateElement(NS_LITERAL_STRING("canvas"), getter_AddRefs(element)); + nsCOMPtr<nsICanvasElement> canvasElement = do_QueryInterface(element); + context->SetCanvasElement(canvasElement); + + nsCOMPtr<nsIDOMCanvasRenderingContext2D> domCanvas = do_QueryInterface(context, &rv); + if (NS_FAILED(rv) || !domCanvas) return FALSE; + + domCanvas->Scale(EGG_PIXBUF_THUMB_LARGE / KZ_CANVAS_WIDTH, KZ_THUMB_HEIGHT / KZ_CANVAS_HEIGHT); + //domCanvas->Scale(0.25, 0.25); + + rv = domCanvas->DrawWindow(domWindow, 0, 0, KZ_CANVAS_WIDTH, KZ_CANVAS_HEIGHT, NS_LITERAL_STRING("rgb(0,0,0)")); + //rv = domCanvas->DrawWindow(domWindow, 0, 0, 1024, 768, NS_LITERAL_STRING("rgb(0,0,0)")); + if (NS_FAILED(rv)) return FALSE; + + nsCOMPtr<nsIInputStream> imgStream; + rv = context->GetInputStream(NS_LITERAL_CSTRING("image/png"), EmptyString(), getter_AddRefs(imgStream)); + if (NS_FAILED(rv) || !imgStream) return FALSE; + + // this code wa picked from content/html/content/src/nsHTMLCanvasElement.cpp in firefox-2.0b. + PRUint32 bufSize; + rv = imgStream->Available(&bufSize); + if (NS_FAILED(rv)) return FALSE; + + bufSize += 16; + PRUint32 imgSize = 0; + char* imgData = (char*)g_malloc((gulong)bufSize); + if (!imgData) return FALSE; + + PRUint32 numReadThisTime = 0; + while ((rv = imgStream->Read(&imgData[imgSize], bufSize - imgSize, + &numReadThisTime)) == NS_OK && numReadThisTime > 0) + { + imgSize += numReadThisTime; + if (imgSize == bufSize) + { + // need a bigger buffer, just double + bufSize *= 2; + char* newImgData = (char*)g_realloc(imgData, (gulong)bufSize); + if (!newImgData) + { + g_free(imgData); + return FALSE; + } + imgData = newImgData; + } + } + + gchar *thumb_filename; + thumb_filename = egg_pixbuf_get_thumb_filename(uri, + EGG_PIXBUF_THUMB_LARGE); + g_file_set_contents(thumb_filename, imgData, imgSize, NULL); + g_free(imgData); + g_free(thumb_filename); + + return TRUE; +} +#endif Index: kazehakase/src/mozilla/MozillaPrivate.h diff -u kazehakase/src/mozilla/MozillaPrivate.h:1.9 kazehakase/src/mozilla/MozillaPrivate.h:1.10 --- kazehakase/src/mozilla/MozillaPrivate.h:1.9 Mon Oct 24 21:27:05 2005 +++ kazehakase/src/mozilla/MozillaPrivate.h Tue Sep 12 08:12:23 2006 @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Id: MozillaPrivate.h,v 1.9 2005/10/24 12:27:05 ikezoe Exp $ + * $Id: MozillaPrivate.h,v 1.10 2006/09/11 23:12:23 ikezoe Exp $ */ /* @@ -51,5 +51,8 @@ gboolean GetEventReceiver (nsIDOMWindow *domWindow, nsIDOMEventReceiver **receiver); gchar *GetURIForDOMWindow (nsIDOMWindow *aDOMWindow); const char *Unescape (const char *text); +#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ + gboolean CreateThumbnail (nsIDOMWindow *domWindow, const gchar *uri); +#endif } #endif /* __MOZILLA_PRIVATE_H__ */ Index: kazehakase/src/mozilla/kz-mozembed.cpp diff -u kazehakase/src/mozilla/kz-mozembed.cpp:1.202 kazehakase/src/mozilla/kz-mozembed.cpp:1.203 --- kazehakase/src/mozilla/kz-mozembed.cpp:1.202 Tue Sep 5 14:51:07 2006 +++ kazehakase/src/mozilla/kz-mozembed.cpp Tue Sep 12 08:12:23 2006 @@ -2866,7 +2866,7 @@ } -#if 1 /* FIXME! */ +#ifndef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ static KzMozThumbnailCreator * kz_window_create_thumbnail_creator (KzWindow *kz) { @@ -2890,16 +2890,25 @@ return creator; } -#endif /* FIXME! */ +#endif + static void kz_moz_embed_create_thumbnail (KzEmbed *kzembed) { g_return_if_fail(KZ_IS_MOZ_EMBED(kzembed)); + gboolean create_thumbnail = FALSE; + KZ_CONF_GET("Global", "create_thumbnail", create_thumbnail, BOOL); + if (!create_thumbnail) return; + KzMozEmbedPrivate *priv = KZ_MOZ_EMBED_GET_PRIVATE (kzembed); KzMozWrapper *wrapper = priv->wrapper; g_return_if_fail (wrapper != NULL); +#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ + if (NS_SUCCEEDED(wrapper->CreateThumbnail())) + g_warning ("Creating thumbnail suceeded with new Gecko APIs!"); +#else nsresult rv; int total, index; rv = wrapper->GetSHInfo (&total, &index); @@ -2914,14 +2923,10 @@ KzWindow *kz = KZ_WINDOW(window); - gboolean create_thumbnail = FALSE; - KZ_CONF_GET("Global", "create_thumbnail", create_thumbnail, BOOL); - if (create_thumbnail) - { - KzMozThumbnailCreator *creator; - creator = kz_window_create_thumbnail_creator(kz); - kz_moz_thumbnail_creator_append_queue(creator, he); - } + KzMozThumbnailCreator *creator; + creator = kz_window_create_thumbnail_creator(kz); + kz_moz_thumbnail_creator_append_queue(creator, he); +#endif } Index: kazehakase/src/mozilla/kz-mozwrapper.cpp diff -u kazehakase/src/mozilla/kz-mozwrapper.cpp:1.116 kazehakase/src/mozilla/kz-mozwrapper.cpp:1.117 --- kazehakase/src/mozilla/kz-mozwrapper.cpp:1.116 Wed Apr 26 10:18:41 2006 +++ kazehakase/src/mozilla/kz-mozwrapper.cpp Tue Sep 12 08:12:23 2006 @@ -2018,3 +2018,21 @@ return certDialogs->ViewCert (NULL, serverCert); } + +#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ +nsresult +KzMozWrapper::CreateThumbnail (void) +{ + nsCOMPtr<nsIDOMWindow> domWindow; + GetDOMWindow(getter_AddRefs(domWindow)); + + nsEmbedCString sURI; + GetDocumentUrl(sURI); + const gchar *uri = sURI.get(); + + if (!MozillaPrivate::CreateThumbnail(domWindow, uri)) + return NS_ERROR_FAILURE; + + return NS_OK; +} +#endif Index: kazehakase/src/mozilla/kz-mozwrapper.h diff -u kazehakase/src/mozilla/kz-mozwrapper.h:1.53 kazehakase/src/mozilla/kz-mozwrapper.h:1.54 --- kazehakase/src/mozilla/kz-mozwrapper.h:1.53 Tue Apr 25 14:31:31 2006 +++ kazehakase/src/mozilla/kz-mozwrapper.h Tue Sep 12 08:12:23 2006 @@ -147,6 +147,10 @@ nsresult ShowPageCertificate (void); +#ifdef MOZ_NSICANVASRENDERINGCONTEXTINTERNAL_HAVE_GETINPUTSTREAM_ + nsresult CreateThumbnail (void); +#endif + nsCOMPtr<nsIWebBrowser> mWebBrowser; protected: nsCOMPtr<nsIDOMEventTarget> mEventTarget;