1635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project/*
28f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * Copyright (C) 2009 Google Inc. All rights reserved.
38f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
4635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Redistribution and use in source and binary forms, with or without
5635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * modification, are permitted provided that the following conditions are
6635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * met:
78f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
8635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions of source code must retain the above copyright
9635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * notice, this list of conditions and the following disclaimer.
10635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions in binary form must reproduce the above
11635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * copyright notice, this list of conditions and the following disclaimer
12635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * in the documentation and/or other materials provided with the
13635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * distribution.
14635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Neither the name of Google Inc. nor the names of its
15635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * contributors may be used to endorse or promote products derived from
16635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * this software without specific prior written permission.
178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
18635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project */
30635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
318f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#ifndef ScriptObject_h
328f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#define ScriptObject_h
33635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
345f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#include "ScriptState.h"
358f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include "ScriptValue.h"
36635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
378f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include <runtime/JSObject.h>
388f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#include <runtime/Protect.h>
39635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
40635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Projectnamespace WebCore {
41643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    class InjectedScriptHost;
420bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    class InspectorBackend;
43643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    class InspectorFrontendHost;
44635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
458f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    class ScriptObject : public ScriptValue {
468f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    public:
470bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        ScriptObject(ScriptState*, JSC::JSObject*);
488f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        ScriptObject() {}
498f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian        JSC::JSObject* jsObject() const { return asObject(jsValue()); }
50d0825bca7fe65beaee391d30da42e937db621564Steve Block        ScriptState* scriptState() const { return m_scriptState; }
515f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
520bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const String& name, const String&);
530bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const char* name, const ScriptObject&);
540bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const char* name, const String&);
550bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const char* name, double);
56643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        bool set(const char* name, long);
570bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const char* name, long long);
580bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const char* name, int);
59231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        bool set(const char* name, unsigned);
60643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        bool set(const char* name, unsigned long);
610bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        bool set(const char* name, bool);
625f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
635f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        static ScriptObject createNew(ScriptState*);
640bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch
650bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch    protected:
660bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        ScriptState* m_scriptState;
675f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    };
685f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian
695f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    class ScriptGlobalObject {
705f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    public:
715f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        static bool set(ScriptState*, const char* name, const ScriptObject&);
72231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#if ENABLE(INSPECTOR)
730bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch        static bool set(ScriptState*, const char* name, InspectorBackend*);
74643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        static bool set(ScriptState*, const char* name, InspectorFrontendHost*);
75643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        static bool set(ScriptState*, const char* name, InjectedScriptHost*);
76231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#endif
775f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        static bool get(ScriptState*, const char* name, ScriptObject&);
785f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        static bool remove(ScriptState*, const char* name);
795f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    private:
805f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian        ScriptGlobalObject() { }
818f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian    };
82635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
838f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian}
84635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
858f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian#endif // ScriptObject_h
86