Issue #1118 - Part 5: Change the way document.open() works

This changes the work we do for document.open() in the following ways:
- We no longer create a new Window when doing document.open().
  We use the same Window but remove all the event listeners on the
  existing DOM tree and Window before removing the document's existing
  children to provide a clean slate document to use for .write().
- We no longer create a session history entry (previously would be a
  wyciwyg URI). We now replace the current one, effectively losing the
  entry for the original document.
- We now support document.open() on windowless documents.
This commit is contained in:
wolfbeast 2019-12-22 19:57:30 +01:00 • committed by Roy Tam
commit fc5d61608c
9 changed files with 400 additions and 297 deletions

View file

@ -704,7 +704,11 @@ public:
virtual void BeginLoad() override;
virtual void EndLoad() override;
virtual void SetReadyStateInternal(ReadyState rs) override;
// Set the readystate of the document. If updateTimingInformation is true,
// this will record relevant timestamps in the document's performance timing.
// Some consumers like document.open() don't want to do that.
virtual void SetReadyStateInternal(ReadyState rs,
bool updateTimingInformation = true) override;
virtual void ContentStateChanged(nsIContent* aContent,
mozilla::EventStates aStateMask)
@ -916,6 +920,14 @@ public:
UpdateFrameRequestCallbackSchedulingState();
}
void SetLoadEventFiring(bool aFiring) override { mLoadEventFiring = aFiring; }
bool SkipLoadEventAfterClose() override {
bool skip = mSkipLoadEventAfterClose;
mSkipLoadEventAfterClose = false;
return skip;
}
virtual nsIDocument* GetTemplateContentsOwner() override;
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsDocument,
@ -1255,6 +1267,11 @@ protected:
*/
Element* GetTitleElement();
/**
* Perform tree disconnection needed by ResetToURI and document.open()
*/
void DisconnectNodeTree();
public:
// Get our title
virtual void GetTitle(nsString& aTitle) override;
@ -1458,6 +1475,20 @@ public:
// additional sheets and sheets from the nsStyleSheetService.
bool mStyleSetFilled:1;
// The HTML spec has a "iframe load in progress" flag, but that doesn't seem
// to have the right semantics. See <https://github.com/whatwg/html/issues/4292>.
// What we have instead is a flag that is set while the window's 'load' event is
// firing if this document is the window's document.
bool mLoadEventFiring : 1;
// The HTML spec has a "mute iframe load" flag, but that doesn't seem to have
// the right semantics. See <https://github.com/whatwg/html/issues/4292>.
// What we have instead is a flag that is set if completion of our document
// via document.close() should skip firing the load event. Note that this
// flag is only relevant for HTML documents, but lives here for reasons that
// are documented above on SkipLoadEventAfterClose().
bool mSkipLoadEventAfterClose : 1;
uint8_t mPendingFullscreenRequests;
uint8_t mXMLDeclarationBits;