web_plugin.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
  3. * Copyright (C) 2014 Opera Software ASA. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above
  12. * copyright notice, this list of conditions and the following disclaimer
  13. * in the documentation and/or other materials provided with the
  14. * distribution.
  15. * * Neither the name of Google Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_PLUGIN_H_
  32. #define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_PLUGIN_H_
  33. #include "cc/paint/paint_canvas.h"
  34. #include "third_party/blink/public/common/page/drag_operation.h"
  35. #include "third_party/blink/public/mojom/input/focus_type.mojom-shared.h"
  36. #include "third_party/blink/public/platform/web_string.h"
  37. #include "third_party/blink/public/platform/web_url.h"
  38. #include "third_party/blink/public/web/web_drag_status.h"
  39. #include "third_party/blink/public/web/web_input_method_controller.h"
  40. #include "v8/include/v8.h"
  41. namespace gfx {
  42. class PointF;
  43. } // namespace gfx
  44. namespace ui {
  45. class Cursor;
  46. struct ImeTextSpan;
  47. }
  48. namespace blink {
  49. class WebCoalescedInputEvent;
  50. class WebDragData;
  51. class WebPluginContainer;
  52. class WebURLResponse;
  53. struct WebPrintParams;
  54. struct WebPrintPresetOptions;
  55. struct WebRect;
  56. struct WebURLError;
  57. template <typename T>
  58. class WebVector;
  59. class WebPlugin {
  60. public:
  61. // Initializes the plugin using |container| to communicate with the renderer
  62. // code. |container| must own this plugin. |container| must not be nullptr.
  63. //
  64. // Returns true if a plugin (not necessarily this one) has been successfully
  65. // initialized into |container|.
  66. //
  67. // NOTE: This method is subtle. This plugin may be marked for deletion via
  68. // destroy() during initialization. When this occurs, container() will
  69. // return nullptr. Because deletions during initialize() must be
  70. // asynchronous, this object is still alive immediately after initialize().
  71. // 1) If container() == nullptr and this method returns true, this plugin
  72. // has been replaced by another during initialization. This new plugin
  73. // may be accessed via container->plugin().
  74. // 2) If container() == nullptr and this method returns false, this plugin
  75. // and the container have both been marked for deletion.
  76. virtual bool Initialize(WebPluginContainer*) = 0;
  77. // Plugins must arrange for themselves to be deleted sometime during or after
  78. // this method is called. This method is only called by the owning
  79. // WebPluginContainer.
  80. // The exception is if the plugin has been detached by a WebPluginContainer,
  81. // i.e. been replaced by another plugin. Then it must be destroyed separately.
  82. // Once this method has been called, container() must return nullptr.
  83. virtual void Destroy() = 0;
  84. // Returns the container that this plugin has been initialized with.
  85. // Must return nullptr if this plugin is scheduled for deletion.
  86. //
  87. // NOTE: This container doesn't necessarily own this plugin. For example,
  88. // if the container has been assigned a new plugin, then the container will
  89. // own the new plugin, not this old plugin.
  90. virtual WebPluginContainer* Container() const { return nullptr; }
  91. virtual v8::Local<v8::Object> V8ScriptableObject(v8::Isolate*) {
  92. return v8::Local<v8::Object>();
  93. }
  94. virtual bool SupportsKeyboardFocus() const { return false; }
  95. // Returns true if this plugin supports input method, which implements
  96. // setComposition(), commitText() and finishComposingText() below.
  97. virtual bool SupportsInputMethod() const { return false; }
  98. virtual bool CanProcessDrag() const { return false; }
  99. virtual void UpdateAllLifecyclePhases(blink::DocumentUpdateReason) = 0;
  100. virtual void Paint(cc::PaintCanvas*, const WebRect&) = 0;
  101. // Coordinates are relative to the containing window.
  102. virtual void UpdateGeometry(const WebRect& window_rect,
  103. const WebRect& clip_rect,
  104. const WebRect& unobscured_rect,
  105. bool is_visible) = 0;
  106. virtual void UpdateFocus(bool focused, mojom::FocusType) = 0;
  107. virtual void UpdateVisibility(bool) = 0;
  108. virtual WebInputEventResult HandleInputEvent(const WebCoalescedInputEvent&,
  109. ui::Cursor*) = 0;
  110. virtual bool HandleDragStatusUpdate(WebDragStatus,
  111. const WebDragData&,
  112. DragOperationsMask,
  113. const gfx::PointF& position,
  114. const gfx::PointF& screen_position) {
  115. return false;
  116. }
  117. virtual void DidReceiveResponse(const WebURLResponse&) = 0;
  118. virtual void DidReceiveData(const char* data, size_t data_length) = 0;
  119. virtual void DidFinishLoading() = 0;
  120. virtual void DidFailLoading(const WebURLError&) = 0;
  121. // Printing interface.
  122. // Whether the plugin supports its own paginated print. The other print
  123. // interface methods are called only if this method returns true.
  124. virtual bool SupportsPaginatedPrint() { return false; }
  125. // Returns true on success and sets the out parameter to the print preset
  126. // options for the document.
  127. virtual bool GetPrintPresetOptionsFromDocument(WebPrintPresetOptions*) {
  128. return false;
  129. }
  130. // Returns true if the plugin is a PDF plugin.
  131. virtual bool IsPdfPlugin() { return false; }
  132. // Sets up printing with the specified printParams. Returns the number of
  133. // pages to be printed at these settings.
  134. virtual int PrintBegin(const WebPrintParams& print_params) { return 0; }
  135. virtual void PrintPage(int page_number, cc::PaintCanvas* canvas) {}
  136. // Ends the print operation.
  137. virtual void PrintEnd() {}
  138. virtual bool HasSelection() const { return false; }
  139. virtual WebString SelectionAsText() const { return WebString(); }
  140. virtual WebString SelectionAsMarkup() const { return WebString(); }
  141. virtual bool CanEditText() const { return false; }
  142. virtual bool HasEditableText() const { return false; }
  143. virtual bool CanUndo() const { return false; }
  144. virtual bool CanRedo() const { return false; }
  145. virtual bool ExecuteEditCommand(const WebString& name) { return false; }
  146. virtual bool ExecuteEditCommand(const WebString& name,
  147. const WebString& value) {
  148. return false;
  149. }
  150. // Sets composition text from input method, and returns true if the
  151. // composition is set successfully. If |replacementRange| is not null, the
  152. // text inside |replacementRange| will be replaced by |text|
  153. virtual bool SetComposition(const WebString& text,
  154. const WebVector<ui::ImeTextSpan>& ime_text_spans,
  155. const WebRange& replacement_range,
  156. int selection_start,
  157. int selection_end) {
  158. return false;
  159. }
  160. // Deletes the ongoing composition if any, inserts the specified text, and
  161. // moves the caret according to relativeCaretPosition. If |replacementRange|
  162. // is not null, the text inside |replacementRange| will be replaced by |text|.
  163. virtual bool CommitText(const WebString& text,
  164. const WebVector<ui::ImeTextSpan>& ime_text_spans,
  165. const WebRange& replacement_range,
  166. int relative_caret_position) {
  167. return false;
  168. }
  169. // Confirms an ongoing composition; holds or moves selections accroding to
  170. // selectionBehavior.
  171. virtual bool FinishComposingText(
  172. WebInputMethodController::ConfirmCompositionBehavior selection_behavior) {
  173. return false;
  174. }
  175. // Deletes the current selection plus the specified number of characters
  176. // before and after the selection or caret.
  177. virtual void ExtendSelectionAndDelete(int before, int after) {}
  178. // Deletes text before and after the current cursor position, excluding the
  179. // selection. The lengths are supplied in UTF-16 Code Unit, not in code points
  180. // or in glyphs.
  181. virtual void DeleteSurroundingText(int before, int after) {}
  182. // Deletes text before and after the current cursor position, excluding the
  183. // selection. The lengths are supplied in code points, not in UTF-16 Code Unit
  184. // or in glyphs. Do nothing if there are one or more invalid surrogate pairs
  185. // in the requested range.
  186. virtual void DeleteSurroundingTextInCodePoints(int before, int after) {}
  187. // If the given position is over a link, returns the absolute url.
  188. // Otherwise an empty url is returned.
  189. virtual WebURL LinkAtPosition(const gfx::Point& position) const {
  190. return WebURL();
  191. }
  192. // Find interface.
  193. // Start a new search. The plugin should search for a little bit at a time so
  194. // that it doesn't block the thread in case of a large document. The results,
  195. // along with the find's identifier, should be sent asynchronously to
  196. // WebLocalFrameClient's reportFindInPage* methods.
  197. // Returns true if the search started, or false if the plugin doesn't support
  198. // search.
  199. virtual bool StartFind(const WebString& search_text,
  200. bool case_sensitive,
  201. int identifier) {
  202. return false;
  203. }
  204. // Tells the plugin to jump forward or backward in the list of find results.
  205. virtual void SelectFindResult(bool forward, int identifier) {}
  206. // Tells the plugin that the user has stopped the find operation.
  207. virtual void StopFind() {}
  208. // View rotation types.
  209. enum RotationType {
  210. kRotationType90Clockwise,
  211. kRotationType90Counterclockwise
  212. };
  213. // Whether the plugin can rotate the view of its content.
  214. virtual bool CanRotateView() { return false; }
  215. // Rotates the plugin's view of its content.
  216. virtual void RotateView(RotationType type) {}
  217. // Check whether a plugin can be interacted with. A positive return value
  218. // means the plugin has not loaded and hence cannot be interacted with.
  219. // The plugin could, however, load successfully later.
  220. virtual bool IsPlaceholder() { return true; }
  221. // Check whether a plugin failed to load, with there being no possibility of
  222. // it loading later.
  223. virtual bool IsErrorPlaceholder() { return false; }
  224. protected:
  225. virtual ~WebPlugin() = default;
  226. };
  227. } // namespace blink
  228. #endif // THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_PLUGIN_H_