add navigator interface
This commit is contained in:
parent
79e557bbe8
commit
ede48d6074
|
@ -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))
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/* Binding to generate Navigator interface
|
||||
*
|
||||
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
|
||||
*
|
||||
* 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 <vince@netsurf-browser.org>";
|
||||
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 <dom/dom.h>
|
||||
|
||||
#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 | "<Browsername>" | "NetSurf" | Browsers named other than
|
||||
* | | | "Netscape", "Mozilla",
|
||||
* | | | "Netscape Navigator",
|
||||
* | | | "Microsoft Internet Explorer"
|
||||
* | | | often other browser have
|
||||
* | | | "(compatible with Netscape)"
|
||||
* | | | append.
|
||||
* ------------+-----------------+--------------+------------------------------
|
||||
* appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version
|
||||
* | | | number e.g "3.0".
|
||||
* ------------+-----------------+--------------+------------------------------
|
||||
* language | "<lang>" | "<lang>" | The language the frontend is
|
||||
* | | | configured for
|
||||
* ------------+-----------------+--------------+------------------------------
|
||||
* platform | "<krn> <hw>" | "<krn> <hw>" | 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);
|
||||
}
|
||||
%}
|
|
@ -0,0 +1,120 @@
|
|||
/* Binding to generate Navigator interface
|
||||
*
|
||||
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
|
||||
*
|
||||
* 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 <vince@netsurf-browser.org>";
|
||||
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 <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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 | "<Browsername>" | "NetSurf" | Browsers named other than
|
||||
* | | | "Netscape", "Mozilla",
|
||||
* | | | "Netscape Navigator",
|
||||
* | | | "Microsoft Internet Explorer"
|
||||
* | | | often other browser have
|
||||
* | | | "(compatible with Netscape)"
|
||||
* | | | append.
|
||||
* ------------+-----------------+--------------+------------------------------
|
||||
* appVersion | "<ver> (<type>)"| "<ver>" | Actually just the version
|
||||
* | | | number e.g "3.0".
|
||||
* ------------+-----------------+--------------+------------------------------
|
||||
* language | "<lang>" | "<lang>" | The language the frontend is
|
||||
* | | | configured for
|
||||
* ------------+-----------------+--------------+------------------------------
|
||||
* platform | "<krn> <hw>" | "<krn> <hw>" | 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()));
|
||||
%}
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue