// Copyright © 2015 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
{
///
/// This interface represents a CefFrame object (i.e. a HTML frame)
///
public interface IFrame : IDisposable
{
///
/// True if this object is currently attached to a valid frame.
///
bool IsValid { get; }
///
/// Execute undo in this frame.
///
void Undo();
///
/// Execute redo in this frame.
///
void Redo();
///
/// Execute cut in this frame.
///
void Cut();
///
/// Execute copy in this frame.
///
void Copy();
///
/// Execute paste in this frame.
///
void Paste();
///
/// Execute delete in this frame.
///
void Delete();
///
/// Execute select all in this frame.
///
void SelectAll();
///
/// Save this frame's HTML source to a temporary file and open it in the
/// default text viewing application. This method can only be called from the
/// browser process.
///
void ViewSource();
///
/// Retrieve this frame's HTML source as a string sent to the specified visitor.
///
///
/// a that when executed returns this frame's HTML source as a string.
///
Task GetSourceAsync();
///
/// Retrieve this frame's HTML source as a string sent to the specified visitor.
/// Use the method for a Task based async wrapper
///
/// visitor will receive string values asynchronously
void GetSource(IStringVisitor visitor);
///
/// Retrieve this frame's display text as a string sent to the specified visitor.
///
///
/// a that when executed returns the frame's display text as a string.
///
Task GetTextAsync();
///
/// Retrieve this frame's display text as a string sent to the specified visitor.
/// Use the method for a Task based async wrapper
///
/// visitor will receive string values asynchronously
void GetText(IStringVisitor visitor);
///
/// Load the custom request. LoadRequest can only be used if a renderer process already exists.
/// In newer versions initially loading about:blank no longer creates a renderer process. You
/// can load a Data Uri initially then call this method.
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
/// WARNING: This method will fail with "bad IPC message" reason
/// INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the
/// request origin using some other mechanism (LoadURL, link click, etc).
///
/// request to be loaded in the frame
void LoadRequest(IRequest request);
///
/// Load the specified url.
///
/// url to be loaded in the frame
void LoadUrl(string url);
///
/// Execute a string of JavaScript code in this frame.
///
/// Javascript to execute
/// is the URL where the script in question can be found, if any.
/// The renderer may request this URL to show the developer the source of the error.
/// is the base line number to use for error reporting.
void ExecuteJavaScriptAsync(string code, string scriptUrl = "about:blank", int startLine = 1);
///
/// 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.
/// is the URL where the script in question can be found, if any.
/// is the base line number to use for error reporting.
/// 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, string scriptUrl = "about:blank", int startLine = 1, TimeSpan? timeout = null);
///
/// Returns true if this is the main (top-level) frame.
///
bool IsMain { get; }
///
/// Returns true if this is the focused frame.
///
bool IsFocused { get; }
///
/// Returns the name for this frame. If the frame has an assigned name (for
/// example, set via the iframe "name" attribute) then that value will be
/// returned. Otherwise a unique name will be constructed based on the frame
/// parent hierarchy. The main (top-level) frame will always have an empty name
/// value.
///
string Name { get; }
///
/// Returns the globally unique identifier for this frame or < 0 if the underlying frame does not yet exist.
///
Int64 Identifier { get; }
///
/// Returns the parent of this frame or NULL if this is the main (top-level) frame.
///
IFrame Parent { get; }
///
/// Returns the URL currently loaded in this frame.
///
string Url { get; }
///
/// Returns the browser that this frame belongs to.
///
IBrowser Browser { get; }
///
/// Gets a value indicating whether the frame has been disposed of.
///
bool IsDisposed { get; }
///
/// Create a custom request for use with
///
/// Initialize the PostData object when creating this request
/// A new instance of the request
IRequest CreateRequest(bool initializePostData = true);
///
/// Create a new URL request that will be treated as originating from this frame
/// and the associated browser. This request may be intercepted by the client via
/// or .
/// Use IUrlRequest.Create instead if you do not want the request to have
/// this association, in which case it may be handled differently (see documentation on that method).
///
/// Requests may originate from both the browser process and the render process.
/// For requests originating from the browser process: - POST data may only contain a single element
/// of type PDE_TYPE_FILE or PDE_TYPE_BYTES.
/// For requests originating from the render process: - POST data may only contain a single element of type PDE_TYPE_BYTES.
/// - 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.
///
/// the web request
/// the client
IUrlRequest CreateUrlRequest(IRequest request, IUrlRequestClient client);
}
}