Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / base / src / nsPluginSafety.h
blobc656c69dbf8c464f3cbdbea1868669272e831940
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsPluginSafety_h__
39 #define nsPluginSafety_h__
41 #include "npapi.h"
42 #include "nsIPluginHost.h"
43 #include "nsIPrefBranch.h"
44 #include "nsIPrefService.h"
45 #include <prinrval.h>
47 #if defined(XP_WIN) && !defined(WINCE)
48 #define CALL_SAFETY_ON
49 #endif
51 void NS_NotifyPluginCall(PRIntervalTime);
53 #ifdef CALL_SAFETY_ON
55 extern PRBool gSkipPluginSafeCalls;
57 #define NS_INIT_PLUGIN_SAFE_CALLS \
58 PR_BEGIN_MACRO \
59 nsresult res; \
60 nsCOMPtr<nsIPrefBranch> pref(do_GetService(NS_PREFSERVICE_CONTRACTID, &res)); \
61 if(NS_SUCCEEDED(res) && pref) \
62 res = pref->GetBoolPref("plugin.dont_try_safe_calls", &gSkipPluginSafeCalls);\
63 PR_END_MACRO
65 #define NS_TRY_SAFE_CALL_RETURN(ret, fun, library, pluginInst) \
66 PR_BEGIN_MACRO \
67 PRIntervalTime startTime = PR_IntervalNow(); \
68 if(gSkipPluginSafeCalls) \
69 ret = fun; \
70 else \
71 { \
72 try \
73 { \
74 ret = fun; \
75 } \
76 catch(...) \
77 { \
78 nsresult res; \
79 nsCOMPtr<nsIPluginHost> host(do_GetService(kCPluginManagerCID, &res));\
80 if(NS_SUCCEEDED(res) && (host != nsnull)) \
81 host->HandleBadPlugin(library, pluginInst);\
82 ret = (NPError)NS_ERROR_FAILURE; \
83 } \
84 } \
85 NS_NotifyPluginCall(startTime); \
86 PR_END_MACRO
88 #define NS_TRY_SAFE_CALL_VOID(fun, library, pluginInst) \
89 PR_BEGIN_MACRO \
90 PRIntervalTime startTime = PR_IntervalNow(); \
91 if(gSkipPluginSafeCalls) \
92 fun; \
93 else \
94 { \
95 try \
96 { \
97 fun; \
98 } \
99 catch(...) \
101 nsresult res; \
102 nsCOMPtr<nsIPluginHost> host(do_GetService(kCPluginManagerCID, &res));\
103 if(NS_SUCCEEDED(res) && (host != nsnull))\
104 host->HandleBadPlugin(library, pluginInst);\
107 NS_NotifyPluginCall(startTime); \
108 PR_END_MACRO
110 #else // vanilla calls
112 #define NS_TRY_SAFE_CALL_RETURN(ret, fun, library, pluginInst) \
113 PR_BEGIN_MACRO \
114 PRIntervalTime startTime = PR_IntervalNow(); \
115 ret = fun; \
116 NS_NotifyPluginCall(startTime); \
117 PR_END_MACRO
119 #define NS_TRY_SAFE_CALL_VOID(fun, library, pluginInst) \
120 PR_BEGIN_MACRO \
121 PRIntervalTime startTime = PR_IntervalNow(); \
122 fun; \
123 NS_NotifyPluginCall(startTime); \
124 PR_END_MACRO
126 #endif // CALL_SAFETY_ON
128 #endif //nsPluginSafety_h__