about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/config.md93
-rw-r--r--res/config.toml7
-rw-r--r--src/config/config.nim11
-rw-r--r--src/html/dom.nim5
-rw-r--r--src/html/env.nim3
-rw-r--r--src/local/pager.nim7
-rw-r--r--src/server/buffer.nim2
-rw-r--r--todo1
8 files changed, 119 insertions, 10 deletions
diff --git a/doc/config.md b/doc/config.md
index e2575a93..80e15215 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -30,6 +30,7 @@ examples.
 
 * [Start](#start)
 * [Search](#search)
+* [Buffer](#buffer)
 * [Encoding](#encoding)
 * [External](#external)
 * [Network](#network)
@@ -101,6 +102,64 @@ appearing on your screen.</td>
 
 </table>
 
+## Buffer
+
+Buffer options are to be placed in the `[buffer]` section.
+
+Following is a list of buffer options:
+
+<table>
+
+<tr>
+<th>Name</th>
+<th>Value</th>
+<th>Function</th>
+</tr>
+
+<tr>
+<td>styling</td>
+<td>boolean</td>
+<td>Enable/disable author style sheets. Note that disabling this does not affect
+user styles set in `[css]`.</td>
+</tr>
+
+<tr>
+<td>scripting</td>
+<td>boolean</td>
+<td>Enable/disable JavaScript in *all* buffers.<br>
+Defaults to false. For security reasons, users are encouraged to selectively
+enable JavaScript with `[[siteconf]]` instead of using this setting.</td>
+</tr>
+
+<tr>
+<td>images</td>
+<td>boolean</td>
+<td>Enable/disable experimental image support.<br>
+Defaults to false, but this may change in the future.</td>
+</tr>
+
+<tr>
+<td>cookie</td>
+<td>boolean</td>
+<td>Enable/disable cookies on sites.<br>
+Defaults to false.<br>
+Note that in Chawan, each website gets a separate cookie jar, so some websites
+relying on cross-site cookies may not work as expected. You may use the
+`[[siteconf]]` "cookie-jar" and "third-party-cookie" settings to adjust this
+behavior for specific sites.</td>
+</tr>
+
+<tr>
+<td>referer-from</td>
+<td>boolean</td>
+<td>Enable/disable the "Referer" header.<br>
+Defaults to false. For security reasons, users are encouraged to leave this
+option disabled, only enabling it for specific sites in `[[siteconf]]`.
+</td>
+</tr>
+
+</table>
+
 ## Search
 
 Search options are to be placed in the `[search]` section.
@@ -389,6 +448,20 @@ completely.</td>
 </tr>
 
 <tr>
+<td>image-mode</td>
+<td>"auto" / "none" / "sixel" / "kitty"</td>
+<td>Specifies the image output mode. "sixel" uses sixels for output, "kitty"
+uses the Kitty image display protocol, "none" disables image display
+completely.<br>
+"auto" tries to detect sixel or kitty support, and falls back to "none" when
+neither are available.<br>
+Defaults to "auto". However, images are still disabled by default, unless you
+also enable `buffer.images` which allows the browser to actually download
+images.
+</td>
+</tr>
+
+<tr>
 <td>alt-screen</td>
 <td>"auto" / boolean</td>
 <td>Enable/disable the alternative screen.</td>
@@ -643,15 +716,29 @@ subdomains.</td>
 <td>Whether or not we should send a Referer header when opening requests
 originating from this domain. Simplified example: if you click a link on a.com
 that refers to b.com, and referer-from is true, b.com is sent "a.com" as the
-Referer header.  
-Defaults to false.
+Referer header.<br>
+Overrides `buffer.referer-from`. Defaults to false.
 </td>
 </tr>
 
 <tr>
 <td>scripting</td>
 <td>boolean</td>
-<td>Enable/disable JavaScript execution on this site.</td>
+<td>Enable/disable JavaScript execution on this site. Overrides
+`buffer.scripting`.</td>
+</tr>
+
+<tr>
+<td>styling</td>
+<td>boolean</td>
+<td>Enable/disable author styles (CSS) on this site. Overrides
+`buffer.styling`.</td>
+</tr>
+
+<tr>
+<td>images</td>
+<td>boolean</td>
+<td>Enable/disable image display on this site. Overrides `buffer.images`.</td>
 </tr>
 
 <tr>
diff --git a/res/config.toml b/res/config.toml
index ea3fcff5..d93eb067 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -231,6 +231,13 @@ form-request = "mailto"
 [protocol.data]
 form-request = "data"
 
+[buffer]
+styling = true
+images = false
+scripting = false
+referer-from = false
+cookie = false
+
 [search]
 wrap = true
 ignore-case = true
diff --git a/src/config/config.nim b/src/config/config.nim
index 8783cb89..4e9d1517 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -59,6 +59,7 @@ type
     scripting*: Option[bool]
     document_charset*: seq[Charset]
     images*: Option[bool]
+    styling*: Option[bool]
     stylesheet*: Option[string]
     proxy*: Option[URL]
     default_headers*: TableRef[string, string]
@@ -140,12 +141,20 @@ type
   ProtocolConfig* = ref object
     form_request*: FormRequestType
 
+  BufferSectionConfig* = object
+    styling* {.jsgetset.}: bool
+    scripting* {.jsgetset.}: bool
+    images* {.jsgetset.}: bool
+    cookie* {.jsgetset.}: bool
+    referer_from* {.jsgetset.}: bool
+
   Config* = ref object
     jsctx: JSContext
     jsvfns*: seq[JSValueFunction]
     configdir {.jsget.}: string
     `include` {.jsget.}: seq[ChaPathResolved]
     start* {.jsget.}: StartConfig
+    buffer* {.jsget.}: BufferSectionConfig
     search* {.jsget.}: SearchConfig
     css* {.jsget.}: CSSConfig
     encoding* {.jsget.}: EncodingConfig
@@ -169,6 +178,7 @@ jsDestructor(EncodingConfig)
 jsDestructor(ExternalConfig)
 jsDestructor(NetworkConfig)
 jsDestructor(DisplayConfig)
+jsDestructor(BufferSectionConfig)
 jsDestructor(Config)
 
 converter toStr*(p: ChaPathResolved): string {.inline.} =
@@ -833,4 +843,5 @@ proc addConfigModule*(ctx: JSContext) =
   ctx.registerType(ExternalConfig)
   ctx.registerType(NetworkConfig)
   ctx.registerType(DisplayConfig)
+  ctx.registerType(BufferSectionConfig, name = "BufferConfig")
   ctx.registerType(Config)
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 503bdf27..bb5128dc 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -87,6 +87,7 @@ type
     factory*: CAtomFactory
     loadingResourcePromises*: seq[EmptyPromise]
     images*: bool
+    styling*: bool
     # ID of the next image
     imageId: int
 
@@ -2245,7 +2246,7 @@ func referrerpolicy(element: HTMLScriptElement): Option[ReferrerPolicy] =
   return strictParseEnum[ReferrerPolicy](element.attr(satReferrerpolicy))
 
 proc sheets*(document: Document): seq[CSSStylesheet] =
-  if document.cachedSheetsInvalid:
+  if document.cachedSheetsInvalid and document.window.styling:
     document.cachedSheets.setLen(0)
     for elem in document.html.descendants:
       if elem of HTMLStyleElement:
@@ -2860,7 +2861,7 @@ var appliesFwdDecl*: proc(mqlist: MediaQueryList; window: Window): bool
 # see https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet
 #TODO make this somewhat compliant with ^this
 proc loadResource(window: Window; link: HTMLLinkElement) =
-  if satStylesheet notin link.relList:
+  if not window.styling or satStylesheet notin link.relList:
     return
   if link.fetchStarted:
     return
diff --git a/src/html/env.nim b/src/html/env.nim
index 0a90007f..0751d12f 100644
--- a/src/html/env.nim
+++ b/src/html/env.nim
@@ -236,7 +236,7 @@ proc runJSJobs*(window: Window) =
     let ctx = r.error
     ctx.writeException(window.console.err)
 
-proc newWindow*(scripting, images: bool; selector: Selector[int];
+proc newWindow*(scripting, images, styling: bool; selector: Selector[int];
     attrs: WindowAttributes; factory: CAtomFactory; navigate: proc(url: URL);
     loader: FileLoader; url: URL): Window =
   let err = newDynFileStream(stderr)
@@ -246,6 +246,7 @@ proc newWindow*(scripting, images: bool; selector: Selector[int];
     navigator: Navigator(),
     loader: loader,
     images: images,
+    styling: styling,
     settings: EnvironmentSettings(
       scripting: scripting,
       origin: url.origin
diff --git a/src/local/pager.nim b/src/local/pager.nim
index cd0df216..cdc08422 100644
--- a/src/local/pager.nim
+++ b/src/local/pager.nim
@@ -1074,10 +1074,11 @@ proc applySiteconf(pager: Pager; url: var URL; charsetOverride: Charset;
   let ctx = pager.jsctx
   var res = BufferConfig(
     userstyle: pager.config.css.stylesheet,
-    referer_from: false,
-    scripting: false,
+    referer_from: pager.config.buffer.referer_from,
+    scripting: pager.config.buffer.scripting,
     charsets: pager.config.encoding.document_charset,
-    images: false,
+    images: pager.config.buffer.images,
+    styling: pager.config.buffer.styling,
     isdump: pager.config.start.headless,
     charsetOverride: charsetOverride,
     protocol: pager.config.protocol
diff --git a/src/server/buffer.nim b/src/server/buffer.nim
index f14cda60..d84bc29c 100644
--- a/src/server/buffer.nim
+++ b/src/server/buffer.nim
@@ -134,6 +134,7 @@ type
   BufferConfig* = object
     userstyle*: string
     referer_from*: bool
+    styling*: bool
     scripting*: bool
     images*: bool
     isdump*: bool
@@ -870,6 +871,7 @@ proc setHTML(buffer: Buffer) =
   buffer.window = newWindow(
     buffer.config.scripting,
     buffer.config.images,
+    buffer.config.styling,
     buffer.selector,
     buffer.attrs,
     factory,
diff --git a/todo b/todo
index 84be5079..f3916460 100644
--- a/todo
+++ b/todo
@@ -74,7 +74,6 @@ layout engine:
 - writing-mode, grid, ruby, ... (i.e. cool new stuff)
 images:
 - more efficient sixel display (store encoded images)
-- document it (when performance is acceptable)
 - proper sixel color register allocation, dithering
 - fix race condition where images decoded after buffer load won't display until
   reshape