| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "sky/engine/core/inspector/InspectorTraceEvents.h" | 44 #include "sky/engine/core/inspector/InspectorTraceEvents.h" |
| 45 #include "sky/engine/v8_inspector/inspector_host.h" | 45 #include "sky/engine/v8_inspector/inspector_host.h" |
| 46 #include "sky/engine/v8_inspector/ScriptDebugListener.h" | 46 #include "sky/engine/v8_inspector/ScriptDebugListener.h" |
| 47 #include "sky/engine/wtf/OwnPtr.h" | 47 #include "sky/engine/wtf/OwnPtr.h" |
| 48 #include "sky/engine/wtf/PassOwnPtr.h" | 48 #include "sky/engine/wtf/PassOwnPtr.h" |
| 49 #include "sky/engine/wtf/StdLibExtras.h" | 49 #include "sky/engine/wtf/StdLibExtras.h" |
| 50 #include "sky/engine/wtf/TemporaryChange.h" | 50 #include "sky/engine/wtf/TemporaryChange.h" |
| 51 | 51 |
| 52 namespace blink { | 52 namespace blink { |
| 53 | 53 |
| 54 static LocalFrame* retrieveFrameWithGlobalObjectCheck(v8::Handle<v8::Context> co
ntext) | |
| 55 { | |
| 56 if (context.IsEmpty()) | |
| 57 return 0; | |
| 58 | |
| 59 // FIXME: This is a temporary hack for crbug.com/345014. | |
| 60 // Currently it's possible that V8 can trigger Debugger::ProcessDebugEvent f
or a context | |
| 61 // that is being initialized (i.e., inside Context::New() of the context). | |
| 62 // We should fix the V8 side so that it won't trigger the event for a half-b
aked context | |
| 63 // because there is no way in the embedder side to check if the context is h
alf-baked or not. | |
| 64 if (isMainThread() && DOMWrapperWorld::windowIsBeingInitialized()) | |
| 65 return 0; | |
| 66 | |
| 67 v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(contex
t->Global(), context->GetIsolate()); | |
| 68 if (global.IsEmpty()) | |
| 69 return 0; | |
| 70 | |
| 71 return toFrameIfNotDetached(context); | |
| 72 } | |
| 73 | |
| 74 void PageScriptDebugServer::setPreprocessorSource(const String& preprocessorSour
ce) | |
| 75 { | |
| 76 if (preprocessorSource.isEmpty()) | |
| 77 m_preprocessorSourceCode.clear(); | |
| 78 else | |
| 79 m_preprocessorSourceCode = adoptPtr(new ScriptSourceCode(preprocessorSou
rce)); | |
| 80 m_scriptPreprocessor.clear(); | |
| 81 } | |
| 82 | |
| 83 PageScriptDebugServer& PageScriptDebugServer::shared() | 54 PageScriptDebugServer& PageScriptDebugServer::shared() |
| 84 { | 55 { |
| 85 DEFINE_STATIC_LOCAL(PageScriptDebugServer, server, ()); | 56 DEFINE_STATIC_LOCAL(PageScriptDebugServer, server, ()); |
| 86 return server; | 57 return server; |
| 87 } | 58 } |
| 88 | 59 |
| 89 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0; | 60 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0; |
| 90 | 61 |
| 91 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate) | 62 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate) |
| 92 { | 63 { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 listener->didContinue(); | 185 listener->didContinue(); |
| 215 | 186 |
| 216 m_pausedHost = 0; | 187 m_pausedHost = 0; |
| 217 } | 188 } |
| 218 | 189 |
| 219 void PageScriptDebugServer::quitMessageLoopOnPause() | 190 void PageScriptDebugServer::quitMessageLoopOnPause() |
| 220 { | 191 { |
| 221 m_clientMessageLoop->quitNow(); | 192 m_clientMessageLoop->quitNow(); |
| 222 } | 193 } |
| 223 | 194 |
| 224 void PageScriptDebugServer::preprocessBeforeCompile(const v8::Debug::EventDetail
s& eventDetails) | |
| 225 { | |
| 226 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext(); | |
| 227 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(eventContext); | |
| 228 if (!frame) | |
| 229 return; | |
| 230 | |
| 231 if (!canPreprocess(frame)) | |
| 232 return; | |
| 233 | |
| 234 v8::Handle<v8::Object> eventData = eventDetails.GetEventData(); | |
| 235 v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext(); | |
| 236 v8::Context::Scope contextScope(debugContext); | |
| 237 v8::TryCatch tryCatch; | |
| 238 // <script> tag source and attribute value source are preprocessed before we
enter V8. | |
| 239 // Avoid preprocessing any internal scripts by processing only eval source i
n this V8 event handler. | |
| 240 v8::Handle<v8::Value> argvEventData[] = { eventData }; | |
| 241 v8::Handle<v8::Value> v8Value = callDebuggerMethod("isEvalCompilation", WTF_
ARRAY_LENGTH(argvEventData), argvEventData); | |
| 242 if (v8Value.IsEmpty() || !v8Value->ToBoolean()->Value()) | |
| 243 return; | |
| 244 | |
| 245 // The name and source are in the JS event data. | |
| 246 String scriptName = toCoreStringWithUndefinedOrNullCheck(callDebuggerMethod(
"getScriptName", WTF_ARRAY_LENGTH(argvEventData), argvEventData)); | |
| 247 String script = toCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("get
ScriptSource", WTF_ARRAY_LENGTH(argvEventData), argvEventData)); | |
| 248 | |
| 249 String preprocessedSource = m_scriptPreprocessor->preprocessSourceCode(scri
pt, scriptName); | |
| 250 | |
| 251 v8::Handle<v8::Value> argvPreprocessedScript[] = { eventData, v8String(debug
Context->GetIsolate(), preprocessedSource) }; | |
| 252 callDebuggerMethod("setScriptSource", WTF_ARRAY_LENGTH(argvPreprocessedScrip
t), argvPreprocessedScript); | |
| 253 } | |
| 254 | |
| 255 static bool isCreatingPreprocessor = false; | |
| 256 | |
| 257 bool PageScriptDebugServer::canPreprocess(LocalFrame* frame) | |
| 258 { | |
| 259 ASSERT(frame); | |
| 260 | |
| 261 if (!m_preprocessorSourceCode || isCreatingPreprocessor) | |
| 262 return false; | |
| 263 | |
| 264 // We delay the creation of the preprocessor until just before the first JS
from the | |
| 265 // Web page to ensure that the debugger's console initialization code has co
mpleted. | |
| 266 if (!m_scriptPreprocessor) { | |
| 267 TemporaryChange<bool> isPreprocessing(isCreatingPreprocessor, true); | |
| 268 m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(*m_preprocessorSo
urceCode.get(), frame)); | |
| 269 } | |
| 270 | |
| 271 if (m_scriptPreprocessor->isValid()) | |
| 272 return true; | |
| 273 | |
| 274 m_scriptPreprocessor.clear(); | |
| 275 // Don't retry the compile if we fail one time. | |
| 276 m_preprocessorSourceCode.clear(); | |
| 277 return false; | |
| 278 } | |
| 279 | |
| 280 // Source to Source processing iff debugger enabled and it has loaded a preproce
ssor. | |
| 281 PassOwnPtr<ScriptSourceCode> PageScriptDebugServer::preprocess(LocalFrame* frame
, const ScriptSourceCode& sourceCode) | |
| 282 { | |
| 283 if (!canPreprocess(frame)) | |
| 284 return PassOwnPtr<ScriptSourceCode>(); | |
| 285 | |
| 286 String preprocessedSource = m_scriptPreprocessor->preprocessSourceCode(sourc
eCode.source(), sourceCode.url()); | |
| 287 return adoptPtr(new ScriptSourceCode(preprocessedSource, sourceCode.url())); | |
| 288 } | |
| 289 | |
| 290 String PageScriptDebugServer::preprocessEventListener(LocalFrame* frame, const S
tring& source, const String& url, const String& functionName) | |
| 291 { | |
| 292 if (!canPreprocess(frame)) | |
| 293 return source; | |
| 294 | |
| 295 return m_scriptPreprocessor->preprocessSourceCode(source, url, functionName)
; | |
| 296 } | |
| 297 | |
| 298 void PageScriptDebugServer::clearPreprocessor() | |
| 299 { | |
| 300 m_scriptPreprocessor.clear(); | |
| 301 } | |
| 302 | |
| 303 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |