private Task<IWebBrowserWindowProvider> InitTask(string fullpath, IWebSessionLogger logger) { TaskCompletionSource<IWebBrowserWindowProvider> tcs = new TaskCompletionSource<IWebBrowserWindowProvider>(); Task.Run(async () => { var cefWindowInfo = CefWindowInfo.Create(); cefWindowInfo.SetAsWindowless(IntPtr.Zero, true); //// Settings for the browser window itself (e.g. enable JavaScript?). var cefBrowserSettings = new CefBrowserSettings(); // Initialize some the cust interactions with the browser process. var cefClient = new TestCefClient(); // Start up the browser instance. CefBrowserHost.CreateBrowser(cefWindowInfo, cefClient, cefBrowserSettings, fullpath); _CefBrowser = await cefClient.GetLoadedBrowserAsync(); _CefFrame = _CefBrowser.GetMainFrame(); _TestCefGlueHTMLWindowProvider = new TestCefGlueHTMLWindowProvider(_CefFrame, cefClient); tcs.SetResult(_TestCefGlueHTMLWindowProvider); }); return tcs.Task; }
public LoadErrorEventArgs(CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl) { Frame = frame; ErrorCode = errorCode; ErrorText = errorText; FailedUrl = failedUrl; }
protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) { if (OnLoadEndEvent != null) { OnLoadEndEvent(browser, frame, httpStatusCode); } }
protected override void OnAddressChange( CefBrowser browser, CefFrame frame, string url ) { if( frame.IsMain ) { owner.OnAddressChanged( url ); } }
internal IWebView GetContext(CefFrame frame) { var taskCompletionSource = _TaskCompletionSources.GetOrDefault(frame.Identifier); if (taskCompletionSource != null) return taskCompletionSource.Task.Result; return _Associated.GetOrDefault(frame.Identifier); }
protected override void OnLoadStart(CefBrowser browser, CefFrame frame) { base.OnLoadStart(browser, frame); var message = CefProcessMessage.Create("SetOverlayAPI"); message.Arguments.SetString(0, frame.Name); browser.SendProcessMessage(CefProcessId.Renderer, message); }
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 }
internal void EnsureLoaded(CefFrame frame) { var view = GetContext(frame); if (view != null) return; var taskCompletionSource = new TaskCompletionSource<IWebView>(); _TaskCompletionSources.Add(frame.Identifier, taskCompletionSource); //run dummy script to load context frame.ExecuteJavaScript("(function(){})()", string.Empty, 0); }
internal OnQueryEventArgs(CefBrowser _browser, CefFrame _frame, long _queryId, string _request, bool _persistent, CefMessageRouterBrowserSide.Callback _callback) { browser = _browser; frame = _frame; queryId = _queryId; request = _request; persistent = _persistent; callback = _callback; Handled = false; //default return value }
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; }
internal void Associate(CefBrowser browser, CefFrame frame, CefV8Context context) { var webView = new CefV8_WebView(context,context.GetTaskRunner()); var taskCompletionSource = _TaskCompletionSources.GetOrDefault(frame.Identifier); if (taskCompletionSource!=null) { _TaskCompletionSources.Remove(frame.Identifier); taskCompletionSource.TrySetResult(webView); } _Associated.Add(frame.Identifier, webView); }
protected override bool OnBeforePopup( CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess ) { var e = new BeforePopupEventArgs( frame, targetUrl, targetFrameName, popupFeatures, windowInfo, client, settings, noJavascriptAccess ); this.owner.OnBeforePopup( e ); client = e.Client; noJavascriptAccess = e.NoJavascriptAccess; return e.Handled; }
public override bool OnQuery(CefBrowser browser, CefFrame frame, long queryId, string request, bool persistent, CefMessageRouterBrowserSide.Callback callback) { Debug.WriteLine(DBGPREFIX + "OnQuery called, [" + queryId + " " + (persistent ? "" : "not" + " persistent]: ") + request); var handler = OnQueryEvent; if (handler != null) { Debug.WriteLine(DBGPREFIX + "OnQuery Delegate"); var e = new OnQueryEventArgs(browser, frame, queryId, request, persistent, callback); handler(this, e); return e.Handled; } return false; }
public BeforePopupEventArgs( CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, CefClient client, CefBrowserSettings settings, bool noJavascriptAccess) { Frame = frame; TargetUrl = targetUrl; TargetFrameName = targetFrameName; PopupFeatures = popupFeatures; WindowInfo = windowInfo; Client = client; Settings = settings; NoJavascriptAccess = noJavascriptAccess; }
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> /// Called before a context menu is displayed. |params| provides information /// about the context menu state. |model| initially contains the default /// context menu. The |model| can be cleared to show no context menu or /// modified to show a custom menu. Do not keep references to |params| or /// |model| outside of this callback. /// </summary> protected virtual void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model) { }
/// <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; }
/// <summary> /// Called when the browser is done loading a frame. The |frame| value will /// never be empty -- call the IsMain() method to check if this frame is the /// main frame. Multiple frames may be loading at the same time. Sub-frames may /// start or continue loading after the main frame load has ended. This method /// will not be called for same page navigations (fragments, history state, /// etc.) or for navigations that fail or are canceled before commit. For /// notification of overall browser load status use OnLoadingStateChange /// instead. /// </summary> protected virtual void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) { }
/// <summary> /// Called when a navigation fails or is canceled. This method may be called /// by itself if before commit or in combination with OnLoadStart/OnLoadEnd if /// after commit. |errorCode| is the error code number, |errorText| is the /// error text and |failedUrl| is the URL that failed to load. /// See net\base\net_error_list.h for complete descriptions of the error codes. /// </summary> protected virtual void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl) { }
/// <summary> /// Returns the main (top-level) frame for the browser. In the browser process /// this will return a valid object until after /// CefLifeSpanHandler::OnBeforeClose is called. In the renderer process this /// will return NULL if the main frame is hosted in a different renderer /// process (e.g. for cross-origin sub-frames). The main frame object will /// change during cross-origin navigation or re-navigation after renderer /// process termination (due to crashes, etc). /// </summary> public CefFrame GetMainFrame() { return(CefFrame.FromNativeOrNull( cef_browser_t.get_main_frame(_self) )); }
protected override void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl) { base.OnLoadError(browser, frame, errorCode, errorText, failedUrl); }
protected override void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context) { _MVVMCefApp.Reset(frame); }
/// <summary> /// Called on the IO thread before a new popup browser is created. The /// |browser| and |frame| values represent the source of the popup request. The /// |target_url| and |target_frame_name| values indicate where the popup /// browser should navigate and may be empty if not specified with the request. /// The |target_disposition| value indicates where the user intended to open /// the popup (e.g. current tab, new tab, etc). The |user_gesture| value will /// be true if the popup was opened via explicit user gesture (e.g. clicking a /// link) or false if the popup opened automatically (e.g. via the /// DomContentLoaded event). The |popupFeatures| structure contains additional /// information about the requested popup window. To allow creation of the /// popup browser optionally modify |windowInfo|, |client|, |settings| and /// |no_javascript_access| and return false. To cancel creation of the popup /// browser return true. The |client| and |settings| values will default to the /// source browser's values. If the |no_javascript_access| value is set to /// false the new browser will not be scriptable and may not be hosted in the /// same renderer process as the source browser. /// </summary> protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess) { return(false); }
/// <summary> /// Called when a new message is received from a different process. Return true /// if the message was handled or false otherwise. It is safe to keep a /// reference to |message| outside of this callback. /// </summary> protected virtual bool OnProcessMessageReceived(CefBrowser browser, CefFrame frame, CefProcessId sourceProcess, CefProcessMessage message) { return(false); }
/// <summary> /// Called when a new node in the the browser gets focus. The |node| value may /// be empty if no specific node has gained focus. The node object passed to /// this method represents a snapshot of the DOM at the time this method is /// executed. DOM objects are only valid for the scope of this method. Do not /// keep references to or attempt to access any DOM objects outside the scope /// of this method. /// </summary> protected virtual void OnFocusedNodeChanged(CefBrowser browser, CefFrame frame, CefDomNode node) { }
/// <summary> /// Called for global uncaught exceptions in a frame. Execution of this /// callback is disabled by default. To enable set /// CefSettings.uncaught_exception_stack_size > 0. /// </summary> protected virtual void OnUncaughtException(CefBrowser browser, CefFrame frame, CefV8Context context, CefV8Exception exception, CefV8StackTrace stackTrace) { }
/// <summary> /// Called immediately before the V8 context for a frame is released. No /// references to the context should be kept after this method is called. /// </summary> protected virtual void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context) { }
/// <summary> /// Returns the frame with the specified identifier, or NULL if not found. /// </summary> public CefFrame GetFrame(long identifier) { return(CefFrame.FromNativeOrNull( cef_browser_t.get_frame_byident(_self, identifier) )); }
/// <summary> /// Returns the focused frame for the browser window. /// </summary> public CefFrame GetFocusedFrame() { return(CefFrame.FromNativeOrNull( cef_browser_t.get_focused_frame(_self) )); }
protected override void OnLoadStart( CefBrowser browser, CefFrame frame ) { owner.OnLoadStart( frame ); }
protected override bool OnBeforeNavigation(CefBrowser browser, CefFrame frame, CefRequest request, CefNavigationType navigation_type, bool isRedirect) { return false; }
/// <summary> /// Called when a frame's address has changed. /// </summary> protected virtual void OnAddressChange(CefBrowser browser, CefFrame frame, string url) { }
/// <summary> /// Called on the IO thread before a new popup window is created. The |browser| /// and |frame| parameters represent the source of the popup request. The /// |target_url| and |target_frame_name| values may be empty if none were /// specified with the request. The |popupFeatures| structure contains /// information about the requested popup window. To allow creation of the /// popup window optionally modify |windowInfo|, |client|, |settings| and /// |no_javascript_access| and return false. To cancel creation of the popup /// window return true. The |client| and |settings| values will default to the /// source browser's values. The |no_javascript_access| value indicates whether /// the new browser window should be scriptable and in the same process as the /// source browser. /// </summary> protected virtual bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess) { return false; }
/// <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 when the browser needs credentials from the user. /// |isProxy| indicates whether the host is a proxy server. |host| contains the /// hostname and |port| contains the port number. Return true to continue the /// request and call CefAuthCallback::Continue() when the authentication /// information is available. Return false to cancel the request. /// </summary> protected virtual bool GetAuthCredentials(CefBrowser browser, CefFrame frame, bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback) { return(false); }
/// <summary> /// Returns the frame for this context. This method will return an empty /// reference for WebWorker contexts. /// </summary> public CefFrame GetFrame() { return(CefFrame.FromNativeOrNull( cef_v8context_t.get_frame(_self) )); }
/// <summary> /// Called on the IO thread when a resource load is redirected. The |old_url| /// parameter will contain the old URL. The |new_url| parameter will contain /// the new URL and can be changed if desired. /// </summary> protected virtual void OnResourceRedirect(CefBrowser browser, CefFrame frame, string oldUrl, ref string newUrl) { }
/// <summary> /// Called after a navigation has been committed and before the browser begins /// loading contents in the frame. The |frame| value will never be empty -- /// call the IsMain() method to check if this frame is the main frame. /// |transition_type| provides information about the source of the navigation /// and an accurate value is only available in the browser process. Multiple /// frames may be loading at the same time. Sub-frames may start or continue /// loading after the main frame load has ended. This method will not be called /// for same page navigations (fragments, history state, etc.) or for /// navigations that fail or are canceled before commit. For notification of /// overall browser load status use OnLoadingStateChange instead. /// </summary> protected virtual void OnLoadStart(CefBrowser browser, CefFrame frame, CefTransitionType transitionType) { }
/// <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 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> /// Called on the IO thread when a resource load is redirected. The |browser| /// and |frame| values represent the source of the request, and may be NULL for /// requests originating from service workers or CefURLRequest. 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| and |response| objects cannot be modified /// in this callback. /// </summary> protected virtual void OnResourceRedirect(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, ref string newUrl) { }
public LoadEndEventArgs(CefFrame frame, int httpStatusCode) { Frame = frame; HttpStatusCode = httpStatusCode; }
/// <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 navigationType, bool isRedirect) { return(false); }
protected override void OnLoadEnd( CefBrowser browser, CefFrame frame, int httpStatusCode ) { owner.OnLoadEnd( frame, httpStatusCode ); }
/// <summary> /// Called to execute a command selected from the context menu. Return true if /// the command was handled or false for the default implementation. See /// cef_menu_id_t for the command ids that have default implementations. All /// user-defined command ids should be between MENU_ID_USER_FIRST and /// MENU_ID_USER_LAST. |params| will have the same values as what was passed to /// OnBeforeContextMenu(). Do not keep a reference to |params| outside of this /// callback. /// </summary> protected virtual bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags) { return(false); }
protected override void OnLoadError(CefBrowser browser, CefFrame frame, CefErrorCode errorCode, string errorText, string failedUrl) { this.core.OnLoadError(errorCode); }
/// <summary> /// Called on the IO thread when a resource load has completed. The |browser| /// and |frame| values represent the source of the request, and may be NULL for /// requests originating from service workers or CefURLRequest. |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. /// This method will be called for all requests, including requests that are /// aborted due to CEF shutdown or destruction of the associated browser. In /// cases where the associated browser is destroyed this callback may arrive /// after the CefLifeSpanHandler::OnBeforeClose callback for that browser. The /// CefFrame::IsValid method can be used to test for this situation, and care /// should be taken not to call |browser| or |frame| methods that modify state /// (like LoadURL, SendProcessMessage, etc.) if the frame is invalid. /// </summary> protected virtual void OnResourceLoadComplete(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response, CefUrlRequestStatus status, long receivedContentLength) { }
protected override void OnContextCreated(CefBrowser browser, CefFrame frame, CefV8Context context) { _MVVMCefApp.Associate(browser, frame, context); }
/// <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) { }
/// <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);
/// <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 /// 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); }
protected override void OnLoadEnd(CefBrowser browser, CefFrame frame, int httpStatusCode) { base.OnLoadEnd(browser, frame, httpStatusCode); _LoadEnded.TrySetResult(browser); }
/// <summary> /// Called on the IO thread before a resource 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 allow the /// resource to load using the default network loader return NULL. To specify a /// handler for the resource return a CefResourceHandler object. The |request| /// object cannot not be modified in this callback. /// </summary> protected virtual CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request) { return(null); }
protected override void OnContextReleased(CefBrowser browser, CefFrame frame, CefV8Context context) { Debug.WriteLine(DBGPREFIX + "OnContextReleased called"); _messageRouter.OnContextReleased(browser, frame, context); }
/// <summary> /// Called to allow custom display of the context menu. |params| provides /// information about the context menu state. |model| contains the context menu /// model resulting from OnBeforeContextMenu. For custom display return true /// and execute |callback| either synchronously or asynchronously with the /// selected command ID. For default display return false. Do not keep /// references to |params| or |model| outside of this callback. /// </summary> protected virtual bool RunContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams parameters, CefMenuModel model, CefRunContextMenuCallback callback) { return(false); }
/// <summary> /// Called on the IO thread when 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. To allow the /// resource load to proceed without modification return false. To redirect or /// retry the resource load optionally modify |request| and return true. /// Modification of the request URL will be treated as a redirect. Requests /// handled using the default network loader cannot be redirected in this /// callback. The |response| object cannot be modified in this callback. /// WARNING: Redirecting using this method is deprecated. Use /// OnBeforeResourceLoad or GetResourceHandler to perform redirects. /// </summary> protected virtual bool OnResourceResponse(CefBrowser browser, CefFrame frame, CefRequest request, CefResponse response) { return(false); }
/// <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 will not contain cookie data. /// </summary> protected abstract CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request);
/// <summary> /// Called on the IO thread to optionally filter resource response content. The /// |browser| and |frame| values represent the source of the request, and may /// be NULL for requests originating from service workers or CefURLRequest. /// |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); }