Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010-2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2010-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 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 #include "DebuggerScriptSource.h" | 35 #include "DebuggerScriptSource.h" |
| 36 #include "V8JavaScriptCallFrame.h" | 36 #include "V8JavaScriptCallFrame.h" |
| 37 #include "bindings/v8/JavaScriptCallFrame.h" | 37 #include "bindings/v8/JavaScriptCallFrame.h" |
| 38 #include "bindings/v8/ScopedPersistent.h" | 38 #include "bindings/v8/ScopedPersistent.h" |
| 39 #include "bindings/v8/ScriptObject.h" | 39 #include "bindings/v8/ScriptObject.h" |
| 40 #include "bindings/v8/V8Binding.h" | 40 #include "bindings/v8/V8Binding.h" |
| 41 #include "bindings/v8/V8RecursionScope.h" | 41 #include "bindings/v8/V8RecursionScope.h" |
| 42 #include "core/inspector/ScriptDebugListener.h" | 42 #include "core/inspector/ScriptDebugListener.h" |
| 43 #include "wtf/StdLibExtras.h" | 43 #include "wtf/StdLibExtras.h" |
| 44 #include "wtf/StringExtras.h" | |
| 44 #include "wtf/Vector.h" | 45 #include "wtf/Vector.h" |
| 45 | 46 |
| 46 namespace WebCore { | 47 namespace WebCore { |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 class ClientDataImpl : public v8::Debug::ClientData { | 51 class ClientDataImpl : public v8::Debug::ClientData { |
| 51 public: | 52 public: |
| 52 ClientDataImpl(PassOwnPtr<ScriptDebugServer::Task> task) : m_task(task) { } | 53 ClientDataImpl(PassOwnPtr<ScriptDebugServer::Task> task) : m_task(task) { } |
| 53 virtual ~ClientDataImpl() { } | 54 virtual ~ClientDataImpl() { } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 78 v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN ame, int argc, v8::Handle<v8::Value> argv[]) | 79 v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN ame, int argc, v8::Handle<v8::Value> argv[]) |
| 79 { | 80 { |
| 80 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast(m_debugger Script.get()->Get(v8::String::NewSymbol(functionName))); | 81 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast(m_debugger Script.get()->Get(v8::String::NewSymbol(functionName))); |
| 81 V8RecursionScope::MicrotaskSuppression scope; | 82 V8RecursionScope::MicrotaskSuppression scope; |
| 82 return function->Call(m_debuggerScript.get(), argc, argv); | 83 return function->Call(m_debuggerScript.get(), argc, argv); |
| 83 } | 84 } |
| 84 | 85 |
| 85 class ScriptDebugServer::ScriptPreprocessor { | 86 class ScriptDebugServer::ScriptPreprocessor { |
| 86 WTF_MAKE_NONCOPYABLE(ScriptPreprocessor); | 87 WTF_MAKE_NONCOPYABLE(ScriptPreprocessor); |
| 87 public: | 88 public: |
| 89 | |
| 88 explicit ScriptPreprocessor(const String& preprocessorScript) | 90 explicit ScriptPreprocessor(const String& preprocessorScript) |
| 89 { | 91 { |
| 90 v8::HandleScope scope; | 92 v8::HandleScope scope; |
| 91 | 93 |
| 92 m_utilityContext.set(v8::Context::New()); | 94 m_utilityContext.set(v8::Context::New()); |
| 93 if (m_utilityContext.isEmpty()) | 95 if (m_utilityContext.isEmpty()) |
| 94 return; | 96 return; |
| 95 | 97 |
| 96 v8::Context::Scope contextScope(m_utilityContext.get()); | 98 v8::Context::Scope contextScope(m_utilityContext.get()); |
| 97 | 99 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 | 132 |
| 131 v8::TryCatch tryCatch; | 133 v8::TryCatch tryCatch; |
| 132 RecursionScopeSuppression suppressionScope; | 134 RecursionScopeSuppression suppressionScope; |
| 133 v8::Handle<v8::Value> resultValue = m_preprocessorFunction->Call(context ->Global(), 2, argv); | 135 v8::Handle<v8::Value> resultValue = m_preprocessorFunction->Call(context ->Global(), 2, argv); |
| 134 | 136 |
| 135 if (tryCatch.HasCaught()) | 137 if (tryCatch.HasCaught()) |
| 136 return sourceCode; | 138 return sourceCode; |
| 137 | 139 |
| 138 if (resultValue->IsString()) { | 140 if (resultValue->IsString()) { |
| 139 v8::String::Utf8Value utf8Value(resultValue); | 141 v8::String::Utf8Value utf8Value(resultValue); |
| 140 return String::fromUTF8(*utf8Value, utf8Value.length()); | 142 |
| 143 String preprocessed = String::fromUTF8(*utf8Value, utf8Value.length( )); | |
| 144 // Zero bytes crash the page if we are preprocessing injectedScripts | |
| 145 if (preprocessed.length() == 0) | |
| 146 return sourceCode; | |
| 147 | |
| 148 return preprocessed; | |
| 141 } | 149 } |
| 142 | 150 |
| 143 return sourceCode; | 151 return sourceCode; |
| 144 } | 152 } |
| 145 | 153 |
| 146 ~ScriptPreprocessor() | 154 ~ScriptPreprocessor() |
| 147 { | 155 { |
| 148 } | 156 } |
| 149 | 157 |
| 150 private: | 158 private: |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 ASSERT(!eventContext.IsEmpty()); | 459 ASSERT(!eventContext.IsEmpty()); |
| 452 | 460 |
| 453 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); | 461 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); |
| 454 if (listener) { | 462 if (listener) { |
| 455 v8::HandleScope scope; | 463 v8::HandleScope scope; |
| 456 if (event == v8::BeforeCompile) { | 464 if (event == v8::BeforeCompile) { |
| 457 | 465 |
| 458 if (!m_scriptPreprocessor) | 466 if (!m_scriptPreprocessor) |
| 459 return; | 467 return; |
| 460 | 468 |
| 469 // Don't preprocess debugger scripts or content scripts | |
| 470 if (V8PerContextDebugData::isSystemScope(eventContext) || V8PerConte xtDebugData::contextCategory(eventContext) == "injected") | |
|
pfeldman
2013/05/01 07:33:55
Please introduce constant for this so that we coul
| |
| 471 return; | |
| 472 | |
| 461 OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release ()); | 473 OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release ()); |
| 474 | |
| 462 v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext(); | 475 v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext(); |
| 463 v8::Context::Scope contextScope(debugContext); | 476 v8::Context::Scope contextScope(debugContext); |
| 464 v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptSource"))); | 477 v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptSource"))); |
| 465 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; | 478 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; |
| 466 v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debug gerScript.get(), 1, argv); | 479 v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debug gerScript.get(), 1, argv); |
| 467 | 480 |
| 468 v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Funct ion>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptName"))); | 481 v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Funct ion>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptName"))); |
| 469 v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() }; | 482 v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() }; |
| 470 v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_deb uggerScript.get(), 1, argv1); | 483 v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_deb uggerScript.get(), 1, argv1); |
| 471 | 484 |
| 485 v8::String::Utf8Value scriptNameUtf8Value(scriptName); | |
| 486 String scriptNameString = String::fromUTF8(*scriptNameUtf8Value, scr iptNameUtf8Value.length()); | |
| 487 if (scriptNameString.contains("data:text/html,chromewebdata")) | |
|
pfeldman
2013/05/01 07:33:55
You can't say "chromewebdata" from blink which is
| |
| 488 return; | |
| 489 | |
| 472 v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource"))); | 490 v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource"))); |
| 473 String patchedScript = preprocessor->preprocessSourceCode(toWebCoreS tringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(s criptName)); | 491 String patchedScript = preprocessor->preprocessSourceCode(toWebCoreS tringWithUndefinedOrNullCheck(script), scriptNameString); |
| 474 | 492 |
| 475 v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8Str ing(patchedScript, debugContext->GetIsolate()) }; | 493 v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8Str ing(patchedScript, debugContext->GetIsolate()) }; |
| 476 setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2); | 494 setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2); |
| 477 m_scriptPreprocessor = preprocessor.release(); | 495 m_scriptPreprocessor = preprocessor.release(); |
| 478 } else if (event == v8::AfterCompile) { | 496 } else if (event == v8::AfterCompile) { |
| 479 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); | 497 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); |
| 480 v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Func tion>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileSc ript"))); | 498 v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Func tion>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileSc ript"))); |
| 481 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; | 499 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; |
| 482 v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debugge rScript.get(), 1, argv); | 500 v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debugge rScript.get(), 1, argv); |
| 483 ASSERT(value->IsObject()); | 501 ASSERT(value->IsObject()); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 *result = ScriptValue(tryCatch.Exception()); | 651 *result = ScriptValue(tryCatch.Exception()); |
| 634 v8::Local<v8::Message> message = tryCatch.Message(); | 652 v8::Local<v8::Message> message = tryCatch.Message(); |
| 635 if (!message.IsEmpty()) | 653 if (!message.IsEmpty()) |
| 636 *exceptionMessage = toWebCoreStringWithUndefinedOrNullCheck(message- >Get()); | 654 *exceptionMessage = toWebCoreStringWithUndefinedOrNullCheck(message- >Get()); |
| 637 } else | 655 } else |
| 638 *result = ScriptValue(value); | 656 *result = ScriptValue(value); |
| 639 } | 657 } |
| 640 | 658 |
| 641 } // namespace WebCore | 659 } // namespace WebCore |
| 642 | 660 |
| OLD | NEW |