| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2009 Apple 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 are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * 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 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "bindings/v8/ScriptController.h" | 33 #include "bindings/v8/ScriptController.h" |
| 34 | 34 |
| 35 #include "V8Event.h" | 35 #include "V8Event.h" |
| 36 #include "V8HTMLElement.h" | 36 #include "V8HTMLElement.h" |
| 37 #include "V8Window.h" | 37 #include "V8Window.h" |
| 38 #include "bindings/v8/BindingSecurity.h" | 38 #include "bindings/v8/BindingSecurity.h" |
| 39 #include "bindings/v8/NPV8Object.h" | 39 #include "bindings/v8/NPV8Object.h" |
| 40 #include "bindings/v8/ScriptCallStackFactory.h" | 40 #include "bindings/v8/ScriptCallStackFactory.h" |
| 41 #include "bindings/v8/ScriptPreprocessor.h" |
| 41 #include "bindings/v8/ScriptSourceCode.h" | 42 #include "bindings/v8/ScriptSourceCode.h" |
| 42 #include "bindings/v8/ScriptValue.h" | 43 #include "bindings/v8/ScriptValue.h" |
| 43 #include "bindings/v8/V8Binding.h" | 44 #include "bindings/v8/V8Binding.h" |
| 44 #include "bindings/v8/V8GCController.h" | 45 #include "bindings/v8/V8GCController.h" |
| 45 #include "bindings/v8/V8HiddenPropertyName.h" | 46 #include "bindings/v8/V8HiddenPropertyName.h" |
| 46 #include "bindings/v8/V8NPObject.h" | 47 #include "bindings/v8/V8NPObject.h" |
| 47 #include "bindings/v8/V8PerContextData.h" | 48 #include "bindings/v8/V8PerContextData.h" |
| 48 #include "bindings/v8/V8ScriptRunner.h" | 49 #include "bindings/v8/V8ScriptRunner.h" |
| 49 #include "bindings/v8/V8WindowShell.h" | 50 #include "bindings/v8/V8WindowShell.h" |
| 50 #include "bindings/v8/npruntime_impl.h" | 51 #include "bindings/v8/npruntime_impl.h" |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 512 |
| 512 void ScriptController::clearWindowShell() | 513 void ScriptController::clearWindowShell() |
| 513 { | 514 { |
| 514 double start = currentTime(); | 515 double start = currentTime(); |
| 515 // V8 binding expects ScriptController::clearWindowShell only be called | 516 // V8 binding expects ScriptController::clearWindowShell only be called |
| 516 // when a frame is loading a new page. This creates a new context for the ne
w page. | 517 // when a frame is loading a new page. This creates a new context for the ne
w page. |
| 517 m_windowShell->clearForNavigation(); | 518 m_windowShell->clearForNavigation(); |
| 518 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 519 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 519 iter->value->clearForNavigation(); | 520 iter->value->clearForNavigation(); |
| 520 V8GCController::hintForCollectGarbage(); | 521 V8GCController::hintForCollectGarbage(); |
| 522 clearScriptPreprocessor(); |
| 521 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); | 523 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); |
| 522 } | 524 } |
| 523 | 525 |
| 524 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 526 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 525 { | 527 { |
| 526 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 528 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
| 527 } | 529 } |
| 528 | 530 |
| 529 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 531 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
| 530 { | 532 { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 644 |
| 643 String scriptResult; | 645 String scriptResult; |
| 644 if (!result.getString(scriptResult)) | 646 if (!result.getString(scriptResult)) |
| 645 return true; | 647 return true; |
| 646 | 648 |
| 647 // We're still in a frame, so there should be a DocumentLoader. | 649 // We're still in a frame, so there should be a DocumentLoader. |
| 648 ASSERT(m_frame->document()->loader()); | 650 ASSERT(m_frame->document()->loader()); |
| 649 | 651 |
| 650 if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangeP
ending()) | 652 if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangeP
ending()) |
| 651 return true; | 653 return true; |
| 652 | 654 |
| 653 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref
'ed and possible destroyed, | 655 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref
'ed and possible destroyed, |
| 654 // so protect it with a RefPtr. | 656 // so protect it with a RefPtr. |
| 655 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) | 657 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) |
| 656 loader->replaceDocument(scriptResult, ownerDocument.get()); | 658 loader->replaceDocument(scriptResult, ownerDocument.get()); |
| 657 return true; | 659 return true; |
| 658 } | 660 } |
| 659 | 661 |
| 660 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
ourceCode) | 662 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
ourceCode) |
| 661 { | 663 { |
| 662 String sourceURL = sourceCode.url(); | 664 String sourceURL = sourceCode.url(); |
| 663 const String* savedSourceURL = m_sourceURL; | 665 const String* savedSourceURL = m_sourceURL; |
| 664 m_sourceURL = &sourceURL; | 666 m_sourceURL = &sourceURL; |
| 665 | 667 |
| 666 v8::HandleScope handleScope; | 668 v8::HandleScope handleScope; |
| 667 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); | 669 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); |
| 668 if (v8Context.IsEmpty()) | 670 if (v8Context.IsEmpty()) |
| 669 return ScriptValue(); | 671 return ScriptValue(); |
| 670 | 672 |
| 673 String processedString = preprocess(sourceCode.source(), sourceURL); |
| 674 ScriptSourceCode processedSourceCode(processedString, sourceCode.url(), sour
ceCode.startPosition()); |
| 675 |
| 671 v8::Context::Scope scope(v8Context); | 676 v8::Context::Scope scope(v8Context); |
| 672 RefPtr<Frame> protect(m_frame); | 677 RefPtr<Frame> protect(m_frame); |
| 673 v8::Local<v8::Value> object = compileAndRunScript(sourceCode); | 678 v8::Local<v8::Value> object = compileAndRunScript(processedSourceCode); |
| 674 | 679 |
| 675 m_sourceURL = savedSourceURL; | 680 m_sourceURL = savedSourceURL; |
| 676 | 681 |
| 677 if (object.IsEmpty()) | 682 if (object.IsEmpty()) |
| 678 return ScriptValue(); | 683 return ScriptValue(); |
| 679 | 684 |
| 680 return ScriptValue(object); | 685 return ScriptValue(object); |
| 681 } | 686 } |
| 682 | 687 |
| 683 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 688 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 707 | 712 |
| 708 v8Results = evaluateHandleScope.Close(resultArray); | 713 v8Results = evaluateHandleScope.Close(resultArray); |
| 709 } | 714 } |
| 710 | 715 |
| 711 if (results && !v8Results.IsEmpty()) { | 716 if (results && !v8Results.IsEmpty()) { |
| 712 for (size_t i = 0; i < v8Results->Length(); ++i) | 717 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 713 results->append(ScriptValue(v8Results->Get(i))); | 718 results->append(ScriptValue(v8Results->Get(i))); |
| 714 } | 719 } |
| 715 } | 720 } |
| 716 | 721 |
| 722 void ScriptController::setScriptPreprocessor(const String& preprocessorBody) |
| 723 { |
| 724 // We delay the creation of the preprocess until just before the first JS fr
om the |
| 725 // Web page to ensure that the debugger's console initialization code has co
mpleted. |
| 726 m_preprocessorSource = preprocessorBody; |
| 727 } |
| 728 |
| 729 void ScriptController::clearScriptPreprocessor() |
| 730 { |
| 731 m_scriptPreprocessor.clear(); |
| 732 m_preprocessorSource = String(); |
| 733 } |
| 734 |
| 735 // Source to Source processing iff debugger enabled and it has loaded a preproce
ssor. |
| 736 String ScriptController::preprocess(const String& scriptSource, const String& sc
riptName) |
| 737 { |
| 738 if (m_preprocessorSource.isEmpty()) |
| 739 return scriptSource; |
| 740 |
| 741 if (!m_frame->page()) |
| 742 return scriptSource; |
| 743 |
| 744 if (!m_scriptPreprocessor) |
| 745 m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(m_preprocessorSou
rce, this, m_frame->page()->console())); |
| 746 |
| 747 return m_scriptPreprocessor->preprocessSourceCode(scriptSource, scriptName); |
| 748 } |
| 749 |
| 750 void ScriptController::preprocessEval(ScriptDebugServer* debugServer, v8::Handle
<v8::Object> eventData) |
| 751 { |
| 752 if (!m_scriptPreprocessor.get()) |
| 753 return; |
| 754 m_scriptPreprocessor->preprocessEval(debugServer, eventData); |
| 755 } |
| 756 |
| 717 } // namespace WebCore | 757 } // namespace WebCore |
| OLD | NEW |