Ejemplo n.º 1
0
        /// <summary>
        /// 在资源加载前,过滤或写入缓存队列
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <param name="arg5"></param>
        /// <returns></returns>
        private CefReturnValue RequestHandler_InterceptBeforeResourceLoad(IWebBrowser arg1, IBrowser arg2, IFrame arg3, IRequest arg4, IRequestCallback arg5)
        {
            if (OnBeforeResourceLoad == null)
            {
                return(CefReturnValue.Continue);
            }
            var args = new BeforeResourceLoadEventArgs(arg4.Url, arg4.ResourceType);

            OnBeforeResourceLoad.Invoke(this, args);
            if (args.CacheToQueue)
            {
                ResourceCacheManager.CreateResource(arg4.Identifier);
            }
            return(!args.Cancel ? CefReturnValue.Continue : CefReturnValue.Cancel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 在资源加载完成后,触发完成事件
        /// </summary>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        /// <param name="arg3"></param>
        /// <param name="arg4"></param>
        /// <param name="arg5"></param>
        /// <param name="arg6"></param>
        /// <param name="arg7"></param>
        private void RequestHandler_InterceptResourceLoadComplete(IWebBrowser arg1, IBrowser arg2, IFrame arg3, IRequest arg4, IResponse arg5, UrlRequestStatus arg6, long arg7)
        {
            var stream = ResourceCacheManager.GetResource(arg4.Identifier);

            if (stream != null)
            {
                stream.Seek(0, System.IO.SeekOrigin.Begin);
            }
            try
            {
                this.OnResourceLoadComplete?.Invoke(this, new ResourceLoadCompleteEventArgs(arg4.Url, arg4.ResourceType, arg7, stream, arg6));
            }
            finally
            {
                ResourceCacheManager.DeleteResource(arg4.Identifier);
            }
        }