0

I want to block certain images in Awesomium from appearing on the page. This code does not work because the Awesomium IResourceInterceptor is not a class, it is an interface.

public class ResourceInterceptor : IResourceInterceptor
{
public bool NoImages { get; set; }

private static string[] _imagesFileTypes = { ".png", ".jpg", ".jpeg", ".gif", ".bmp" };

public ResourceResponse OnRequest(ResourceRequest request)
{
    string ext = System.IO.Path.GetExtension(request.Url.ToString()).ToLower();

    if (NoImages && _imagesFileTypes.Contains(ext))
    {
        request.Cancel();
    }

    return null;
}

public bool OnFilterNavigation(NavigationRequest request)
{
    return false;
}

}

How do I modify the OnRequest method of a IResourceInterceptor when it is an interface?

user2155059
  • 151
  • 3
  • 14

1 Answers1

1

You can write your own implementation of an interface. An interface describes what methods are available on classes that implement the interface. So you can write your own class implementing the IResourceInterceptor interface and use it like that:

In the constructor as usual:

WebCore.Initialized += WebCoreInitialzed; 
//create an instance of your Interceptor (you need a private field of course)
interceptor = new ResourceInterceptor();

And in the event handeler function:

private void WebCoreInitialzed(object sender, CoreStartEventArgs e)
{
    WebCore.ResourceInterceptor = interceptor;
}

If you are unfamiliar with the concept of interfaces you may want to read the msdn article here

A stackoverflow question to interface that does list some tutorial can be found here

Community
  • 1
  • 1
Sjoerd222888
  • 3,228
  • 3
  • 31
  • 64