Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / custom / CustomElementMicrotaskImportStep.cpp
index 9dcc851..e8fccfc 100644 (file)
 #include "core/dom/custom/CustomElementMicrotaskImportStep.h"
 
 #include "core/dom/custom/CustomElementMicrotaskDispatcher.h"
+#include "core/dom/custom/CustomElementMicrotaskQueue.h"
+#include "core/html/imports/HTMLImportChild.h"
+#include "core/html/imports/HTMLImportLoader.h"
+#include <stdio.h>
 
 namespace WebCore {
 
-PassOwnPtr<CustomElementMicrotaskImportStep> CustomElementMicrotaskImportStep::create()
+PassOwnPtr<CustomElementMicrotaskImportStep> CustomElementMicrotaskImportStep::create(HTMLImportChild* import)
 {
-    return adoptPtr(new CustomElementMicrotaskImportStep());
+    return adoptPtr(new CustomElementMicrotaskImportStep(import));
 }
 
-void CustomElementMicrotaskImportStep::enqueue(PassOwnPtr<CustomElementMicrotaskStep> step)
+CustomElementMicrotaskImportStep::CustomElementMicrotaskImportStep(HTMLImportChild* import)
+    : m_import(import->weakPtr())
+    , m_queue(import->loader()->microtaskQueue())
+    , m_weakFactory(this)
 {
-    // work should not be being created after the import is done
-    // because the parser is done
-    ASSERT(!m_importFinished);
-    m_queue.enqueue(step);
 }
 
-void CustomElementMicrotaskImportStep::importDidFinish()
+CustomElementMicrotaskImportStep::~CustomElementMicrotaskImportStep()
 {
-    // imports should only "finish" once
-    ASSERT(!m_importFinished);
-    m_importFinished = true;
-    CustomElementMicrotaskDispatcher::instance().importDidFinish(this);
+}
+
+bool CustomElementMicrotaskImportStep::shouldWaitForImport() const
+{
+    return m_import && !m_import->isLoaded();
+}
+
+bool CustomElementMicrotaskImportStep::shouldStopProcessing() const
+{
+    return m_import && m_import->isSync();
+}
+
+void CustomElementMicrotaskImportStep::didUpgradeAllCustomElements()
+{
+    ASSERT(m_queue);
+    if (m_import)
+        m_import->didFinishUpgradingCustomElements();
 }
 
 CustomElementMicrotaskStep::Result CustomElementMicrotaskImportStep::process()
 {
-    Result result = m_queue.dispatch();
-    if (!m_importFinished)
-        result = Result(result | ShouldStop);
+    Result result = m_queue->dispatch();
+    if (!(result & ShouldStop) && !shouldWaitForImport())
+        didUpgradeAllCustomElements();
+
+    if (shouldWaitForImport())
+        result = Result(result | ShouldRemain | ShouldStop);
+    if (!shouldStopProcessing())
+        result = Result(result & ~ShouldStop);
     return result;
 }
 
+#if !defined(NDEBUG)
+void CustomElementMicrotaskImportStep::show(unsigned indent)
+{
+    fprintf(stderr, "%*sImport(wait=%d sync=%d, url=%s)\n", indent, "", shouldWaitForImport(), shouldStopProcessing(), m_import ? m_import->url().string().utf8().data() : "null");
+    m_queue->show(indent + 1);
+}
+#endif
+
 } // namespace WebCore