예제 #1
0
void ScriptRunner::executeScripts()
{
    RefPtrWillBeRawPtr<Document> protect(m_document.get());

    WillBeHeapDeque<RawPtrWillBeMember<ScriptLoader>> scriptLoaders;
    scriptLoaders.swap(m_scriptsToExecuteSoon);

    WillBeHeapHashSet<RawPtrWillBeMember<ScriptLoader>> inorderSet;
    while (!m_scriptsToExecuteInOrder.isEmpty() && m_scriptsToExecuteInOrder.first()->isReady()) {
        ScriptLoader* script = m_scriptsToExecuteInOrder.takeFirst();
        inorderSet.add(script);
        scriptLoaders.append(script);
    }

    while (!scriptLoaders.isEmpty()) {
        scriptLoaders.takeFirst()->execute();
        m_document->decrementLoadEventDelayCount();

        if (yieldForHighPriorityWork())
            break;
    }

    // If we have to yield, we must re-enqueue any scriptLoaders back onto the front of
    // m_scriptsToExecuteInOrder or m_scriptsToExecuteSoon depending on where the script
    // came from.
    // NOTE a yield followed by a notifyScriptReady(... ASYNC_EXECUTION) will result in that script executing
    // before any pre-existing ScriptsToExecuteInOrder.
    while (!scriptLoaders.isEmpty()) {
        ScriptLoader* script = scriptLoaders.takeLast();
        if (inorderSet.contains(script))
            m_scriptsToExecuteInOrder.prepend(script);
        else
            m_scriptsToExecuteSoon.prepend(script);
    }
}
void FullscreenElementStack::fullScreenChangeDelayTimerFired(Timer<FullscreenElementStack>*)
{
    // Since we dispatch events in this function, it's possible that the
    // document will be detached and GC'd. We protect it here to make sure we
    // can finish the function successfully.
    RefPtrWillBeRawPtr<Document> protectDocument(document());
    WillBeHeapDeque<RefPtrWillBeMember<Node> > changeQueue;
    m_fullScreenChangeEventTargetQueue.swap(changeQueue);
    WillBeHeapDeque<RefPtrWillBeMember<Node> > errorQueue;
    m_fullScreenErrorEventTargetQueue.swap(errorQueue);

    while (!changeQueue.isEmpty()) {
        RefPtrWillBeRawPtr<Node> node = changeQueue.takeFirst();
        if (!node)
            node = document()->documentElement();
        // The dispatchEvent below may have blown away our documentElement.
        if (!node)
            continue;

        // If the element was removed from our tree, also message the documentElement. Since we may
        // have a document hierarchy, check that node isn't in another document.
        if (!document()->contains(node.get()) && !node->inDocument())
            changeQueue.append(document()->documentElement());

        node->dispatchEvent(Event::createBubble(EventTypeNames::webkitfullscreenchange));
    }

    while (!errorQueue.isEmpty()) {
        RefPtrWillBeRawPtr<Node> node = errorQueue.takeFirst();
        if (!node)
            node = document()->documentElement();
        // The dispatchEvent below may have blown away our documentElement.
        if (!node)
            continue;

        // If the element was removed from our tree, also message the documentElement. Since we may
        // have a document hierarchy, check that node isn't in another document.
        if (!document()->contains(node.get()) && !node->inDocument())
            errorQueue.append(document()->documentElement());

        node->dispatchEvent(Event::createBubble(EventTypeNames::webkitfullscreenerror));
    }
}
예제 #3
0
void Fullscreen::eventQueueTimerFired(Timer<Fullscreen>*)
{
    // Since we dispatch events in this function, it's possible that the
    // document will be detached and GC'd. We protect it here to make sure we
    // can finish the function successfully.
    RefPtrWillBeRawPtr<Document> protectDocument(document());
    WillBeHeapDeque<RefPtrWillBeMember<Event> > eventQueue;
    m_eventQueue.swap(eventQueue);

    while (!eventQueue.isEmpty()) {
        RefPtrWillBeRawPtr<Event> event = eventQueue.takeFirst();
        Node* target = event->target()->toNode();

        // If the element was removed from our tree, also message the documentElement.
        if (!target->inDocument() && document()->documentElement()) {
            ASSERT(isPrefixed(event->type()));
            eventQueue.append(createEvent(event->type(), *document()->documentElement()));
        }

        target->dispatchEvent(event);
    }
}
예제 #4
0
void WebSocket::EventQueue::dispatchQueuedEvents()
{
    if (m_state != Active)
        return;

    RefPtrWillBeRawPtr<EventQueue> protect(this);

    WillBeHeapDeque<RefPtrWillBeMember<Event> > events;
    events.swap(m_events);
    while (!events.isEmpty()) {
        if (m_state == Stopped || m_state == Suspended)
            break;
        ASSERT(m_state == Active);
        ASSERT(m_target->executionContext());
        m_target->dispatchEvent(events.takeFirst());
        // |this| can be stopped here.
    }
    if (m_state == Suspended) {
        while (!m_events.isEmpty())
            events.append(m_events.takeFirst());
        events.swap(m_events);
    }
}