示例#1
0
 public OnProcessRequestEventArgs(string _id, CefRequest _request, CefCallback _callback)
 {
     id = _id;
     request = _request;
     callback = _callback;
     continueRequest = false; //do not continue by default 
 }
        public AssetSchemeHandler(BrowserConfig config, CefRequest request)
        {
            this.config = config;
            isComplete = false;

            length = remaining = -1;
        }
示例#3
0
 public OnGetResourceHandlerEventArgs(string _id, CefBrowser _browser, CefFrame _frame, CefRequest _request)
 {
     id = _id;
     browser = _browser;
     frame = _frame;
     request = _request;
     DelegateRequest = false; //Default do not delegate, allow CEF to handle using network
 }
        protected override bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigationType, bool isRedirect)
        {
            Console.WriteLine("OnBeforeNavigation: Request.Url={0} NavigationType={1} IsRedirect={2}",
                request.Url,
                navigationType,
                isRedirect
                );

            return false;
        }
示例#5
0
        /// <summary>
        /// Create a new URL request. Only GET, POST, HEAD, DELETE and PUT request
        /// methods are supported. Multiple post data elements are not supported and
        /// elements of type PDE_TYPE_FILE are only supported for requests originating
        /// from the browser process. Requests originating from the render process will
        /// receive the same handling as requests originating from Web content -- if
        /// the response contains Content-Disposition or Mime-Type header values that
        /// would not normally be rendered then the response may receive special
        /// handling inside the browser (for example, via the file download code path
        /// instead of the URL request code path). The |request| object will be marked
        /// as read-only after calling this method.
        /// </summary>
        public static CefUrlRequest Create(CefRequest request, CefUrlRequestClient client)
        {
            if (request == null) throw new ArgumentNullException("request");

            var n_request = request.ToNative();
            var n_client = client.ToNative();

            return CefUrlRequest.FromNative(
                cef_urlrequest_t.create(n_request, n_client)
                );
        }
示例#6
0
        protected override CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request)
        {
            Debug.WriteLine(DBGPREFIX + "OnGetResourceHandler called for URL: " + request.Url);
	        var handler = OnGetResourceHandlerEvent;
	        if (handler != null)
	        {
                LVCefRequest lvCefRequest = new LVCefRequest(OnProcessRequestEvent, OnCancelEvent);
                Debug.WriteLine(DBGPREFIX + "OnGetResourceHandler for URL: " + request.Url + " assigned id " + lvCefRequest.id);
		        var e = new OnGetResourceHandlerEventArgs(lvCefRequest.id, browser, frame, request);
		        handler(this, e);

                if (e.DelegateRequest)
                {
                    Debug.WriteLine(DBGPREFIX + "OnGetResourceHandler for id " + lvCefRequest.id + " to be delegated");
                    return lvCefRequest;
                }
	        }
            Debug.WriteLine(DBGPREFIX + "OnGetResourceHandler for URL: " + request.Url + " to be handled normally by CEF");
            return null;
        }
 /// <summary>
 /// Returns the request object used to create this URL request. The returned
 /// object is read-only and should not be modified.
 /// </summary>
 public CefRequest GetRequest()
 {
     return(CefRequest.FromNative(
                cef_urlrequest_t.get_request(_self)
                ));
 }
示例#8
0
 /// <summary>
 /// Called on the IO thread when a resource load has completed. |request| and
 /// |response| represent the request and response respectively and cannot be
 /// modified in this callback. |status| indicates the load completion status.
 /// |received_content_length| is the number of response bytes actually read.
 /// </summary>
 protected virtual void OnResourceLoadComplete(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefUrlRequestStatus status, long receivedContentLength)
 {
 }
示例#9
0
 /// <summary>
 /// Called on the IO thread when a resource response is received. To allow the
 /// resource to load normally return false. To redirect or retry the resource
 /// modify |request| (url, headers or post body) and return true. The
 /// |response| object cannot be modified in this callback.
 /// </summary>
 protected virtual bool OnResourceResponse(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response)
 {
     return(false);
 }
示例#10
0
 /// <summary>
 /// Called on the IO thread before a resource is loaded. To allow the resource
 /// to load normally return NULL. To specify a handler for the resource return
 /// a CefResourceHandler object. The |request| object should not be modified in
 /// this callback.
 /// </summary>
 protected virtual CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return(null);
 }
 protected override bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect)
 {
     return false;
 }
示例#12
0
 /// <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);
