2012-06-11 02:17:30 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/log.h"
|
|
|
|
|
2012-08-09 19:26:57 +04:00
|
|
|
#include "javascript/jsapi.h"
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
/* IDL
|
2012-06-27 22:16:45 +04:00
|
|
|
|
|
|
|
[NamedPropertiesObject]
|
|
|
|
interface Window : EventTarget {
|
|
|
|
// the current browsing context
|
|
|
|
[Unforgeable] readonly attribute WindowProxy window;
|
|
|
|
[Replaceable] readonly attribute WindowProxy self;
|
|
|
|
[Unforgeable] readonly attribute Document document;
|
2012-06-30 20:38:12 +04:00
|
|
|
attribute DOMString name;
|
2012-06-27 22:16:45 +04:00
|
|
|
[PutForwards=href, Unforgeable] readonly attribute Location location;
|
|
|
|
readonly attribute History history;
|
|
|
|
|
|
|
|
boolean find(optional DOMString aString, optional boolean aCaseSensitive, optional boolean aBackwards, optional boolean aWrapAround, optional boolean aWholeWord, optional boolean aSearchInFrames, optional boolean aShowDialog);
|
|
|
|
|
|
|
|
[Replaceable] readonly attribute BarProp locationbar;
|
|
|
|
[Replaceable] readonly attribute BarProp menubar;
|
|
|
|
[Replaceable] readonly attribute BarProp personalbar;
|
|
|
|
[Replaceable] readonly attribute BarProp scrollbars;
|
|
|
|
[Replaceable] readonly attribute BarProp statusbar;
|
|
|
|
[Replaceable] readonly attribute BarProp toolbar;
|
2012-06-30 20:38:12 +04:00
|
|
|
attribute DOMString status;
|
2012-06-27 22:16:45 +04:00
|
|
|
void close();
|
|
|
|
void stop();
|
|
|
|
void focus();
|
|
|
|
void blur();
|
|
|
|
|
|
|
|
// other browsing contexts
|
|
|
|
[Replaceable] readonly attribute WindowProxy frames;
|
|
|
|
[Replaceable] readonly attribute unsigned long length;
|
|
|
|
[Unforgeable] readonly attribute WindowProxy top;
|
2012-06-30 20:38:12 +04:00
|
|
|
attribute WindowProxy? opener;
|
2012-06-27 22:16:45 +04:00
|
|
|
readonly attribute WindowProxy parent;
|
|
|
|
readonly attribute Element? frameElement;
|
|
|
|
WindowProxy open(optional DOMString url, optional DOMString target, optional DOMString features, optional boolean replace);
|
|
|
|
getter WindowProxy (unsigned long index);
|
|
|
|
getter object (DOMString name);
|
|
|
|
|
|
|
|
// the user agent
|
2012-06-30 20:38:12 +04:00
|
|
|
readonly attribute Navigator navigator;
|
2012-06-27 22:16:45 +04:00
|
|
|
readonly attribute External external;
|
|
|
|
readonly attribute ApplicationCache applicationCache;
|
|
|
|
|
|
|
|
// user prompts
|
|
|
|
void alert(DOMString message);
|
|
|
|
boolean confirm(DOMString message);
|
|
|
|
DOMString? prompt(DOMString message, optional DOMString default);
|
|
|
|
void print();
|
|
|
|
any showModalDialog(DOMString url, optional any argument);
|
|
|
|
|
|
|
|
// cross-document messaging
|
|
|
|
void postMessage(any message, DOMString targetOrigin, optional sequence<Transferable> transfer);
|
|
|
|
|
|
|
|
// event handler IDL attributes
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onabort;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onafterprint;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onbeforeprint;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onbeforeunload;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onblur;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oncancel;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oncanplay;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oncanplaythrough;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onchange;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onclick;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onclose;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oncontextmenu;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oncuechange;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondblclick;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondrag;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondragend;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondragenter;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondragleave;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondragover;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondragstart;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondrop;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ondurationchange;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onemptied;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onended;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onerror;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onfocus;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onhashchange;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oninput;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? oninvalid;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onkeydown;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onkeypress;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onkeyup;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onload;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onloadeddata;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onloadedmetadata;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onloadstart;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmessage;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmousedown;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmousemove;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmouseout;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmouseover;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmouseup;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onmousewheel;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onoffline;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ononline;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onpause;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onplay;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onplaying;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onpagehide;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onpageshow;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onpopstate;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onprogress;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onratechange;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onreset;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onresize;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onscroll;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onseeked;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onseeking;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onselect;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onshow;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onstalled;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onstorage;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onsubmit;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onsuspend;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? ontimeupdate;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onunload;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onvolumechange;
|
|
|
|
[TreatNonCallableAsNull] attribute Function? onwaiting;
|
|
|
|
};
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
static JSBool JSAPI_NATIVE(alert, JSContext *cx, uintN argc, jsval *vp)
|
2012-06-11 02:17:30 +04:00
|
|
|
{
|
|
|
|
JSString* u16_txt;
|
|
|
|
char *txt;
|
2012-06-28 03:39:18 +04:00
|
|
|
unsigned long length;
|
2012-06-11 02:17:30 +04:00
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
|
2012-06-11 02:17:30 +04:00
|
|
|
return JS_FALSE;
|
|
|
|
|
2012-06-28 03:39:18 +04:00
|
|
|
JSString_to_char(u16_txt, txt, length);
|
2012-06-11 02:17:30 +04:00
|
|
|
|
|
|
|
warn_user(txt, NULL);
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
|
2012-06-11 02:17:30 +04:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
static JSBool JSAPI_NATIVE(confirm, JSContext *cx, uintN argc, jsval *vp)
|
2012-06-28 03:39:18 +04:00
|
|
|
{
|
|
|
|
JSString* u16_txt;
|
|
|
|
char *txt;
|
|
|
|
unsigned long length;
|
|
|
|
JSBool result = JS_FALSE;
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
|
2012-06-28 03:39:18 +04:00
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSString_to_char(u16_txt, txt, length);
|
|
|
|
|
|
|
|
warn_user(txt, NULL);
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
JSAPI_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(result));
|
|
|
|
|
2012-06-28 03:39:18 +04:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
static JSBool JSAPI_NATIVE(prompt, JSContext *cx, uintN argc, jsval *vp)
|
2012-06-28 03:39:18 +04:00
|
|
|
{
|
|
|
|
JSString* u16_txt;
|
|
|
|
char *txt;
|
|
|
|
unsigned long length;
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
if (!JS_ConvertArguments(cx, argc, JSAPI_ARGV(cx, vp), "S", &u16_txt))
|
2012-06-28 03:39:18 +04:00
|
|
|
return JS_FALSE;
|
|
|
|
|
|
|
|
JSString_to_char(u16_txt, txt, length);
|
|
|
|
|
|
|
|
warn_user(txt, NULL);
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
|
2012-06-28 03:39:18 +04:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2012-06-27 22:16:45 +04:00
|
|
|
|
2012-07-01 13:10:00 +04:00
|
|
|
static JSBool JSAPI_NATIVE(close, JSContext *cx, uintN argc, jsval *vp)
|
|
|
|
{
|
|
|
|
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool JSAPI_NATIVE(stop, JSContext *cx, uintN argc, jsval *vp)
|
|
|
|
{
|
|
|
|
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool JSAPI_NATIVE(focus, JSContext *cx, uintN argc, jsval *vp)
|
|
|
|
{
|
|
|
|
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSBool JSAPI_NATIVE(blur, JSContext *cx, uintN argc, jsval *vp)
|
|
|
|
{
|
|
|
|
JSAPI_SET_RVAL(cx, vp, JSVAL_VOID);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-26 22:55:57 +04:00
|
|
|
static JSFunctionSpec jsfunctions_window[] =
|
2012-06-11 02:17:30 +04:00
|
|
|
{
|
2012-07-01 13:10:00 +04:00
|
|
|
JSAPI_FS(close, 0, 0),
|
|
|
|
JSAPI_FS(stop, 0, 0),
|
|
|
|
JSAPI_FS(focus, 0, 0),
|
|
|
|
JSAPI_FS(blur, 0, 0),
|
2012-06-30 20:38:12 +04:00
|
|
|
JSAPI_FS(alert, 1, 0),
|
|
|
|
JSAPI_FS(confirm, 1, 0),
|
|
|
|
JSAPI_FS(prompt, 1, 0),
|
|
|
|
JSAPI_FS_END
|
2012-06-11 02:17:30 +04:00
|
|
|
};
|
|
|
|
|
2012-06-27 22:16:45 +04:00
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
static JSBool JSAPI_PROPERTYGET(window, JSContext *cx, JSObject *obj, jsval *vp)
|
2012-06-27 22:16:45 +04:00
|
|
|
{
|
|
|
|
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-30 20:38:12 +04:00
|
|
|
static JSBool JSAPI_PROPERTYGET(self, JSContext *cx, JSObject *obj, jsval *vp)
|
|
|
|
{
|
|
|
|
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj));
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-27 22:16:45 +04:00
|
|
|
static JSPropertySpec jsproperties_window[] =
|
|
|
|
{
|
2012-08-17 14:52:59 +04:00
|
|
|
JSAPI_PS_RO(window, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
|
|
|
|
JSAPI_PS_RO(self, 0, JSPROP_ENUMERATE | JSPROP_SHARED),
|
2012-06-30 20:38:12 +04:00
|
|
|
JSAPI_PS_END
|
2012-06-27 22:16:45 +04:00
|
|
|
};
|
|
|
|
|
2012-06-26 22:55:57 +04:00
|
|
|
/* The class of the global object. */
|
|
|
|
static JSClass jsclass_window = {
|
2012-06-30 20:38:12 +04:00
|
|
|
"window",
|
2012-06-26 22:55:57 +04:00
|
|
|
JSCLASS_HAS_PRIVATE | JSCLASS_GLOBAL_FLAGS,
|
2012-06-30 20:38:12 +04:00
|
|
|
JS_PropertyStub,
|
|
|
|
JS_PropertyStub,
|
|
|
|
JS_PropertyStub,
|
2012-06-26 22:55:57 +04:00
|
|
|
JS_StrictPropertyStub,
|
2012-06-30 20:38:12 +04:00
|
|
|
JS_EnumerateStub,
|
|
|
|
JS_ResolveStub,
|
|
|
|
JS_ConvertStub,
|
2012-06-26 22:55:57 +04:00
|
|
|
JS_FinalizeStub,
|
|
|
|
JSCLASS_NO_OPTIONAL_MEMBERS
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
|
2012-06-11 02:17:30 +04:00
|
|
|
{
|
2012-06-26 22:55:57 +04:00
|
|
|
JSObject *window = NULL;
|
2012-06-30 20:38:12 +04:00
|
|
|
|
2012-06-26 22:55:57 +04:00
|
|
|
if (parent == NULL) {
|
|
|
|
window = JS_NewCompartmentAndGlobalObject(cx, &jsclass_window, NULL);
|
|
|
|
if (window == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-07-31 17:48:53 +04:00
|
|
|
/** @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, window);
|
|
|
|
|
2012-06-26 22:55:57 +04:00
|
|
|
/* Populate the global object with the standard globals, like
|
2012-07-31 17:48:53 +04:00
|
|
|
* Object and Array.
|
|
|
|
*/
|
2012-06-26 22:55:57 +04:00
|
|
|
if (!JS_InitStandardClasses(cx, window)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* @todo sort out windows that are not globals */
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
2012-06-27 22:16:45 +04:00
|
|
|
/* private pointer to browsing context */
|
|
|
|
if (!JS_SetPrivate(cx, window, win_priv))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* functions */
|
2012-06-26 22:55:57 +04:00
|
|
|
if (!JS_DefineFunctions(cx, window, jsfunctions_window)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-27 22:16:45 +04:00
|
|
|
/* properties */
|
|
|
|
if (!JS_DefineProperties(cx, window, jsproperties_window))
|
2012-06-26 22:55:57 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
LOG(("Created new window object %p", window));
|
|
|
|
|
|
|
|
return window;
|
2012-06-11 02:17:30 +04:00
|
|
|
}
|