/src/mozilla-central/dom/plugins/base/nsPluginInstanceOwner.h
Line | Count | Source (jump to first uncovered line) |
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 "mozilla/StaticPtr.h" |
12 | | #include "npapi.h" |
13 | | #include "nsCOMPtr.h" |
14 | | #include "nsIKeyEventInPluginCallback.h" |
15 | | #include "nsIPluginInstanceOwner.h" |
16 | | #include "nsIPrivacyTransitionObserver.h" |
17 | | #include "nsIDOMEventListener.h" |
18 | | #include "nsPluginHost.h" |
19 | | #include "nsPluginNativeWindow.h" |
20 | | #include "nsWeakReference.h" |
21 | | #include "gfxRect.h" |
22 | | |
23 | | #ifdef XP_MACOSX |
24 | | #include "mozilla/gfx/QuartzSupport.h" |
25 | | #include <ApplicationServices/ApplicationServices.h> |
26 | | #endif |
27 | | |
28 | | class nsIInputStream; |
29 | | class nsPluginDOMContextMenuListener; |
30 | | class nsPluginFrame; |
31 | | class nsDisplayListBuilder; |
32 | | |
33 | | #if defined(MOZ_X11) |
34 | | class gfxContext; |
35 | | #endif |
36 | | |
37 | | namespace mozilla { |
38 | | class TextComposition; |
39 | | namespace dom { |
40 | | class Element; |
41 | | class Event; |
42 | | struct MozPluginParameter; |
43 | | } // namespace dom |
44 | | namespace widget { |
45 | | class PuppetWidget; |
46 | | } // namespace widget |
47 | | } // namespace mozilla |
48 | | |
49 | | using mozilla::widget::PuppetWidget; |
50 | | |
51 | | #ifdef MOZ_X11 |
52 | | #include "gfxXlibNativeRenderer.h" |
53 | | #endif |
54 | | |
55 | | class nsPluginInstanceOwner final : public nsIPluginInstanceOwner |
56 | | , public nsIDOMEventListener |
57 | | , public nsIPrivacyTransitionObserver |
58 | | , public nsIKeyEventInPluginCallback |
59 | | , public nsSupportsWeakReference |
60 | | { |
61 | | public: |
62 | | typedef mozilla::gfx::DrawTarget DrawTarget; |
63 | | |
64 | | nsPluginInstanceOwner(); |
65 | | |
66 | | NS_DECL_ISUPPORTS |
67 | | NS_DECL_NSIPLUGININSTANCEOWNER |
68 | | NS_DECL_NSIPRIVACYTRANSITIONOBSERVER |
69 | | |
70 | | NS_IMETHOD GetURL(const char *aURL, const char *aTarget, |
71 | | nsIInputStream *aPostStream, |
72 | | void *aHeadersData, uint32_t aHeadersDataLen, |
73 | | bool aDoCheckLoadURIChecks) override; |
74 | | |
75 | | NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace, |
76 | | double *destX, double *destY, NPCoordinateSpace destSpace) override; |
77 | | |
78 | | NPError InitAsyncSurface(NPSize *size, NPImageFormat format, |
79 | | void *initData, NPAsyncSurface *surface) override; |
80 | | NPError FinalizeAsyncSurface(NPAsyncSurface *surface) override; |
81 | | void SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed) override; |
82 | | |
83 | | /** |
84 | | * Get the type of the HTML tag that was used ot instantiate this |
85 | | * plugin. Currently supported tags are EMBED or OBJECT. |
86 | | */ |
87 | | NS_IMETHOD GetTagType(nsPluginTagType *aResult); |
88 | | |
89 | | void GetParameters(nsTArray<mozilla::dom::MozPluginParameter>& parameters); |
90 | | void GetAttributes(nsTArray<mozilla::dom::MozPluginParameter>& attributes); |
91 | | |
92 | | /** |
93 | | * Returns the DOM element corresponding to the tag which references |
94 | | * this plugin in the document. |
95 | | * |
96 | | * @param aDOMElement - resulting DOM element |
97 | | * @result - NS_OK if this operation was successful |
98 | | */ |
99 | | NS_IMETHOD GetDOMElement(mozilla::dom::Element** aResult); |
100 | | |
101 | | // nsIDOMEventListener interfaces |
102 | | NS_DECL_NSIDOMEVENTLISTENER |
103 | | |
104 | | nsresult ProcessMouseDown(mozilla::dom::Event* aMouseEvent); |
105 | | nsresult ProcessKeyPress(mozilla::dom::Event* aKeyEvent); |
106 | | nsresult Destroy(); |
107 | | |
108 | | #ifdef XP_WIN |
109 | | void Paint(const RECT& aDirty, HDC aDC); |
110 | | #elif defined(XP_MACOSX) |
111 | | void Paint(const gfxRect& aDirtyRect, CGContextRef cgContext); |
112 | | void RenderCoreAnimation(CGContextRef aCGContext, int aWidth, int aHeight); |
113 | | void DoCocoaEventDrawRect(const gfxRect& aDrawRect, CGContextRef cgContext); |
114 | | #elif defined(MOZ_X11) |
115 | | void Paint(gfxContext* aContext, |
116 | | const gfxRect& aFrameRect, |
117 | | const gfxRect& aDirtyRect); |
118 | | #endif |
119 | | |
120 | | //locals |
121 | | |
122 | | nsresult Init(nsIContent* aContent); |
123 | | |
124 | | void* GetPluginPort(); |
125 | | void ReleasePluginPort(void* pluginPort); |
126 | | |
127 | | nsEventStatus ProcessEvent(const mozilla::WidgetGUIEvent& anEvent); |
128 | | |
129 | | static void GeneratePluginEvent( |
130 | | const mozilla::WidgetCompositionEvent* aSrcCompositionEvent, |
131 | | mozilla::WidgetCompositionEvent* aDistCompositionEvent); |
132 | | |
133 | | #if defined(XP_WIN) |
134 | | void SetWidgetWindowAsParent(HWND aWindowToAdopt); |
135 | | nsresult SetNetscapeWindowAsParent(HWND aWindowToAdopt); |
136 | | #endif |
137 | | |
138 | | #ifdef XP_MACOSX |
139 | | enum { ePluginPaintEnable, ePluginPaintDisable }; |
140 | | |
141 | | void WindowFocusMayHaveChanged(); |
142 | | |
143 | | bool WindowIsActive(); |
144 | | void SendWindowFocusChanged(bool aIsActive); |
145 | | NPDrawingModel GetDrawingModel(); |
146 | | bool IsRemoteDrawingCoreAnimation(); |
147 | | |
148 | | NPEventModel GetEventModel(); |
149 | | static void CARefresh(nsITimer *aTimer, void *aClosure); |
150 | | void AddToCARefreshTimer(); |
151 | | void RemoveFromCARefreshTimer(); |
152 | | // This calls into the plugin (NPP_SetWindow) and can run script. |
153 | | void FixUpPluginWindow(int32_t inPaintState); |
154 | | void HidePluginWindow(); |
155 | | // Set plugin port info in the plugin (in the 'window' member of the |
156 | | // NPWindow structure passed to the plugin by SetWindow()). |
157 | | void SetPluginPort(); |
158 | | #else // XP_MACOSX |
159 | | void UpdateWindowPositionAndClipRect(bool aSetWindow); |
160 | | void UpdateWindowVisibility(bool aVisible); |
161 | | #endif // XP_MACOSX |
162 | | |
163 | | void ResolutionMayHaveChanged(); |
164 | | #if defined(XP_MACOSX) || defined(XP_WIN) |
165 | | nsresult ContentsScaleFactorChanged(double aContentsScaleFactor); |
166 | | #endif |
167 | | |
168 | | void UpdateDocumentActiveState(bool aIsActive); |
169 | | |
170 | | void SetFrame(nsPluginFrame *aFrame); |
171 | | nsPluginFrame* GetFrame(); |
172 | | |
173 | | uint32_t GetLastEventloopNestingLevel() const { |
174 | | return mLastEventloopNestingLevel; |
175 | | } |
176 | | |
177 | | static uint32_t GetEventloopNestingLevel(); |
178 | | |
179 | 0 | void ConsiderNewEventloopNestingLevel() { |
180 | 0 | uint32_t currentLevel = GetEventloopNestingLevel(); |
181 | 0 |
|
182 | 0 | if (currentLevel < mLastEventloopNestingLevel) { |
183 | 0 | mLastEventloopNestingLevel = currentLevel; |
184 | 0 | } |
185 | 0 | } |
186 | | |
187 | | const char* GetPluginName() |
188 | | { |
189 | | if (mInstance && mPluginHost) { |
190 | | const char* name = nullptr; |
191 | | if (NS_SUCCEEDED(mPluginHost->GetPluginName(mInstance, &name)) && name) |
192 | | return name; |
193 | | } |
194 | | return ""; |
195 | | } |
196 | | |
197 | | #ifdef MOZ_X11 |
198 | | void GetPluginDescription(nsACString& aDescription) |
199 | 0 | { |
200 | 0 | aDescription.Truncate(); |
201 | 0 | if (mInstance && mPluginHost) { |
202 | 0 | nsCOMPtr<nsIPluginTag> pluginTag; |
203 | 0 |
|
204 | 0 | mPluginHost->GetPluginTagForInstance(mInstance, |
205 | 0 | getter_AddRefs(pluginTag)); |
206 | 0 | if (pluginTag) { |
207 | 0 | pluginTag->GetDescription(aDescription); |
208 | 0 | } |
209 | 0 | } |
210 | 0 | } |
211 | | #endif |
212 | | |
213 | | bool SendNativeEvents() |
214 | 0 | { |
215 | | #ifdef XP_WIN |
216 | | // XXX we should remove the plugin name check |
217 | | return mPluginWindow->type == NPWindowTypeDrawable && |
218 | | (MatchPluginName("Shockwave Flash") || |
219 | | MatchPluginName("Test Plug-in")); |
220 | | #elif defined(MOZ_X11) || defined(XP_MACOSX) |
221 | | return true; |
222 | | #else |
223 | | return false; |
224 | | #endif |
225 | | } |
226 | | |
227 | | bool MatchPluginName(const char *aPluginName) |
228 | | { |
229 | | return strncmp(GetPluginName(), aPluginName, strlen(aPluginName)) == 0; |
230 | | } |
231 | | |
232 | | void NotifyPaintWaiter(nsDisplayListBuilder* aBuilder); |
233 | | |
234 | | // Returns the image container that has our currently displayed image. |
235 | | already_AddRefed<mozilla::layers::ImageContainer> GetImageContainer(); |
236 | | // Returns true if this is windowed plugin that can return static captures |
237 | | // for scroll operations. |
238 | | bool NeedsScrollImageLayer(); |
239 | | |
240 | | void DidComposite(); |
241 | | |
242 | | /** |
243 | | * Returns the bounds of the current async-rendered surface. This can only |
244 | | * change in response to messages received by the event loop (i.e. not during |
245 | | * painting). |
246 | | */ |
247 | | nsIntSize GetCurrentImageSize(); |
248 | | |
249 | | // Methods to update the background image we send to async plugins. |
250 | | // The eventual target of these operations is PluginInstanceParent, |
251 | | // but it takes several hops to get there. |
252 | | void SetBackgroundUnknown(); |
253 | | already_AddRefed<DrawTarget> BeginUpdateBackground(const nsIntRect& aRect); |
254 | | void EndUpdateBackground(const nsIntRect& aRect); |
255 | | |
256 | | bool UseAsyncRendering(); |
257 | | |
258 | | already_AddRefed<nsIURI> GetBaseURI() const; |
259 | | |
260 | | bool GetCompositionString(uint32_t aIndex, nsTArray<uint8_t>* aString, |
261 | | int32_t* aLength); |
262 | | bool SetCandidateWindow( |
263 | | const mozilla::widget::CandidateWindowPosition& aPosition); |
264 | | bool RequestCommitOrCancel(bool aCommitted); |
265 | | bool EnableIME(bool aEnable); |
266 | | |
267 | | // See nsIKeyEventInPluginCallback |
268 | | virtual void HandledWindowedPluginKeyEvent( |
269 | | const mozilla::NativeEventData& aKeyEventData, |
270 | | bool aIsConsumed) override; |
271 | | |
272 | | /** |
273 | | * OnWindowedPluginKeyEvent() is called when the plugin process receives |
274 | | * native key event directly. |
275 | | * |
276 | | * @param aNativeKeyData The key event which was received by the |
277 | | * plugin process directly. |
278 | | */ |
279 | | void OnWindowedPluginKeyEvent( |
280 | | const mozilla::NativeEventData& aNativeKeyData); |
281 | | |
282 | | void GetCSSZoomFactor(float *result); |
283 | | private: |
284 | | virtual ~nsPluginInstanceOwner(); |
285 | | |
286 | | // return FALSE if LayerSurface dirty (newly created and don't have valid plugin content yet) |
287 | | bool IsUpToDate() |
288 | 0 | { |
289 | 0 | nsIntSize size; |
290 | 0 | return NS_SUCCEEDED(mInstance->GetImageSize(&size)) && |
291 | 0 | size == nsIntSize(mPluginWindow->width, mPluginWindow->height); |
292 | 0 | } |
293 | | |
294 | | #if defined(XP_WIN) |
295 | | nsIWidget* GetContainingWidgetIfOffset(); |
296 | | already_AddRefed<mozilla::TextComposition> GetTextComposition(); |
297 | | void HandleNoConsumedCompositionMessage( |
298 | | mozilla::WidgetCompositionEvent* aCompositionEvent, |
299 | | const NPEvent* aPluginEvent); |
300 | | bool mGotCompositionData; |
301 | | bool mSentStartComposition; |
302 | | bool mPluginDidNotHandleIMEComposition; |
303 | | #endif |
304 | | |
305 | | nsPluginNativeWindow *mPluginWindow; |
306 | | RefPtr<nsNPAPIPluginInstance> mInstance; |
307 | | nsPluginFrame *mPluginFrame; |
308 | | nsWeakPtr mContent; // WEAK, content owns us |
309 | | nsCString mDocumentBase; |
310 | | bool mWidgetCreationComplete; |
311 | | nsCOMPtr<nsIWidget> mWidget; |
312 | | RefPtr<nsPluginHost> mPluginHost; |
313 | | |
314 | | #ifdef XP_MACOSX |
315 | | static mozilla::StaticRefPtr<nsITimer> sCATimer; |
316 | | static nsTArray<nsPluginInstanceOwner*> *sCARefreshListeners; |
317 | | bool mSentInitialTopLevelWindowEvent; |
318 | | bool mLastWindowIsActive; |
319 | | bool mLastContentFocused; |
320 | | // True if, the next time the window is activated, we should blur ourselves. |
321 | | bool mShouldBlurOnActivate; |
322 | | #endif |
323 | | double mLastScaleFactor; |
324 | | double mLastCSSZoomFactor; |
325 | | // Initially, the event loop nesting level we were created on, it's updated |
326 | | // if we detect the appshell is on a lower level as long as we're not stopped. |
327 | | // We delay DoStopPlugin() until the appshell reaches this level or lower. |
328 | | uint32_t mLastEventloopNestingLevel; |
329 | | bool mContentFocused; |
330 | | bool mWidgetVisible; // used on Mac to store our widget's visible state |
331 | | #ifdef MOZ_X11 |
332 | | // Used with windowless plugins only, initialized in CreateWidget(). |
333 | | bool mFlash10Quirks; |
334 | | #endif |
335 | | bool mPluginWindowVisible; |
336 | | bool mPluginDocumentActiveState; |
337 | | |
338 | | #ifdef XP_MACOSX |
339 | | NPEventModel mEventModel; |
340 | | // This is a hack! UseAsyncRendering() can incorrectly return false |
341 | | // when we don't have an object frame (possible as of bug 90268). |
342 | | // We hack around this by always returning true if we've ever |
343 | | // returned true. |
344 | | bool mUseAsyncRendering; |
345 | | #endif |
346 | | |
347 | | // pointer to wrapper for nsIDOMContextMenuListener |
348 | | RefPtr<nsPluginDOMContextMenuListener> mCXMenuListener; |
349 | | |
350 | | nsresult DispatchKeyToPlugin(mozilla::dom::Event* aKeyEvent); |
351 | | nsresult DispatchMouseToPlugin(mozilla::dom::Event* aMouseEvent, |
352 | | bool aAllowPropagate = false); |
353 | | nsresult DispatchFocusToPlugin(mozilla::dom::Event* aFocusEvent); |
354 | | nsresult DispatchCompositionToPlugin(mozilla::dom::Event* aEvent); |
355 | | |
356 | | #ifdef XP_WIN |
357 | | void CallDefaultProc(const mozilla::WidgetGUIEvent* aEvent); |
358 | | #endif |
359 | | |
360 | | #ifdef XP_MACOSX |
361 | | static NPBool ConvertPointPuppet(PuppetWidget *widget, nsPluginFrame* pluginFrame, |
362 | | double sourceX, double sourceY, NPCoordinateSpace sourceSpace, |
363 | | double *destX, double *destY, NPCoordinateSpace destSpace); |
364 | | static NPBool ConvertPointNoPuppet(nsIWidget *widget, nsPluginFrame* pluginFrame, |
365 | | double sourceX, double sourceY, NPCoordinateSpace sourceSpace, |
366 | | double *destX, double *destY, NPCoordinateSpace destSpace); |
367 | | void PerformDelayedBlurs(); |
368 | | #endif // XP_MACOSX |
369 | | |
370 | | int mLastMouseDownButtonType; |
371 | | |
372 | | #ifdef MOZ_X11 |
373 | | class Renderer : public gfxXlibNativeRenderer |
374 | | { |
375 | | public: |
376 | | Renderer(NPWindow* aWindow, nsPluginInstanceOwner* aInstanceOwner, |
377 | | const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect) |
378 | | : mWindow(aWindow), mInstanceOwner(aInstanceOwner), |
379 | | mPluginSize(aPluginSize), mDirtyRect(aDirtyRect) |
380 | 0 | {} |
381 | | virtual nsresult DrawWithXlib(cairo_surface_t* surface, |
382 | | nsIntPoint offset, |
383 | | nsIntRect* clipRects, uint32_t numClipRects) override; |
384 | | private: |
385 | | NPWindow* mWindow; |
386 | | nsPluginInstanceOwner* mInstanceOwner; |
387 | | const nsIntSize& mPluginSize; |
388 | | const nsIntRect& mDirtyRect; |
389 | | }; |
390 | | #endif |
391 | | |
392 | | bool mWaitingForPaint; |
393 | | }; |
394 | | |
395 | | #endif // nsPluginInstanceOwner_h_ |
396 | | |