示例#13
0
 /// <summary>
 /// Create a new CefRequest object.
 /// </summary>
 public static CefRequest Create()
 {
     return(CefRequest.FromNative(
                cef_request_t.create()
                ));
 }
 /// <summary>
 /// Called on the browser process IO thread before a resource request is
 /// initiated. The |browser| and |frame| values represent the source of the
 /// request, and may be NULL for requests originating from service workers or
 /// CefURLRequest. |request| represents the request contents and cannot be
 /// modified in this callback. |is_navigation| will be true if the resource
 /// request is a navigation. |is_download| will be true if the resource request
 /// is a download. |request_initiator| is the origin (scheme + domain) of the
 /// page that initiated the request. Set |disable_default_handling| to true to
 /// disable default handling of the request, in which case it will need to be
 /// handled via CefResourceRequestHandler::GetResourceHandler or it will be
 /// canceled. To allow the resource load to proceed with default handling
 /// return NULL. To specify a handler for the resource return a
 /// CefResourceRequestHandler object. This method will not be called if the
 /// client associated with |browser| returns a non-NULL value from
 /// CefRequestHandler::GetResourceRequestHandler for the same request
 /// (identified by CefRequest::GetIdentifier).
 /// </summary>
 protected abstract CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling);
 /// <summary>
 /// Called on the IO thread before a resource request is loaded. The |request|
 /// object may be modified. To cancel the request return true otherwise return
 /// false.
 /// </summary>
 protected virtual bool OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return false;
 }
 /// <summary>
 /// Return a new resource handler instance to handle the request or an empty
 /// reference to allow default handling of the request. |browser| and |frame|
 /// will be the browser window and frame respectively that originated the
 /// request or NULL if the request did not originate from a browser window
 /// (for example, if the request came from CefURLRequest). The |request| object
 /// passed to this method cannot be modified.
 /// </summary>
 protected abstract CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request);
 /// <summary>
 /// Called when |server| receives an HTTP 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). Call CefServer
 /// methods either synchronously or asynchronusly to send a response.
 /// </summary>
 protected abstract void OnHttpRequest(CefServer server, int connectionId, string clientAddress, CefRequest request);
 /// <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);
示例#19
0
 protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
 {
     Debug.WriteLine(DBGPREFIX + "OnBeforeBrowse");
     _messageRouter.OnBeforeBrowse(browser, frame);
     return false;
 }
示例#20
0
            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;
            }
示例#21
0
 protected virtual bool ProcessRequest(CefRequest request, CefCallback callback)
 {
     request.Dispose();
     callback.Dispose();
     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 before a resource is loaded. To allow the resource
 /// to load normally return NULL. To specify a handler for the resource return
 /// a CefResourceHandler object. The |request| object should not be modified in
 /// this callback.
 /// </summary>
 protected virtual CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return null;
 }
示例#24
0
文件: CefFrame.cs 项目: rajsite/lvcef
        /// <summary>
        /// Load the request represented by the |request| object.
        /// </summary>
        public void LoadRequest(CefRequest request)
        {
            if (request == null) throw new ArgumentNullException("request");

            cef_frame_t.load_request(_self, request.ToNative());
        }
示例#25
0
 /// <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);
        protected override CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request)
        {
            if (browser == null || request == null)
            {
                API.Instance.Log("Browser null - Frame null: requested with null browser or request (rapidly opening and closing?)");
                return null;
            }

            BrowserWrapper browserWrapper;

            if (BrowserManager.Instance.TryGetBrowser(browser.Identifier, out browserWrapper))
            {
                return new AssetSchemeHandler(browserWrapper.BrowserConfig, request);
            }
            else
            {
                API.Instance.Log("Browser {0} - Frame {1}: {2} scheme with request {3} failed to locate browser config; Defaulting", browser.Identifier, (frame != null) ? frame.Identifier : -1, schemeName, request.Url);
                return null;
            }
        }
示例#27
0
 /// <summary>
 /// Called before browser navigation. Return true to cancel the navigation or
 /// false to allow the navigation to proceed. The |request| object cannot be
 /// modified in this callback.
 /// </summary>
 protected virtual bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect)
 {
     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)
            {
                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;
        }
示例#29
0
 /// <summary>
 /// Called on the IO thread before a resource request is loaded. The |request|
 /// object may be modified. To cancel the request return true otherwise return
 /// false.
 /// </summary>
 protected virtual bool OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return(false);
 }
示例#30
0
 /// <summary>
 /// Called on the IO thread to handle requests for URLs with an unknown
 /// protocol component. The |browser| and |frame| values represent the source
 /// of the request, and may be NULL for requests originating from service
 /// workers or CefURLRequest. |request| cannot be modified in this callback.
 /// Set |allow_os_execution| to true to attempt execution via the registered OS
 /// protocol handler, if any.
 /// SECURITY WARNING: YOU SHOULD USE THIS METHOD TO ENFORCE RESTRICTIONS BASED
 /// ON SCHEME, HOST OR OTHER URL ANALYSIS BEFORE ALLOWING OS EXECUTION.
 /// </summary>
 protected virtual void OnProtocolExecution(CefBrowser browser, CefFrame frame, CefRequest request, ref bool allowOSExecution)
 {
 }
