0

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?)

Vaibhav Mule
  • 5,016
  • 4
  • 35
  • 52
Kaya
  • 1
  • 1

1 Answers1

0

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();
Kaya
  • 1
  • 1