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/FindOptions.h> 30#include <WebCore/GraphicsLayer.h> 31#include <WebCore/KURL.h> 32#include <WebCore/ScrollTypes.h> 33#include <WebCore/SecurityOrigin.h> 34#include <wtf/RefCounted.h> 35#include <wtf/RetainPtr.h> 36#include <wtf/Vector.h> 37 38#if PLATFORM(MAC) 39#include "LayerHostingContext.h" 40 41OBJC_CLASS NSObject; 42OBJC_CLASS PDFDocument; 43#endif 44 45struct NPObject; 46 47namespace CoreIPC { 48 class ArgumentEncoder; 49 class ArgumentDecoder; 50} 51 52namespace WebCore { 53 class AffineTransform; 54 class FloatPoint; 55 class GraphicsContext; 56 class IntPoint; 57 class IntRect; 58 class IntSize; 59 class FloatPoint; 60 class Scrollbar; 61 class SharedBuffer; 62} 63 64namespace WebKit { 65 66class ShareableBitmap; 67class WebKeyboardEvent; 68class WebMouseEvent; 69class WebWheelEvent; 70 71class PluginController; 72 73class Plugin : public ThreadSafeRefCounted<Plugin> { 74public: 75 struct Parameters { 76 WebCore::KURL url; 77 Vector<String> names; 78 Vector<String> values; 79 String mimeType; 80 bool isFullFramePlugin; 81 bool shouldUseManualLoader; 82#if PLATFORM(MAC) 83 LayerHostingMode layerHostingMode; 84#endif 85 86 void encode(CoreIPC::ArgumentEncoder&) const; 87 static bool decode(CoreIPC::ArgumentDecoder&, Parameters&); 88 }; 89 90 // Sets the active plug-in controller and initializes the plug-in. 91 bool initialize(PluginController*, const Parameters&); 92 93 virtual bool isBeingAsynchronouslyInitialized() const = 0; 94 95 // Destroys the plug-in. 96 void destroyPlugin(); 97 98 // Returns the plug-in controller for this plug-in. 99 PluginController* controller() { return m_pluginController; } 100 const PluginController* controller() const { return m_pluginController; } 101 102 virtual ~Plugin(); 103 104private: 105 106 // Initializes the plug-in. If the plug-in fails to initialize this should return false. 107 // This is only called by the other initialize overload so it can be made private. 108 virtual bool initialize(const Parameters&) = 0; 109 110 // Destroys the plug-in. 111 virtual void destroy() = 0; 112 113public: 114 115 // Tells the plug-in to paint itself into the given graphics context. The passed-in context and 116 // dirty rect are in window coordinates. The context is saved/restored by the caller. 117 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect) = 0; 118 119 // Invalidate native tintable controls. The passed-in context is in window coordinates. 120 virtual void updateControlTints(WebCore::GraphicsContext*); 121 122 // Returns whether the plug-in supports snapshotting or not. 123 virtual bool supportsSnapshotting() const = 0; 124 125 // Tells the plug-in to draw itself into a bitmap, and return that. 126 virtual PassRefPtr<ShareableBitmap> snapshot() = 0; 127 128#if PLATFORM(MAC) 129 // If a plug-in is using the Core Animation drawing model, this returns its plug-in layer. 130 virtual PlatformLayer* pluginLayer() = 0; 131#endif 132 133 // Returns whether the plug-in is transparent or not. 134 virtual bool isTransparent() = 0; 135 136 // Returns whether we should send wheel events to this plug-in. 137 virtual bool wantsWheelEvents() = 0; 138 139 // Tells the plug-in that its geometry has changed. The clip rect is in plug-in coordinates, and the affine transform can be used 140 // to convert from root view coordinates to plug-in coordinates. 141 virtual void geometryDidChange(const WebCore::IntSize& pluginSize, const WebCore::IntRect& clipRect, const WebCore::AffineTransform& pluginToRootViewTransform) = 0; 142 143 // 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.) 144 virtual void visibilityDidChange() = 0; 145 146 // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has finished. 147 virtual void frameDidFinishLoading(uint64_t requestID) = 0; 148 149 // Tells the plug-in that a frame load request that the plug-in made by calling PluginController::loadURL has failed. 150 virtual void frameDidFail(uint64_t requestID, bool wasCancelled) = 0; 151 152 // Tells the plug-in that a request to evaluate JavaScript (using PluginController::loadURL) has been fulfilled and passes 153 // back the result. If evaluating the script failed, result will be null. 154 virtual void didEvaluateJavaScript(uint64_t requestID, const String& result) = 0; 155 156 // Tells the plug-in that a stream has received its HTTP response. 157 virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, 158 uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName) = 0; 159 160 // Tells the plug-in that a stream did receive data. 161 virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length) = 0; 162 163 // Tells the plug-in that a stream has finished loading. 164 virtual void streamDidFinishLoading(uint64_t streamID) = 0; 165 166 // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled. 167 virtual void streamDidFail(uint64_t streamID, bool wasCancelled) = 0; 168 169 // Tells the plug-in that the manual stream has received its HTTP response. 170 virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, 171 uint32_t lastModifiedTime, const String& mimeType, const String& headers, const String& suggestedFileName) = 0; 172 173 // Tells the plug-in that the manual stream did receive data. 174 virtual void manualStreamDidReceiveData(const char* bytes, int length) = 0; 175 176 // Tells the plug-in that a stream has finished loading. 177 virtual void manualStreamDidFinishLoading() = 0; 178 179 // Tells the plug-in that a stream has failed to load, either because of network errors or because the load was cancelled. 180 virtual void manualStreamDidFail(bool wasCancelled) = 0; 181 182 // Tells the plug-in to handle the passed in mouse event. The plug-in should return true if it processed the event. 183 virtual bool handleMouseEvent(const WebMouseEvent&) = 0; 184 185 // Tells the plug-in to handle the passed in wheel event. The plug-in should return true if it processed the event. 186 virtual bool handleWheelEvent(const WebWheelEvent&) = 0; 187 188 // Tells the plug-in to handle the passed in mouse over event. The plug-in should return true if it processed the event. 189 virtual bool handleMouseEnterEvent(const WebMouseEvent&) = 0; 190 191 // Tells the plug-in to handle the passed in mouse leave event. The plug-in should return true if it processed the event. 192 virtual bool handleMouseLeaveEvent(const WebMouseEvent&) = 0; 193 194 // Tells the plug-in to handle the passed in context menu event. The plug-in should return true if it processed the event. 195 virtual bool handleContextMenuEvent(const WebMouseEvent&) = 0; 196 197 // Tells the plug-in to handle the passed in keyboard event. The plug-in should return true if it processed the event. 198 virtual bool handleKeyboardEvent(const WebKeyboardEvent&) = 0; 199 200 // Tells the plug-in to handle the passed in editing command. The plug-in should return true if it executed the command. 201 virtual bool handleEditingCommand(const String& commandName, const String& argument) = 0; 202 203 // Ask the plug-in whether it will be able to handle the given editing command. 204 virtual bool isEditingCommandEnabled(const String&) = 0; 205 206 // Ask the plug-in whether it should be allowed to execute JavaScript or navigate to JavaScript URLs. 207 virtual bool shouldAllowScripting() = 0; 208 209 // Ask the plug-in whether it wants URLs and files dragged onto it to cause navigation. 210 virtual bool shouldAllowNavigationFromDrags() = 0; 211 212 // Ask the plug-in whether it wants to override full-page zoom. 213 virtual bool handlesPageScaleFactor() = 0; 214 215 // Tells the plug-in about focus changes. 216 virtual void setFocus(bool) = 0; 217 218 // Get the NPObject that corresponds to the plug-in's scriptable object. Returns a retained object. 219 virtual NPObject* pluginScriptableNPObject() = 0; 220 221#if PLATFORM(MAC) 222 // Tells the plug-in about window focus changes. 223 virtual void windowFocusChanged(bool) = 0; 224 225 // Tells the plug-in about window and plug-in frame changes. 226 virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates) = 0; 227 228 // Tells the plug-in about window visibility changes. 229 virtual void windowVisibilityChanged(bool) = 0; 230 231 // Get the per complex text input identifier. 232 virtual uint64_t pluginComplexTextInputIdentifier() const = 0; 233 234 // Send the complex text input to the plug-in. 235 virtual void sendComplexTextInput(const String& textInput) = 0; 236 237 // Tells the plug-in about changes to the layer hosting mode. 238 virtual void setLayerHostingMode(LayerHostingMode) = 0; 239#endif 240 241 // Tells the plug-in about scale factor changes. 242 virtual void contentsScaleFactorChanged(float) = 0; 243 244 // Called when the storage blocking policy for this plug-in changes. 245 virtual void storageBlockingStateChanged(bool) = 0; 246 247 // Called when the private browsing state for this plug-in changes. 248 virtual void privateBrowsingStateChanged(bool) = 0; 249 250 // Gets the form value representation for the plug-in, letting plug-ins participate in form submission. 251 virtual bool getFormValue(String& formValue) = 0; 252 253 // Tells the plug-in that it should scroll. The plug-in should return true if it did scroll. 254 virtual bool handleScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity) = 0; 255 256 // A plug-in can use WebCore scroll bars. Make them known, so that hit testing can find them. 257 // FIXME: This code should be in PluginView or its base class, not in individual plug-ins. 258 virtual WebCore::Scrollbar* horizontalScrollbar() = 0; 259 virtual WebCore::Scrollbar* verticalScrollbar() = 0; 260 261#if PLATFORM(MAC) 262 virtual RetainPtr<PDFDocument> pdfDocumentForPrinting() const { return 0; } 263 virtual NSObject *accessibilityObject() const { return 0; } 264#endif 265 266 virtual unsigned countFindMatches(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0; 267 268 virtual bool findString(const String& target, WebCore::FindOptions, unsigned maxMatchCount) = 0; 269 270 virtual WebCore::IntPoint convertToRootView(const WebCore::IntPoint& pointInLocalCoordinates) const; 271 272 virtual bool shouldAlwaysAutoStart() const { return false; } 273 274 virtual PassRefPtr<WebCore::SharedBuffer> liveResourceData() const = 0; 275 276 virtual bool performDictionaryLookupAtLocation(const WebCore::FloatPoint&) = 0; 277 278 virtual String getSelectionString() const = 0; 279 280protected: 281 Plugin(); 282 283private: 284 PluginController* m_pluginController; 285}; 286 287} // namespace WebKit 288 289#endif // Plugin_h 290