Diff
Modified: trunk/Source/WebCore/ChangeLog (139131 => 139132)
--- trunk/Source/WebCore/ChangeLog 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/ChangeLog 2013-01-09 00:42:52 UTC (rev 139132)
@@ -1,3 +1,38 @@
+2013-01-08 Rafael Weinstein <[email protected]>
+
+ [HTMLTemplateElement] Allow <template> content to be inspected
+ https://bugs.webkit.org/show_bug.cgi?id=105839
+
+ Reviewed by Pavel Feldman.
+
+ In addition to the plumbing which allows template contents to be
+ displayed within the inspector, this patch adds a manually-managed
+ weakref from the template document back to its host document (typically
+ the creator). This is required so that the inspector agent can be found
+ for template elements.
+
+ * dom/Document.cpp:
+ (WebCore::Document::~Document):
+ (WebCore::Document::templateDocument):
+ * dom/Document.h:
+ (Document):
+ (WebCore::Document::setTemplateDocumentHost):
+ (WebCore::Document::templateDocumentHost):
+ * editing/markup.cpp:
+ (WebCore::createFragmentForInnerOuterHTML):
+ * html/HTMLTemplateElement.cpp:
+ (WebCore::HTMLTemplateElement::content):
+ * inspector/Inspector.json:
+ * inspector/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::buildObjectForNode):
+ * inspector/InspectorInstrumentation.h:
+ (WebCore::InspectorInstrumentation::instrumentingAgentsForDocument):
+ * inspector/front-end/DOMAgent.js:
+ (WebInspector.DOMNode):
+ (WebInspector.DOMNode.prototype.hasChildNodes):
+ (WebInspector.DOMNode.prototype._insertChild):
+ (WebInspector.DOMNode.prototype._setChildrenPayload):
+
2013-01-08 Hajime Morrita <[email protected]>
[Shadow DOM] Distribution related code on ShadowRoot should be minimized.
Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (139131 => 139132)
--- trunk/Source/WebCore/dom/ContainerNode.cpp 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp 2013-01-09 00:42:52 UTC (rev 139132)
@@ -142,7 +142,7 @@
{
#if ENABLE(TEMPLATE_ELEMENT)
Document* document = node->document();
- return document && document == document->templateContentsOwnerDocument();
+ return document && document == document->templateDocument();
#else
UNUSED_PARAM(node);
return false;
Modified: trunk/Source/WebCore/dom/Document.cpp (139131 => 139132)
--- trunk/Source/WebCore/dom/Document.cpp 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/dom/Document.cpp 2013-01-09 00:42:52 UTC (rev 139132)
@@ -504,6 +504,9 @@
#ifndef NDEBUG
, m_didDispatchViewportPropertiesChanged(false)
#endif
+#if ENABLE(TEMPLATE_ELEMENT)
+ , m_templateDocumentHost(0)
+#endif
{
setTreeScope(this);
@@ -608,6 +611,11 @@
ASSERT(!m_parentTreeScope);
ASSERT(!m_guardRefCount);
+#if ENABLE(TEMPLATE_ELEMENT)
+ if (m_templateDocument)
+ m_templateDocument->setTemplateDocumentHost(0); // balanced in templateDocument().
+#endif
+
#if ENABLE(TOUCH_EVENT_TRACKING)
if (Document* ownerDocument = this->ownerDocument())
ownerDocument->didRemoveEventTargetNode(this);
@@ -5951,17 +5959,19 @@
}
#if ENABLE(TEMPLATE_ELEMENT)
-Document* Document::ensureTemplateContentsOwnerDocument()
+Document* Document::ensureTemplateDocument()
{
- if (const Document* document = templateContentsOwnerDocument())
+ if (const Document* document = templateDocument())
return const_cast<Document*>(document);
if (isHTMLDocument())
- m_templateContentsOwnerDocument = HTMLDocument::create(0, blankURL());
+ m_templateDocument = HTMLDocument::create(0, blankURL());
else
- m_templateContentsOwnerDocument = Document::create(0, blankURL());
+ m_templateDocument = Document::create(0, blankURL());
- return m_templateContentsOwnerDocument.get();
+ m_templateDocument->setTemplateDocumentHost(this); // balanced in dtor.
+
+ return m_templateDocument.get();
}
#endif
Modified: trunk/Source/WebCore/dom/Document.h (139131 => 139132)
--- trunk/Source/WebCore/dom/Document.h 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/dom/Document.h 2013-01-09 00:42:52 UTC (rev 139132)
@@ -1190,8 +1190,10 @@
#endif
#if ENABLE(TEMPLATE_ELEMENT)
- const Document* templateContentsOwnerDocument() const;
- Document* ensureTemplateContentsOwnerDocument();
+ const Document* templateDocument() const;
+ Document* ensureTemplateDocument();
+ void setTemplateDocumentHost(Document* templateDocumentHost) { m_templateDocumentHost = templateDocumentHost; }
+ Document* templateDocumentHost() { return m_templateDocumentHost; }
#endif
virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0);
@@ -1556,7 +1558,8 @@
LocaleIdentifierToLocaleMap m_localeCache;
#if ENABLE(TEMPLATE_ELEMENT)
- RefPtr<Document> m_templateContentsOwnerDocument;
+ RefPtr<Document> m_templateDocument;
+ Document* m_templateDocumentHost; // Manually managed weakref (backpointer from m_templateDocument).
#endif
};
@@ -1567,13 +1570,13 @@
}
#if ENABLE(TEMPLATE_ELEMENT)
-inline const Document* Document::templateContentsOwnerDocument() const
+inline const Document* Document::templateDocument() const
{
// If DOCUMENT does not have a browsing context, Let TEMPLATE CONTENTS OWNER be DOCUMENT and abort these steps.
if (!m_frame)
return this;
- return m_templateContentsOwnerDocument.get();
+ return m_templateDocument.get();
}
#endif
Modified: trunk/Source/WebCore/editing/markup.cpp (139131 => 139132)
--- trunk/Source/WebCore/editing/markup.cpp 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/editing/markup.cpp 2013-01-09 00:42:52 UTC (rev 139132)
@@ -1001,7 +1001,7 @@
Document* document = contextElement->document();
#if ENABLE(TEMPLATE_ELEMENT)
if (contextElement->hasTagName(templateTag))
- document = document->ensureTemplateContentsOwnerDocument();
+ document = document->ensureTemplateDocument();
#endif
RefPtr<DocumentFragment> fragment = DocumentFragment::create(document);
Modified: trunk/Source/WebCore/html/HTMLTemplateElement.cpp (139131 => 139132)
--- trunk/Source/WebCore/html/HTMLTemplateElement.cpp 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/html/HTMLTemplateElement.cpp 2013-01-09 00:42:52 UTC (rev 139132)
@@ -61,7 +61,7 @@
DocumentFragment* HTMLTemplateElement::content() const
{
if (!m_content)
- m_content = TemplateContentDocumentFragment::create(document()->ensureTemplateContentsOwnerDocument(), this);
+ m_content = TemplateContentDocumentFragment::create(document()->ensureTemplateDocument(), this);
return m_content.get();
}
@@ -82,7 +82,7 @@
HTMLElement::didMoveToNewDocument(oldDocument);
if (!m_content)
return;
- document()->ensureTemplateContentsOwnerDocument()->adoptIfNeeded(m_content.get());
+ document()->ensureTemplateDocument()->adoptIfNeeded(m_content.get());
}
#ifndef NDEBUG
Modified: trunk/Source/WebCore/inspector/Inspector.json (139131 => 139132)
--- trunk/Source/WebCore/inspector/Inspector.json 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/inspector/Inspector.json 2013-01-09 00:42:52 UTC (rev 139132)
@@ -1652,7 +1652,8 @@
{ "name": "value", "type": "string", "optional": true, "description": "<code>Attr</code>'s value." },
{ "name": "frameId", "$ref": "Network.FrameId", "optional": true, "description": "Frame ID for frame owner elements." },
{ "name": "contentDocument", "$ref": "Node", "optional": true, "description": "Content document for frame owner elements." },
- { "name": "shadowRoots", "type": "array", "optional": true, "items": { "$ref": "Node" }, "description": "Shadow root list for given element host." }
+ { "name": "shadowRoots", "type": "array", "optional": true, "items": { "$ref": "Node" }, "description": "Shadow root list for given element host." },
+ { "name": "templateContent", "$ref": "Node", "optional": true, "description": "Content document fragment for template elements" }
],
"description": "DOM interaction is implemented in terms of mirror objects that represent the actual DOM nodes. DOMNode is a base node mirror type."
},
Modified: trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp (139131 => 139132)
--- trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp 2013-01-09 00:42:52 UTC (rev 139132)
@@ -63,6 +63,8 @@
#include "FrameTree.h"
#include "HTMLElement.h"
#include "HTMLFrameOwnerElement.h"
+#include "HTMLNames.h"
+#include "HTMLTemplateElement.h"
#include "HitTestResult.h"
#include "IdentifiersFactory.h"
#include "InjectedScriptManager.h"
@@ -1294,6 +1296,12 @@
shadowRoots->addItem(buildObjectForNode(root, 0, nodesMap));
value->setShadowRoots(shadowRoots);
}
+
+#if ENABLE(TEMPLATE_ELEMENT)
+ if (element->hasTagName(HTMLNames::templateTag))
+ value->setTemplateContent(buildObjectForNode(static_cast<HTMLTemplateElement*>(element)->content(), 0, nodesMap));
+#endif
+
} else if (node->isDocumentNode()) {
Document* document = static_cast<Document*>(node);
value->setDocumentURL(documentURLString(document));
Modified: trunk/Source/WebCore/inspector/InspectorInstrumentation.h (139131 => 139132)
--- trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/inspector/InspectorInstrumentation.h 2013-01-09 00:42:52 UTC (rev 139132)
@@ -1985,8 +1985,14 @@
inline InstrumentingAgents* InspectorInstrumentation::instrumentingAgentsForDocument(Document* document)
{
- if (document)
- return instrumentingAgentsForPage(document->page());
+ if (document) {
+ Page* page = document->page();
+#if ENABLE(TEMPLATE_ELEMENT)
+ if (!page && document->templateDocumentHost())
+ page = document->templateDocumentHost()->page();
+#endif
+ return instrumentingAgentsForPage(page);
+ }
return 0;
}
#endif
Modified: trunk/Source/WebCore/inspector/front-end/DOMAgent.js (139131 => 139132)
--- trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2013-01-09 00:32:15 UTC (rev 139131)
+++ trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2013-01-09 00:42:52 UTC (rev 139132)
@@ -75,6 +75,9 @@
}
}
+ if (payload.templateContent)
+ this._templateContent = new WebInspector.DOMNode(this._domAgent, this.ownerDocument, true, payload.templateContent);
+
if (payload.children)
this._setChildrenPayload(payload.children);
@@ -132,7 +135,7 @@
*/
hasChildNodes: function()
{
- return this._childNodeCount > 0 || !!this._shadowRoots.length;
+ return this._childNodeCount > 0 || !!this._shadowRoots.length || this._templateContent;
},
/**
@@ -453,7 +456,11 @@
if (!prev) {
if (!this.children) {
// First node
- this.children = this._shadowRoots.concat([ node ]);
+ this.children = this._shadowRoots.slice();
+ if (this._templateContent)
+ this.children.push(this._templateContent);
+
+ this.children.push(node);
} else
this.children.unshift(node);
} else
@@ -483,6 +490,9 @@
return;
this.children = this._shadowRoots.slice();
+ if (this._templateContent)
+ this.children.push(this._templateContent);
+
for (var i = 0; i < payloads.length; ++i) {
var payload = payloads[i];
var node = new WebInspector.DOMNode(this._domAgent, this.ownerDocument, this._isInShadowTree, payload);