From ede48d60748101e9795050955d934ea6e329d4c5 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 31 Oct 2012 01:22:35 +0000 Subject: add navigator interface --- Makefile.sources.javascript | 5 +- javascript/jsapi/binding.h | 4 +- javascript/jsapi/bindings/example.bnd | 90 ++++++++++++++++++++++++ javascript/jsapi/bindings/navigator.bnd | 120 ++++++++++++++++++++++++++++++++ javascript/jsapi/bindings/window.bnd | 12 ++-- javascript/jsapi/window.c | 3 +- 6 files changed, 225 insertions(+), 9 deletions(-) create mode 100644 javascript/jsapi/bindings/example.bnd create mode 100644 javascript/jsapi/bindings/navigator.bnd diff --git a/Makefile.sources.javascript b/Makefile.sources.javascript index e188df6c1..626854869 100644 --- a/Makefile.sources.javascript +++ b/Makefile.sources.javascript @@ -12,6 +12,7 @@ S_JSAPI_BINDING:= JSAPI_BINDING_htmldocument := javascript/jsapi/bindings/htmldocument.bnd JSAPI_BINDING_window := javascript/jsapi/bindings/window.bnd +JSAPI_BINDING_navigator := javascript/jsapi/bindings/navigator.bnd # 1: input file # 2: output file @@ -29,8 +30,8 @@ endef # Javascript sources ifeq ($(NETSURF_USE_JS),YES) -S_JSAPI = navigator.c console.c htmlelement.c -#htmldocument.c window.c +S_JSAPI = console.c htmlelement.c +#htmldocument.c window.c navigator.c S_JAVASCRIPT += content.c jsapi.c $(addprefix jsapi/,$(S_JSAPI)) diff --git a/javascript/jsapi/binding.h b/javascript/jsapi/binding.h index 7ead6f6cb..2d88c005b 100644 --- a/javascript/jsapi/binding.h +++ b/javascript/jsapi/binding.h @@ -65,13 +65,15 @@ JSObject *jsapi_new_Document(JSContext *cx, */ JSObject *jsapi_new_Console(JSContext *cx, JSObject *parent); + +JSObject *jsapi_InitClass_Navigator(JSContext *cx, JSObject *parent); /** Create a new javascript navigator object * * @param cx The javascript context. * @param parent The parent object, usually a global window object * @return new javascript object or NULL on error */ -JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *parent); +JSObject *jsapi_new_Navigator(JSContext *cx, JSObject *proto, JSObject *parent); /** Create a new javascript element object * diff --git a/javascript/jsapi/bindings/example.bnd b/javascript/jsapi/bindings/example.bnd new file mode 100644 index 000000000..897e9a530 --- /dev/null +++ b/javascript/jsapi/bindings/example.bnd @@ -0,0 +1,90 @@ +/* Binding to generate Navigator interface + * + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * Released under the terms of the MIT License, + * http://www.opensource.org/licenses/mit-license + */ + +#include "dom.bnd" + +webidlfile "html.idl"; + +hdrcomment "Copyright 2012 Vincent Sanders "; +hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; +hdrcomment "Released under the terms of the MIT License,"; +hdrcomment " http://www.opensource.org/licenses/mit-license"; + +preamble %{ + +#include + +#include "utils/config.h" +#include "utils/log.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +/* + * navigator properties for netsurf + * + * Property | Everyone else | NetSurf | Notes + * ------------+-----------------+--------------+------------------------------ + * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless + * | | | constant as everyone returns + * | | | "Mozilla" which is dumb + * ------------+-----------------+--------------+------------------------------ + * appName | "" | "NetSurf" | Browsers named other than + * | | | "Netscape", "Mozilla", + * | | | "Netscape Navigator", + * | | | "Microsoft Internet Explorer" + * | | | often other browser have + * | | | "(compatible with Netscape)" + * | | | append. + * ------------+-----------------+--------------+------------------------------ + * appVersion | " ()"| "" | Actually just the version + * | | | number e.g "3.0". + * ------------+-----------------+--------------+------------------------------ + * language | "" | "" | The language the frontend is + * | | | configured for + * ------------+-----------------+--------------+------------------------------ + * platform | " " | " " | Efectively uname -s -i, + * | | | eg "Linux x86_64" + * ------------+-----------------+--------------+------------------------------ + * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string + * | | | with excessive lies + * ------------+-----------------+--------------+------------------------------ + */ + +%} + +binding navigator { + type js_libdom; /* the binding type */ + + interface Navigator; /* Web IDL interface to generate */ + + /* private members: + * - stored in private context structure. + * - passed as parameters to constructor and stored automatically. + * - are *not* considered for property getters/setters. + * + * internal members: + * - value stored in private context structure + * - not passed to constructor + * - must be instantiated by constructor + * - are considered for property getters/setters. + */ + private "dom_document *" node; + private "struct html_content *" htmlc; +} + +operation write %{ + LOG(("content %p parser %p writing %s", + private->htmlc, private->htmlc->parser, text)); + + if (private->htmlc->parser != NULL) { + dom_hubbub_parser_insert_chunk(private->htmlc->parser, (uint8_t *)text, text_len); + } +%} diff --git a/javascript/jsapi/bindings/navigator.bnd b/javascript/jsapi/bindings/navigator.bnd new file mode 100644 index 000000000..596f1ac63 --- /dev/null +++ b/javascript/jsapi/bindings/navigator.bnd @@ -0,0 +1,120 @@ +/* Binding to generate Navigator interface + * + * Copyright 2012 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * Released under the terms of the MIT License, + * http://www.opensource.org/licenses/mit-license + */ + +#include "dom.bnd" + +webidlfile "html.idl"; + +hdrcomment "Copyright 2012 Vincent Sanders "; +hdrcomment "This file is part of NetSurf, http://www.netsurf-browser.org/"; +hdrcomment "Released under the terms of the MIT License,"; +hdrcomment " http://www.opensource.org/licenses/mit-license"; + +preamble %{ + +#include +#include + +#include "desktop/netsurf.h" +#include "desktop/options.h" + +#include "utils/config.h" +#include "utils/useragent.h" +#include "utils/log.h" +#include "utils/utsname.h" + +#include "javascript/jsapi.h" +#include "javascript/jsapi/binding.h" + +/* + * navigator properties for netsurf + * + * Property | Everyone else | NetSurf | Notes + * ------------+-----------------+--------------+------------------------------ + * appCodeName | "Mozilla" | "NetSurf" | This is kinda a pointless + * | | | constant as everyone returns + * | | | "Mozilla" which is dumb + * ------------+-----------------+--------------+------------------------------ + * appName | "" | "NetSurf" | Browsers named other than + * | | | "Netscape", "Mozilla", + * | | | "Netscape Navigator", + * | | | "Microsoft Internet Explorer" + * | | | often other browser have + * | | | "(compatible with Netscape)" + * | | | append. + * ------------+-----------------+--------------+------------------------------ + * appVersion | " ()"| "" | Actually just the version + * | | | number e.g "3.0". + * ------------+-----------------+--------------+------------------------------ + * language | "" | "" | The language the frontend is + * | | | configured for + * ------------+-----------------+--------------+------------------------------ + * platform | " " | " " | Efectively uname -s -i, + * | | | eg "Linux x86_64" + * ------------+-----------------+--------------+------------------------------ + * userAgent | "Mozilla/5.0 (" | "NetSurf" | The usual useragent string + * | | | with excessive lies + * ------------+-----------------+--------------+------------------------------ + */ + +#define NAVIGATOR_APPNAME "NetSurf" +#define NAVIGATOR_APPCODENAME "NetSurf" +%} + +binding navigator { + type js_libdom; /* the binding type */ + + interface Navigator; /* Web IDL interface to generate */ + +} + +getter appName %{ + jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPNAME)); +%} + +getter appCodeName %{ + jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, NAVIGATOR_APPCODENAME)); +%} + +getter appVersion %{ + jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, netsurf_version)); +%} + +getter language %{ + const char *alang = nsoption_charp(accept_language); + + if (alang != NULL) { + jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, alang)); + } + +%} + +getter platform %{ + struct utsname *cutsname; + + cutsname = malloc(sizeof(struct utsname)); + + if ((cutsname != NULL) && (uname(cutsname) >= 0)) { + char *platstr; + int platstrlen; + + platstrlen = strlen(cutsname->sysname) + strlen(cutsname->machine) + 2; + platstr = malloc(platstrlen); + if (platstr != NULL) { + snprintf(platstr, platstrlen, "%s %s", cutsname->sysname, cutsname->machine); + jsretval = STRING_TO_JSVAL(JS_NewStringCopyN(cx, platstr, platstrlen - 1)); + free(platstr); + } + } +%} + +getter userAgent %{ + jsretval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, user_agent_string())); +%} diff --git a/javascript/jsapi/bindings/window.bnd b/javascript/jsapi/bindings/window.bnd index c0b659ea1..9d4a844a1 100644 --- a/javascript/jsapi/bindings/window.bnd +++ b/javascript/jsapi/bindings/window.bnd @@ -79,6 +79,11 @@ api init %{ if (user_proto == NULL) { return NULL; } + + user_proto = jsapi_InitClass_Navigator(cx, prototype); + if (user_proto == NULL) { + return NULL; + } %} api new %{ @@ -99,13 +104,12 @@ api new %{ return NULL; } -/* - private->navigator_obj = jsapi_new_Navigator(cx, window); - if (private->navigator_obj == NULL) { + private->navigator = jsapi_new_Navigator(cx, NULL, newobject); + if (private->navigator == NULL) { free(private); return NULL; } -*/ + /** @todo forms, history, location */ private->console = jsapi_new_Console(cx, newobject); diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c index 476a38324..062d925da 100644 --- a/javascript/jsapi/window.c +++ b/javascript/jsapi/window.c @@ -263,13 +263,12 @@ JSObject *jsapi_new_Window(JSContext *cx, return NULL; } -/* private->navigator_obj = jsapi_new_Navigator(cx, window); if (private->navigator_obj == NULL) { free(private); return NULL; } -*/ + /** @todo forms, history, location */ private->console_obj = jsapi_new_Console(cx, window); -- cgit v1.2.3