OSDN Git Service

Merge WebKit at r84325: Initial merge by git.
[android-x86/external-webkit.git] / Source / WebCore / bindings / js / JSInjectedScriptHostCustom.cpp
1 /*
2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4  * Copyright (C) 2010-2011 Google Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following disclaimer
14  * in the documentation and/or other materials provided with the
15  * distribution.
16  *     * Neither the name of Google Inc. nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "config.h"
34 #include "JSInjectedScriptHost.h"
35
36 #if ENABLE(INSPECTOR)
37
38 #if ENABLE(DATABASE)
39 #include "Database.h"
40 #include "JSDatabase.h"
41 #endif
42 #include "ExceptionCode.h"
43 #include "InjectedScriptHost.h"
44 #include "InspectorDebuggerAgent.h"
45 #include "InspectorValues.h"
46 #include "JSNode.h"
47 #include "ScriptValue.h"
48 #if ENABLE(DOM_STORAGE)
49 #include "Storage.h"
50 #include "JSStorage.h"
51 #endif
52 #include <runtime/JSLock.h>
53
54 #if ENABLE(JAVASCRIPT_DEBUGGER)
55 #include "JavaScriptCallFrame.h"
56 #include "JSJavaScriptCallFrame.h"
57 #include "ScriptDebugServer.h"
58 #endif
59
60 using namespace JSC;
61
62 namespace WebCore {
63
64 Node* InjectedScriptHost::scriptValueAsNode(ScriptValue value)
65 {
66     if (!value.isObject() || value.isNull())
67         return 0;
68     return toNode(value.jsValue());
69 }
70
71 ScriptValue InjectedScriptHost::nodeAsScriptValue(ScriptState* state, Node* node)
72 {
73     JSLock lock(SilenceAssertionsOnly);
74     return ScriptValue(state->globalData(), toJS(state, node));
75 }
76
77 JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec)
78 {
79 #if ENABLE(JAVASCRIPT_DEBUGGER)
80     JavaScriptCallFrame* callFrame = impl()->debuggerAgent()->scriptDebugServer().currentCallFrame();
81     if (!callFrame || !callFrame->isValid())
82         return jsUndefined();
83
84     JSLock lock(SilenceAssertionsOnly);
85     return toJS(exec, callFrame);
86 #else
87     UNUSED_PARAM(exec);
88     return jsUndefined();
89 #endif
90 }
91
92 JSValue JSInjectedScriptHost::inspectedNode(ExecState* exec)
93 {
94     if (exec->argumentCount() < 1)
95         return jsUndefined();
96
97     Node* node = impl()->inspectedNode(exec->argument(0).toInt32(exec));
98     if (!node)
99         return jsUndefined();
100
101     JSLock lock(SilenceAssertionsOnly);
102     return toJS(exec, node);
103 }
104
105 JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
106 {
107     if (exec->argumentCount() < 1)
108         return jsUndefined();
109
110     UString result = exec->argument(0).toThisObject(exec)->className();
111     return jsString(exec, result);
112 }
113
114 JSValue JSInjectedScriptHost::inspect(ExecState* exec)
115 {
116     if (exec->argumentCount() >= 2) {
117         ScriptValue object(exec->globalData(), exec->argument(0));
118         ScriptValue hints(exec->globalData(), exec->argument(1));
119         impl()->inspectImpl(object.toInspectorValue(exec), hints.toInspectorValue(exec));
120     }
121     return jsUndefined();
122 }
123
124 JSValue JSInjectedScriptHost::databaseId(ExecState* exec)
125 {
126     if (exec->argumentCount() < 1)
127         return jsUndefined();
128 #if ENABLE(DATABASE)
129     Database* database = toDatabase(exec->argument(0));
130     if (database)
131         return jsNumber(impl()->databaseIdImpl(database));
132 #endif
133     return jsUndefined();
134 }
135
136 JSValue JSInjectedScriptHost::storageId(ExecState* exec)
137 {
138     if (exec->argumentCount() < 1)
139         return jsUndefined();
140 #if ENABLE(DOM_STORAGE)
141     Storage* storage = toStorage(exec->argument(0));
142     if (storage)
143         return jsNumber(impl()->storageIdImpl(storage));
144 #endif
145     return jsUndefined();
146 }
147
148 } // namespace WebCore
149
150 #endif // ENABLE(INSPECTOR)