diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-24 21:47:33 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-24 21:47:33 +0100 |
| commit | 67acbd2deca94a1c8af7247731b222322451ca4f (patch) | |
| tree | 638f2f9f87f45be2f193e80de9f0ef503455d8fb /src | |
| parent | 7ef3ef1c2b95ab3c621e2b327412f12acc014b9a (diff) | |
| download | chawan-67acbd2deca94a1c8af7247731b222322451ca4f.tar.gz | |
buffer: support navigation on load/click, use origin for hover checking
Navigation from e.g. setTimeout still doesn't work.
Also, the hover check now uses the auth origin instead of the host, and
the auth origin now works for "file" as expected.
Diffstat (limited to 'src')
| -rw-r--r-- | src/local/container.nim | 7 | ||||
| -rw-r--r-- | src/server/buffer.nim | 12 | ||||
| -rw-r--r-- | src/types/url.nim | 18 |
3 files changed, 28 insertions, 9 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index 8c51e362..ff2ef9fe 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -469,8 +469,11 @@ func getHoverText*(container: Container): string = "" proc isHoverURL*(container: Container; url: URL): bool = - let hoverurl = parseURL(container.hoverText[htLink]) - return hoverurl.isSome and url.host == hoverurl.get.host + let x = parseURL(container.hoverText[htLink]) + if x.isSome: + let hoverUrl = x.get + return url.authOrigin.isSameOrigin(hoverUrl.authOrigin) + return false proc triggerEvent(container: Container; event: ContainerEvent) = if container.lastEvent == nil: diff --git a/src/server/buffer.nim b/src/server/buffer.nim index ce8a82c8..6a50ed03 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -92,6 +92,7 @@ type istream: PosixStream lines: FlexibleGrid loader: FileLoader + navigateUrl: URL # stored when JS tries to navigate needsBOMSniff: bool onReshapeImmediately: bool outputId: int @@ -428,8 +429,7 @@ func cursorBytes(buffer: Buffer; y, cc: int): int = return i proc navigate(buffer: Buffer; url: URL) = - #TODO how? - # maybe we could reuse meta refresh for the time being + buffer.navigateUrl = url stderr.write("navigate to " & $url & "\n") #TODO rewrite findPrevLink, findNextLink to use the box tree instead @@ -723,6 +723,10 @@ type CheckRefreshResult* = object url*: URL proc checkRefresh*(buffer: Buffer): CheckRefreshResult {.proxy.} = + if buffer.navigateUrl != nil: + let url = buffer.navigateUrl + buffer.navigateUrl = nil + return CheckRefreshResult(n: 0, url: url) if buffer.document == nil: return CheckRefreshResult(n: -1) let element = buffer.document.findMetaRefresh() @@ -1591,8 +1595,12 @@ proc click*(buffer: Buffer; cursorx, cursory: int): ClickResult {.proxy.} = let event = newEvent(window.toAtom(satClick), element) canceled = window.jsctx.dispatch(element, event) buffer.maybeReshape() + let url = buffer.navigateUrl + buffer.navigateUrl = nil if not canceled and clickable != nil: return buffer.click(clickable) + if url != nil: + return ClickResult(open: newRequest(url, hmGet)) return ClickResult() proc select*(buffer: Buffer; selected: int): ClickResult {.proxy.} = diff --git a/src/types/url.nim b/src/types/url.nim index a2bb3f82..64078dbd 100644 --- a/src/types/url.nim +++ b/src/types/url.nim @@ -1169,11 +1169,19 @@ proc origin*(url: URL): Origin = else: return Origin(t: otOpaque, s: $url) +# Whether the URL is a net path (ref. RFC 2396). +# In general, this means that its serialization will look like +# "scheme://host:port/blah" instead of "scheme:/blah", *except* for +# file URLs which are special-cased for legacy reasons (they become +# "file:///blah", but are treated as absoluteURI). +func isNetPath(url: URL): bool = + return url.hostType != htNone and url.scheme != "file" + # This follows somewhat different rules from the standard: -# * with htNone, the origin is opaque. +# * for URLs with a net_path, the origin is opaque. # * with other host types, the origin is a tuple origin. proc authOrigin*(url: URL): Origin = - if url.hostType != htNone: + if url.isNetPath(): return Origin( t: otTuple, tup: (url.scheme, url.hostname, url.port, none(string)) @@ -1214,11 +1222,11 @@ proc setProtocol*(url: URL; s: string) {.jsfset: "protocol".} = stateOverride = some(usSchemeStart)) proc setUsername*(url: URL; username: string) {.jsfset: "username".} = - if url.hostType != htNone and url.scheme != "file": + if url.isNetPath(): url.username = username.percentEncode(UserInfoPercentEncodeSet) proc setPassword*(url: URL; password: string) {.jsfset: "password".} = - if url.hostType != htNone and url.scheme != "file": + if url.isNetPath(): url.password = password.percentEncode(UserInfoPercentEncodeSet) proc host*(url: URL): string {.jsfget.} = @@ -1242,7 +1250,7 @@ proc port*(url: URL): string {.jsfget.} = return "" proc setPort*(url: URL; s: string) {.jsfset: "port".} = - if url.hostType != htNone and url.scheme != "file": + if url.isNetPath(): if s == "": url.port = none(uint16) else: |