| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #if ENABLE(INSPECTOR) | |
| 34 | 33 |
| 35 #include "InspectorRuntimeAgent.h" | 34 #include "InspectorRuntimeAgent.h" |
| 36 | 35 |
| 37 #include "InjectedScript.h" | 36 #include "InjectedScript.h" |
| 38 #include "InjectedScriptManager.h" | 37 #include "InjectedScriptManager.h" |
| 39 #include "InspectorValues.h" | 38 #include "InspectorValues.h" |
| 40 #include <wtf/PassRefPtr.h> | 39 #include <wtf/PassRefPtr.h> |
| 41 | 40 |
| 42 | 41 |
| 43 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 44 #include "ScriptDebugServer.h" | 42 #include "ScriptDebugServer.h" |
| 45 #endif | |
| 46 | 43 |
| 47 namespace WebCore { | 44 namespace WebCore { |
| 48 | 45 |
| 49 static bool asBool(const bool* const b) | 46 static bool asBool(const bool* const b) |
| 50 { | 47 { |
| 51 return b ? *b : false; | 48 return b ? *b : false; |
| 52 } | 49 } |
| 53 | 50 |
| 54 InspectorRuntimeAgent::InspectorRuntimeAgent(InstrumentingAgents* instrumentingA
gents, InspectorCompositeState* state, InjectedScriptManager* injectedScriptMana
ger) | 51 InspectorRuntimeAgent::InspectorRuntimeAgent(InstrumentingAgents* instrumentingA
gents, InspectorCompositeState* state, InjectedScriptManager* injectedScriptMana
ger) |
| 55 : InspectorBaseAgent<InspectorRuntimeAgent>("Runtime", instrumentingAgents,
state) | 52 : InspectorBaseAgent<InspectorRuntimeAgent>("Runtime", instrumentingAgents,
state) |
| 56 , m_enabled(false) | 53 , m_enabled(false) |
| 57 , m_injectedScriptManager(injectedScriptManager) | 54 , m_injectedScriptManager(injectedScriptManager) |
| 58 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 59 , m_scriptDebugServer(0) | 55 , m_scriptDebugServer(0) |
| 60 #endif | |
| 61 { | 56 { |
| 62 } | 57 } |
| 63 | 58 |
| 64 InspectorRuntimeAgent::~InspectorRuntimeAgent() | 59 InspectorRuntimeAgent::~InspectorRuntimeAgent() |
| 65 { | 60 { |
| 66 } | 61 } |
| 67 | 62 |
| 68 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 69 static ScriptDebugServer::PauseOnExceptionsState setPauseOnExceptionsState(Scrip
tDebugServer* scriptDebugServer, ScriptDebugServer::PauseOnExceptionsState newSt
ate) | 63 static ScriptDebugServer::PauseOnExceptionsState setPauseOnExceptionsState(Scrip
tDebugServer* scriptDebugServer, ScriptDebugServer::PauseOnExceptionsState newSt
ate) |
| 70 { | 64 { |
| 71 ASSERT(scriptDebugServer); | 65 ASSERT(scriptDebugServer); |
| 72 ScriptDebugServer::PauseOnExceptionsState presentState = scriptDebugServer->
pauseOnExceptionsState(); | 66 ScriptDebugServer::PauseOnExceptionsState presentState = scriptDebugServer->
pauseOnExceptionsState(); |
| 73 if (presentState != newState) | 67 if (presentState != newState) |
| 74 scriptDebugServer->setPauseOnExceptionsState(newState); | 68 scriptDebugServer->setPauseOnExceptionsState(newState); |
| 75 return presentState; | 69 return presentState; |
| 76 } | 70 } |
| 77 #endif | |
| 78 | 71 |
| 79 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& exp
ression, const String* const objectGroup, const bool* const includeCommandLineAP
I, const bool* const doNotPauseOnExceptionsAndMuteConsole, const int* executionC
ontextId, const bool* const returnByValue, const bool* generatePreview, RefPtr<T
ypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThr
own) | 72 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& exp
ression, const String* const objectGroup, const bool* const includeCommandLineAP
I, const bool* const doNotPauseOnExceptionsAndMuteConsole, const int* executionC
ontextId, const bool* const returnByValue, const bool* generatePreview, RefPtr<T
ypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThr
own) |
| 80 { | 73 { |
| 81 InjectedScript injectedScript = injectedScriptForEval(errorString, execution
ContextId); | 74 InjectedScript injectedScript = injectedScriptForEval(errorString, execution
ContextId); |
| 82 if (injectedScript.hasNoValue()) | 75 if (injectedScript.hasNoValue()) |
| 83 return; | 76 return; |
| 84 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 85 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = S
criptDebugServer::DontPauseOnExceptions; | 77 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = S
criptDebugServer::DontPauseOnExceptions; |
| 86 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) | 78 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) |
| 87 previousPauseOnExceptionsState = setPauseOnExceptionsState(m_scriptDebug
Server, ScriptDebugServer::DontPauseOnExceptions); | 79 previousPauseOnExceptionsState = setPauseOnExceptionsState(m_scriptDebug
Server, ScriptDebugServer::DontPauseOnExceptions); |
| 88 #endif | |
| 89 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) | 80 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) |
| 90 muteConsole(); | 81 muteConsole(); |
| 91 | 82 |
| 92 injectedScript.evaluate(errorString, expression, objectGroup ? *objectGroup
: "", asBool(includeCommandLineAPI), asBool(returnByValue), asBool(generatePrevi
ew), &result, wasThrown); | 83 injectedScript.evaluate(errorString, expression, objectGroup ? *objectGroup
: "", asBool(includeCommandLineAPI), asBool(returnByValue), asBool(generatePrevi
ew), &result, wasThrown); |
| 93 | 84 |
| 94 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) { | 85 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) { |
| 95 unmuteConsole(); | 86 unmuteConsole(); |
| 96 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 97 setPauseOnExceptionsState(m_scriptDebugServer, previousPauseOnExceptions
State); | 87 setPauseOnExceptionsState(m_scriptDebugServer, previousPauseOnExceptions
State); |
| 98 #endif | |
| 99 } | 88 } |
| 100 } | 89 } |
| 101 | 90 |
| 102 void InspectorRuntimeAgent::callFunctionOn(ErrorString* errorString, const Strin
g& objectId, const String& expression, const RefPtr<InspectorArray>* const optio
nalArguments, const bool* const doNotPauseOnExceptionsAndMuteConsole, const bool
* const returnByValue, const bool* generatePreview, RefPtr<TypeBuilder::Runtime:
:RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) | 91 void InspectorRuntimeAgent::callFunctionOn(ErrorString* errorString, const Strin
g& objectId, const String& expression, const RefPtr<InspectorArray>* const optio
nalArguments, const bool* const doNotPauseOnExceptionsAndMuteConsole, const bool
* const returnByValue, const bool* generatePreview, RefPtr<TypeBuilder::Runtime:
:RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) |
| 103 { | 92 { |
| 104 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb
jectId(objectId); | 93 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb
jectId(objectId); |
| 105 if (injectedScript.hasNoValue()) { | 94 if (injectedScript.hasNoValue()) { |
| 106 *errorString = "Inspected frame has gone"; | 95 *errorString = "Inspected frame has gone"; |
| 107 return; | 96 return; |
| 108 } | 97 } |
| 109 String arguments; | 98 String arguments; |
| 110 if (optionalArguments) | 99 if (optionalArguments) |
| 111 arguments = (*optionalArguments)->toJSONString(); | 100 arguments = (*optionalArguments)->toJSONString(); |
| 112 | 101 |
| 113 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 114 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = S
criptDebugServer::DontPauseOnExceptions; | 102 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = S
criptDebugServer::DontPauseOnExceptions; |
| 115 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) | 103 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) |
| 116 previousPauseOnExceptionsState = setPauseOnExceptionsState(m_scriptDebug
Server, ScriptDebugServer::DontPauseOnExceptions); | 104 previousPauseOnExceptionsState = setPauseOnExceptionsState(m_scriptDebug
Server, ScriptDebugServer::DontPauseOnExceptions); |
| 117 #endif | |
| 118 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) | 105 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) |
| 119 muteConsole(); | 106 muteConsole(); |
| 120 | 107 |
| 121 injectedScript.callFunctionOn(errorString, objectId, expression, arguments,
asBool(returnByValue), asBool(generatePreview), &result, wasThrown); | 108 injectedScript.callFunctionOn(errorString, objectId, expression, arguments,
asBool(returnByValue), asBool(generatePreview), &result, wasThrown); |
| 122 | 109 |
| 123 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) { | 110 if (asBool(doNotPauseOnExceptionsAndMuteConsole)) { |
| 124 unmuteConsole(); | 111 unmuteConsole(); |
| 125 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 126 setPauseOnExceptionsState(m_scriptDebugServer, previousPauseOnExceptions
State); | 112 setPauseOnExceptionsState(m_scriptDebugServer, previousPauseOnExceptions
State); |
| 127 #endif | |
| 128 } | 113 } |
| 129 } | 114 } |
| 130 | 115 |
| 131 void InspectorRuntimeAgent::getProperties(ErrorString* errorString, const String
& objectId, const bool* const ownProperties, RefPtr<TypeBuilder::Array<TypeBuild
er::Runtime::PropertyDescriptor> >& result, RefPtr<TypeBuilder::Array<TypeBuilde
r::Runtime::InternalPropertyDescriptor> >& internalProperties) | 116 void InspectorRuntimeAgent::getProperties(ErrorString* errorString, const String
& objectId, const bool* const ownProperties, RefPtr<TypeBuilder::Array<TypeBuild
er::Runtime::PropertyDescriptor> >& result, RefPtr<TypeBuilder::Array<TypeBuilde
r::Runtime::InternalPropertyDescriptor> >& internalProperties) |
| 132 { | 117 { |
| 133 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb
jectId(objectId); | 118 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb
jectId(objectId); |
| 134 if (injectedScript.hasNoValue()) { | 119 if (injectedScript.hasNoValue()) { |
| 135 *errorString = "Inspected frame has gone"; | 120 *errorString = "Inspected frame has gone"; |
| 136 return; | 121 return; |
| 137 } | 122 } |
| 138 | 123 |
| 139 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 140 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = s
etPauseOnExceptionsState(m_scriptDebugServer, ScriptDebugServer::DontPauseOnExce
ptions); | 124 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = s
etPauseOnExceptionsState(m_scriptDebugServer, ScriptDebugServer::DontPauseOnExce
ptions); |
| 141 #endif | |
| 142 muteConsole(); | 125 muteConsole(); |
| 143 | 126 |
| 144 injectedScript.getProperties(errorString, objectId, ownProperties ? *ownProp
erties : false, &result); | 127 injectedScript.getProperties(errorString, objectId, ownProperties ? *ownProp
erties : false, &result); |
| 145 injectedScript.getInternalProperties(errorString, objectId, &internalPropert
ies); | 128 injectedScript.getInternalProperties(errorString, objectId, &internalPropert
ies); |
| 146 | 129 |
| 147 unmuteConsole(); | 130 unmuteConsole(); |
| 148 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 149 setPauseOnExceptionsState(m_scriptDebugServer, previousPauseOnExceptionsStat
e); | 131 setPauseOnExceptionsState(m_scriptDebugServer, previousPauseOnExceptionsStat
e); |
| 150 #endif | |
| 151 } | 132 } |
| 152 | 133 |
| 153 void InspectorRuntimeAgent::releaseObject(ErrorString*, const String& objectId) | 134 void InspectorRuntimeAgent::releaseObject(ErrorString*, const String& objectId) |
| 154 { | 135 { |
| 155 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb
jectId(objectId); | 136 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptForOb
jectId(objectId); |
| 156 if (!injectedScript.hasNoValue()) | 137 if (!injectedScript.hasNoValue()) |
| 157 injectedScript.releaseObject(objectId); | 138 injectedScript.releaseObject(objectId); |
| 158 } | 139 } |
| 159 | 140 |
| 160 void InspectorRuntimeAgent::releaseObjectGroup(ErrorString*, const String& objec
tGroup) | 141 void InspectorRuntimeAgent::releaseObjectGroup(ErrorString*, const String& objec
tGroup) |
| 161 { | 142 { |
| 162 m_injectedScriptManager->releaseObjectGroup(objectGroup); | 143 m_injectedScriptManager->releaseObjectGroup(objectGroup); |
| 163 } | 144 } |
| 164 | 145 |
| 165 void InspectorRuntimeAgent::run(ErrorString*) | 146 void InspectorRuntimeAgent::run(ErrorString*) |
| 166 { | 147 { |
| 167 } | 148 } |
| 168 | 149 |
| 169 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 170 void InspectorRuntimeAgent::setScriptDebugServer(ScriptDebugServer* scriptDebugS
erver) | 150 void InspectorRuntimeAgent::setScriptDebugServer(ScriptDebugServer* scriptDebugS
erver) |
| 171 { | 151 { |
| 172 m_scriptDebugServer = scriptDebugServer; | 152 m_scriptDebugServer = scriptDebugServer; |
| 173 } | 153 } |
| 174 #endif // ENABLE(JAVASCRIPT_DEBUGGER) | |
| 175 | 154 |
| 176 } // namespace WebCore | 155 } // namespace WebCore |
| 177 | 156 |
| 178 #endif // ENABLE(INSPECTOR) | |
| OLD | NEW |