0
votes

I want to read the <param> values of custom plugin

I could not find answer on the internet, what I found was:
https://github.com/firebreath/FireBreath/blob/master/src/NpapiCore/NpapiPlugin.cpp#L76

I see params are stored in pluginMain->setParams(paramList);

Can you point how can I access this paramList later? or pluginMain
Is there pluginMain->getParams()? I could not find reference
Nor I could locate the source for setParams().

The question is, how do I get that parameters from PluginWindowXXX or FB::NpapiPluginXXX ?

I exported m_npHost to PluginWindowXXX, set breakpoint in it with gdb but still no success.

All I can think of was:

(gdb) p ((FB::Npapi::NpapiBrowserHost)this->m_npHost)->GetValue
$17 = {NPError (const FB::Npapi::NpapiBrowserHost * const, NPNVariable, void *)} 0x7fe435adeff8 <FB::Npapi::NpapiBrowserHost::GetValue(NPNVariable, void*) const>

Obviously what I do is wrong but I am stuck,
I am passing this host from NpapiPluginX11.cpp

pluginWin->setHost(m_npHost);
2

2 Answers

1
votes

taxilian's answer is the most correct one as always but I'll give a try. I'm reading params in my MyPluginAPI constructor.

MyPluginAPI::MyPluginAPI(const MyPluginPtr& plugin, const FB::BrowserHostPtr& host) : m_plugin(plugin), m_host(host)
{
    string settings; //<param name="settings" value="{'foo':'bar'}">
    settings = plugin->getParam("settings");    
}
0
votes

Inside your PluginCore-derived class, you can use either the getParam method or the getParamVariant method.

From the FireBreath Source:

boost::optional<std::string> PluginCore::getParam(const std::string& key) {
    boost::optional<std::string> rval;
    FB::VariantMap::const_iterator fnd = m_params.find(key.c_str());
    if (fnd != m_params.end())
        rval.reset(fnd->second.convert_cast<std::string>());
    return rval;
}

FB::variant FB::PluginCore::getParamVariant( const std::string& key )
{
    FB::VariantMap::const_iterator fnd = m_params.find(key.c_str());
    if (fnd != m_params.end())
        return fnd->second;
    return FB::variant();
}

So if it's for sure a string (which it pretty much is, unless it starts with on, in which case it might have been converted to a referenced function), you can use:

boost::optional<std::string> mystr = getParam("mystr");
if (mystr) { 
   call_fn_with_string(*mystr);
}

Alternately, you can get it as a variant and convert it:

FB::variant mystrVal = getParamVariant("mystr");
try {
    call_fn_with_string(mystrVal.convert_cast<std::string>());
} catch (FB::bad_variant_cast &err) {
    // What to do if the cast to string fails
}