1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Mozilla IPCShell.
15 : *
16 : * The Initial Developer of the Original Code is
17 : * Ben Turner <bent.mozilla@gmail.com>.
18 : * Portions created by the Initial Developer are Copyright (C) 2009
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 2 or later (the "GPL"), or
25 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 : * in which case the provisions of the GPL or the LGPL are applicable instead
27 : * of those above. If you wish to allow use of your version of this file only
28 : * under the terms of either the GPL or the LGPL, and not to allow others to
29 : * use your version of this file under the terms of the MPL, indicate your
30 : * decision by deleting the provisions above and replace them with the notice
31 : * and other provisions required by the GPL or the LGPL. If you do not delete
32 : * the provisions above, a recipient may use your version of this file under
33 : * the terms of any one of the MPL, the GPL or the LGPL.
34 : *
35 : * ***** END LICENSE BLOCK ***** */
36 :
37 : #ifndef _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
38 : #define _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
39 :
40 : #include "base/basictypes.h"
41 :
42 : #include <string>
43 : #include <stdio.h>
44 :
45 : #include "nsAutoJSValHolder.h"
46 : #include "nsCOMPtr.h"
47 : #include "nsDebug.h"
48 : #include "nsStringGlue.h"
49 :
50 : struct JSContext;
51 : struct JSObject;
52 : struct JSPrincipals;
53 :
54 : class nsIJSContextStack;
55 :
56 : namespace mozilla {
57 : namespace ipc {
58 :
59 : class XPCShellEnvironment
60 : {
61 : public:
62 : static XPCShellEnvironment* CreateEnvironment();
63 : ~XPCShellEnvironment();
64 :
65 : bool EvaluateString(const nsString& aString,
66 : nsString* aResult = nsnull);
67 :
68 : JSPrincipals* GetPrincipal() {
69 : return mJSPrincipals;
70 : }
71 :
72 : JSObject* GetGlobalObject() {
73 : return mGlobalHolder.ToJSObject();
74 : }
75 :
76 0 : JSContext* GetContext() {
77 0 : return mCx;
78 : }
79 :
80 : void SetExitCode(int aExitCode) {
81 : mExitCode = aExitCode;
82 : }
83 : int ExitCode() {
84 : return mExitCode;
85 : }
86 :
87 : void SetIsQuitting() {
88 : mQuitting = JS_TRUE;
89 : }
90 0 : JSBool IsQuitting() {
91 0 : return mQuitting;
92 : }
93 :
94 : void SetShouldReportWarnings(JSBool aReportWarnings) {
95 : mReportWarnings = aReportWarnings;
96 : }
97 : JSBool ShouldReportWarnings() {
98 : return mReportWarnings;
99 : }
100 :
101 : void SetShouldCompoleOnly(JSBool aCompileOnly) {
102 : mCompileOnly = aCompileOnly;
103 : }
104 : JSBool ShouldCompileOnly() {
105 : return mCompileOnly;
106 : }
107 :
108 : class AutoContextPusher
109 : {
110 : public:
111 : AutoContextPusher(XPCShellEnvironment* aEnv);
112 : ~AutoContextPusher();
113 : private:
114 : XPCShellEnvironment* mEnv;
115 : };
116 :
117 : protected:
118 : XPCShellEnvironment();
119 : bool Init();
120 :
121 : private:
122 : JSContext* mCx;
123 : nsAutoJSValHolder mGlobalHolder;
124 : nsCOMPtr<nsIJSContextStack> mCxStack;
125 : JSPrincipals* mJSPrincipals;
126 :
127 : int mExitCode;
128 : JSBool mQuitting;
129 : JSBool mReportWarnings;
130 : JSBool mCompileOnly;
131 : };
132 :
133 : } /* namespace ipc */
134 : } /* namespace mozilla */
135 :
136 : #endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */
|