bug 313956: expand installer .exe contents to make complete mar. r=ted.
[gecko.git] / ipc / testshell / XPCShellEnvironment.h
blob7f8297f5b604d613b15b8c0b2a6606e15d9b8f83
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 * The Original Code is Mozilla IPCShell.
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.
21 * Contributor(s):
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.
35 * ***** END LICENSE BLOCK ***** */
37 #ifndef _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
38 #define _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
40 #include "base/basictypes.h"
42 #include <string>
43 #include <stdio.h>
45 #include "nsAutoJSValHolder.h"
46 #include "nsCOMPtr.h"
47 #include "nsDebug.h"
48 #include "nsStringGlue.h"
50 struct JSContext;
51 struct JSObject;
52 struct JSPrincipals;
54 class nsIJSContextStack;
56 namespace mozilla {
57 namespace ipc {
59 class XPCShellEnvironment
61 public:
62 static XPCShellEnvironment* CreateEnvironment();
63 ~XPCShellEnvironment();
65 bool EvaluateString(const nsString& aString,
66 nsString* aResult = nsnull);
68 JSPrincipals* GetPrincipal() {
69 return mJSPrincipals;
72 JSObject* GetGlobalObject() {
73 return mGlobalHolder.ToJSObject();
76 JSContext* GetContext() {
77 return mCx;
80 void SetExitCode(int aExitCode) {
81 mExitCode = aExitCode;
83 int ExitCode() {
84 return mExitCode;
87 void SetIsQuitting() {
88 mQuitting = JS_TRUE;
90 JSBool IsQuitting() {
91 return mQuitting;
94 void SetShouldReportWarnings(JSBool aReportWarnings) {
95 mReportWarnings = aReportWarnings;
97 JSBool ShouldReportWarnings() {
98 return mReportWarnings;
101 void SetShouldCompoleOnly(JSBool aCompileOnly) {
102 mCompileOnly = aCompileOnly;
104 JSBool ShouldCompileOnly() {
105 return mCompileOnly;
108 class AutoContextPusher
110 public:
111 AutoContextPusher(XPCShellEnvironment* aEnv);
112 ~AutoContextPusher();
113 private:
114 XPCShellEnvironment* mEnv;
117 protected:
118 XPCShellEnvironment();
119 bool Init();
121 private:
122 JSContext* mCx;
123 nsAutoJSValHolder mGlobalHolder;
124 nsCOMPtr<nsIJSContextStack> mCxStack;
125 JSPrincipals* mJSPrincipals;
127 int mExitCode;
128 JSBool mQuitting;
129 JSBool mReportWarnings;
130 JSBool mCompileOnly;
133 } /* namespace ipc */
134 } /* namespace mozilla */
136 #endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */