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