Changeset 64873 in webkit


Ignore:
Timestamp:
Aug 6, 2010 3:07:50 PM (14 years ago)
Author:
tonyg@chromium.org
Message:

2010-08-06 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Eric Seidel.

Factor an AsyncScriptRunner out of Document
https://bugs.webkit.org/show_bug.cgi?id=43633

This copies the existing implementation exactly. In the future
this will use PendingScript which handles ref counting without
the need for those manual ref()/deref()s. This is also currently
a trivial class, but a little more logic will be added to it to
support <script async>.

No new tests because no new functionality.

  • Android.mk:
  • CMakeLists.txt:
  • GNUmakefile.am:
  • WebCore.gypi:
  • WebCore.pro:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/AsyncScriptRunner.cpp: Added. (WebCore::AsyncScriptRunner::AsyncScriptRunner): (WebCore::AsyncScriptRunner::~AsyncScriptRunner): (WebCore::AsyncScriptRunner::executeScriptSoon): (WebCore::AsyncScriptRunner::suspend): (WebCore::AsyncScriptRunner::resume): (WebCore::AsyncScriptRunner::timerFired):
  • dom/AsyncScriptRunner.h: Added. (WebCore::AsyncScriptRunner::create): (WebCore::AsyncScriptRunner::hasPendingScripts):
  • dom/Document.cpp: (WebCore::Document::Document): (WebCore::Document::~Document):
  • dom/Document.h: (WebCore::Document::asyncScriptRunner):
  • dom/ScriptElement.cpp: (WebCore::ScriptElementData::notifyFinished):
  • page/PageGroupLoadDeferrer.cpp: (WebCore::PageGroupLoadDeferrer::PageGroupLoadDeferrer): (WebCore::PageGroupLoadDeferrer::~PageGroupLoadDeferrer):
