Commit d283b776 authored by aandrey@chromium.org's avatar aandrey@chromium.org

DevTools: Blackbox content scripts - backend support.

BUG=160207
R=vsevik, yurys@chromium.org

Review URL: https://codereview.chromium.org/547603003

git-svn-id: svn://svn.chromium.org/blink/trunk@181561 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 49879cc6
...@@ -86,6 +86,7 @@ static const char columnNumber[] = "columnNumber"; ...@@ -86,6 +86,7 @@ static const char columnNumber[] = "columnNumber";
static const char condition[] = "condition"; static const char condition[] = "condition";
static const char isAnti[] = "isAnti"; static const char isAnti[] = "isAnti";
static const char skipStackPattern[] = "skipStackPattern"; static const char skipStackPattern[] = "skipStackPattern";
static const char skipContentScripts[] = "skipContentScripts";
static const char skipAllPauses[] = "skipAllPauses"; static const char skipAllPauses[] = "skipAllPauses";
static const char skipAllPausesExpiresOnReload[] = "skipAllPausesExpiresOnReload"; static const char skipAllPausesExpiresOnReload[] = "skipAllPausesExpiresOnReload";
...@@ -125,6 +126,7 @@ InspectorDebuggerAgent::InspectorDebuggerAgent(InjectedScriptManager* injectedSc ...@@ -125,6 +126,7 @@ InspectorDebuggerAgent::InspectorDebuggerAgent(InjectedScriptManager* injectedSc
, m_listener(nullptr) , m_listener(nullptr)
, m_skippedStepInCount(0) , m_skippedStepInCount(0)
, m_skipAllPauses(false) , m_skipAllPauses(false)
, m_skipContentScripts(false)
, m_asyncCallStackTracker(adoptPtrWillBeNoop(new AsyncCallStackTracker())) , m_asyncCallStackTracker(adoptPtrWillBeNoop(new AsyncCallStackTracker()))
{ {
} }
...@@ -160,6 +162,7 @@ void InspectorDebuggerAgent::disable() ...@@ -160,6 +162,7 @@ void InspectorDebuggerAgent::disable()
m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, JSONObject::create()); m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, JSONObject::create());
m_state->setLong(DebuggerAgentState::pauseOnExceptionsState, ScriptDebugServer::DontPauseOnExceptions); m_state->setLong(DebuggerAgentState::pauseOnExceptionsState, ScriptDebugServer::DontPauseOnExceptions);
m_state->setString(DebuggerAgentState::skipStackPattern, ""); m_state->setString(DebuggerAgentState::skipStackPattern, "");
m_state->setBoolean(DebuggerAgentState::skipContentScripts, false);
m_state->setLong(DebuggerAgentState::asyncCallStackDepth, 0); m_state->setLong(DebuggerAgentState::asyncCallStackDepth, 0);
m_instrumentingAgents->setInspectorDebuggerAgent(0); m_instrumentingAgents->setInspectorDebuggerAgent(0);
...@@ -219,6 +222,7 @@ void InspectorDebuggerAgent::restore() ...@@ -219,6 +222,7 @@ void InspectorDebuggerAgent::restore()
String error; String error;
setPauseOnExceptionsImpl(&error, pauseState); setPauseOnExceptionsImpl(&error, pauseState);
m_cachedSkipStackRegExp = compileSkipCallFramePattern(m_state->getString(DebuggerAgentState::skipStackPattern)); m_cachedSkipStackRegExp = compileSkipCallFramePattern(m_state->getString(DebuggerAgentState::skipStackPattern));
m_skipContentScripts = m_state->getBoolean(DebuggerAgentState::skipContentScripts);
m_skipAllPauses = m_state->getBoolean(DebuggerAgentState::skipAllPauses); m_skipAllPauses = m_state->getBoolean(DebuggerAgentState::skipAllPauses);
if (m_skipAllPauses && m_state->getBoolean(DebuggerAgentState::skipAllPausesExpiresOnReload)) { if (m_skipAllPauses && m_state->getBoolean(DebuggerAgentState::skipAllPausesExpiresOnReload)) {
m_skipAllPauses = false; m_skipAllPauses = false;
...@@ -476,40 +480,35 @@ void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array ...@@ -476,40 +480,35 @@ void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array
asyncStackTrace = currentAsyncStackTrace(); asyncStackTrace = currentAsyncStackTrace();
} }
PassRefPtrWillBeRawPtr<JavaScriptCallFrame> InspectorDebuggerAgent::topCallFrameSkipUnknownSources() PassRefPtrWillBeRawPtr<JavaScriptCallFrame> InspectorDebuggerAgent::topCallFrameSkipUnknownSources(String* scriptURL, bool* isBlackboxed)
{ {
for (int index = 0; ; ++index) { for (int index = 0; ; ++index) {
RefPtrWillBeRawPtr<JavaScriptCallFrame> frame = scriptDebugServer().callFrameNoScopes(index); RefPtrWillBeRawPtr<JavaScriptCallFrame> frame = scriptDebugServer().callFrameNoScopes(index);
if (!frame) if (!frame)
return nullptr; return nullptr;
String scriptIdString = String::number(frame->sourceID()); ScriptsMap::iterator it = m_scripts.find(String::number(frame->sourceID()));
if (m_scripts.contains(scriptIdString)) if (it == m_scripts.end())
return frame.release(); continue;
*scriptURL = scriptSourceURL(it->value);
*isBlackboxed = (m_skipContentScripts && it->value.isContentScript)
|| (m_cachedSkipStackRegExp && !scriptURL->isEmpty() && m_cachedSkipStackRegExp->match(*scriptURL) != -1);
return frame.release();
} }
} }
String InspectorDebuggerAgent::scriptURL(JavaScriptCallFrame* frame)
{
String scriptIdString = String::number(frame->sourceID());
ScriptsMap::iterator it = m_scripts.find(scriptIdString);
if (it == m_scripts.end())
return String();
return scriptSourceURL(it->value);
}
ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptionPause() ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptionPause()
{ {
if (m_steppingFromFramework) if (m_steppingFromFramework)
return ScriptDebugListener::NoSkip; return ScriptDebugListener::NoSkip;
// FIXME: Fast return: if (!m_cachedSkipStackRegExp && !has_any_anti_breakpoint) return ScriptDebugListener::NoSkip; // FIXME: Fast return: if (!m_skipContentScripts && !m_cachedSkipStackRegExp && !has_any_anti_breakpoint) return ScriptDebugListener::NoSkip;
RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSources(); String topFrameScriptUrl;
bool isBlackboxed = false;
RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSources(&topFrameScriptUrl, &isBlackboxed);
if (!topFrame) if (!topFrame)
return ScriptDebugListener::NoSkip; return ScriptDebugListener::NoSkip;
if (isBlackboxed)
String topFrameScriptUrl = scriptURL(topFrame.get());
if (m_cachedSkipStackRegExp && !topFrameScriptUrl.isEmpty() && m_cachedSkipStackRegExp->match(topFrameScriptUrl) != -1)
return ScriptDebugListener::Continue; return ScriptDebugListener::Continue;
// Match against breakpoints. // Match against breakpoints.
...@@ -554,12 +553,16 @@ ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptio ...@@ -554,12 +553,16 @@ ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptio
ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPause() ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPause()
{ {
if (!m_cachedSkipStackRegExp || m_steppingFromFramework) if (m_steppingFromFramework)
return ScriptDebugListener::NoSkip;
// Fast return.
if (!m_skipContentScripts && !m_cachedSkipStackRegExp)
return ScriptDebugListener::NoSkip; return ScriptDebugListener::NoSkip;
RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSources(); String scriptUrl;
String scriptUrl = scriptURL(topFrame.get()); bool isBlackboxed = false;
if (scriptUrl.isEmpty() || m_cachedSkipStackRegExp->match(scriptUrl) == -1) RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSources(&scriptUrl, &isBlackboxed);
if (!topFrame || !isBlackboxed)
return ScriptDebugListener::NoSkip; return ScriptDebugListener::NoSkip;
if (m_skippedStepInCount == 0) { if (m_skippedStepInCount == 0) {
...@@ -586,15 +589,13 @@ ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPaus ...@@ -586,15 +589,13 @@ ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPaus
bool InspectorDebuggerAgent::isTopCallFrameInFramework() bool InspectorDebuggerAgent::isTopCallFrameInFramework()
{ {
if (!m_cachedSkipStackRegExp) if (!m_skipContentScripts && !m_cachedSkipStackRegExp)
return false;
RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSources();
if (!topFrame)
return false; return false;
String scriptUrl = scriptURL(topFrame.get()); String scriptUrl;
return !scriptUrl.isEmpty() && m_cachedSkipStackRegExp->match(scriptUrl) != -1; bool isBlackboxed = false;
RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSources(&scriptUrl, &isBlackboxed);
return topFrame && isBlackboxed;
} }
PassRefPtr<TypeBuilder::Debugger::Location> InspectorDebuggerAgent::resolveBreakpoint(const String& breakpointId, const String& scriptId, const ScriptBreakpoint& breakpoint, BreakpointSource source) PassRefPtr<TypeBuilder::Debugger::Location> InspectorDebuggerAgent::resolveBreakpoint(const String& breakpointId, const String& scriptId, const ScriptBreakpoint& breakpoint, BreakpointSource source)
...@@ -1142,7 +1143,7 @@ void InspectorDebuggerAgent::setVariableValue(ErrorString* errorString, int scop ...@@ -1142,7 +1143,7 @@ void InspectorDebuggerAgent::setVariableValue(ErrorString* errorString, int scop
injectedScript.setVariableValue(errorString, m_currentCallStack, callFrameId, functionObjectId, scopeNumber, variableName, newValueString); injectedScript.setVariableValue(errorString, m_currentCallStack, callFrameId, functionObjectId, scopeNumber, variableName, newValueString);
} }
void InspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const String* pattern) void InspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const String* pattern, const bool* skipContentScripts)
{ {
OwnPtr<ScriptRegexp> compiled; OwnPtr<ScriptRegexp> compiled;
String patternValue = pattern ? *pattern : ""; String patternValue = pattern ? *pattern : "";
...@@ -1155,6 +1156,8 @@ void InspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const Str ...@@ -1155,6 +1156,8 @@ void InspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const Str
} }
m_state->setString(DebuggerAgentState::skipStackPattern, patternValue); m_state->setString(DebuggerAgentState::skipStackPattern, patternValue);
m_cachedSkipStackRegExp = compiled.release(); m_cachedSkipStackRegExp = compiled.release();
m_skipContentScripts = asBool(skipContentScripts);
m_state->setBoolean(DebuggerAgentState::skipContentScripts, m_skipContentScripts);
} }
void InspectorDebuggerAgent::setAsyncCallStackDepth(ErrorString*, int depth) void InspectorDebuggerAgent::setAsyncCallStackDepth(ErrorString*, int depth)
......
...@@ -144,7 +144,7 @@ public: ...@@ -144,7 +144,7 @@ public:
virtual void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&, const int* executionContextId, const String* objectGroup, const bool* doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) OVERRIDE; virtual void runScript(ErrorString*, const TypeBuilder::Debugger::ScriptId&, const int* executionContextId, const String* objectGroup, const bool* doNotPauseOnExceptionsAndMuteConsole, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>&) OVERRIDE;
virtual void setOverlayMessage(ErrorString*, const String*) OVERRIDE; virtual void setOverlayMessage(ErrorString*, const String*) OVERRIDE;
virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String& in_variableName, const RefPtr<JSONObject>& in_newValue, const String* in_callFrame, const String* in_functionObjectId) OVERRIDE FINAL; virtual void setVariableValue(ErrorString*, int in_scopeNumber, const String& in_variableName, const RefPtr<JSONObject>& in_newValue, const String* in_callFrame, const String* in_functionObjectId) OVERRIDE FINAL;
virtual void skipStackFrames(ErrorString*, const String* pattern) OVERRIDE FINAL; virtual void skipStackFrames(ErrorString*, const String* pattern, const bool* skipContentScripts) OVERRIDE FINAL;
virtual void setAsyncCallStackDepth(ErrorString*, int depth) OVERRIDE FINAL; virtual void setAsyncCallStackDepth(ErrorString*, int depth) OVERRIDE FINAL;
void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data); void schedulePauseOnNextStatement(InspectorFrontend::Debugger::Reason::Enum breakReason, PassRefPtr<JSONObject> data);
...@@ -240,8 +240,7 @@ private: ...@@ -240,8 +240,7 @@ private:
String sourceMapURLForScript(const Script&, CompileResult); String sourceMapURLForScript(const Script&, CompileResult);
PassRefPtrWillBeRawPtr<JavaScriptCallFrame> topCallFrameSkipUnknownSources(); PassRefPtrWillBeRawPtr<JavaScriptCallFrame> topCallFrameSkipUnknownSources(String* scriptURL, bool* isBlackboxed);
String scriptURL(JavaScriptCallFrame*);
AsyncCallStackTracker& asyncCallStackTracker() { return *m_asyncCallStackTracker; }; AsyncCallStackTracker& asyncCallStackTracker() { return *m_asyncCallStackTracker; };
typedef HashMap<String, Script> ScriptsMap; typedef HashMap<String, Script> ScriptsMap;
...@@ -267,6 +266,7 @@ private: ...@@ -267,6 +266,7 @@ private:
int m_skippedStepInCount; int m_skippedStepInCount;
int m_minFrameCountForSkip; int m_minFrameCountForSkip;
bool m_skipAllPauses; bool m_skipAllPauses;
bool m_skipContentScripts;
OwnPtr<ScriptRegexp> m_cachedSkipStackRegExp; OwnPtr<ScriptRegexp> m_cachedSkipStackRegExp;
OwnPtrWillBeMember<AsyncCallStackTracker> m_asyncCallStackTracker; OwnPtrWillBeMember<AsyncCallStackTracker> m_asyncCallStackTracker;
PromiseTracker m_promiseTracker; PromiseTracker m_promiseTracker;
......
...@@ -3396,7 +3396,8 @@ ...@@ -3396,7 +3396,8 @@
{ {
"name": "skipStackFrames", "name": "skipStackFrames",
"parameters": [ "parameters": [
{ "name": "script", "optional": true, "type": "string", "description": "Regular expression defining the scripts to ignore while stepping." } { "name": "script", "type": "string", "optional": true, "description": "Regular expression defining the scripts to ignore while stepping." },
{ "name": "skipContentScripts", "type": "boolean", "optional": true, "description": "True, if all content scripts should be ignored." }
], ],
"hidden": true, "hidden": true,
"description": "Makes backend skip steps in the sources with names matching given pattern. VM will try leave blacklisted scripts by performing 'step in' several times, finally resorting to 'step out' if unsuccessful." "description": "Makes backend skip steps in the sources with names matching given pattern. VM will try leave blacklisted scripts by performing 'step in' several times, finally resorting to 'step out' if unsuccessful."
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment