dom/plugins/base/nsPluginInstanceOwner.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/base/nsPluginInstanceOwner.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,405 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +// vim:set ts=2 sts=2 sw=2 et cin:
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsPluginInstanceOwner_h_
    1.11 +#define nsPluginInstanceOwner_h_
    1.12 +
    1.13 +#include "mozilla/Attributes.h"
    1.14 +#include "npapi.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsIPluginInstanceOwner.h"
    1.17 +#include "nsIPrivacyTransitionObserver.h"
    1.18 +#include "nsIDOMEventListener.h"
    1.19 +#include "nsPluginHost.h"
    1.20 +#include "nsPluginNativeWindow.h"
    1.21 +#include "nsWeakReference.h"
    1.22 +#include "gfxRect.h"
    1.23 +
    1.24 +#ifdef XP_MACOSX
    1.25 +#include "mozilla/gfx/QuartzSupport.h"
    1.26 +#include <ApplicationServices/ApplicationServices.h>
    1.27 +#endif
    1.28 +
    1.29 +class nsIInputStream;
    1.30 +struct nsIntRect;
    1.31 +class nsPluginDOMContextMenuListener;
    1.32 +class nsObjectFrame;
    1.33 +class nsDisplayListBuilder;
    1.34 +
    1.35 +#ifdef MOZ_X11
    1.36 +class gfxXlibSurface;
    1.37 +#ifdef MOZ_WIDGET_QT
    1.38 +#include "gfxQtNativeRenderer.h"
    1.39 +#else
    1.40 +#include "gfxXlibNativeRenderer.h"
    1.41 +#endif
    1.42 +#endif
    1.43 +
    1.44 +class nsPluginInstanceOwner : public nsIPluginInstanceOwner,
    1.45 +                              public nsIDOMEventListener,
    1.46 +                              public nsIPrivacyTransitionObserver,
    1.47 +                              public nsSupportsWeakReference
    1.48 +{
    1.49 +public:
    1.50 +  nsPluginInstanceOwner();
    1.51 +  virtual ~nsPluginInstanceOwner();
    1.52 +  
    1.53 +  NS_DECL_ISUPPORTS
    1.54 +  NS_DECL_NSIPLUGININSTANCEOWNER
    1.55 +  NS_DECL_NSIPRIVACYTRANSITIONOBSERVER
    1.56 +  
    1.57 +  NS_IMETHOD GetURL(const char *aURL, const char *aTarget,
    1.58 +                    nsIInputStream *aPostStream, 
    1.59 +                    void *aHeadersData, uint32_t aHeadersDataLen) MOZ_OVERRIDE;
    1.60 +  
    1.61 +  NS_IMETHOD ShowStatus(const char16_t *aStatusMsg) MOZ_OVERRIDE;
    1.62 +  
    1.63 +  NPError    ShowNativeContextMenu(NPMenu* menu, void* event) MOZ_OVERRIDE;
    1.64 +  
    1.65 +  NPBool     ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
    1.66 +                          double *destX, double *destY, NPCoordinateSpace destSpace) MOZ_OVERRIDE;
    1.67 +  
    1.68 +  virtual NPError InitAsyncSurface(NPSize *size, NPImageFormat format,
    1.69 +                                   void *initData, NPAsyncSurface *surface) MOZ_OVERRIDE;
    1.70 +  virtual NPError FinalizeAsyncSurface(NPAsyncSurface *surface) MOZ_OVERRIDE;
    1.71 +  virtual void SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed) MOZ_OVERRIDE;
    1.72 +
    1.73 +  /**
    1.74 +   * Get the type of the HTML tag that was used ot instantiate this
    1.75 +   * plugin.  Currently supported tags are EMBED, OBJECT and APPLET.
    1.76 +   */
    1.77 +  NS_IMETHOD GetTagType(nsPluginTagType *aResult);
    1.78 +
    1.79 +  /**
    1.80 +   * Get a ptr to the paired list of parameter names and values,
    1.81 +   * returns the length of the array.
    1.82 +   *
    1.83 +   * Each name or value is a null-terminated string.
    1.84 +   */
    1.85 +  NS_IMETHOD GetParameters(uint16_t& aCount,
    1.86 +                           const char*const*& aNames,
    1.87 +                           const char*const*& aValues);
    1.88 +
    1.89 +  /**
    1.90 +   * Get the value for the named parameter.  Returns null
    1.91 +   * if the parameter was not set.
    1.92 +   *
    1.93 +   * @param aName   - name of the parameter
    1.94 +   * @param aResult - parameter value
    1.95 +   * @result        - NS_OK if this operation was successful
    1.96 +   */
    1.97 +  NS_IMETHOD GetParameter(const char* aName, const char* *aResult);
    1.98 +
    1.99 +  /**
   1.100 +   * QueryInterface on nsIPluginInstancePeer to get this.
   1.101 +   *
   1.102 +   * (Corresponds to NPP_New's argc, argn, and argv arguments.)
   1.103 +   * Get a ptr to the paired list of attribute names and values,
   1.104 +   * returns the length of the array.
   1.105 +   *
   1.106 +   * Each name or value is a null-terminated string.
   1.107 +   */
   1.108 +  NS_IMETHOD GetAttributes(uint16_t& aCount,
   1.109 +                           const char*const*& aNames,
   1.110 +                           const char*const*& aValues);
   1.111 +
   1.112 +
   1.113 +  /**
   1.114 +   * Gets the value for the named attribute.
   1.115 +   *
   1.116 +   * @param aName   - the name of the attribute to find
   1.117 +   * @param aResult - the resulting attribute
   1.118 +   * @result - NS_OK if this operation was successful, NS_ERROR_FAILURE if
   1.119 +   * this operation failed. result is set to NULL if the attribute is not found
   1.120 +   * else to the found value.
   1.121 +   */
   1.122 +  NS_IMETHOD GetAttribute(const char* aName, const char* *aResult);
   1.123 +
   1.124 +  /**
   1.125 +   * Returns the DOM element corresponding to the tag which references
   1.126 +   * this plugin in the document.
   1.127 +   *
   1.128 +   * @param aDOMElement - resulting DOM element
   1.129 +   * @result - NS_OK if this operation was successful
   1.130 +   */
   1.131 +  NS_IMETHOD GetDOMElement(nsIDOMElement* * aResult);
   1.132 +  
   1.133 +  // nsIDOMEventListener interfaces 
   1.134 +  NS_DECL_NSIDOMEVENTLISTENER
   1.135 +  
   1.136 +  nsresult ProcessMouseDown(nsIDOMEvent* aKeyEvent);
   1.137 +  nsresult ProcessKeyPress(nsIDOMEvent* aKeyEvent);
   1.138 +  nsresult Destroy();  
   1.139 +
   1.140 +#ifdef XP_WIN
   1.141 +  void Paint(const RECT& aDirty, HDC aDC);
   1.142 +#elif defined(XP_MACOSX)
   1.143 +  void Paint(const gfxRect& aDirtyRect, CGContextRef cgContext);  
   1.144 +  void RenderCoreAnimation(CGContextRef aCGContext, int aWidth, int aHeight);
   1.145 +  void DoCocoaEventDrawRect(const gfxRect& aDrawRect, CGContextRef cgContext);
   1.146 +#elif defined(MOZ_X11) || defined(ANDROID)
   1.147 +  void Paint(gfxContext* aContext,
   1.148 +             const gfxRect& aFrameRect,
   1.149 +             const gfxRect& aDirtyRect);
   1.150 +#endif
   1.151 +
   1.152 +  //locals
   1.153 +  
   1.154 +  nsresult Init(nsIContent* aContent);
   1.155 +  
   1.156 +  void* GetPluginPortFromWidget();
   1.157 +  void ReleasePluginPort(void* pluginPort);
   1.158 +
   1.159 +  nsEventStatus ProcessEvent(const mozilla::WidgetGUIEvent& anEvent);
   1.160 +  
   1.161 +#ifdef XP_MACOSX
   1.162 +  enum { ePluginPaintEnable, ePluginPaintDisable };
   1.163 +  
   1.164 +  NPDrawingModel GetDrawingModel();
   1.165 +  bool IsRemoteDrawingCoreAnimation();
   1.166 +  nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
   1.167 +  NPEventModel GetEventModel();
   1.168 +  static void CARefresh(nsITimer *aTimer, void *aClosure);
   1.169 +  void AddToCARefreshTimer();
   1.170 +  void RemoveFromCARefreshTimer();
   1.171 +  // This calls into the plugin (NPP_SetWindow) and can run script.
   1.172 +  void* FixUpPluginWindow(int32_t inPaintState);
   1.173 +  void HidePluginWindow();
   1.174 +  // Set a flag that (if true) indicates the plugin port info has changed and
   1.175 +  // SetWindow() needs to be called.
   1.176 +  void SetPluginPortChanged(bool aState) { mPluginPortChanged = aState; }
   1.177 +  // Return a pointer to the internal nsPluginPort structure that's used to
   1.178 +  // store a copy of plugin port info and to detect when it's been changed.
   1.179 +  void* GetPluginPortCopy();
   1.180 +  // Set plugin port info in the plugin (in the 'window' member of the
   1.181 +  // NPWindow structure passed to the plugin by SetWindow()) and set a
   1.182 +  // flag (mPluginPortChanged) to indicate whether or not this info has
   1.183 +  // changed, and SetWindow() needs to be called again.
   1.184 +  void* SetPluginPortAndDetectChange();
   1.185 +  // Flag when we've set up a Thebes (and CoreGraphics) context in
   1.186 +  // nsObjectFrame::PaintPlugin().  We need to know this in
   1.187 +  // FixUpPluginWindow() (i.e. we need to know when FixUpPluginWindow() has
   1.188 +  // been called from nsObjectFrame::PaintPlugin() when we're using the
   1.189 +  // CoreGraphics drawing model).
   1.190 +  void BeginCGPaint();
   1.191 +  void EndCGPaint();
   1.192 +#else // XP_MACOSX
   1.193 +  void UpdateWindowPositionAndClipRect(bool aSetWindow);
   1.194 +  void UpdateWindowVisibility(bool aVisible);
   1.195 +  void UpdateDocumentActiveState(bool aIsActive);
   1.196 +#endif // XP_MACOSX
   1.197 +
   1.198 +  void SetFrame(nsObjectFrame *aFrame);
   1.199 +  nsObjectFrame* GetFrame();
   1.200 +
   1.201 +  uint32_t GetLastEventloopNestingLevel() const {
   1.202 +    return mLastEventloopNestingLevel; 
   1.203 +  }
   1.204 +  
   1.205 +  static uint32_t GetEventloopNestingLevel();
   1.206 +  
   1.207 +  void ConsiderNewEventloopNestingLevel() {
   1.208 +    uint32_t currentLevel = GetEventloopNestingLevel();
   1.209 +    
   1.210 +    if (currentLevel < mLastEventloopNestingLevel) {
   1.211 +      mLastEventloopNestingLevel = currentLevel;
   1.212 +    }
   1.213 +  }
   1.214 +  
   1.215 +  const char* GetPluginName()
   1.216 +  {
   1.217 +    if (mInstance && mPluginHost) {
   1.218 +      const char* name = nullptr;
   1.219 +      if (NS_SUCCEEDED(mPluginHost->GetPluginName(mInstance, &name)) && name)
   1.220 +        return name;
   1.221 +    }
   1.222 +    return "";
   1.223 +  }
   1.224 +  
   1.225 +#ifdef MOZ_X11
   1.226 +  void GetPluginDescription(nsACString& aDescription)
   1.227 +  {
   1.228 +    aDescription.Truncate();
   1.229 +    if (mInstance && mPluginHost) {
   1.230 +      nsCOMPtr<nsIPluginTag> pluginTag;
   1.231 +      
   1.232 +      mPluginHost->GetPluginTagForInstance(mInstance,
   1.233 +                                           getter_AddRefs(pluginTag));
   1.234 +      if (pluginTag) {
   1.235 +        pluginTag->GetDescription(aDescription);
   1.236 +      }
   1.237 +    }
   1.238 +  }
   1.239 +#endif
   1.240 +  
   1.241 +  bool SendNativeEvents()
   1.242 +  {
   1.243 +#ifdef XP_WIN
   1.244 +    // XXX we should remove the plugin name check
   1.245 +    return mPluginWindow->type == NPWindowTypeDrawable &&
   1.246 +    (MatchPluginName("Shockwave Flash") ||
   1.247 +     MatchPluginName("Test Plug-in"));
   1.248 +#elif defined(MOZ_X11) || defined(XP_MACOSX)
   1.249 +    return true;
   1.250 +#else
   1.251 +    return false;
   1.252 +#endif
   1.253 +  }
   1.254 +  
   1.255 +  bool MatchPluginName(const char *aPluginName)
   1.256 +  {
   1.257 +    return strncmp(GetPluginName(), aPluginName, strlen(aPluginName)) == 0;
   1.258 +  }
   1.259 +  
   1.260 +  void NotifyPaintWaiter(nsDisplayListBuilder* aBuilder);
   1.261 +
   1.262 +  // Returns the image container that has our currently displayed image.
   1.263 +  already_AddRefed<mozilla::layers::ImageContainer> GetImageContainer();
   1.264 +
   1.265 +  /**
   1.266 +   * Returns the bounds of the current async-rendered surface. This can only
   1.267 +   * change in response to messages received by the event loop (i.e. not during
   1.268 +   * painting).
   1.269 +   */
   1.270 +  nsIntSize GetCurrentImageSize();
   1.271 +  
   1.272 +  // Methods to update the background image we send to async plugins.
   1.273 +  // The eventual target of these operations is PluginInstanceParent,
   1.274 +  // but it takes several hops to get there.
   1.275 +  void SetBackgroundUnknown();
   1.276 +  already_AddRefed<gfxContext> BeginUpdateBackground(const nsIntRect& aRect);
   1.277 +  void EndUpdateBackground(gfxContext* aContext, const nsIntRect& aRect);
   1.278 +  
   1.279 +  bool UseAsyncRendering();
   1.280 +
   1.281 +  already_AddRefed<nsIURI> GetBaseURI() const;
   1.282 +
   1.283 +#ifdef MOZ_WIDGET_ANDROID
   1.284 +  // Returns the image container for the specified VideoInfo
   1.285 +  void GetVideos(nsTArray<nsNPAPIPluginInstance::VideoInfo*>& aVideos);
   1.286 +  already_AddRefed<mozilla::layers::ImageContainer> GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInfo* aVideoInfo);
   1.287 +
   1.288 +  void Invalidate();
   1.289 +
   1.290 +  void RequestFullScreen();
   1.291 +  void ExitFullScreen();
   1.292 +
   1.293 +  // Called from AndroidJNI when we removed the fullscreen view.
   1.294 +  static void ExitFullScreen(jobject view);
   1.295 +#endif
   1.296 +  
   1.297 +private:
   1.298 +  
   1.299 +  // return FALSE if LayerSurface dirty (newly created and don't have valid plugin content yet)
   1.300 +  bool IsUpToDate()
   1.301 +  {
   1.302 +    nsIntSize size;
   1.303 +    return NS_SUCCEEDED(mInstance->GetImageSize(&size)) &&
   1.304 +    size == nsIntSize(mPluginWindow->width, mPluginWindow->height);
   1.305 +  }
   1.306 +  
   1.307 +  void FixUpURLS(const nsString &name, nsAString &value);
   1.308 +#ifdef MOZ_WIDGET_ANDROID
   1.309 +  mozilla::LayoutDeviceRect GetPluginRect();
   1.310 +  bool AddPluginView(const mozilla::LayoutDeviceRect& aRect = mozilla::LayoutDeviceRect(0, 0, 0, 0));
   1.311 +  void RemovePluginView();
   1.312 +
   1.313 +  bool mFullScreen;
   1.314 +  void* mJavaView;
   1.315 +#endif 
   1.316 + 
   1.317 +  nsPluginNativeWindow       *mPluginWindow;
   1.318 +  nsRefPtr<nsNPAPIPluginInstance> mInstance;
   1.319 +  nsObjectFrame              *mObjectFrame;
   1.320 +  nsIContent                 *mContent; // WEAK, content owns us
   1.321 +  nsCString                   mDocumentBase;
   1.322 +  bool                        mWidgetCreationComplete;
   1.323 +  nsCOMPtr<nsIWidget>         mWidget;
   1.324 +  nsRefPtr<nsPluginHost>      mPluginHost;
   1.325 +  
   1.326 +#ifdef XP_MACOSX
   1.327 +  NP_CGContext                              mCGPluginPortCopy;
   1.328 +  int32_t                                   mInCGPaintLevel;
   1.329 +  mozilla::RefPtr<MacIOSurface>             mIOSurface;
   1.330 +  mozilla::RefPtr<nsCARenderer>             mCARenderer;
   1.331 +  CGColorSpaceRef                           mColorProfile;
   1.332 +  static nsCOMPtr<nsITimer>                *sCATimer;
   1.333 +  static nsTArray<nsPluginInstanceOwner*>  *sCARefreshListeners;
   1.334 +  bool                                      mSentInitialTopLevelWindowEvent;
   1.335 +#endif
   1.336 +
   1.337 +  // Initially, the event loop nesting level we were created on, it's updated
   1.338 +  // if we detect the appshell is on a lower level as long as we're not stopped.
   1.339 +  // We delay DoStopPlugin() until the appshell reaches this level or lower.
   1.340 +  uint32_t                    mLastEventloopNestingLevel;
   1.341 +  bool                        mContentFocused;
   1.342 +  bool                        mWidgetVisible;    // used on Mac to store our widget's visible state
   1.343 +#ifdef XP_MACOSX
   1.344 +  bool                        mPluginPortChanged;
   1.345 +#endif
   1.346 +#ifdef MOZ_X11
   1.347 +  // Used with windowless plugins only, initialized in CreateWidget().
   1.348 +  bool                        mFlash10Quirks;
   1.349 +#endif
   1.350 +  bool                        mPluginWindowVisible;
   1.351 +  bool                        mPluginDocumentActiveState;
   1.352 +
   1.353 +  uint16_t          mNumCachedAttrs;
   1.354 +  uint16_t          mNumCachedParams;
   1.355 +  char              **mCachedAttrParamNames;
   1.356 +  char              **mCachedAttrParamValues;
   1.357 +  
   1.358 +#ifdef XP_MACOSX
   1.359 +  NPEventModel mEventModel;
   1.360 +  // This is a hack! UseAsyncRendering() can incorrectly return false
   1.361 +  // when we don't have an object frame (possible as of bug 90268).
   1.362 +  // We hack around this by always returning true if we've ever
   1.363 +  // returned true.
   1.364 +  bool mUseAsyncRendering;
   1.365 +#endif
   1.366 +  
   1.367 +  // pointer to wrapper for nsIDOMContextMenuListener
   1.368 +  nsRefPtr<nsPluginDOMContextMenuListener> mCXMenuListener;
   1.369 +  
   1.370 +  nsresult DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent);
   1.371 +  nsresult DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent,
   1.372 +                                 bool aAllowPropagate = false);
   1.373 +  nsresult DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent);
   1.374 +
   1.375 +  int mLastMouseDownButtonType;
   1.376 +  
   1.377 +  nsresult EnsureCachedAttrParamArrays();
   1.378 +  
   1.379 +#ifdef MOZ_X11
   1.380 +  class Renderer
   1.381 +#if defined(MOZ_WIDGET_QT)
   1.382 +  : public gfxQtNativeRenderer
   1.383 +#else
   1.384 +  : public gfxXlibNativeRenderer
   1.385 +#endif
   1.386 +  {
   1.387 +  public:
   1.388 +    Renderer(NPWindow* aWindow, nsPluginInstanceOwner* aInstanceOwner,
   1.389 +             const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect)
   1.390 +    : mWindow(aWindow), mInstanceOwner(aInstanceOwner),
   1.391 +    mPluginSize(aPluginSize), mDirtyRect(aDirtyRect)
   1.392 +    {}
   1.393 +    virtual nsresult DrawWithXlib(cairo_surface_t* surface,
   1.394 +                                  nsIntPoint offset,
   1.395 +                                  nsIntRect* clipRects, uint32_t numClipRects) MOZ_OVERRIDE;
   1.396 +  private:
   1.397 +    NPWindow* mWindow;
   1.398 +    nsPluginInstanceOwner* mInstanceOwner;
   1.399 +    const nsIntSize& mPluginSize;
   1.400 +    const nsIntRect& mDirtyRect;
   1.401 +  };
   1.402 +#endif
   1.403 +
   1.404 +  bool mWaitingForPaint;
   1.405 +};
   1.406 +
   1.407 +#endif // nsPluginInstanceOwner_h_
   1.408 +

mercurial