[ilovegom commit] r78 - in trunk/gom: . examples include include/xpgom src/xpgom src/xulapp src/xulapp/chrome src/x...

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 21, 2008, 3:28:32 AM8/21/08
to gom-c...@googlegroups.com
Author: ja...@87k.net
Date: Thu Aug 21 00:26:36 2008
New Revision: 78

Added:
trunk/gom/include/xpgom/xgScriptElement.hh
trunk/gom/include/xpgom/xgString.hh
trunk/gom/src/xpgom/xgScriptElement.cc
trunk/gom/src/xulapp/
trunk/gom/src/xulapp/application.ini.in
trunk/gom/src/xulapp/chrome/
trunk/gom/src/xulapp/chrome/chrome.manifest
trunk/gom/src/xulapp/chrome/content/
trunk/gom/src/xulapp/chrome/content/xpgom/
trunk/gom/src/xulapp/chrome/content/xpgom/gom.js
trunk/gom/src/xulapp/chrome/content/xpgom/gom.xul
trunk/gom/src/xulapp/defaults/
trunk/gom/src/xulapp/defaults/preferences/
trunk/gom/src/xulapp/defaults/preferences/prefs.js
Removed:
trunk/gom/include/nsIScriptGlobalObject.h
Modified:
trunk/gom/ChangeLog
trunk/gom/Makefile.am
trunk/gom/configure.ac
trunk/gom/examples/console.gom
trunk/gom/include/gommacros.h
trunk/gom/include/xpgom/Makefile.inc
trunk/gom/src/xpgom/Makefile.inc
trunk/gom/src/xpgom/xgGomElementFactory.cc
trunk/gom/src/xpgom/xgGomModule.cc
trunk/gom/src/xpgom/xgGtkElement.cc
trunk/gom/src/xpgom/xgGtkElementFactory.cc

Log:
2008-08-21 jacob berkman <ja...@ilovegom.org>

* src/xulapp/chrome/content/xpgom/gom.xul: gom as a xulrunner
app

* src/xpgom/xgGomModule.cc: just register our XTF components

* src/xpgom/xgGomElementFactory.cc (CreateElement): add
support for script tags

* src/xpgom/xgScriptElement.cc: an implementation of <script>
elements

* src/xpgom/xgGtkElement.cc (GetAttribute): use string APIs
that work for both frozen and internal linkage

Modified: trunk/gom/ChangeLog
==============================================================================
--- trunk/gom/ChangeLog (original)
+++ trunk/gom/ChangeLog Thu Aug 21 00:26:36 2008
@@ -1,3 +1,24 @@
+2008-08-21 jacob berkman <ja...@ilovegom.org>
+
+ * src/xulapp/chrome/content/xpgom/gom.xul: gom as a xulrunner
+ app
+
+ * src/xpgom/xgGomModule.cc: just register our XTF components
+
+ * src/xpgom/xgGomElementFactory.cc (CreateElement): add
+ support for script tags
+
+ * src/xpgom/xgScriptElement.cc: an implementation of <script>
+ elements
+
+ * src/xpgom/xgGtkElement.cc (GetAttribute): use string APIs
+ that work for both frozen and internal linkage
+
+2008-08-17 jacob berkman <ja...@ilovegom.org>
+
+ * src/xpgom/xgWindow.cc (XG_HandleScriptError): work around
+ NS_HandleScriptError being in headers, but not in xpcom glue
+
2008-08-16 jacob berkman <ja...@ilovegom.org>

* src/xpgom/xgGomModule.cc: update for xgWindow

Modified: trunk/gom/Makefile.am
==============================================================================
--- trunk/gom/Makefile.am (original)
+++ trunk/gom/Makefile.am Thu Aug 21 00:26:36 2008
@@ -40,6 +40,7 @@
noinst_DATA :=

noinst_HEADERS :=
+idl_headers :=

BUILT_SOURCES :=
CLEANFILES :=

Modified: trunk/gom/configure.ac
==============================================================================
--- trunk/gom/configure.ac (original)
+++ trunk/gom/configure.ac Thu Aug 21 00:26:36 2008
@@ -69,14 +69,15 @@
# Checks for header files.
CPPFLAGS_save=$CPPFLAGS

