Title: [107202] trunk
Revision
107202
Author
[email protected]
Date
2012-02-09 01:54:04 -0800 (Thu, 09 Feb 2012)

Log Message

Disable adding a shadow root to elements having a dynamic built-in shadow root.
https://bugs.webkit.org/show_bug.cgi?id=77935

Patch by Shinya Kawanaka <[email protected]> on 2012-02-09
Reviewed by Hajime Morita.

Source/WebCore:

We temporarily disable adding a shadow root in elements having a dynamic user agent shadow root.
These shadow roots are currently created using Element::ensureShadowRoot.
So we don't check the condition if a shadow root is created eaither using Element::ensureShadowRoot
or ShadowRoot::CreatingUserAgentShadowRoot is specified for ShadowRoot::create.

Test: fast/dom/shadow/shadow-disable.html

* dom/Element.cpp:
(WebCore::Element::ensureShadowRoot):
* dom/ShadowRoot.cpp:
(WebCore::allowsUserShadowRoot):
(WebCore):
(WebCore::ShadowRoot::create):
* dom/ShadowRoot.h:
(ShadowRoot):
* html/HTMLDetailsElement.cpp:
(WebCore::HTMLDetailsElement::createShadowSubtree):
  ShadowRoot::CreatingUserAgentShadowRoot is specified.
* html/HTMLKeygenElement.cpp:
(WebCore::HTMLKeygenElement::HTMLKeygenElement): ditto.
* html/HTMLMeterElement.cpp:
(WebCore::HTMLMeterElement::createShadowSubtree): ditto.
* html/HTMLProgressElement.cpp:
(WebCore::HTMLProgressElement::createShadowSubtree): ditto.
* html/HTMLSummaryElement.cpp:
(WebCore::HTMLSummaryElement::createShadowSubtree): ditto.
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::createShadowSubtree): ditto.

LayoutTests:

* fast/dom/shadow/shadow-disable-expected.txt: Added.
* fast/dom/shadow/shadow-disable.html: Added.
* platform/efl/Skipped:
* platform/gtk/Skipped:
* platform/mac/Skipped:
* platform/qt/Skipped:
* platform/win/Skipped:
* platform/wincairo/Skipped:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (107201 => 107202)


--- trunk/LayoutTests/ChangeLog	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/ChangeLog	2012-02-09 09:54:04 UTC (rev 107202)
@@ -1,3 +1,19 @@
+2012-02-09  Shinya Kawanaka  <[email protected]>
+
+        Disable adding a shadow root to elements having a dynamic built-in shadow root.
+        https://bugs.webkit.org/show_bug.cgi?id=77935
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/shadow/shadow-disable-expected.txt: Added.
+        * fast/dom/shadow/shadow-disable.html: Added.
+        * platform/efl/Skipped:
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+        * platform/wincairo/Skipped:
+
 2012-02-08  Alexander Pavlov  <[email protected]>
 
         Web Inspector: hovering over element with :hover style halts inspector

Added: trunk/LayoutTests/fast/dom/shadow/shadow-disable-expected.txt (0 => 107202)


--- trunk/LayoutTests/fast/dom/shadow/shadow-disable-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-disable-expected.txt	2012-02-09 09:54:04 UTC (rev 107202)
@@ -0,0 +1,29 @@
+Tests to ensure that shadow element cannot be created in elements having dynamically created shadow root.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+DIV
+PASS new WebKitShadowRoot(element) is not null
+SPAN
+PASS new WebKitShadowRoot(element) is not null
+A
+PASS new WebKitShadowRoot(element) is not null
+SECTION
+PASS new WebKitShadowRoot(element) is not null
+INPUT
+PASS new WebKitShadowRoot(element) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+TEXTAREA
+PASS new WebKitShadowRoot(element) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+SELECT
+PASS new WebKitShadowRoot(element) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+AUDIO
+PASS new WebKitShadowRoot(element) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+VIDEO
+PASS new WebKitShadowRoot(element) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+tref
+PASS new WebKitShadowRoot(element) threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/shadow/shadow-disable.html (0 => 107202)


