LCOV - code coverage report
Current view: directory - dom/plugins/ipc - PluginModuleParent.h (source / functions) Found Hit Coverage
Test: app.info Lines: 2 0 0.0 %
Date: 2012-07-07 Functions: 1 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * vim: sw=4 ts=4 et :
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla Plugin App.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  *   Chris Jones <jones.chris.g@gmail.com>
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2009
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef dom_plugins_PluginModuleParent_h
      40                 : #define dom_plugins_PluginModuleParent_h 1
      41                 : 
      42                 : #include <cstring>
      43                 : 
      44                 : #include "base/basictypes.h"
      45                 : 
      46                 : #include "prlink.h"
      47                 : 
      48                 : #include "npapi.h"
      49                 : #include "npfunctions.h"
      50                 : 
      51                 : #include "base/string_util.h"
      52                 : 
      53                 : #include "mozilla/FileUtils.h"
      54                 : #include "mozilla/PluginLibrary.h"
      55                 : #include "mozilla/plugins/PPluginModuleParent.h"
      56                 : #include "mozilla/plugins/PluginInstanceParent.h"
      57                 : #include "mozilla/plugins/PluginProcessParent.h"
      58                 : #include "mozilla/plugins/PluginIdentifierParent.h"
      59                 : 
      60                 : #include "nsAutoPtr.h"
      61                 : #include "nsDataHashtable.h"
      62                 : #include "nsHashKeys.h"
      63                 : #include "nsIFileStreams.h"
      64                 : 
      65                 : namespace mozilla {
      66                 : namespace dom {
      67                 : class PCrashReporterParent;
      68                 : class CrashReporterParent;
      69                 : }
      70                 : 
      71                 : namespace plugins {
      72                 : //-----------------------------------------------------------------------------
      73                 : 
      74                 : class BrowserStreamParent;
      75                 : 
      76                 : /**
      77                 :  * PluginModuleParent
      78                 :  *
      79                 :  * This class implements the NPP API from the perspective of the rest
      80                 :  * of Gecko, forwarding NPP calls along to the child process that is
      81                 :  * actually running the plugin.
      82                 :  *
      83                 :  * This class /also/ implements a version of the NPN API, because the
      84                 :  * child process needs to make these calls back into Gecko proper.
      85                 :  * This class is responsible for "actually" making those function calls.
      86                 :  */
      87                 : class PluginModuleParent : public PPluginModuleParent, PluginLibrary
      88                 : {
      89                 : private:
      90                 :     typedef mozilla::PluginLibrary PluginLibrary;
      91                 :     typedef mozilla::dom::PCrashReporterParent PCrashReporterParent;
      92                 :     typedef mozilla::dom::CrashReporterParent CrashReporterParent;
      93                 : 
      94                 : protected:
      95                 : 
      96                 :     virtual PPluginIdentifierParent*
      97                 :     AllocPPluginIdentifier(const nsCString& aString,
      98                 :                            const int32_t& aInt,
      99                 :                            const bool& aTemporary);
     100                 : 
     101                 :     virtual bool
     102                 :     DeallocPPluginIdentifier(PPluginIdentifierParent* aActor);
     103                 : 
     104                 :     PPluginInstanceParent*
     105                 :     AllocPPluginInstance(const nsCString& aMimeType,
     106                 :                          const uint16_t& aMode,
     107                 :                          const InfallibleTArray<nsCString>& aNames,
     108                 :                          const InfallibleTArray<nsCString>& aValues,
     109                 :                          NPError* rv);
     110                 : 
     111                 :     virtual bool
     112                 :     DeallocPPluginInstance(PPluginInstanceParent* aActor);
     113                 : 
     114                 : public:
     115                 :     // aFilePath is UTF8, not native!
     116                 :     PluginModuleParent(const char* aFilePath);
     117                 :     virtual ~PluginModuleParent();
     118                 : 
     119                 :     NS_OVERRIDE virtual void SetPlugin(nsNPAPIPlugin* plugin)
     120                 :     {
     121                 :         mPlugin = plugin;
     122                 :     }
     123                 : 
     124                 :     NS_OVERRIDE virtual void ActorDestroy(ActorDestroyReason why);
     125                 : 
     126                 :     /**
     127                 :      * LoadModule
     128                 :      *
     129                 :      * This may or may not launch a plugin child process,
     130                 :      * and may or may not be very expensive.
     131                 :      */
     132                 :     static PluginLibrary* LoadModule(const char* aFilePath);
     133                 : 
     134               0 :     const NPNetscapeFuncs* GetNetscapeFuncs() {
     135               0 :         return mNPNIface;
     136                 :     }
     137                 : 
     138                 :     PluginProcessParent* Process() const { return mSubprocess; }
     139                 :     base::ProcessHandle ChildProcessHandle() { return mSubprocess->GetChildProcessHandle(); }
     140                 : 
     141                 :     bool OkToCleanup() const {
     142                 :         return !IsOnCxxStack();
     143                 :     }
     144                 : 
     145                 :     /**
     146                 :      * Get an identifier actor for this NPIdentifier. If this is a temporary
     147                 :      * identifier, the temporary refcount is increased by one. This method
     148                 :      * is intended only for use by StackIdentifier and the scriptable
     149                 :      * Enumerate hook.
     150                 :      */
     151                 :     PluginIdentifierParent*
     152                 :     GetIdentifierForNPIdentifier(NPP npp, NPIdentifier aIdentifier);
     153                 : 
     154                 :     void ProcessRemoteNativeEventsInRPCCall();
     155                 : 
     156                 : protected:
     157                 :     NS_OVERRIDE
     158                 :     virtual mozilla::ipc::RPCChannel::RacyRPCPolicy
     159                 :     MediateRPCRace(const Message& parent, const Message& child)
     160                 :     {
     161                 :         return MediateRace(parent, child);
     162                 :     }
     163                 : 
     164                 :     virtual bool RecvXXX_HACK_FIXME_cjones(Shmem& mem) { NS_RUNTIMEABORT("not reached"); return false; }
     165                 : 
     166                 :     NS_OVERRIDE
     167                 :     virtual bool ShouldContinueFromReplyTimeout();
     168                 : 
     169                 :     NS_OVERRIDE
     170                 :     virtual bool
     171                 :     RecvBackUpXResources(const FileDescriptor& aXSocketFd);
     172                 : 
     173                 :     virtual bool
     174                 :     AnswerNPN_UserAgent(nsCString* userAgent);
     175                 : 
     176                 :     virtual bool
     177                 :     AnswerNPN_GetValue_WithBoolReturn(const NPNVariable& aVariable,
     178                 :                                       NPError* aError,
     179                 :                                       bool* aBoolVal);
     180                 : 
     181                 :     NS_OVERRIDE
     182                 :     virtual bool AnswerProcessSomeEvents();
     183                 : 
     184                 :     NS_OVERRIDE virtual bool
     185                 :     RecvProcessNativeEventsInRPCCall();
     186                 : 
     187                 :     NS_OVERRIDE virtual bool
     188                 :     RecvPluginShowWindow(const uint32_t& aWindowId, const bool& aModal,
     189                 :                          const int32_t& aX, const int32_t& aY,
     190                 :                          const size_t& aWidth, const size_t& aHeight);
     191                 : 
     192                 :     NS_OVERRIDE virtual bool
     193                 :     RecvPluginHideWindow(const uint32_t& aWindowId);
     194                 : 
     195                 :     NS_OVERRIDE virtual PCrashReporterParent*
     196                 :     AllocPCrashReporter(mozilla::dom::NativeThreadId* id,
     197                 :                         PRUint32* processType);
     198                 :     NS_OVERRIDE virtual bool
     199                 :     DeallocPCrashReporter(PCrashReporterParent* actor);
     200                 : 
     201                 :     NS_OVERRIDE virtual bool
     202                 :     RecvSetCursor(const NSCursorInfo& aCursorInfo);
     203                 : 
     204                 :     NS_OVERRIDE virtual bool
     205                 :     RecvShowCursor(const bool& aShow);
     206                 : 
     207                 :     NS_OVERRIDE virtual bool
     208                 :     RecvPushCursor(const NSCursorInfo& aCursorInfo);
     209                 : 
     210                 :     NS_OVERRIDE virtual bool
     211                 :     RecvPopCursor();
     212                 : 
     213                 :     NS_OVERRIDE virtual bool
     214                 :     RecvGetNativeCursorsSupported(bool* supported);
     215                 : 
     216                 :     NS_OVERRIDE virtual bool
     217                 :     RecvNPN_SetException(PPluginScriptableObjectParent* aActor,
     218                 :                          const nsCString& aMessage);
     219                 : 
     220                 :     NS_OVERRIDE virtual bool
     221                 :     RecvNPN_ReloadPlugins(const bool& aReloadPages);
     222                 : 
     223                 :     static PluginInstanceParent* InstCast(NPP instance);
     224                 :     static BrowserStreamParent* StreamCast(NPP instance, NPStream* s);
     225                 : 
     226                 : private:
     227                 :     void SetPluginFuncs(NPPluginFuncs* aFuncs);
     228                 : 
     229                 :     // Implement the module-level functions from NPAPI; these are
     230                 :     // normally resolved directly from the DSO.
     231                 : #ifdef OS_LINUX
     232                 :     NPError NP_Initialize(const NPNetscapeFuncs* npnIface,
     233                 :                           NPPluginFuncs* nppIface);
     234                 : #else
     235                 :     NPError NP_Initialize(const NPNetscapeFuncs* npnIface);
     236                 :     NPError NP_GetEntryPoints(NPPluginFuncs* nppIface);
     237                 : #endif
     238                 : 
     239                 :     // NPP-like API that Gecko calls are trampolined into.  These 
     240                 :     // messages then get forwarded along to the plugin instance,
     241                 :     // and then eventually the child process.
     242                 : 
     243                 :     static NPError NPP_Destroy(NPP instance, NPSavedData** save);
     244                 : 
     245                 :     static NPError NPP_SetWindow(NPP instance, NPWindow* window);
     246                 :     static NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
     247                 :                                  NPBool seekable, uint16_t* stype);
     248                 :     static NPError NPP_DestroyStream(NPP instance,
     249                 :                                      NPStream* stream, NPReason reason);
     250                 :     static int32_t NPP_WriteReady(NPP instance, NPStream* stream);
     251                 :     static int32_t NPP_Write(NPP instance, NPStream* stream,
     252                 :                              int32_t offset, int32_t len, void* buffer);
     253                 :     static void NPP_StreamAsFile(NPP instance,
     254                 :                                  NPStream* stream, const char* fname);
     255                 :     static void NPP_Print(NPP instance, NPPrint* platformPrint);
     256                 :     static int16_t NPP_HandleEvent(NPP instance, void* event);
     257                 :     static void NPP_URLNotify(NPP instance, const char* url,
     258                 :                               NPReason reason, void* notifyData);
     259                 :     static NPError NPP_GetValue(NPP instance,
     260                 :                                 NPPVariable variable, void *ret_value);
     261                 :     static NPError NPP_SetValue(NPP instance, NPNVariable variable,
     262                 :                                 void *value);
     263                 :     static void NPP_URLRedirectNotify(NPP instance, const char* url,
     264                 :                                       int32_t status, void* notifyData);
     265                 : 
     266                 :     virtual bool HasRequiredFunctions();
     267                 :     virtual nsresult AsyncSetWindow(NPP instance, NPWindow* window);
     268                 :     virtual nsresult GetImageContainer(NPP instance, mozilla::layers::ImageContainer** aContainer);
     269                 :     virtual nsresult GetImageSize(NPP instance, nsIntSize* aSize);
     270                 :     NS_OVERRIDE virtual bool UseAsyncPainting() { return true; }
     271                 :     NS_OVERRIDE
     272                 :     virtual nsresult SetBackgroundUnknown(NPP instance);
     273                 :     NS_OVERRIDE
     274                 :     virtual nsresult BeginUpdateBackground(NPP instance,
     275                 :                                            const nsIntRect& aRect,
     276                 :                                            gfxContext** aCtx);
     277                 :     NS_OVERRIDE
     278                 :     virtual nsresult EndUpdateBackground(NPP instance,
     279                 :                                          gfxContext* aCtx,
     280                 :                                          const nsIntRect& aRect);
     281                 : 
     282                 : #if defined(XP_UNIX) && !defined(XP_MACOSX) && !defined(MOZ_WIDGET_GONK)
     283                 :     virtual nsresult NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs, NPError* error);
     284                 : #else
     285                 :     virtual nsresult NP_Initialize(NPNetscapeFuncs* bFuncs, NPError* error);
     286                 : #endif
     287                 :     virtual nsresult NP_Shutdown(NPError* error);
     288                 :     virtual nsresult NP_GetMIMEDescription(const char** mimeDesc);
     289                 :     virtual nsresult NP_GetValue(void *future, NPPVariable aVariable,
     290                 :                                  void *aValue, NPError* error);
     291                 : #if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_OS2)
     292                 :     virtual nsresult NP_GetEntryPoints(NPPluginFuncs* pFuncs, NPError* error);
     293                 : #endif
     294                 :     virtual nsresult NPP_New(NPMIMEType pluginType, NPP instance,
     295                 :                              uint16_t mode, int16_t argc, char* argn[],
     296                 :                              char* argv[], NPSavedData* saved,
     297                 :                              NPError* error);
     298                 :     virtual nsresult NPP_ClearSiteData(const char* site, uint64_t flags,
     299                 :                                        uint64_t maxAge);
     300                 :     virtual nsresult NPP_GetSitesWithData(InfallibleTArray<nsCString>& result);
     301                 : 
     302                 : #if defined(XP_MACOSX)
     303                 :     virtual nsresult IsRemoteDrawingCoreAnimation(NPP instance, bool *aDrawing);
     304                 : #endif
     305                 : #if defined(MOZ_WIDGET_QT) && (MOZ_PLATFORM_MAEMO == 6)
     306                 :     virtual nsresult HandleGUIEvent(NPP instance, const nsGUIEvent& anEvent,
     307                 :                                     bool* handled);
     308                 : #endif
     309                 : 
     310                 : private:
     311                 :     CrashReporterParent* CrashReporter();
     312                 : 
     313                 : #ifdef MOZ_CRASHREPORTER
     314                 :     void WriteExtraDataForMinidump(CrashReporter::AnnotationTable& notes);
     315                 : #endif
     316                 :     void CleanupFromTimeout();
     317                 :     static int TimeoutChanged(const char* aPref, void* aModule);
     318                 :     void NotifyPluginCrashed();
     319                 : 
     320                 :     PluginProcessParent* mSubprocess;
     321                 :     // the plugin thread in mSubprocess
     322                 :     NativeThreadId mPluginThread;
     323                 :     bool mShutdown;
     324                 :     bool mClearSiteDataSupported;
     325                 :     bool mGetSitesWithDataSupported;
     326                 :     const NPNetscapeFuncs* mNPNIface;
     327                 :     nsDataHashtable<nsVoidPtrHashKey, PluginIdentifierParent*> mIdentifiers;
     328                 :     nsNPAPIPlugin* mPlugin;
     329                 :     ScopedRunnableMethodFactory<PluginModuleParent> mTaskFactory;
     330                 :     nsString mPluginDumpID;
     331                 :     nsString mBrowserDumpID;
     332                 :     nsString mHangID;
     333                 : 
     334                 : #ifdef MOZ_X11
     335                 :     // Dup of plugin's X socket, used to scope its resources to this
     336                 :     // object instead of the plugin process's lifetime
     337                 :     ScopedClose mPluginXSocketFdDup;
     338                 : #endif
     339                 : 
     340                 :     friend class mozilla::dom::CrashReporterParent;
     341                 : };
     342                 : 
     343                 : } // namespace plugins
     344                 : } // namespace mozilla
     345                 : 
     346                 : #endif  // ifndef dom_plugins_PluginModuleParent_h

Generated by: LCOV version 1.7