示例#31
0
 /// <summary>
 /// Called on the IO thread before a resource request is loaded. The |request|
 /// object may be modified. Return RV_CONTINUE to continue the request
 /// immediately. Return RV_CONTINUE_ASYNC and call CefRequestCallback::
 /// Continue() 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, CefRequestCallback callback)
 {
     return(CefReturnValue.Continue);
 }
示例#32
0
 /// <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 optionally
 /// filter cookies for the request return a CefCookieAccessFilter object. The
 /// |request| object cannot not be modified in this callback.
 /// </summary>
 protected abstract CefCookieAccessFilter GetCookieAccessFilter(CefBrowser browser, CefFrame frame, CefRequest request);
示例#33
0
 /// <summary>
 /// Called on the IO thread when a resource load is redirected. The |request|
 /// parameter will contain the old URL and other request-related information.
 /// The |response| parameter will contain the response that resulted in the
 /// redirect. The |new_url| parameter will contain the new URL and can be
 /// changed if desired. The |request| object cannot be modified in this
 /// callback.
 /// </summary>
 protected virtual void OnResourceRedirect(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, ref string newUrl)
 {
 }
示例#34
0
 /// <summary>
 /// Called on the IO thread before sending a network request with a "Cookie"
 /// request header. Return true to allow cookies to be included in the network
 /// request or false to block cookies. The |request| object should not be
 /// modified in this callback.
 /// </summary>
 protected virtual bool CanGetCookies(CefBrowser browser, CefFrame frame, CefRequest request)
 {
     return(true);
 }
示例#35
0
 /// <summary>
 /// Called on the IO thread to optionally filter resource response content.
 /// |request| and |response| represent the request and response respectively
 /// and cannot be modified in this callback.
 /// </summary>
 protected virtual CefResponseFilter GetResourceResponseFilter(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response)
 {
     return(null);
 }
示例#36
0
 /// <summary>
 /// Called on the IO thread when receiving a network request with a
 /// "Set-Cookie" response header value represented by |cookie|. Return true to
 /// allow the cookie to be stored or false to block the cookie. The |request|
 /// object should not be modified in this callback.
 /// </summary>
 protected virtual bool CanSetCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefCookie cookie)
 {
     return(true);
 }
示例#37
0
 /// <summary>
 /// Called on the UI thread before browser navigation. Return true to cancel
 /// the navigation or false to allow the navigation to proceed. The |request|
 /// object cannot be modified in this callback.
 /// CefLoadHandler::OnLoadingStateChange will be called twice in all cases.
 /// If the navigation is allowed CefLoadHandler::OnLoadStart and
 /// CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled
 /// CefLoadHandler::OnLoadError will be called with an |errorCode| value of
 /// ERR_ABORTED.
 /// </summary>
 protected virtual bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
 {
     return(false);
 }
 /// <summary>
 /// Called on the IO thread before a resource request is sent. The |browser|
 /// and |frame| values represent the source of the request, and may be NULL for
 /// requests originating from service workers or CefURLRequest. |request|
 /// cannot be modified in this callback. Return true if the specified cookie
 /// can be sent with the request or false otherwise.
 /// </summary>
 protected abstract bool CanSendCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefCookie cookie);
 /// <summary>
 /// Called on the IO thread after a resource response is received. The
 /// |browser| and |frame| values represent the source of the request, and may
 /// be NULL for requests originating from service workers or CefURLRequest.
 /// |request| cannot be modified in this callback. Return true if the specified
 /// cookie returned with the response can be saved or false otherwise.
 /// </summary>
 protected abstract bool CanSaveCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefCookie cookie);
 /// <summary>
 /// Called on the UI thread before browser navigation. Return true to cancel
 /// the navigation or false to allow the navigation to proceed. The |request|
 /// object cannot be modified in this callback.
 /// CefLoadHandler::OnLoadingStateChange will be called twice in all cases.
 /// If the navigation is allowed CefLoadHandler::OnLoadStart and
 /// CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled
 /// CefLoadHandler::OnLoadError will be called with an |errorCode| value of
 /// ERR_ABORTED.
 /// </summary>
 protected virtual bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect)
 {
     return false;
 }
示例#41
0
 /// <summary>
 /// Return a new resource handler instance to handle the request or an empty
 /// reference to allow default handling of the request. |browser| and |frame|
 /// will be the browser window and frame respectively that originated the
 /// request or NULL if the request did not originate from a browser window
 /// (for example, if the request came from CefURLRequest). The |request| object
 /// passed to this method will not contain cookie data.
 /// </summary>
 protected abstract CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request);
示例#42
0
 /// <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);