Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / dom / plugins / PluginInstanceParent.h
blob83b5c6fd68ec69eab82d4e4b8d32c0d5ff534876
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: sw=4 ts=4 et :
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Plugin App.
18 * The Initial Developer of the Original Code is
19 * Chris Jones <jones.chris.g@gmail.com>
20 * Portions created by the Initial Developer are Copyright (C) 2009
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef dom_plugins_PluginInstanceParent_h
40 #define dom_plugins_PluginInstanceParent_h 1
42 #include "mozilla/plugins/PPluginInstanceParent.h"
43 #include "mozilla/plugins/PluginScriptableObjectParent.h"
44 #if defined(OS_WIN)
45 #include "mozilla/gfx/SharedDIBWin.h"
46 #elif defined(OS_MACOSX)
47 #include "nsCoreAnimationSupport.h"
48 #endif
50 #include "npfunctions.h"
51 #include "nsAutoPtr.h"
52 #include "nsDataHashtable.h"
53 #include "nsHashKeys.h"
54 #include "nsRect.h"
55 #include "gfxASurface.h"
56 #include "ImageLayers.h"
57 #ifdef MOZ_X11
58 class gfxXlibSurface;
59 #endif
61 namespace mozilla {
62 namespace plugins {
64 class PBrowserStreamParent;
65 class PluginModuleParent;
67 class PluginInstanceParent : public PPluginInstanceParent
69 friend class PluginModuleParent;
70 friend class BrowserStreamParent;
71 friend class PluginStreamParent;
72 friend class StreamNotifyParent;
74 public:
75 PluginInstanceParent(PluginModuleParent* parent,
76 NPP npp,
77 const nsCString& mimeType,
78 const NPNetscapeFuncs* npniface);
80 virtual ~PluginInstanceParent();
82 bool Init();
83 NPError Destroy();
85 NS_OVERRIDE virtual void ActorDestroy(ActorDestroyReason why);
87 virtual PPluginScriptableObjectParent*
88 AllocPPluginScriptableObject();
90 NS_OVERRIDE virtual bool
91 RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectParent* aActor);
93 virtual bool
94 DeallocPPluginScriptableObject(PPluginScriptableObjectParent* aObject);
95 virtual PBrowserStreamParent*
96 AllocPBrowserStream(const nsCString& url,
97 const uint32_t& length,
98 const uint32_t& lastmodified,
99 PStreamNotifyParent* notifyData,
100 const nsCString& headers,
101 const nsCString& mimeType,
102 const bool& seekable,
103 NPError* rv,
104 uint16_t *stype);
105 virtual bool
106 DeallocPBrowserStream(PBrowserStreamParent* stream);
108 virtual PPluginStreamParent*
109 AllocPPluginStream(const nsCString& mimeType,
110 const nsCString& target,
111 NPError* result);
112 virtual bool
113 DeallocPPluginStream(PPluginStreamParent* stream);
115 virtual bool
116 AnswerNPN_GetValue_NPNVjavascriptEnabledBool(bool* value, NPError* result);
117 virtual bool
118 AnswerNPN_GetValue_NPNVisOfflineBool(bool* value, NPError* result);
119 virtual bool
120 AnswerNPN_GetValue_NPNVnetscapeWindow(NativeWindowHandle* value,
121 NPError* result);
122 virtual bool
123 AnswerNPN_GetValue_NPNVWindowNPObject(
124 PPluginScriptableObjectParent** value,
125 NPError* result);
126 virtual bool
127 AnswerNPN_GetValue_NPNVPluginElementNPObject(
128 PPluginScriptableObjectParent** value,
129 NPError* result);
130 virtual bool
131 AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result);
133 virtual bool
134 AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result);
135 virtual bool
136 AnswerNPN_SetValue_NPPVpluginTransparent(const bool& transparent,
137 NPError* result);
138 virtual bool
139 AnswerNPN_SetValue_NPPVpluginDrawingModel(const int& drawingModel,
140 NPError* result);
141 virtual bool
142 AnswerNPN_SetValue_NPPVpluginEventModel(const int& eventModel,
143 NPError* result);
145 virtual bool
146 AnswerNPN_GetURL(const nsCString& url, const nsCString& target,
147 NPError *result);
149 virtual bool
150 AnswerNPN_PostURL(const nsCString& url, const nsCString& target,
151 const nsCString& buffer, const bool& file,
152 NPError* result);
154 virtual PStreamNotifyParent*
155 AllocPStreamNotify(const nsCString& url, const nsCString& target,
156 const bool& post, const nsCString& buffer,
157 const bool& file,
158 NPError* result);
160 NS_OVERRIDE virtual bool
161 AnswerPStreamNotifyConstructor(PStreamNotifyParent* actor,
162 const nsCString& url,
163 const nsCString& target,
164 const bool& post, const nsCString& buffer,
165 const bool& file,
166 NPError* result);
168 virtual bool
169 DeallocPStreamNotify(PStreamNotifyParent* notifyData);
171 virtual bool
172 RecvNPN_InvalidateRect(const NPRect& rect);
174 // Async rendering
175 virtual bool
176 RecvShow(const NPRect& updatedRect,
177 const SurfaceDescriptor& newSurface,
178 SurfaceDescriptor* prevSurface);
180 virtual PPluginSurfaceParent*
181 AllocPPluginSurface(const WindowsSharedMemoryHandle& handle,
182 const gfxIntSize& size,
183 const bool& transparent);
185 virtual bool
186 DeallocPPluginSurface(PPluginSurfaceParent* s);
188 virtual bool
189 AnswerNPN_PushPopupsEnabledState(const bool& aState);
191 virtual bool
192 AnswerNPN_PopPopupsEnabledState();
194 NS_OVERRIDE virtual bool
195 AnswerNPN_GetValueForURL(const NPNURLVariable& variable,
196 const nsCString& url,
197 nsCString* value, NPError* result);
199 NS_OVERRIDE virtual bool
200 AnswerNPN_SetValueForURL(const NPNURLVariable& variable,
201 const nsCString& url,
202 const nsCString& value, NPError* result);
204 NS_OVERRIDE virtual bool
205 AnswerNPN_GetAuthenticationInfo(const nsCString& protocol,
206 const nsCString& host,
207 const int32_t& port,
208 const nsCString& scheme,
209 const nsCString& realm,
210 nsCString* username,
211 nsCString* password,
212 NPError* result);
214 NS_OVERRIDE virtual bool
215 AnswerNPN_ConvertPoint(const double& sourceX,
216 const bool& ignoreDestX,
217 const double& sourceY,
218 const bool& ignoreDestY,
219 const NPCoordinateSpace& sourceSpace,
220 const NPCoordinateSpace& destSpace,
221 double *destX,
222 double *destY,
223 bool *result);
225 NS_OVERRIDE virtual bool
226 RecvNegotiatedCarbon();
228 NPError NPP_SetWindow(const NPWindow* aWindow);
230 NPError NPP_GetValue(NPPVariable variable, void* retval);
231 NPError NPP_SetValue(NPNVariable variable, void* value);
233 void NPP_URLRedirectNotify(const char* url, int32_t status,
234 void* notifyData);
236 NPError NPP_NewStream(NPMIMEType type, NPStream* stream,
237 NPBool seekable, uint16_t* stype);
238 NPError NPP_DestroyStream(NPStream* stream, NPReason reason);
240 void NPP_Print(NPPrint* platformPrint);
242 int16_t NPP_HandleEvent(void* event);
244 void NPP_URLNotify(const char* url, NPReason reason, void* notifyData);
246 PluginModuleParent* Module()
248 return mParent;
251 const NPNetscapeFuncs* GetNPNIface()
253 return mNPNIface;
256 bool
257 RegisterNPObjectForActor(NPObject* aObject,
258 PluginScriptableObjectParent* aActor);
260 void
261 UnregisterNPObject(NPObject* aObject);
263 PluginScriptableObjectParent*
264 GetActorForNPObject(NPObject* aObject);
267 GetNPP()
269 return mNPP;
272 virtual bool
273 AnswerPluginFocusChange(const bool& gotFocus);
275 #if defined(OS_MACOSX)
276 void Invalidate();
277 #endif // definied(OS_MACOSX)
279 nsresult AsyncSetWindow(NPWindow* window);
280 nsresult GetSurface(gfxASurface** aSurface);
281 nsresult GetImage(mozilla::layers::ImageContainer* aContainer, mozilla::layers::Image** aImage);
282 #ifdef XP_MACOSX
283 nsresult IsRemoteDrawingCoreAnimation(PRBool *aDrawing);
284 #endif
285 nsresult SetBackgroundUnknown();
286 nsresult BeginUpdateBackground(const nsIntRect& aRect,
287 gfxContext** aCtx);
288 nsresult EndUpdateBackground(gfxContext* aCtx,
289 const nsIntRect& aRect);
291 private:
292 // Create an appropriate platform surface for a background of size
293 // |aSize|. Return true if successful.
294 bool CreateBackground(const nsIntSize& aSize);
295 void DestroyBackground();
296 SurfaceDescriptor BackgroundDescriptor() /*const*/;
298 NS_OVERRIDE
299 virtual PPluginBackgroundDestroyerParent*
300 AllocPPluginBackgroundDestroyer();
302 NS_OVERRIDE
303 virtual bool
304 DeallocPPluginBackgroundDestroyer(PPluginBackgroundDestroyerParent* aActor);
306 // Quirks mode support for various plugin mime types
307 enum PluginQuirks {
308 // OSX: Don't use the refresh timer for plug-ins
309 // using this quirk. These plug-in most have another
310 // way to refresh the window.
311 COREANIMATION_REFRESH_TIMER = 1,
314 void InitQuirksModes(const nsCString& aMimeType);
316 bool InternalGetValueForNPObject(NPNVariable aVariable,
317 PPluginScriptableObjectParent** aValue,
318 NPError* aResult);
320 private:
321 PluginModuleParent* mParent;
322 NPP mNPP;
323 const NPNetscapeFuncs* mNPNIface;
324 NPWindowType mWindowType;
325 int mQuirks;
327 nsDataHashtable<nsVoidPtrHashKey, PluginScriptableObjectParent*> mScriptableObjects;
329 #if defined(OS_WIN)
330 private:
331 // Used in rendering windowless plugins in other processes.
332 bool SharedSurfaceSetWindow(const NPWindow* aWindow, NPRemoteWindow& aRemoteWindow);
333 void SharedSurfaceBeforePaint(RECT &rect, NPRemoteEvent& npremoteevent);
334 void SharedSurfaceAfterPaint(NPEvent* npevent);
335 void SharedSurfaceRelease();
336 // Used in handling parent/child forwarding of events.
337 static LRESULT CALLBACK PluginWindowHookProc(HWND hWnd, UINT message,
338 WPARAM wParam, LPARAM lParam);
339 void SubclassPluginWindow(HWND aWnd);
340 void UnsubclassPluginWindow();
342 private:
343 gfx::SharedDIBWin mSharedSurfaceDib;
344 nsIntRect mPluginPort;
345 nsIntRect mSharedSize;
346 HWND mPluginHWND;
347 WNDPROC mPluginWndProc;
348 bool mNestedEventState;
349 #endif // defined(XP_WIN)
350 #if defined(OS_MACOSX)
351 private:
352 Shmem mShSurface;
353 size_t mShWidth;
354 size_t mShHeight;
355 CGColorSpaceRef mShColorSpace;
356 int16_t mDrawingModel;
357 nsIOSurface *mIOSurface;
358 #endif // definied(OS_MACOSX)
360 // ObjectFrame layer wrapper
361 nsRefPtr<gfxASurface> mFrontSurface;
362 // For windowless+transparent instances, this surface contains a
363 // "pretty recent" copy of the pixels under its <object> frame.
364 // On the plugin side, we use this surface to avoid doing alpha
365 // recovery when possible. This surface is created and owned by
366 // the browser, but a "read-only" reference is sent to the plugin.
368 // We have explicitly chosen not to provide any guarantees about
369 // the consistency of the pixels in |mBackground|. A plugin may
370 // be able to observe partial updates to the background.
371 nsRefPtr<gfxASurface> mBackground;
375 } // namespace plugins
376 } // namespace mozilla
378 #endif // ifndef dom_plugins_PluginInstanceParent_h