// Copyright © 2010-2014 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 System.Threading.Tasks;
namespace CefSharp
{
public interface IWebBrowser : IDisposable
{
///
/// Event handler for receiving Javascript console messages being sent from web pages.
///
event ConsoleMessageEventHandler ConsoleMessage;
///
/// Event handler for changes to the status message.
///
event StatusMessageEventHandler StatusMessage;
///
/// 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.
///
event FrameLoadStartEventHandler FrameLoadStart;
///
/// 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.
///
event FrameLoadEndEventHandler FrameLoadEnd;
///
/// Event handler that will get called when the resource load for a navigation fails or is canceled.
///
event LoadErrorEventHandler LoadError;
///
/// Loads the specified URL.
///
/// The URL to be loaded.
void Load(string url);
///
/// Loads custom HTML content into the web browser.
///
/// The HTML content.
/// The URL that will be treated as the address of the content.
void LoadHtml(string html, string url);
///
/// Registers a Javascript object in this specific browser instance.
///
/// The name of the object. (e.g. "foo", if you want the object to be accessible as window.foo).
/// The object to be made accessible to Javascript.
void RegisterJsObject(string name, object objectToBind);
///
/// Execute some Javascript code in the context of this WebBrowser. As the method name implies, the script will be
/// executed asynchronously, and the method therefore returns before the script has actually been executed.
///
/// The Javascript code that should be executed.
void ExecuteScriptAsync(string script);
///
/// Execute some Javascript code in the context of this WebBrowser, and return the result of the evaluation
/// in an Async fashion
///
/// The Javascript code that should be executed.
/// The timeout after which the Javascript code execution should be aborted.
/// /// A Task that can be awaited to perform the script execution
Task EvaluateScriptAsync(string script, TimeSpan? timeout = null);
IDialogHandler DialogHandler { get; set; }
IRequestHandler RequestHandler { get; set; }
ILifeSpanHandler LifeSpanHandler { get; set; }
IKeyboardHandler KeyboardHandler { get; set; }
IJsDialogHandler JsDialogHandler { get; set; }
IDownloadHandler DownloadHandler { get; set; }
bool IsBrowserInitialized { get; }
///
/// A flag that indicates whether the control is currently loading one or more web pages (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool IsLoading { get; set; }
///
/// A flag that indicates whether the state of the control current supports the GoBack action (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool CanGoBack { get; }
///
/// A flag that indicates whether the state of the control currently supports the GoForward action (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool CanGoForward { get; }
///
/// A flag that indicates whether the state of the control currently supports the Reload action (true) or not (false).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
bool CanReload { get; }
///
/// The address (URL) which the browser control is currently displaying. Can be set to a simplified URL
/// (e.g. www.google.com) or a full URL (e.g. http://www.google.com). Will automatically be updated as the user
/// navigates to another page (e.g. by clicking on a link).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
string Address { get; set; }
///
/// The title of the web page being currently displayed.
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
string Title { get; }
string TooltipText { get; set; }
///
/// The zoom level at which the browser control is currently displaying. Can be set to 0 to clear the zoom level (resets to
/// default zoom level).
///
/// In the WPF control, this property is implemented as a Dependency Property and fully supports data
/// binding.
double ZoomLevel { get; set; }
///
/// Url which can be loaded in a browser control to view the dev tools
///
string DevToolsUrl { get; }
///
/// Search for text within the current page.
///
/// Can be used in can conjunction with searchText to have multiple
/// searches running simultaneously.
/// search text
/// indicates whether to search forward or backward within the page.
/// indicates whether the search should be case-sensitive.
/// indicates whether this is the first request or a follow-up.
void Find(int identifier, string searchText, bool forward, bool matchCase, bool findNext);
///
/// Cancel all searches that are currently going on.
///
/// clear the current search selection
void StopFinding(bool clearSelection);
///
/// Stops loading the current page.
///
void Stop();
///
/// Retrieve the main frame's HTML source using a .
///
/// that when executed returns the frame source as a string
Task GetSourceAsync();
///
/// Retrieve the main frame's display text using a .
///
/// that when executed returns the frame display text as a string.
Task GetTextAsync();
///
/// Opens up a new program window (using the default text editor) where the source code of the currently displayed web
/// page is shown.
///
void ViewSource();
///
/// Attempts to give focus to the IWpfWebBrowser control.
///
/// true if keyboard focus and logical focus were set to this element; false if only logical focus
/// was set to this element, or if the call to this method did not force the focus to change.
bool Focus();
///
/// Reloads the page being displayed. This method will use data from the browser's cache, if available.
///
void Reload();
///
/// Reloads the page being displayed, optionally ignoring the cache (which means the whole page including all .css, .js
/// etc. resources will be re-fetched).
///
/// true A reload is performed ignoring brwpser cache; false A reload is
/// performed using files from the browser cache, if available.
void Reload(bool ignoreCache);
}
}