ipc/testshell/XPCShellEnvironment.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/testshell/XPCShellEnvironment.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
     1.9 +#define _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_
    1.10 +
    1.11 +#include "base/basictypes.h"
    1.12 +
    1.13 +#include <string>
    1.14 +#include <stdio.h>
    1.15 +
    1.16 +#include "nsAutoJSValHolder.h"
    1.17 +#include "nsCOMPtr.h"
    1.18 +#include "nsDebug.h"
    1.19 +#include "nsString.h"
    1.20 +#include "nsJSPrincipals.h"
    1.21 +#include "nsContentUtils.h"
    1.22 +#include "js/TypeDecls.h"
    1.23 +
    1.24 +struct JSPrincipals;
    1.25 +
    1.26 +namespace mozilla {
    1.27 +namespace ipc {
    1.28 +
    1.29 +class XPCShellEnvironment
    1.30 +{
    1.31 +public:
    1.32 +    static XPCShellEnvironment* CreateEnvironment();
    1.33 +    ~XPCShellEnvironment();
    1.34 +
    1.35 +    void ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj,
    1.36 +                     const char *filename, FILE *file, bool forceTTY);
    1.37 +    bool EvaluateString(const nsString& aString,
    1.38 +                        nsString* aResult = nullptr);
    1.39 +
    1.40 +    JSPrincipals* GetPrincipal() {
    1.41 +        return nsJSPrincipals::get(nsContentUtils::GetSystemPrincipal());
    1.42 +    }
    1.43 +
    1.44 +    JSObject* GetGlobalObject() {
    1.45 +        return mGlobalHolder.ToJSObject();
    1.46 +    }
    1.47 +
    1.48 +    void SetIsQuitting() {
    1.49 +        mQuitting = true;
    1.50 +    }
    1.51 +    bool IsQuitting() {
    1.52 +        return mQuitting;
    1.53 +    }
    1.54 +
    1.55 +protected:
    1.56 +    XPCShellEnvironment();
    1.57 +    bool Init();
    1.58 +
    1.59 +private:
    1.60 +    nsAutoJSValHolder mGlobalHolder;
    1.61 +
    1.62 +    bool mQuitting;
    1.63 +};
    1.64 +
    1.65 +} /* namespace ipc */
    1.66 +} /* namespace mozilla */
    1.67 +
    1.68 +#endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */

mercurial