[webkit-changes] cvs commit: WebCore ChangeLog

Alexey ap at opensource.apple.com
Wed Dec 28 10:46:25 PST 2005


ap          05/12/28 10:46:24

  Modified:    khtml/html html_headimpl.cpp htmlparser.cpp htmlparser.h
                        htmltokenizer.h htmltokenizer.cpp
               khtml/misc loader.h loader.cpp
               .        ChangeLog
  Log:
          Reviewed by Darin, landed by ap.
  
          Test: fast/dom/HTMLScriptElement/script-load-events.html
  
          - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5812
            Generate load events for <script> elements
  
          * khtml/html/html_headimpl.cpp:
          (HTMLScriptElementImpl::parseMappedAttribute): Parse the onload and onerror attributes.
          (HTMLScriptElementImpl::closeRenderer): Call base class's implementation.
          (HTMLScriptElementImpl::notifyFinished): Dispatch load and error events.
          * khtml/html/htmlparser.h:
          * khtml/html/htmlparser.cpp:
          (HTMLParser::parseToken): Return the node that was inserted.
          * khtml/html/htmltokenizer.h: Added scriptNode, a RefPtr to the node corresponding
          to the current load request.
          * khtml/html/htmltokenizer.cpp:
          (HTMLTokenizer::scriptHandler): Reset scriptNode if a load request was not made.
          (HTMLTokenizer::parseTag): Set scriptNode to the node created from the script tag.
          (HTMLTokenizer::processToken): Return the node that was inserted.
          (HTMLTokenizer::notifyFinished): Reset scriptNode and dispatch load and error events.
          * khtml/misc/loader.h:
          (CachedScript::errorOccurred): Added.
          * khtml/misc/loader.cpp:
          (CachedScript::CachedScript):
          (CachedScript::error):
  
  Revision  Changes    Path
  1.65      +15 -2     WebCore/khtml/html/html_headimpl.cpp
  
  Index: html_headimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_headimpl.cpp,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- html_headimpl.cpp	23 Dec 2005 18:44:16 -0000	1.64
  +++ html_headimpl.cpp	28 Dec 2005 18:46:21 -0000	1.65
  @@ -28,6 +28,7 @@
   
   #include "html/html_documentimpl.h"
   #include "xml/dom_textimpl.h"
  +#include "xml/EventNames.h"
   
   #include "khtmlview.h"
   #include "khtml_part.h"
  @@ -45,6 +46,7 @@
   
   using namespace DOM;
   using namespace HTMLNames;
  +using namespace EventNames;
   using namespace khtml;
   
   HTMLBaseElementImpl::HTMLBaseElementImpl(DocumentImpl *doc)
  @@ -507,7 +509,8 @@
   
   void HTMLScriptElementImpl::parseMappedAttribute(MappedAttributeImpl *attr)
   {
  -    if (attr->name() == srcAttr) {
  +    const QualifiedName& attrName = attr->name();
  +    if (attrName == srcAttr) {
           if (m_evaluated || m_cachedScript || m_createdByParser || !inDocument())
               return;
   
  @@ -522,6 +525,10 @@
               m_cachedScript = getDocument()->docLoader()->requestScript(url, charset);
               m_cachedScript->ref(this);
           }
  +    } else if (attrName == onerrorAttr) {
  +        setHTMLEventListener(errorEvent, attr);
  +    } else if (attrName == onloadAttr) {
  +        setHTMLEventListener(loadEvent, attr);
       } else
           HTMLElementImpl::parseMappedAttribute(attr);
   }
  @@ -532,6 +539,7 @@
       // allow dynamic loading later.
       if (getAttribute(srcAttr).isEmpty() && text().isEmpty())
           setCreatedByParser(false);
  +    HTMLElementImpl::closeRenderer();
   }
   
   void HTMLScriptElementImpl::insertedIntoDocument()
  @@ -581,7 +589,12 @@
   
       assert(cs == m_cachedScript);
   
  -    evaluateScript(cs->url(), cs->script());
  +    if (cs->errorOccurred())
  +        dispatchHTMLEvent(errorEvent, false, false);
  +    else {
  +        evaluateScript(cs->url(), cs->script());
  +        dispatchHTMLEvent(loadEvent, false, false);
  +    }
   
       cs->deref(this);
       m_cachedScript = 0;
  
  
  
  1.128     +7 -4      WebCore/khtml/html/htmlparser.cpp
  
  Index: htmlparser.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/htmlparser.cpp,v
  retrieving revision 1.127
  retrieving revision 1.128
  diff -u -r1.127 -r1.128
  --- htmlparser.cpp	27 Dec 2005 18:26:14 -0000	1.127
  +++ htmlparser.cpp	28 Dec 2005 18:46:22 -0000	1.128
  @@ -180,7 +180,7 @@
       currentIsReferenced = newCurrentIsReferenced;
   }
   
  -void HTMLParser::parseToken(Token *t)
  +NodeImpl *HTMLParser::parseToken(Token *t)
   {
       if (!discard_until.isNull()) {
           if (t->tagName == discard_until && !t->beginTag)
  @@ -188,7 +188,7 @@
   
           // do not skip </iframe>
           if (!discard_until.isNull() || (current->localName() != t->tagName))
  -            return;
  +            return 0;
       }
   
       // Apparently some sites use </br> instead of <br>.  Be compatible with IE and Firefox and treat this like <br>.
  @@ -197,7 +197,7 @@
   
       if (!t->beginTag) {
           processCloseTag(t);
  -        return;
  +        return 0;
       }
   
       // ignore spaces, if we're not inside a paragraph or other inline code
  @@ -210,7 +210,7 @@
       NodeImpl *n = getNode(t);
       // just to be sure, and to catch currently unimplemented stuff
       if (!n)
  -        return;
  +        return 0;
   
       RefPtr<NodeImpl> protectNode(n);
   
  @@ -240,7 +240,10 @@
   
           if (form == n)
               form = 0;
  +        
  +        return 0;
       }
  +    return n;
   }
   
   static bool isTableSection(NodeImpl* n)
  
  
  
  1.32      +1 -1      WebCore/khtml/html/htmlparser.h
  
  Index: htmlparser.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/htmlparser.h,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- htmlparser.h	19 Dec 2005 20:41:46 -0000	1.31
  +++ htmlparser.h	28 Dec 2005 18:46:22 -0000	1.32
  @@ -62,7 +62,7 @@
       /**
        * parses one token delivered by the tokenizer
        */
  -    void parseToken(khtml::Token *_t);
  +    DOM::NodeImpl *parseToken(khtml::Token *_t);
       
       /**
        * tokenizer says it's not going to be sending us any more tokens
  
  
  
  1.49      +2 -1      WebCore/khtml/html/htmltokenizer.h
  
  Index: htmltokenizer.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/htmltokenizer.h,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- htmltokenizer.h	27 Dec 2005 18:26:14 -0000	1.48
  +++ htmltokenizer.h	28 Dec 2005 18:46:22 -0000	1.49
  @@ -112,7 +112,7 @@
       void end();
   
       void reset();
  -    void processToken();
  +    DOM::NodeImpl *processToken();
   
       State processListing(TokenizerString, State);
       State parseComment(TokenizerString&, State);
  @@ -324,6 +324,7 @@
       // the output of the script to be postponed until after the script has finished executing
       int m_executingScript;
       QPtrQueue<CachedScript> pendingScripts;
  +    RefPtr<DOM::NodeImpl> scriptNode;
       // you can pause the tokenizer if you need to display a dialog or something
       bool onHold;
   
  
  
  
  1.131     +23 -5     WebCore/khtml/html/htmltokenizer.cpp
  
  Index: htmltokenizer.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/htmltokenizer.cpp,v
  retrieving revision 1.130
  retrieving revision 1.131
  diff -u -r1.130 -r1.131
  --- htmltokenizer.cpp	27 Dec 2005 18:26:14 -0000	1.130
  +++ htmltokenizer.cpp	28 Dec 2005 18:46:22 -0000	1.131
  @@ -43,6 +43,7 @@
   #include "khtmlview.h"
   #include "khtml_part.h"
   #include "xml/dom_docimpl.h"
  +#include "xml/EventNames.h"
   #include "css/csshelper.h"
   #include "ecma/kjs_proxy.h"
   #include <kcharsets.h>
  @@ -53,6 +54,7 @@
   #include <stdlib.h>
   
   using namespace DOM::HTMLNames;
  +using namespace DOM::EventNames;
   
   using DOM::AtomicString;
   using DOM::AttributeImpl;
  @@ -66,6 +68,7 @@
   using DOM::QualifiedName;
   using DOM::MappedAttributeImpl;
   using DOM::NamedMappedAttrMapImpl;
  +using DOM::NodeImpl;
   
   #include "kentities.c"
   
  @@ -385,6 +388,8 @@
   #endif
               if ( (cs = parser->doc()->docLoader()->requestScript(scriptSrc, scriptSrcCharset) ))
                   pendingScripts.enqueue(cs);
  +            else
  +                scriptNode = 0;
           }
           scriptSrc=QString::null;
       }
  @@ -394,6 +399,7 @@
           kdDebug( 6036 ) << QString(scriptCode, scriptCodeSize) << endl;
           kdDebug( 6036 ) << "---END SCRIPT---" << endl;
   #endif
  +        scriptNode = 0;
           // Parse scriptCode containing <script> info
           doScriptExec = true;
       }
  @@ -1275,11 +1281,13 @@
                   }
               }
   
  -            processToken();
  +            NodeImpl *n = processToken();
   
               if (tagName == preTag) {
                   state.setDiscardLF(true); // Discard the first LF after we open a pre.
               } else if (tagName == scriptTag) {
  +                assert(!scriptNode);
  +                scriptNode = n;
                   if (beginTag) {
                       searchStopper = scriptEnd;
                       searchStopperLen = 8;
  @@ -1663,7 +1671,7 @@
           end(); // this actually causes us to be deleted
   }
   
  -void HTMLTokenizer::processToken()
  +NodeImpl *HTMLTokenizer::processToken()
   {
       KJSProxyImpl *jsProxy = (view && view->part()) ? view->part()->jScript() : 0L;    
       if (jsProxy)
  @@ -1685,7 +1693,7 @@
           currToken.reset();
           if (jsProxy)
               jsProxy->setEventHandlerLineno(lineno+src.lineCount());
  -        return;
  +        return 0;
       }
   
       dest = buffer;
  @@ -1712,15 +1720,17 @@
       }
       kdDebug( 6036 ) << endl;
   #endif
  +    NodeImpl *n = 0;
       
       if (!m_parserStopped) {
           // pass the token over to the parser, the parser DOES NOT delete the token
  -        parser->parseToken(&currToken);
  +        n = parser->parseToken(&currToken);
       }
       
       currToken.reset();
       if (jsProxy)
           jsProxy->setEventHandlerLineno(0);
  +    return n;
   }
   
   HTMLTokenizer::~HTMLTokenizer()
  @@ -1773,14 +1783,22 @@
           // make sure we forget about the script before we execute the new one
           // infinite recursion might happen otherwise
           QString cachedScriptUrl( cs->url().qstring() );
  +        bool errorOccurred = cs->errorOccurred();
           cs->deref(this);
  +        RefPtr<NodeImpl> n = scriptNode;
  +        scriptNode = 0;
   
   #ifdef INSTRUMENT_LAYOUT_SCHEDULING
           if (!parser->doc()->ownerElement())
               printf("external script beginning execution at %d\n", parser->doc()->elapsedTime());
   #endif
   
  -	m_state = scriptExecution(scriptSource.qstring(), m_state, cachedScriptUrl);
  +	if (errorOccurred)
  +            n->dispatchHTMLEvent(errorEvent, false, false);
  +        else {
  +            m_state = scriptExecution(scriptSource.qstring(), m_state, cachedScriptUrl);
  +            n->dispatchHTMLEvent(loadEvent, false, false);
  +        }
   
           // The state of pendingScripts.isEmpty() can change inside the scriptExecution()
           // call above, so test afterwards.
  
  
  
  1.50      +3 -0      WebCore/khtml/misc/loader.h
  
  Index: loader.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/misc/loader.h,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- loader.h	20 Dec 2005 08:49:48 -0000	1.49
  +++ loader.h	28 Dec 2005 18:46:23 -0000	1.50
  @@ -293,12 +293,15 @@
   	virtual void error( int err, const char *text );
   
           virtual bool schedule() const { return false; }
  +        
  +        bool errorOccurred() const { return m_errorOccurred; }
   
   	void checkNotify();
   
       protected:
   	DOM::DOMString m_script;
           QTextCodec* m_codec;
  +        bool m_errorOccurred;
       };
   
       class ImageSource;
  
  
  
  1.85      +3 -0      WebCore/khtml/misc/loader.cpp
  
  Index: loader.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/misc/loader.cpp,v
  retrieving revision 1.84
  retrieving revision 1.85
  diff -u -r1.84 -r1.85
  --- loader.cpp	23 Dec 2005 18:44:21 -0000	1.84
  +++ loader.cpp	28 Dec 2005 18:46:23 -0000	1.85
  @@ -253,6 +253,7 @@
       // But some websites think their scripts are <some wrong mimetype here>
       // and refuse to serve them if we only accept application/x-javascript.
       setAccept( QString::fromLatin1("*/*") );
  +    m_errorOccurred = false;
       // load the file
       Cache::loader()->load(dl, this, false);
       m_loading = true;
  @@ -265,6 +266,7 @@
   CachedScript::CachedScript(const DOMString &url, const QString &script_data)
       : CachedObject(url, Script, KIO::CC_Verify, 0, script_data.length())
   {
  +    m_errorOccurred = false;
       m_loading = false;
       m_status = Persistent;
       m_codec = 0;
  @@ -323,6 +325,7 @@
   void CachedScript::error( int /*err*/, const char */*text*/ )
   {
       m_loading = false;
  +    m_errorOccurred = true;
       checkNotify();
   }
   
  
  
  
  1.50      +29 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- ChangeLog	28 Dec 2005 18:21:49 -0000	1.49
  +++ ChangeLog	28 Dec 2005 18:46:24 -0000	1.50
  @@ -1,3 +1,32 @@
  +2005-12-28  Mitz Pettel  <opendarwin.org at mitzpettel.com>
  +
  +        Reviewed by Darin, landed by ap.
  +
  +        Test: fast/dom/HTMLScriptElement/script-load-events.html
  +
  +        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5812
  +          Generate load events for <script> elements
  +
  +        * khtml/html/html_headimpl.cpp:
  +        (HTMLScriptElementImpl::parseMappedAttribute): Parse the onload and onerror attributes.
  +        (HTMLScriptElementImpl::closeRenderer): Call base class's implementation.
  +        (HTMLScriptElementImpl::notifyFinished): Dispatch load and error events.
  +        * khtml/html/htmlparser.h:
  +        * khtml/html/htmlparser.cpp:
  +        (HTMLParser::parseToken): Return the node that was inserted.
  +        * khtml/html/htmltokenizer.h: Added scriptNode, a RefPtr to the node corresponding
  +        to the current load request.
  +        * khtml/html/htmltokenizer.cpp:
  +        (HTMLTokenizer::scriptHandler): Reset scriptNode if a load request was not made.
  +        (HTMLTokenizer::parseTag): Set scriptNode to the node created from the script tag.
  +        (HTMLTokenizer::processToken): Return the node that was inserted.
  +        (HTMLTokenizer::notifyFinished): Reset scriptNode and dispatch load and error events.
  +        * khtml/misc/loader.h:
  +        (CachedScript::errorOccurred): Added.
  +        * khtml/misc/loader.cpp:
  +        (CachedScript::CachedScript):
  +        (CachedScript::error):
  +
   2005-12-28  Alexey Proskuryakov  <ap at nypop.com>
   
           Reviewed by Maciej.
  
  
  



More information about the webkit-changes mailing list