dom/plugins/ipc/PluginModuleParent.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: sw=4 ts=4 et :
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 mozilla_plugins_PluginModuleParent_h
michael@0 8 #define mozilla_plugins_PluginModuleParent_h
michael@0 9
michael@0 10 #include "base/process.h"
michael@0 11 #include "mozilla/FileUtils.h"
michael@0 12 #include "mozilla/PluginLibrary.h"
michael@0 13 #include "mozilla/plugins/ScopedMethodFactory.h"
michael@0 14 #include "mozilla/plugins/PluginProcessParent.h"
michael@0 15 #include "mozilla/plugins/PPluginModuleParent.h"
michael@0 16 #include "mozilla/plugins/PluginMessageUtils.h"
michael@0 17 #include "npapi.h"
michael@0 18 #include "npfunctions.h"
michael@0 19 #include "nsAutoPtr.h"
michael@0 20 #include "nsDataHashtable.h"
michael@0 21 #include "nsHashKeys.h"
michael@0 22 #include "nsIObserver.h"
michael@0 23
michael@0 24 #ifdef MOZ_CRASHREPORTER
michael@0 25 #include "nsExceptionHandler.h"
michael@0 26 #endif
michael@0 27
michael@0 28 namespace mozilla {
michael@0 29 namespace dom {
michael@0 30 class PCrashReporterParent;
michael@0 31 class CrashReporterParent;
michael@0 32 }
michael@0 33
michael@0 34 namespace plugins {
michael@0 35 //-----------------------------------------------------------------------------
michael@0 36
michael@0 37 class BrowserStreamParent;
michael@0 38 class PluginIdentifierParent;
michael@0 39 class PluginInstanceParent;
michael@0 40
michael@0 41 #ifdef XP_WIN
michael@0 42 class PluginHangUIParent;
michael@0 43 #endif
michael@0 44
michael@0 45 /**
michael@0 46 * PluginModuleParent
michael@0 47 *
michael@0 48 * This class implements the NPP API from the perspective of the rest
michael@0 49 * of Gecko, forwarding NPP calls along to the child process that is
michael@0 50 * actually running the plugin.
michael@0 51 *
michael@0 52 * This class /also/ implements a version of the NPN API, because the
michael@0 53 * child process needs to make these calls back into Gecko proper.
michael@0 54 * This class is responsible for "actually" making those function calls.
michael@0 55 */
michael@0 56 class PluginModuleParent
michael@0 57 : public PPluginModuleParent
michael@0 58 , public PluginLibrary
michael@0 59 #ifdef MOZ_CRASHREPORTER_INJECTOR
michael@0 60 , public CrashReporter::InjectorCrashCallback
michael@0 61 #endif
michael@0 62 {
michael@0 63 private:
michael@0 64 typedef mozilla::PluginLibrary PluginLibrary;
michael@0 65 typedef mozilla::dom::PCrashReporterParent PCrashReporterParent;
michael@0 66 typedef mozilla::dom::CrashReporterParent CrashReporterParent;
michael@0 67
michael@0 68 protected:
michael@0 69
michael@0 70 virtual PPluginIdentifierParent*
michael@0 71 AllocPPluginIdentifierParent(const nsCString& aString,
michael@0 72 const int32_t& aInt,
michael@0 73 const bool& aTemporary) MOZ_OVERRIDE;
michael@0 74
michael@0 75 virtual bool
michael@0 76 DeallocPPluginIdentifierParent(PPluginIdentifierParent* aActor) MOZ_OVERRIDE;
michael@0 77
michael@0 78 PPluginInstanceParent*
michael@0 79 AllocPPluginInstanceParent(const nsCString& aMimeType,
michael@0 80 const uint16_t& aMode,
michael@0 81 const InfallibleTArray<nsCString>& aNames,
michael@0 82 const InfallibleTArray<nsCString>& aValues,
michael@0 83 NPError* rv) MOZ_OVERRIDE;
michael@0 84
michael@0 85 virtual bool
michael@0 86 DeallocPPluginInstanceParent(PPluginInstanceParent* aActor) MOZ_OVERRIDE;
michael@0 87
michael@0 88 public:
michael@0 89 // aFilePath is UTF8, not native!
michael@0 90 PluginModuleParent(const char* aFilePath);
michael@0 91 virtual ~PluginModuleParent();
michael@0 92
michael@0 93 virtual void SetPlugin(nsNPAPIPlugin* plugin) MOZ_OVERRIDE
michael@0 94 {
michael@0 95 mPlugin = plugin;
michael@0 96 }
michael@0 97
michael@0 98 virtual void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
michael@0 99
michael@0 100 /**
michael@0 101 * LoadModule
michael@0 102 *
michael@0 103 * This may or may not launch a plugin child process,
michael@0 104 * and may or may not be very expensive.
michael@0 105 */
michael@0 106 static PluginLibrary* LoadModule(const char* aFilePath);
michael@0 107
michael@0 108 const NPNetscapeFuncs* GetNetscapeFuncs() {
michael@0 109 return mNPNIface;
michael@0 110 }
michael@0 111
michael@0 112 PluginProcessParent* Process() const { return mSubprocess; }
michael@0 113 base::ProcessHandle ChildProcessHandle() { return mSubprocess->GetChildProcessHandle(); }
michael@0 114
michael@0 115 bool OkToCleanup() const {
michael@0 116 return !IsOnCxxStack();
michael@0 117 }
michael@0 118
michael@0 119 /**
michael@0 120 * Get an identifier actor for this NPIdentifier. If this is a temporary
michael@0 121 * identifier, the temporary refcount is increased by one. This method
michael@0 122 * is intended only for use by StackIdentifier and the scriptable
michael@0 123 * Enumerate hook.
michael@0 124 */
michael@0 125 PluginIdentifierParent*
michael@0 126 GetIdentifierForNPIdentifier(NPP npp, NPIdentifier aIdentifier);
michael@0 127
michael@0 128 void ProcessRemoteNativeEventsInInterruptCall();
michael@0 129
michael@0 130 void TerminateChildProcess(MessageLoop* aMsgLoop);
michael@0 131
michael@0 132 #ifdef XP_WIN
michael@0 133 void
michael@0 134 ExitedCxxStack() MOZ_OVERRIDE;
michael@0 135 #endif // XP_WIN
michael@0 136
michael@0 137 protected:
michael@0 138 virtual mozilla::ipc::RacyInterruptPolicy
michael@0 139 MediateInterruptRace(const Message& parent, const Message& child) MOZ_OVERRIDE
michael@0 140 {
michael@0 141 return MediateRace(parent, child);
michael@0 142 }
michael@0 143
michael@0 144 virtual bool ShouldContinueFromReplyTimeout() MOZ_OVERRIDE;
michael@0 145
michael@0 146 virtual bool
michael@0 147 RecvBackUpXResources(const FileDescriptor& aXSocketFd) MOZ_OVERRIDE;
michael@0 148
michael@0 149 virtual bool
michael@0 150 AnswerNPN_UserAgent(nsCString* userAgent) MOZ_OVERRIDE;
michael@0 151
michael@0 152 virtual bool
michael@0 153 AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable,
michael@0 154 NPError* aError,
michael@0 155 bool* aBoolVal) MOZ_OVERRIDE;
michael@0 156
michael@0 157 virtual bool AnswerProcessSomeEvents() MOZ_OVERRIDE;
michael@0 158
michael@0 159 virtual bool
michael@0 160 RecvProcessNativeEventsInInterruptCall() MOZ_OVERRIDE;
michael@0 161
michael@0 162 virtual bool
michael@0 163 RecvPluginShowWindow(const uint32_t& aWindowId, const bool& aModal,
michael@0 164 const int32_t& aX, const int32_t& aY,
michael@0 165 const size_t& aWidth, const size_t& aHeight) MOZ_OVERRIDE;
michael@0 166
michael@0 167 virtual bool
michael@0 168 RecvPluginHideWindow(const uint32_t& aWindowId) MOZ_OVERRIDE;
michael@0 169
michael@0 170 virtual PCrashReporterParent*
michael@0 171 AllocPCrashReporterParent(mozilla::dom::NativeThreadId* id,
michael@0 172 uint32_t* processType) MOZ_OVERRIDE;
michael@0 173 virtual bool
michael@0 174 DeallocPCrashReporterParent(PCrashReporterParent* actor) MOZ_OVERRIDE;
michael@0 175
michael@0 176 virtual bool
michael@0 177 RecvSetCursor(const NSCursorInfo& aCursorInfo) MOZ_OVERRIDE;
michael@0 178
michael@0 179 virtual bool
michael@0 180 RecvShowCursor(const bool& aShow) MOZ_OVERRIDE;
michael@0 181
michael@0 182 virtual bool
michael@0 183 RecvPushCursor(const NSCursorInfo& aCursorInfo) MOZ_OVERRIDE;
michael@0 184
michael@0 185 virtual bool
michael@0 186 RecvPopCursor() MOZ_OVERRIDE;
michael@0 187
michael@0 188 virtual bool
michael@0 189 RecvGetNativeCursorsSupported(bool* supported) MOZ_OVERRIDE;
michael@0 190
michael@0 191 virtual bool
michael@0 192 RecvNPN_SetException(PPluginScriptableObjectParent* aActor,
michael@0 193 const nsCString& aMessage) MOZ_OVERRIDE;
michael@0 194
michael@0 195 virtual bool
michael@0 196 RecvNPN_ReloadPlugins(const bool& aReloadPages) MOZ_OVERRIDE;
michael@0 197
michael@0 198 static PluginInstanceParent* InstCast(NPP instance);
michael@0 199 static BrowserStreamParent* StreamCast(NPP instance, NPStream* s);
michael@0 200
michael@0 201 private:
michael@0 202 void SetPluginFuncs(NPPluginFuncs* aFuncs);
michael@0 203
michael@0 204 // Implement the module-level functions from NPAPI; these are
michael@0 205 // normally resolved directly from the DSO.
michael@0 206 #ifdef OS_LINUX
michael@0 207 NPError NP_Initialize(const NPNetscapeFuncs* npnIface,
michael@0 208 NPPluginFuncs* nppIface);
michael@0 209 #else
michael@0 210 NPError NP_Initialize(const NPNetscapeFuncs* npnIface);
michael@0 211 NPError NP_GetEntryPoints(NPPluginFuncs* nppIface);
michael@0 212 #endif
michael@0 213
michael@0 214 // NPP-like API that Gecko calls are trampolined into. These
michael@0 215 // messages then get forwarded along to the plugin instance,
michael@0 216 // and then eventually the child process.
michael@0 217
michael@0 218 static NPError NPP_Destroy(NPP instance, NPSavedData** save);
michael@0 219
michael@0 220 static NPError NPP_SetWindow(NPP instance, NPWindow* window);
michael@0 221 static NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
michael@0 222 NPBool seekable, uint16_t* stype);
michael@0 223 static NPError NPP_DestroyStream(NPP instance,
michael@0 224 NPStream* stream, NPReason reason);
michael@0 225 static int32_t NPP_WriteReady(NPP instance, NPStream* stream);
michael@0 226 static int32_t NPP_Write(NPP instance, NPStream* stream,
michael@0 227 int32_t offset, int32_t len, void* buffer);
michael@0 228 static void NPP_StreamAsFile(NPP instance,
michael@0 229 NPStream* stream, const char* fname);
michael@0 230 static void NPP_Print(NPP instance, NPPrint* platformPrint);
michael@0 231 static int16_t NPP_HandleEvent(NPP instance, void* event);
michael@0 232 static void NPP_URLNotify(NPP instance, const char* url,
michael@0 233 NPReason reason, void* notifyData);
michael@0 234 static NPError NPP_GetValue(NPP instance,
michael@0 235 NPPVariable variable, void *ret_value);
michael@0 236 static NPError NPP_SetValue(NPP instance, NPNVariable variable,
michael@0 237 void *value);
michael@0 238 static void NPP_URLRedirectNotify(NPP instance, const char* url,
michael@0 239 int32_t status, void* notifyData);
michael@0 240
michael@0 241 virtual bool HasRequiredFunctions();
michael@0 242 virtual nsresult AsyncSetWindow(NPP instance, NPWindow* window);
michael@0 243 virtual nsresult GetImageContainer(NPP instance, mozilla::layers::ImageContainer** aContainer);
michael@0 244 virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize);
michael@0 245 virtual bool IsOOP() MOZ_OVERRIDE { return true; }
michael@0 246 virtual nsresult SetBackgroundUnknown(NPP instance) MOZ_OVERRIDE;
michael@0 247 virtual nsresult BeginUpdateBackground(NPP instance,
michael@0 248 const nsIntRect& aRect,
michael@0 249 gfxContext** aCtx) MOZ_OVERRIDE;
michael@0 250 virtual nsresult EndUpdateBackground(NPP instance,
michael@0 251 gfxContext* aCtx,
michael@0 252 const nsIntRect& aRect) MOZ_OVERRIDE;
michael@0 253
michael@0 254 #if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(MOZ_WIDGET_GONK)
michael@0 255 virtual nsresult NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs, NPError* error);
michael@0 256 #else
michael@0 257 virtual nsresult NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error);
michael@0 258 #endif
michael@0 259 virtual nsresult NP_Shutdown(NPError* error);
michael@0 260 virtual nsresult NP_GetMIMEDescription(const char** mimeDesc);
michael@0 261 virtual nsresult NP_GetValue(void *future, NPPVariable aVariable,
michael@0 262 void *aValue, NPError* error);
michael@0 263 #if defined(XP_WIN) || defined(XP_MACOSX)
michael@0 264 virtual nsresult NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error);
michael@0 265 #endif
michael@0 266 virtual nsresult NPP_New(NPMIMEType pluginType, NPP instance,
michael@0 267 uint16_t mode, int16_t argc, char* argn[],
michael@0 268 char* argv[], NPSavedData* saved,
michael@0 269 NPError* error);
michael@0 270 virtual nsresult NPP_ClearSiteData(const char* site, uint64_t flags,
michael@0 271 uint64_t maxAge);
michael@0 272 virtual nsresult NPP_GetSitesWithData(InfallibleTArray<nsCString>& result);
michael@0 273
michael@0 274 #if defined(XP_MACOSX)
michael@0 275 virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing);
michael@0 276 virtual nsresult ContentsScaleFactorChanged(NPP instance, double aContentsScaleFactor);
michael@0 277 #endif
michael@0 278
michael@0 279 private:
michael@0 280 CrashReporterParent* CrashReporter();
michael@0 281
michael@0 282 #ifdef MOZ_CRASHREPORTER
michael@0 283 void ProcessFirstMinidump();
michael@0 284 void WriteExtraDataForMinidump(CrashReporter::AnnotationTable& notes);
michael@0 285 #endif
michael@0 286 void CleanupFromTimeout(const bool aByHangUI);
michael@0 287 void SetChildTimeout(const int32_t aChildTimeout);
michael@0 288 static void TimeoutChanged(const char* aPref, void* aModule);
michael@0 289 void NotifyPluginCrashed();
michael@0 290
michael@0 291 #ifdef MOZ_ENABLE_PROFILER_SPS
michael@0 292 void InitPluginProfiling();
michael@0 293 void ShutdownPluginProfiling();
michael@0 294 #endif
michael@0 295
michael@0 296 PluginProcessParent* mSubprocess;
michael@0 297 bool mShutdown;
michael@0 298 bool mClearSiteDataSupported;
michael@0 299 bool mGetSitesWithDataSupported;
michael@0 300 const NPNetscapeFuncs* mNPNIface;
michael@0 301 nsDataHashtable<nsPtrHashKey<void>, PluginIdentifierParent*> mIdentifiers;
michael@0 302 nsNPAPIPlugin* mPlugin;
michael@0 303 ScopedMethodFactory<PluginModuleParent> mTaskFactory;
michael@0 304 nsString mPluginDumpID;
michael@0 305 nsString mBrowserDumpID;
michael@0 306 nsString mHangID;
michael@0 307 nsRefPtr<nsIObserver> mProfilerObserver;
michael@0 308 #ifdef XP_WIN
michael@0 309 InfallibleTArray<float> mPluginCpuUsageOnHang;
michael@0 310 PluginHangUIParent *mHangUIParent;
michael@0 311 bool mHangUIEnabled;
michael@0 312 bool mIsTimerReset;
michael@0 313 #ifdef MOZ_CRASHREPORTER
michael@0 314 /**
michael@0 315 * This mutex protects the crash reporter when the Plugin Hang UI event
michael@0 316 * handler is executing off main thread. It is intended to protect both
michael@0 317 * the mCrashReporter variable in addition to the CrashReporterParent object
michael@0 318 * that mCrashReporter refers to.
michael@0 319 */
michael@0 320 mozilla::Mutex mCrashReporterMutex;
michael@0 321 CrashReporterParent* mCrashReporter;
michael@0 322 #endif // MOZ_CRASHREPORTER
michael@0 323
michael@0 324
michael@0 325 void
michael@0 326 EvaluateHangUIState(const bool aReset);
michael@0 327
michael@0 328 bool
michael@0 329 GetPluginName(nsAString& aPluginName);
michael@0 330
michael@0 331 /**
michael@0 332 * Launches the Plugin Hang UI.
michael@0 333 *
michael@0 334 * @return true if plugin-hang-ui.exe has been successfully launched.
michael@0 335 * false if the Plugin Hang UI is disabled, already showing,
michael@0 336 * or the launch failed.
michael@0 337 */
michael@0 338 bool
michael@0 339 LaunchHangUI();
michael@0 340
michael@0 341 /**
michael@0 342 * Finishes the Plugin Hang UI and cancels if it is being shown to the user.
michael@0 343 */
michael@0 344 void
michael@0 345 FinishHangUI();
michael@0 346 #endif
michael@0 347
michael@0 348 #ifdef MOZ_X11
michael@0 349 // Dup of plugin's X socket, used to scope its resources to this
michael@0 350 // object instead of the plugin process's lifetime
michael@0 351 ScopedClose mPluginXSocketFdDup;
michael@0 352 #endif
michael@0 353
michael@0 354 friend class mozilla::dom::CrashReporterParent;
michael@0 355
michael@0 356 #ifdef MOZ_CRASHREPORTER_INJECTOR
michael@0 357 void InitializeInjector();
michael@0 358
michael@0 359 void OnCrash(DWORD processID) MOZ_OVERRIDE;
michael@0 360
michael@0 361 DWORD mFlashProcess1;
michael@0 362 DWORD mFlashProcess2;
michael@0 363 #endif
michael@0 364 };
michael@0 365
michael@0 366 } // namespace plugins
michael@0 367 } // namespace mozilla
michael@0 368
michael@0 369 #endif // mozilla_plugins_PluginModuleParent_h

mercurial