Files
palemoon27/dom/plugins/ipc/PluginModuleChild.h
T
roytam1 e9ba40cf6b import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1178833 - Fix for unified builds when a new file is added to layout/base. r=mstange (bf961c00fd)
- Bug 1178847 - Add a MobileViewportManager to manage setting the CSS viewport on B2G. r=botond,tn (937ba486fa)
- Bug 1178847 - Don't use the MobileViewportManager code on Mulet or Fennec yet. r=botond (3061b2c617)
- Bug 1168950. Add the document to DoProcessRestyles profile label. r=dbaron (2347b76411)
- Bug 1187792 - Don't set the SPCSPS unless meta-viewport or zooming is enabled. r=botond (a8f5ed1006)
- Bug 1193062 - Don't double-send target APZC confirmations that might race each other. r=kats (de48467401)
- Bug 1186004 - Add a pref to enable/disable APZ zooming behaviour. r=botond (fc3653c979)
- Bug 1193062 - Add a PAN_MOMENTUM state. r=kats (10c8bb1a5e)
- Bug 1148350 - Have ConvertToGecko use a live screen-to-apzc transform to avoid transform mismatches. r=botond (9eee9ea6f2)
- Bug 1169844 - Remove incorrect assertion and properly untransform wheel events for overscroll situations. r=botond (9b101b53bb)
- Bug 1169690 - Accelerate flings correctly in the presence of overscroll handoff. r=kats (49d55c05f4)
- Bug 1158424 - Extract a BreadthFirstSearch() helper function. r=kats (6a49498185)
- Bug 1158424 - Add APZCTreeManager::FindRootContentApzcForLayersId(). r=kats (d6c7ecf781)
- Bug 1158424 - Fix APZCTreeManager::GetMultitouchTarget(). r=kats (bf8571a4ca)
- Bug 1174205 - Make sure to acquire the tree lock before finding the multitouch target. r=botond (bdbd98f2c7)
- Bug 1211660 - Remove dead obj argument from two functions. r=Waldo. (efba5a2f8d)
- Bug 1158424 - Undeprecate HasNoParentWithSameLayersId(). r=kats (d994ea28f8)
- Fix AsyncCompositionManager not comparing layer tree IDs when finding scrollbar targets. (bug 1151169, r=kats) (c7dbc4776a)
- Bug 1163259. Make sure we don't look at the parent ref layer when looking for a layer with the frame metrics for a scrollbar. r=kats (8b99d2c830)
- Bug 1164340. Convert the scrollbar thumb ratio to a unitless ratio properly for non-zoomable scrollframes. r=botond (27f56cab56)
- Bug 1164340. Fix up some scrollbar related comments in AsyncCompositionManager. r=botond (b9d540bea9)
- Bug 1164767. Modify async scrollbar positioning code to deal with containerless root scrollables. r=botond (501d07592e)
- Bug 1158424 - Remove FrameMetrics::IsRootScrollable() (it just duplicated IsRootContent()). r=kats (672fd034b3)
- Bug 1120683 - Properly handle unapplying 3D projective transforms throughout APZ code. r=botond (a46612811a)
- Bug 1148868 - Make APZ wheel handling handle pixel scrolling on OS X. r=dvander, r=kats (da3bd34135)
- Bug 1193062 - Add fields to PanGestureInput and ScrollWheelInput. r=kats (716ba34e18)
- Bug 1189565 - Send resize events when backing scale factor changes. r=mstange (4e81a7bbf7)
- Bug 1193062 - Add nsCocoaUtils::ModifiersForEvent. r=smichaud (da67b22ff7)
- Bug 1016035 - Remove the ability to swipe vertically. r=kats (fa315e0b97)
- Bug 1016035 - Refactor the code that decides whether we want to start a swipe. r=kats (3091961328)
- Bug 1016035 - Make the threshold in AxisPhysicsMSDModel::IsFinished controllable by the caller. r=kip (76df4d85a2)
- Bug 1016035 - More swipe refactoring. r=kats (2abcd05b33)
- Bug 1016035 - Implement the swipe animation ourselves instead of calling the NSEvent trackSwipe API. r=kats (4842b2a728)
- Bug 1016035 - Move swipe tracking code into DispatchAPZWheelInputEvent. r=kats (bb1052b87c)
- Bug 1016035 - Also mark widgetWheelEvents that are handled by APZ with mCanStartSwipe. r=kats (21809b902d)
- Bug 1016035 - Put PanGestureInput events into a queue if they can end up as a swipe. r=kats (2ebac59047)
- Bug 1016035 - Split up MaybeTrackScrollEventAsSwipe into SendMayStartSwipe and TrackScrollEventAsSwipe. r=kats (ced10d9671)
- Bug 1016035 - Send MayStartSwipe event before sending the wheel event. r=kats (b3346b81fb)
- Fix some fields missing in the widget event IPC glue. (bug 1139711, r=kats) (1298b25705)
- Bug 1016035 - Add mCanTriggerSwipe and TriggersSwipe(). r=masayuki (664a059972)
- Bug 1016035 - Make APZEventState report defaultPrevented=true when the event started a swipe. r=kats (128d627ac7)
- Bug 1016035 - Set scroll overflow information on potential swipe start events that have been processed by APZ. r=masayuki (b5931f6320)
- Bug 1206801 - fix broken CONFIG['DEBUG'] checks in moz.build files; r=mshal (292d5ac709)
- Bug 1186424: Refactor AsmJSValidate.cpp in preparation for parallelization; r=luke (4868bc66ca)
- Bug 1129267 - Fix by backing out patch for bug 1118615. r=mstange (ea8aaba04e)
- Bug 1182411 Part 1: Make plugin quirks available to the Parent as well as the Child. r=jimm (1f2551a6b7)
- Bug 1228462 - "PluginQuirks.* uses DOS CRLF". r=jmathies (b569a6c6c8)
- Bug 1152300 - When focus shifts from a native plugin window to content, content needs to forward the request for focus change to chrome. r=enn (5bd811fadd)
- Bug 1185529: On Windows, ensure that NPAPI child window has the correct parent before setwindow is called. r=jimm (9d94fdf2ff)
- Bug 1182411 Part 2: Change winless popup surrogate to have its parent set in the chrome process. r=jimm (adee9bb012)
2022-02-02 12:04:50 +08:00