--- trunk/LayoutTests/fast/dom/shadow/shadow-disable.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-disable.html	2012-02-09 09:54:04 UTC (rev 107202)
@@ -0,0 +1,52 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<p id="description"></p>
+<svg xmlns="http://www.w3.org/2000/svg" style="display:none"><tref id="tref" /></svg>
+<pre id="console"></pre>
+<script>
+description("Tests to ensure that shadow element cannot be created in elements having dynamically created shadow root.");
+
+function testToAddShadowRoot(element, success) {
+    debug(element.nodeName);
+
+    if (success)
+        shouldNotBe("new WebKitShadowRoot(element)", "null");
+    else
+        shouldThrow("new WebKitShadowRoot(element)");
+}
+
+var elementsToSuccess = [
+    document.createElement('div'),
+    document.createElement('span'),
+    document.createElement('a'),
+    document.createElement('section')
+];
+
+var elementsToFail = [
+    document.createElement('input'),
+    document.createElement('textarea'),
+    document.createElement('select'),
+    document.createElement('audio'),
+    document.createElement('video'),
+    document.getElementById('tref')
+];
+
+for (var i = 0; i < elementsToSuccess.length; ++i) {
+    var element = elementsToSuccess[i];
+    testToAddShadowRoot(element, true);
+}
+
+for (var i = 0; i < elementsToFail.length; ++i) {
+    var element = elementsToFail[i];
+    testToAddShadowRoot(element, false);
+}
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/platform/efl/Skipped (107201 => 107202)


--- trunk/LayoutTests/platform/efl/Skipped	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/platform/efl/Skipped	2012-02-09 09:54:04 UTC (rev 107202)
@@ -1938,6 +1938,7 @@
 
 # ENABLE(SHADOW_DOM) is disabled.
 fast/dom/shadow/shadow-root-js-api.html
+fast/dom/shadow/shadow-disable.html
 
 # CSS Filters support not yet enabled (needs ENABLE_CSS_FILTERS).
 # https://bugs.webkit.org/show_bug.cgi?id=68469

Modified: trunk/LayoutTests/platform/gtk/Skipped (107201 => 107202)


--- trunk/LayoutTests/platform/gtk/Skipped	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/platform/gtk/Skipped	2012-02-09 09:54:04 UTC (rev 107202)
@@ -351,6 +351,7 @@
 
 # ENABLE(SHADOW_DOM) is disabled.
 fast/dom/shadow/shadow-root-js-api.html
+fast/dom/shadow/shadow-disable.html
 
 # CSS Regions support not yet enabled. http://webkit.org/b/57312
 fast/regions

Modified: trunk/LayoutTests/platform/mac/Skipped (107201 => 107202)


--- trunk/LayoutTests/platform/mac/Skipped	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/platform/mac/Skipped	2012-02-09 09:54:04 UTC (rev 107202)
@@ -420,6 +420,7 @@
 
 # ENABLE(SHADOW_DOM) is disabled.
 fast/dom/shadow/shadow-root-js-api.html
+fast/dom/shadow/shadow-disable.html
 
 # JSC does not support setIsolatedWorldSecurityOrigin (http://webkit.org/b/61540)
 http/tests/security/isolatedWorld/cross-origin-xhr.html

Modified: trunk/LayoutTests/platform/qt/Skipped (107201 => 107202)


--- trunk/LayoutTests/platform/qt/Skipped	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/platform/qt/Skipped	2012-02-09 09:54:04 UTC (rev 107202)
@@ -159,6 +159,7 @@
 
 # ENABLE(SHADOW_DOM) is disabled.
 fast/dom/shadow/shadow-root-js-api.html
+fast/dom/shadow/shadow-disable.html
 
 # CSS Regions support not yet enabled. http://webkit.org/b/57312
 fast/regions

Modified: trunk/LayoutTests/platform/win/Skipped (107201 => 107202)


--- trunk/LayoutTests/platform/win/Skipped	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/platform/win/Skipped	2012-02-09 09:54:04 UTC (rev 107202)
@@ -1442,6 +1442,7 @@
 
 # ENABLE(SHADOW_DOM) is disabled.
 fast/dom/shadow/shadow-root-js-api.html
+fast/dom/shadow/shadow-disable.html
 
 # CSS Regions support not yet enabled. http://webkit.org/b/57312
 fast/regions

Modified: trunk/LayoutTests/platform/wincairo/Skipped (107201 => 107202)


--- trunk/LayoutTests/platform/wincairo/Skipped	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/LayoutTests/platform/wincairo/Skipped	2012-02-09 09:54:04 UTC (rev 107202)
@@ -1963,6 +1963,7 @@
 
 # ENABLE(SHADOW_DOM) is disabled.
 fast/dom/shadow/shadow-root-js-api.html
+fast/dom/shadow/shadow-disable.html
 
 # CSS Regions support not yet enabled. http://webkit.org/b/57312
 fast/regions

Modified: trunk/Source/WebCore/ChangeLog (107201 => 107202)


