Skybound Software is looking to hire experienced C# developers to work on Stylizer and other forthcoming Skybound products. Click here for details.
GeckoFX is an open-source component which makes it easy to embed Mozilla Gecko (Firefox) into any .NET Windows Forms application. Written in clean, fully commented C#, GeckoFX is the perfect replacement for the default Internet Explorer-based WebBrowser control. Download GeckoFX @ Google Code >
GeckoFX is made by Skybound Software, authors of Stylizer—the professional CSS editor with a strong focus on visual control, error-free workflow, and productivity. Learn About Stylizer >
Discuss GeckoFX, the Open-Source Gecko Control for .NET
You are not logged in.
Pages: 1
For our project, we're attempting to restrict connections to an approved list of URLs/domains.
I've inserted a breakpoint in GeckoWebBrowser's nsIWebProgressListener.OnStateChange and can retrieve the URIs of all direct links (images, javascript includes, etc.), but nothing happens when there is an asynchronous request of a URL.
For example, browsing to http://jquery.com/demo/thickbox/ and trying the "AJAX Content" demos, doesn't trigger a call to OnStateChange for the actual retrieval of the ajaxOverFlow.html page.
I've had similar non-results testing my own pages that use jQuery's ajax functions.
Is there any way to listen for these sort of requests?
Thanks.
Offline
Update:
I was able to get this working by implementing nsIObserver and adding that to the Observer service, as described here: https://developer.mozilla.org/en/Settin … st_headers
Offline
Elaboration:
1. Implement nsIObserver in a class (or in GeckoWebBrowser.cs itself).
2. In GeckoResponse.cs, change nsIChannel and nsIHttpChannel interfaces to be public.
3. In nsInterfaces.cs, make nsIRequest and nsIUri interfaces public.
4. Add nsIObserverServices interface to nsInterfaces.cs :
[Guid("D07F5192-E3D1-11d2-8ACD-00105A1B8860")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport()]
internal interface nsIObserverService
{
#region nsIObserverService
[PreserveSigAttribute]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int addObserver([MarshalAs(UnmanagedType.Interface)] nsIObserver anObserver,
[MarshalAs(UnmanagedType.LPStr)] string aTopic,
bool ownsWeak);
[PreserveSigAttribute]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int removeObserver([MarshalAs(UnmanagedType.Interface)] nsIObserver anObserver,
[MarshalAs(UnmanagedType.LPStr)] string aTopic);
[PreserveSigAttribute]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int notifyObservers([MarshalAs(UnmanagedType.Interface)] IntPtr aSubject,
[MarshalAs(UnmanagedType.LPStr)] string aTopic,
[MarshalAs(UnmanagedType.LPWStr)] string someData);
[PreserveSigAttribute]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
int enumerateObservers([MarshalAs(UnmanagedType.LPStr)] string aTopic,
[MarshalAs(UnmanagedType.Interface)] out nsISimpleEnumerator ret);
#endregion
}5. In GeckoWebBrowser.OnHandleCreated, register your observer (if you created another class to implement nsIObserver, then replace "this" with a reference to your observer):
nsIObserverService obsServ = Xpcom.GetService<nsIObserverService>("@mozilla.org/observer-service;1");
obsServ.addObserver(this, "http-on-modify-request", false);6. In the Observer method of your observe, you can retrieve the uri like this:
GeckoResponse.nsIHttpChannel channel = Xpcom.QueryInterface<GeckoResponse.nsIHttpChannel>(aSubject);
Uri uri;
Uri.TryCreate(nsString.Get(channel.GetName), UriKind.Absolute, out uri);You can call channel.Cancel(0), if you want to cancel the request.
I hope this helps.
Best wishes,
-Joshua
Offline
Hi,
Can you explain me, please, how i implement my call back to use my oberve function?
Thanks for your help
Offline
Pages: 1