Location:
trunk/WebCore
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/Android.mk

    r64857 r64873  
    9999        \
    100100        dom/ActiveDOMObject.cpp \
     101        dom/AsyncScriptRunner.cpp \
    101102        dom/Attr.cpp \
    102103        dom/Attribute.cpp \
  • trunk/WebCore/CMakeLists.txt

    r64857 r64873  
    774774
    775775    dom/ActiveDOMObject.cpp
     776    dom/AsyncScriptRunner.cpp
    776777    dom/Attr.cpp
    777778    dom/Attribute.cpp
  • trunk/WebCore/ChangeLog

    r64872 r64873  
     12010-08-06  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Factor an AsyncScriptRunner out of Document
     6        https://bugs.webkit.org/show_bug.cgi?id=43633
     7
     8        This copies the existing implementation exactly. In the future
     9        this will use PendingScript which handles ref counting without
     10        the need for those manual ref()/deref()s. This is also currently
     11        a trivial class, but a little more logic will be added to it to
     12        support <script async>.
     13
     14        No new tests because no new functionality.
     15
     16        * Android.mk:
     17        * CMakeLists.txt:
     18        * GNUmakefile.am:
     19        * WebCore.gypi:
     20        * WebCore.pro:
     21        * WebCore.vcproj/WebCore.vcproj:
     22        * WebCore.xcodeproj/project.pbxproj:
     23        * dom/AsyncScriptRunner.cpp: Added.
     24        (WebCore::AsyncScriptRunner::AsyncScriptRunner):
     25        (WebCore::AsyncScriptRunner::~AsyncScriptRunner):
     26        (WebCore::AsyncScriptRunner::executeScriptSoon):
     27        (WebCore::AsyncScriptRunner::suspend):
     28        (WebCore::AsyncScriptRunner::resume):
     29        (WebCore::AsyncScriptRunner::timerFired):
     30        * dom/AsyncScriptRunner.h: Added.
     31        (WebCore::AsyncScriptRunner::create):
     32        (WebCore::AsyncScriptRunner::hasPendingScripts):
     33        * dom/Document.cpp:
     34        (WebCore::Document::Document):
     35        (WebCore::Document::~Document):
     36        * dom/Document.h:
     37        (WebCore::Document::asyncScriptRunner):
     38        * dom/ScriptElement.cpp:
     39        (WebCore::ScriptElementData::notifyFinished):
     40        * page/PageGroupLoadDeferrer.cpp:
     41        (WebCore::PageGroupLoadDeferrer::PageGroupLoadDeferrer):
     42        (WebCore::PageGroupLoadDeferrer::~PageGroupLoadDeferrer):
     43
    1442010-08-06  James Robinson  <jamesr@chromium.org>
    245
  • trunk/WebCore/GNUmakefile.am

    r64865 r64873  
    970970        WebCore/dom/ActiveDOMObject.cpp \
    971971        WebCore/dom/ActiveDOMObject.h \
     972        WebCore/dom/AsyncScriptRunner.cpp \
     973        WebCore/dom/AsyncScriptRunner.h \
    972974        WebCore/dom/Attr.cpp \
    973975        WebCore/dom/Attr.h \
  • trunk/WebCore/WebCore.gypi

    r64870 r64873  
    10761076            'dom/ActiveDOMObject.cpp',
    10771077            'dom/ActiveDOMObject.h',
     1078            'dom/AsyncScriptRunner.cpp',
     1079            'dom/AsyncScriptRunner.h',
    10781080            'dom/Attr.cpp',
    10791081            'dom/Attr.h',
  • trunk/WebCore/WebCore.pro

    r64857 r64873  
    460460    css/WebKitCSSTransformValue.cpp \
    461461    dom/ActiveDOMObject.cpp \
     462    dom/AsyncScriptRunner.cpp \
    462463    dom/Attr.cpp \
    463464    dom/Attribute.cpp \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r64857 r64873  
    3253032530                        </File>
    3253132531                        <File
     32532                                RelativePath="..\dom\AsyncScriptRunner.cpp"
     32533                                >
     32534                        </File>
     32535                        <File
     32536                                RelativePath="..\dom\AsyncScriptRunner.h"
     32537                                >
     32538                        </File>
     32539                        <File
    3253232540                                RelativePath="..\dom\Attr.cpp"
    3253332541                                >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r64863 r64873  
    23572357                89CD029411C85B870070B791 /* JSBlobBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 89CD029211C85B870070B791 /* JSBlobBuilder.h */; };
    23582358                8A12E35D11FA33280025836A /* DocumentLoadTiming.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A12E35C11FA33280025836A /* DocumentLoadTiming.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2359                8A413AE01207BBA50082016E /* AsyncScriptRunner.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A413ADE1207BBA50082016E /* AsyncScriptRunner.h */; settings = {ATTRIBUTES = (Private, ); }; };
     2360                8A413AE11207BBA50082016E /* AsyncScriptRunner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A413ADF1207BBA50082016E /* AsyncScriptRunner.cpp */; };
    23592361                8A7CC96B12076D73001D4588 /* PendingScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A7CC96A12076D73001D4588 /* PendingScript.h */; settings = {ATTRIBUTES = (Private, ); }; };
    23602362                8A7CC97012076F8A001D4588 /* PendingScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A7CC96F12076F8A001D4588 /* PendingScript.cpp */; };
     
    81608162                89CD029211C85B870070B791 /* JSBlobBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSBlobBuilder.h; sourceTree = "<group>"; };
    81618163                8A12E35C11FA33280025836A /* DocumentLoadTiming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentLoadTiming.h; sourceTree = "<group>"; };
     8164                8A413ADE1207BBA50082016E /* AsyncScriptRunner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AsyncScriptRunner.h; sourceTree = "<group>"; };
     8165                8A413ADF1207BBA50082016E /* AsyncScriptRunner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AsyncScriptRunner.cpp; sourceTree = "<group>"; };
    81628166                8A7CC96A12076D73001D4588 /* PendingScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PendingScript.h; sourceTree = "<group>"; };
    81638167                8A7CC96F12076F8A001D4588 /* PendingScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PendingScript.cpp; sourceTree = "<group>"; };
     
    1708217086                                E1C4DE6D0EA75C650023CCD6 /* ActiveDOMObject.cpp */,
    1708317087                                E1C4DE680EA75C1E0023CCD6 /* ActiveDOMObject.h */,
     17088                                8A413ADE1207BBA50082016E /* AsyncScriptRunner.h */,
     17089                                8A413ADF1207BBA50082016E /* AsyncScriptRunner.cpp */,
    1708417090                                A8C4A7FC09D563270003AC8D /* Attr.cpp */,
    1708517091                                A8C4A7FB09D563270003AC8D /* Attr.h */,
     
    2008320089                                97DD4D870FDF4D6E00ECF9A4 /* XSSAuditor.h in Headers */,
    2008420090                                CE172E011136E8CE0062A533 /* ZoomMode.h in Headers */,
     20091                                8A413AE01207BBA50082016E /* AsyncScriptRunner.h in Headers */,
    2008520092                        );
    2008620093                        runOnlyForDeploymentPostprocessing = 0;
     
    2249922506                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
    2250022507                                97DD4D860FDF4D6E00ECF9A4 /* XSSAuditor.cpp in Sources */,
     22508                                8A413AE11207BBA50082016E /* AsyncScriptRunner.cpp in Sources */,
    2250122509                        );
    2250222510                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/dom/Document.cpp

    r64845 r64873  
    2929#include "AXObjectCache.h"
    3030#include "AnimationController.h"
     31#include "AsyncScriptRunner.h"
    3132#include "Attr.h"
    3233#include "Attribute.h"
     
    374375    , m_overMinimumLayoutThreshold(false)
    375376    , m_extraLayoutDelay(0)
    376     , m_executeScriptSoonTimer(this, &Document::executeScriptSoonTimerFired)
     377    , m_asyncScriptRunner(AsyncScriptRunner::create())
    377378    , m_xmlVersion("1.0")
    378379    , m_xmlStandalone(false)
     
    523524    ASSERT(!m_styleRecalcTimer.isActive());
    524525
    525     for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i)
    526         m_scriptsToExecuteSoon[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
     526    m_asyncScriptRunner.clear();
    527527
    528528    removeAllEventListeners();
     
    48324832}
    48334833
    4834 void Document::executeScriptSoonTimerFired(Timer<Document>* timer)
    4835 {
    4836     ASSERT_UNUSED(timer, timer == &m_executeScriptSoonTimer);
    4837 
    4838     Vector<pair<ScriptElementData*, CachedResourceHandle<CachedScript> > > scripts;
    4839     scripts.swap(m_scriptsToExecuteSoon);
    4840     size_t size = scripts.size();
    4841     for (size_t i = 0; i < size; ++i) {
    4842         scripts[i].first->execute(scripts[i].second.get());
    4843         scripts[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
    4844     }
    4845 }
    4846 
    4847 void Document::executeScriptSoon(ScriptElementData* data, CachedResourceHandle<CachedScript> cachedScript)
    4848 {
    4849     ASSERT_ARG(data, data);
    4850 
    4851     Element* element = data->element();
    4852     ASSERT(element);
    4853     ASSERT(element->document() == this);
    4854     ASSERT(element->inDocument());
    4855 
    4856     m_scriptsToExecuteSoon.append(make_pair(data, cachedScript));
    4857     element->ref(); // Balanced by deref()s in executeScriptSoonTimerFired() and ~Document().
    4858     if (!m_executeScriptSoonTimer.isActive())
    4859         m_executeScriptSoonTimer.startOneShot(0);
    4860 }
    4861 
    4862 void Document::suspendExecuteScriptSoonTimer()
    4863 {
    4864     m_executeScriptSoonTimer.stop();
    4865 }
    4866 
    4867 void Document::resumeExecuteScriptSoonTimer()
    4868 {
    4869     if (!m_scriptsToExecuteSoon.isEmpty())
    4870         m_executeScriptSoonTimer.startOneShot(0);
    4871 }
    4872 
    48734834// FF method for accessing the selection added for compatibility.
    48744835DOMSelection* Document::getSelection() const
  • trunk/WebCore/dom/Document.h

    r64272 r64873  
    4949namespace WebCore {
    5050
     51    class AsyncScriptRunner;
    5152    class Attr;
    5253    class AXObjectCache;
     
    842843
    843844    int docID() const { return m_docID; }
    844 
    845     void executeScriptSoon(ScriptElementData*, CachedResourceHandle<CachedScript>);
    846 
    847     void suspendExecuteScriptSoonTimer();
    848     void resumeExecuteScriptSoonTimer();
     845   
     846    AsyncScriptRunner* asyncScriptRunner() { return m_asyncScriptRunner.get(); }
    849847
    850848#if ENABLE(XSLT)
     
    10501048
    10511049    String encoding() const;
    1052 
    1053     void executeScriptSoonTimerFired(Timer<Document>*);
    10541050
    10551051    void updateTitle();
     
    12021198    // points during the lifetime of the Document.
    12031199    int m_extraLayoutDelay;
    1204 
    1205     Vector<std::pair<ScriptElementData*, CachedResourceHandle<CachedScript> > > m_scriptsToExecuteSoon;
    1206     Timer<Document> m_executeScriptSoonTimer;
    1207    
     1200   
     1201    OwnPtr<AsyncScriptRunner> m_asyncScriptRunner;
     1202
    12081203#if ENABLE(XSLT)
    12091204    OwnPtr<TransformSource> m_transformSource;
  • trunk/WebCore/dom/ScriptElement.cpp

    r63998 r64873  
    2525#include "ScriptElement.h"
    2626
     27#include "AsyncScriptRunner.h"
    2728#include "CachedScript.h"
    2829#include "DocLoader.h"
     
    247248{
    248249    ASSERT_UNUSED(o, o == m_cachedScript);
    249     m_element->document()->executeScriptSoon(this, m_cachedScript);
     250    m_element->document()->asyncScriptRunner()->executeScriptSoon(this, m_cachedScript);
    250251    m_cachedScript = 0;
    251252}
  • trunk/WebCore/page/PageGroupLoadDeferrer.cpp

    r63080 r64873  
    2222#include "PageGroupLoadDeferrer.h"
    2323
     24#include "AsyncScriptRunner.h"
    2425#include "Frame.h"
    2526#include "Page.h"
     
    4647            for (Frame* frame = otherPage->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
    4748                frame->document()->suspendActiveDOMObjects();
    48                 frame->document()->suspendExecuteScriptSoonTimer();
     49                frame->document()->asyncScriptRunner()->suspend();
    4950            }
    5051        }
     
    6566            for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
    6667                frame->document()->resumeActiveDOMObjects();
    67                 frame->document()->resumeExecuteScriptSoonTimer();
     68                frame->document()->asyncScriptRunner()->resume();
    6869            }
    6970        }
Note: See TracChangeset for help on using the changeset viewer.