--- trunk/Source/WebCore/ChangeLog	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/ChangeLog	2012-02-09 09:54:04 UTC (rev 107202)
@@ -1,3 +1,39 @@
+2012-02-09  Shinya Kawanaka  <[email protected]>
+
+        Disable adding a shadow root to elements having a dynamic built-in shadow root.
+        https://bugs.webkit.org/show_bug.cgi?id=77935
+
+        Reviewed by Hajime Morita.
+
+        We temporarily disable adding a shadow root in elements having a dynamic user agent shadow root.
+        These shadow roots are currently created using Element::ensureShadowRoot.
+        So we don't check the condition if a shadow root is created eaither using Element::ensureShadowRoot
+        or ShadowRoot::CreatingUserAgentShadowRoot is specified for ShadowRoot::create.
+
+        Test: fast/dom/shadow/shadow-disable.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::ensureShadowRoot):
+        * dom/ShadowRoot.cpp:
+        (WebCore::allowsUserShadowRoot):
+        (WebCore):
+        (WebCore::ShadowRoot::create):
+        * dom/ShadowRoot.h:
+        (ShadowRoot):
+        * html/HTMLDetailsElement.cpp:
+        (WebCore::HTMLDetailsElement::createShadowSubtree):
+          ShadowRoot::CreatingUserAgentShadowRoot is specified.
+        * html/HTMLKeygenElement.cpp:
+        (WebCore::HTMLKeygenElement::HTMLKeygenElement): ditto.
+        * html/HTMLMeterElement.cpp:
+        (WebCore::HTMLMeterElement::createShadowSubtree): ditto.
+        * html/HTMLProgressElement.cpp:
+        (WebCore::HTMLProgressElement::createShadowSubtree): ditto.
+        * html/HTMLSummaryElement.cpp:
+        (WebCore::HTMLSummaryElement::createShadowSubtree): ditto.
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::createShadowSubtree): ditto.
+
 2012-02-08  Alexander Pavlov  <[email protected]>
 
         Web Inspector: hovering over element with :hover style halts inspector

Modified: trunk/Source/WebCore/dom/Element.cpp (107201 => 107202)


--- trunk/Source/WebCore/dom/Element.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -1199,10 +1199,7 @@
     if (ShadowRoot* existingRoot = shadowRoot())
         return existingRoot;
 
-    ExceptionCode ec = 0;
-    setShadowRoot(ShadowRoot::create(document()), ec);
-    ASSERT(!ec);
-    return shadowRoot();
+    return ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot).get();
 }
 
 void Element::removeShadowRoot()

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (107201 => 107202)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -31,7 +31,9 @@
 #include "Document.h"
 #include "Element.h"
 #include "HTMLContentElement.h"
+#include "HTMLNames.h"
 #include "NodeRareData.h"
+#include "SVGNames.h"
 #include "Text.h"
 
 namespace WebCore {
@@ -59,12 +61,50 @@
         clearRareData();
 }
 
