How to open a file which includes in Chrome extension by C/C++?

风流意气都作罢 提交于 2019-12-01 14:02:26

There are two ways you could address this; the first is to simply use javascript to get the path and then pass it into the plugin in a method call.

The second is to get the path to the plugin .dll file and then calculate the location of config.txt relative to that as explained on the website.

I suppose the other option would be to try to use:

m_host->getDOMWindow()->getNode("chrome")->getNode("extension")->getNode("getURL")->callMethod<FB::variant>("", FB::variant_list_of("config.txt");

I don't know if that would actually work or not; I haven't tried it, and I may have even mistyped some of the function calls, but it might be worth a try.

I finally managed to find a way to get the "config.txt" in my NPAPI plugin by XmlHttpRequest.

const char* getconfig =
" window.__config_txt__ = (function() {"
"     var ret = \"Default return value\";"
"     var xhr = new XMLHttpRequest();"
"     xhr.open(\"GET\", \"config.txt\", false);"
"     xhr.onreadystatechange = function() {"
"       if(xhr.readyState == 4) {"
"         ret = xhr.responseText;"
"       };"
"     };"
"     xhr.send();"
"     return ret;"
" })();";
m_host->evaluateJavaScript(getconfig);

if (window && window->getJSObject()->HasProperty("window")) {
    std::string content = window->getProperty<std::string>("__config_txt__");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!