XPCShellEnvironment.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #ifndef _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
  5. #define _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
  6. #include "base/basictypes.h"
  7. #include <string>
  8. #include <stdio.h>
  9. #include "nsCOMPtr.h"
  10. #include "nsDebug.h"
  11. #include "nsString.h"
  12. #include "nsJSPrincipals.h"
  13. #include "nsContentUtils.h"
  14. #include "js/RootingAPI.h"
  15. #include "js/TypeDecls.h"
  16. struct JSPrincipals;
  17. namespace mozilla {
  18. namespace ipc {
  19. class XPCShellEnvironment
  20. {
  21. public:
  22. static XPCShellEnvironment* CreateEnvironment();
  23. ~XPCShellEnvironment();
  24. void ProcessFile(JSContext *cx, const char *filename, FILE *file, bool forceTTY);
  25. bool EvaluateString(const nsString& aString,
  26. nsString* aResult = nullptr);
  27. JSPrincipals* GetPrincipal() {
  28. return nsJSPrincipals::get(nsContentUtils::GetSystemPrincipal());
  29. }
  30. JSObject* GetGlobalObject() {
  31. return mGlobalHolder;
  32. }
  33. void SetIsQuitting() {
  34. mQuitting = true;
  35. }
  36. bool IsQuitting() {
  37. return mQuitting;
  38. }
  39. protected:
  40. XPCShellEnvironment();
  41. bool Init();
  42. private:
  43. JS::PersistentRooted<JSObject *> mGlobalHolder;
  44. bool mQuitting;
  45. };
  46. } /* namespace ipc */
  47. } /* namespace mozilla */
  48. #endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */