I'm building a customized version of Firefox Fennec, and I want to inject some javascript to current tab when user has selected some menus.
I think JS::Evaluate(jsContext, jsOptions, scriptSrc, scriptlength, &retValue) can do that, but I can't figure out which one is the right parameter for jsContext.
(I got nsCOMPtr domWindow for current tab, but will that help?)
Code below is working :)
nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface( domWindow );
if (!globalObject) break;
nsresult rv = globalObject->EnsureScriptEnvironment();
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIScriptContext> context = globalObject->GetScriptContext();
if (!context) break;
mozilla::dom::AutoEntryScript entryScript(globalObject, true, context->GetNativeContext());
JSContext *cx = entryScript.cx();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.