/// <summary> /// A portion of the file contents have been received. This method will /// be called multiple times until the download is complete. Return /// |true| to continue receiving data and |false| to cancel. /// </summary> private int received_data(cef_download_handler_t* self, void* data, int data_size) { ThrowIfObjectDisposed(); var m_stream = new UnmanagedMemoryStream((byte*)data, data_size, data_size, FileAccess.Read); var handled = this.ReceivedData(m_stream); m_stream.Dispose(); return handled ? 1 : 0; }
/// <summary> /// The download is complete. /// </summary> private void complete(cef_download_handler_t* self) { ThrowIfObjectDisposed(); this.Complete(); }
/// <summary> /// Called on the UI thread when a server indicates via the 'Content- /// Disposition' header that a response represents a file to download. /// |mimeType| is the mime type for the download, |fileName| is the /// suggested target file name and |contentLength| is either the value of /// the 'Content-Size' header or -1 if no size was provided. Set /// |handler| to the CefDownloadHandler instance that will recieve the /// file contents. Return true to download the file or false to cancel /// the file download. /// </summary> private int get_download_handler(cef_request_handler_t* self, cef_browser_t* browser, /*const*/ cef_string_t* mimeType, /*const*/ cef_string_t* fileName, long contentLength, cef_download_handler_t** handler) { ThrowIfObjectDisposed(); var m_browser = CefBrowser.From(browser); var m_mimeType = cef_string_t.ToString(mimeType); var m_fileName = cef_string_t.ToString(fileName); CefDownloadHandler m_handler; var handled = this.GetDownloadHandler(m_browser, m_mimeType, m_fileName, contentLength, out m_handler); if (m_handler != null) { *handler = m_handler.GetNativePointerAndAddRef(); } return handled ? 1 : 0; }