简体   繁体   中英

Awesomium IWebview ResourceInterceptor c#

I want use multiple views to use in Awesomium but It has ResourceInterceptor in WebCore common usage i cannot assign ResourceInerceptor separately, How to achive

    List<myBrowser> browsers = new List<myBrowser>();
       WebCore.Started += (se, ea) => { 
       WebCore.ResourceInterceptor = new myResourceInterceptor(); 
        };
      for (int i = 0; i < 5; i++)
        {
         WebSession session = WebCore.CreateWebSession(folder + "\\b" + i,new WebPreferences());
         WebView view = WebCore.CreateWebView(1024, 768, session, WebViewType.Window);
         myBrowser b = new myBrowser(folder + "\\b" + i,ref view);
         b.view.Source = "www.google.com".ToUri();
        }




    public class myBrowser
    {
      .. .
     public myBrowser(string data,ref WebView view)
      {
          this.dataFolder = data;
          this.view = view;
          view.LoadingFrameComplete += view_LoadingFrameComplete;            
       }
    }

   // I can get unique WebViewId (request.ViewId) how to route this event to correct "myBrowser"
   public class myResourceInterceptor: IResourceInterceptor
    {
      public ResourceResponse OnRequest(ResourceRequest request)
      {
        Console.Write("Request"+request.ViewId); 
      }
    }

I can get unique WebViewId (request.ViewId) in IResourceInterceptor.OnRequest how to route this event to correct "myBrowser" instance

Or is there a better way to achive this need ?

I wish to get an answer this time :)

You shouldn't need to route it back to the correct instance manually. The mybrowser instance, or websession that sent the request will get the response back when you return a ResourceResponse in the OnRequest method. If for some reason you really need the MyBrowser instance, keep a Dictionary of ViewId,MyBrowser instead of just a List of MyBrowser, then you can index the browser you want. The viewid should be in the webview you create.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM