Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1150)

Side by Side Diff: Source/core/inspector/InspectorDebuggerAgent.cpp

Issue 547603003: DevTools: Blackbox content scripts - backend support. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/inspector/InspectorDebuggerAgent.h ('k') | Source/devtools/protocol.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 static const char asyncCallStackDepth[] = "asyncCallStackDepth"; 79 static const char asyncCallStackDepth[] = "asyncCallStackDepth";
80 80
81 // Breakpoint properties. 81 // Breakpoint properties.
82 static const char url[] = "url"; 82 static const char url[] = "url";
83 static const char isRegex[] = "isRegex"; 83 static const char isRegex[] = "isRegex";
84 static const char lineNumber[] = "lineNumber"; 84 static const char lineNumber[] = "lineNumber";
85 static const char columnNumber[] = "columnNumber"; 85 static const char columnNumber[] = "columnNumber";
86 static const char condition[] = "condition"; 86 static const char condition[] = "condition";
87 static const char isAnti[] = "isAnti"; 87 static const char isAnti[] = "isAnti";
88 static const char skipStackPattern[] = "skipStackPattern"; 88 static const char skipStackPattern[] = "skipStackPattern";
89 static const char skipContentScripts[] = "skipContentScripts";
89 static const char skipAllPauses[] = "skipAllPauses"; 90 static const char skipAllPauses[] = "skipAllPauses";
90 static const char skipAllPausesExpiresOnReload[] = "skipAllPausesExpiresOnReload "; 91 static const char skipAllPausesExpiresOnReload[] = "skipAllPausesExpiresOnReload ";
91 92
92 }; 93 };
93 94
94 static const int maxSkipStepInCount = 20; 95 static const int maxSkipStepInCount = 20;
95 96
96 const char InspectorDebuggerAgent::backtraceObjectGroup[] = "backtrace"; 97 const char InspectorDebuggerAgent::backtraceObjectGroup[] = "backtrace";
97 98
98 static String breakpointIdSuffix(InspectorDebuggerAgent::BreakpointSource source ) 99 static String breakpointIdSuffix(InspectorDebuggerAgent::BreakpointSource source )
(...skipping 19 matching lines...) Expand all
118 , m_injectedScriptManager(injectedScriptManager) 119 , m_injectedScriptManager(injectedScriptManager)
119 , m_frontend(0) 120 , m_frontend(0)
120 , m_pausedScriptState(nullptr) 121 , m_pausedScriptState(nullptr)
121 , m_javaScriptPauseScheduled(false) 122 , m_javaScriptPauseScheduled(false)
122 , m_debuggerStepScheduled(false) 123 , m_debuggerStepScheduled(false)
123 , m_steppingFromFramework(false) 124 , m_steppingFromFramework(false)
124 , m_pausingOnNativeEvent(false) 125 , m_pausingOnNativeEvent(false)
125 , m_listener(nullptr) 126 , m_listener(nullptr)
126 , m_skippedStepInCount(0) 127 , m_skippedStepInCount(0)
127 , m_skipAllPauses(false) 128 , m_skipAllPauses(false)
129 , m_skipContentScripts(false)
128 , m_asyncCallStackTracker(adoptPtrWillBeNoop(new AsyncCallStackTracker())) 130 , m_asyncCallStackTracker(adoptPtrWillBeNoop(new AsyncCallStackTracker()))
129 { 131 {
130 } 132 }
131 133
132 InspectorDebuggerAgent::~InspectorDebuggerAgent() 134 InspectorDebuggerAgent::~InspectorDebuggerAgent()
133 { 135 {
134 #if !ENABLE(OILPAN) 136 #if !ENABLE(OILPAN)
135 ASSERT(!m_instrumentingAgents->inspectorDebuggerAgent()); 137 ASSERT(!m_instrumentingAgents->inspectorDebuggerAgent());
136 #endif 138 #endif
137 } 139 }
(...skipping 15 matching lines...) Expand all
153 155
154 if (m_listener) 156 if (m_listener)
155 m_listener->debuggerWasEnabled(); 157 m_listener->debuggerWasEnabled();
156 } 158 }
157 159
158 void InspectorDebuggerAgent::disable() 160 void InspectorDebuggerAgent::disable()
159 { 161 {
160 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, JSONObject::cr eate()); 162 m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, JSONObject::cr eate());
161 m_state->setLong(DebuggerAgentState::pauseOnExceptionsState, ScriptDebugServ er::DontPauseOnExceptions); 163 m_state->setLong(DebuggerAgentState::pauseOnExceptionsState, ScriptDebugServ er::DontPauseOnExceptions);
162 m_state->setString(DebuggerAgentState::skipStackPattern, ""); 164 m_state->setString(DebuggerAgentState::skipStackPattern, "");
165 m_state->setBoolean(DebuggerAgentState::skipContentScripts, false);
163 m_state->setLong(DebuggerAgentState::asyncCallStackDepth, 0); 166 m_state->setLong(DebuggerAgentState::asyncCallStackDepth, 0);
164 m_instrumentingAgents->setInspectorDebuggerAgent(0); 167 m_instrumentingAgents->setInspectorDebuggerAgent(0);
165 168
166 scriptDebugServer().clearBreakpoints(); 169 scriptDebugServer().clearBreakpoints();
167 scriptDebugServer().clearCompiledScripts(); 170 scriptDebugServer().clearCompiledScripts();
168 scriptDebugServer().clearPreprocessor(); 171 scriptDebugServer().clearPreprocessor();
169 stopListeningScriptDebugServer(); 172 stopListeningScriptDebugServer();
170 clear(); 173 clear();
171 174
172 if (m_listener) 175 if (m_listener)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 215
213 void InspectorDebuggerAgent::restore() 216 void InspectorDebuggerAgent::restore()
214 { 217 {
215 if (enabled()) { 218 if (enabled()) {
216 m_frontend->globalObjectCleared(); 219 m_frontend->globalObjectCleared();
217 enable(); 220 enable();
218 long pauseState = m_state->getLong(DebuggerAgentState::pauseOnExceptions State); 221 long pauseState = m_state->getLong(DebuggerAgentState::pauseOnExceptions State);
219 String error; 222 String error;
220 setPauseOnExceptionsImpl(&error, pauseState); 223 setPauseOnExceptionsImpl(&error, pauseState);
221 m_cachedSkipStackRegExp = compileSkipCallFramePattern(m_state->getString (DebuggerAgentState::skipStackPattern)); 224 m_cachedSkipStackRegExp = compileSkipCallFramePattern(m_state->getString (DebuggerAgentState::skipStackPattern));
225 m_skipContentScripts = m_state->getBoolean(DebuggerAgentState::skipConte ntScripts);
222 m_skipAllPauses = m_state->getBoolean(DebuggerAgentState::skipAllPauses) ; 226 m_skipAllPauses = m_state->getBoolean(DebuggerAgentState::skipAllPauses) ;
223 if (m_skipAllPauses && m_state->getBoolean(DebuggerAgentState::skipAllPa usesExpiresOnReload)) { 227 if (m_skipAllPauses && m_state->getBoolean(DebuggerAgentState::skipAllPa usesExpiresOnReload)) {
224 m_skipAllPauses = false; 228 m_skipAllPauses = false;
225 m_state->setBoolean(DebuggerAgentState::skipAllPauses, false); 229 m_state->setBoolean(DebuggerAgentState::skipAllPauses, false);
226 } 230 }
227 asyncCallStackTracker().setAsyncCallStackDepth(m_state->getLong(Debugger AgentState::asyncCallStackDepth)); 231 asyncCallStackTracker().setAsyncCallStackDepth(m_state->getLong(Debugger AgentState::asyncCallStackDepth));
228 } 232 }
229 } 233 }
230 234
231 void InspectorDebuggerAgent::setFrontend(InspectorFrontend* frontend) 235 void InspectorDebuggerAgent::setFrontend(InspectorFrontend* frontend)
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 473
470 void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array <CallFrame> >& callFrames, RefPtr<StackTrace>& asyncStackTrace) 474 void InspectorDebuggerAgent::getBacktrace(ErrorString* errorString, RefPtr<Array <CallFrame> >& callFrames, RefPtr<StackTrace>& asyncStackTrace)
471 { 475 {
472 if (!assertPaused(errorString)) 476 if (!assertPaused(errorString))
473 return; 477 return;
474 m_currentCallStack = scriptDebugServer().currentCallFrames(); 478 m_currentCallStack = scriptDebugServer().currentCallFrames();
475 callFrames = currentCallFrames(); 479 callFrames = currentCallFrames();
476 asyncStackTrace = currentAsyncStackTrace(); 480 asyncStackTrace = currentAsyncStackTrace();
477 } 481 }
478 482
479 PassRefPtrWillBeRawPtr<JavaScriptCallFrame> InspectorDebuggerAgent::topCallFrame SkipUnknownSources() 483 PassRefPtrWillBeRawPtr<JavaScriptCallFrame> InspectorDebuggerAgent::topCallFrame SkipUnknownSources(String* scriptURL, bool* isBlackboxed)
480 { 484 {
481 for (int index = 0; ; ++index) { 485 for (int index = 0; ; ++index) {
482 RefPtrWillBeRawPtr<JavaScriptCallFrame> frame = scriptDebugServer().call FrameNoScopes(index); 486 RefPtrWillBeRawPtr<JavaScriptCallFrame> frame = scriptDebugServer().call FrameNoScopes(index);
483 if (!frame) 487 if (!frame)
484 return nullptr; 488 return nullptr;
485 String scriptIdString = String::number(frame->sourceID()); 489 ScriptsMap::iterator it = m_scripts.find(String::number(frame->sourceID( )));
486 if (m_scripts.contains(scriptIdString)) 490 if (it == m_scripts.end())
487 return frame.release(); 491 continue;
492 *scriptURL = scriptSourceURL(it->value);
493 *isBlackboxed = (m_skipContentScripts && it->value.isContentScript)
494 || (m_cachedSkipStackRegExp && !scriptURL->isEmpty() && m_cachedSkip StackRegExp->match(*scriptURL) != -1);
495 return frame.release();
488 } 496 }
489 } 497 }
490 498
491 String InspectorDebuggerAgent::scriptURL(JavaScriptCallFrame* frame)
492 {
493 String scriptIdString = String::number(frame->sourceID());
494 ScriptsMap::iterator it = m_scripts.find(scriptIdString);
495 if (it == m_scripts.end())
496 return String();
497 return scriptSourceURL(it->value);
498 }
499
500 ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptio nPause() 499 ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptio nPause()
501 { 500 {
502 if (m_steppingFromFramework) 501 if (m_steppingFromFramework)
503 return ScriptDebugListener::NoSkip; 502 return ScriptDebugListener::NoSkip;
504 503
505 // FIXME: Fast return: if (!m_cachedSkipStackRegExp && !has_any_anti_breakpo int) return ScriptDebugListener::NoSkip; 504 // FIXME: Fast return: if (!m_skipContentScripts && !m_cachedSkipStackRegExp && !has_any_anti_breakpoint) return ScriptDebugListener::NoSkip;
506 505
507 RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSo urces(); 506 String topFrameScriptUrl;
507 bool isBlackboxed = false;
508 RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSo urces(&topFrameScriptUrl, &isBlackboxed);
508 if (!topFrame) 509 if (!topFrame)
509 return ScriptDebugListener::NoSkip; 510 return ScriptDebugListener::NoSkip;
510 511 if (isBlackboxed)
511 String topFrameScriptUrl = scriptURL(topFrame.get());
512 if (m_cachedSkipStackRegExp && !topFrameScriptUrl.isEmpty() && m_cachedSkipS tackRegExp->match(topFrameScriptUrl) != -1)
513 return ScriptDebugListener::Continue; 512 return ScriptDebugListener::Continue;
514 513
515 // Match against breakpoints. 514 // Match against breakpoints.
516 if (topFrameScriptUrl.isEmpty()) 515 if (topFrameScriptUrl.isEmpty())
517 return ScriptDebugListener::NoSkip; 516 return ScriptDebugListener::NoSkip;
518 517
519 // Prepare top frame parameters. 518 // Prepare top frame parameters.
520 int topFrameLineNumber = topFrame->line(); 519 int topFrameLineNumber = topFrame->line();
521 int topFrameColumnNumber = topFrame->column(); 520 int topFrameColumnNumber = topFrame->column();
522 521
(...skipping 24 matching lines...) Expand all
547 continue; 546 continue;
548 547
549 return ScriptDebugListener::Continue; 548 return ScriptDebugListener::Continue;
550 } 549 }
551 550
552 return ScriptDebugListener::NoSkip; 551 return ScriptDebugListener::NoSkip;
553 } 552 }
554 553
555 ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPaus e() 554 ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPaus e()
556 { 555 {
557 if (!m_cachedSkipStackRegExp || m_steppingFromFramework) 556 if (m_steppingFromFramework)
557 return ScriptDebugListener::NoSkip;
558 // Fast return.
559 if (!m_skipContentScripts && !m_cachedSkipStackRegExp)
558 return ScriptDebugListener::NoSkip; 560 return ScriptDebugListener::NoSkip;
559 561
560 RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSo urces(); 562 String scriptUrl;
561 String scriptUrl = scriptURL(topFrame.get()); 563 bool isBlackboxed = false;
562 if (scriptUrl.isEmpty() || m_cachedSkipStackRegExp->match(scriptUrl) == -1) 564 RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSo urces(&scriptUrl, &isBlackboxed);
565 if (!topFrame || !isBlackboxed)
563 return ScriptDebugListener::NoSkip; 566 return ScriptDebugListener::NoSkip;
564 567
565 if (m_skippedStepInCount == 0) { 568 if (m_skippedStepInCount == 0) {
566 m_minFrameCountForSkip = scriptDebugServer().frameCount(); 569 m_minFrameCountForSkip = scriptDebugServer().frameCount();
567 m_skippedStepInCount = 1; 570 m_skippedStepInCount = 1;
568 return ScriptDebugListener::StepInto; 571 return ScriptDebugListener::StepInto;
569 } 572 }
570 573
571 if (m_skippedStepInCount < maxSkipStepInCount && topFrame->isAtReturn() && s criptDebugServer().frameCount() <= m_minFrameCountForSkip) 574 if (m_skippedStepInCount < maxSkipStepInCount && topFrame->isAtReturn() && s criptDebugServer().frameCount() <= m_minFrameCountForSkip)
572 m_skippedStepInCount = maxSkipStepInCount; 575 m_skippedStepInCount = maxSkipStepInCount;
573 576
574 if (m_skippedStepInCount >= maxSkipStepInCount) { 577 if (m_skippedStepInCount >= maxSkipStepInCount) {
575 if (m_pausingOnNativeEvent) { 578 if (m_pausingOnNativeEvent) {
576 m_pausingOnNativeEvent = false; 579 m_pausingOnNativeEvent = false;
577 m_skippedStepInCount = 0; 580 m_skippedStepInCount = 0;
578 return ScriptDebugListener::Continue; 581 return ScriptDebugListener::Continue;
579 } 582 }
580 return ScriptDebugListener::StepOut; 583 return ScriptDebugListener::StepOut;
581 } 584 }
582 585
583 ++m_skippedStepInCount; 586 ++m_skippedStepInCount;
584 return ScriptDebugListener::StepInto; 587 return ScriptDebugListener::StepInto;
585 } 588 }
586 589
587 bool InspectorDebuggerAgent::isTopCallFrameInFramework() 590 bool InspectorDebuggerAgent::isTopCallFrameInFramework()
588 { 591 {
589 if (!m_cachedSkipStackRegExp) 592 if (!m_skipContentScripts && !m_cachedSkipStackRegExp)
590 return false; 593 return false;
591 594
592 RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSo urces(); 595 String scriptUrl;
593 if (!topFrame) 596 bool isBlackboxed = false;
594 return false; 597 RefPtrWillBeRawPtr<JavaScriptCallFrame> topFrame = topCallFrameSkipUnknownSo urces(&scriptUrl, &isBlackboxed);
595 598 return topFrame && isBlackboxed;
596 String scriptUrl = scriptURL(topFrame.get());
597 return !scriptUrl.isEmpty() && m_cachedSkipStackRegExp->match(scriptUrl) != -1;
598 } 599 }
599 600
600 PassRefPtr<TypeBuilder::Debugger::Location> InspectorDebuggerAgent::resolveBreak point(const String& breakpointId, const String& scriptId, const ScriptBreakpoint & breakpoint, BreakpointSource source) 601 PassRefPtr<TypeBuilder::Debugger::Location> InspectorDebuggerAgent::resolveBreak point(const String& breakpointId, const String& scriptId, const ScriptBreakpoint & breakpoint, BreakpointSource source)
601 { 602 {
602 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId); 603 ScriptsMap::iterator scriptIterator = m_scripts.find(scriptId);
603 if (scriptIterator == m_scripts.end()) 604 if (scriptIterator == m_scripts.end())
604 return nullptr; 605 return nullptr;
605 Script& script = scriptIterator->value; 606 Script& script = scriptIterator->value;
606 if (breakpoint.lineNumber < script.startLine || script.endLine < breakpoint. lineNumber) 607 if (breakpoint.lineNumber < script.startLine || script.endLine < breakpoint. lineNumber)
607 return nullptr; 608 return nullptr;
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1136 }
1136 } else { 1137 } else {
1137 *errorString = "Either call frame or function object must be specified"; 1138 *errorString = "Either call frame or function object must be specified";
1138 return; 1139 return;
1139 } 1140 }
1140 String newValueString = newValue->toJSONString(); 1141 String newValueString = newValue->toJSONString();
1141 1142
1142 injectedScript.setVariableValue(errorString, m_currentCallStack, callFrameId , functionObjectId, scopeNumber, variableName, newValueString); 1143 injectedScript.setVariableValue(errorString, m_currentCallStack, callFrameId , functionObjectId, scopeNumber, variableName, newValueString);
1143 } 1144 }
1144 1145
1145 void InspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const Str ing* pattern) 1146 void InspectorDebuggerAgent::skipStackFrames(ErrorString* errorString, const Str ing* pattern, const bool* skipContentScripts)
1146 { 1147 {
1147 OwnPtr<ScriptRegexp> compiled; 1148 OwnPtr<ScriptRegexp> compiled;
1148 String patternValue = pattern ? *pattern : ""; 1149 String patternValue = pattern ? *pattern : "";
1149 if (!patternValue.isEmpty()) { 1150 if (!patternValue.isEmpty()) {
1150 compiled = compileSkipCallFramePattern(patternValue); 1151 compiled = compileSkipCallFramePattern(patternValue);
1151 if (!compiled) { 1152 if (!compiled) {
1152 *errorString = "Invalid regular expression"; 1153 *errorString = "Invalid regular expression";
1153 return; 1154 return;
1154 } 1155 }
1155 } 1156 }
1156 m_state->setString(DebuggerAgentState::skipStackPattern, patternValue); 1157 m_state->setString(DebuggerAgentState::skipStackPattern, patternValue);
1157 m_cachedSkipStackRegExp = compiled.release(); 1158 m_cachedSkipStackRegExp = compiled.release();
1159 m_skipContentScripts = asBool(skipContentScripts);
1160 m_state->setBoolean(DebuggerAgentState::skipContentScripts, m_skipContentScr ipts);
1158 } 1161 }
1159 1162
1160 void InspectorDebuggerAgent::setAsyncCallStackDepth(ErrorString*, int depth) 1163 void InspectorDebuggerAgent::setAsyncCallStackDepth(ErrorString*, int depth)
1161 { 1164 {
1162 m_state->setLong(DebuggerAgentState::asyncCallStackDepth, depth); 1165 m_state->setLong(DebuggerAgentState::asyncCallStackDepth, depth);
1163 asyncCallStackTracker().setAsyncCallStackDepth(depth); 1166 asyncCallStackTracker().setAsyncCallStackDepth(depth);
1164 } 1167 }
1165 1168
1166 void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directive Text) 1169 void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directive Text)
1167 { 1170 {
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 void InspectorDebuggerAgent::trace(Visitor* visitor) 1479 void InspectorDebuggerAgent::trace(Visitor* visitor)
1477 { 1480 {
1478 visitor->trace(m_injectedScriptManager); 1481 visitor->trace(m_injectedScriptManager);
1479 visitor->trace(m_listener); 1482 visitor->trace(m_listener);
1480 visitor->trace(m_asyncCallStackTracker); 1483 visitor->trace(m_asyncCallStackTracker);
1481 InspectorBaseAgent::trace(visitor); 1484 InspectorBaseAgent::trace(visitor);
1482 } 1485 }
1483 1486
1484 } // namespace blink 1487 } // namespace blink
1485 1488
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorDebuggerAgent.h ('k') | Source/devtools/protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698