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 26 #ifndef Plugin_h 27 #define Plugin_h 28 29 #include <WebCore/GraphicsLayer.h> 30 #include <WebCore/KURL.h> 31 #include <wtf/RefCounted.h> 32 #include <wtf/Vector.h> 33 34 struct NPObject; 35 36 namespace CoreIPC { 37 class ArgumentEncoder; 38 class ArgumentDecoder; 39 } 40 41 namespace WebCore { 42 class GraphicsContext; 43 class IntRect; 44 } 45 46 namespace WebKit { 47 48 class ShareableBitmap; 49 class WebKeyboardEvent; 50 class WebMouseEvent; 51 class WebWheelEvent; 52 53 class PluginController; 54 55 class Plugin : public RefCounted<Plugin> { 56 public: 57 struct Parameters { 58 WebCore::KURL url; 59 Vector<String> names; 60 Vector<String> values; 61 String mimeType; 62 bool loadManually; 63 64 void encode(CoreIPC::ArgumentEncoder*) const; 65 static bool decode(CoreIPC::ArgumentDecoder*, Parameters&); 66 }; 67 68 virtual ~Plugin(); 69 70 // Initializes the plug-in. If the plug-in fails to initialize this should return false. 71 virtual bool initialize(PluginController*, const Parameters&) = 0; 72 73 // Destroys the plug-in. 74 virtual void destroy() = 0; 75 76 // Tells the plug-in to paint itself into the given graphics context. The passed-in context and 77 // dirty rect are in window coordinates. The context is saved/restored by the caller. 78 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect) = 0; 79 80 // Tells the plug-in to draw itself into a bitmap, and return that. 81 virtual PassRefPtr<ShareableBitmap> snapshot() = 0; 82 83 #if PLATFORM(MAC) 84 // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer. 85 virtual PlatformLayer* pluginLayer() = 0; 86 #endif 87 88 // Returns whether the plug-in is transparent or not. 89 virtual bool isTransparent() = 0; 90 91 // Tells the plug-in that either the plug-ins frame rect or its clip rect has changed. Both rects are in window coordinates. 92 virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect) = 0; 93 94 // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has finished. 95 virtual void frameDidFinishLoading(uint64_t requestID) = 0; 96 97 // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has failed. 98 virtual void frameDidFail(uint64_t requestID, bool wasCancelled) = 0; 99 100 // Tells the plug-in that a request to evaluate JavaScript (using PluginController::loadURL) has been fulfilled and passes 101 // back the result. If evaluating the script failed, result will be null. 102 virtual void didEvaluateJavaScript(uint64_t requestID, const String& requestURLString, const String& result) = 0; 103 104 // Tells the plug-in that a stream has received its HTTP response. 105 virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, 106 uint32_t lastModifiedTime, const String& mimeType, const String& headers) = 0; 107 108 // Tells the plug-in that a stream did receive data. 109 virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0; 110 111 // Tells the plug-in that a stream has finished loading. 112 virtual void streamDidFinishLoading(uint64_t streamID) = 0; 113 114 // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled. 115 virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0; 116 117 // Tells the plug-in that the manual stream has received its HTTP response. 118 virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, 119 uint32_t lastModifiedTime, const String& mimeType, const String& headers) = 0; 120 121 // Tells the plug-in that the manual stream did receive data. 122 virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0; 123 124 // Tells the plug-in that a stream has finished loading. 125 virtual void manualStreamDidFinishLoading() = 0; 126 127 // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled. 128 virtual void manualStreamDidFail(bool wasCancelled) = 0; 129 130 // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event. 131 virtual bool handleMouseEvent(const WebMouseEvent&) = 0; 132 133 // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event. 134 virtual bool handleWheelEvent(const WebWheelEvent&) = 0; 135 136 // Tells the plug-in to handle the passed in mouse over event. The plug-in should return true if it processed the event. 137 virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0; 138 139 // Tells the plug-in to handle the passed in mouse leave event. The plug-in should return true if it processed the event. 140 virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0; 141 142 // Tells the plug-in to handle the passed in keyboard event. The plug-in should return true if it processed the event. 143 virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0; 144 145 // Tells the plug-in about focus changes. 146 virtual void setFocus(bool) = 0; 147 148 // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object. 149 virtual NPObject* pluginScriptableNPObject() = 0; 150 151 #if PLATFORM(MAC) 152 // Tells the plug-in about window focus changes. 153 virtual void windowFocusChanged(bool) = 0; 154 155 // Tells the plug-in about window and plug-in frame changes. 156 virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0; 157 158 // Tells the plug-in about window visibility changes. 159 virtual void windowVisibilityChanged(bool) = 0; 160 161 // Get the per complex text input identifier. 162 virtual uint64_t pluginComplexTextInputIdentifier() const = 0; 163 164 // Send the complex text input to the plug-in. 165 virtual void sendComplexTextInput(const String& textInput) = 0; 166 #endif 167 168 // Called when the private browsing state for this plug-in changes. 169 virtual void privateBrowsingStateChanged(bool) = 0; 170 171 // Returns the plug-in controller for this plug-in. 172 // FIXME: We could just have the controller be a member variable of Plugin. 173 virtual PluginController* controller() = 0; 174 175 protected: 176 Plugin(); 177 }; 178 179 } // namespace WebKit 180 181 #endif // Plugin_h 182