Logo Search packages:      
Sourcecode: icedtea-web version File versions  Download package

void PluginRequestProcessor::sendMember ( std::vector< std::string * > *  message_parts  ) 

Sends request member pointer to the Java side.

This is a static function, called in another thread. Since certain data can only be requested from the main thread in Mozilla, this function does whatever it can seperately, and then makes an internal request that causes _sendMember to do the rest of the work.

Parameters:
message_parts The request message

Request data from Java if necessary

Definition at line 520 of file IcedTeaPluginRequestProcessor.cc.

References async_call_thread_data::call_successful, async_call_thread_data::parameters, async_call_thread_data::result, and async_call_thread_data::result_ready.

{
    // member initialization
    std::vector<std::string> args;
    JavaRequestProcessor java_request = JavaRequestProcessor();
    JavaResultData* java_result;
    NPVariant* parent_ptr;

    //int reference;
    std::string member_id = std::string();
    std::string jsObjectClassID = std::string();
    std::string jsObjectConstructorID = std::string();
    std::string response = std::string();

    NPIdentifier member_identifier;

    int method_id;
    int instance_id;
    int reference;

    // debug printout of parent thread data
    IcedTeaPluginUtilities::printStringPtrVector("PluginRequestProcessor::getMember:", message_parts);

    reference = atoi(message_parts->at(3)->c_str());

    // store info in local variables for easy access
    instance_id = atoi(message_parts->at(1)->c_str());
    parent_ptr = (NPVariant*) (IcedTeaPluginUtilities::stringToJSID(message_parts->at(5)));
    member_id.append(*(message_parts->at(6)));

    /** Request data from Java if necessary **/
    if (*(message_parts->at(4)) == "GetSlot")
    {
        member_identifier = browser_functions.getintidentifier(atoi(member_id.c_str()));
    } else
    {
        // make a new request for getString, to get the name of the identifier
        java_result = java_request.getString(member_id);

        // the result we want is in result_string (assuming there was no error)
        if (java_result->error_occurred)
        {
            printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg);
            //goto cleanup;
        }

        member_identifier = browser_functions.getstringidentifier(java_result->return_string->c_str());
    }

    AsyncCallThreadData thread_data = AsyncCallThreadData();
    thread_data.result_ready = false;
    thread_data.parameters = std::vector<void*>();
    thread_data.result = std::string();

    NPP instance = IcedTeaPluginUtilities::getInstanceFromMemberPtr(parent_ptr);
    thread_data.parameters.push_back(instance);
    thread_data.parameters.push_back(NPVARIANT_TO_OBJECT(*parent_ptr));
    thread_data.parameters.push_back(&member_identifier);

#ifdef CHROMIUM_WORKAROUND
    // Workaround for chromium
    _getMember(&thread_data);

    if (!thread_data.call_successful)
    {
#endif
        thread_data.result_ready = false;
        browser_functions.pluginthreadasynccall(instance, &_getMember, &thread_data);

        while (!thread_data.result_ready) usleep(2000); // wait till ready

#ifdef CHROMIUM_WORKAROUND
    }
#endif

    PLUGIN_DEBUG("Member PTR after internal request: %s\n", thread_data.result.c_str());

    java_result = java_request.findClass(0, "netscape.javascript.JSObject");

    // the result we want is in result_string (assuming there was no error)
    if (java_result->error_occurred)
    {
        printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg);
        //goto cleanup;
    }

    jsObjectClassID.append(*(java_result->return_string));

    args = std::vector<std::string>();
    std::string longArg = "J";
    args.push_back(longArg);

    java_result = java_request.getMethodID(jsObjectClassID,
                                           browser_functions.getstringidentifier("<init>"),
                                           args);

    // the result we want is in result_string (assuming there was no error)
    if (java_result->error_occurred)
    {
        printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg);
        //goto cleanup;
    }

    jsObjectConstructorID.append(*(java_result->return_string));

    // We have the method id. Now create a new object.

    args.clear();
    args.push_back(thread_data.result);
    java_result = java_request.newObjectWithConstructor("",
                                         jsObjectClassID,
                                         jsObjectConstructorID,
                                         args);

    // the result we want is in result_string (assuming there was no error)
    if (java_result->error_occurred)
    {
        printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg);
        //goto cleanup;
    }


    IcedTeaPluginUtilities::constructMessagePrefix(0, reference, &response);
    if (*(message_parts->at(2)) == "GetSlot")
    {
        response.append(" JavaScriptGetMember ");
    } else {
        response.append(" JavaScriptGetSlot ");
    }
    response.append(java_result->return_string->c_str());
    plugin_to_java_bus->post(response.c_str());


    // Now be a good citizen and help keep the heap free of garbage
    cleanup:

    pthread_mutex_lock(&tc_mutex);
    thread_count--;
    pthread_mutex_unlock(&tc_mutex);
}


Generated by  Doxygen 1.6.0   Back to index