dom/plugins/ipc/PluginModuleParent.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/ipc/PluginModuleParent.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,369 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: sw=4 ts=4 et :
     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 mozilla_plugins_PluginModuleParent_h
    1.11 +#define mozilla_plugins_PluginModuleParent_h
    1.12 +
    1.13 +#include "base/process.h"
    1.14 +#include "mozilla/FileUtils.h"
    1.15 +#include "mozilla/PluginLibrary.h"
    1.16 +#include "mozilla/plugins/ScopedMethodFactory.h"
    1.17 +#include "mozilla/plugins/PluginProcessParent.h"
    1.18 +#include "mozilla/plugins/PPluginModuleParent.h"
    1.19 +#include "mozilla/plugins/PluginMessageUtils.h"
    1.20 +#include "npapi.h"
    1.21 +#include "npfunctions.h"
    1.22 +#include "nsAutoPtr.h"
    1.23 +#include "nsDataHashtable.h"
    1.24 +#include "nsHashKeys.h"
    1.25 +#include "nsIObserver.h"
    1.26 +
    1.27 +#ifdef MOZ_CRASHREPORTER
    1.28 +#include "nsExceptionHandler.h"
    1.29 +#endif
    1.30 +
    1.31 +namespace mozilla {
    1.32 +namespace dom {
    1.33 +class PCrashReporterParent;
    1.34 +class CrashReporterParent;
    1.35 +}
    1.36 +
    1.37 +namespace plugins {
    1.38 +//-----------------------------------------------------------------------------
    1.39 +
    1.40 +class BrowserStreamParent;
    1.41 +class PluginIdentifierParent;
    1.42 +class PluginInstanceParent;
    1.43 +
    1.44 +#ifdef XP_WIN
    1.45 +class PluginHangUIParent;
    1.46 +#endif
    1.47 +
    1.48 +/**
    1.49 + * PluginModuleParent
    1.50 + *
    1.51 + * This class implements the NPP API from the perspective of the rest
    1.52 + * of Gecko, forwarding NPP calls along to the child process that is
    1.53 + * actually running the plugin.
    1.54 + *
    1.55 + * This class /also/ implements a version of the NPN API, because the
    1.56 + * child process needs to make these calls back into Gecko proper.
    1.57 + * This class is responsible for "actually" making those function calls.
    1.58 + */
    1.59 +class PluginModuleParent
    1.60 +    : public PPluginModuleParent
    1.61 +    , public PluginLibrary
    1.62 +#ifdef MOZ_CRASHREPORTER_INJECTOR
    1.63 +    , public CrashReporter::InjectorCrashCallback
    1.64 +#endif
    1.65 +{
    1.66 +private:
    1.67 +    typedef mozilla::PluginLibrary PluginLibrary;
    1.68 +    typedef mozilla::dom::PCrashReporterParent PCrashReporterParent;
    1.69 +    typedef mozilla::dom::CrashReporterParent CrashReporterParent;
    1.70 +
    1.71 +protected:
    1.72 +
    1.73 +    virtual PPluginIdentifierParent*
    1.74 +    AllocPPluginIdentifierParent(const nsCString& aString,
    1.75 +                                 const int32_t& aInt,
    1.76 +                                 const bool& aTemporary) MOZ_OVERRIDE;
    1.77 +
    1.78 +    virtual bool
    1.79 +    DeallocPPluginIdentifierParent(PPluginIdentifierParent* aActor) MOZ_OVERRIDE;
    1.80 +
    1.81 +    PPluginInstanceParent*
    1.82 +    AllocPPluginInstanceParent(const nsCString& aMimeType,
    1.83 +                               const uint16_t& aMode,
    1.84 +                               const InfallibleTArray<nsCString>& aNames,
    1.85 +                               const InfallibleTArray<nsCString>& aValues,
    1.86 +                               NPError* rv) MOZ_OVERRIDE;
    1.87 +
    1.88 +    virtual bool
    1.89 +    DeallocPPluginInstanceParent(PPluginInstanceParent* aActor) MOZ_OVERRIDE;
    1.90 +
    1.91 +public:
    1.92 +    // aFilePath is UTF8, not native!
    1.93 +    PluginModuleParent(const char* aFilePath);
    1.94 +    virtual ~PluginModuleParent();
    1.95 +
    1.96 +    virtual void SetPlugin(nsNPAPIPlugin* plugin) MOZ_OVERRIDE
    1.97 +    {
    1.98 +        mPlugin = plugin;
    1.99 +    }
   1.100 +
   1.101 +    virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
   1.102 +
   1.103 +    /**
   1.104 +     * LoadModule
   1.105 +     *
   1.106 +     * This may or may not launch a plugin child process,
   1.107 +     * and may or may not be very expensive.
   1.108 +     */
   1.109 +    static PluginLibrary* LoadModule(const char* aFilePath);
   1.110 +
   1.111 +    const NPNetscapeFuncs* GetNetscapeFuncs() {
   1.112 +        return mNPNIface;
   1.113 +    }
   1.114 +
   1.115 +    PluginProcessParent* Process() const { return mSubprocess; }
   1.116 +    base::ProcessHandle ChildProcessHandle() { return mSubprocess->GetChildProcessHandle(); }
   1.117 +
   1.118 +    bool OkToCleanup() const {
   1.119 +        return !IsOnCxxStack();
   1.120 +    }
   1.121 +
   1.122 +    /**
   1.123 +     * Get an identifier actor for this NPIdentifier. If this is a temporary
   1.124 +     * identifier, the temporary refcount is increased by one. This method
   1.125 +     * is intended only for use by StackIdentifier and the scriptable
   1.126 +     * Enumerate hook.
   1.127 +     */
   1.128 +    PluginIdentifierParent*
   1.129 +    GetIdentifierForNPIdentifier(NPP npp, NPIdentifier aIdentifier);
   1.130 +
   1.131 +    void ProcessRemoteNativeEventsInInterruptCall();
   1.132 +
   1.133 +    void TerminateChildProcess(MessageLoop* aMsgLoop);
   1.134 +
   1.135 +#ifdef XP_WIN
   1.136 +    void
   1.137 +    ExitedCxxStack() MOZ_OVERRIDE;
   1.138 +#endif // XP_WIN
   1.139 +
   1.140 +protected:
   1.141 +    virtual mozilla::ipc::RacyInterruptPolicy
   1.142 +    MediateInterruptRace(const Message& parent, const Message& child) MOZ_OVERRIDE
   1.143 +    {
   1.144 +        return MediateRace(parent, child);
   1.145 +    }
   1.146 +
   1.147 +    virtual bool ShouldContinueFromReplyTimeout() MOZ_OVERRIDE;
   1.148 +
   1.149 +    virtual bool
   1.150 +    RecvBackUpXResources(const FileDescriptor& aXSocketFd) MOZ_OVERRIDE;
   1.151 +
   1.152 +    virtual bool
   1.153 +    AnswerNPN_UserAgent(nsCString* userAgent) MOZ_OVERRIDE;
   1.154 +
   1.155 +    virtual bool
   1.156 +    AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable,
   1.157 +                                      NPError* aError,
   1.158 +                                      bool* aBoolVal) MOZ_OVERRIDE;
   1.159 +
   1.160 +    virtual bool AnswerProcessSomeEvents() MOZ_OVERRIDE;
   1.161 +
   1.162 +    virtual bool
   1.163 +    RecvProcessNativeEventsInInterruptCall() MOZ_OVERRIDE;
   1.164 +
   1.165 +    virtual bool
   1.166 +    RecvPluginShowWindow(const uint32_t& aWindowId, const bool& aModal,
   1.167 +                         const int32_t& aX, const int32_t& aY,
   1.168 +                         const size_t& aWidth, const size_t& aHeight) MOZ_OVERRIDE;
   1.169 +
   1.170 +    virtual bool
   1.171 +    RecvPluginHideWindow(const uint32_t& aWindowId) MOZ_OVERRIDE;
   1.172 +
   1.173 +    virtual PCrashReporterParent*
   1.174 +    AllocPCrashReporterParent(mozilla::dom::NativeThreadId* id,
   1.175 +                              uint32_t* processType) MOZ_OVERRIDE;
   1.176 +    virtual bool
   1.177 +    DeallocPCrashReporterParent(PCrashReporterParent* actor) MOZ_OVERRIDE;
   1.178 +
   1.179 +    virtual bool
   1.180 +    RecvSetCursor(const NSCursorInfo& aCursorInfo) MOZ_OVERRIDE;
   1.181 +
   1.182 +    virtual bool
   1.183 +    RecvShowCursor(const bool& aShow) MOZ_OVERRIDE;
   1.184 +
   1.185 +    virtual bool
   1.186 +    RecvPushCursor(const NSCursorInfo& aCursorInfo) MOZ_OVERRIDE;
   1.187 +
   1.188 +    virtual bool
   1.189 +    RecvPopCursor() MOZ_OVERRIDE;
   1.190 +
   1.191 +    virtual bool
   1.192 +    RecvGetNativeCursorsSupported(bool* supported) MOZ_OVERRIDE;
   1.193 +
   1.194 +    virtual bool
   1.195 +    RecvNPN_SetException(PPluginScriptableObjectParent* aActor,
   1.196 +                         const nsCString& aMessage) MOZ_OVERRIDE;
   1.197 +
   1.198 +    virtual bool
   1.199 +    RecvNPN_ReloadPlugins(const bool& aReloadPages) MOZ_OVERRIDE;
   1.200 +
   1.201 +    static PluginInstanceParent* InstCast(NPP instance);
   1.202 +    static BrowserStreamParent* StreamCast(NPP instance, NPStream* s);
   1.203 +
   1.204 +private:
   1.205 +    void SetPluginFuncs(NPPluginFuncs* aFuncs);
   1.206 +
   1.207 +    // Implement the module-level functions from NPAPI; these are
   1.208 +    // normally resolved directly from the DSO.
   1.209 +#ifdef OS_LINUX
   1.210 +    NPError NP_Initialize(const NPNetscapeFuncs* npnIface,
   1.211 +                          NPPluginFuncs* nppIface);
   1.212 +#else
   1.213 +    NPError NP_Initialize(const NPNetscapeFuncs* npnIface);
   1.214 +    NPError NP_GetEntryPoints(NPPluginFuncs* nppIface);
   1.215 +#endif
   1.216 +
   1.217 +    // NPP-like API that Gecko calls are trampolined into.  These 
   1.218 +    // messages then get forwarded along to the plugin instance,
   1.219 +    // and then eventually the child process.
   1.220 +
   1.221 +    static NPError NPP_Destroy(NPP instance, NPSavedData** save);
   1.222 +
   1.223 +    static NPError NPP_SetWindow(NPP instance, NPWindow* window);
   1.224 +    static NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
   1.225 +                                 NPBool seekable, uint16_t* stype);
   1.226 +    static NPError NPP_DestroyStream(NPP instance,
   1.227 +                                     NPStream* stream, NPReason reason);
   1.228 +    static int32_t NPP_WriteReady(NPP instance, NPStream* stream);
   1.229 +    static int32_t NPP_Write(NPP instance, NPStream* stream,
   1.230 +                             int32_t offset, int32_t len, void* buffer);
   1.231 +    static void NPP_StreamAsFile(NPP instance,
   1.232 +                                 NPStream* stream, const char* fname);
   1.233 +    static void NPP_Print(NPP instance, NPPrint* platformPrint);
   1.234 +    static int16_t NPP_HandleEvent(NPP instance, void* event);
   1.235 +    static void NPP_URLNotify(NPP instance, const char* url,
   1.236 +                              NPReason reason, void* notifyData);
   1.237 +    static NPError NPP_GetValue(NPP instance,
   1.238 +                                NPPVariable variable, void *ret_value);
   1.239 +    static NPError NPP_SetValue(NPP instance, NPNVariable variable,
   1.240 +                                void *value);
   1.241 +    static void NPP_URLRedirectNotify(NPP instance, const char* url,
   1.242 +                                      int32_t status, void* notifyData);
   1.243 +
   1.244 +    virtual bool HasRequiredFunctions();
   1.245 +    virtual nsresult AsyncSetWindow(NPP instance, NPWindow* window);
   1.246 +    virtual nsresult GetImageContainer(NPP instance, mozilla::layers::ImageContainer** aContainer);
   1.247 +    virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize);
   1.248 +    virtual bool IsOOP() MOZ_OVERRIDE { return true; }
   1.249 +    virtual nsresult SetBackgroundUnknown(NPP instance) MOZ_OVERRIDE;
   1.250 +    virtual nsresult BeginUpdateBackground(NPP instance,
   1.251 +                                           const nsIntRect& aRect,
   1.252 +                                           gfxContext** aCtx) MOZ_OVERRIDE;
   1.253 +    virtual nsresult EndUpdateBackground(NPP instance,
   1.254 +                                         gfxContext* aCtx,
   1.255 +                                         const nsIntRect& aRect) MOZ_OVERRIDE;
   1.256 +
   1.257 +#if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(MOZ_WIDGET_GONK)
   1.258 +    virtual nsresult NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs, NPError* error);
   1.259 +#else
   1.260 +    virtual nsresult NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error);
   1.261 +#endif
   1.262 +    virtual nsresult NP_Shutdown(NPError* error);
   1.263 +    virtual nsresult NP_GetMIMEDescription(const char** mimeDesc);
   1.264 +    virtual nsresult NP_GetValue(void *future, NPPVariable aVariable,
   1.265 +                                 void *aValue, NPError* error);
   1.266 +#if defined(XP_WIN) || defined(XP_MACOSX)
   1.267 +    virtual nsresult NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error);
   1.268 +#endif
   1.269 +    virtual nsresult NPP_New(NPMIMEType pluginType, NPP instance,
   1.270 +                             uint16_t mode, int16_t argc, char* argn[],
   1.271 +                             char* argv[], NPSavedData* saved,
   1.272 +                             NPError* error);
   1.273 +    virtual nsresult NPP_ClearSiteData(const char* site, uint64_t flags,
   1.274 +                                       uint64_t maxAge);
   1.275 +    virtual nsresult NPP_GetSitesWithData(InfallibleTArray<nsCString>& result);
   1.276 +
   1.277 +#if defined(XP_MACOSX)
   1.278 +    virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing);
   1.279 +    virtual nsresult ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor);
   1.280 +#endif
   1.281 +
   1.282 +private:
   1.283 +    CrashReporterParent* CrashReporter();
   1.284 +
   1.285 +#ifdef MOZ_CRASHREPORTER
   1.286 +    void ProcessFirstMinidump();
   1.287 +    void WriteExtraDataForMinidump(CrashReporter::AnnotationTable& notes);
   1.288 +#endif
   1.289 +    void CleanupFromTimeout(const bool aByHangUI);
   1.290 +    void SetChildTimeout(const int32_t aChildTimeout);
   1.291 +    static void TimeoutChanged(const char* aPref, void* aModule);
   1.292 +    void NotifyPluginCrashed();
   1.293 +
   1.294 +#ifdef MOZ_ENABLE_PROFILER_SPS
   1.295 +    void InitPluginProfiling();
   1.296 +    void ShutdownPluginProfiling();
   1.297 +#endif
   1.298 +
   1.299 +    PluginProcessParent* mSubprocess;
   1.300 +    bool mShutdown;
   1.301 +    bool mClearSiteDataSupported;
   1.302 +    bool mGetSitesWithDataSupported;
   1.303 +    const NPNetscapeFuncs* mNPNIface;
   1.304 +    nsDataHashtable<nsPtrHashKey<void>, PluginIdentifierParent*> mIdentifiers;
   1.305 +    nsNPAPIPlugin* mPlugin;
   1.306 +    ScopedMethodFactory<PluginModuleParent> mTaskFactory;
   1.307 +    nsString mPluginDumpID;
   1.308 +    nsString mBrowserDumpID;
   1.309 +    nsString mHangID;
   1.310 +    nsRefPtr<nsIObserver> mProfilerObserver;
   1.311 +#ifdef XP_WIN
   1.312 +    InfallibleTArray<float> mPluginCpuUsageOnHang;
   1.313 +    PluginHangUIParent *mHangUIParent;
   1.314 +    bool mHangUIEnabled;
   1.315 +    bool mIsTimerReset;
   1.316 +#ifdef MOZ_CRASHREPORTER
   1.317 +    /**
   1.318 +     * This mutex protects the crash reporter when the Plugin Hang UI event
   1.319 +     * handler is executing off main thread. It is intended to protect both
   1.320 +     * the mCrashReporter variable in addition to the CrashReporterParent object
   1.321 +     * that mCrashReporter refers to.
   1.322 +     */
   1.323 +    mozilla::Mutex mCrashReporterMutex;
   1.324 +    CrashReporterParent* mCrashReporter;
   1.325 +#endif // MOZ_CRASHREPORTER
   1.326 +
   1.327 +
   1.328 +    void
   1.329 +    EvaluateHangUIState(const bool aReset);
   1.330 +
   1.331 +    bool
   1.332 +    GetPluginName(nsAString& aPluginName);
   1.333 +
   1.334 +    /**
   1.335 +     * Launches the Plugin Hang UI.
   1.336 +     *
   1.337 +     * @return true if plugin-hang-ui.exe has been successfully launched.
   1.338 +     *         false if the Plugin Hang UI is disabled, already showing,
   1.339 +     *               or the launch failed.
   1.340 +     */
   1.341 +    bool
   1.342 +    LaunchHangUI();
   1.343 +
   1.344 +    /**
   1.345 +     * Finishes the Plugin Hang UI and cancels if it is being shown to the user.
   1.346 +     */
   1.347 +    void
   1.348 +    FinishHangUI();
   1.349 +#endif
   1.350 +
   1.351 +#ifdef MOZ_X11
   1.352 +    // Dup of plugin's X socket, used to scope its resources to this
   1.353 +    // object instead of the plugin process's lifetime
   1.354 +    ScopedClose mPluginXSocketFdDup;
   1.355 +#endif
   1.356 +
   1.357 +    friend class mozilla::dom::CrashReporterParent;
   1.358 +
   1.359 +#ifdef MOZ_CRASHREPORTER_INJECTOR
   1.360 +    void InitializeInjector();
   1.361 +    
   1.362 +    void OnCrash(DWORD processID) MOZ_OVERRIDE;
   1.363 +
   1.364 +    DWORD mFlashProcess1;
   1.365 +    DWORD mFlashProcess2;
   1.366 +#endif
   1.367 +};
   1.368 +
   1.369 +} // namespace plugins
   1.370 +} // namespace mozilla
   1.371 +
   1.372 +#endif // mozilla_plugins_PluginModuleParent_h

mercurial