NetscapePlugin.h revision 2fc2651226baac27029e38c9d6ef883fa32084db
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 NetscapePlugin_h 27#define NetscapePlugin_h 28 29#include "NetscapePluginModule.h" 30#include "Plugin.h" 31#include "RunLoop.h" 32#include <WebCore/GraphicsLayer.h> 33#include <WebCore/IntRect.h> 34#include <wtf/HashMap.h> 35#include <wtf/text/CString.h> 36#include <wtf/text/StringHash.h> 37 38namespace WebCore { 39 class HTTPHeaderMap; 40} 41 42namespace WebKit { 43 44class NetscapePluginStream; 45 46class NetscapePlugin : public Plugin { 47public: 48 static PassRefPtr<NetscapePlugin> create(PassRefPtr<NetscapePluginModule> pluginModule); 49 virtual ~NetscapePlugin(); 50 51 static PassRefPtr<NetscapePlugin> fromNPP(NPP); 52 53#if PLATFORM(MAC) 54 NPError setDrawingModel(NPDrawingModel); 55 NPError setEventModel(NPEventModel); 56 NPBool convertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double& destX, double& destY, NPCoordinateSpace destSpace); 57 NPError popUpContextMenu(NPMenu*); 58 59 mach_port_t compositingRenderServerPort(); 60 61#ifndef NP_NO_CARBON 62 WindowRef windowRef() const; 63 bool isWindowActive() const { return m_windowHasFocus; } 64 65 static NetscapePlugin* netscapePluginFromWindow(WindowRef); 66 static unsigned buttonState(); 67#endif 68 69#elif PLATFORM(WIN) 70 HWND containingWindow() const; 71#endif 72 73 void invalidate(const NPRect*); 74 static const char* userAgent(NPP); 75 void loadURL(const String& method, const String& urlString, const String& target, const WebCore::HTTPHeaderMap& headerFields, 76 const Vector<uint8_t>& httpBody, bool sendNotification, void* notificationData); 77 NPError destroyStream(NPStream*, NPReason); 78 void setIsWindowed(bool); 79 void setStatusbarText(const String&); 80 static void setException(const String&); 81 bool evaluate(NPObject*, const String&scriptString, NPVariant* result); 82 bool isPrivateBrowsingEnabled(); 83 84 // These return retained objects. 85 NPObject* windowScriptNPObject(); 86 NPObject* pluginElementNPObject(); 87 88 void cancelStreamLoad(NetscapePluginStream*); 89 void removePluginStream(NetscapePluginStream*); 90 91 bool isAcceleratedCompositingEnabled(); 92 93 void pushPopupsEnabledState(bool enabled); 94 void popPopupsEnabledState(); 95 96 String proxiesForURL(const String& urlString); 97 String cookiesForURL(const String& urlString); 98 void setCookiesForURL(const String& urlString, const String& cookieString); 99 100 // Member functions for calling into the plug-in. 101 NPError NPP_New(NPMIMEType pluginType, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData*); 102 NPError NPP_Destroy(NPSavedData**); 103 NPError NPP_SetWindow(NPWindow*); 104 NPError NPP_NewStream(NPMIMEType, NPStream*, NPBool seekable, uint16_t* stype); 105 NPError NPP_DestroyStream(NPStream*, NPReason); 106 void NPP_StreamAsFile(NPStream*, const char* filename); 107 int32_t NPP_WriteReady(NPStream*); 108 int32_t NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer); 109 int16_t NPP_HandleEvent(void* event); 110 void NPP_URLNotify(const char* url, NPReason, void* notifyData); 111 NPError NPP_GetValue(NPPVariable, void *value); 112 NPError NPP_SetValue(NPNVariable, void *value); 113 114private: 115 NetscapePlugin(PassRefPtr<NetscapePluginModule> pluginModule); 116 117 void callSetWindow(); 118 bool shouldLoadSrcURL(); 119 NetscapePluginStream* streamFromID(uint64_t streamID); 120 void stopAllStreams(); 121 bool allowPopups() const; 122 123 const char* userAgent(); 124 125 bool platformPostInitialize(); 126 void platformDestroy(); 127 bool platformInvalidate(const WebCore::IntRect&); 128 void platformGeometryDidChange(); 129 void platformPaint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect); 130 131 bool platformHandleMouseEvent(const WebMouseEvent&); 132 bool platformHandleWheelEvent(const WebWheelEvent&); 133 bool platformHandleMouseEnterEvent(const WebMouseEvent&); 134 bool platformHandleMouseLeaveEvent(const WebMouseEvent&); 135 bool platformHandleKeyboardEvent(const WebKeyboardEvent&); 136 void platformSetFocus(bool); 137 138 // Plugin 139 virtual bool initialize(PluginController*, const Parameters&); 140 virtual void destroy(); 141 virtual void paint(WebCore::GraphicsContext*, const WebCore::IntRect& dirtyRect); 142#if PLATFORM(MAC) 143 virtual PlatformLayer* pluginLayer(); 144#endif 145 virtual void geometryDidChange(const WebCore::IntRect& frameRect, const WebCore::IntRect& clipRect); 146 virtual void frameDidFinishLoading(uint64_t requestID); 147 virtual void frameDidFail(uint64_t requestID, bool wasCancelled); 148 virtual void didEvaluateJavaScript(uint64_t requestID, const String& requestURLString, const String& result); 149 virtual void streamDidReceiveResponse(uint64_t streamID, const WebCore::KURL& responseURL, uint32_t streamLength, 150 uint32_t lastModifiedTime, const String& mimeType, const String& headers); 151 virtual void streamDidReceiveData(uint64_t streamID, const char* bytes, int length); 152 virtual void streamDidFinishLoading(uint64_t streamID); 153 virtual void streamDidFail(uint64_t streamID, bool wasCancelled); 154 virtual void manualStreamDidReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, 155 uint32_t lastModifiedTime, const String& mimeType, const String& headers); 156 virtual void manualStreamDidReceiveData(const char* bytes, int length); 157 virtual void manualStreamDidFinishLoading(); 158 virtual void manualStreamDidFail(bool wasCancelled); 159 160 virtual bool handleMouseEvent(const WebMouseEvent&); 161 virtual bool handleWheelEvent(const WebWheelEvent&); 162 virtual bool handleMouseEnterEvent(const WebMouseEvent&); 163 virtual bool handleMouseLeaveEvent(const WebMouseEvent&); 164 virtual bool handleKeyboardEvent(const WebKeyboardEvent&); 165 virtual void setFocus(bool); 166 virtual NPObject* pluginScriptableNPObject(); 167 168#if PLATFORM(MAC) 169 virtual void windowFocusChanged(bool); 170 virtual void windowAndViewFramesChanged(const WebCore::IntRect& windowFrameInScreenCoordinates, const WebCore::IntRect& viewFrameInWindowCoordinates); 171 virtual void windowVisibilityChanged(bool); 172 173 virtual uint64_t pluginComplexTextInputIdentifier() const; 174 virtual void sendComplexTextInput(const String& textInput); 175#endif 176 177 virtual void privateBrowsingStateChanged(bool); 178 179 virtual PluginController* controller(); 180 181 PluginController* m_pluginController; 182 uint64_t m_nextRequestID; 183 184 typedef HashMap<uint64_t, std::pair<String, void*> > PendingURLNotifyMap; 185 PendingURLNotifyMap m_pendingURLNotifications; 186 187 typedef HashMap<uint64_t, RefPtr<NetscapePluginStream> > StreamsMap; 188 StreamsMap m_streams; 189 190 RefPtr<NetscapePluginModule> m_pluginModule; 191 NPP_t m_npp; 192 NPWindow m_npWindow; 193 194 WebCore::IntRect m_frameRect; 195 WebCore::IntRect m_clipRect; 196 197 CString m_userAgent; 198 199 bool m_isStarted; 200 bool m_isWindowed; 201 bool m_inNPPNew; 202 bool m_loadManually; 203 RefPtr<NetscapePluginStream> m_manualStream; 204 Vector<bool, 8> m_popupEnabledStates; 205 206#if PLATFORM(MAC) 207 NPDrawingModel m_drawingModel; 208 NPEventModel m_eventModel; 209 RetainPtr<PlatformLayer> m_pluginLayer; 210 211 NPCocoaEvent* m_currentMouseEvent; 212 213 bool m_pluginHasFocus; 214 bool m_windowHasFocus; 215 216 WebCore::IntRect m_windowFrameInScreenCoordinates; 217 WebCore::IntRect m_viewFrameInWindowCoordinates; 218 219#ifndef NP_NO_CARBON 220 void nullEventTimerFired(); 221 222 // FIXME: It's a bit wasteful to have one null event timer per plug-in. 223 // We should investigate having one per window. 224 RunLoop::Timer<NetscapePlugin> m_nullEventTimer; 225 NP_CGContext m_npCGContext; 226#endif 227#elif PLATFORM(WIN) 228 HWND m_window; 229#endif 230}; 231 232} // namespace WebKit 233 234#endif // NetscapePlugin_h 235