372 lines
12 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 et :
* 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 dom_plugins_PluginModuleChild_h
#define dom_plugins_PluginModuleChild_h 1
#include "mozilla/Attributes.h"
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "prlink.h"
#include "npapi.h"
#include "npfunctions.h"
#include "nsAutoPtr.h"
#include "nsDataHashtable.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#ifdef MOZ_WIDGET_COCOA
#include "PluginInterposeOSX.h"
#endif
#include "mozilla/plugins/PPluginModuleChild.h"
#include "mozilla/plugins/PluginInstanceChild.h"
#include "mozilla/plugins/PluginMessageUtils.h"
#include "mozilla/plugins/PluginQuirks.h"
// NOTE: stolen from nsNPAPIPlugin.h
#if defined(XP_WIN)
#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name)
#else
#define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (* _name)
#endif
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_GETENTRYPOINTS) (NPPluginFuncs* pCallbacks);
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGININIT) (const NPNetscapeFuncs* pCallbacks);
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT) (const NPNetscapeFuncs* pCallbacks, NPPluginFuncs* fCallbacks);
typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) (void);
namespace mozilla {
namespace plugins {
#ifdef MOZ_WIDGET_QT
class NestedLoopTimer;
static const int kNestedLoopDetectorIntervalMs = 90;
#endif
class PluginInstanceChild;
class PluginModuleChild : public PPluginModuleChild
{
virtual mozilla::ipc::RacyInterruptPolicy
MediateInterruptRace(const Message& parent, const Message& child) override
{
return MediateRace(parent, child);
}
virtual bool ShouldContinueFromReplyTimeout() override;
virtual bool RecvSettingChanged(const PluginSettings& aSettings) override;
// Implement the PPluginModuleChild interface
virtual bool RecvDisableFlashProtectedMode() override;
virtual bool AnswerNP_GetEntryPoints(NPError* rv) override;
virtual bool AnswerNP_Initialize(const PluginSettings& aSettings, NPError* rv) override;
virtual bool RecvAsyncNP_Initialize(const PluginSettings& aSettings) override;
virtual bool AnswerSyncNPP_New(PPluginInstanceChild* aActor, NPError* rv)
override;
virtual bool RecvAsyncNPP_New(PPluginInstanceChild* aActor) override;
virtual PPluginModuleChild*
AllocPPluginModuleChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) override;
virtual PPluginInstanceChild*
AllocPPluginInstanceChild(const nsCString& aMimeType,
const uint16_t& aMode,
const InfallibleTArray<nsCString>& aNames,
const InfallibleTArray<nsCString>& aValues)
override;
virtual bool
DeallocPPluginInstanceChild(PPluginInstanceChild* aActor) override;
virtual bool
RecvPPluginInstanceConstructor(PPluginInstanceChild* aActor,
const nsCString& aMimeType,
const uint16_t& aMode,
InfallibleTArray<nsCString>&& aNames,
InfallibleTArray<nsCString>&& aValues)
override;
virtual bool
AnswerNP_Shutdown(NPError *rv) override;
virtual bool
AnswerOptionalFunctionsSupported(bool *aURLRedirectNotify,
bool *aClearSiteData,
bool *aGetSitesWithData) override;
virtual bool
AnswerNPP_ClearSiteData(const nsCString& aSite,
const uint64_t& aFlags,
const uint64_t& aMaxAge,
NPError* aResult) override;
virtual bool
AnswerNPP_GetSitesWithData(InfallibleTArray<nsCString>* aResult) override;
virtual bool
RecvSetAudioSessionData(const nsID& aId,
const nsString& aDisplayName,
const nsString& aIconPath) override;
virtual bool
RecvSetParentHangTimeout(const uint32_t& aSeconds) override;
virtual void
ActorDestroy(ActorDestroyReason why) override;
MOZ_NORETURN void QuickExit();
virtual bool
RecvProcessNativeEventsInInterruptCall() override;
virtual bool RecvStartProfiler(const uint32_t& aEntries,
const double& aInterval,
nsTArray<nsCString>&& aFeatures,
nsTArray<nsCString>&& aThreadNameFilters) override;
virtual bool RecvStopProfiler() override;
virtual bool RecvGatherProfile() override;
public:
explicit PluginModuleChild(bool aIsChrome);
virtual ~PluginModuleChild();
bool CommonInit(base::ProcessId aParentPid,
MessageLoop* aIOLoop,
IPC::Channel* aChannel);
// aPluginFilename is UTF8, not native-charset!
bool InitForChrome(const std::string& aPluginFilename,
base::ProcessId aParentPid,
MessageLoop* aIOLoop,
IPC::Channel* aChannel);
bool InitForContent(base::ProcessId aParentPid,
MessageLoop* aIOLoop,
IPC::Channel* aChannel);
static PluginModuleChild*
CreateForContentProcess(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess);
void CleanUp();
NPError NP_Shutdown();
const char* GetUserAgent();
static const NPNetscapeFuncs sBrowserFuncs;
static PluginModuleChild* GetChrome();
/**
* The child implementation of NPN_CreateObject.
*/
static NPObject* NPN_CreateObject(NPP aNPP, NPClass* aClass);
/**
* The child implementation of NPN_RetainObject.
*/
static NPObject* NPN_RetainObject(NPObject* aNPObj);
/**
* The child implementation of NPN_ReleaseObject.
*/
static void NPN_ReleaseObject(NPObject* aNPObj);
/**
* The child implementations of NPIdentifier-related functions.
*/
static NPIdentifier NPN_GetStringIdentifier(const NPUTF8* aName);
static void NPN_GetStringIdentifiers(const NPUTF8** aNames,
int32_t aNameCount,
NPIdentifier* aIdentifiers);
static NPIdentifier NPN_GetIntIdentifier(int32_t aIntId);
static bool NPN_IdentifierIsString(NPIdentifier aIdentifier);
static NPUTF8* NPN_UTF8FromIdentifier(NPIdentifier aIdentifier);
static int32_t NPN_IntFromIdentifier(NPIdentifier aIdentifier);
#ifdef MOZ_WIDGET_COCOA
void ProcessNativeEvents();
void PluginShowWindow(uint32_t window_id, bool modal, CGRect r) {
SendPluginShowWindow(window_id, modal, r.origin.x, r.origin.y, r.size.width, r.size.height);
}
void PluginHideWindow(uint32_t window_id) {
SendPluginHideWindow(window_id);
}
void SetCursor(NSCursorInfo& cursorInfo) {
SendSetCursor(cursorInfo);
}
void ShowCursor(bool show) {
SendShowCursor(show);
}
void PushCursor(NSCursorInfo& cursorInfo) {
SendPushCursor(cursorInfo);
}
void PopCursor() {
SendPopCursor();
}
bool GetNativeCursorsSupported() {
return Settings().nativeCursorsSupported();
}
#endif
int GetQuirks() { return mQuirks; }
const PluginSettings& Settings() const { return mCachedSettings; }
private:
NPError DoNP_Initialize(const PluginSettings& aSettings);
void AddQuirk(PluginQuirks quirk) {
if (mQuirks == QUIRKS_NOT_INITIALIZED)
mQuirks = 0;
mQuirks |= quirk;
}
void InitQuirksModes(const nsCString& aMimeType);
bool InitGraphics();
void DeinitGraphics();
#if defined(OS_WIN)
void HookProtectedMode();
#endif
#if defined(MOZ_WIDGET_GTK)
static gboolean DetectNestedEventLoop(gpointer data);
static gboolean ProcessBrowserEvents(gpointer data);
virtual void EnteredCxxStack() override;
virtual void ExitedCxxStack() override;
#elif defined(MOZ_WIDGET_QT)
virtual void EnteredCxxStack() override;
virtual void ExitedCxxStack() override;
#endif
PRLibrary* mLibrary;
nsCString mPluginFilename; // UTF8
int mQuirks;
bool mIsChrome;
bool mHasShutdown; // true if NP_Shutdown has run
Transport* mTransport;
// we get this from the plugin
NP_PLUGINSHUTDOWN mShutdownFunc;
#if defined(OS_LINUX) || defined(OS_BSD)
NP_PLUGINUNIXINIT mInitializeFunc;
#elif defined(OS_WIN) || defined(OS_MACOSX)
NP_PLUGININIT mInitializeFunc;
NP_GETENTRYPOINTS mGetEntryPointsFunc;
#endif
NPPluginFuncs mFunctions;
PluginSettings mCachedSettings;
#if defined(MOZ_WIDGET_GTK)
// If a plugin spins a nested glib event loop in response to a
// synchronous IPC message from the browser, the loop might break
// only after the browser responds to a request sent by the
// plugin. This can happen if a plugin uses gtk's synchronous
// copy/paste, for example. But because the browser is blocked on
// a condvar, it can't respond to the request. This situation
// isn't technically a deadlock, but the symptoms are basically
// the same from the user's perspective.
//
// We take two steps to prevent this
//
// (1) Detect nested event loops spun by the plugin. This is
// done by scheduling a glib timer event in the plugin
// process whenever the browser might block on the plugin.
// If the plugin indeed spins a nested loop, this timer event
// will fire "soon" thereafter.
//
// (2) When a nested loop is detected, deschedule the
// nested-loop-detection timer and in its place, schedule
// another timer that periodically calls back into the
// browser and spins a mini event loop. This mini event loop
// processes a handful of pending native events.
//
// Because only timer (1) or (2) (or neither) may be active at any
// point in time, we use the same member variable
// |mNestedLoopTimerId| to refer to both.
//
// When the browser no longer might be blocked on a plugin's IPC
// response, we deschedule whichever of (1) or (2) is active.
guint mNestedLoopTimerId;
# ifdef DEBUG
// Depth of the stack of calls to g_main_context_dispatch before any
// nested loops are run. This is 1 when IPC calls are dispatched from
// g_main_context_iteration, or 0 when dispatched directly from
// MessagePumpForUI.
int mTopLoopDepth;
# endif
#elif defined (MOZ_WIDGET_QT)
NestedLoopTimer *mNestedLoopTimerObject;
#endif
public: // called by PluginInstanceChild
/**
* Dealloc an NPObject after last-release or when the associated instance
* is destroyed. This function will remove the object from mObjectMap.
*/
static void DeallocNPObject(NPObject* o);
NPError NPP_Destroy(PluginInstanceChild* instance) {
return mFunctions.destroy(instance->GetNPP(), 0);
}
private:
#if defined(OS_WIN)
virtual void EnteredCall() override;
virtual void ExitedCall() override;
// Entered/ExitedCall notifications keep track of whether the plugin has
// entered a nested event loop within this interrupt call.
struct IncallFrame
{
IncallFrame()
: _spinning(false)
, _savedNestableTasksAllowed(false)
{ }
bool _spinning;
bool _savedNestableTasksAllowed;
};
nsAutoTArray<IncallFrame, 8> mIncallPumpingStack;
static LRESULT CALLBACK NestedInputEventHook(int code,
WPARAM wParam,
LPARAM lParam);
static LRESULT CALLBACK CallWindowProcHook(int code,
WPARAM wParam,
LPARAM lParam);
void SetEventHooks();
void ResetEventHooks();
HHOOK mNestedEventHook;
HHOOK mGlobalCallWndProcHook;
#endif
};
} /* namespace plugins */
} /* namespace mozilla */
#endif // ifndef dom_plugins_PluginModuleChild_h