diff options
-rw-r--r-- | src/html/dom.nim | 14 | ||||
-rw-r--r-- | src/html/env.nim | 46 |
2 files changed, 58 insertions, 2 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 1a3b72d5..da08898b 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -76,12 +76,21 @@ type type Window* = ref object + console* {.jsget.}: console + navigator* {.jsget.}: Navigator settings*: EnvironmentSettings loader*: Option[FileLoader] jsrt*: JSRuntime jsctx*: JSContext document* {.jsget.}: Document - console* {.jsget.}: console + + # Navigator stuff + Navigator* = ref object + plugins: PluginArray + + PluginArray* = ref object + + MimeTypeArray* = ref object # "For historical reasons, console is lowercased." # Also, for a more practical reason: so the javascript macros don't confuse @@ -1710,7 +1719,8 @@ proc execute*(element: HTMLScriptElement) = #TODO not if shadow root document.currentScript = element if document.window != nil and document.window.jsctx != nil: - let ret = document.window.jsctx.eval(element.scriptResult.script.record, "<script>", JS_EVAL_TYPE_GLOBAL) + let script = element.scriptResult.script + let ret = document.window.jsctx.eval(script.record, $script.baseURL, JS_EVAL_TYPE_GLOBAL) if JS_IsException(ret): let ss = newStringStream() document.window.jsctx.writeException(ss) diff --git a/src/html/env.nim b/src/html/env.nim index 29b1de09..7af33d9b 100644 --- a/src/html/env.nim +++ b/src/html/env.nim @@ -4,9 +4,54 @@ import io/loader import js/javascript import types/url +# NavigatorID +proc appCodeName(navigator: Navigator): string {.jsfget.} = "Mozilla" +proc appName(navigator: Navigator): string {.jsfget.} = "Netscape" +proc appVersion(navigator: Navigator): string {.jsfget.} = "5.0 (Windows)" +proc platform(navigator: Navigator): string {.jsfget.} = "Win32" +proc product(navigator: Navigator): string {.jsfget.} = "Gecko" +proc productSub(navigator: Navigator): string {.jsfget.} = "20100101" +proc userAgent(navigator: Navigator): string {.jsfget.} = "chawan" #TODO TODO TODO this should be configurable +proc vendor(navigator: Navigator): string {.jsfget.} = "" +proc vendorSub(navigator: Navigator): string {.jsfget.} = "" +proc taintEnabled(navigator: Navigator): bool {.jsfget.} = false +proc oscpu(navigator: Navigator): string {.jsfget.} = "Windows NT 10.0" + +# NavigatorLanguage +proc language(navigator: Navigator): string {.jsfget.} = "en-US" +proc languages(navigator: Navigator): seq[string] {.jsfget.} = @["en-US"] #TODO frozen array? + +# NavigatorOnline +proc onLine(navigator: Navigator): bool {.jsfget.} = true # none of your business :) + +#TODO NavigatorContentUtils + +# NavigatorCookies +# "this website needs cookies to be enabled to function correctly" +# I'll take your incorrectly functioning website over the tracking any day. +proc cookieEnabled(navigator: Navigator): bool {.jsfget.} = true + +# NavigatorPlugins +proc pdfViewerEnabled(navigator: Navigator): bool {.jsfget.} = false +proc javaEnabled(navigator: Navigator): bool {.jsfunc.} = false +proc namedItem(pluginArray: PluginArray): string {.jsfunc.} = "" +proc namedItem(mimeTypeArray: MimeTypeArray): string {.jsfunc.} = "" +proc item(pluginArray: PluginArray): JSValue {.jsfunc.} = JS_NULL +proc length(pluginArray: PluginArray): int {.jsfget.} = 0 +proc item(mimeTypeArray: MimeTypeArray): JSValue {.jsfunc.} = JS_NULL +proc length(mimeTypeArray: MimeTypeArray): int {.jsfget.} = 0 +proc getter(pluginArray: PluginArray, i: int): Option[JSValue] {.jsgetprop.} = discard +proc getter(mimeTypeArray: MimeTypeArray, i: int): Option[JSValue] {.jsgetprop.} = discard + +proc addNavigatorModule(ctx: JSContext) = + ctx.registerType(Navigator) + ctx.registerType(PluginArray) + ctx.registerType(MimeTypeArray) + proc newWindow*(scripting: bool, loader = none(FileLoader)): Window = result = Window( console: console(), + navigator: Navigator(), loader: loader, settings: EnvironmentSettings( scripting: scripting @@ -23,6 +68,7 @@ proc newWindow*(scripting: bool, loader = none(FileLoader)): Window = ctx.setProperty(global, "window", global) JS_FreeValue(ctx, global) ctx.addconsoleModule() + ctx.addNavigatorModule() ctx.addDOMModule() ctx.addURLModule() ctx.addHTMLModule() |