Skip to content

Make tools Document-scoped instead of Window-scoped #173

@domfarolino

Description

@domfarolino

It's important that tools are document-scoped. Most of the time Window/Navigator and Document are 1:1, however navigations away from the initial about:blank Document share a Window object, which complicates things.

The case where this is observable is when you register tools with the initial about:blank Document, and then navigate away from it. Per the current spec, after the navigation, calls to navigator.modelContext return the same object that holds the same map of tools, which means tools are effectively shared across this navigation.

I recently caught this bug in Chromium when working on the iframe + permission policy implementation, and ended up changing Blink's implementation such that:

  1. The backing ModelContext interface object is stored on Document instead of Navigator
  2. The navigator.modelContext IDL getter doesn't just return the same object; instead it consults its Window's active Document, and returns its ModelContext object. It returns null if the Window isn't available (detached document) or if the document isn't fully active (bf-cache).

I'll update the spec to agree with this.


Follow-up: API placement

An oddity of the above is that the API is effectively scoped to the Document, yet it lives off of navigator. I personally never liked putting things on navigator, and would recommend that we do one of two things:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions