dom/plugins/base/nsPluginInstanceOwner.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial