This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 22485 - [Custom]: registration context is defined oddly since Window of a document may change
Summary: [Custom]: registration context is defined oddly since Window of a document ma...
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 14968
  Show dependency treegraph
 
Reported: 2013-06-26 19:30 UTC by Olli Pettay
Modified: 2013-08-13 20:44 UTC (History)
1 user (show)

See Also:


Attachments

Description Olli Pettay 2013-06-26 19:30:52 UTC
http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#dom-document-open step 15.

Not sure how registration context should behave if there is a new Window.
Comment 1 Dimitri Glazkov 2013-06-26 19:36:17 UTC
document.open doesn't create a new Window, it seems? Can you help me understand the problem a bit better?
Comment 2 Olli Pettay 2013-06-26 19:50:27 UTC
document.open does create a new window.

"Replace the Document's singleton objects with _new_ instances of those objects. (This includes in particular the Window,..."
Comment 3 Dimitri Glazkov 2013-06-26 19:54:12 UTC
(In reply to comment #2)
> document.open does create a new window.
> 
> "Replace the Document's singleton objects with _new_ instances of those
> objects. (This includes in particular the Window,..."

Durr. Thanks!
Comment 4 Dominic Cooney 2013-07-12 14:02:24 UTC
Maybe the registration context should not be associated with the Window per se. Instead registration contexts are transmitted between documents.

For example:

When a window loads a document, it associates that document with a new registration context.

A document X's template document Y is associated with the registration context associated with X.

document.implementation.createHTMLDocument associates the resulting document with the registration context associated with 'document'.

etc.

This has the benefit that x.implementation.createHTMLDocument gives consistent results, irregardless of which window is running the script that acts on x.
Comment 5 Dimitri Glazkov 2013-07-12 22:37:59 UTC
(In reply to comment #4)

> This has the benefit that x.implementation.createHTMLDocument gives
> consistent results, irregardless of which window is running the script that
> acts on x.

Can you help me understand this? If I have main document A that contains an iframe B, and A reaches into B and attempts to createHTMLDocument on its document, we need to make sure that the document has the registration context from B, right?
Comment 6 Dominic Cooney 2013-07-12 23:48:44 UTC
(In reply to comment #5)
> (In reply to comment #4)
> 
> > This has the benefit that x.implementation.createHTMLDocument gives
> > consistent results, irregardless of which window is running the script that
> > acts on x.
> 
> Can you help me understand this? If I have main document A that contains an
> iframe B, and A reaches into B and attempts to createHTMLDocument on its
> document, we need to make sure that the document has the registration
> context from B, right?

Right. The spec today has this:

"Whenever created, each document must retain a weak reference to the Window object of the browsing context's active document. This referenced Window object is called the registration context."

I assume? this means that if A reaches into B and does 

doc = B.contentDocument.implementation.createHTMLDocument();

'doc' should be associated with the registration context of A, because the window that's running the script, etc. is A's.

If you think it is B, I am prepared to believe you, but then what does

doc2 = doc.implementation.createHTMLDocument();

associate doc2 with? In terms of browsing contexts, B has fled the scene.

So I'm proposing that documents are associated with a registration context, and when creating documents in specific situations, that association is transmitted to the new document in a process like quantum entanglement.

After having a crack at implementing something in Blink, I think you could do anything right up to letting the author imperatively state which documents they want entangled.

The idea of changing the entanglement of a document after custom element processing has started sounds scary, but it is really not--remember we have to solve the adoptNode problem. Changing the entanglement would look, from the point of view of the old context, like all of the elements got put up for adoption at once.

I have no idea whether this is a good idea, except to say it is a nice conservative security default to entangle very little, maybe just template and imports. And then the author can decide to entangle other kinds of documents if he/she wants.
Comment 7 Dimitri Glazkov 2013-08-07 22:30:34 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > 
> > > This has the benefit that x.implementation.createHTMLDocument gives
> > > consistent results, irregardless of which window is running the script that
> > > acts on x.
> > 
> > Can you help me understand this? If I have main document A that contains an
> > iframe B, and A reaches into B and attempts to createHTMLDocument on its
> > document, we need to make sure that the document has the registration
> > context from B, right?
> 
> Right. The spec today has this:
> 
> "Whenever created, each document must retain a weak reference to the Window
> object of the browsing context's active document. This referenced Window
> object is called the registration context."
> 
> I assume? this means that if A reaches into B and does 
> 
> doc = B.contentDocument.implementation.createHTMLDocument();
> 
> 'doc' should be associated with the registration context of A, because the
> window that's running the script, etc. is A's.
> 
> If you think it is B, I am prepared to believe you, but then what does
> 
> doc2 = doc.implementation.createHTMLDocument();
> 
> associate doc2 with? In terms of browsing contexts, B has fled the scene.
> 
> So I'm proposing that documents are associated with a registration context,
> and when creating documents in specific situations, that association is
> transmitted to the new document in a process like quantum entanglement.

This is reasonable. We can start very small, by:

1) declaring the registration context its own thing, then
2) defining how a new registration context is created during http://www.whatwg.org/specs/web-apps/current-work/#read-html
3) defining how it's passed along to new Document instances in specific imperative APIs.

WDYT? This should take care of the Window/Document conundrum cleanly and allow future refinements toward solving bug 22466
Comment 8 Dominic Cooney 2013-08-08 07:50:27 UTC
(In reply to comment #7)
> This is reasonable. We can start very small, by:
> 
> 1) declaring the registration context its own thing, then
> 2) defining how a new registration context is created during
> http://www.whatwg.org/specs/web-apps/current-work/#read-html
> 3) defining how it's passed along to new Document instances in specific
> imperative APIs.
> 
> WDYT? This should take care of the Window/Document conundrum cleanly and
> allow future refinements toward solving bug 22466

Sounds like a plan.
Comment 9 Dimitri Glazkov 2013-08-13 20:44:44 UTC
https://dvcs.w3.org/hg/webcomponents/rev/71b32d02423b

PTAL.