user597474
user597474

Reputation:

How to set Mozilla preferences from Java when using the SWT browser widget?

I'm using the SWT browser widget to embed a Mozilla browser inside a Java process, and I'd like to modify the browser's about:config preferences programmatically from Java, at run time. Is this possible to do? And if so, how?

Upvotes: 3

Views: 895

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57681

You can probably use JavaXPCOM for that. Something like this should work:

import org.mozilla.xpcom.Mozilla;
import org.mozilla.interfaces.nsIServiceManager;
import org.mozilla.interfaces.nsIPrefBranch;

...

Mozilla mozilla = Mozilla.getInstance();
nsIServiceManager serviceManager = mozilla.getServiceManager();
nsIPrefBranch prefs = (nsIPrefBranch)serviceManager
    .getServiceByContractID("@mozilla.org/preferences-service;1",
        nsIPrefBranch.NS_IPREFBRANCH_IID);
prefs.setBoolPref("javascript.enabled", false);

If you cannot access JavaXPCOM then this likely isn't doable.

Upvotes: 2

Related Questions