-xulrunner_cppflags="-I$xulrunnersdk/sdk/include"
-for subdir in content dom js widget xpcom xpconnect ; do
+xulrunner_cppflags="-DDEBUG -include xpcom-config.h
-I$xulrunnersdk/sdk/include"
+#xulrunner_cppflags="-DMOZILLA_INTERNAL_API $xulrunner_cppflags"
+for subdir in content xpcom dom xpconnect js widget layout ; do
xulrunner_cppflags="$xulrunner_cppflags
-I$xulrunnersdk/include/$subdir"
done
-CPPFLAGS="$CPPFLAGS_save -include xpcom-config.h $xulrunner_cppflags"
-CXXFLAGS="$CXXFLAGS -fshort-wchar"
+CPPFLAGS="$CPPFLAGS_save $xulrunner_cppflags"
+CXXFLAGS="$CXXFLAGS -fshort-wchar -fno-rtti -fno-exceptions"
AC_LANG_PUSH([C++])
-AC_CHECK_HEADERS([nsXPCOM.h nsIIOService.h nsIXTFElementFactory.h
nsIAtom.h nsIDOMNavigator.h nsIXPConnect.h nsEvent.h],[],[
+AC_CHECK_HEADERS([nsIXTFElement.h nsIAtom.h nsDOMError.h
nsIXPCScriptable.h nsEvent.h nsCompatibility.h],[],[
AC_MSG_ERROR([$xulrunnersdk is missing XPCOM headers.])
])
AC_LANG_POP([C++])
@@ -89,6 +90,7 @@
# Checks for library functions.
LIBS_save=$LIBS

+#
http://developer.mozilla.org/en/docs/XPCOM_Glue#Sample_Compiler.2FLinker_Flags
xulrunner_libs="-L$xulrunnersdk/sdk/lib"
LIBS="$LIBS_save $xulrunner_libs"
case $host_os in
@@ -102,7 +104,12 @@
AC_MSG_ERROR([I don't know how to link components on $host_os])
;;
esac
+# "Internal Linkage" :(
+#XPGOM_LIBS="$GOM_LIBS $xulrunner_libs -L$xulrunnersdk/lib
$xulrunnersdk/../docshell/build/libdocshell.dylib -lxpcom_core -lxpcom
-lnspr4"
+# "Dependent Glue"
XPGOM_LIBS="$GOM_LIBS $xulrunner_libs -L$xulrunnersdk/bin $xplibpath
-lxpcomglue_s -lxpcom -lnspr4"
+# "Standalone Glue"
+#XPGOM_LIBS="$GOM_LIBS $xulrunner_libs -lxpcomglue"

LIBS=$LIBS_save

@@ -114,6 +121,6 @@
AC_CONFIG_FILES([
gom-0.pc
Makefile
-src/xpgom/xgNavigator.js
+src/xulapp/application.ini
])
AC_OUTPUT

Modified: trunk/gom/examples/console.gom
==============================================================================
--- trunk/gom/examples/console.gom (original)
+++ trunk/gom/examples/console.gom Thu Aug 21 00:26:36 2008
@@ -4,7 +4,7 @@
<module name="gtk+-2.0"/>
</config>
<app>
- <script contentType="text/javascript" src="jquery-1.2.3.js"></script>
+ <script type="application/javascript" src="jquery-1.2.3.js"></script>
<GtkWindow id="win" title="Gom Console"
widthRequest="400" heightRequest="300" borderWidth="6"
ondeleteEvent="quit();"
@@ -23,7 +23,7 @@
</GtkHBox>
</GtkVBox>
</GtkWindow>
- <script contentType="text/javascript"><![CDATA[
+ <script type="application/javascript"><![CDATA[
(function(){
var history = [];
var histIdx = -1;

Modified: trunk/gom/include/gommacros.h
==============================================================================
--- trunk/gom/include/gommacros.h (original)
+++ trunk/gom/include/gommacros.h Thu Aug 21 00:26:36 2008
@@ -179,15 +179,10 @@
#define GOM_UNSET_WEAK(p) GOM_SET_WEAK(p, NULL)

#define GOM_ASTRING_TO_GSTRING_RETURN(_aCString, _aString, _errval) \
- nsCAutoString _aCString##String; \
- if (NS_FAILED (NS_UTF16ToCString (_aString, NS_CSTRING_ENCODING_UTF8,
_aCString##String))) { \
- return _errval; \
- } \
- const char *_aCString = _aCString##String.get();
+ GOM_ASTRING_TO_GSTRING(_aCString, _aString)

#define GOM_ASTRING_TO_GSTRING(_aCString, _aString) \
- nsCAutoString _aCString##String; \
- NS_UTF16ToCString (_aString, NS_CSTRING_ENCODING_UTF8,
_aCString##String); \
+ NS_ConvertUTF16toUTF8 _aCString##String (_aString); \
const char *_aCString = _aCString##String.get();

#define GOM_ATOM_TO_GSTRING_RETURN(_aCString, _aAtom, _errval) \
@@ -197,14 +192,7 @@
}

#define GOM_GSTRING_TO_ASTRING_RETURN(_aString, _aCString, _errval) \
- G_STMT_START { \
- nsCAutoString _aCString##String (_aCString); \
- if (NS_FAILED (NS_CStringToUTF16 (_aCString##String,
NS_CSTRING_ENCODING_UTF8, _aString))) { \
- g_free (_aCString); \
- return _errval; \
- } \
- g_free (_aCString); \
- } G_STMT_END
+ NS_ConvertUTF8toUTF16 _aString (_aCString)

#define GOM_RETURN_NSRESULT_FROM_GERROR(_err) \
G_STMT_START { \

Modified: trunk/gom/include/xpgom/Makefile.inc
==============================================================================
--- trunk/gom/include/xpgom/Makefile.inc (original)
+++ trunk/gom/include/xpgom/Makefile.inc Thu Aug 21 00:26:36 2008
@@ -2,16 +2,3 @@

# xpgomincludedir := $(includedir)/gom-0/xpgom
# xpgominclude_HEADERS :=
-noinst_HEADERS += include/xpgom/gomwrapped.hh
-noinst_HEADERS += include/xpgom/gomwrappedattr.hh
-noinst_HEADERS += include/xpgom/gomwrappeddocument.hh
-noinst_HEADERS += include/xpgom/gomwrappeddomimplementation.hh
-noinst_HEADERS += include/xpgom/gomwrappedelement.hh
-noinst_HEADERS += include/xpgom/gomwrappednamednodemap.hh
-noinst_HEADERS += include/xpgom/gomwrappednode.hh
-noinst_HEADERS += include/xpgom/xgDOMImplementation.hh
-noinst_HEADERS += include/xpgom/xgDocument.hh
-noinst_HEADERS += include/xpgom/xgElement.hh
-noinst_HEADERS += include/xpgom/xgNode.hh
-noinst_HEADERS += include/xpgom/xgNodeList.hh
-noinst_HEADERS += include/xpgom/xgWrapped.hh

Added: trunk/gom/include/xpgom/xgScriptElement.hh
==============================================================================
--- (empty file)
+++ trunk/gom/include/xpgom/xgScriptElement.hh Thu Aug 21 00:26:36 2008
@@ -0,0 +1,61 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef XG_SCRIPT_ELEMENT_HH
+#define XG_SCRIPT_ELEMENT_HH
+
+#include <xpgom/xgString.hh>
+
+#include <nsCOMPtr.h>
+#include <nsIURI.h>
+#include <nsIXTFElement.h>
+#include <nsIXTFElementWrapper.h>
+#include <nsWeakReference.h>
+
+class xgScriptElement : public nsIXTFElement
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXTFELEMENT
+
+ xgScriptElement ();
+ //nsresult Init();
+
+private:
+ ~xgScriptElement ();
+
+protected:
+ nsresult DownloadScript ();
+ nsresult EvaluateScript ();
+ nsresult MaybeEvaluateScript ();
+
+ nsAutoString mScript;
+ nsWeakPtr mGlobal;
+ nsCOMPtr<nsIURI> mDocumentURI;
+ nsWeakPtr mElement;
+ nsCAutoString mSrc;
+ PRUint32 mLangId;
+ bool mActive;
+};
+
+#endif // XG_SCRIPT_ELEMENT_HH

Added: trunk/gom/include/xpgom/xgString.hh
==============================================================================
--- (empty file)
+++ trunk/gom/include/xpgom/xgString.hh Thu Aug 21 00:26:36 2008
@@ -0,0 +1,34 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef XG_STRING_HH
+#define XG_STRING_HH
+
+#ifdef MOZILLA_INTERNAL_API
+#include <nsString.h>
+#else
+#include <nsStringAPI.h>
+#endif
+
+#endif // XG_STRING_HH
+

Modified: trunk/gom/src/xpgom/Makefile.inc
==============================================================================
--- trunk/gom/src/xpgom/Makefile.inc (original)
+++ trunk/gom/src/xpgom/Makefile.inc Thu Aug 21 00:26:36 2008
@@ -3,30 +3,18 @@
lib_LTLIBRARIES += libxpgom.la

libxpgom_la_SOURCES :=
-#libxpgom_la_SOURCES += src/xpgom/gomwrapped.cc
-#libxpgom_la_SOURCES += src/xpgom/gomwrappedattr.cc
-#libxpgom_la_SOURCES += src/xpgom/gomwrappeddocument.cc
-#libxpgom_la_SOURCES += src/xpgom/gomwrappeddomimplementation.cc
-#libxpgom_la_SOURCES += src/xpgom/gomwrappedelement.cc
-#libxpgom_la_SOURCES += src/xpgom/gomwrappednamednodemap.cc
-#libxpgom_la_SOURCES += src/xpgom/gomwrappednode.cc
-#libxpgom_la_SOURCES += src/xpgom/xgDocument.cc
-#libxpgom_la_SOURCES += src/xpgom/xgDOMImplementation.cc
-#libxpgom_la_SOURCES += src/xpgom/xgElement.cc
libxpgom_la_SOURCES += src/xpgom/xgGomElementFactory.cc
libxpgom_la_SOURCES += src/xpgom/xgGtkElement.cc
libxpgom_la_SOURCES += src/xpgom/xgGtkElementFactory.cc
libxpgom_la_SOURCES += src/xpgom/xgGomModule.cc
-#libxpgom_la_SOURCES += src/xpgom/xgNode.cc
-libxpgom_la_SOURCES += src/xpgom/xgWindow.cc
-#libxpgom_la_SOURCES += src/xpgom/xgWrapped.cc
+libxpgom_la_SOURCES += src/xpgom/xgScriptElement.cc

-$(libxpgom_la_SOURCES): idl/xgPIWrapped.hh idl/xgIWindow.hh
idl/xgIParser.hh
+dist_noinst_DATA += src/xpgom/xgDocShellUnimplemented.cc
+
+$(libxpgom_la_SOURCES): $(idl_headers)

libxpgom_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-I$(top_builddir)/idl $(XPGOM_CFLAGS)
libxpgom_la_LIBDADD :=
libxpgom_la_LDFLAGS := -avoid-version -export-dynamic -no-undefined
$(XPGOM_LIBS)

dist_noinst_DATA += src/xpgom/xgParser.js
-
-# libxpgom_la_DEPENDENCIES := libgom.a

Modified: trunk/gom/src/xpgom/xgGomElementFactory.cc
==============================================================================
--- trunk/gom/src/xpgom/xgGomElementFactory.cc (original)
+++ trunk/gom/src/xpgom/xgGomElementFactory.cc Thu Aug 21 00:26:36 2008
@@ -24,6 +24,10 @@
#include "config.h"

#include "xpgom/xgGomElementFactory.hh"
+#include "xpgom/xgScriptElement.hh"
+#include "xpgom/xgString.hh"
+
+#include <nsISupportsUtils.h>

/* Implementation file */
NS_IMPL_ISUPPORTS1(xgGomElementFactory, nsIXTFElementFactory)
@@ -42,5 +46,10 @@
NS_IMETHODIMP
xgGomElementFactory::CreateElement (const nsAString &tagName,
nsIXTFElement **_retval)
{
- return NS_ERROR_NOT_IMPLEMENTED;
+ *_retval = NULL;
+ if (tagName.EqualsLiteral ("script")) {
+ *_retval = new xgScriptElement;
+ }
+ NS_IF_ADDREF (*_retval);
+ return NS_OK;
}

Modified: trunk/gom/src/xpgom/xgGomModule.cc
==============================================================================
--- trunk/gom/src/xpgom/xgGomModule.cc (original)
+++ trunk/gom/src/xpgom/xgGomModule.cc Thu Aug 21 00:26:36 2008
@@ -25,20 +25,9 @@

#include <glib/gmacros.h>

-#if 0
-#include "xpgom/xgDOMImplementation.hh"
-#include "xpgom/gomwrappeddomimplementation.hh"
-#include "xpgom/gomwrappeddocument.hh"
-#include "xpgom/gomwrappedelement.hh"
-#include "xpgom/gomwrappednamednodemap.hh"
-#include "xpgom/gomwrappedattr.hh"
-#endif
-
-#include "xpgom/xgWindow.hh"
#include "xpgom/xgGomElementFactory.hh"
#include "xpgom/xgGtkElementFactory.hh"
-
-#include "gom/gomwidget.h"
+#include "xpgom/xgString.hh"

#include <gtk/gtk.h>

@@ -46,15 +35,9 @@
#include <nsIFile.h>
#include <nsIGenericFactory.h>
#include <nsIXTFElementFactory.h>
-#include <nsStringAPI.h>

NS_GENERIC_FACTORY_CONSTRUCTOR(xgGomElementFactory);
NS_GENERIC_FACTORY_CONSTRUCTOR(xgGtkElementFactory);
-//NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(xgDOMImplementation, Init);
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT (xgWindow, Init);
-
-//NS_DECL_CLASSINFO(xgDOMImplementation)
-NS_DECL_CLASSINFO (xgWindow)

static const nsModuleComponentInfo components[] = {
{
@@ -67,27 +50,6 @@
XG_GTKELEMENTFACTORY_CID, XG_GTKELEMENTFACTORY_CONTRACTID,
xgGtkElementFactoryConstructor
},
- {
- "Gom Global Window Object",
- XG_WINDOW_CID, XG_WINDOW_CONTRACTID,
- xgWindowConstructor,
- NULL, NULL, NULL,
- NS_CI_INTERFACE_GETTER_NAME (xgWindow),
- NULL,
- &NS_CLASSINFO_NAME (xgWindow)
-
-#if 0
- },
- {
- "Gom DOM Implementation",
- XG_DOMIMPLEMENTATION_CID, XG_DOMIMPLEMENTATION_CONTRACTID,
- xgDOMImplementationConstructor,
- /* xgGomRegistrationProc */ NULL, NULL, NULL,
- NS_CI_INTERFACE_GETTER_NAME (xgDOMImplementation),
- NULL,
- &NS_CLASSINFO_NAME(xgDOMImplementation)
-#endif
- }
};

static nsresult
@@ -102,14 +64,6 @@
#include "gomwidgets.c"
#undef WIDGET

-#if 0
- gom_widget_init ();
- g_type_class_ref (GOM_TYPE_WRAPPED_DOM_IMPLEMENTATION);
- g_type_class_ref (GOM_TYPE_WRAPPED_NAMED_NODE_MAP);
- g_type_class_ref (GOM_TYPE_WRAPPED_ATTR);
- g_type_class_ref (GOM_TYPE_WRAPPED_ELEMENT);
- g_type_class_ref (GOM_TYPE_WRAPPED_DOCUMENT);
-#endif
return NS_OK;
}


Modified: trunk/gom/src/xpgom/xgGtkElement.cc
==============================================================================
--- trunk/gom/src/xpgom/xgGtkElement.cc (original)
+++ trunk/gom/src/xpgom/xgGtkElement.cc Thu Aug 21 00:26:36 2008
@@ -414,17 +414,17 @@
g_value_init (&gval, G_TYPE_STRING);
g_object_get_property (G_OBJECT (mObject), prop, &gval);
if (G_VALUE_HOLDS (&gval, G_TYPE_STRING)) {
- nsCAutoString rval (g_value_get_string (&gval));
+ _retval = NS_ConvertUTF8toUTF16 (nsCAutoString (g_value_get_string
(&gval)));
g_value_unset (&gval);
- return NS_CStringToUTF16 (rval, NS_CSTRING_ENCODING_UTF8, _retval);
+ return NS_OK;
}
g_value_unset (&gval);
} else {
const GValue *gvalp = (const GValue *)g_hash_table_lookup (mAttrs,
prop);
if (gvalp) {
if (G_VALUE_HOLDS_STRING (gvalp)) {
- nsCAutoString rval (g_value_get_string (gvalp));
- return NS_CStringToUTF16 (rval, NS_CSTRING_ENCODING_UTF8, _retval);
+ _retval = NS_ConvertUTF8toUTF16 (nsCAutoString (g_value_get_string
(gvalp)));
+ return NS_OK;
}
}
}

Modified: trunk/gom/src/xpgom/xgGtkElementFactory.cc
==============================================================================
--- trunk/gom/src/xpgom/xgGtkElementFactory.cc (original)
+++ trunk/gom/src/xpgom/xgGtkElementFactory.cc Thu Aug 21 00:26:36 2008
@@ -25,9 +25,9 @@

#include "xpgom/xgGtkElement.hh"
#include "xpgom/xgGtkElementFactory.hh"
+#include "xpgom/xgString.hh"

#include <nsCOMPtr.h>
-#include <nsStringAPI.h>

#include <gtk/gtkwidget.h>


Added: trunk/gom/src/xpgom/xgScriptElement.cc
==============================================================================
--- (empty file)
+++ trunk/gom/src/xpgom/xgScriptElement.cc Thu Aug 21 00:26:36 2008
@@ -0,0 +1,404 @@
+/*
+The MIT License
+
+Copyright (c) 2008 jacob berkman <ja...@ilovegom.org>
+
+Permission is hereby granted, free of charge, to any person obtaining a
copy
+of this software and associated documentation files (the "Software"), to
deal
+in the Software without restriction, including without limitation the
rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#include "config.h"
+
+#include "xpgom/xgScriptElement.hh"
+
+#include <nsDOMError.h>
+#include <nsIAtom.h>
+#include <nsIChannel.h>
+#include <nsIDOM3Document.h>
+#include <nsIDOMDocument.h>
+#include <nsIDOMElement.h>
+#include <nsIDOMScriptObjectFactory.h>
+#include <nsIDocument.h>
+#include <nsIIOService.h>
+#include <nsIInputStream.h>
+#include <nsIProgrammingLanguage.h>
+#include <nsIScriptContext.h>
+#include <nsIScriptGlobalObject.h>
+#include <nsISupportsImpl.h>
+#include <nsServiceManagerUtils.h>
+#include <nsIXTFElementWrapper.h>
+
+#include <glib/gmessages.h>
+
+#include <stdio.h>
+
+#include "gommacros.h"
+
+static NS_DEFINE_CID (kDOMScriptObjectFactoryCID,
NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
+
+xgScriptElement::xgScriptElement()
+ : mLangId (nsIProgrammingLanguage::UNKNOWN),
+ mActive (true)
+{
+}
+
+xgScriptElement::~xgScriptElement()
+{
+}
+
+NS_IMPL_ISUPPORTS1 (xgScriptElement, nsIXTFElement)
+
+nsresult
+xgScriptElement::DownloadScript ()
+{
+ NS_ENSURE_TRUE (mActive, NS_ERROR_FAILURE);
+
+ nsresult rv;
+ nsCOMPtr<nsIIOService> io (do_GetService
("@mozilla.org/network/io-service;1", &rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ nsCOMPtr<nsIChannel> chan;
+ rv = io->NewChannel (mSrc, "UTF-8", mDocumentURI, getter_AddRefs
(chan));
+ mDocumentURI = NULL;
+ mSrc.Truncate ();
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ nsCOMPtr<nsIURI> uri;
+ rv = chan->GetOriginalURI (getter_AddRefs (uri));
+ if (NS_SUCCEEDED (rv)) {
+ nsCAutoString curi;
+ if (NS_SUCCEEDED (uri->GetSpec (curi))) {
+ g_message (GOM_LOC ("<script> downloading %s..."), curi.get());
+ }
+ }
+
+ nsCOMPtr<nsIInputStream> stream;
+ rv = chan->Open (getter_AddRefs (stream));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ nsCAutoString script;
+ PRUint32 bytes_read;
+ char buf[BUFSIZ];
+ while (1) {
+ rv = stream->Read (buf, BUFSIZ, &bytes_read);
+ if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ continue;
+ }
+ NS_ENSURE_SUCCESS (rv, rv);
+ if (bytes_read == 0) {
+ stream->Close();
+ break;
+ }
+ script.Append (buf, bytes_read);
+ }
+ mScript = NS_ConvertUTF8toUTF16 (script);
+
+ return NS_OK;
+}
+
+nsresult
+xgScriptElement::EvaluateScript ()
+{
+ NS_ENSURE_TRUE (mActive, NS_ERROR_FAILURE);
+ mActive = false;
+
+ NS_ENSURE_FALSE (mScript.IsEmpty(), NS_OK);
+
+ nsCOMPtr<nsIScriptGlobalObject> global = do_QueryReferent (mGlobal);
+ NS_ENSURE_TRUE (global, NS_ERROR_FAILURE);
+
+ nsresult rv = global->EnsureScriptEnvironment (mLangId);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ nsCOMPtr<nsIScriptContext> cx (global->GetScriptContext (mLangId));
+ NS_ENSURE_TRUE (cx, NS_ERROR_FAILURE);
+
+ nsAutoString aRet;
+ PRBool isUndefined;
+ rv = cx->EvaluateString (mScript, NULL, NULL, NULL, 0, 0, &aRet,
&isUndefined);
+ mScript.Truncate ();
+ mGlobal = NULL;
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ g_message (GOM_LOC ("<script> evaluated to %s (%d)"),
+ isUndefined ? "<undefined>" : NS_ConvertUTF16toUTF8 (aRet).get(),
+ isUndefined);
+
+ return NS_OK;
+}
+
+nsresult
+xgScriptElement::MaybeEvaluateScript ()
+{
+ NS_ENSURE_TRUE (mActive, NS_ERROR_FAILURE);
+ nsresult rv;
+ if (mLangId != nsIProgrammingLanguage::UNKNOWN) {
+ if (!mSrc.IsEmpty ()){
+ if (!mDocumentURI) {
+ return NS_OK;
+ }
+ rv = DownloadScript ();
+ mActive = NS_SUCCEEDED (rv);
+ NS_ENSURE_SUCCESS (rv, rv);
+ }
+ if (!mScript.IsEmpty ()) {
+ rv = EvaluateScript ();
+ NS_ENSURE_FALSE (mActive, NS_ERROR_FAILURE);
+ NS_ENSURE_SUCCESS (rv, rv);
+ }
+ }
+ return NS_OK;
+}
+
+/* void onCreated (in nsIXTFElementWrapper wrapper); */
+NS_IMETHODIMP
+xgScriptElement::OnCreated (nsIXTFElementWrapper *wrapper)
+{
+ nsCOMPtr<nsIDOMElement> elem;
+ wrapper->GetElementNode (getter_AddRefs (elem));
+
+ // unset in OnDestroyed
+ mElement = getter_AddRefs (NS_GetWeakReference (elem));
+
+ wrapper->SetNotificationMask (NOTIFY_DOCUMENT_CHANGED |
+ NOTIFY_WILL_INSERT_CHILD |
+ NOTIFY_WILL_APPEND_CHILD |
+ NOTIFY_ATTRIBUTE_SET |
+ NOTIFY_DONE_ADDING_CHILDREN);
+
+ nsCOMPtr<nsIDOMDocument> doc;
+ nsresult rv = elem->GetOwnerDocument (getter_AddRefs (doc));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ return NS_OK;
+}
+
+/* void onDestroyed (); */
+NS_IMETHODIMP xgScriptElement::OnDestroyed()
+{
+ return NS_OK;
+}
+
+/* readonly attribute boolean isAttributeHandler; */
+NS_IMETHODIMP xgScriptElement::GetIsAttributeHandler(PRBool
*aIsAttributeHandler)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void getScriptingInterfaces (out unsigned long count, [array, size_is
(count), retval] out nsIIDPtr array); */
+NS_IMETHODIMP xgScriptElement::GetScriptingInterfaces(PRUint32 *count,
nsIID * **array)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willChangeDocument (in nsIDOMDocument newDoc); */
+NS_IMETHODIMP xgScriptElement::WillChangeDocument(nsIDOMDocument *newDoc)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void documentChanged (in nsIDOMDocument newDoc); */
+NS_IMETHODIMP
+xgScriptElement::DocumentChanged (nsIDOMDocument *newDoc)
+{
+ if (!mActive) {
+ return NS_OK;
+ }
+
+ nsCOMPtr<nsIScriptGlobalObject> global = do_QueryReferent (mGlobal);
+ NS_ENSURE_FALSE (global, NS_ERROR_FAILURE);
+
+ nsCOMPtr<nsIDocument> doc (do_QueryInterface (newDoc));
+ if (doc) {
+ global = doc->GetScriptGlobalObject ();
+ }
+ mGlobal = getter_AddRefs (NS_GetWeakReference (global));
+ if (!global) {
+ g_warning (GOM_LOC ("Could not find a ScriptedGlobalObject; disabling
this script"));
+ mActive = false;
+ }
+
+ mDocumentURI = doc->GetDocumentURI ();
+ if (!mDocumentURI) {
+ nsCOMPtr<nsIDOM3Document> doc3 (do_QueryInterface (newDoc));
+ NS_ENSURE_TRUE (doc3, NS_OK);
+
+ nsCOMPtr<nsIIOService> io (do_GetService
("@mozilla.org/network/io-service;1"));
+ NS_ENSURE_TRUE (io, NS_OK);
+
+ nsAutoString uriStr;
+ nsresult rv = doc3->GetDocumentURI (uriStr);
+ NS_ENSURE_SUCCESS (rv, NS_OK);
+
+ rv = io->NewURI (NS_ConvertUTF16toUTF8 (uriStr), "UTF-8", NULL,
getter_AddRefs (mDocumentURI));
+ NS_ENSURE_SUCCESS (rv, NS_OK);
+ }
+
+ nsCAutoString spec;
+ mDocumentURI->GetSpec (spec);
+ g_message (GOM_LOC ("Have documentURI: %s"), spec.get());
+ return MaybeEvaluateScript ();
+}
+
+/* void willChangeParent (in nsIDOMElement newParent); */
+NS_IMETHODIMP xgScriptElement::WillChangeParent(nsIDOMElement *newParent)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void parentChanged (in nsIDOMElement newParent); */
+NS_IMETHODIMP xgScriptElement::ParentChanged(nsIDOMElement *newParent)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willInsertChild (in nsIDOMNode child, in unsigned long index); */
+NS_IMETHODIMP
+xgScriptElement::WillInsertChild (nsIDOMNode *child, PRUint32 index)
+{
+ return WillAppendChild (child);
+}
+
+/* void childInserted (in nsIDOMNode child, in unsigned long index); */
+NS_IMETHODIMP
+xgScriptElement::ChildInserted(nsIDOMNode *child, PRUint32 index)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willAppendChild (in nsIDOMNode child); */
+NS_IMETHODIMP xgScriptElement::WillAppendChild (nsIDOMNode *child)
+{
+ PRUint16 childType;
+ nsresult rv = child->GetNodeType (&childType);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ NS_ENSURE_TRUE (childType == nsIDOMNode::TEXT_NODE ||
+ childType == nsIDOMNode::CDATA_SECTION_NODE,
+ NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
+
+ if (!mActive) {
+ return NS_OK;
+ }
+
+ nsAutoString text;
+ rv = child->GetNodeValue (text);
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ mScript.Append (text);
+ return NS_OK;
+}
+
+/* void childAppended (in nsIDOMNode child); */
+NS_IMETHODIMP xgScriptElement::ChildAppended(nsIDOMNode *child)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willRemoveChild (in unsigned long index); */
+NS_IMETHODIMP xgScriptElement::WillRemoveChild(PRUint32 index)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void childRemoved (in unsigned long index); */
+NS_IMETHODIMP xgScriptElement::ChildRemoved(PRUint32 index)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void willSetAttribute (in nsIAtom name, in AString newValue); */
+NS_IMETHODIMP xgScriptElement::WillSetAttribute(nsIAtom *name, const
nsAString &newValue)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void attributeSet (in nsIAtom name, in AString newValue); */
+NS_IMETHODIMP
+xgScriptElement::AttributeSet (nsIAtom *name, const nsAString &newValue)
+{
+ if (!mActive) {
+ return NS_OK;
+ }
+
+ nsresult rv = NS_OK;
+ if (name->Equals (NS_LITERAL_STRING ("src"))) {
+ NS_ENSURE_TRUE (mSrc.IsEmpty(), NS_OK);
+ mSrc = NS_ConvertUTF16toUTF8 (newValue);
+ g_message (GOM_LOC ("got src=\"%s\""), mSrc.get());
+ } else if (name->Equals (NS_LITERAL_STRING ("type"))) {
+ nsCOMPtr<nsIDOMScriptObjectFactory> sof (do_GetService
(kDOMScriptObjectFactoryCID, &rv));
+ NS_ENSURE_SUCCESS (rv, rv);
+
+ rv = sof->GetIDForScriptType (newValue, &mLangId);
+ NS_ENSURE_SUCCESS (rv, rv);
+ }
+
+ return MaybeEvaluateScript ();
+}
+
+/* void willRemoveAttribute (in nsIAtom name); */
+NS_IMETHODIMP xgScriptElement::WillRemoveAttribute(nsIAtom *name)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void attributeRemoved (in nsIAtom name); */
+NS_IMETHODIMP xgScriptElement::AttributeRemoved(nsIAtom *name)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void beginAddingChildren (); */
+NS_IMETHODIMP xgScriptElement::BeginAddingChildren()
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void doneAddingChildren (); */
+NS_IMETHODIMP
+xgScriptElement::DoneAddingChildren ()
+{
+ if (!mActive) {
+ return NS_OK;
+ }
+ return MaybeEvaluateScript ();
+}
+
+/* boolean handleDefault (in nsIDOMEvent aEvent); */
+NS_IMETHODIMP xgScriptElement::HandleDefault(nsIDOMEvent *aEvent, PRBool
*_retval)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void cloneState (in nsIDOMElement aElement); */
+NS_IMETHODIMP xgScriptElement::CloneState(nsIDOMElement *aElement)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* readonly attribute nsIDOMAttr accesskeyNode; */
+NS_IMETHODIMP xgScriptElement::GetAccesskeyNode(nsIDOMAttr *
*aAccesskeyNode)
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}
+
+/* void performAccesskey (); */
+NS_IMETHODIMP xgScriptElement::PerformAccesskey()
+{
+ XG_RETURN_NOT_IMPLEMENTED;
+}

Added: trunk/gom/src/xulapp/application.ini.in
==============================================================================
--- (empty file)
+++ trunk/gom/src/xulapp/application.ini.in Thu Aug 21 00:26:36 2008
@@ -0,0 +1,12 @@
+[App]
+Vendor=87k Networks
+Name=Gom
+Version=@VERSION@
+BuildID=0
+Copyright=Copyright (c) 2008 jacob berkman
+ID=xp...@ilovegom.org
+
+[Gecko]
+MinVersion=1.9
+MaxVersion=1.9.0.*
+

Added: trunk/gom/src/xulapp/chrome/chrome.manifest
==============================================================================
--- (empty file)
+++ trunk/gom/src/xulapp/chrome/chrome.manifest Thu Aug 21 00:26:36 2008
@@ -0,0 +1,2 @@
+content xpgom file:content/xpgom/
+

Added: trunk/gom/src/xulapp/chrome/content/xpgom/gom.js
==============================================================================
--- (empty file)
+++ trunk/gom/src/xulapp/chrome/content/xpgom/gom.js Thu Aug 21 00:26:36
2008
@@ -0,0 +1,14 @@
+function main () {
+ const Ci = Components.interfaces;
+ dump ("Ok, let's see what we've got.\n");
+ var cmdLine = window.arguments[0];
+ cmdLine = cmdLine.QueryInterface (Ci.nsICommandLine);
+ var url = cmdLine.getArgument (0);
+ alert (url);
+};
+function go () {
+ var urlbar = document.getElementById ('urlbar');
+ var browser = document.getElementById ('browser');
+ browser.loadURI (urlbar.value, null, null);
+};
+//addEventListener("load", main, false);

Added: trunk/gom/src/xulapp/chrome/content/xpgom/gom.xul
==============================================================================
--- (empty file)
+++ trunk/gom/src/xulapp/chrome/content/xpgom/gom.xul Thu Aug 21 00:26:36
2008
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+<window
+ id="main"
+ title="Gom"
+ height="300"
+ width="400"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script src="gom.js"/>
+ <hbox>
+ <textbox id="urlbar" flex="1"
value="file:///Users/jacob/cvs/gom/examples/console.gom" onchange="go();"/>
+ <button id="go" label="Go" oncommand="go();"/>
+ </hbox>
+ <browser id="browser" src="" flex="1" type="content-primary"/>
+</window>

Added: trunk/gom/src/xulapp/defaults/preferences/prefs.js
==============================================================================
--- (empty file)
+++ trunk/gom/src/xulapp/defaults/preferences/prefs.js Thu Aug 21 00:26:36
2008
@@ -0,0 +1 @@
+pref ('toolkit.defaultChromeURI', 'chrome://xpgom/content/gom.xul');

Reply all
Reply to author
Forward
0 new messages