| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2009 Google Inc. All rights reserved. | 4 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include "Database.h" | 40 #include "Database.h" |
| 41 #include "JSDatabase.h" | 41 #include "JSDatabase.h" |
| 42 #endif | 42 #endif |
| 43 #include "ExceptionCode.h" | 43 #include "ExceptionCode.h" |
| 44 #include "Frame.h" | 44 #include "Frame.h" |
| 45 #include "FrameLoader.h" | 45 #include "FrameLoader.h" |
| 46 #include "InjectedScriptHost.h" | 46 #include "InjectedScriptHost.h" |
| 47 #include "InspectorController.h" | 47 #include "InspectorController.h" |
| 48 #include "InspectorResource.h" | 48 #include "InspectorResource.h" |
| 49 #include "JSDOMWindow.h" | 49 #include "JSDOMWindow.h" |
| 50 #include "JSInspectedObjectWrapper.h" | |
| 51 #include "JSInspectorCallbackWrapper.h" | |
| 52 #include "JSNode.h" | 50 #include "JSNode.h" |
| 53 #include "JSRange.h" | 51 #include "JSRange.h" |
| 54 #include "Node.h" | 52 #include "Node.h" |
| 55 #include "Page.h" | 53 #include "Page.h" |
| 56 #if ENABLE(DOM_STORAGE) | 54 #if ENABLE(DOM_STORAGE) |
| 57 #include "Storage.h" | 55 #include "Storage.h" |
| 58 #include "JSStorage.h" | 56 #include "JSStorage.h" |
| 59 #endif | 57 #endif |
| 60 #include "TextIterator.h" | 58 #include "TextIterator.h" |
| 61 #include "VisiblePosition.h" | 59 #include "VisiblePosition.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (args.size() < 1) | 103 if (args.size() < 1) |
| 106 return jsUndefined(); | 104 return jsUndefined(); |
| 107 | 105 |
| 108 InspectorController* ic = impl()->inspectorController(); | 106 InspectorController* ic = impl()->inspectorController(); |
| 109 if (!ic) | 107 if (!ic) |
| 110 return jsUndefined(); | 108 return jsUndefined(); |
| 111 | 109 |
| 112 Database* database = impl()->databaseForId(args.at(0).toInt32(exec)); | 110 Database* database = impl()->databaseForId(args.at(0).toInt32(exec)); |
| 113 if (!database) | 111 if (!database) |
| 114 return jsUndefined(); | 112 return jsUndefined(); |
| 115 // Could use currentWorld(exec) ... but which exec! The following mixed use
of exec & inspectedWindow->globalExec() scares me! | 113 return toJS(exec, database); |
| 116 JSDOMWindow* inspectedWindow = toJSDOMWindow(ic->inspectedPage()->mainFrame(
), debuggerWorld()); | |
| 117 return JSInspectedObjectWrapper::wrap(inspectedWindow->globalExec(), toJS(ex
ec, database)); | |
| 118 } | 114 } |
| 119 #endif | 115 #endif |
| 120 | 116 |
| 121 JSValue JSInjectedScriptHost::inspectedWindow(ExecState*, const ArgList&) | |
| 122 { | |
| 123 InspectorController* ic = impl()->inspectorController(); | |
| 124 if (!ic) | |
| 125 return jsUndefined(); | |
| 126 JSDOMWindow* inspectedWindow = toJSDOMWindow(ic->inspectedPage()->mainFrame(
), debuggerWorld()); | |
| 127 return JSInspectedObjectWrapper::wrap(inspectedWindow->globalExec(), inspect
edWindow); | |
| 128 } | |
| 129 | |
| 130 JSValue JSInjectedScriptHost::wrapCallback(ExecState* exec, const ArgList& args) | |
| 131 { | |
| 132 if (args.size() < 1) | |
| 133 return jsUndefined(); | |
| 134 | |
| 135 return JSInspectorCallbackWrapper::wrap(exec, args.at(0)); | |
| 136 } | |
| 137 | |
| 138 #if ENABLE(JAVASCRIPT_DEBUGGER) | 117 #if ENABLE(JAVASCRIPT_DEBUGGER) |
| 139 | 118 |
| 140 JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec, const ArgList&) | 119 JSValue JSInjectedScriptHost::currentCallFrame(ExecState* exec, const ArgList&) |
| 141 { | 120 { |
| 142 JavaScriptCallFrame* callFrame = impl()->currentCallFrame(); | 121 JavaScriptCallFrame* callFrame = impl()->currentCallFrame(); |
| 143 if (!callFrame || !callFrame->isValid()) | 122 if (!callFrame || !callFrame->isValid()) |
| 144 return jsUndefined(); | 123 return jsUndefined(); |
| 145 | 124 |
| 146 // FIXME: I am not sure if this is actually needed. Can we just use exec? | |
| 147 ExecState* globalExec = callFrame->scopeChain()->globalObject->globalExec(); | |
| 148 | |
| 149 JSLock lock(SilenceAssertionsOnly); | 125 JSLock lock(SilenceAssertionsOnly); |
| 150 return JSInspectedObjectWrapper::wrap(globalExec, toJS(exec, callFrame)); | 126 return toJS(exec, callFrame); |
| 151 } | 127 } |
| 152 | 128 |
| 153 #endif | 129 #endif |
| 154 | 130 |
| 155 JSValue JSInjectedScriptHost::nodeForId(ExecState* exec, const ArgList& args) | 131 JSValue JSInjectedScriptHost::nodeForId(ExecState* exec, const ArgList& args) |
| 156 { | 132 { |
| 157 if (args.size() < 1) | 133 if (args.size() < 1) |
| 158 return jsUndefined(); | 134 return jsUndefined(); |
| 159 | 135 |
| 160 Node* node = impl()->nodeForId(args.at(0).toInt32(exec)); | 136 Node* node = impl()->nodeForId(args.at(0).toInt32(exec)); |
| 161 if (!node) | 137 if (!node) |
| 162 return jsUndefined(); | 138 return jsUndefined(); |
| 163 | 139 |
| 164 InspectorController* ic = impl()->inspectorController(); | 140 InspectorController* ic = impl()->inspectorController(); |
| 165 if (!ic) | 141 if (!ic) |
| 166 return jsUndefined(); | 142 return jsUndefined(); |
| 167 | 143 |
| 168 JSLock lock(SilenceAssertionsOnly); | 144 JSLock lock(SilenceAssertionsOnly); |
| 169 JSDOMWindow* inspectedWindow = toJSDOMWindow(ic->inspectedPage()->mainFrame(
), debuggerWorld()); | 145 return toJS(exec, node); |
| 170 return JSInspectedObjectWrapper::wrap(inspectedWindow->globalExec(), toJS(ex
ec, deprecatedGlobalObjectForPrototype(inspectedWindow->globalExec()), node)); | |
| 171 } | |
| 172 | |
| 173 JSValue JSInjectedScriptHost::wrapObject(ExecState* exec, const ArgList& args) | |
| 174 { | |
| 175 if (args.size() < 2) | |
| 176 return jsUndefined(); | |
| 177 | |
| 178 return impl()->wrapObject(ScriptValue(args.at(0)), args.at(1).toString(exec)
).jsValue(); | |
| 179 } | |
| 180 | |
| 181 JSValue JSInjectedScriptHost::unwrapObject(ExecState* exec, const ArgList& args) | |
| 182 { | |
| 183 if (args.size() < 1) | |
| 184 return jsUndefined(); | |
| 185 | |
| 186 return impl()->unwrapObject(args.at(0).toString(exec)).jsValue(); | |
| 187 } | 146 } |
| 188 | 147 |
| 189 JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec, const ArgL
ist& args) | 148 JSValue JSInjectedScriptHost::pushNodePathToFrontend(ExecState* exec, const ArgL
ist& args) |
| 190 { | 149 { |
| 191 if (args.size() < 3) | 150 if (args.size() < 3) |
| 192 return jsUndefined(); | 151 return jsUndefined(); |
| 193 | 152 |
| 194 JSQuarantinedObjectWrapper* wrapper = JSQuarantinedObjectWrapper::asWrapper(
args.at(0)); | 153 Node* node = toNode(args.at(0)); |
| 195 if (!wrapper) | |
| 196 return jsUndefined(); | |
| 197 | |
| 198 Node* node = toNode(wrapper->unwrappedObject()); | |
| 199 if (!node) | 154 if (!node) |
| 200 return jsUndefined(); | 155 return jsUndefined(); |
| 201 | 156 |
| 202 bool withChildren = args.at(1).toBoolean(exec); | 157 bool withChildren = args.at(1).toBoolean(exec); |
| 203 bool selectInUI = args.at(2).toBoolean(exec); | 158 bool selectInUI = args.at(2).toBoolean(exec); |
| 204 return jsNumber(exec, impl()->pushNodePathToFrontend(node, withChildren, sel
ectInUI)); | 159 return jsNumber(exec, impl()->pushNodePathToFrontend(node, withChildren, sel
ectInUI)); |
| 205 } | 160 } |
| 206 | 161 |
| 207 #if ENABLE(DATABASE) | 162 #if ENABLE(DATABASE) |
| 208 JSValue JSInjectedScriptHost::selectDatabase(ExecState*, const ArgList& args) | 163 JSValue JSInjectedScriptHost::selectDatabase(ExecState*, const ArgList& args) |
| 209 { | 164 { |
| 210 if (args.size() < 1) | 165 if (args.size() < 1) |
| 211 return jsUndefined(); | 166 return jsUndefined(); |
| 212 | 167 |
| 213 JSQuarantinedObjectWrapper* wrapper = JSQuarantinedObjectWrapper::asWrapper(
args.at(0)); | 168 Database* database = toDatabase(args.at(0)); |
| 214 if (!wrapper) | |
| 215 return jsUndefined(); | |
| 216 | |
| 217 Database* database = toDatabase(wrapper->unwrappedObject()); | |
| 218 if (database) | 169 if (database) |
| 219 impl()->selectDatabase(database); | 170 impl()->selectDatabase(database); |
| 220 return jsUndefined(); | 171 return jsUndefined(); |
| 221 } | 172 } |
| 222 #endif | 173 #endif |
| 223 | 174 |
| 224 #if ENABLE(DOM_STORAGE) | 175 #if ENABLE(DOM_STORAGE) |
| 225 JSValue JSInjectedScriptHost::selectDOMStorage(ExecState*, const ArgList& args) | 176 JSValue JSInjectedScriptHost::selectDOMStorage(ExecState*, const ArgList& args) |
| 226 { | 177 { |
| 227 if (args.size() < 1) | 178 if (args.size() < 1) |
| 228 return jsUndefined(); | 179 return jsUndefined(); |
| 229 InspectorController* ic = impl()->inspectorController(); | 180 InspectorController* ic = impl()->inspectorController(); |
| 230 if (!ic) | 181 if (!ic) |
| 231 return jsUndefined(); | 182 return jsUndefined(); |
| 232 | 183 |
| 233 JSQuarantinedObjectWrapper* wrapper = JSQuarantinedObjectWrapper::asWrapper(
args.at(0)); | 184 Storage* storage = toStorage(args.at(0)); |
| 234 if (!wrapper) | |
| 235 return jsUndefined(); | |
| 236 | |
| 237 Storage* storage = toStorage(wrapper->unwrappedObject()); | |
| 238 if (storage) | 185 if (storage) |
| 239 impl()->selectDOMStorage(storage); | 186 impl()->selectDOMStorage(storage); |
| 240 return jsUndefined(); | 187 return jsUndefined(); |
| 241 } | 188 } |
| 242 #endif | 189 #endif |
| 243 | 190 |
| 244 ScriptObject InjectedScriptHost::injectedScriptFor(ScriptState* scriptState) | 191 ScriptObject InjectedScriptHost::injectedScriptFor(ScriptState* scriptState) |
| 245 { | 192 { |
| 246 JSLock lock(SilenceAssertionsOnly); | 193 JSLock lock(SilenceAssertionsOnly); |
| 247 JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptStat
e->lexicalGlobalObject()); | 194 JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptStat
e->lexicalGlobalObject()); |
| 248 JSObject* injectedScript = globalObject->injectedScript(); | 195 JSObject* injectedScript = globalObject->injectedScript(); |
| 249 if (injectedScript) | 196 if (injectedScript) |
| 250 return ScriptObject(scriptState, injectedScript); | 197 return ScriptObject(scriptState, injectedScript); |
| 251 | 198 |
| 252 ASSERT(!m_injectedScriptSource.isEmpty()); | 199 ASSERT(!m_injectedScriptSource.isEmpty()); |
| 253 ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSou
rce, this, scriptState, m_nextInjectedScriptId); | 200 ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSou
rce, this, scriptState, m_nextInjectedScriptId); |
| 254 globalObject->setInjectedScript(injectedScriptObject.jsObject()); | 201 globalObject->setInjectedScript(injectedScriptObject.jsObject()); |
| 255 m_idToInjectedScript.set(m_nextInjectedScriptId, injectedScriptObject); | 202 m_idToInjectedScript.set(m_nextInjectedScriptId, injectedScriptObject); |
| 256 m_nextInjectedScriptId++; | 203 m_nextInjectedScriptId++; |
| 257 return injectedScriptObject; | 204 return injectedScriptObject; |
| 258 } | 205 } |
| 259 | 206 |
| 260 } // namespace WebCore | 207 } // namespace WebCore |
| 261 | 208 |
| 262 #endif // ENABLE(INSPECTOR) | 209 #endif // ENABLE(INSPECTOR) |
| OLD | NEW |