Exemplo n.º 1
0
bool CppVariant::invokeDefault(const CppVariant* arguments, uint32_t argumentCount,
                               CppVariant& result) const
{
    WEBKIT_ASSERT(isObject());
    NPObject* npObject = value.objectValue;
    NPVariant r;
    bool status = WebBindings::invokeDefault(0, npObject, arguments, argumentCount, &r);
    result.set(r);
    return status;
}
Exemplo n.º 2
0
void TestPlugin::drawPrimitive()
{
    WEBKIT_ASSERT(m_scene.primitive == PrimitiveTriangle);
    WEBKIT_ASSERT(m_scene.vbo);
    WEBKIT_ASSERT(m_scene.program);

    m_context->useProgram(m_scene.program);

    // Bind primitive color.
    float color[4];
    premultiplyAlpha(m_scene.primitiveColor, m_scene.opacity, color);
    m_context->uniform4f(m_scene.colorLocation, color[0], color[1], color[2], color[3]);

    // Bind primitive vertices.
    m_context->bindBuffer(GL_ARRAY_BUFFER, m_scene.vbo);
    m_context->enableVertexAttribArray(m_scene.positionLocation);
    m_context->vertexAttribPointer(m_scene.positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
    m_context->drawArrays(GL_TRIANGLES, 0, 3);
}
WebFilterOperation::WebFilterOperation(FilterType type, SkScalar matrix[20])
    : m_type(type)
    , m_amount(0)
    , m_dropShadowOffset(0, 0)
    , m_dropShadowColor(0)
    , m_zoomInset(0)
{
    WEBKIT_ASSERT(m_type == FilterTypeColorMatrix);
    memcpy(m_matrix, matrix, sizeof(m_matrix));
}
Exemplo n.º 4
0
bool CppVariant::invoke(const string& method, const CppVariant* arguments,
                        uint32_t argumentCount, CppVariant& result) const
{
    WEBKIT_ASSERT(isObject());
    NPIdentifier methodName = WebBindings::getStringIdentifier(method.c_str());
    NPObject* npObject = value.objectValue;
    if (!WebBindings::hasMethod(0, npObject, methodName))
        return false;
    NPVariant r;
    bool status = WebBindings::invoke(0, npObject, methodName, arguments, argumentCount, &r);
    result.set(r);
    return status;
}
CppVariant* CppBoundClass::getAsCppVariant()
{
    if (!m_selfVariant.isObject()) {
        // Create an NPObject using our static NPClass. The first argument (a
        // plugin's instance handle) is passed through to the allocate function
        // directly, and we don't use it, so it's ok to be 0.
        NPObject* npObj = WebBindings::createObject(0, &CppNPObject::npClass);
        CppNPObject* obj = reinterpret_cast<CppNPObject*>(npObj);
        obj->boundClass = this;
        m_selfVariant.set(npObj);
        WebBindings::releaseObject(npObj); // CppVariant takes the reference.
    }
    WEBKIT_ASSERT(m_selfVariant.isObject());
    return &m_selfVariant;
}
Exemplo n.º 6
0
TestPlugin::TestPlugin(WebFrame* frame, const WebPluginParams& params, WebTestDelegate* delegate)
    : m_frame(frame)
    , m_delegate(delegate)
    , m_container(0)
    , m_context(0)
    , m_touchEventRequest(WebPluginContainer::TouchEventRequestTypeNone)
    , m_reRequestTouchEvents(false)
    , m_printEventDetails(false)
    , m_printUserGestureStatus(false)
    , m_canProcessDrag(false)
{
    static const WebString kAttributePrimitive = WebString::fromUTF8("primitive");
    static const WebString kAttributeBackgroundColor = WebString::fromUTF8("background-color");
    static const WebString kAttributePrimitiveColor = WebString::fromUTF8("primitive-color");
    static const WebString kAttributeOpacity = WebString::fromUTF8("opacity");
    static const WebString kAttributeAcceptsTouch = WebString::fromUTF8("accepts-touch");
    static const WebString kAttributeReRequestTouchEvents = WebString::fromUTF8("re-request-touch");
    static const WebString kAttributePrintEventDetails = WebString::fromUTF8("print-event-details");
    static const WebString kAttributeCanProcessDrag = WebString::fromUTF8("can-process-drag");
    static const WebString kAttributePrintUserGestureStatus = WebString::fromUTF8("print-user-gesture-status");

    WEBKIT_ASSERT(params.attributeNames.size() == params.attributeValues.size());
    size_t size = params.attributeNames.size();
    for (size_t i = 0; i < size; ++i) {
        const WebString& attributeName = params.attributeNames[i];
        const WebString& attributeValue = params.attributeValues[i];

        if (attributeName == kAttributePrimitive)
            m_scene.primitive = parsePrimitive(attributeValue);
        else if (attributeName == kAttributeBackgroundColor)
            parseColor(attributeValue, m_scene.backgroundColor);
        else if (attributeName == kAttributePrimitiveColor)
            parseColor(attributeValue, m_scene.primitiveColor);
        else if (attributeName == kAttributeOpacity)
            m_scene.opacity = parseOpacity(attributeValue);
        else if (attributeName == kAttributeAcceptsTouch)
            m_touchEventRequest = parseTouchEventRequestType(attributeValue);
        else if (attributeName == kAttributeReRequestTouchEvents)
            m_reRequestTouchEvents = parseBoolean(attributeValue);
        else if (attributeName == kAttributePrintEventDetails)
            m_printEventDetails = parseBoolean(attributeValue);
        else if (attributeName == kAttributeCanProcessDrag)
            m_canProcessDrag = parseBoolean(attributeValue);
        else if (attributeName == kAttributePrintUserGestureStatus)
            m_printUserGestureStatus = parseBoolean(attributeValue);
    }
}
Exemplo n.º 7
0
bool TestPlugin::initPrimitive()
{
    WEBKIT_ASSERT(m_scene.primitive == PrimitiveTriangle);

    m_scene.vbo = m_context->createBuffer();
    if (!m_scene.vbo)
        return false;

    const float vertices[] = {
        0.0f,  0.8f, 0.0f,
        -0.8f, -0.8f, 0.0f,
        0.8f, -0.8f, 0.0f };
    m_context->bindBuffer(GL_ARRAY_BUFFER, m_scene.vbo);
    m_context->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW);
    m_context->bufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
    return true;
}
Exemplo n.º 8
0
vector<string> CppVariant::toStringVector() const
{

    WEBKIT_ASSERT(isObject());
    vector<string> stringVector;
    NPObject* npValue = value.objectValue;
    NPIdentifier lengthId = WebBindings::getStringIdentifier("length");

    if (!WebBindings::hasProperty(0, npValue, lengthId))
        return stringVector;

    NPVariant lengthValue;
    if (!WebBindings::getProperty(0, npValue, lengthId, &lengthValue))
        return stringVector;

    int length = 0;
    // The length is a double in some cases.
    if (NPVARIANT_IS_DOUBLE(lengthValue))
        length = static_cast<int>(NPVARIANT_TO_DOUBLE(lengthValue));
    else if (NPVARIANT_IS_INT32(lengthValue))
        length = NPVARIANT_TO_INT32(lengthValue);
    WebBindings::releaseVariantValue(&lengthValue);

    // For sanity, only allow 100 items.
    length = min(100, length);
    for (int i = 0; i < length; ++i) {
        // Get each of the items.
        char indexInChar[20]; // Enough size to store 32-bit integer
        snprintf(indexInChar, 20, "%d", i);
        string index(indexInChar);
        NPIdentifier indexId = WebBindings::getStringIdentifier(index.c_str());
        if (!WebBindings::hasProperty(0, npValue, indexId))
            continue;
        NPVariant indexValue;
        if (!WebBindings::getProperty(0, npValue, indexId, &indexValue))
            continue;
        if (NPVARIANT_IS_STRING(indexValue)) {
            string item(NPVARIANT_TO_STRING(indexValue).UTF8Characters,
                        NPVARIANT_TO_STRING(indexValue).UTF8Length);
            stringVector.push_back(item);
        }
        WebBindings::releaseVariantValue(&indexValue);
    }
    return stringVector;
}
Exemplo n.º 9
0
bool MockGrammarCheck::checkGrammarOfString(const WebString& text, vector<WebTextCheckingResult>* results)
{
    WEBKIT_ASSERT(results);
    string16 stringText = text;
    if (find_if(stringText.begin(), stringText.end(), isASCIIAlpha) == stringText.end())
        return true;

    // Find matching grammatical errors from known ones. This function has to
    // check all errors because the given text may consist of two or more
    // sentences that have grammatical errors.
    static const struct {
        const char* text;
        int location;
        int length;
    } grammarErrors[] = {
        {"I have a issue.", 7, 1},
        {"I have an grape.", 7, 2},
        {"I have an kiwi.", 7, 2},
        {"I have an muscat.", 7, 2},
        {"You has the right.", 4, 3},
        {"apple orange zz.", 0, 16},
        {"apple zz orange.", 0, 16},
        {"apple,zz,orange.", 0, 16},
        {"orange,zz,apple.", 0, 16},
        {"the the adlj adaasj sdklj. there there", 0, 38},
        {"zz apple orange.", 0, 16},
    };
    for (size_t i = 0; i < ARRAYSIZE_UNSAFE(grammarErrors); ++i) {
        size_t offset = 0;
        string16 error(grammarErrors[i].text, grammarErrors[i].text + strlen(grammarErrors[i].text));
        while ((offset = stringText.find(error, offset)) != string16::npos) {
            results->push_back(WebTextCheckingResult(WebTextCheckingTypeGrammar, offset + grammarErrors[i].location, grammarErrors[i].length));
            offset += grammarErrors[i].length;
        }
    }
    return false;
}
Exemplo n.º 10
0
bool CppVariant::toBoolean() const
{
    WEBKIT_ASSERT(isBool());
    return value.boolValue;
}
Exemplo n.º 11
0
string CppVariant::toString() const
{
    WEBKIT_ASSERT(isString());
    return string(value.stringValue.UTF8Characters,
                  value.stringValue.UTF8Length);
}
Exemplo n.º 12
0
float WebSpeechGrammar::weight() const
{
    WEBKIT_ASSERT(m_private.get());
    return m_private->weight();
}
Exemplo n.º 13
0
WebURL WebSpeechGrammar::src() const
{
    WEBKIT_ASSERT(m_private.get());
    return m_private->src();
}
Exemplo n.º 14
0
bool MockSpellCheck::spellCheckWord(const WebString& text, int* misspelledOffset, int* misspelledLength)
{
    WEBKIT_ASSERT(misspelledOffset);
    WEBKIT_ASSERT(misspelledLength);

    // Initialize this spellchecker.
    initializeIfNeeded();

    // Reset the result values as our spellchecker does.
    *misspelledOffset = 0;
    *misspelledLength = 0;

    // Convert to a string16 because we store string16 instances in
    // m_misspelledWords and WebString has no find().
    string16 stringText = text;
    int skippedLength = 0;

    while (!stringText.empty()) {
        // Extract the first possible English word from the given string.
        // The given string may include non-ASCII characters or numbers. So, we
        // should filter out such characters before start looking up our
        // misspelled-word table.
        // (This is a simple version of our SpellCheckWordIterator class.)
        // If the given string doesn't include any ASCII characters, we can treat the
        // string as valid one.
        string16::iterator firstChar = find_if(stringText.begin(), stringText.end(), isASCIIAlpha);
        if (firstChar == stringText.end())
            return true;
        int wordOffset = distance(stringText.begin(), firstChar);
        int maxWordLength = static_cast<int>(stringText.length()) - wordOffset;
        int wordLength;
        string16 word;

        // Look up our misspelled-word table to check if the extracted word is a
        // known misspelled word, and return the offset and the length of the
        // extracted word if this word is a known misspelled word.
        // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a
        // misspelled-word table.)
        for (size_t i = 0; i < m_misspelledWords.size(); ++i) {
            wordLength = static_cast<int>(m_misspelledWords.at(i).length()) > maxWordLength ? maxWordLength : static_cast<int>(m_misspelledWords.at(i).length());
            word = stringText.substr(wordOffset, wordLength);
            if (word == m_misspelledWords.at(i) && (static_cast<int>(stringText.length()) == wordOffset + wordLength || isNotASCIIAlpha(stringText[wordOffset + wordLength]))) {
                *misspelledOffset = wordOffset + skippedLength;
                *misspelledLength = wordLength;
                break;
            }
        }

        if (*misspelledLength > 0)
            break;

        string16::iterator lastChar = find_if(stringText.begin() + wordOffset, stringText.end(), isNotASCIIAlpha);
        if (lastChar == stringText.end())
            wordLength = static_cast<int>(stringText.length()) - wordOffset;
        else
            wordLength = distance(firstChar, lastChar);

        WEBKIT_ASSERT(0 < wordOffset + wordLength);
        stringText = stringText.substr(wordOffset + wordLength);
        skippedLength += wordOffset + wordLength;
    }

    return false;
}