mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 19:25:01 +00:00
44fdfa94c8
* JSB Rewrite - Add CefSharp.RegisterBoundObject javascript method To get around the problem of IPC timing, I've reversed the communication, now it's the render process requesting the bound objects, the implementation is incomplete at this stage, more just a basic proof of concept Rewrite BindingTest.html using QUnit One of the tests doesn't map correctly as it requires def user interaction TODO: - Get objects by name - Rename Messages.h values that relate to this change so they are more descriptive - Better error handling - Caching of objects within a render process - Investigate global context options, don't think it's possible to call an async method directly in the global context # Conflicts: # CefSharp.Example/Resources/BindingTest.html * JSB Improve Request/Response message names * BindingTest.html - Output stress test results * Remove JavascriptRootObject was leftover from time we used WCF to transmit objects * JavascriptObjectRepository - Objects are now sent in the same list with an IsAsync flag Separation when sending over IPC with two unique lists isn't necessary * JavascriptObjectRepository - Return objects by name or return all by default Untabify CefAppUnmanagedWrapper.cpp Add minor comment to CefBrowserWrapper for a reminder that we use Frame Identifier as dictionary key * Add //TODO: JSB comments for work that's left to be done Ideally within a render process we cache bound objects once they've been communicated, It would also be nice to make multiple binding requests so objects can later be added dynamically * JSB Allow multiple calls to CefSharp.RegisterBoundObject Update BindingTest.html to name two distinct calls to different bound objects * JSB - Add some notes about caching, no working implementation yet * JSB - Dynamically Register object on Request * JSB Add ability to unbind an object and rename RegisterBoundObject to BindObjectAsync # Conflicts: # CefSharp.Example/Resources/BindingTest.html * JSB BindObjectAsync - if objects already bound then return false * JSB - Ignore Indexer properties Were previously throwing an exception * JSB - Add LegacyJavascriptBindingEnabled option so preserve existing behaviour This is only useful for SPA application and those that only navigate to pages hosting within a single domain. Any sort of cross-site navigation and a new render process will be spawned and objects won't be bound automatically (You can use the new methods to request they're bound yourself, at least in theory, more testing required on this) * Add LegacyBindingTest.html Current disabled by default. To enable uncomment CefSharpSettings.LegacyJavascriptBindingEnabled = true; in CefExample.cs * RegisterJsObject and RegisterAsyncJsObject can now only be used when CefSharpSettings.LegacyJavascriptBindingEnabled = true See https://github.com/cefsharp/CefSharp/issues/2246 for details
270 lines
14 KiB
C#
270 lines
14 KiB
C#
// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
using System;
|
|
using CefSharp.ModelBinding;
|
|
|
|
namespace CefSharp
|
|
{
|
|
/// <summary>
|
|
/// ChromiumWebBrowser implementations implement this interface. Can be cast to
|
|
/// the concrete implementation to access UI specific features.
|
|
/// </summary>
|
|
/// <seealso cref="System.IDisposable" />
|
|
public interface IWebBrowser : IDisposable
|
|
{
|
|
/// <summary>
|
|
/// Event handler for receiving Javascript console messages being sent from web pages.
|
|
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
|
|
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
|
|
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
|
|
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
|
|
/// </summary>
|
|
event EventHandler<ConsoleMessageEventArgs> ConsoleMessage;
|
|
|
|
/// <summary>
|
|
/// Event handler for changes to the status message.
|
|
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
|
|
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang.
|
|
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
|
|
/// (The exception to this is when your running with settings.MultiThreadedMessageLoop = false, then they'll be the same thread).
|
|
/// </summary>
|
|
event EventHandler<StatusMessageEventArgs> StatusMessage;
|
|
|
|
/// <summary>
|
|
/// Event handler that will get called when the browser begins loading a 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 may not be called for a
|
|
/// particular frame if the load request for that frame fails. For notification of overall browser load status use
|
|
/// OnLoadingStateChange instead.
|
|
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
|
|
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
|
|
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
|
|
/// </summary>
|
|
/// <remarks>Whilst this may seem like a logical place to execute js, it's called before the DOM has been loaded, implement
|
|
/// <see cref="IRenderProcessMessageHandler.OnContextCreated"/> as it's called when the underlying V8Context is created
|
|
/// (Only called for the main frame at this stage)</remarks>
|
|
event EventHandler<FrameLoadStartEventArgs> FrameLoadStart;
|
|
|
|
/// <summary>
|
|
/// Event handler that will get called when the browser is done loading a 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 always be called
|
|
/// for all frames irrespective of whether the request completes successfully.
|
|
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
|
|
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
|
|
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
|
|
/// </summary>
|
|
event EventHandler<FrameLoadEndEventArgs> FrameLoadEnd;
|
|
|
|
/// <summary>
|
|
/// Event handler that will get called when the resource load for a navigation fails or is canceled.
|
|
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
|
|
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
|
|
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
|
|
/// </summary>
|
|
event EventHandler<LoadErrorEventArgs> LoadError;
|
|
|
|
/// <summary>
|
|
/// Event handler that will get called when the Loading state has changed.
|
|
/// This event will be fired twice. Once when loading is initiated either programmatically or
|
|
/// by user action, and once when loading is terminated due to completion, cancellation of failure.
|
|
/// It's important to note this event is fired on a CEF UI thread, which by default is not the same as your application UI
|
|
/// thread. It is unwise to block on this thread for any length of time as your browser will become unresponsive and/or hang..
|
|
/// To access UI elements you'll need to Invoke/Dispatch onto the UI Thread.
|
|
/// </summary>
|
|
event EventHandler<LoadingStateChangedEventArgs> LoadingStateChanged;
|
|
|
|
/// <summary>
|
|
/// Loads the specified URL.
|
|
/// </summary>
|
|
/// <param name="url">The URL to be loaded.</param>
|
|
void Load(string url);
|
|
|
|
/// <summary>
|
|
/// Registers a Javascript object in this specific browser instance.
|
|
/// </summary>
|
|
/// <param name="name">The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).</param>
|
|
/// <param name="objectToBind">The object to be made accessible to Javascript.</param>
|
|
/// <param name="options">binding options - camelCaseJavascriptNames default to true </param>
|
|
void RegisterJsObject(string name, object objectToBind, BindingOptions options = null);
|
|
|
|
/// <summary>
|
|
/// <para>Asynchronously registers a Javascript object in this specific browser instance.</para>
|
|
/// <para>Only methods of the object will be available.</para>
|
|
/// </summary>
|
|
/// <param name="name">The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).</param>
|
|
/// <param name="objectToBind">The object to be made accessible to Javascript.</param>
|
|
/// <param name="options">binding options - camelCaseJavascriptNames default to true </param>
|
|
/// <remarks>The registered methods can only be called in an async way, they will all return immeditaly and the resulting
|
|
/// object will be a standard javascript Promise object which is usable to wait for completion or failure.</remarks>
|
|
void RegisterAsyncJsObject(string name, object objectToBind, BindingOptions options = null);
|
|
|
|
IJavascriptObjectRepository JavascriptObjectRepository { get; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IDialogHandler" /> and assign to handle dialog events.
|
|
/// </summary>
|
|
/// <value>The dialog handler.</value>
|
|
IDialogHandler DialogHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IRequestHandler" /> and assign to handle events related to browser requests.
|
|
/// </summary>
|
|
/// <value>The request handler.</value>
|
|
IRequestHandler RequestHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IDisplayHandler" /> and assign to handle events related to browser display state.
|
|
/// </summary>
|
|
/// <value>The display handler.</value>
|
|
IDisplayHandler DisplayHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="ILoadHandler" /> and assign to handle events related to browser load status.
|
|
/// </summary>
|
|
/// <value>The load handler.</value>
|
|
ILoadHandler LoadHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="ILifeSpanHandler" /> and assign to handle events related to popups.
|
|
/// </summary>
|
|
/// <value>The life span handler.</value>
|
|
ILifeSpanHandler LifeSpanHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IKeyboardHandler" /> and assign to handle events related to key press.
|
|
/// </summary>
|
|
/// <value>The keyboard handler.</value>
|
|
IKeyboardHandler KeyboardHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IJsDialogHandler" /> and assign to handle events related to JavaScript Dialogs.
|
|
/// </summary>
|
|
/// <value>The js dialog handler.</value>
|
|
IJsDialogHandler JsDialogHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IDragHandler" /> and assign to handle events related to dragging.
|
|
/// </summary>
|
|
/// <value>The drag handler.</value>
|
|
IDragHandler DragHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IDownloadHandler" /> and assign to handle events related to downloading files.
|
|
/// </summary>
|
|
/// <value>The download handler.</value>
|
|
IDownloadHandler DownloadHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IContextMenuHandler" /> and assign to handle events related to the browser context menu
|
|
/// </summary>
|
|
/// <value>The menu handler.</value>
|
|
IContextMenuHandler MenuHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IFocusHandler" /> and assign to handle events related to the browser component's focus
|
|
/// </summary>
|
|
/// <value>The focus handler.</value>
|
|
IFocusHandler FocusHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IResourceHandlerFactory" /> and control the loading of resources
|
|
/// </summary>
|
|
/// <value>The resource handler factory.</value>
|
|
IResourceHandlerFactory ResourceHandlerFactory { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IGeolocationHandler" /> and assign to handle requests for permission to use geolocation.
|
|
/// </summary>
|
|
/// <value>The geolocation handler.</value>
|
|
IGeolocationHandler GeolocationHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IRenderProcessMessageHandler" /> and assign to handle messages from the render process.
|
|
/// </summary>
|
|
/// <value>The render process message handler.</value>
|
|
IRenderProcessMessageHandler RenderProcessMessageHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// Implement <see cref="IFindHandler" /> to handle events related to find results.
|
|
/// </summary>
|
|
/// <value>The find handler.</value>
|
|
IFindHandler FindHandler { get; set; }
|
|
|
|
/// <summary>
|
|
/// A flag that indicates whether the WebBrowser is initialized (true) or not (false).
|
|
/// </summary>
|
|
/// <value><c>true</c> if this instance is browser initialized; otherwise, <c>false</c>.</value>
|
|
/// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data
|
|
/// binding.</remarks>
|
|
bool IsBrowserInitialized { get; }
|
|
|
|
/// <summary>
|
|
/// A flag that indicates whether the control is currently loading one or more web pages (true) or not (false).
|
|
/// </summary>
|
|
/// <value><c>true</c> if this instance is loading; otherwise, <c>false</c>.</value>
|
|
/// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data
|
|
/// binding.</remarks>
|
|
bool IsLoading { get; }
|
|
|
|
/// <summary>
|
|
/// A flag that indicates whether the state of the control current supports the GoBack action (true) or not (false).
|
|
/// </summary>
|
|
/// <value><c>true</c> if this instance can go back; otherwise, <c>false</c>.</value>
|
|
/// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data
|
|
/// binding.</remarks>
|
|
bool CanGoBack { get; }
|
|
|
|
/// <summary>
|
|
/// A flag that indicates whether the state of the control currently supports the GoForward action (true) or not (false).
|
|
/// </summary>
|
|
/// <value><c>true</c> if this instance can go forward; otherwise, <c>false</c>.</value>
|
|
/// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data
|
|
/// binding.</remarks>
|
|
bool CanGoForward { get; }
|
|
|
|
/// <summary>
|
|
/// The address (URL) which the browser control is currently displaying.
|
|
/// Will automatically be updated as the user navigates to another page (e.g. by clicking on a link).
|
|
/// </summary>
|
|
/// <value>The address.</value>
|
|
/// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data
|
|
/// binding.</remarks>
|
|
string Address { get; }
|
|
|
|
/// <summary>
|
|
/// The text that will be displayed as a ToolTip
|
|
/// </summary>
|
|
/// <value>The tooltip text.</value>
|
|
string TooltipText { get; }
|
|
|
|
/// <summary>
|
|
/// A flag that indicates if you can execute javascript in the main frame.
|
|
/// Flag is set to true in IRenderProcessMessageHandler.OnContextCreated.
|
|
/// and false in IRenderProcessMessageHandler.OnContextReleased
|
|
/// </summary>
|
|
bool CanExecuteJavascriptInMainFrame { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the custom request context assigned to this browser instance
|
|
/// If no instance was assigned this will be null and the global
|
|
/// request context will have been used for this browser.
|
|
/// You can access the global request context through Cef.GetGlobalRequestContext()
|
|
/// </summary>
|
|
IRequestContext RequestContext { get; }
|
|
|
|
/// <summary>
|
|
/// Attempts to give focus to the IWebBrowser control.
|
|
/// </summary>
|
|
/// <returns><c>true</c> if keyboard focus and logical focus were set to this element; <c>false</c> if only logical focus
|
|
/// was set to this element, or if the call to this method did not force the focus to change.</returns>
|
|
bool Focus();
|
|
|
|
/// <summary>
|
|
/// Returns the current CEF Browser Instance
|
|
/// </summary>
|
|
/// <returns>browser instance or null</returns>
|
|
IBrowser GetBrowser();
|
|
}
|
|
}
|