|
Re: How can I disable XULRunner/firefox Embedded Browser offline mode [message #505947 is a reply to message #505793] |
Tue, 05 January 2010 15:32 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
Hi Ryan,
I tried following a SWT.MOZILLA Browser link after unplugging my network
connection and just got a "...could not reach url..." error message, so I
don't have a test case that matches yours. However I found some info that
could be relevant, if you can give it a try.
Starting from: http://www.advogato.org/article/1014.html
And then seeing:
http://www.oxymoronical.com/experiments/apidocs/interface/ns IIOService2
I put together the snippet below which at least sounds like it could fix
your case. It requires that you use JavaXPCOM, which is explained in
http://www.eclipse.org/swt/faq.php#howusejavaxpcom . Also note that if this
does not quite solve your case, nsIIOService provides method
"setOffline(boolean)", which could be helpful.
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.mozilla.interfaces.*;
import org.mozilla.xpcom.Mozilla;
public class ModifiedSnippet267 {
static Browser browser;
public static void main (String [] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
try {
browser = new Browser(shell, SWT.MOZILLA);
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " +
e.getMessage());
display.dispose();
return;
}
browser.setUrl("http://www.google.com");
shell.setBounds(10,10,400,400);
shell.open();
// start JavaXPCOM section
nsIIOService ioService =
(nsIIOService)Mozilla.getInstance().getServiceManager().getS erviceByContract
ID("@mozilla.org/network/io-service;1", nsIIOService.NS_IIOSERVICE_IID);
nsIIOService2 ioService2 =
(nsIIOService2)ioService.queryInterface(nsIIOService2.NS_IIO SERVICE2_IID);
ioService2.setManageOfflineStatus(false);
// end JavaXPCOM section
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
I'd be interested to know if this fixes your case, please follow up if you
have any problems.
Grant
"Ryan" <ryan_swt@itheroes.com.au> wrote in message
news:hhucce$3pm$1@build.eclipse.org...
> Hi,
>
> I have an SWT app which uses an embedded browser to browse a webapp
running on localhost. I get an issue when there is no active network
connection and XULRunner switches to offline mode and comes up with an error
saying to turn offline mode off.
>
> I am running windows and can only find references to linux Network Manager
on searches which doesn't help.
>
> I found a firefox extension that would do the trick, but I don't know if
it can be installed with XULRunner?
>
> Is there another way I can disable offline mode? Any help would be
appreciated. I'm contemplating just installing a dummy network adapter in
windows to trick it, but that isn't very good for distribution :).
>
> Running Windows
> Tried XULRunner 1.9.0 and 1.9.1 series and firefox 3.6 beta.
>
> Many Thanks,
>
> Ryan
>
|
|
|
Re: How can I disable XULRunner/firefox Embedded Browser offline mode [message #506073 is a reply to message #505793] |
Wed, 06 January 2010 01:20 |
Eclipse User |
|
|
|
Originally posted by: jccanova.gmail.com
Hi,
I hope i can help you.
There is a option on configuration (about:config) that control the online
offline mode.
"browser.offline" True: Attempt to retrieve pages from cache.
False (default): Assume a connection is present and retrieve resources where
necessary.
Probably this is being turned on/off by the browser (this i still dont know
how).
You can manage this property directly from XulRunner in a mozilla browser
(SWT.Mozilla)
Retrieving first the serviceManager, then the propertiesService... get the
Branch. use a empty branch.... then alter the value always to true...
here is a snippet in this case i was testing the proxy config....
Mozilla mozilla = Mozilla.getInstance();
nsIServiceManager serviceManager = mozilla.getServiceManager();
nsIComponentManager componentManager = mozilla.getComponentManager();
nsIWebBrowser thisBrowser = (nsIWebBrowser)
thisClass.proxyBrowser.getWebBrowser();
nsIPrefService preferencesService = (nsIPrefService)
serviceManager.getServiceByContractID("@mozilla.org/preferences-service;1 " ,
"decb9cc7-c08f-4ea5-be91-a8fc637ce2d2");// nsIPrefService
nsIPrefBranch prefs = preferencesService.getDefaultBranch("");
String root = prefs.getRoot();
try {
HttpProxy.main(new String[]{"c:/temp"});
} catch (Exception e) {
e.printStackTrace();
}
if (prefs.getPrefType("network.proxy.http") !=0 &&
prefs.getPrefType("network.proxy.http_port") !=0) {
prefs.setIntPref("network.proxy.type", 1);
prefs.unlockPref("network.proxy.http");
prefs.setCharPref("network.proxy.http", "127.0.0.1");
prefs.unlockPref("network.proxy.http_port");
prefs.setIntPref("network.proxy.http_port",8083 );
}
if (prefs.getPrefType("network.http.accept.default")!=0){
prefs.unlockPref("network.http.accept.default");
System.err.println(prefs.getCharPref("network.http.accept.default "));
}
In your case you gona use the "browser.offline" property...
Regards,
"Ryan" <ryan_swt@itheroes.com.au> wrote in message
news:hhucce$3pm$1@build.eclipse.org...
> Hi,
>
> I have an SWT app which uses an embedded browser to browse a webapp
> running on localhost. I get an issue when there is no active network
> connection and XULRunner switches to offline mode and comes up with an
> error saying to turn offline mode off.
>
> I am running windows and can only find references to linux Network Manager
> on searches which doesn't help.
>
> I found a firefox extension that would do the trick, but I don't know if
> it can be installed with XULRunner?
>
> Is there another way I can disable offline mode? Any help would be
> appreciated. I'm contemplating just installing a dummy network adapter in
> windows to trick it, but that isn't very good for distribution :).
>
> Running Windows
> Tried XULRunner 1.9.0 and 1.9.1 series and firefox 3.6 beta.
>
> Many Thanks,
>
> Ryan
>
|
|
|
|
Re: [Solved] Re: How can I disable XULRunner/firefox Embedded Browser offline mode [message #506491 is a reply to message #506085] |
Thu, 07 January 2010 17:06 |
Eclipse User |
|
|
|
Originally posted by: jccanova.gmail.com
Tks to you,
no i understood how i can manage NetworkServices in XullRunner :)
"Ryan" <ryan_swt@itheroes.com.au> wrote in message
news:hi0ung$1m5$1@build.eclipse.org...
> Thanks very much,
>
> The nsIIOService2 did the trick.
>
> I also had to set
>
> ioService2.setOffline(false);
>
> otherwise if the application started without a network connection it was
> in offline mode. But this was easy to find because it is in the
> documentation for nsIIOService2.
>
> Regarding the browser.offline property. I have tried that one when using
> firefox and it didn't make any difference. I'm not sure what it is meant
> to do.
>
> Many thanks,
>
> Ryan
|
|
|
Powered by
FUDForum. Page generated in 0.05194 seconds