1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
16 * The Original Code is Mozilla Plugin App.
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.
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef dom_plugins_PluginModuleParent_h
40 #define dom_plugins_PluginModuleParent_h 1
44 #include "base/basictypes.h"
49 #include "npfunctions.h"
51 #include "base/string_util.h"
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"
60 #include "nsAutoPtr.h"
61 #include "nsDataHashtable.h"
62 #include "nsHashKeys.h"
63 #include "nsIFileStreams.h"
64 #include "nsTObserverArray.h"
69 //-----------------------------------------------------------------------------
71 class BrowserStreamParent
;
76 * This class implements the NPP API from the perspective of the rest
77 * of Gecko, forwarding NPP calls along to the child process that is
78 * actually running the plugin.
80 * This class /also/ implements a version of the NPN API, because the
81 * child process needs to make these calls back into Gecko proper.
82 * This class is responsible for "actually" making those function calls.
84 class PluginModuleParent
: public PPluginModuleParent
, PluginLibrary
87 typedef mozilla::PluginLibrary PluginLibrary
;
91 virtual PPluginIdentifierParent
*
92 AllocPPluginIdentifier(const nsCString
& aString
,
96 DeallocPPluginIdentifier(PPluginIdentifierParent
* aActor
);
98 PPluginInstanceParent
*
99 AllocPPluginInstance(const nsCString
& aMimeType
,
100 const uint16_t& aMode
,
101 const InfallibleTArray
<nsCString
>& aNames
,
102 const InfallibleTArray
<nsCString
>& aValues
,
106 DeallocPPluginInstance(PPluginInstanceParent
* aActor
);
109 PluginModuleParent(const char* aFilePath
);
110 virtual ~PluginModuleParent();
112 NS_OVERRIDE
virtual void SetPlugin(nsNPAPIPlugin
* plugin
)
117 NS_OVERRIDE
virtual void ActorDestroy(ActorDestroyReason why
);
122 * This may or may not launch a plugin child process,
123 * and may or may not be very expensive.
125 static PluginLibrary
* LoadModule(const char* aFilePath
);
127 const NPNetscapeFuncs
* GetNetscapeFuncs() {
131 PluginProcessParent
* Process() const { return mSubprocess
; }
132 base::ProcessHandle
ChildProcessHandle() { return mSubprocess
->GetChildProcessHandle(); }
134 bool OkToCleanup() const {
135 return !IsOnCxxStack();
138 PPluginIdentifierParent
*
139 GetIdentifierForNPIdentifier(NPIdentifier aIdentifier
);
142 void AddToRefreshTimer(PluginInstanceParent
*aInstance
);
143 void RemoveFromRefreshTimer(PluginInstanceParent
*aInstance
);
148 virtual mozilla::ipc::RPCChannel::RacyRPCPolicy
149 MediateRPCRace(const Message
& parent
, const Message
& child
)
151 return MediateRace(parent
, child
);
154 virtual bool RecvXXX_HACK_FIXME_cjones(Shmem
& mem
) { NS_RUNTIMEABORT("not reached"); return false; }
157 virtual bool ShouldContinueFromReplyTimeout();
161 RecvBackUpXResources(const FileDescriptor
& aXSocketFd
);
164 AnswerNPN_UserAgent(nsCString
* userAgent
);
167 AnswerNPN_GetValue_WithBoolReturn(const NPNVariable
& aVariable
,
172 virtual bool AnswerProcessSomeEvents();
174 NS_OVERRIDE
virtual bool
175 RecvProcessNativeEventsInRPCCall();
178 RecvAppendNotesToCrashReport(const nsCString
& aNotes
);
180 NS_OVERRIDE
virtual bool
181 RecvPluginShowWindow(const uint32_t& aWindowId
, const bool& aModal
,
182 const int32_t& aX
, const int32_t& aY
,
183 const size_t& aWidth
, const size_t& aHeight
);
185 NS_OVERRIDE
virtual bool
186 RecvPluginHideWindow(const uint32_t& aWindowId
);
188 static PluginInstanceParent
* InstCast(NPP instance
);
189 static BrowserStreamParent
* StreamCast(NPP instance
, NPStream
* s
);
192 void SetPluginFuncs(NPPluginFuncs
* aFuncs
);
194 // Implement the module-level functions from NPAPI; these are
195 // normally resolved directly from the DSO.
197 NPError
NP_Initialize(const NPNetscapeFuncs
* npnIface
,
198 NPPluginFuncs
* nppIface
);
200 NPError
NP_Initialize(const NPNetscapeFuncs
* npnIface
);
201 NPError
NP_GetEntryPoints(NPPluginFuncs
* nppIface
);
204 // NPP-like API that Gecko calls are trampolined into. These
205 // messages then get forwarded along to the plugin instance,
206 // and then eventually the child process.
208 static NPError
NPP_Destroy(NPP instance
, NPSavedData
** save
);
210 static NPError
NPP_SetWindow(NPP instance
, NPWindow
* window
);
211 static NPError
NPP_NewStream(NPP instance
, NPMIMEType type
, NPStream
* stream
,
212 NPBool seekable
, uint16_t* stype
);
213 static NPError
NPP_DestroyStream(NPP instance
,
214 NPStream
* stream
, NPReason reason
);
215 static int32_t NPP_WriteReady(NPP instance
, NPStream
* stream
);
216 static int32_t NPP_Write(NPP instance
, NPStream
* stream
,
217 int32_t offset
, int32_t len
, void* buffer
);
218 static void NPP_StreamAsFile(NPP instance
,
219 NPStream
* stream
, const char* fname
);
220 static void NPP_Print(NPP instance
, NPPrint
* platformPrint
);
221 static int16_t NPP_HandleEvent(NPP instance
, void* event
);
222 static void NPP_URLNotify(NPP instance
, const char* url
,
223 NPReason reason
, void* notifyData
);
224 static NPError
NPP_GetValue(NPP instance
,
225 NPPVariable variable
, void *ret_value
);
226 static NPError
NPP_SetValue(NPP instance
, NPNVariable variable
,
229 virtual bool HasRequiredFunctions();
230 virtual nsresult
AsyncSetWindow(NPP instance
, NPWindow
* window
);
231 virtual nsresult
GetSurface(NPP instance
, gfxASurface
** aSurface
);
232 NS_OVERRIDE
virtual bool UseAsyncPainting() { return true; }
234 #if defined(XP_UNIX) && !defined(XP_MACOSX)
235 virtual nsresult
NP_Initialize(NPNetscapeFuncs
* bFuncs
, NPPluginFuncs
* pFuncs
, NPError
* error
);
237 virtual nsresult
NP_Initialize(NPNetscapeFuncs
* bFuncs
, NPError
* error
);
239 virtual nsresult
NP_Shutdown(NPError
* error
);
240 virtual nsresult
NP_GetMIMEDescription(const char** mimeDesc
);
241 virtual nsresult
NP_GetValue(void *future
, NPPVariable aVariable
,
242 void *aValue
, NPError
* error
);
243 #if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_OS2)
244 virtual nsresult
NP_GetEntryPoints(NPPluginFuncs
* pFuncs
, NPError
* error
);
246 virtual nsresult
NPP_New(NPMIMEType pluginType
, NPP instance
,
247 uint16_t mode
, int16_t argc
, char* argn
[],
248 char* argv
[], NPSavedData
* saved
,
251 void WritePluginExtraDataForMinidump(const nsAString
& id
);
252 void WriteExtraDataForHang();
253 void CleanupFromTimeout();
254 static int TimeoutChanged(const char* aPref
, void* aModule
);
255 void NotifyPluginCrashed();
257 nsCString mCrashNotes
;
258 PluginProcessParent
* mSubprocess
;
259 // the plugin thread in mSubprocess
260 NativeThreadId mPluginThread
;
262 const NPNetscapeFuncs
* mNPNIface
;
263 nsDataHashtable
<nsVoidPtrHashKey
, PluginIdentifierParent
*> mIdentifiers
;
264 nsNPAPIPlugin
* mPlugin
;
265 time_t mProcessStartTime
;
266 ScopedRunnableMethodFactory
<PluginModuleParent
> mTaskFactory
;
267 nsString mPluginDumpID
;
268 nsString mBrowserDumpID
;
272 nsCOMPtr
<nsITimer
> mCATimer
;
273 nsTObserverArray
<PluginInstanceParent
*> mCATimerTargets
;
277 // Dup of plugin's X socket, used to scope its resources to this
278 // object instead of the plugin process's lifetime
279 ScopedClose mPluginXSocketFdDup
;
283 } // namespace plugins
284 } // namespace mozilla
286 #endif // ifndef dom_plugins_PluginModuleParent_h