Closed Bug 232698 Opened 21 years ago Closed 14 years ago

Allow javascript to create a new HTML document in memory

Categories

(Core :: DOM: Core & HTML, defect)

x86
All
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 592827

People

(Reporter: doronr, Unassigned)

Details

Attachments

(2 files, 1 obsolete file)

 
HTMLDOMImplementation?  What's that?
Ah, I remember, that's why we decided not to support createHTMLDocument, it got
dropped from DOM Level 2. What we should rather do is to allow creation of
html-documents by passing an appropriate doctype to createDocument. While we're
there we should proably support creating xul, xhtml and svg documents by passing
appropriate name/namespaces to createDocument.
Indeed, HTMLDOMImplementation's createHTMLDocument() is no longer in specs, my
bad.  Renaming the bug.

Note that in IE, createDocumentFragment returns a full HTMLDocument, so that is
how this got brought up at IBM.
Summary: Implement HTMLDOMImplementation's createHTMLDocument() → Allow javascript to create a new HTML document in memory
there's a patch for this in bug 33871
So could we make document.implementation.createDocument create html documents by
giving it a mimetype?
createDocument is specified at
http://www.w3.org/TR/2004/PR-DOM-Level-3-Core-20040205/core.html#ID-102161490

We could maybe hack together something where using an HTML4 doctype does the
right thing?
Yeah, I think that's a reasonable approach.
Attached patch first trySplinter Review
Comment on attachment 151944 [details] [diff] [review]
first try

Thanks for peterv for all the help.

Should I return somethign for unknown namespaces perhaps?
Attachment #151944 - Flags: review?(peterv)
Attachment #151944 - Flags: superreview?(jst)
Comment on attachment 151944 [details] [diff] [review]
first try

Looks good. No need to return anything for unknown namespaces. People should be
able to create documents in whatever unknown namespace etc.

sr=jst
Attachment #151944 - Flags: superreview?(jst) → superreview+
Comment on attachment 151944 [details] [diff] [review]
first try

>+  // check the namespace
>+  if (aNamespaceURI.Equals(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"))) {
>+    // xhtml
>+    rv = NS_NewHTMLDocument(getter_AddRefs(doc));
>+#ifdef MOZ_SVG
>+  } else if (aNamespaceURI.Equals(NS_LITERAL_STRING("http://www.w3.org/2000/svg"))) {

Move the else onto its own line.

>+    // svg
>+    rv = NS_NewSVGDocument(getter_AddRefs(doc));
>+#endif    
>+  } else {

Same here.

>   if (!doc)
>     return NS_ERROR_OUT_OF_MEMORY;
> 

>   if (NS_FAILED(rv)) {
>-    delete doc;
>-
>     return rv;
>   }

No need to check both doc and rv, just NS_ENSURE_SUCCESS(rv, rv);

>+    rv = domDoc->CreateElementNS(aNamespaceURI, aQualifiedName,
>                               getter_AddRefs(root));

Align getter_AddRefs with the opening parenthesis.
Attachment #151944 - Flags: review?(peterv) → review+
Do we want to add support for XUL documents?
Comment on attachment 151944 [details] [diff] [review]
first try

>+  if (aNamespaceURI.Equals(NS_LITERAL_STRING("http://www.w3.org/1999/xhtml"))) {
if (aNamespaceURI.EqualsLiteral("http://www.w3.org/1999/xhtml")) {
I understood both comment #6 and the level 3 spec to talk about doctypes as the
deciding criteria, the patch seems to use namespaces though.
Is that intenional?
If we are to use doctypes which ones would be used to create HTML documents? And
XUL doesn't seem to have a doctype.
Regarding XUL - I took the hard way and implemented a NS_NewXULDocument that
takes a nsIDocument (the current one needs a nsIXULDocument).  Was a good lesson.

Should I use this for consistency sake or simply QI my nsIDocument to a
nsIXULDocument in my code?
Comment on attachment 152945 [details] [diff] [review]
Fix review comments and add XUL document creation

>Index: content/xml/document/src/nsXMLDocument.cpp
>===================================================================
>RCS file: /cvsroot/mozilla/content/xml/document/src/nsXMLDocument.cpp,v
>retrieving revision 1.214
>diff -u -r1.214 nsXMLDocument.cpp
>--- content/xml/document/src/nsXMLDocument.cpp	25 Jun 2004 12:25:59 -0000	1.214
>+++ content/xml/document/src/nsXMLDocument.cpp	12 Jul 2004 14:31:20 -0000
>@@ -91,6 +91,11 @@
> #include "nsIJSContextStack.h"
> #include "nsNodeInfoManager.h"
> #include "nsContentCreatorFunctions.h"
>+#include "nsIXULDocument.h"

is this going to break minimo? They don't build XUL, IIRC


<...>
>+  // check the namespace
>+  if (aNamespaceURI.EqualsLiteral("http://www.w3.org/1999/xhtml")) {
>+    // xhtml
>+    rv = NS_NewHTMLDocument(getter_AddRefs(doc));
>+  } else if (aNamespaceURI.EqualsLiteral("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul")) {
>+    // xul

---
>+    nsCOMPtr<nsIXULDocument> xulDoc = do_QueryInterface(doc);
>+    rv = NS_NewXULDocument(getter_AddRefs(xulDoc));
___

How can this work? It might be that do_QueryInterface checks for null, but I
see no
way that xulDoc will point to anything related to doc.
nsCOMPtr<nsIXULDocument> xulDoc;
rv = NS_NewXULDocument(getter_AddRefs(xulDoc));
NS_ENSURE_SUCCESS(rv, rv);
doc = do_QueryInterface(xuldoc);
sounds more like it.

>+#ifdef MOZ_SVG
>+  } else if (aNamespaceURI.EqualsLiteral("http://www.w3.org/2000/svg")) {
>+    // svg
>+    rv = NS_NewSVGDocument(getter_AddRefs(doc));
>+#endif    
>+  } else {
>+    // default to XMLDocument for backwards compat
>+    rv = NS_NewXMLDocument(getter_AddRefs(doc));
>+  }  

<...>
Pike is right, debug build hung with that code.  Fixed that.
Attachment #152945 - Attachment is obsolete: true
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: