我想在Awesomium中使用多个视图,但它在WebCore中有ResourceInterceptor,我无法单独分配ResourceInceptor,如何实现
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);
}
}
我可以在IResourceInterceptor中获得唯一的WebViewId(request.ViewId)。请求如何将此事件路由到正确的"myBrowser"实例
或者有更好的方法来满足这种需求吗?
我希望这次能得到一个答案:)
您不需要手动将其路由回正确的实例。当您在OnRequest方法中返回ResourceResponse时,发送请求的mybrowser实例或Web会话将得到响应。如果出于某种原因,您确实需要MyBrowser实例,请保留ViewId的Dictionary,MyBrowser,而不仅仅是MyBrowser的List,然后您可以为所需的浏览器编制索引。viewid应该在您创建的Web视图中。