Chromium Code Reviews| 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 | 509 |
| 509 void ScriptController::clearWindowShell() | 510 void ScriptController::clearWindowShell() |
| 510 { | 511 { |
| 511 double start = currentTime(); | 512 double start = currentTime(); |
| 512 // V8 binding expects ScriptController::clearWindowShell only be called | 513 // V8 binding expects ScriptController::clearWindowShell only be called |
| 513 // when a frame is loading a new page. This creates a new context for the ne w page. | 514 // when a frame is loading a new page. This creates a new context for the ne w page. |
| 514 m_windowShell->clearForNavigation(); | 515 m_windowShell->clearForNavigation(); |
| 515 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i solatedWorlds.end(); ++iter) | 516 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i solatedWorlds.end(); ++iter) |
| 516 iter->value->clearForNavigation(); | 517 iter->value->clearForNavigation(); |
| 517 V8GCController::hintForCollectGarbage(); | 518 V8GCController::hintForCollectGarbage(); |
| 519 clearScriptPreprocessor(); | |
| 518 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo wShell", (currentTime() - start) * 1000, 0, 10000, 50); | 520 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo wShell", (currentTime() - start) * 1000, 0, 10000, 50); |
| 519 } | 521 } |
| 520 | 522 |
| 521 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 523 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 522 { | 524 { |
| 523 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma xCallStackSizeToCapture, stackTraceOptions); | 525 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma xCallStackSizeToCapture, stackTraceOptions); |
| 524 } | 526 } |
| 525 | 527 |
| 526 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se curityOrigin*> >& result) | 528 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se curityOrigin*> >& result) |
| 527 { | 529 { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 | 641 |
| 640 String scriptResult; | 642 String scriptResult; |
| 641 if (!result.getString(scriptResult)) | 643 if (!result.getString(scriptResult)) |
| 642 return true; | 644 return true; |
| 643 | 645 |
| 644 // We're still in a frame, so there should be a DocumentLoader. | 646 // We're still in a frame, so there should be a DocumentLoader. |
| 645 ASSERT(m_frame->document()->loader()); | 647 ASSERT(m_frame->document()->loader()); |
| 646 | 648 |
| 647 if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangeP ending()) | 649 if (!locationChangeBefore && m_frame->navigationScheduler()->locationChangeP ending()) |
| 648 return true; | 650 return true; |
| 649 | 651 |
| 650 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref 'ed and possible destroyed, | 652 // DocumentWriter::replaceDocument can cause the DocumentLoader to get deref 'ed and possible destroyed, |
| 651 // so protect it with a RefPtr. | 653 // so protect it with a RefPtr. |
| 652 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) | 654 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) |
| 653 loader->replaceDocument(scriptResult, ownerDocument.get()); | 655 loader->replaceDocument(scriptResult, ownerDocument.get()); |
| 654 return true; | 656 return true; |
| 655 } | 657 } |
| 656 | 658 |
| 657 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s ourceCode) | 659 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s ourceCode) |
| 658 { | 660 { |
| 659 String sourceURL = sourceCode.url(); | 661 String sourceURL = sourceCode.url(); |
| 660 const String* savedSourceURL = m_sourceURL; | 662 const String* savedSourceURL = m_sourceURL; |
| 661 m_sourceURL = &sourceURL; | 663 m_sourceURL = &sourceURL; |
| 662 | 664 |
| 663 v8::HandleScope handleScope; | 665 v8::HandleScope handleScope; |
| 664 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra me); | 666 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra me); |
| 665 if (v8Context.IsEmpty()) | 667 if (v8Context.IsEmpty()) |
| 666 return ScriptValue(); | 668 return ScriptValue(); |
| 667 | 669 |
| 670 String processedString = m_frame->script()->preprocess(sourceCode.source(), sourceURL); | |
|
haraken
2013/07/11 01:13:59
What's the difference between preprocess() and m_f
johnjbarton
2013/07/11 19:14:42
Done.
| |
| 671 ScriptSourceCode processedSourceCode(processedString, sourceCode.url(), sour ceCode.startPosition()); | |
| 672 | |
| 668 v8::Context::Scope scope(v8Context); | 673 v8::Context::Scope scope(v8Context); |
| 669 RefPtr<Frame> protect(m_frame); | 674 RefPtr<Frame> protect(m_frame); |
| 670 v8::Local<v8::Value> object = compileAndRunScript(sourceCode); | 675 v8::Local<v8::Value> object = compileAndRunScript(processedSourceCode); |
| 671 | 676 |
| 672 m_sourceURL = savedSourceURL; | 677 m_sourceURL = savedSourceURL; |
| 673 | 678 |
| 674 if (object.IsEmpty()) | 679 if (object.IsEmpty()) |
| 675 return ScriptValue(); | 680 return ScriptValue(); |
| 676 | 681 |
| 677 return ScriptValue(object); | 682 return ScriptValue(object); |
| 678 } | 683 } |
| 679 | 684 |
| 680 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 685 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 704 | 709 |
| 705 v8Results = evaluateHandleScope.Close(resultArray); | 710 v8Results = evaluateHandleScope.Close(resultArray); |
| 706 } | 711 } |
| 707 | 712 |
| 708 if (results && !v8Results.IsEmpty()) { | 713 if (results && !v8Results.IsEmpty()) { |
| 709 for (size_t i = 0; i < v8Results->Length(); ++i) | 714 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 710 results->append(ScriptValue(v8Results->Get(i))); | 715 results->append(ScriptValue(v8Results->Get(i))); |
| 711 } | 716 } |
| 712 } | 717 } |
| 713 | 718 |
| 719 bool ScriptController::hasScriptPreprocessor() | |
| 720 { | |
| 721 return m_scriptPreprocessor && m_scriptPreprocessor->hasPreprocessorFunction (); | |
| 722 } | |
| 723 | |
| 724 bool ScriptController::isPreprocessingScript() | |
| 725 { | |
| 726 return hasScriptPreprocessor() && m_scriptPreprocessor->isPreprocessing(); | |
| 727 } | |
| 728 | |
| 729 void ScriptController::setScriptPreprocessor(const String& preprocessorBody) | |
| 730 { | |
| 731 // We delay the creation of the preprocess until just before the first JS fr om the | |
| 732 // Web page to ensure that the debugger's console initialization code has co mpleted. | |
| 733 m_preprocessorSource = preprocessorBody; | |
| 734 } | |
| 735 | |
| 736 void ScriptController::clearScriptPreprocessor() | |
| 737 { | |
| 738 m_scriptPreprocessor.clear(); | |
| 739 m_preprocessorSource = String(); | |
| 740 } | |
| 741 | |
| 742 String ScriptController::preprocess(const String& scriptSource, const String& sc riptName) | |
|
haraken
2013/07/11 01:13:59
Would you add a comment here about the exact condi
johnjbarton
2013/07/11 19:14:42
Done. (The comment was also in the .h file).
| |
| 743 { | |
| 744 if (m_preprocessorSource.isEmpty()) | |
| 745 return scriptSource; | |
| 746 | |
| 747 if (!m_frame->page()) | |
| 748 return scriptSource; | |
| 749 | |
| 750 if (!m_scriptPreprocessor) | |
| 751 m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(m_preprocessorSou rce, this, m_frame->page()->console())); | |
| 752 | |
| 753 if (!m_scriptPreprocessor->hasPreprocessorFunction()) | |
| 754 return scriptSource; | |
| 755 | |
| 756 return m_scriptPreprocessor->preprocessSourceCode(scriptSource, scriptName); | |
| 757 } | |
|
haraken
2013/07/11 01:13:59
I'm not happy with having a lot of proxy methods t
johnjbarton
2013/07/11 19:14:42
Two objectives lead to proxy methods:
1) encapsu
| |
| 758 | |
| 759 | |
| 714 } // namespace WebCore | 760 } // namespace WebCore |
| OLD | NEW |