- fixed <rdar://problem/
3986228> Not able to load additional script blocks dynamically
Run scripts when they're inserted into the document. Use createdByParser bit to make sure
that scripts aren't run twice, once while parsing and again when inserting.
* khtml/html/html_headimpl.cpp:
(HTMLScriptElementImpl::HTMLScriptElementImpl):
(HTMLScriptElementImpl::~HTMLScriptElementImpl):
(HTMLScriptElementImpl::insertedIntoDocument):
(HTMLScriptElementImpl::removedFromDocument):
(HTMLScriptElementImpl::notifyFinished):
* khtml/html/html_headimpl.h:
(DOM::HTMLScriptElementImpl::setCreatedByParser):
* khtml/html/htmlparser.cpp:
(KHTMLParser::getElement):
* khtml/xml/xml_tokenizer.cpp:
(khtml::XMLTokenizer::startElement):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9105
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2005-05-04 Vicki Murley <vicki@apple.com>
+
+ Reviewed by darin.
+
+ - fixed <rdar://problem/3986228> Not able to load additional script blocks dynamically
+
+ Run scripts when they're inserted into the document. Use createdByParser bit to make sure
+ that scripts aren't run twice, once while parsing and again when inserting.
+
+ * khtml/html/html_headimpl.cpp:
+ (HTMLScriptElementImpl::HTMLScriptElementImpl):
+ (HTMLScriptElementImpl::~HTMLScriptElementImpl):
+ (HTMLScriptElementImpl::insertedIntoDocument):
+ (HTMLScriptElementImpl::removedFromDocument):
+ (HTMLScriptElementImpl::notifyFinished):
+ * khtml/html/html_headimpl.h:
+ (DOM::HTMLScriptElementImpl::setCreatedByParser):
+ * khtml/html/htmlparser.cpp:
+ (KHTMLParser::getElement):
+ * khtml/xml/xml_tokenizer.cpp:
+ (khtml::XMLTokenizer::startElement):
+
2005-05-03 David Hyatt <hyatt@apple.com>
Normalize all our custom properties in our implementation to be -khtml (remove all the -apple).
#include "khtmlview.h"
#include "khtml_part.h"
+#include "kjs_proxy.h"
#include "misc/htmlhashes.h"
#include "misc/loader.h"
// -------------------------------------------------------------------------
-HTMLScriptElementImpl::HTMLScriptElementImpl(DocumentPtr *doc) : HTMLElementImpl(doc)
+HTMLScriptElementImpl::HTMLScriptElementImpl(DocumentPtr *doc)
+ : HTMLElementImpl(doc), m_cachedScript(0), m_createdByParser(false)
{
}
HTMLScriptElementImpl::~HTMLScriptElementImpl()
{
+ if (m_cachedScript)
+ m_cachedScript->deref(this);
+}
+
+void HTMLScriptElementImpl::insertedIntoDocument()
+{
+ HTMLElementImpl::insertedIntoDocument();
+
+ assert(!m_cachedScript);
+
+ if (m_createdByParser)
+ return;
+
+ QString url = getAttribute(ATTR_SRC).string();
+ if (!url.isEmpty()) {
+ QString charset = getAttribute(ATTR_CHARSET).string();
+ m_cachedScript = getDocument()->docLoader()->requestScript(DOMString(url), charset);
+ m_cachedScript->ref(this);
+ return;
+ }
+
+ DOMString scriptString = "";
+ for (NodeImpl *n = firstChild(); n; n = n->nextSibling())
+ if (n->isTextNode())
+ scriptString += static_cast<TextImpl*>(n)->data();
+
+ DocumentImpl *doc = getDocument();
+ KHTMLPart *part = doc->part();
+ if (!part)
+ return;
+ KJSProxy *proxy = KJSProxy::proxy(part);
+ if (!proxy)
+ return;
+
+ proxy->evaluate(doc->URL(), 0, scriptString.string(), Node());
+ DocumentImpl::updateDocumentsRendering();
+}
+
+void HTMLScriptElementImpl::removedFromDocument()
+{
+ HTMLElementImpl::removedFromDocument();
+
+ if (m_cachedScript) {
+ m_cachedScript->deref(this);
+ m_cachedScript = 0;
+ }
+}
+
+void HTMLScriptElementImpl::notifyFinished(CachedObject* o)
+{
+ CachedScript *cs = static_cast<CachedScript *>(o);
+
+ assert(cs == m_cachedScript);
+
+ KHTMLPart *part = getDocument()->part();
+ if (part) {
+ KJSProxy *proxy = KJSProxy::proxy(part);
+ if (proxy) {
+ proxy->evaluate(cs->url().string(), 0, cs->script().string(), Node());
+ DocumentImpl::updateDocumentsRendering();
+ }
+ }
+
+ cs->deref(this);
+ m_cachedScript = 0;
}
NodeImpl::Id HTMLScriptElementImpl::id() const
namespace khtml {
class CachedCSSStyleSheet;
-};
+ class CachedScript;
+}
namespace DOM {
// -------------------------------------------------------------------------
-class HTMLScriptElementImpl : public HTMLElementImpl
+class HTMLScriptElementImpl : public HTMLElementImpl, public khtml::CachedObjectClient
{
public:
HTMLScriptElementImpl(DocumentPtr *doc);
-
~HTMLScriptElementImpl();
+
+ virtual void insertedIntoDocument();
+ virtual void removedFromDocument();
+ virtual void notifyFinished(khtml::CachedObject *finishedObj);
virtual Id id() const;
-
virtual bool isURLAttribute(AttributeImpl *attr) const;
-
+
+ void setCreatedByParser(bool createdByParser) { m_createdByParser = createdByParser; }
+
+private:
+ khtml::CachedScript *m_cachedScript;
+ bool m_createdByParser;
};
// -------------------------------------------------------------------------
if (!includesCommentsInDOM)
return 0;
break;
+
+ case ID_SCRIPT:
+ {
+ HTMLScriptElementImpl *scriptElement = new HTMLScriptElementImpl(document);
+ scriptElement->setCreatedByParser(true);
+ return scriptElement;
+ }
}
return document->document()->createHTMLElement(t->id);
m_currentNode = implicitTBody;
}
+ if (newElement->id() == ID_SCRIPT)
+ static_cast<HTMLScriptElementImpl *>(newElement)->setCreatedByParser(true);
+
if (m_currentNode->addChild(newElement)) {
if (m_view && !newElement->attached())
newElement->attach();