|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 // vim:set ts=2 sts=2 sw=2 et cin: |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsPluginInstanceOwner_h_ |
|
8 #define nsPluginInstanceOwner_h_ |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "npapi.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsIPluginInstanceOwner.h" |
|
14 #include "nsIPrivacyTransitionObserver.h" |
|
15 #include "nsIDOMEventListener.h" |
|
16 #include "nsPluginHost.h" |
|
17 #include "nsPluginNativeWindow.h" |
|
18 #include "nsWeakReference.h" |
|
19 #include "gfxRect.h" |
|
20 |
|
21 #ifdef XP_MACOSX |
|
22 #include "mozilla/gfx/QuartzSupport.h" |
|
23 #include <ApplicationServices/ApplicationServices.h> |
|
24 #endif |
|
25 |
|
26 class nsIInputStream; |
|
27 struct nsIntRect; |
|
28 class nsPluginDOMContextMenuListener; |
|
29 class nsObjectFrame; |
|
30 class nsDisplayListBuilder; |
|
31 |
|
32 #ifdef MOZ_X11 |
|
33 class gfxXlibSurface; |
|
34 #ifdef MOZ_WIDGET_QT |
|
35 #include "gfxQtNativeRenderer.h" |
|
36 #else |
|
37 #include "gfxXlibNativeRenderer.h" |
|
38 #endif |
|
39 #endif |
|
40 |
|
41 class nsPluginInstanceOwner : public nsIPluginInstanceOwner, |
|
42 public nsIDOMEventListener, |
|
43 public nsIPrivacyTransitionObserver, |
|
44 public nsSupportsWeakReference |
|
45 { |
|
46 public: |
|
47 nsPluginInstanceOwner(); |
|
48 virtual ~nsPluginInstanceOwner(); |
|
49 |
|
50 NS_DECL_ISUPPORTS |
|
51 NS_DECL_NSIPLUGININSTANCEOWNER |
|
52 NS_DECL_NSIPRIVACYTRANSITIONOBSERVER |
|
53 |
|
54 NS_IMETHOD GetURL(const char *aURL, const char *aTarget, |
|
55 nsIInputStream *aPostStream, |
|
56 void *aHeadersData, uint32_t aHeadersDataLen) MOZ_OVERRIDE; |
|
57 |
|
58 NS_IMETHOD ShowStatus(const char16_t *aStatusMsg) MOZ_OVERRIDE; |
|
59 |
|
60 NPError ShowNativeContextMenu(NPMenu* menu, void* event) MOZ_OVERRIDE; |
|
61 |
|
62 NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, |
|
63 double *destX, double *destY, NPCoordinateSpace destSpace) MOZ_OVERRIDE; |
|
64 |
|
65 virtual NPError InitAsyncSurface(NPSize *size, NPImageFormat format, |
|
66 void *initData, NPAsyncSurface *surface) MOZ_OVERRIDE; |
|
67 virtual NPError FinalizeAsyncSurface(NPAsyncSurface *surface) MOZ_OVERRIDE; |
|
68 virtual void SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed) MOZ_OVERRIDE; |
|
69 |
|
70 /** |
|
71 * Get the type of the HTML tag that was used ot instantiate this |
|
72 * plugin. Currently supported tags are EMBED, OBJECT and APPLET. |
|
73 */ |
|
74 NS_IMETHOD GetTagType(nsPluginTagType *aResult); |
|
75 |
|
76 /** |
|
77 * Get a ptr to the paired list of parameter names and values, |
|
78 * returns the length of the array. |
|
79 * |
|
80 * Each name or value is a null-terminated string. |
|
81 */ |
|
82 NS_IMETHOD GetParameters(uint16_t& aCount, |
|
83 const char*const*& aNames, |
|
84 const char*const*& aValues); |
|
85 |
|
86 /** |
|
87 * Get the value for the named parameter. Returns null |
|
88 * if the parameter was not set. |
|
89 * |
|
90 * @param aName - name of the parameter |
|
91 * @param aResult - parameter value |
|
92 * @result - NS_OK if this operation was successful |
|
93 */ |
|
94 NS_IMETHOD GetParameter(const char* aName, const char* *aResult); |
|
95 |
|
96 /** |
|
97 * QueryInterface on nsIPluginInstancePeer to get this. |
|
98 * |
|
99 * (Corresponds to NPP_New's argc, argn, and argv arguments.) |
|
100 * Get a ptr to the paired list of attribute names and values, |
|
101 * returns the length of the array. |
|
102 * |
|
103 * Each name or value is a null-terminated string. |
|
104 */ |
|
105 NS_IMETHOD GetAttributes(uint16_t& aCount, |
|
106 const char*const*& aNames, |
|
107 const char*const*& aValues); |
|
108 |
|
109 |
|
110 /** |
|
111 * Gets the value for the named attribute. |
|
112 * |
|
113 * @param aName - the name of the attribute to find |
|
114 * @param aResult - the resulting attribute |
|
115 * @result - NS_OK if this operation was successful, NS_ERROR_FAILURE if |
|
116 * this operation failed. result is set to NULL if the attribute is not found |
|
117 * else to the found value. |
|
118 */ |
|
119 NS_IMETHOD GetAttribute(const char* aName, const char* *aResult); |
|
120 |
|
121 /** |
|
122 * Returns the DOM element corresponding to the tag which references |
|
123 * this plugin in the document. |
|
124 * |
|
125 * @param aDOMElement - resulting DOM element |
|
126 * @result - NS_OK if this operation was successful |
|
127 */ |
|
128 NS_IMETHOD GetDOMElement(nsIDOMElement* * aResult); |
|
129 |
|
130 // nsIDOMEventListener interfaces |
|
131 NS_DECL_NSIDOMEVENTLISTENER |
|
132 |
|
133 nsresult ProcessMouseDown(nsIDOMEvent* aKeyEvent); |
|
134 nsresult ProcessKeyPress(nsIDOMEvent* aKeyEvent); |
|
135 nsresult Destroy(); |
|
136 |
|
137 #ifdef XP_WIN |
|
138 void Paint(const RECT& aDirty, HDC aDC); |
|
139 #elif defined(XP_MACOSX) |
|
140 void Paint(const gfxRect& aDirtyRect, CGContextRef cgContext); |
|
141 void RenderCoreAnimation(CGContextRef aCGContext, int aWidth, int aHeight); |
|
142 void DoCocoaEventDrawRect(const gfxRect& aDrawRect, CGContextRef cgContext); |
|
143 #elif defined(MOZ_X11) || defined(ANDROID) |
|
144 void Paint(gfxContext* aContext, |
|
145 const gfxRect& aFrameRect, |
|
146 const gfxRect& aDirtyRect); |
|
147 #endif |
|
148 |
|
149 //locals |
|
150 |
|
151 nsresult Init(nsIContent* aContent); |
|
152 |
|
153 void* GetPluginPortFromWidget(); |
|
154 void ReleasePluginPort(void* pluginPort); |
|
155 |
|
156 nsEventStatus ProcessEvent(const mozilla::WidgetGUIEvent& anEvent); |
|
157 |
|
158 #ifdef XP_MACOSX |
|
159 enum { ePluginPaintEnable, ePluginPaintDisable }; |
|
160 |
|
161 NPDrawingModel GetDrawingModel(); |
|
162 bool IsRemoteDrawingCoreAnimation(); |
|
163 nsresult ContentsScaleFactorChanged(double aContentsScaleFactor); |
|
164 NPEventModel GetEventModel(); |
|
165 static void CARefresh(nsITimer *aTimer, void *aClosure); |
|
166 void AddToCARefreshTimer(); |
|
167 void RemoveFromCARefreshTimer(); |
|
168 // This calls into the plugin (NPP_SetWindow) and can run script. |
|
169 void* FixUpPluginWindow(int32_t inPaintState); |
|
170 void HidePluginWindow(); |
|
171 // Set a flag that (if true) indicates the plugin port info has changed and |
|
172 // SetWindow() needs to be called. |
|
173 void SetPluginPortChanged(bool aState) { mPluginPortChanged = aState; } |
|
174 // Return a pointer to the internal nsPluginPort structure that's used to |
|
175 // store a copy of plugin port info and to detect when it's been changed. |
|
176 void* GetPluginPortCopy(); |
|
177 // Set plugin port info in the plugin (in the 'window' member of the |
|
178 // NPWindow structure passed to the plugin by SetWindow()) and set a |
|
179 // flag (mPluginPortChanged) to indicate whether or not this info has |
|
180 // changed, and SetWindow() needs to be called again. |
|
181 void* SetPluginPortAndDetectChange(); |
|
182 // Flag when we've set up a Thebes (and CoreGraphics) context in |
|
183 // nsObjectFrame::PaintPlugin(). We need to know this in |
|
184 // FixUpPluginWindow() (i.e. we need to know when FixUpPluginWindow() has |
|
185 // been called from nsObjectFrame::PaintPlugin() when we're using the |
|
186 // CoreGraphics drawing model). |
|
187 void BeginCGPaint(); |
|
188 void EndCGPaint(); |
|
189 #else // XP_MACOSX |
|
190 void UpdateWindowPositionAndClipRect(bool aSetWindow); |
|
191 void UpdateWindowVisibility(bool aVisible); |
|
192 void UpdateDocumentActiveState(bool aIsActive); |
|
193 #endif // XP_MACOSX |
|
194 |
|
195 void SetFrame(nsObjectFrame *aFrame); |
|
196 nsObjectFrame* GetFrame(); |
|
197 |
|
198 uint32_t GetLastEventloopNestingLevel() const { |
|
199 return mLastEventloopNestingLevel; |
|
200 } |
|
201 |
|
202 static uint32_t GetEventloopNestingLevel(); |
|
203 |
|
204 void ConsiderNewEventloopNestingLevel() { |
|
205 uint32_t currentLevel = GetEventloopNestingLevel(); |
|
206 |
|
207 if (currentLevel < mLastEventloopNestingLevel) { |
|
208 mLastEventloopNestingLevel = currentLevel; |
|
209 } |
|
210 } |
|
211 |
|
212 const char* GetPluginName() |
|
213 { |
|
214 if (mInstance && mPluginHost) { |
|
215 const char* name = nullptr; |
|
216 if (NS_SUCCEEDED(mPluginHost->GetPluginName(mInstance, &name)) && name) |
|
217 return name; |
|
218 } |
|
219 return ""; |
|
220 } |
|
221 |
|
222 #ifdef MOZ_X11 |
|
223 void GetPluginDescription(nsACString& aDescription) |
|
224 { |
|
225 aDescription.Truncate(); |
|
226 if (mInstance && mPluginHost) { |
|
227 nsCOMPtr<nsIPluginTag> pluginTag; |
|
228 |
|
229 mPluginHost->GetPluginTagForInstance(mInstance, |
|
230 getter_AddRefs(pluginTag)); |
|
231 if (pluginTag) { |
|
232 pluginTag->GetDescription(aDescription); |
|
233 } |
|
234 } |
|
235 } |
|
236 #endif |
|
237 |
|
238 bool SendNativeEvents() |
|
239 { |
|
240 #ifdef XP_WIN |
|
241 // XXX we should remove the plugin name check |
|
242 return mPluginWindow->type == NPWindowTypeDrawable && |
|
243 (MatchPluginName("Shockwave Flash") || |
|
244 MatchPluginName("Test Plug-in")); |
|
245 #elif defined(MOZ_X11) || defined(XP_MACOSX) |
|
246 return true; |
|
247 #else |
|
248 return false; |
|
249 #endif |
|
250 } |
|
251 |
|
252 bool MatchPluginName(const char *aPluginName) |
|
253 { |
|
254 return strncmp(GetPluginName(), aPluginName, strlen(aPluginName)) == 0; |
|
255 } |
|
256 |
|
257 void NotifyPaintWaiter(nsDisplayListBuilder* aBuilder); |
|
258 |
|
259 // Returns the image container that has our currently displayed image. |
|
260 already_AddRefed<mozilla::layers::ImageContainer> GetImageContainer(); |
|
261 |
|
262 /** |
|
263 * Returns the bounds of the current async-rendered surface. This can only |
|
264 * change in response to messages received by the event loop (i.e. not during |
|
265 * painting). |
|
266 */ |
|
267 nsIntSize GetCurrentImageSize(); |
|
268 |
|
269 // Methods to update the background image we send to async plugins. |
|
270 // The eventual target of these operations is PluginInstanceParent, |
|
271 // but it takes several hops to get there. |
|
272 void SetBackgroundUnknown(); |
|
273 already_AddRefed<gfxContext> BeginUpdateBackground(const nsIntRect& aRect); |
|
274 void EndUpdateBackground(gfxContext* aContext, const nsIntRect& aRect); |
|
275 |
|
276 bool UseAsyncRendering(); |
|
277 |
|
278 already_AddRefed<nsIURI> GetBaseURI() const; |
|
279 |
|
280 #ifdef MOZ_WIDGET_ANDROID |
|
281 // Returns the image container for the specified VideoInfo |
|
282 void GetVideos(nsTArray<nsNPAPIPluginInstance::VideoInfo*>& aVideos); |
|
283 already_AddRefed<mozilla::layers::ImageContainer> GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInfo* aVideoInfo); |
|
284 |
|
285 void Invalidate(); |
|
286 |
|
287 void RequestFullScreen(); |
|
288 void ExitFullScreen(); |
|
289 |
|
290 // Called from AndroidJNI when we removed the fullscreen view. |
|
291 static void ExitFullScreen(jobject view); |
|
292 #endif |
|
293 |
|
294 private: |
|
295 |
|
296 // return FALSE if LayerSurface dirty (newly created and don't have valid plugin content yet) |
|
297 bool IsUpToDate() |
|
298 { |
|
299 nsIntSize size; |
|
300 return NS_SUCCEEDED(mInstance->GetImageSize(&size)) && |
|
301 size == nsIntSize(mPluginWindow->width, mPluginWindow->height); |
|
302 } |
|
303 |
|
304 void FixUpURLS(const nsString &name, nsAString &value); |
|
305 #ifdef MOZ_WIDGET_ANDROID |
|
306 mozilla::LayoutDeviceRect GetPluginRect(); |
|
307 bool AddPluginView(const mozilla::LayoutDeviceRect& aRect = mozilla::LayoutDeviceRect(0, 0, 0, 0)); |
|
308 void RemovePluginView(); |
|
309 |
|
310 bool mFullScreen; |
|
311 void* mJavaView; |
|
312 #endif |
|
313 |
|
314 nsPluginNativeWindow *mPluginWindow; |
|
315 nsRefPtr<nsNPAPIPluginInstance> mInstance; |
|
316 nsObjectFrame *mObjectFrame; |
|
317 nsIContent *mContent; // WEAK, content owns us |
|
318 nsCString mDocumentBase; |
|
319 bool mWidgetCreationComplete; |
|
320 nsCOMPtr<nsIWidget> mWidget; |
|
321 nsRefPtr<nsPluginHost> mPluginHost; |
|
322 |
|
323 #ifdef XP_MACOSX |
|
324 NP_CGContext mCGPluginPortCopy; |
|
325 int32_t mInCGPaintLevel; |
|
326 mozilla::RefPtr<MacIOSurface> mIOSurface; |
|
327 mozilla::RefPtr<nsCARenderer> mCARenderer; |
|
328 CGColorSpaceRef mColorProfile; |
|
329 static nsCOMPtr<nsITimer> *sCATimer; |
|
330 static nsTArray<nsPluginInstanceOwner*> *sCARefreshListeners; |
|
331 bool mSentInitialTopLevelWindowEvent; |
|
332 #endif |
|
333 |
|
334 // Initially, the event loop nesting level we were created on, it's updated |
|
335 // if we detect the appshell is on a lower level as long as we're not stopped. |
|
336 // We delay DoStopPlugin() until the appshell reaches this level or lower. |
|
337 uint32_t mLastEventloopNestingLevel; |
|
338 bool mContentFocused; |
|
339 bool mWidgetVisible; // used on Mac to store our widget's visible state |
|
340 #ifdef XP_MACOSX |
|
341 bool mPluginPortChanged; |
|
342 #endif |
|
343 #ifdef MOZ_X11 |
|
344 // Used with windowless plugins only, initialized in CreateWidget(). |
|
345 bool mFlash10Quirks; |
|
346 #endif |
|
347 bool mPluginWindowVisible; |
|
348 bool mPluginDocumentActiveState; |
|
349 |
|
350 uint16_t mNumCachedAttrs; |
|
351 uint16_t mNumCachedParams; |
|
352 char **mCachedAttrParamNames; |
|
353 char **mCachedAttrParamValues; |
|
354 |
|
355 #ifdef XP_MACOSX |
|
356 NPEventModel mEventModel; |
|
357 // This is a hack! UseAsyncRendering() can incorrectly return false |
|
358 // when we don't have an object frame (possible as of bug 90268). |
|
359 // We hack around this by always returning true if we've ever |
|
360 // returned true. |
|
361 bool mUseAsyncRendering; |
|
362 #endif |
|
363 |
|
364 // pointer to wrapper for nsIDOMContextMenuListener |
|
365 nsRefPtr<nsPluginDOMContextMenuListener> mCXMenuListener; |
|
366 |
|
367 nsresult DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent); |
|
368 nsresult DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent, |
|
369 bool aAllowPropagate = false); |
|
370 nsresult DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent); |
|
371 |
|
372 int mLastMouseDownButtonType; |
|
373 |
|
374 nsresult EnsureCachedAttrParamArrays(); |
|
375 |
|
376 #ifdef MOZ_X11 |
|
377 class Renderer |
|
378 #if defined(MOZ_WIDGET_QT) |
|
379 : public gfxQtNativeRenderer |
|
380 #else |
|
381 : public gfxXlibNativeRenderer |
|
382 #endif |
|
383 { |
|
384 public: |
|
385 Renderer(NPWindow* aWindow, nsPluginInstanceOwner* aInstanceOwner, |
|
386 const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect) |
|
387 : mWindow(aWindow), mInstanceOwner(aInstanceOwner), |
|
388 mPluginSize(aPluginSize), mDirtyRect(aDirtyRect) |
|
389 {} |
|
390 virtual nsresult DrawWithXlib(cairo_surface_t* surface, |
|
391 nsIntPoint offset, |
|
392 nsIntRect* clipRects, uint32_t numClipRects) MOZ_OVERRIDE; |
|
393 private: |
|
394 NPWindow* mWindow; |
|
395 nsPluginInstanceOwner* mInstanceOwner; |
|
396 const nsIntSize& mPluginSize; |
|
397 const nsIntRect& mDirtyRect; |
|
398 }; |
|
399 #endif |
|
400 |
|
401 bool mWaitingForPaint; |
|
402 }; |
|
403 |
|
404 #endif // nsPluginInstanceOwner_h_ |
|
405 |