+static bool allowsAuthorShadowRoot(Element* element)
+{
+    // FIXME: MEDIA recreates shadow root dynamically.
+    // https://bugs.webkit.org/show_bug.cgi?id=77936
+    if (element->hasTagName(HTMLNames::videoTag) || element->hasTagName(HTMLNames::audioTag))
+        return false;
+
+    // FIXME: ValidationMessage recreates shadow root dynamically.
+    // https://bugs.webkit.org/show_bug.cgi?id=77937
+    // Especially, INPUT recreates shadow root dynamically.
+    // https://bugs.webkit.org/show_bug.cgi?id=77930
+    if (element->isFormControlElement())
+        return false;
+
+    // FIXME: We disable multiple shadow subtrees for SVG for while, because there will be problems to support it.
+    // https://bugs.webkit.org/show_bug.cgi?id=78205
+    // Especially SVG TREF recreates shadow root dynamically.
+    // https://bugs.webkit.org/show_bug.cgi?id=77938
+    if (element->isSVGElement())
+        return false;
+
+    return true;
+}
+
 PassRefPtr<ShadowRoot> ShadowRoot::create(Element* element, ExceptionCode& ec)
 {
+    return create(element, CreatingAuthorShadowRoot, ec);
+}
+
+PassRefPtr<ShadowRoot> ShadowRoot::create(Element* element, ShadowRootCreationPurpose purpose, ExceptionCode& ec)
+{
     if (!element || element->shadowRoot()) {
         ec = HIERARCHY_REQUEST_ERR;
         return 0;
     }
+
+    // Since some elements recreates shadow root dynamically, multiple shadow subtrees won't work well in that element.
+    // Until they are fixed, we disable adding author shadow root for them.
+    if (purpose == CreatingAuthorShadowRoot && !allowsAuthorShadowRoot(element)) {
+        ec = HIERARCHY_REQUEST_ERR;
+        return 0;
+    }
+
+    ASSERT(purpose != CreatingUserAgentShadowRoot || !element->shadowRoot());
     RefPtr<ShadowRoot> shadowRoot = create(element->document());
 
     ec = 0;

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (107201 => 107202)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-02-09 09:54:04 UTC (rev 107202)
@@ -42,6 +42,16 @@
     static PassRefPtr<ShadowRoot> create(Document*);
     static PassRefPtr<ShadowRoot> create(Element*, ExceptionCode&);
 
+    // FIXME: We will support multiple shadow subtrees, however current implementation does not work well
+    // if a shadow root is dynamically created. So we prohibit multiple shadow subtrees
+    // in several elements for a while.
+    // See https://bugs.webkit.org/show_bug.cgi?id=77503 and related bugs.
+    enum ShadowRootCreationPurpose {
+        CreatingUserAgentShadowRoot,
+        CreatingAuthorShadowRoot,
+    };
+    static PassRefPtr<ShadowRoot> create(Element*, ShadowRootCreationPurpose, ExceptionCode& = ASSERT_NO_EXCEPTION);
+
     void recalcShadowTreeStyle(StyleChange);
 
     void setNeedsReattachHostChildrenAndShadow();

Modified: trunk/Source/WebCore/html/HTMLDetailsElement.cpp (107201 => 107202)


--- trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/html/HTMLDetailsElement.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -110,7 +110,7 @@
 {
     ASSERT(!shadowRoot());
 
-    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ASSERT_NO_EXCEPTION);
+    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot);
     root->appendChild(DetailsSummaryElement::create(document()), ASSERT_NO_EXCEPTION, true);
     root->appendChild(DetailsContentElement::create(document()), ASSERT_NO_EXCEPTION, true);
 }

Modified: trunk/Source/WebCore/html/HTMLKeygenElement.cpp (107201 => 107202)


--- trunk/Source/WebCore/html/HTMLKeygenElement.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/html/HTMLKeygenElement.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -86,7 +86,7 @@
     }
 
     ASSERT(!shadowRoot());
-    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ASSERT_NO_EXCEPTION);
+    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot);
     root->appendChild(select, ec);
 }
 

Modified: trunk/Source/WebCore/html/HTMLMeterElement.cpp (107201 => 107202)


--- trunk/Source/WebCore/html/HTMLMeterElement.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/html/HTMLMeterElement.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -241,7 +241,7 @@
     ExceptionCode ec = 0;
     bar->appendChild(m_value, ec);
 
-    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ASSERT_NO_EXCEPTION);
+    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot);
     root->appendChild(bar, ec);
 }
 

Modified: trunk/Source/WebCore/html/HTMLProgressElement.cpp (107201 => 107202)


--- trunk/Source/WebCore/html/HTMLProgressElement.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/html/HTMLProgressElement.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -159,7 +159,7 @@
     m_value = ProgressValueElement::create(document());
     bar->appendChild(m_value, ASSERT_NO_EXCEPTION);
 
-    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ASSERT_NO_EXCEPTION);
+    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot, ASSERT_NO_EXCEPTION);
     root->appendChild(bar, ASSERT_NO_EXCEPTION);
 }
 

Modified: trunk/Source/WebCore/html/HTMLSummaryElement.cpp (107201 => 107202)


--- trunk/Source/WebCore/html/HTMLSummaryElement.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/html/HTMLSummaryElement.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -74,7 +74,7 @@
 void HTMLSummaryElement::createShadowSubtree()
 {
     ASSERT(!shadowRoot());
-    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ASSERT_NO_EXCEPTION);
+    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot);
     root->appendChild(DetailsMarkerControl::create(document()), ASSERT_NO_EXCEPTION, true);
     root->appendChild(SummaryContentElement::create(document()), ASSERT_NO_EXCEPTION, true);
 }

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (107201 => 107202)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2012-02-09 09:51:29 UTC (rev 107201)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2012-02-09 09:54:04 UTC (rev 107202)
@@ -85,7 +85,7 @@
 void HTMLTextAreaElement::createShadowSubtree()
 {
     ASSERT(!shadowRoot());
-    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ASSERT_NO_EXCEPTION);
+    RefPtr<ShadowRoot> root = ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot);
     root->appendChild(TextControlInnerTextElement::create(document()), ASSERT_NO_EXCEPTION);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to