Example #1
0
void checkTextOfParagraph(TextCheckerClient* client, const UChar* text, int length,
                          TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
{
#if USE(UNIFIED_TEXT_CHECKING)
    client->checkTextOfParagraph(text, length, checkingTypes, results);
#else
    Vector<TextCheckingResult> spellingResult;
    if (checkingTypes & TextCheckingTypeSpelling)
        findMisspellings(client, text, 0, length, spellingResult);

#if USE(GRAMMAR_CHECKING)
    Vector<TextCheckingResult> grammarResult;
    if (checkingTypes & TextCheckingTypeGrammar) {
        // Only checks grammartical error before the first misspellings
        int grammarCheckLength = length;
        for (size_t i = 0; i < spellingResult.size(); ++i) {
            if (spellingResult[i].location < grammarCheckLength)
                grammarCheckLength = spellingResult[i].location;
        }

        findBadGrammars(client, text, 0, grammarCheckLength, grammarResult);
    }

    if (grammarResult.size())
        results.swap(grammarResult);
#endif

    if (spellingResult.size()) {
        if (results.isEmpty())
            results.swap(spellingResult);
        else
            results.appendVector(spellingResult);
    }
#endif
}
void checkTextOfParagraph(TextCheckerClient& client, const String& text, TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results)
{
    Vector<UChar> characters;
    text.appendTo(characters);
    unsigned length = text.length();

    Vector<TextCheckingResult> spellingResult;
    if (checkingTypes & TextCheckingTypeSpelling)
        findMisspellings(client, characters.data(), 0, length, spellingResult);

    Vector<TextCheckingResult> grammarResult;
    if (checkingTypes & TextCheckingTypeGrammar) {
        // Only checks grammartical error before the first misspellings
        int grammarCheckLength = length;
        for (const auto& spelling : spellingResult) {
            if (spelling.location < grammarCheckLength)
                grammarCheckLength = spelling.location;
        }

        findBadGrammars(client, characters.data(), 0, grammarCheckLength, grammarResult);
    }

    if (grammarResult.size())
        results.swap(grammarResult);

    if (spellingResult.size()) {
        if (results.isEmpty())
            results.swap(spellingResult);
        else
            results.appendVector(spellingResult);
    }
}
Example #3
0
void ShortReferenceMap::setNameMap(Vector<StringC> &map)
{
  map.swap(nameMap_);
  // Make sure we know it's defined.
  if (nameMap_.size() == 0)
    nameMap_.resize(1);
}
Example #4
0
void ImageEventSender::dispatchPendingEvents()
{
    // Need to avoid re-entering this function; if new dispatches are
    // scheduled before the parent finishes processing the list, they
    // will set a timer and eventually be processed.
    if (!m_dispatchingList.isEmpty())
        return;

    m_timer.stop();

    m_dispatchSoonList.checkConsistency();

    m_dispatchingList.swap(m_dispatchSoonList);
    size_t size = m_dispatchingList.size();
    for (size_t i = 0; i < size; ++i) {
        if (ImageLoader* loader = m_dispatchingList[i]) {
            m_dispatchingList[i] = 0;
            if (m_eventType == eventNames().beforeloadEvent)
                loader->dispatchPendingBeforeLoadEvent();
            else
                loader->dispatchPendingLoadEvent();
        }
    }
    m_dispatchingList.clear();
}
Example #5
0
void ScriptRunner::timerFired(Timer<ScriptRunner>* timer)
{
	ActionLogScope log_scope("script runner timer");
    ASSERT_UNUSED(timer, timer == &m_timer);

    RefPtr<Document> protect(m_document);

    Vector<PendingScript> scripts;
    scripts.swap(m_scriptsToExecuteSoon);

    size_t numInOrderScriptsToExecute = 0;
    for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_scriptsToExecuteInOrder[numInOrderScriptsToExecute].cachedScript()->isLoaded(); ++numInOrderScriptsToExecute)
        scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]);
    if (numInOrderScriptsToExecute)
        m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute);

    size_t size = scripts.size();
    for (size_t i = 0; i < size; ++i) {
        CachedScript* cachedScript = scripts[i].cachedScript();
        RefPtr<Element> element = scripts[i].releaseElementAndClear();
        ScriptElement* script = toScriptElement(element.get());
        ActionLogFormat(ActionLog::READ_MEMORY, "ScriptRunner-%p-%p",
        		static_cast<void*>(this), static_cast<void*>(script));
        script->execute(cachedScript);
        m_document->decrementLoadEventDelayCount();
    }
}
void V8PerIsolateData::runEndOfScopeTasks()
{
    Vector<OwnPtr<EndOfScopeTask>> tasks;
    tasks.swap(m_endOfScopeTasks);
    for (const auto& task : tasks)
        task->run();
    ASSERT(m_endOfScopeTasks.isEmpty());
}
void MediaStream::activityEventTimerFired()
{
    Vector<Ref<Event>> events;
    events.swap(m_scheduledActivityEvents);

    for (auto& event : events)
        dispatchEvent(event);
}
Example #8
0
Vector<PaintChunk> PaintChunker::releasePaintChunks() {
  Vector<PaintChunk> chunks;
  chunks.swap(m_chunks);
  m_chunkBehavior.clear();
  m_currentChunkId = WTF::nullopt;
  m_currentProperties = PaintChunkProperties();
  return chunks;
}
ComplexTextController::ComplexTextRun::ComplexTextRun(ATSUTextLayout atsuTextLayout, const SimpleFontData* fontData, const UChar* characters, unsigned stringLocation, size_t stringLength, bool ltr, bool directionalOverride)
    : m_fontData(fontData)
    , m_characters(characters)
    , m_stringLocation(stringLocation)
    , m_stringLength(stringLength)
    , m_indexEnd(stringLength)
    , m_directionalOverride(directionalOverride)
    , m_isMonotonic(true)
{
    OSStatus status;

    status = ATSUSetTextLayoutRefCon(atsuTextLayout, reinterpret_cast<URefCon>(this));

    ATSLineLayoutOptions lineLayoutOptions = kATSLineKeepSpacesOutOfMargin | kATSLineHasNoHangers;

    Boolean rtl = !ltr;

    Vector<UChar, 256> substituteCharacters;
    bool shouldCheckForMirroring = !ltr && !fontData->m_ATSUMirrors;
    bool shouldCheckForArabic = !fontData->shapesArabic();
    bool shouldShapeArabic = false;

    bool mirrored = false;
    for (size_t i = 0; i < stringLength; ++i) {
        if (shouldCheckForMirroring) {
            UChar mirroredChar = u_charMirror(characters[i]);
            if (mirroredChar != characters[i]) {
                if (!mirrored) {
                    mirrored = true;
                    substituteCharacters.grow(stringLength);
                    memcpy(substituteCharacters.data(), characters, stringLength * sizeof(UChar));
                    ATSUTextMoved(atsuTextLayout, substituteCharacters.data());
                }
                substituteCharacters[i] = mirroredChar;
            }
        }
        if (shouldCheckForArabic && isArabicChar(characters[i])) {
            shouldCheckForArabic = false;
            shouldShapeArabic = true;
        }
    }

    if (shouldShapeArabic) {
        Vector<UChar, 256> shapedArabic(stringLength);
        shapeArabic(substituteCharacters.isEmpty() ? characters : substituteCharacters.data(), shapedArabic.data(), stringLength);
        substituteCharacters.swap(shapedArabic);
        ATSUTextMoved(atsuTextLayout, substituteCharacters.data());
    }

    if (directionalOverride) {
        UChar override = ltr ? leftToRightOverride : rightToLeftOverride;
        if (substituteCharacters.isEmpty()) {
            substituteCharacters.grow(stringLength + 2);
            substituteCharacters[0] = override;
            memcpy(substituteCharacters.data() + 1, characters, stringLength * sizeof(UChar));
            substituteCharacters[stringLength + 1] = popDirectionalFormatting;
            ATSUTextMoved(atsuTextLayout, substituteCharacters.data());
        } else {
void CookieDatabaseBackingStore::getCookiesFromDatabase(Vector<ParsedCookie*>& stackOfCookies, unsigned int limit)
{
    // It is not a huge performance hit to wait on the reply here because this is only done once during setup and when turning off private mode.
    TypedReplyBuffer< Vector<ParsedCookie*>* > replyBuffer(0);
    dispatchMessage(createMethodCallMessageWithReturn(&CookieDatabaseBackingStore::invokeGetCookiesWithLimit, &replyBuffer, this, limit));
    Vector<ParsedCookie*>* cookies = replyBuffer.pointer();
    stackOfCookies.swap(*cookies);
    delete cookies;
}
Example #11
0
void MutationObserver::notifyMutationObservers()
{
    // https://dom.spec.whatwg.org/#notify-mutation-observers
    // 1. Unset mutation observer compound microtask queued flag.
    mutationObserverCompoundMicrotaskQueuedFlag = false;

    ASSERT(isMainThread());
    static bool deliveryInProgress = false;
    if (deliveryInProgress)
        return;
    deliveryInProgress = true;

    if (!suspendedMutationObservers().isEmpty()) {
        Vector<RefPtr<MutationObserver>> suspended;
        copyToVector(suspendedMutationObservers(), suspended);
        for (auto& observer : suspended) {
            if (!observer->canDeliver())
                continue;

            suspendedMutationObservers().remove(observer);
            activeMutationObservers().add(observer);
        }
    }

    while (!activeMutationObservers().isEmpty() || !signalSlotList().isEmpty()) {
        // 2. Let notify list be a copy of unit of related similar-origin browsing contexts' list of MutationObserver objects.
        Vector<RefPtr<MutationObserver>> notifyList;
        copyToVector(activeMutationObservers(), notifyList);
        activeMutationObservers().clear();
        std::sort(notifyList.begin(), notifyList.end(), [](auto& lhs, auto& rhs) {
            return lhs->m_priority < rhs->m_priority;
        });

        // 3. Let signalList be a copy of unit of related similar-origin browsing contexts' signal slot list.
        // 4. Empty unit of related similar-origin browsing contexts' signal slot list.
        Vector<RefPtr<HTMLSlotElement>> slotList;
        if (!signalSlotList().isEmpty()) {
            slotList.swap(signalSlotList());
            for (auto& slot : slotList)
                slot->didRemoveFromSignalSlotList();
        }

        // 5. For each MutationObserver object mo in notify list, execute a compound microtask subtask
        for (auto& observer : notifyList) {
            if (observer->canDeliver())
                observer->deliver();
            else
                suspendedMutationObservers().add(observer);
        }

        // 6. For each slot slot in signalList, in order, fire an event named slotchange, with its bubbles attribute set to true, at slot.
        for (auto& slot : slotList)
            slot->dispatchSlotChangeEvent();
    }

    deliveryInProgress = false;
}
Example #12
0
void MediaStream::scheduledEventTimerFired()
{
    Vector<RefPtr<Event>> events;
    events.swap(m_scheduledEvents);

    for (auto it = events.begin(), end = events.end(); it != end; ++it)
        dispatchEvent((*it).release());

    events.clear();
}
Example #13
0
void RTCDataChannel::scheduledEventTimerFired()
{
    if (m_stopped)
        return;

    Vector<RefPtr<Event>> events;
    events.swap(m_scheduledEvents);

    for (auto& event : events)
        dispatchEvent(event.release());
}
Example #14
0
void WebGeolocationServiceMockImpl::notifyPendingPermissions()
{
    ASSERT(s_permissionState == PermissionStateAllowed || s_permissionState ==  PermissionStateDenied);
    Vector<int> pendingPermissionRequests;
    pendingPermissionRequests.swap(m_pendingPermissionRequests);
    for (Vector<int>::const_iterator it = pendingPermissionRequests.begin(); it != pendingPermissionRequests.end(); ++it) {
        ASSERT(*it > 0);
        IdToBridgeMap::iterator iter = m_idToBridgeMap.find(*it);
        if (iter != m_idToBridgeMap.end())
            iter->second->setIsAllowed(s_permissionState == PermissionStateAllowed);
    }
}
void MyWebFrame::timerFired(Timer<MyWebFrame>*)
{
    LOGD("Handling requests...");
    Vector<RefPtr<WebCore::ResourceLoaderAndroid> > reqs;
    reqs.swap(m_requests);
    Vector<RefPtr<WebCore::ResourceLoaderAndroid> >::iterator i = reqs.begin();
    Vector<RefPtr<WebCore::ResourceLoaderAndroid> >::iterator end = reqs.end();
    for (; i != end; i++)
        static_cast<MyResourceLoader*>((*i).get())->handleRequest();

    LOGD("...done");
}
Example #16
0
void RTCDTMFSender::scheduledEventTimerFired(Timer<RTCDTMFSender>*)
{
    if (m_stopped)
        return;

    Vector<RefPtr<Event>> events;
    events.swap(m_scheduledEvents);

    Vector<RefPtr<Event>>::iterator it = events.begin();
    for (; it != events.end(); ++it)
        dispatchEvent((*it).release());
}
// Called in the WebCore thread
void WebIconDatabase::deliverNotifications()
{
    ASSERT(mDeliveryRequested);

    // Swap the notifications queue
    Vector<WTF::String> queue;
    mNotificationsMutex.lock();
    queue.swap(mNotifications);
    mDeliveryRequested = false;
    mNotificationsMutex.unlock();

    // Swap the clients queue
    Vector<WebIconDatabaseClient*> clients;
    clients.swap(mClients);

    for (unsigned i = 0; i < queue.size(); ++i) {
        for (unsigned j = 0; j < clients.size(); ++j) {
            clients[j]->didAddIconForPageUrl(queue[i]);
        }
    }
}
Example #18
0
void FontLoader::loadPendingFonts()
{
    ASSERT(m_resourceFetcher);

    Vector<ResourcePtr<FontResource> > fontsToBeginLoading;
    fontsToBeginLoading.swap(m_fontsToBeginLoading);

    for (size_t i = 0; i < fontsToBeginLoading.size(); ++i) {
        fontsToBeginLoading[i]->beginLoadIfNeeded(m_resourceFetcher);
        // Balances incrementRequestCount() in beginLoadingFontSoon().
        m_resourceFetcher->decrementRequestCount(fontsToBeginLoading[i].get());
    }
}
inline void CustomElementReactionStack::ElementQueue::invokeAll()
{
    RELEASE_ASSERT(!m_invoking);
    SetForScope<bool> invoking(m_invoking, true);
    Vector<Ref<Element>> elements;
    elements.swap(m_elements);
    RELEASE_ASSERT(m_elements.isEmpty());
    for (auto& element : elements) {
        auto* queue = element->reactionQueue();
        ASSERT(queue);
        queue->invokeAll(element.get());
    }
    RELEASE_ASSERT(m_elements.isEmpty());
}
Example #20
0
void CSSFontSelector::beginLoadTimerFired(Timer<WebCore::CSSFontSelector>*)
{
    Vector<CachedResourceHandle<CachedFont> > fontsToBeginLoading;
    fontsToBeginLoading.swap(m_fontsToBeginLoading);

    CachedResourceLoader* cachedResourceLoader = m_document->cachedResourceLoader();
    for (size_t i = 0; i < fontsToBeginLoading.size(); ++i) {
        fontsToBeginLoading[i]->beginLoadIfNeeded(cachedResourceLoader);
        // Balances incrementRequestCount() in beginLoadingFontSoon().
        cachedResourceLoader->decrementRequestCount(fontsToBeginLoading[i].get());
    }
    // Ensure that if the request count reaches zero, the frame loader will know about it.
    cachedResourceLoader->loadDone();
}
Example #21
0
void RTCPeerConnection::dispatchScheduledEvent()
{
    if (m_stopped)
        return;

    Vector<RefPtr<Event> > events;
    events.swap(m_scheduledEvents);

    Vector<RefPtr<Event> >::iterator it = events.begin();
    for (; it != events.end(); ++it)
        dispatchEvent((*it).release());

    events.clear();
}
Example #22
0
void MediaStream::scheduledEventTimerFired(Timer<MediaStream>*)
{
    if (m_stopped)
        return;

    Vector<RefPtr<Event> > events;
    events.swap(m_scheduledEvents);

    Vector<RefPtr<Event> >::iterator it = events.begin();
    for (; it != events.end(); ++it)
        dispatchEvent((*it).release());

    events.clear();
}
Example #23
0
void ThreadableWebSocketChannelClientWrapper::processPendingTasks()
{
    if (m_suspended)
        return;
    if (!m_syncMethodDone) {
        // When a synchronous operation is in progress (i.e. the execution stack contains
        // WorkerThreadableWebSocketChannel::waitForMethodCompletion()), we cannot invoke callbacks in this run loop.
        m_context->postTask(createCallbackTask(&ThreadableWebSocketChannelClientWrapper::processPendingTasksCallback, this));
        return;
    }
    Vector<OwnPtr<ScriptExecutionContext::Task> > tasks;
    tasks.swap(m_pendingTasks);
    for (Vector<OwnPtr<ScriptExecutionContext::Task> >::const_iterator iter = tasks.begin(); iter != tasks.end(); ++iter)
        (*iter)->performTask(0);
}
Example #24
0
void AsyncScriptRunner::timerFired(Timer<AsyncScriptRunner>* timer)
{
    ASSERT_UNUSED(timer, timer == &m_timer);

    RefPtr<Document> protect(m_document);
    
    Vector<pair<ScriptElementData*, CachedResourceHandle<CachedScript> > > scripts;
    scripts.swap(m_scriptsToExecuteSoon);
    size_t size = scripts.size();
    for (size_t i = 0; i < size; ++i) {
        scripts[i].first->execute(scripts[i].second.get());
        scripts[i].first->element()->deref(); // Balances ref() in executeScriptSoon().
        m_document->decrementLoadEventDelayCount();
    }
}
Example #25
0
void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data)
{
    LOG(Network, "ResourceHandle::platformLoadResourceSynchronously:%s allowStoredCredentials:%u", request.url().string().utf8().data(), storedCredentials);

    ASSERT(!request.isEmpty());

    ASSERT(response.isNull());
    ASSERT(error.isNull());

    OwnPtr<SynchronousLoaderClient> client = SynchronousLoaderClient::create();
    client->setAllowStoredCredentials(storedCredentials == AllowStoredCredentials);

    RefPtr<ResourceHandle> handle = adoptRef(new ResourceHandle(context, request, client.get(), false /*defersLoading*/, true /*shouldContentSniff*/));

    handle->d->m_storageSession = context->storageSession().platformSession();

    if (handle->d->m_scheduledFailureType != NoFailure) {
        error = context->blockedError(request);
        return;
    }

    handle->createCFURLConnection(storedCredentials == AllowStoredCredentials, ResourceHandle::shouldContentSniffURL(request.url()),
                                  SchedulingBehavior::Synchronous, handle->client()->connectionProperties(handle.get()).get());

    CFURLConnectionScheduleWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode());
    CFURLConnectionScheduleDownloadWithRunLoop(handle->connection(), CFRunLoopGetCurrent(), synchronousLoadRunLoopMode());
    CFURLConnectionStart(handle->connection());

    while (!client->isDone())
        CFRunLoopRunInMode(synchronousLoadRunLoopMode(), UINT_MAX, true);

    error = client->error();

    CFURLConnectionCancel(handle->connection());

    if (error.isNull())
        response = client->response();
    else {
        response = ResourceResponse(request.url(), String(), 0, String(), String());
        // FIXME: ResourceHandleMac also handles authentication errors by setting code to 401. CFNet version should probably do the same.
        if (error.domain() == String(kCFErrorDomainCFNetwork))
            response.setHTTPStatusCode(error.errorCode());
        else
            response.setHTTPStatusCode(404);
    }

    data.swap(client->mutableData());
}
void AsyncScriptRunner::timerFired(Timer<AsyncScriptRunner>* timer)
{
    ASSERT_UNUSED(timer, timer == &m_timer);

    RefPtr<Document> protect(m_document);
    
    Vector<PendingScript> scripts;
    scripts.swap(m_scriptsToExecuteSoon);
    size_t size = scripts.size();
    for (size_t i = 0; i < size; ++i) {
        CachedScript* cachedScript = scripts[i].cachedScript();
        RefPtr<Element> element = scripts[i].releaseElementAndClear();
        toScriptElement(element.get())->execute(cachedScript);
        m_document->decrementLoadEventDelayCount();
    }
}
void CoordinatedGraphicsScene::syncRemoteContent()
{
    // We enqueue messages and execute them during paint, as they require an active GL context.
    ensureRootLayer();

    Vector<Function<void()> > renderQueue;
    bool calledOnMainThread = WTF::isMainThread();
    if (!calledOnMainThread)
        m_renderQueueMutex.lock();
    renderQueue.swap(m_renderQueue);
    if (!calledOnMainThread)
        m_renderQueueMutex.unlock();

    for (size_t i = 0; i < renderQueue.size(); ++i)
        renderQueue[i]();
}
Example #28
0
void MediaStreamTrack::dispatchQueuedEvents()
{
    Vector<RefPtr<Event>> events;
    {
        MutexLocker locker(m_mutex);
        m_eventDispatchScheduled = false;
        events.swap(m_scheduledEvents);
    }
    if (!scriptExecutionContext())
        return;

    for (auto it = events.begin(); it != events.end(); ++it)
        dispatchEvent((*it).release());

    events.clear();
}
void ScriptedAnimationController::dispatchEvents()
{
    Vector<RefPtr<Event> > events;
    events.swap(m_eventQueue);
    m_perFrameEvents.clear();

    for (size_t i = 0; i < events.size(); ++i) {
        EventTarget* eventTarget = events[i]->target();
        // FIXME: we should figure out how to make dispatchEvent properly virtual to avoid
        // special casting window.
        // FIXME: We should not fire events for nodes that are no longer in the tree.
        if (LocalDOMWindow* window = eventTarget->toDOMWindow())
            window->dispatchEvent(events[i], nullptr);
        else
            eventTarget->dispatchEvent(events[i]);
    }
}
Example #30
0
S32 NetworkStream::Read(Vector<Byte>& _vBuffer_, S32 _iOffset, S32 _iSize)
{
	if (_iOffset < 0) {
		throw std::out_of_range("_iOffset is less than 0");
	} else if (_iOffset > (S32)_vBuffer_.size()) {
		throw std::out_of_range("_iOffset is greater than the length of _vBuffer_");
	} else if (_iSize < 0) {
		throw std::out_of_range("_iSize is less than 0");
	} else if (_iSize > (S32)_vBuffer_.size() - _iOffset) {
		throw std::out_of_range("_iSize is greater than the length of _vBuffer_ minus the value of the _iOffset parameter");
	}

	Vector<Byte> vBuffer(_vBuffer_.data() + _iOffset, _vBuffer_.data() + _iOffset + _iSize);
	S32 iResult = m_pSocket->Receive(vBuffer);
	_vBuffer_.swap(vBuffer);
	return iResult;
}