2012-10-30 00:09:29 +04:00
|
|
|
/* binding to generate window */
|
|
|
|
|
|
|
|
#include "dom.bnd"
|
|
|
|
|
|
|
|
webidlfile "html.idl";
|
|
|
|
|
|
|
|
hdrcomment "Part of NetSurf Project";
|
|
|
|
|
|
|
|
preamble %{
|
|
|
|
|
|
|
|
#include <dom/dom.h>
|
|
|
|
|
|
|
|
#include "utils/config.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
|
|
|
|
#include "javascript/jsapi.h"
|
|
|
|
#include "javascript/jsapi/binding.h"
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
binding window {
|
|
|
|
type js_libdom; /* the binding type */
|
|
|
|
|
|
|
|
interface Window; /* Web IDL interface to generate */
|
|
|
|
|
|
|
|
/* private are parameters to constructor stored in private
|
|
|
|
* context structure.
|
|
|
|
*
|
|
|
|
* internal are value stored in private context structure but not
|
|
|
|
* passed to constructor but are considered for property
|
|
|
|
* getters/setters.
|
|
|
|
*/
|
|
|
|
private "struct browser_window *" bw;
|
|
|
|
private "struct html_content *" htmlc;
|
|
|
|
internal "JSObject *" document;
|
|
|
|
internal "JSObject *" navigator;
|
|
|
|
internal "JSObject *" console;
|
|
|
|
internal "JSObject *" location;
|
|
|
|
}
|
2012-10-30 03:46:07 +04:00
|
|
|
|
2012-11-06 22:06:23 +04:00
|
|
|
api mark %{
|
|
|
|
if (private != NULL) {
|
|
|
|
if (private->document != NULL) {
|
2012-11-08 04:40:21 +04:00
|
|
|
JSAPI_GCMARK(private->document);
|
2012-11-06 22:06:23 +04:00
|
|
|
}
|
|
|
|
if (private->navigator != NULL) {
|
2012-11-08 04:40:21 +04:00
|
|
|
JSAPI_GCMARK(private->navigator);
|
2012-11-06 22:06:23 +04:00
|
|
|
}
|
|
|
|
if (private->console != NULL) {
|
2012-11-08 04:40:21 +04:00
|
|
|
JSAPI_GCMARK(private->console);
|
2012-11-06 22:06:23 +04:00
|
|
|
}
|
|
|
|
if (private->location != NULL) {
|
2012-11-08 04:40:21 +04:00
|
|
|
JSAPI_GCMARK(private->location);
|
2012-11-06 22:06:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
%}
|
|
|
|
|
2012-11-03 17:52:13 +04:00
|
|
|
api global %{
|
|
|
|
%}
|
2012-10-30 03:46:07 +04:00
|
|
|
|
2012-10-30 00:09:29 +04:00
|
|
|
api init %{
|
|
|
|
JSObject *user_proto;
|
|
|
|
|
|
|
|
prototype = JS_NewCompartmentAndGlobalObject(cx, &JSClass_Window, NULL);
|
|
|
|
if (prototype == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @todo reconsider global object handling. future
|
|
|
|
* editions of spidermonkey appear to be removing the
|
|
|
|
* idea of a global so we probably need to handle
|
|
|
|
* global object references internally
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* set the contexts global */
|
|
|
|
JS_SetGlobalObject(cx, prototype);
|
|
|
|
|
|
|
|
/* Populate the global object with the standard globals, like
|
|
|
|
* Object and Array.
|
|
|
|
*/
|
|
|
|
if (!JS_InitStandardClasses(cx, prototype)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add functions to prototype */
|
|
|
|
if (!JS_DefineFunctions(cx, prototype, jsclass_functions)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add properties to prototype */
|
|
|
|
if (!JS_DefineProperties(cx, prototype, jsclass_properties))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Initialises all the user javascript classes to make their
|
|
|
|
* prototypes available.
|
|
|
|
*/
|
|
|
|
/** @todo should we be managing these prototype objects ourselves */
|
|
|
|
user_proto = jsapi_InitClass_Document(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-31 05:22:35 +04:00
|
|
|
|
|
|
|
user_proto = jsapi_InitClass_Navigator(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-31 18:31:18 +04:00
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
user_proto = jsapi_InitClass_Location(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-31 18:31:18 +04:00
|
|
|
user_proto = jsapi_InitClass_Console(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-02 01:13:14 +04:00
|
|
|
user_proto = jsapi_InitClass_HTMLElement(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-04 01:37:06 +04:00
|
|
|
user_proto = jsapi_InitClass_HTMLCollection(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_proto = jsapi_InitClass_NodeList(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-07 22:52:30 +04:00
|
|
|
user_proto = jsapi_InitClass_Text(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-14 06:11:01 +04:00
|
|
|
user_proto = jsapi_InitClass_Node(cx, prototype);
|
|
|
|
if (user_proto == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-30 00:09:29 +04:00
|
|
|
%}
|
|
|
|
|
|
|
|
api new %{
|
|
|
|
/* @todo sort out windows that are not globals */
|
|
|
|
assert(parent == NULL);
|
|
|
|
|
|
|
|
/* the window object is the global so its prototype *is* the instance */
|
|
|
|
newobject = prototype;
|
|
|
|
|
|
|
|
/* instantiate the subclasses off the window global */
|
|
|
|
private->document = jsapi_new_Document(cx,
|
|
|
|
NULL,
|
|
|
|
newobject,
|
2012-11-04 15:18:37 +04:00
|
|
|
(dom_document *)dom_node_ref(htmlc->document),
|
2012-10-30 00:09:29 +04:00
|
|
|
htmlc);
|
|
|
|
if (private->document == NULL) {
|
|
|
|
free(private);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-31 05:22:35 +04:00
|
|
|
private->navigator = jsapi_new_Navigator(cx, NULL, newobject);
|
|
|
|
if (private->navigator == NULL) {
|
2012-10-30 00:09:29 +04:00
|
|
|
free(private);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-31 05:22:35 +04:00
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
private->location = jsapi_new_Location(cx, NULL, newobject, bw);
|
|
|
|
if (private->location == NULL) {
|
|
|
|
free(private);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-10-30 00:09:29 +04:00
|
|
|
|
2012-10-31 18:31:18 +04:00
|
|
|
private->console = jsapi_new_Console(cx, NULL, newobject);
|
2012-10-30 00:09:29 +04:00
|
|
|
if (private->console == NULL) {
|
|
|
|
free(private);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
/** @todo forms, history */
|
|
|
|
|
2012-10-30 00:09:29 +04:00
|
|
|
LOG(("Created new window object %p", newobject));
|
|
|
|
%}
|
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
operation confirm %{
|
|
|
|
warn_user(message, NULL);
|
|
|
|
%}
|
2012-10-30 00:09:29 +04:00
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
operation alert %{
|
|
|
|
warn_user(message, NULL);
|
|
|
|
%}
|
2012-10-30 00:09:29 +04:00
|
|
|
|
2012-11-02 03:30:28 +04:00
|
|
|
operation prompt %{
|
|
|
|
warn_user(message, NULL);
|
|
|
|
%}
|
|
|
|
|
|
|
|
getter window %{
|
|
|
|
jsret = obj;
|
|
|
|
%}
|
|
|
|
|
|
|
|
getter self %{
|
|
|
|
jsret = obj;
|
|
|
|
%}
|