[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: [browser] How to handle each display/shell dialog box and choose default action
|
Hi Kamil,
This can only be done for SWT.MOZILLA-style Browsers, by providing your own
nsIPromptService via JavaXPCOM. Note that once you do this then your prompt
service will be used for all Mozilla-based Browser instances regardless of
whether you created them or not (so this will be all SWT.MOZILLA-style
Browsers on win32 and OSX, and ALL Browser instances on linux). A snippet
that demonstrates this is shown below. For general information about using
JavaXPCOM in the Browser see
http://www.eclipse.org/swt/faq.php#howusejavaxpcom . nsIPromptService is
documented at
http://www.xulplanet.com/references/xpcomref/ifaces/nsIPromptService.html .
import org.eclipse.swt.*;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
import org.mozilla.interfaces.*;
import org.mozilla.xpcom.Mozilla;
public class Main0 {
public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
shell.setBounds(10,10,200,200);
shell.setLayout(new FillLayout());
Browser browser;
try {
browser = new Browser(shell, SWT.MOZILLA);
browser.setUrl("google.com");
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " +
e.getMessage());
return;
}
nsIComponentRegistrar registrar = Mozilla.getInstance
().getComponentRegistrar ();
String NS_PROMPTSERVICE_CID = "a2112d6a-0e28-421f-b46a-25c0b308cbd0";
String NS_PROMPTSERVICE_CONTRACTID =
"@mozilla.org/embedcomp/prompt-service;1";
registrar.registerFactory (NS_PROMPTSERVICE_CID, "Prompt Service",
NS_PROMPTSERVICE_CONTRACTID, new nsIFactory () {
public nsISupports queryInterface (String uuid) {
if (uuid.equals (nsIFactory.NS_IFACTORY_IID) ||
uuid.equals (nsIFactory.NS_ISUPPORTS_IID)) return this;
return null;
}
public nsISupports createInstance (nsISupports outer, String iid) {
return createPromptService ();
}
public void lockFactory (boolean lock) {}
});
shell.open();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
static nsIPromptService createPromptService() {
return new nsIPromptService () {
public nsISupports queryInterface(String uuid) {
if (uuid.equals (nsIPromptService.NS_IPROMPTSERVICE_IID) ||
uuid.equals (nsIPromptService.NS_ISUPPORTS_IID)) return
this;
return null;
}
public boolean select(nsIDOMWindow arg0, String arg1, String arg2,
long arg3, String[] arg4, int[] arg5) {
// your implementation here
return false;
}
public boolean promptUsernameAndPassword(nsIDOMWindow arg0, String
arg1, String arg2, String[] arg3, String[] arg4, String arg5, boolean[]
arg6) {
// your implementation here
return false;
}
public boolean promptPassword(nsIDOMWindow arg0, String arg1, String
arg2, String[] arg3, String arg4, boolean[] arg5) {
// your implementation here
return false;
}
public boolean prompt(nsIDOMWindow arg0, String arg1, String arg2,
String[] arg3, String arg4, boolean[] arg5) {
// your implementation here
return false;
}
public int confirmEx(nsIDOMWindow arg0, String arg1, String arg2,
long arg3, String arg4, String arg5, String arg6, String arg7, boolean[]
arg8) {
// your implementation here
return 0;
}
public boolean confirmCheck(nsIDOMWindow arg0, String arg1, String
arg2, String arg3, boolean[] arg4) {
// your implementation here
return false;
}
public boolean confirm(nsIDOMWindow arg0, String arg1, String arg2)
{
// your implementation here
return false;
}
public void alertCheck(nsIDOMWindow arg0, String arg1, String arg2,
String arg3, boolean[] arg4) {
// your implementation here
}
public void alert(nsIDOMWindow arg0, String arg1, String arg2) {
// your implementation here
}
};
}
}
HTH,
Grant
"Kamil Lenartowicz" <kamil.lenartowicz@xxxxxxxxx> wrote in message
news:e8fa15902073030f83e87a6fe9afef8a$1@xxxxxxxxxxxxxxxxxx
> Hi
>
> I have such problem: I want to handle every dialog box (not knowed) which
> was executed on display and automatically choose default action on it. Is
> it possible? The problem is connected with swt browser component which I
> want to use hidden - not doing show on display - my demon application will
> do some operations on this browser (in shadow).
>
> I want to send various command (and get some info like current html code)
> to this browser but the problem is that this browser can execute dialog
> box (java script) and stop/block... It is very important for me to use
> browser like that.
>
> Thanks for answers and sory for my poor english
>