Plugin.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef Plugin_h
  26. #define Plugin_h
  27. #include <WebCore/FindOptions.h>
  28. #include <WebCore/GraphicsLayer.h>
  29. #include <WebCore/KURL.h>
  30. #include <WebCore/ScrollTypes.h>
  31. #include <WebCore/SecurityOrigin.h>
  32. #include <wtf/RefCounted.h>
  33. #include <wtf/RetainPtr.h>
  34. #include <wtf/Vector.h>
  35. #if PLATFORM(MAC)
  36. #include "LayerHostingContext.h"
  37. OBJC_CLASS NSObject;
  38. OBJC_CLASS PDFDocument;
  39. #endif
  40. struct NPObject;
  41. namespace CoreIPC {
  42. class ArgumentEncoder;
  43. class ArgumentDecoder;
  44. }
  45. namespace WebCore {
  46. class AffineTransform;
  47. class FloatPoint;
  48. class GraphicsContext;
  49. class IntPoint;
  50. class IntRect;
  51. class IntSize;
  52. class FloatPoint;
  53. class Scrollbar;
  54. class SharedBuffer;
  55. }
  56. namespace WebKit {
  57. class ShareableBitmap;
  58. class WebKeyboardEvent;
  59. class WebMouseEvent;
  60. class WebWheelEvent;
  61. class PluginController;
  62. class Plugin : public ThreadSafeRefCounted<Plugin> {
  63. public:
  64. struct Parameters {
  65. WebCore::KURL url;
  66. Vector<String> names;
  67. Vector<String> values;
  68. String mimeType;
  69. bool isFullFramePlugin;
  70. bool shouldUseManualLoader;
  71. #if PLATFORM(MAC)
  72. LayerHostingMode layerHostingMode;
  73. #endif
  74. void encode(CoreIPC::ArgumentEncoder&) const;
  75. static bool decode(CoreIPC::ArgumentDecoder&, Parameters&);
  76. };
  77. // Sets the active plug-in controller and initializes the plug-in.
  78. bool initialize(PluginController*, const Parameters&);
  79. virtual bool isBeingAsynchronouslyInitialized() const = 0;
  80. // Destroys the plug-in.
  81. void destroyPlugin();
  82. // Returns the plug-in controller for this plug-in.
  83. PluginController* controller() { return m_pluginController; }
  84. const PluginController* controller() const { return m_pluginController; }
  85. virtual ~Plugin();
  86. private:
  87. // Initializes the plug-in. If the plug-in fails to initialize this should return false.
  88. // This is only called by the other initialize overload so it can be made private.
  89. virtual bool initialize(const Parameters&) = 0;
  90. // Destroys the plug-in.
  91. virtual void destroy() = 0;
  92. public:
  93. // Tells the plug-in to paint itself into the given graphics context. The passed-in context and
  94. // dirty rect are in window coordinates. The context is saved/restored by the caller.
  95. virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect) = 0;
  96. // Invalidate native tintable controls. The passed-in context is in window coordinates.
  97. virtual void updateControlTints(WebCore::GraphicsContext*);
  98. // Returns whether the plug-in supports snapshotting or not.
  99. virtual bool supportsSnapshotting() const = 0;
  100. // Tells the plug-in to draw itself into a bitmap, and return that.
  101. virtual PassRefPtr<ShareableBitmap> snapshot() = 0;
  102. #if PLATFORM(MAC)
  103. // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer.
  104. virtual PlatformLayer* pluginLayer() = 0;
  105. #endif
  106. // Returns whether the plug-in is transparent or not.
  107. virtual bool isTransparent() = 0;
  108. // Returns whether we should send wheel events to this plug-in.
  109. virtual bool wantsWheelEvents() = 0;
  110. // Tells the plug-in that its geometry has changed. The clip rect is in plug-in coordinates, and the affine transform can be used
  111. // to convert from root view coordinates to plug-in coordinates.
  112. virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform) = 0;
  113. // Tells the plug-in that it has been explicitly hidden or shown. (Note that this is not called when the plug-in becomes obscured from view on screen.)
  114. virtual void visibilityDidChange() = 0;
  115. // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has finished.
  116. virtual void frameDidFinishLoading(uint64_t requestID) = 0;
  117. // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has failed.
  118. virtual void frameDidFail(uint64_t requestID, bool wasCancelled) = 0;
  119. // Tells the plug-in that a request to evaluate JavaScript (using PluginController::loadURL) has been fulfilled and passes
  120. // back the result. If evaluating the script failed, result will be null.
  121. virtual void didEvaluateJavaScript(uint64_t requestID, const String& result) = 0;
  122. // Tells the plug-in that a stream has received its HTTP response.
  123. virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength,
  124. uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName) = 0;
  125. // Tells the plug-in that a stream did receive data.
  126. virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0;
  127. // Tells the plug-in that a stream has finished loading.
  128. virtual void streamDidFinishLoading(uint64_t streamID) = 0;
  129. // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled.
  130. virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0;
  131. // Tells the plug-in that the manual stream has received its HTTP response.
  132. virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength,
  133. uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName) = 0;
  134. // Tells the plug-in that the manual stream did receive data.
  135. virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0;
  136. // Tells the plug-in that a stream has finished loading.
  137. virtual void manualStreamDidFinishLoading() = 0;
  138. // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled.
  139. virtual void manualStreamDidFail(bool wasCancelled) = 0;
  140. // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event.
  141. virtual bool handleMouseEvent(const WebMouseEvent&) = 0;
  142. // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event.
  143. virtual bool handleWheelEvent(const WebWheelEvent&) = 0;
  144. // Tells the plug-in to handle the passed in mouse over event. The plug-in should return true if it processed the event.
  145. virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0;
  146. // Tells the plug-in to handle the passed in mouse leave event. The plug-in should return true if it processed the event.
  147. virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0;
  148. // Tells the plug-in to handle the passed in context menu event. The plug-in should return true if it processed the event.
  149. virtual bool handleContextMenuEvent(const WebMouseEvent&) = 0;
  150. // Tells the plug-in to handle the passed in keyboard event. The plug-in should return true if it processed the event.
  151. virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0;
  152. // Tells the plug-in to handle the passed in editing command. The plug-in should return true if it executed the command.
  153. virtual bool handleEditingCommand(const String& commandName, const String& argument) = 0;
  154. // Ask the plug-in whether it will be able to handle the given editing command.
  155. virtual bool isEditingCommandEnabled(const String&) = 0;
  156. // Ask the plug-in whether it should be allowed to execute JavaScript or navigate to JavaScript URLs.
  157. virtual bool shouldAllowScripting() = 0;
  158. // Ask the plug-in whether it wants URLs and files dragged onto it to cause navigation.
  159. virtual bool shouldAllowNavigationFromDrags() = 0;
  160. // Ask the plug-in whether it wants to override full-page zoom.
  161. virtual bool handlesPageScaleFactor() = 0;
  162. // Tells the plug-in about focus changes.
  163. virtual void setFocus(bool) = 0;
  164. // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object.
  165. virtual NPObject* pluginScriptableNPObject() = 0;
  166. #if PLATFORM(MAC)
  167. // Tells the plug-in about window focus changes.
  168. virtual void windowFocusChanged(bool) = 0;
  169. // Tells the plug-in about window and plug-in frame changes.
  170. virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0;
  171. // Tells the plug-in about window visibility changes.
  172. virtual void windowVisibilityChanged(bool) = 0;
  173. // Get the per complex text input identifier.
  174. virtual uint64_t pluginComplexTextInputIdentifier() const = 0;
  175. // Send the complex text input to the plug-in.
  176. virtual void sendComplexTextInput(const String& textInput) = 0;
  177. // Tells the plug-in about changes to the layer hosting mode.
  178. virtual void setLayerHostingMode(LayerHostingMode) = 0;
  179. #endif
  180. // Tells the plug-in about scale factor changes.
  181. virtual void contentsScaleFactorChanged(float) = 0;
  182. // Called when the storage blocking policy for this plug-in changes.
  183. virtual void storageBlockingStateChanged(bool) = 0;
  184. // Called when the private browsing state for this plug-in changes.
  185. virtual void privateBrowsingStateChanged(bool) = 0;
  186. // Gets the form value representation for the plug-in, letting plug-ins participate in form submission.
  187. virtual bool getFormValue(String& formValue) = 0;
  188. // Tells the plug-in that it should scroll. The plug-in should return true if it did scroll.
  189. virtual bool handleScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity) = 0;
  190. // A plug-in can use WebCore scroll bars. Make them known, so that hit testing can find them.
  191. // FIXME: This code should be in PluginView or its base class, not in individual plug-ins.
  192. virtual WebCore::Scrollbar* horizontalScrollbar() = 0;
  193. virtual WebCore::Scrollbar* verticalScrollbar() = 0;
  194. #if PLATFORM(MAC)
  195. virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; }
  196. virtual NSObject *accessibilityObject() const { return 0; }
  197. #endif
  198. virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
  199. virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0;
  200. virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint& pointInLocalCoordinates) const;
  201. virtual bool shouldAlwaysAutoStart() const { return false; }
  202. virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const = 0;
  203. virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) = 0;
  204. virtual String getSelectionString() const = 0;
  205. protected:
  206. Plugin();
  207. private:
  208. PluginController* m_pluginController;
  209. };
  210. } // namespace WebKit
  211. #endif // Plugin_h