// // Summary: // Open the response stream. - To handle the request immediately set handleRequest // to true and return true. - To decide at a later time set handleRequest to false, // return true, and execute callback to continue or cancel the request. - To cancel // the request immediately set handleRequest to true and return false. This method // will be called in sequence but not from a dedicated thread. For backwards compatibility // set handleRequest to false and return false and the CefSharp.IResourceHandler.ProcessRequest(CefSharp.IRequest,CefSharp.ICallback) // method will be called. // // Parameters: // request: // request // // handleRequest: // see main summary // // callback: // callback // // Returns: // see main summary public bool Open(IRequest request, out bool handleRequest, ICallback callback) { uri = new Uri(request.Url); fileName = uri.AbsolutePath; // if url is blocked /*if (...request.Url....) { * * // cancel the request - set handleRequest to true and return false * handleRequest = true; * return false; * }*/ // if url is browser file if (uri.Host == "storage") { fileName = appPath + uri.Host + fileName; if (File.Exists(fileName)) { Task.Factory.StartNew(() => { using (callback) { FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); mimeType = ResourceHandler.GetMimeType(Path.GetExtension(fileName)); stream = fStream; callback.Continue(); } }); // handle the request at a later time handleRequest = false; return(true); } } // if url is request for icon of another file if (uri.Host == "fileicon") { Task.Factory.StartNew(() => { using (callback) { stream = FileIconUtils.GetFileIcon(fileName, FileIconSize.Large); mimeType = ResourceHandler.GetMimeType(".png"); callback.Continue(); } }); // handle the request at a later time handleRequest = false; return(true); } // by default reject callback.Dispose(); // cancel the request - set handleRequest to true and return false handleRequest = true; return(false); }
// // Summary: // Begin processing the request. // // Parameters: // request: // The request object. // // callback: // The callback used to Continue or Cancel the request (async). // // Returns: // To handle the request return true and call CefSharp.ICallback.Continue() // once the response header information is available CefSharp.ICallback.Continue() // can also be called from inside this method if header information is available // immediately). To cancel the request return false. public bool ProcessRequest(IRequest request, ICallback callback) { uri = new Uri(request.Url); fileName = uri.AbsolutePath; // if url is blocked /*if (!myForm.IsURLOk(request.Url)) { * * // return true so it does not open up * return true; * }*/ // if url is browser file if (uri.Host == "storage") { fileName = appPath + uri.Host + fileName; if (File.Exists(fileName)) { Task.Factory.StartNew(() => { using (callback) { //var bytes = Encoding.UTF8.GetBytes(resource); //stream = new MemoryStream(bytes); FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); mimeType = ResourceHandler.GetMimeType(Path.GetExtension(fileName)); stream = fStream; callback.Continue(); } }); return(true); } } // if url is request for icon of another file if (uri.Host == "fileicon") { Task.Factory.StartNew(() => { using (callback) { stream = FileIconUtils.GetFileIcon(fileName, FileIconSize.Large); mimeType = ResourceHandler.GetMimeType(".png"); callback.Continue(); } }); return(true); } // by default reject callback.Dispose(); return(false); }