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
5 : *
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/
10 : *
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.
15 : *
16 : * The Original Code is Mozilla Plugin App.
17 : *
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.
22 : *
23 : * Contributor(s):
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef dom_plugins_PluginInstanceParent_h
40 : #define dom_plugins_PluginInstanceParent_h 1
41 :
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(MOZ_WIDGET_COCOA)
47 : #include "nsCoreAnimationSupport.h"
48 : #endif
49 :
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
60 : #include "nsGUIEvent.h"
61 :
62 : namespace mozilla {
63 : namespace plugins {
64 :
65 : class PBrowserStreamParent;
66 : class PluginModuleParent;
67 :
68 : class PluginInstanceParent : public PPluginInstanceParent
69 : {
70 : friend class PluginModuleParent;
71 : friend class BrowserStreamParent;
72 : friend class PluginStreamParent;
73 : friend class StreamNotifyParent;
74 :
75 : public:
76 : PluginInstanceParent(PluginModuleParent* parent,
77 : NPP npp,
78 : const nsCString& mimeType,
79 : const NPNetscapeFuncs* npniface);
80 :
81 : virtual ~PluginInstanceParent();
82 :
83 : bool Init();
84 : NPError Destroy();
85 :
86 : NS_OVERRIDE virtual void ActorDestroy(ActorDestroyReason why);
87 :
88 : virtual PPluginScriptableObjectParent*
89 : AllocPPluginScriptableObject();
90 :
91 : NS_OVERRIDE virtual bool
92 : RecvPPluginScriptableObjectConstructor(PPluginScriptableObjectParent* aActor);
93 :
94 : virtual bool
95 : DeallocPPluginScriptableObject(PPluginScriptableObjectParent* aObject);
96 : virtual PBrowserStreamParent*
97 : AllocPBrowserStream(const nsCString& url,
98 : const uint32_t& length,
99 : const uint32_t& lastmodified,
100 : PStreamNotifyParent* notifyData,
101 : const nsCString& headers,
102 : const nsCString& mimeType,
103 : const bool& seekable,
104 : NPError* rv,
105 : uint16_t *stype);
106 : virtual bool
107 : DeallocPBrowserStream(PBrowserStreamParent* stream);
108 :
109 : virtual PPluginStreamParent*
110 : AllocPPluginStream(const nsCString& mimeType,
111 : const nsCString& target,
112 : NPError* result);
113 : virtual bool
114 : DeallocPPluginStream(PPluginStreamParent* stream);
115 :
116 : virtual bool
117 : AnswerNPN_GetValue_NPNVjavascriptEnabledBool(bool* value, NPError* result);
118 : virtual bool
119 : AnswerNPN_GetValue_NPNVisOfflineBool(bool* value, NPError* result);
120 : virtual bool
121 : AnswerNPN_GetValue_NPNVnetscapeWindow(NativeWindowHandle* value,
122 : NPError* result);
123 : virtual bool
124 : AnswerNPN_GetValue_NPNVWindowNPObject(
125 : PPluginScriptableObjectParent** value,
126 : NPError* result);
127 : virtual bool
128 : AnswerNPN_GetValue_NPNVPluginElementNPObject(
129 : PPluginScriptableObjectParent** value,
130 : NPError* result);
131 : virtual bool
132 : AnswerNPN_GetValue_NPNVprivateModeBool(bool* value, NPError* result);
133 :
134 : virtual bool
135 : AnswerNPN_GetValue_NPNVdocumentOrigin(nsCString* value, NPError* result);
136 :
137 : virtual bool
138 : AnswerNPN_SetValue_NPPVpluginWindow(const bool& windowed, NPError* result);
139 : virtual bool
140 : AnswerNPN_SetValue_NPPVpluginTransparent(const bool& transparent,
141 : NPError* result);
142 : virtual bool
143 : AnswerNPN_SetValue_NPPVpluginUsesDOMForCursor(const bool& useDOMForCursor,
144 : NPError* result);
145 : virtual bool
146 : AnswerNPN_SetValue_NPPVpluginDrawingModel(const int& drawingModel,
147 : OptionalShmem *remoteImageData,
148 : CrossProcessMutexHandle *mutex,
149 : NPError* result);
150 : virtual bool
151 : AnswerNPN_SetValue_NPPVpluginEventModel(const int& eventModel,
152 : NPError* result);
153 :
154 : virtual bool
155 : AnswerNPN_GetURL(const nsCString& url, const nsCString& target,
156 : NPError *result);
157 :
158 : virtual bool
159 : AnswerNPN_PostURL(const nsCString& url, const nsCString& target,
160 : const nsCString& buffer, const bool& file,
161 : NPError* result);
162 :
163 : virtual PStreamNotifyParent*
164 : AllocPStreamNotify(const nsCString& url, const nsCString& target,
165 : const bool& post, const nsCString& buffer,
166 : const bool& file,
167 : NPError* result);
168 :
169 : NS_OVERRIDE virtual bool
170 : AnswerPStreamNotifyConstructor(PStreamNotifyParent* actor,
171 : const nsCString& url,
172 : const nsCString& target,
173 : const bool& post, const nsCString& buffer,
174 : const bool& file,
175 : NPError* result);
176 :
177 : virtual bool
178 : DeallocPStreamNotify(PStreamNotifyParent* notifyData);
179 :
180 : virtual bool
181 : RecvNPN_InvalidateRect(const NPRect& rect);
182 :
183 : // Async rendering
184 : virtual bool
185 : RecvShow(const NPRect& updatedRect,
186 : const SurfaceDescriptor& newSurface,
187 : SurfaceDescriptor* prevSurface);
188 :
189 : virtual PPluginSurfaceParent*
190 : AllocPPluginSurface(const WindowsSharedMemoryHandle& handle,
191 : const gfxIntSize& size,
192 : const bool& transparent);
193 :
194 : virtual bool
195 : DeallocPPluginSurface(PPluginSurfaceParent* s);
196 :
197 : virtual bool
198 : AnswerNPN_PushPopupsEnabledState(const bool& aState);
199 :
200 : virtual bool
201 : AnswerNPN_PopPopupsEnabledState();
202 :
203 : NS_OVERRIDE virtual bool
204 : AnswerNPN_GetValueForURL(const NPNURLVariable& variable,
205 : const nsCString& url,
206 : nsCString* value, NPError* result);
207 :
208 : NS_OVERRIDE virtual bool
209 : AnswerNPN_SetValueForURL(const NPNURLVariable& variable,
210 : const nsCString& url,
211 : const nsCString& value, NPError* result);
212 :
213 : NS_OVERRIDE virtual bool
214 : AnswerNPN_GetAuthenticationInfo(const nsCString& protocol,
215 : const nsCString& host,
216 : const int32_t& port,
217 : const nsCString& scheme,
218 : const nsCString& realm,
219 : nsCString* username,
220 : nsCString* password,
221 : NPError* result);
222 :
223 : NS_OVERRIDE virtual bool
224 : AnswerNPN_ConvertPoint(const double& sourceX,
225 : const bool& ignoreDestX,
226 : const double& sourceY,
227 : const bool& ignoreDestY,
228 : const NPCoordinateSpace& sourceSpace,
229 : const NPCoordinateSpace& destSpace,
230 : double *destX,
231 : double *destY,
232 : bool *result);
233 :
234 : virtual bool
235 : AnswerNPN_InitAsyncSurface(const gfxIntSize& size,
236 : const NPImageFormat& format,
237 : NPRemoteAsyncSurface* surfData,
238 : bool* result);
239 :
240 : virtual bool
241 : RecvRedrawPlugin();
242 :
243 : NS_OVERRIDE virtual bool
244 : RecvNegotiatedCarbon();
245 :
246 : NPError NPP_SetWindow(const NPWindow* aWindow);
247 :
248 : NPError NPP_GetValue(NPPVariable variable, void* retval);
249 : NPError NPP_SetValue(NPNVariable variable, void* value);
250 :
251 : void NPP_URLRedirectNotify(const char* url, int32_t status,
252 : void* notifyData);
253 :
254 : NPError NPP_NewStream(NPMIMEType type, NPStream* stream,
255 : NPBool seekable, uint16_t* stype);
256 : NPError NPP_DestroyStream(NPStream* stream, NPReason reason);
257 :
258 : void NPP_Print(NPPrint* platformPrint);
259 :
260 : int16_t NPP_HandleEvent(void* event);
261 :
262 : void NPP_URLNotify(const char* url, NPReason reason, void* notifyData);
263 :
264 0 : PluginModuleParent* Module()
265 : {
266 0 : return mParent;
267 : }
268 :
269 0 : const NPNetscapeFuncs* GetNPNIface()
270 : {
271 0 : return mNPNIface;
272 : }
273 :
274 : bool
275 : RegisterNPObjectForActor(NPObject* aObject,
276 : PluginScriptableObjectParent* aActor);
277 :
278 : void
279 : UnregisterNPObject(NPObject* aObject);
280 :
281 : PluginScriptableObjectParent*
282 : GetActorForNPObject(NPObject* aObject);
283 :
284 : NPP
285 0 : GetNPP()
286 : {
287 0 : return mNPP;
288 : }
289 :
290 : virtual bool
291 : AnswerPluginFocusChange(const bool& gotFocus);
292 :
293 : nsresult AsyncSetWindow(NPWindow* window);
294 : nsresult GetImageContainer(mozilla::layers::ImageContainer** aContainer);
295 : nsresult GetImageSize(nsIntSize* aSize);
296 : #ifdef XP_MACOSX
297 : nsresult IsRemoteDrawingCoreAnimation(bool *aDrawing);
298 : #endif
299 : nsresult SetBackgroundUnknown();
300 : nsresult BeginUpdateBackground(const nsIntRect& aRect,
301 : gfxContext** aCtx);
302 : nsresult EndUpdateBackground(gfxContext* aCtx,
303 : const nsIntRect& aRect);
304 : #if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
305 : nsresult HandleGUIEvent(const nsGUIEvent& anEvent, bool* handled);
306 : #endif
307 :
308 : void DidComposite() { SendNPP_DidComposite(); }
309 :
310 : private:
311 : // Create an appropriate platform surface for a background of size
312 : // |aSize|. Return true if successful.
313 : bool CreateBackground(const nsIntSize& aSize);
314 : void DestroyBackground();
315 : SurfaceDescriptor BackgroundDescriptor() /*const*/;
316 :
317 : typedef mozilla::layers::ImageContainer ImageContainer;
318 : ImageContainer *GetImageContainer();
319 :
320 : NS_OVERRIDE
321 : virtual PPluginBackgroundDestroyerParent*
322 : AllocPPluginBackgroundDestroyer();
323 :
324 : NS_OVERRIDE
325 : virtual bool
326 : DeallocPPluginBackgroundDestroyer(PPluginBackgroundDestroyerParent* aActor);
327 :
328 : bool InternalGetValueForNPObject(NPNVariable aVariable,
329 : PPluginScriptableObjectParent** aValue,
330 : NPError* aResult);
331 :
332 : bool IsAsyncDrawing();
333 :
334 : private:
335 : PluginModuleParent* mParent;
336 : NPP mNPP;
337 : const NPNetscapeFuncs* mNPNIface;
338 : NPWindowType mWindowType;
339 : Shmem mRemoteImageDataShmem;
340 : nsAutoPtr<CrossProcessMutex> mRemoteImageDataMutex;
341 : int16_t mDrawingModel;
342 : nsAutoPtr<mozilla::layers::CompositionNotifySink> mNotifySink;
343 :
344 : nsDataHashtable<nsVoidPtrHashKey, PluginScriptableObjectParent*> mScriptableObjects;
345 :
346 : #if defined(OS_WIN)
347 : private:
348 : // Used in rendering windowless plugins in other processes.
349 : bool SharedSurfaceSetWindow(const NPWindow* aWindow, NPRemoteWindow& aRemoteWindow);
350 : void SharedSurfaceBeforePaint(RECT &rect, NPRemoteEvent& npremoteevent);
351 : void SharedSurfaceAfterPaint(NPEvent* npevent);
352 : void SharedSurfaceRelease();
353 : // Used in handling parent/child forwarding of events.
354 : static LRESULT CALLBACK PluginWindowHookProc(HWND hWnd, UINT message,
355 : WPARAM wParam, LPARAM lParam);
356 : void SubclassPluginWindow(HWND aWnd);
357 : void UnsubclassPluginWindow();
358 :
359 : private:
360 : gfx::SharedDIBWin mSharedSurfaceDib;
361 : nsIntRect mPluginPort;
362 : nsIntRect mSharedSize;
363 : HWND mPluginHWND;
364 : WNDPROC mPluginWndProc;
365 : bool mNestedEventState;
366 : #endif // defined(XP_WIN)
367 : #if defined(MOZ_WIDGET_COCOA)
368 : private:
369 : Shmem mShSurface;
370 : uint16_t mShWidth;
371 : uint16_t mShHeight;
372 : CGColorSpaceRef mShColorSpace;
373 : nsRefPtr<nsIOSurface> mIOSurface;
374 : nsRefPtr<nsIOSurface> mFrontIOSurface;
375 : #endif // definied(MOZ_WIDGET_COCOA)
376 :
377 : // ObjectFrame layer wrapper
378 : nsRefPtr<gfxASurface> mFrontSurface;
379 : // For windowless+transparent instances, this surface contains a
380 : // "pretty recent" copy of the pixels under its <object> frame.
381 : // On the plugin side, we use this surface to avoid doing alpha
382 : // recovery when possible. This surface is created and owned by
383 : // the browser, but a "read-only" reference is sent to the plugin.
384 : //
385 : // We have explicitly chosen not to provide any guarantees about
386 : // the consistency of the pixels in |mBackground|. A plugin may
387 : // be able to observe partial updates to the background.
388 : nsRefPtr<gfxASurface> mBackground;
389 :
390 : nsRefPtr<ImageContainer> mImageContainer;
391 : };
392 :
393 :
394 : } // namespace plugins
395 : } // namespace mozilla
396 :
397 : #endif // ifndef dom_plugins_PluginInstanceParent_h
|