/CefSharp/IFrame.cs

https://github.com/cefsharp/CefSharp · C# · 203 lines · 35 code · 28 blank · 140 comment · 0 complexity · 6665f65b45555a770ed08aeda879e389 MD5 · raw file

  1. // Copyright © 2015 The CefSharp Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  4. using System;
  5. using System.Threading.Tasks;
  6. namespace CefSharp
  7. {
  8. /// <summary>
  9. /// This interface represents a CefFrame object (i.e. a HTML frame)
  10. /// </summary>
  11. public interface IFrame : IDisposable
  12. {
  13. /// <summary>
  14. /// True if this object is currently attached to a valid frame.
  15. /// </summary>
  16. bool IsValid { get; }
  17. /// <summary>
  18. /// Execute undo in this frame.
  19. /// </summary>
  20. void Undo();
  21. /// <summary>
  22. /// Execute redo in this frame.
  23. /// </summary>
  24. void Redo();
  25. /// <summary>
  26. /// Execute cut in this frame.
  27. /// </summary>
  28. void Cut();
  29. /// <summary>
  30. /// Execute copy in this frame.
  31. /// </summary>
  32. void Copy();
  33. /// <summary>
  34. /// Execute paste in this frame.
  35. /// </summary>
  36. void Paste();
  37. /// <summary>
  38. /// Execute delete in this frame.
  39. /// </summary>
  40. void Delete();
  41. /// <summary>
  42. /// Execute select all in this frame.
  43. /// </summary>
  44. void SelectAll();
  45. /// <summary>
  46. /// Save this frame's HTML source to a temporary file and open it in the
  47. /// default text viewing application. This method can only be called from the
  48. /// browser process.
  49. /// </summary>
  50. void ViewSource();
  51. /// <summary>
  52. /// Retrieve this frame's HTML source as a string sent to the specified visitor.
  53. /// </summary>
  54. /// <returns>
  55. /// a <see cref="Task{String}"/> that when executed returns this frame's HTML source as a string.
  56. /// </returns>
  57. Task<string> GetSourceAsync();
  58. /// <summary>
  59. /// Retrieve this frame's HTML source as a string sent to the specified visitor.
  60. /// Use the <see cref="GetSourceAsync"/> method for a Task based async wrapper
  61. /// </summary>
  62. /// <param name="visitor">visitor will receive string values asynchronously</param>
  63. void GetSource(IStringVisitor visitor);
  64. /// <summary>
  65. /// Retrieve this frame's display text as a string sent to the specified visitor.
  66. /// </summary>
  67. /// <returns>
  68. /// a <see cref="Task{String}"/> that when executed returns the frame's display text as a string.
  69. /// </returns>
  70. Task<string> GetTextAsync();
  71. /// <summary>
  72. /// Retrieve this frame's display text as a string sent to the specified visitor.
  73. /// Use the <see cref="GetTextAsync"/> method for a Task based async wrapper
  74. /// </summary>
  75. /// <param name="visitor">visitor will receive string values asynchronously</param>
  76. void GetText(IStringVisitor visitor);
  77. /// <summary>
  78. /// Load the custom request.
  79. /// WARNING: This method will fail with "bad IPC message" reason
  80. /// INVALID_INITIATOR_ORIGIN (213) unless you first navigate to the
  81. /// request origin using some other mechanism (LoadURL, link click, etc).
  82. /// </summary>
  83. /// <param name="request">request to be loaded in the frame</param>
  84. void LoadRequest(IRequest request);
  85. /// <summary>
  86. /// Load the specified url.
  87. /// </summary>
  88. /// <param name="url">url to be loaded in the frame</param>
  89. void LoadUrl(string url);
  90. /// <summary>
  91. /// Execute a string of JavaScript code in this frame.
  92. /// </summary>
  93. /// <param name="code">Javascript to execute</param>
  94. /// <param name="scriptUrl">is the URL where the script in question can be found, if any.
  95. /// The renderer may request this URL to show the developer the source of the error.</param>
  96. /// <param name="startLine">is the base line number to use for error reporting.</param>
  97. void ExecuteJavaScriptAsync(string code, string scriptUrl = "about:blank", int startLine = 1);
  98. /// <summary>
  99. /// Execute some Javascript code in the context of this WebBrowser, and return the result of the evaluation
  100. /// in an Async fashion
  101. /// </summary>
  102. /// <param name="script">The Javascript code that should be executed.</param>
  103. /// <param name="scriptUrl">is the URL where the script in question can be found, if any.</param>
  104. /// <param name="startLine">is the base line number to use for error reporting.</param>
  105. /// <param name="timeout">The timeout after which the Javascript code execution should be aborted.</param>
  106. /// <param name="useImmediatelyInvokedFuncExpression">When true the script is wrapped in a self executing function.
  107. /// Make sure to use a return statement in your javascript. e.g. (function () { return 42; })();
  108. /// When false don't include a return statement e.g. 42;
  109. /// </param>
  110. /// <returns>A Task that can be awaited to perform the script execution</returns>
  111. Task<JavascriptResponse> EvaluateScriptAsync(string script, string scriptUrl = "about:blank", int startLine = 1, TimeSpan? timeout = null, bool useImmediatelyInvokedFuncExpression = false);
  112. /// <summary>
  113. /// Returns true if this is the main (top-level) frame.
  114. /// </summary>
  115. bool IsMain { get; }
  116. /// <summary>
  117. /// Returns true if this is the focused frame.
  118. /// </summary>
  119. bool IsFocused { get; }
  120. /// <summary>
  121. /// Returns the name for this frame. If the frame has an assigned name (for
  122. /// example, set via the iframe "name" attribute) then that value will be
  123. /// returned. Otherwise a unique name will be constructed based on the frame
  124. /// parent hierarchy. The main (top-level) frame will always have an empty name
  125. /// value.
  126. /// </summary>
  127. string Name { get; }
  128. /// <summary>
  129. /// Returns the globally unique identifier for this frame or &lt; 0 if the underlying frame does not yet exist.
  130. /// </summary>
  131. Int64 Identifier { get; }
  132. /// <summary>
  133. /// Returns the parent of this frame or NULL if this is the main (top-level) frame.
  134. /// </summary>
  135. IFrame Parent { get; }
  136. /// <summary>
  137. /// Returns the URL currently loaded in this frame.
  138. /// </summary>
  139. string Url { get; }
  140. /// <summary>
  141. /// Returns the browser that this frame belongs to.
  142. /// </summary>
  143. IBrowser Browser { get; }
  144. /// <summary>
  145. /// Gets a value indicating whether the frame has been disposed of.
  146. /// </summary>
  147. bool IsDisposed { get; }
  148. /// <summary>
  149. /// Create a custom request for use with <see cref="LoadRequest"/>
  150. /// </summary>
  151. /// <param name="initializePostData">Initialize the PostData object when creating this request</param>
  152. /// <returns>A new instance of the request</returns>
  153. IRequest CreateRequest(bool initializePostData = true);
  154. /// <summary>
  155. /// Create a new URL request that will be treated as originating from this frame
  156. /// and the associated browser. This request may be intercepted by the client via
  157. /// <see cref="IResourceRequestHandler"/> or <see cref="ISchemeHandlerFactory"/>.
  158. /// Use IUrlRequest.Create instead if you do not want the request to have
  159. /// this association, in which case it may be handled differently (see documentation on that method).
  160. ///
  161. /// Requests may originate from both the browser process and the render process.
  162. /// For requests originating from the browser process: - POST data may only contain a single element
  163. /// of type PDE_TYPE_FILE or PDE_TYPE_BYTES.
  164. /// For requests originating from the render process: - POST data may only contain a single element of type PDE_TYPE_BYTES.
  165. /// - If the response contains Content-Disposition or Mime-Type header values that would not normally be rendered then
  166. /// the response may receive special handling inside the browser
  167. /// for example, via the file download code path instead of the URL request code path).
  168. ///
  169. /// The request object will be marked as read-only after calling this method.
  170. /// </summary>
  171. /// <param name="request">the web request</param>
  172. /// <param name="client">the client</param>
  173. IUrlRequest CreateUrlRequest(IRequest request, IUrlRequestClient client);
  174. }
  175. }