//
        // 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);
        }
Exemple #2
0
        // TOP LEVEL API

        public static MemoryStream GetFileIcon(string name, FileIconSize size)
        {
            Icon icon = FileIconUtils.IconFromExtension(name.GetAfter("."), size);

            using (icon) {
                using (var bmp = icon.ToBitmap()) {
                    MemoryStream ms = new MemoryStream();
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    ms.Seek(0, SeekOrigin.Begin);
                    return(ms);
                }
            }
        }