|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ |
|
6 #define _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ |
|
7 |
|
8 #include "base/basictypes.h" |
|
9 |
|
10 #include <string> |
|
11 #include <stdio.h> |
|
12 |
|
13 #include "nsAutoJSValHolder.h" |
|
14 #include "nsCOMPtr.h" |
|
15 #include "nsDebug.h" |
|
16 #include "nsString.h" |
|
17 #include "nsJSPrincipals.h" |
|
18 #include "nsContentUtils.h" |
|
19 #include "js/TypeDecls.h" |
|
20 |
|
21 struct JSPrincipals; |
|
22 |
|
23 namespace mozilla { |
|
24 namespace ipc { |
|
25 |
|
26 class XPCShellEnvironment |
|
27 { |
|
28 public: |
|
29 static XPCShellEnvironment* CreateEnvironment(); |
|
30 ~XPCShellEnvironment(); |
|
31 |
|
32 void ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj, |
|
33 const char *filename, FILE *file, bool forceTTY); |
|
34 bool EvaluateString(const nsString& aString, |
|
35 nsString* aResult = nullptr); |
|
36 |
|
37 JSPrincipals* GetPrincipal() { |
|
38 return nsJSPrincipals::get(nsContentUtils::GetSystemPrincipal()); |
|
39 } |
|
40 |
|
41 JSObject* GetGlobalObject() { |
|
42 return mGlobalHolder.ToJSObject(); |
|
43 } |
|
44 |
|
45 void SetIsQuitting() { |
|
46 mQuitting = true; |
|
47 } |
|
48 bool IsQuitting() { |
|
49 return mQuitting; |
|
50 } |
|
51 |
|
52 protected: |
|
53 XPCShellEnvironment(); |
|
54 bool Init(); |
|
55 |
|
56 private: |
|
57 nsAutoJSValHolder mGlobalHolder; |
|
58 |
|
59 bool mQuitting; |
|
60 }; |
|
61 |
|
62 } /* namespace ipc */ |
|
63 } /* namespace mozilla */ |
|
64 |
|
65 #endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */ |