public OnProcessRequestEventArgs(string _id, CefRequest _request, CefCallback _callback) { id = _id; request = _request; callback = _callback; continueRequest = false; //do not continue by default }
private int process_request(cef_resource_handler_t *self, cef_request_t *request, cef_callback_t *callback) { CheckSelf(self); var m_request = CefRequest.FromNative(request); var m_callback = CefCallback.FromNative(callback); var result = ProcessRequest(m_request, m_callback); return(result ? 1 : 0); }
private void on_web_socket_request(cef_server_handler_t *self, cef_server_t *server, int connection_id, cef_string_t *client_address, cef_request_t *request, cef_callback_t *callback) { CheckSelf(self); var mServer = CefServer.FromNative(server); var mClientAddress = cef_string_t.ToString(client_address); var mRequest = CefRequest.FromNative(request); var mCallback = CefCallback.FromNative(callback); OnWebSocketRequest(mServer, connection_id, mClientAddress, mRequest, mCallback); }
private int on_quota_request(cef_request_handler_t *self, cef_browser_t *browser, cef_string_t *origin_url, long new_size, cef_callback_t *callback) { CheckSelf(self); var m_browser = CefBrowser.FromNative(browser); var m_origin_url = cef_string_t.ToString(origin_url); var m_callback = CefCallback.FromNative(callback); var result = OnQuotaRequest(m_browser, m_origin_url, new_size, m_callback); return(result ? 1 : 0); }
private int process_request(cef_resource_handler_t *self, cef_request_t *request, cef_callback_t *callback) { CheckSelf(self); var m_request = CefRequest.FromNative(request); var m_callback = CefCallback.FromNative(callback); #pragma warning disable CS0618 // Type or member is obsolete var result = ProcessRequest(m_request, m_callback); #pragma warning restore CS0618 // Type or member is obsolete return(result ? 1 : 0); }
private int on_certificate_error(cef_request_handler_t *self, cef_browser_t *browser, CefErrorCode cert_error, cef_string_t *request_url, cef_sslinfo_t *ssl_info, cef_callback_t *callback) { CheckSelf(self); var m_browser = CefBrowser.FromNative(browser); var m_request_url = cef_string_t.ToString(request_url); var m_ssl_info = CefSslInfo.FromNative(ssl_info); var m_callback = CefCallback.FromNativeOrNull(callback); var result = OnCertificateError(m_browser, cert_error, m_request_url, m_ssl_info, m_callback); return(result ? 1 : 0); }
private int open(cef_resource_handler_t *self, cef_request_t *request, int *handle_request, cef_callback_t *callback) { CheckSelf(self); var m_request = CefRequest.FromNative(request); var m_callback = CefCallback.FromNative(callback); var m_result = Open(m_request, out var m_handleRequest, m_callback); *handle_request = m_handleRequest ? 1 : 0; return(m_result ? 1 : 0); }
private int process_request(cef_resource_handler_t *self, cef_request_t *request, cef_callback_t *callback) { CheckSelf(self); var m_request = CefRequest.FromNative(request); var m_callback = CefCallback.FromNative(callback); //////string url = m_request.Url; //////Debug.WriteLine(url); var result = ProcessRequest(m_request, m_callback); return(result ? 1 : 0); }
private int read_response(cef_resource_handler_t *self, void *data_out, int bytes_to_read, int *bytes_read, cef_callback_t *callback) { CheckSelf(self); var m_callback = CefCallback.FromNative(callback); using (var m_stream = new UnmanagedMemoryStream((byte *)data_out, bytes_to_read, bytes_to_read, FileAccess.Write)) { int m_bytesRead; var result = ReadResponse(m_stream, bytes_to_read, out m_bytesRead, m_callback); * bytes_read = m_bytesRead; return(result ? 1 : 0); } }
private int read_response(cef_resource_handler_t *self, void *data_out, int bytes_to_read, int *bytes_read, cef_callback_t *callback) { CheckSelf(self); var m_callback = CefCallback.FromNative(callback); using (var m_stream = new UnmanagedMemoryStream((byte *)data_out, bytes_to_read, bytes_to_read, FileAccess.Write)) { int m_bytesRead; #pragma warning disable CS0618 // Type or member is obsolete var result = ReadResponse(m_stream, bytes_to_read, out m_bytesRead, m_callback); #pragma warning restore CS0618 // Type or member is obsolete *bytes_read = m_bytesRead; return(result ? 1 : 0); } }
private CefReturnValue on_before_resource_load(cef_resource_request_handler_t *self, cef_browser_t *browser, cef_frame_t *frame, cef_request_t *request, cef_callback_t *callback) { CheckSelf(self); var m_browser = CefBrowser.FromNativeOrNull(browser); var m_frame = CefFrame.FromNativeOrNull(frame); var m_request = CefRequest.FromNative(request); var m_callback = CefCallback.FromNative(callback); var result = OnBeforeResourceLoad(m_browser, m_frame, m_request, m_callback); if (result != CefReturnValue.ContinueAsync) { m_browser.Dispose(); m_frame.Dispose(); m_request.Dispose(); m_callback.Dispose(); } return(result); }
protected override bool ProcessRequest(CefRequest request, CefCallback callback) { if (request == null || callback == null) { return false; } try { uri = new Uri(request.Url); } catch (Exception) { API.Instance.Log("AssetSchemeHandler::ProcessRequest: Unable to parse path {0}", request.Url); return false; } Uri relativeUrl = new Uri(config.BrowserSourceSettings.Url); if (relativeUrl.LocalPath.Length == 1) { API.Instance.Log("AssetSchemeHandler::ProcessRequest: Invalid url (this shouldn't happen) {0}", relativeUrl); return false; } string relativePath = relativeUrl.LocalPath.Substring(1); string filename; try { filename = Path.GetFileName(relativePath); relativePath = Path.GetDirectoryName(relativePath); } catch (ArgumentException) { API.Instance.Log("AssetSchemeHandler::ProcessRequest: Unable to create absolute path from {0} and {1}", relativeUrl.LocalPath, uri.LocalPath); return false; } if (uri.LocalPath.Length == 1) { isAssetWrapping = true; string extension = Path.GetExtension(filename); if (extension.Length > 1 && extension.StartsWith(".")) { extension = extension.Substring(1); } string wrappedAssetMimeType; if (!MimeTypeManager.MimeTypes.TryGetValue(extension, out wrappedAssetMimeType)) { wrappedAssetMimeType = "text/html"; } string resolvedTemplate = config.BrowserSourceSettings.Template; resolvedTemplate = resolvedTemplate.Replace("$(FILE)", filename); resolvedTemplate = resolvedTemplate.Replace("$(WIDTH)", config.BrowserSourceSettings.Width.ToString()); resolvedTemplate = resolvedTemplate.Replace("$(HEIGHT)", config.BrowserSourceSettings.Height.ToString()); resolvedTemplate = resolvedTemplate.Replace("$(MIMETYPE)", wrappedAssetMimeType); inputStream = new MemoryStream(Encoding.UTF8.GetBytes(resolvedTemplate)); } else { isAssetWrapping = false; if (uri.LocalPath != null && uri.LocalPath.Length > 1) { resolvedPath = uri.LocalPath.Substring(1); } else { API.Instance.Log("AssetSchemeHandler::ProcessRequest: Unable to parse path {0}", request.Url); return false; } bool isIgnoringIntercept = uri.Query != null && uri.Query.Length != 0; // if there is a query param, it should ignore interception if (!isIgnoringIntercept && config.BrowserSourceSettings.IsApplyingTemplate) { resolvedPath = Path.Combine(relativePath, resolvedPath); } API.Instance.Log("AssetSchemeHandler::ProcessRequest handling file {0}", resolvedPath); try { inputStream = new FileStream(resolvedPath, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (Exception e) { if (inputStream != null) { inputStream.Dispose(); inputStream = null; } API.Instance.Log("AssetSchemeHandler::ProcessRequest of file {0} failed; {1}", resolvedPath, e.Message); callback.Cancel(); return false; } } length = remaining = inputStream.Length; callback.Continue(); return true; }
protected override bool ReadResponse(Stream response, int bytesToRead, out int bytesRead, CefCallback callback) { if (response == null || inputStream == null) { if (inputStream != null) { inputStream.Dispose(); inputStream = null; } bytesRead = 0; return false; } try { if (isComplete) { bytesRead = 0; return false; } bytesRead = StreamUtils.CopyStream(inputStream, response, bytesToRead); remaining -= bytesRead; if (remaining == 0) { isComplete = true; inputStream.Dispose(); inputStream = null; } return true; } catch (Exception e) { API.Instance.Log("AssetSchemeHandler::ReadResponse of file {0} failed; {1}", isAssetWrapping ? "{wrapped asset}" : resolvedPath, e.Message); if (inputStream != null) { inputStream.Dispose(); inputStream = null; } bytesRead = 0; callback.Cancel(); return false; } }
protected override bool ProcessRequest(CefRequest request, CefCallback callback) { if (request == null || callback == null) { return false; } try { uri = new Uri(request.Url); } catch (Exception e) { API.Instance.Log("AssetSchemeHandler::ProcessRequest: Unable to parse path {0}", request.Url); return false; } if (uri.LocalPath.Length == 1) { isAssetWrapping = true; String resolvedTemplate = config.BrowserSourceSettings.Template; resolvedTemplate = resolvedTemplate.Replace("$(FILE)", config.BrowserSourceSettings.Url); resolvedTemplate = resolvedTemplate.Replace("$(WIDTH)", config.BrowserSourceSettings.Width.ToString()); resolvedTemplate = resolvedTemplate.Replace("$(HEIGHT)", config.BrowserSourceSettings.Height.ToString()); inputStream = new MemoryStream(Encoding.UTF8.GetBytes(resolvedTemplate)); } else { isAssetWrapping = false; if (uri.LocalPath != null && uri.LocalPath.Length > 1) { resolvedPath = uri.LocalPath.Substring(1); } else { API.Instance.Log("AssetSchemeHandler::ProcessRequest: Unable to parse path {0}", request.Url); return false; } try { inputStream = new FileStream(resolvedPath, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (Exception e) { if (inputStream != null) { inputStream.Dispose(); inputStream = null; } API.Instance.Log("AssetSchemeHandler::ProcessRequest of file {0} failed; {1}", resolvedPath, e.Message); callback.Cancel(); return false; } } length = remaining = inputStream.Length; callback.Continue(); return true; }
/// <summary> /// Called on the IO thread when JavaScript requests a specific storage quota /// size via the webkitStorageInfo.requestQuota function. |origin_url| is the /// origin of the page making the request. |new_size| is the requested quota /// size in bytes. Return true to continue the request and call CefCallback /// methods either in this method or at a later time to grant or deny the /// request. Return false to cancel the request immediately. /// </summary> protected virtual bool OnQuotaRequest(CefBrowser browser, string originUrl, long newSize, CefCallback callback) { return(false); }
protected virtual bool ReadResponse(Stream response, int bytesToRead, out int bytesRead, CefCallback callback) { bytesRead = 0; return(false); }
/// <summary> /// Called on the UI thread to handle requests for URLs with an invalid /// SSL certificate. Return true and call CefCallback methods either in this /// method or at a later time to continue or cancel the request. Return false /// to cancel the request immediately. If CefSettings.ignore_certificate_errors /// is set all invalid certificates will be accepted without calling this /// method. /// </summary> protected virtual bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSslInfo sslInfo, CefCallback callback) { return(false); }
protected virtual bool ProcessRequest(CefRequest request, CefCallback callback) { request.Dispose(); callback.Dispose(); return(false); }
/// <summary> /// Open the response stream. To handle the request immediately set /// |handle_request| to true and return true. To decide at a later time set /// |handle_request| to false, return true, and execute |callback| to continue /// or cancel the request. To cancel the request immediately set /// |handle_request| to true and return false. This method will be called in /// sequence but not from a dedicated thread. For backwards compatibility set /// |handle_request| to false and return false and the ProcessRequest method /// will be called. /// </summary> protected abstract bool Open(CefRequest request, out bool handleRequest, CefCallback callback);
/// <summary> /// Called on the IO thread before a resource request is loaded. The |browser| /// and |frame| values represent the source of the request, and may be NULL for /// requests originating from service workers or CefURLRequest. To redirect or /// change the resource load optionally modify |request|. Modification of the /// request URL will be treated as a redirect. Return RV_CONTINUE to continue /// the request immediately. Return RV_CONTINUE_ASYNC and call CefCallback /// methods at a later time to continue or cancel the request asynchronously. /// Return RV_CANCEL to cancel the request immediately. /// </summary> protected virtual CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefCallback callback) { return(CefReturnValue.Continue); }
/// <summary> /// Begin processing the request. To handle the request return true and call /// CefCallback::Continue() once the response header information is available /// (CefCallback::Continue() can also be called from inside this method if /// header information is available immediately). To cancel the request return /// false. /// </summary> protected abstract bool ProcessRequest(CefRequest request, CefCallback callback);
/// <summary> /// Called when |server| receives a WebSocket request. |connection_id| uniquely /// identifies the connection, |client_address| is the requesting IPv4 or /// IPv6 client address including port number, and |request| contains the /// request contents (URL, method, headers and optional POST data). Execute /// |callback| either synchronously or asynchronously to accept or decline the /// WebSocket connection. If the request is accepted then OnWebSocketConnected /// will be called after the WebSocket has connected and incoming messages will /// be delivered to the OnWebSocketMessage callback. If the request is declined /// then the client will be disconnected and OnClientDisconnected will be /// called. Call the CefServer::SendWebSocketMessage method after receiving the /// OnWebSocketConnected callback to respond with WebSocket messages. /// </summary> protected abstract void OnWebSocketRequest(CefServer server, int connectionId, string clientAddress, CefRequest request, CefCallback callback);
/// <summary> /// Read response data. If data is available immediately copy up to /// |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of /// bytes copied, and return true. To read the data at a later time set /// |bytes_read| to 0, return true and call CefCallback::Continue() when the /// data is available. To indicate response completion return false. /// </summary> protected abstract bool ReadResponse(Stream response, int bytesToRead, out int bytesRead, CefCallback callback);
protected override bool ProcessRequest(CefRequest request, CefCallback callback) { Debug.WriteLine(DBGPREFIX + "ProcessRequest for id: " + id); var handler = OnProcessRequestEvent; if (handler != null) { var e = new OnProcessRequestEventArgs(id, request, callback); handler(null, e); Debug.WriteLine(DBGPREFIX + "ProcessRequest for id: " + id + (e.continueRequest ? " will continue processing" : " will be cancelled") ); return e.continueRequest; } return false; }
protected override bool ReadResponse(System.IO.Stream response, int bytesToRead, out int bytesRead, CefCallback callback) { throw new NotImplementedException(); }