Files
palemoon27/dom/plugins/base/nsPluginInstanceOwner.h
T
roytam1 df2987f659 import changes from `dev' branch of rmottola/Arctic-Fox:
- bit of Bug 1219134: P2. Use LibAV/FFmpeg logic to detect invalid pts. r=edwin (34d2a7d442)
- Bug 1195018 - Support 'background_color' member in the manifest processor. r=marcosc (1451b14321)
- Bug 1240490 - Fix console prefix used by the App Manifest processor. r=marcosc (e3196b53c8)
- Bug 1086997 - Localize developer warnings issued by the manifest processor. r=baku (7659fc5dd6)
- Bug 1258899 - teach manifest processor about dir member. r=baku (00b40c51c2)
- Bug 1262739 - Remove support for splash_screens member in Manifest Processor r=mconley (bceb0d2517)
- Bug 1264813 - Remove image object's density member from Web Manifest processor. r=mconley (f34da7259e)
- Bug 1264816 - Drop background_color from Web manifest image object. r=mconley (40c55f7bf9)
- Bug 1186908 - Return manifest members to canonical form after processing. r=mconley. (59d9a12a17)
- Bug 293394 - javascript: should never execute with chrome privs. r=bz (0dcc8f146b)
- bit of Bug 1153267 - part 2 (a0c5f7fda8)
- Bug 1254320 - Remove SEC_NORMAL from dom/json/ . r=bz (cd068db51c)
- Bug 1262590 - [e10s] AppProcessChecker.cpp has DEUBG typo preventing DEBUG messages. r=mconley (f9ffab4e57)
- Bug 1263556 - Remove EmptyBlobImpl in dom/ipc/Blob.cpp, r=smaug (3f4fe63e05)
- Bug 1261072 - File::GetName() should be const, r=smaug (bccd7475f1)
- Bug 1257759 part.1 Use switch-case at the first message handling in PluginInstanceChild::PluginWindowProcInternal() r=m_kato (bc0d4c457e)
- Bug 1257759 part.2 Separate Windows' message and related definitions from nsWindowDefs.h to mozilla/widget/WinMessages.h r=jimm (f8b5cb62f8)
- Bug 1153829 - Don't use MOZ_ALWAYS_INLINE for non-inline functions. r=jimm (c0e5b26c35)
- Bug 1257759 part.3 ModifierKeyState should be available in plugin module r=jimm (aa3fc81f63)
- Bug 1257759 part.4 Rename WidgetGUIEvent::PluginEvent to NativeEventData for using this class to send native event from plugin process to content and/or chrome process r=smaug (49392203ad)
- Bug 1255968 - Part 1: Let the callback of PeekMessages() to return a boolean to be able to break out the loop. r=dvander (d7f926ee7e)
- Bug 1255968 - Part 2: Implement puppet widget's HasPendingInputEvent() for interruptible reflow to work in content process. r=bz (5a0915e650)
- Bug 1257759 part.5 PluginInstanceChild should post received native key event to chrome process if the key combination may be a shortcut key r=jimm (ad1e3ad1c0)
- Bug 1252152 - Make plugin instances destroyed while that instance is on the stack crash earlier and more usefully, r=jimm (2238cc2a79)
- Bug 1257759 part.6 Keep event order between keyboard events and IME events in a plugin process r=jimm (32cbe1b13e)
- Bug 1257759 part.7 Add new internal events which represent key events on plugin r=smaug (161725755a)
- Bug 1257759 part.8 nsXBLWindowKeyHandler should handle eKeyDownOnPlugin and eKeyUpOnPlugin events only with reserved shortcut key handlers r=smaug (aa7cd1d786)
- Bug 1257759 part.9 Implement nsWindow::OnKeyEventInPluginProcess() on Windows r=jimm (245b2709e4)
- Bug 1257759 part.10 PluginInstanceChild should consume WM_*CHAR messages which follow consumed WM_*KEYDOWN or WM_*KEYUP message r=jimm (db355e6a77)
- Bug 1261735 (part 1) - Overhaul the atom implementation. r=froydnj,erahm. (abbed483f7)
- Bug 1261735 (part 2) - Inline some {Dynamic,Static}Atom methods. r=erahm. (97b11fa656)
- Bug 1261735 (part 3) - De-virtualize nsIAtom::IsStaticAtom(). r=froydnj,erahm. (4e0465a84a)
- Bug 1257207 - Increase ATOM_HASHTABLE_INITIAL_LENGTH. r=froydnj. (fe663e9c77)
- Bug 1261735 (part 4) - Change StaticAtomEntry::mAtom to |StaticAtom*|. r=erahm. (999fff7b8c)
- Bug 1261744 - Add two missing null checks for nsStringBuffer::Alloc(). r=erahm. (dd9ef00b6a)
- Bug 1266295 - Remove unnecessary compiler version checks for gcc <= 4.8.0 in xpcom. r=froydnj (b2f17f8d1a)
- Bug 1259706: Add NS_INLINE_DECL_THREADSAFE_VIRTUAL_REFCOUNTING macro. r=froydnj (d56a5fd48b)
- just a space (1508ec768f)
- Bug 1236991 - part 1: allow forwarding label direction through nsITooltipTextProvider, r=enndeakin (8d49127ffa)
- Bug 1245649: Enable no-nested-ternary. r=mconley (43c7b99372)
- Bug 1236991 - part 2: implement a default tooltiptextprovider in toolkit, r=enndeakin (a0a378979f)
- Bug 1251032 - Send RenderFrame info down to child in BrowserFrameOpenWindow. r=kanru (aec01fcec9)
- Bug 1246327 - Remove dom.always_allow_move_resize_window preference. r=jst (d06d83d596)
- Bug 1158228 - merge github's readability code into m-c, rs=me (38da823ce7)
- Bug 1158184 - merge recent github readability changes into m-c, rs=me (3b634d63c8)
- Bug 1162917 - update readability from github repo, rs=me (29dd18a9f0)
- No bug - update readability from github repo, includes fix for bug 1230050, rs=uplift-with-r+-patches-from-github (fa04927c71)
- Bug 1265866 - update Readability to the latest version from github, rs=me (c89e4dbeac)
- bits of Bug 1158228 (950dd3d561)
- Bug 1249579 - part2 : audio competing suspend/resume methods. r=snorp, baku. (3b6ddc018d)
- Bug 1266221 P1 Get devtools http service worker testing option from top window. r=bz (e8492118f0)
- Bug 225910 - Use nsIURI's GetRef and GetHasRef in nsDocShell. r=bz (76da6473d4)
- Bug 1261471: Remove support for getting mozIDOMWindowProxy via GetInterface. r=mrbkap (04904ed142)
- Bug 1264725 - Isolate Troubleshoot.jsm (about:support) from addons with null names. r=felipe (4ebb240827)
- Bug 1227730 - Support closing libnotify alerts. r=karlt,MattN (73d8b583dc)
2024-05-23 23:25:42 +08:00

430 lines
14 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// vim:set ts=2 sts=2 sw=2 et cin:
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsPluginInstanceOwner_h_
#define nsPluginInstanceOwner_h_
#include "mozilla/Attributes.h"
#include "npapi.h"
#include "nsCOMPtr.h"
#include "nsIKeyEventInPluginCallback.h"
#include "nsIPluginInstanceOwner.h"
#include "nsIPrivacyTransitionObserver.h"
#include "nsIDOMEventListener.h"
#include "nsPluginHost.h"
#include "nsPluginNativeWindow.h"
#include "nsWeakReference.h"
#include "gfxRect.h"
#ifdef XP_MACOSX
#include "mozilla/gfx/QuartzSupport.h"
#include <ApplicationServices/ApplicationServices.h>
#endif
class nsIInputStream;
class nsPluginDOMContextMenuListener;
class nsPluginFrame;
class nsDisplayListBuilder;
#if defined(MOZ_X11) || defined(ANDROID)
class gfxContext;
#endif
namespace mozilla {
class TextComposition;
namespace dom {
struct MozPluginParameter;
} // namespace dom
namespace widget {
class PuppetWidget;
} // namespace widget
} // namespace mozilla
using mozilla::widget::PuppetWidget;
#ifdef MOZ_X11
#ifdef MOZ_WIDGET_QT
#include "gfxQtNativeRenderer.h"
#else
#include "gfxXlibNativeRenderer.h"
#endif
#endif
class nsPluginInstanceOwner final : public nsIPluginInstanceOwner
, public nsIDOMEventListener
, public nsIPrivacyTransitionObserver
, public nsIKeyEventInPluginCallback
, public nsSupportsWeakReference
{
public:
typedef mozilla::gfx::DrawTarget DrawTarget;
nsPluginInstanceOwner();
NS_DECL_ISUPPORTS
NS_DECL_NSIPLUGININSTANCEOWNER
NS_DECL_NSIPRIVACYTRANSITIONOBSERVER
NS_IMETHOD GetURL(const char *aURL, const char *aTarget,
nsIInputStream *aPostStream,
void *aHeadersData, uint32_t aHeadersDataLen,
bool aDoCheckLoadURIChecks) override;
NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace) override;
NPError InitAsyncSurface(NPSize *size, NPImageFormat format,
void *initData, NPAsyncSurface *surface) override;
NPError FinalizeAsyncSurface(NPAsyncSurface *surface) override;
void SetCurrentAsyncSurface(NPAsyncSurface *surface, NPRect *changed) override;
/**
* Get the type of the HTML tag that was used ot instantiate this
* plugin. Currently supported tags are EMBED, OBJECT and APPLET.
*/
NS_IMETHOD GetTagType(nsPluginTagType *aResult);
void GetParameters(nsTArray<mozilla::dom::MozPluginParameter>& parameters);
void GetAttributes(nsTArray<mozilla::dom::MozPluginParameter>& attributes);
/**
* Returns the DOM element corresponding to the tag which references
* this plugin in the document.
*
* @param aDOMElement - resulting DOM element
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD GetDOMElement(nsIDOMElement* * aResult);
// nsIDOMEventListener interfaces
NS_DECL_NSIDOMEVENTLISTENER
nsresult ProcessMouseDown(nsIDOMEvent* aKeyEvent);
nsresult ProcessKeyPress(nsIDOMEvent* aKeyEvent);
nsresult Destroy();
#ifdef XP_WIN
void Paint(const RECT& aDirty, HDC aDC);
#elif defined(XP_MACOSX)
void Paint(const gfxRect& aDirtyRect, CGContextRef cgContext);
void RenderCoreAnimation(CGContextRef aCGContext, int aWidth, int aHeight);
void DoCocoaEventDrawRect(const gfxRect& aDrawRect, CGContextRef cgContext);
#elif defined(MOZ_X11) || defined(ANDROID)
void Paint(gfxContext* aContext,
const gfxRect& aFrameRect,
const gfxRect& aDirtyRect);
#endif
//locals
nsresult Init(nsIContent* aContent);
void* GetPluginPort();
void ReleasePluginPort(void* pluginPort);
nsEventStatus ProcessEvent(const mozilla::WidgetGUIEvent& anEvent);
static void GeneratePluginEvent(
const mozilla::WidgetCompositionEvent* aSrcCompositionEvent,
mozilla::WidgetCompositionEvent* aDistCompositionEvent);
#if defined(XP_WIN)
void SetWidgetWindowAsParent(HWND aWindowToAdopt);
nsresult SetNetscapeWindowAsParent(HWND aWindowToAdopt);
#endif
#ifdef XP_MACOSX
enum { ePluginPaintEnable, ePluginPaintDisable };
void WindowFocusMayHaveChanged();
bool WindowIsActive();
void SendWindowFocusChanged(bool aIsActive);
NPDrawingModel GetDrawingModel();
bool IsRemoteDrawingCoreAnimation();
nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
NPEventModel GetEventModel();
static void CARefresh(nsITimer *aTimer, void *aClosure);
void AddToCARefreshTimer();
void RemoveFromCARefreshTimer();
// This calls into the plugin (NPP_SetWindow) and can run script.
void FixUpPluginWindow(int32_t inPaintState);
void HidePluginWindow();
// Set plugin port info in the plugin (in the 'window' member of the
// NPWindow structure passed to the plugin by SetWindow()).
void SetPluginPort();
#else // XP_MACOSX
void UpdateWindowPositionAndClipRect(bool aSetWindow);
void UpdateWindowVisibility(bool aVisible);
#endif // XP_MACOSX
void ResolutionMayHaveChanged();
void UpdateDocumentActiveState(bool aIsActive);
void SetFrame(nsPluginFrame *aFrame);
nsPluginFrame* GetFrame();
uint32_t GetLastEventloopNestingLevel() const {
return mLastEventloopNestingLevel;
}
static uint32_t GetEventloopNestingLevel();
void ConsiderNewEventloopNestingLevel() {
uint32_t currentLevel = GetEventloopNestingLevel();
if (currentLevel < mLastEventloopNestingLevel) {
mLastEventloopNestingLevel = currentLevel;
}
}
const char* GetPluginName()
{
if (mInstance && mPluginHost) {
const char* name = nullptr;
if (NS_SUCCEEDED(mPluginHost->GetPluginName(mInstance, &name)) && name)
return name;
}
return "";
}
#ifdef MOZ_X11
void GetPluginDescription(nsACString& aDescription)
{
aDescription.Truncate();
if (mInstance && mPluginHost) {
nsCOMPtr<nsIPluginTag> pluginTag;
mPluginHost->GetPluginTagForInstance(mInstance,
getter_AddRefs(pluginTag));
if (pluginTag) {
pluginTag->GetDescription(aDescription);
}
}
}
#endif
bool SendNativeEvents()
{
#ifdef XP_WIN
// XXX we should remove the plugin name check
return mPluginWindow->type == NPWindowTypeDrawable &&
(MatchPluginName("Shockwave Flash") ||
MatchPluginName("Test Plug-in"));
#elif defined(MOZ_X11) || defined(XP_MACOSX)
return true;
#else
return false;
#endif
}
bool MatchPluginName(const char *aPluginName)
{
return strncmp(GetPluginName(), aPluginName, strlen(aPluginName)) == 0;
}
void NotifyPaintWaiter(nsDisplayListBuilder* aBuilder);
// Returns the image container that has our currently displayed image.
already_AddRefed<mozilla::layers::ImageContainer> GetImageContainer();
// Returns true if this is windowed plugin that can return static captures
// for scroll operations.
bool NeedsScrollImageLayer();
// Notification we receive from nsPluginFrame about scroll state.
bool UpdateScrollState(bool aIsScrolling);
void DidComposite();
/**
* Returns the bounds of the current async-rendered surface. This can only
* change in response to messages received by the event loop (i.e. not during
* painting).
*/
nsIntSize GetCurrentImageSize();
// Methods to update the background image we send to async plugins.
// The eventual target of these operations is PluginInstanceParent,
// but it takes several hops to get there.
void SetBackgroundUnknown();
already_AddRefed<DrawTarget> BeginUpdateBackground(const nsIntRect& aRect);
void EndUpdateBackground(const nsIntRect& aRect);
bool UseAsyncRendering();
already_AddRefed<nsIURI> GetBaseURI() const;
#ifdef MOZ_WIDGET_ANDROID
// Returns the image container for the specified VideoInfo
void GetVideos(nsTArray<nsNPAPIPluginInstance::VideoInfo*>& aVideos);
already_AddRefed<mozilla::layers::ImageContainer> GetImageContainerForVideo(nsNPAPIPluginInstance::VideoInfo* aVideoInfo);
void Invalidate();
void RequestFullScreen();
void ExitFullScreen();
// Called from AndroidJNI when we removed the fullscreen view.
static void ExitFullScreen(jobject view);
#endif
void NotifyHostAsyncInitFailed();
void NotifyHostCreateWidget();
void NotifyDestroyPending();
bool GetCompositionString(uint32_t aIndex, nsTArray<uint8_t>* aString,
int32_t* aLength);
bool SetCandidateWindow(
const mozilla::widget::CandidateWindowPosition& aPosition);
bool RequestCommitOrCancel(bool aCommitted);
// See nsIKeyEventInPluginCallback
virtual void HandledWindowedPluginKeyEvent(
const mozilla::NativeEventData& aKeyEventData,
bool aIsConsumed) override;
/**
* OnWindowedPluginKeyEvent() is called when the plugin process receives
* native key event directly.
*
* @param aNativeKeyData The key event which was received by the
* plugin process directly.
*/
void OnWindowedPluginKeyEvent(
const mozilla::NativeEventData& aNativeKeyData);
void GetCSSZoomFactor(float *result);
private:
virtual ~nsPluginInstanceOwner();
// return FALSE if LayerSurface dirty (newly created and don't have valid plugin content yet)
bool IsUpToDate()
{
nsIntSize size;
return NS_SUCCEEDED(mInstance->GetImageSize(&size)) &&
size == nsIntSize(mPluginWindow->width, mPluginWindow->height);
}
#ifdef MOZ_WIDGET_ANDROID
mozilla::LayoutDeviceRect GetPluginRect();
bool AddPluginView(const mozilla::LayoutDeviceRect& aRect = mozilla::LayoutDeviceRect(0, 0, 0, 0));
void RemovePluginView();
bool mFullScreen;
void* mJavaView;
#endif
#if defined(XP_WIN)
nsIWidget* GetContainingWidgetIfOffset();
already_AddRefed<mozilla::TextComposition> GetTextComposition();
void HandleNoConsumedCompositionMessage(
mozilla::WidgetCompositionEvent* aCompositionEvent,
const NPEvent* aPluginEvent);
bool mGotCompositionData;
bool mSentStartComposition;
bool mPluginDidNotHandleIMEComposition;
#endif
nsPluginNativeWindow *mPluginWindow;
RefPtr<nsNPAPIPluginInstance> mInstance;
nsPluginFrame *mPluginFrame;
nsWeakPtr mContent; // WEAK, content owns us
nsCString mDocumentBase;
bool mWidgetCreationComplete;
nsCOMPtr<nsIWidget> mWidget;
RefPtr<nsPluginHost> mPluginHost;
#ifdef XP_MACOSX
static nsCOMPtr<nsITimer> *sCATimer;
static nsTArray<nsPluginInstanceOwner*> *sCARefreshListeners;
bool mSentInitialTopLevelWindowEvent;
bool mLastWindowIsActive;
bool mLastContentFocused;
double mLastScaleFactor;
// True if, the next time the window is activated, we should blur ourselves.
bool mShouldBlurOnActivate;
#endif
double mLastCSSZoomFactor;
// Initially, the event loop nesting level we were created on, it's updated
// if we detect the appshell is on a lower level as long as we're not stopped.
// We delay DoStopPlugin() until the appshell reaches this level or lower.
uint32_t mLastEventloopNestingLevel;
bool mContentFocused;
bool mWidgetVisible; // used on Mac to store our widget's visible state
#ifdef MOZ_X11
// Used with windowless plugins only, initialized in CreateWidget().
bool mFlash10Quirks;
#endif
bool mPluginWindowVisible;
bool mPluginDocumentActiveState;
#ifdef XP_MACOSX
NPEventModel mEventModel;
// This is a hack! UseAsyncRendering() can incorrectly return false
// when we don't have an object frame (possible as of bug 90268).
// We hack around this by always returning true if we've ever
// returned true.
bool mUseAsyncRendering;
#endif
// pointer to wrapper for nsIDOMContextMenuListener
RefPtr<nsPluginDOMContextMenuListener> mCXMenuListener;
nsresult DispatchKeyToPlugin(nsIDOMEvent* aKeyEvent);
nsresult DispatchMouseToPlugin(nsIDOMEvent* aMouseEvent,
bool aAllowPropagate = false);
nsresult DispatchFocusToPlugin(nsIDOMEvent* aFocusEvent);
nsresult DispatchCompositionToPlugin(nsIDOMEvent* aEvent);
#ifdef XP_WIN
void CallDefaultProc(const mozilla::WidgetGUIEvent* aEvent);
#endif
#ifdef XP_MACOSX
static NPBool ConvertPointPuppet(PuppetWidget *widget, nsPluginFrame* pluginFrame,
double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace);
static NPBool ConvertPointNoPuppet(nsIWidget *widget, nsPluginFrame* pluginFrame,
double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace);
void PerformDelayedBlurs();
#endif // XP_MACOSX
int mLastMouseDownButtonType;
#ifdef MOZ_X11
class Renderer
#if defined(MOZ_WIDGET_QT)
: public gfxQtNativeRenderer
#else
: public gfxXlibNativeRenderer
#endif
{
public:
Renderer(NPWindow* aWindow, nsPluginInstanceOwner* aInstanceOwner,
const nsIntSize& aPluginSize, const nsIntRect& aDirtyRect)
: mWindow(aWindow), mInstanceOwner(aInstanceOwner),
mPluginSize(aPluginSize), mDirtyRect(aDirtyRect)
{}
virtual nsresult DrawWithXlib(cairo_surface_t* surface,
nsIntPoint offset,
nsIntRect* clipRects, uint32_t numClipRects) override;
private:
NPWindow* mWindow;
nsPluginInstanceOwner* mInstanceOwner;
const nsIntSize& mPluginSize;
const nsIntRect& mDirtyRect;
};
#endif
bool mWaitingForPaint;
#if defined(XP_WIN)
bool mScrollState;
#endif
};
#endif // nsPluginInstanceOwner_h_