Commit 1a840305 authored by aandrey@chromium.org's avatar aandrey@chromium.org

DevTools: nits: introduce a handy asBool(bool*) and use across agents.

R=loislo, yurys

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

git-svn-id: svn://svn.chromium.org/blink/trunk@179157 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 359e4aa0
......@@ -109,6 +109,11 @@ protected:
}
};
inline bool asBool(const bool* const b)
{
return b ? *b : false;
}
} // namespace blink
#endif // !defined(InspectorBaseAgent_h)
......@@ -1244,7 +1244,7 @@ void InspectorDOMAgent::setInspectModeEnabled(ErrorString* errorString, bool ena
{
if (enabled && !pushDocumentUponHandlelessOperation(errorString))
return;
SearchMode searchMode = enabled ? (inspectUAShadowDOM && *inspectUAShadowDOM ? SearchingForUAShadow : SearchingForNormal) : NotSearching;
SearchMode searchMode = enabled ? (asBool(inspectUAShadowDOM) ? SearchingForUAShadow : SearchingForNormal) : NotSearching;
setSearchingForNode(errorString, searchMode, highlightConfig ? highlightConfig->get() : 0);
}
......
......@@ -252,9 +252,8 @@ void InspectorDebuggerAgent::setBreakpointsActive(ErrorString*, bool active)
void InspectorDebuggerAgent::setSkipAllPauses(ErrorString*, bool skipped, const bool* untilReload)
{
m_skipAllPauses = skipped;
bool untilReloadValue = untilReload && *untilReload;
m_state->setBoolean(DebuggerAgentState::skipAllPauses, m_skipAllPauses);
m_state->setBoolean(DebuggerAgentState::skipAllPausesExpiresOnReload, untilReloadValue);
m_state->setBoolean(DebuggerAgentState::skipAllPausesExpiresOnReload, asBool(untilReload));
}
void InspectorDebuggerAgent::pageDidCommitLoad()
......@@ -320,7 +319,7 @@ void InspectorDebuggerAgent::setBreakpointByUrl(ErrorString* errorString, int li
return;
}
bool isAntiBreakpointValue = isAntiBreakpoint && *isAntiBreakpoint;
bool isAntiBreakpointValue = asBool(isAntiBreakpoint);
String url = optionalURL ? *optionalURL : *optionalURLRegex;
int columnNumber;
......@@ -426,7 +425,6 @@ void InspectorDebuggerAgent::removeBreakpoint(const String& breakpointId)
void InspectorDebuggerAgent::continueToLocation(ErrorString* errorString, const RefPtr<JSONObject>& location, const bool* interstateLocationOpt)
{
bool interstateLocation = interstateLocationOpt ? *interstateLocationOpt : false;
if (!m_continueToLocationBreakpointId.isEmpty()) {
scriptDebugServer().removeBreakpoint(m_continueToLocationBreakpointId);
m_continueToLocationBreakpointId = "";
......@@ -440,7 +438,7 @@ void InspectorDebuggerAgent::continueToLocation(ErrorString* errorString, const
return;
ScriptBreakpoint breakpoint(lineNumber, columnNumber, "");
m_continueToLocationBreakpointId = scriptDebugServer().setBreakpoint(scriptId, breakpoint, &lineNumber, &columnNumber, interstateLocation);
m_continueToLocationBreakpointId = scriptDebugServer().setBreakpoint(scriptId, breakpoint, &lineNumber, &columnNumber, asBool(interstateLocationOpt));
resume(errorString);
}
......@@ -609,20 +607,16 @@ PassRefPtr<TypeBuilder::Debugger::Location> InspectorDebuggerAgent::resolveBreak
void InspectorDebuggerAgent::searchInContent(ErrorString* error, const String& scriptId, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<Array<blink::TypeBuilder::Page::SearchMatch> >& results)
{
bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
ScriptsMap::iterator it = m_scripts.find(scriptId);
if (it != m_scripts.end())
results = ContentSearchUtils::searchInTextByLines(it->value.source, query, caseSensitive, isRegex);
results = ContentSearchUtils::searchInTextByLines(it->value.source, query, asBool(optionalCaseSensitive), asBool(optionalIsRegex));
else
*error = "No script for id: " + scriptId;
}
void InspectorDebuggerAgent::setScriptSource(ErrorString* error, RefPtr<TypeBuilder::Debugger::SetScriptSourceError>& errorData, const String& scriptId, const String& newContent, const bool* const preview, RefPtr<Array<CallFrame> >& newCallFrames, RefPtr<JSONObject>& result, RefPtr<StackTrace>& asyncStackTrace)
{
bool previewOnly = preview && *preview;
if (!scriptDebugServer().setScriptSource(scriptId, newContent, previewOnly, error, errorData, &m_currentCallStack, &result))
if (!scriptDebugServer().setScriptSource(scriptId, newContent, asBool(preview), error, errorData, &m_currentCallStack, &result))
return;
newCallFrames = currentCallFrames();
......@@ -976,7 +970,7 @@ void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, const
}
ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = scriptDebugServer().pauseOnExceptionsState();
if (doNotPauseOnExceptionsAndMuteConsole ? *doNotPauseOnExceptionsAndMuteConsole : false) {
if (asBool(doNotPauseOnExceptionsAndMuteConsole)) {
if (previousPauseOnExceptionsState != ScriptDebugServer::DontPauseOnExceptions)
scriptDebugServer().setPauseOnExceptionsState(ScriptDebugServer::DontPauseOnExceptions);
muteConsole();
......@@ -992,12 +986,12 @@ void InspectorDebuggerAgent::evaluateOnCallFrame(ErrorString* errorString, const
asyncCallStacks[i] = (*it)->callFrames();
}
injectedScript.evaluateOnCallFrame(errorString, m_currentCallStack, asyncCallStacks, callFrameId, expression, objectGroup ? *objectGroup : "", includeCommandLineAPI ? *includeCommandLineAPI : false, returnByValue ? *returnByValue : false, generatePreview ? *generatePreview : false, &result, wasThrown, &exceptionDetails);
injectedScript.evaluateOnCallFrame(errorString, m_currentCallStack, asyncCallStacks, callFrameId, expression, objectGroup ? *objectGroup : "", asBool(includeCommandLineAPI), asBool(returnByValue), asBool(generatePreview), &result, wasThrown, &exceptionDetails);
// V8 doesn't generate afterCompile event when it's in debugger therefore there is no content of evaluated scripts on frontend
// therefore contents of the stack does not provide necessary information
if (exceptionDetails)
exceptionDetails->setStackTrace(TypeBuilder::Array<TypeBuilder::Console::CallFrame>::create());
if (doNotPauseOnExceptionsAndMuteConsole ? *doNotPauseOnExceptionsAndMuteConsole : false) {
if (asBool(doNotPauseOnExceptionsAndMuteConsole)) {
unmuteConsole();
if (scriptDebugServer().pauseOnExceptionsState() != previousPauseOnExceptionsState)
scriptDebugServer().setPauseOnExceptionsState(previousPauseOnExceptionsState);
......@@ -1042,7 +1036,7 @@ void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId&
}
ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = scriptDebugServer().pauseOnExceptionsState();
if (doNotPauseOnExceptionsAndMuteConsole && *doNotPauseOnExceptionsAndMuteConsole) {
if (asBool(doNotPauseOnExceptionsAndMuteConsole)) {
if (previousPauseOnExceptionsState != ScriptDebugServer::DontPauseOnExceptions)
scriptDebugServer().setPauseOnExceptionsState(ScriptDebugServer::DontPauseOnExceptions);
muteConsole();
......@@ -1068,7 +1062,7 @@ void InspectorDebuggerAgent::runScript(ErrorString* errorString, const ScriptId&
exceptionDetails->setStackTrace(stackTraceValue->buildInspectorArray());
}
if (doNotPauseOnExceptionsAndMuteConsole && *doNotPauseOnExceptionsAndMuteConsole) {
if (asBool(doNotPauseOnExceptionsAndMuteConsole)) {
unmuteConsole();
if (scriptDebugServer().pauseOnExceptionsState() != previousPauseOnExceptionsState)
scriptDebugServer().setPauseOnExceptionsState(previousPauseOnExceptionsState);
......
......@@ -152,7 +152,7 @@ private:
void InspectorHeapProfilerAgent::startTrackingHeapObjects(ErrorString*, const bool* trackAllocations)
{
m_state->setBoolean(HeapProfilerAgentState::heapObjectsTrackingEnabled, true);
bool allocationTrackingEnabled = trackAllocations && *trackAllocations;
bool allocationTrackingEnabled = asBool(trackAllocations);
m_state->setBoolean(HeapProfilerAgentState::allocationTrackingEnabled, allocationTrackingEnabled);
startTrackingHeapObjectsInternal(allocationTrackingEnabled);
}
......@@ -251,7 +251,7 @@ void InspectorHeapProfilerAgent::takeHeapSnapshot(ErrorString* errorString, cons
};
String title = "Snapshot " + String::number(m_nextUserInitiatedHeapSnapshotNumber++);
HeapSnapshotProgress progress(reportProgress && *reportProgress ? m_frontend : 0);
HeapSnapshotProgress progress(asBool(reportProgress) ? m_frontend : 0);
RefPtr<ScriptHeapSnapshot> snapshot = ScriptProfiler::takeHeapSnapshot(title, &progress);
if (!snapshot) {
*errorString = "Failed to take heap snapshot";
......
......@@ -122,9 +122,9 @@ void InspectorInputAgent::dispatchKeyEvent(ErrorString* error, const String& typ
keyIdentifier ? *keyIdentifier : "",
windowsVirtualKeyCode ? *windowsVirtualKeyCode : 0,
nativeVirtualKeyCode ? *nativeVirtualKeyCode : 0,
autoRepeat ? *autoRepeat : false,
isKeypad ? *isKeypad : false,
isSystemKey ? *isSystemKey : false,
asBool(autoRepeat),
asBool(isKeypad),
asBool(isSystemKey),
static_cast<PlatformEvent::Modifiers>(modifiers ? *modifiers : 0),
timestamp ? *timestamp : currentTime());
m_client->dispatchKeyEvent(event);
......@@ -132,7 +132,7 @@ void InspectorInputAgent::dispatchKeyEvent(ErrorString* error, const String& typ
void InspectorInputAgent::dispatchMouseEvent(ErrorString* error, const String& type, int x, int y, const int* modifiers, const double* timestamp, const String* button, const int* clickCount, const bool* deviceSpace)
{
if (deviceSpace && *deviceSpace) {
if (asBool(deviceSpace)) {
*error = "Internal error: events with device coordinates should be processed on the embedder level.";
return;
}
......
......@@ -544,7 +544,7 @@ void InspectorPageAgent::reload(ErrorString*, const bool* const optionalIgnoreCa
{
m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *optionalScriptToEvaluateOnLoad : "";
m_pendingScriptPreprocessor = optionalScriptPreprocessor ? *optionalScriptPreprocessor : "";
m_page->deprecatedLocalMainFrame()->loader().reload(optionalIgnoreCache && *optionalIgnoreCache ? EndToEndReload : NormalReload);
m_page->deprecatedLocalMainFrame()->loader().reload(asBool(optionalIgnoreCache) ? EndToEndReload : NormalReload);
}
void InspectorPageAgent::navigate(ErrorString*, const String& url, String* outFrameId)
......@@ -739,9 +739,6 @@ void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, c
{
results = TypeBuilder::Array<TypeBuilder::Page::SearchMatch>::create();
bool isRegex = optionalIsRegex ? *optionalIsRegex : false;
bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false;
LocalFrame* frame = frameForId(frameId);
KURL kurl(ParsedURLString, url);
......@@ -759,7 +756,7 @@ void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, c
if (!success)
return;
results = ContentSearchUtils::searchInTextByLines(content, query, caseSensitive, isRegex);
results = ContentSearchUtils::searchInTextByLines(content, query, asBool(optionalCaseSensitive), asBool(optionalIsRegex));
}
void InspectorPageAgent::setDocumentContent(ErrorString* errorString, const String& frameId, const String& html)
......@@ -1405,7 +1402,7 @@ bool InspectorPageAgent::compositingEnabled(ErrorString* errorString)
void InspectorPageAgent::setShowViewportSizeOnResize(ErrorString*, bool show, const bool* showGrid)
{
m_state->setBoolean(PageAgentState::showSizeOnResize, show);
m_state->setBoolean(PageAgentState::showGridOnResize, showGrid && *showGrid);
m_state->setBoolean(PageAgentState::showGridOnResize, asBool(showGrid));
}
void InspectorPageAgent::clearEditedResourcesContent()
......
......@@ -46,11 +46,6 @@ namespace InspectorRuntimeAgentState {
static const char runtimeEnabled[] = "runtimeEnabled";
};
static bool asBool(const bool* const b)
{
return b ? *b : false;
}
InspectorRuntimeAgent::InspectorRuntimeAgent(InjectedScriptManager* injectedScriptManager, ScriptDebugServer* scriptDebugServer)
: InspectorBaseAgent<InspectorRuntimeAgent>("Runtime")
, m_enabled(false)
......@@ -134,10 +129,9 @@ void InspectorRuntimeAgent::getProperties(ErrorString* errorString, const String
ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = setPauseOnExceptionsState(m_scriptDebugServer, ScriptDebugServer::DontPauseOnExceptions);
muteConsole();
bool accessorPropertiesOnlyValue = accessorPropertiesOnly && *accessorPropertiesOnly;
injectedScript.getProperties(errorString, objectId, ownProperties && *ownProperties, accessorPropertiesOnlyValue, &result);
injectedScript.getProperties(errorString, objectId, asBool(ownProperties), asBool(accessorPropertiesOnly), &result);
if (!accessorPropertiesOnlyValue)
if (!asBool(accessorPropertiesOnly))
injectedScript.getInternalProperties(errorString, objectId, &internalProperties);
unmuteConsole();
......
......@@ -365,7 +365,7 @@ void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS
else
m_maxCallStackDepth = 5;
if (bufferEvents && *bufferEvents) {
if (asBool(bufferEvents)) {
m_bufferedEvents = TypeBuilder::Array<TimelineEvent>::create();
m_lastProgressTimestamp = timestamp();
}
......@@ -374,9 +374,9 @@ void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS
setLiveEvents(*liveEvents);
m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallStackDepth);
m_state->setBoolean(TimelineAgentState::includeCounters, includeCounters && *includeCounters);
m_state->setBoolean(TimelineAgentState::includeGPUEvents, includeGPUEvents && *includeGPUEvents);
m_state->setBoolean(TimelineAgentState::bufferEvents, bufferEvents && *bufferEvents);
m_state->setBoolean(TimelineAgentState::includeCounters, asBool(includeCounters));
m_state->setBoolean(TimelineAgentState::includeGPUEvents, asBool(includeGPUEvents));
m_state->setBoolean(TimelineAgentState::bufferEvents, asBool(bufferEvents));
m_state->setString(TimelineAgentState::liveEvents, liveEvents ? *liveEvents : "");
innerStart();
......
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