| 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 14 matching lines...) Expand all Loading... |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 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 "V8DOMWindow.h" | |
| 36 #include "V8Event.h" | 35 #include "V8Event.h" |
| 37 #include "V8HTMLElement.h" | 36 #include "V8HTMLElement.h" |
| 37 #include "V8Window.h" |
| 38 #include "bindings/v8/BindingSecurity.h" | 38 #include "bindings/v8/BindingSecurity.h" |
| 39 #include "bindings/v8/NPObjectWrapper.h" | 39 #include "bindings/v8/NPObjectWrapper.h" |
| 40 #include "bindings/v8/NPV8Object.h" | 40 #include "bindings/v8/NPV8Object.h" |
| 41 #include "bindings/v8/ScriptCallStackFactory.h" | 41 #include "bindings/v8/ScriptCallStackFactory.h" |
| 42 #include "bindings/v8/ScriptSourceCode.h" | 42 #include "bindings/v8/ScriptSourceCode.h" |
| 43 #include "bindings/v8/ScriptValue.h" | 43 #include "bindings/v8/ScriptValue.h" |
| 44 #include "bindings/v8/V8Binding.h" | 44 #include "bindings/v8/V8Binding.h" |
| 45 #include "bindings/v8/V8DOMWindowShell.h" | |
| 46 #include "bindings/v8/V8GCController.h" | 45 #include "bindings/v8/V8GCController.h" |
| 47 #include "bindings/v8/V8HiddenPropertyName.h" | 46 #include "bindings/v8/V8HiddenPropertyName.h" |
| 48 #include "bindings/v8/V8NPObject.h" | 47 #include "bindings/v8/V8NPObject.h" |
| 49 #include "bindings/v8/V8PerContextData.h" | 48 #include "bindings/v8/V8PerContextData.h" |
| 50 #include "bindings/v8/V8ScriptRunner.h" | 49 #include "bindings/v8/V8ScriptRunner.h" |
| 50 #include "bindings/v8/V8WindowShell.h" |
| 51 #include "bindings/v8/npruntime_impl.h" | 51 #include "bindings/v8/npruntime_impl.h" |
| 52 #include "bindings/v8/npruntime_priv.h" | 52 #include "bindings/v8/npruntime_priv.h" |
| 53 #include "core/dom/Document.h" | 53 #include "core/dom/Document.h" |
| 54 #include "core/dom/Event.h" | 54 #include "core/dom/Event.h" |
| 55 #include "core/dom/EventListener.h" | 55 #include "core/dom/EventListener.h" |
| 56 #include "core/dom/EventNames.h" | 56 #include "core/dom/EventNames.h" |
| 57 #include "core/dom/Node.h" | 57 #include "core/dom/Node.h" |
| 58 #include "core/dom/ScriptableDocumentParser.h" | 58 #include "core/dom/ScriptableDocumentParser.h" |
| 59 #include "core/dom/UserGestureIndicator.h" | 59 #include "core/dom/UserGestureIndicator.h" |
| 60 #include "core/html/HTMLPlugInElement.h" | 60 #include "core/html/HTMLPlugInElement.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 | 85 |
| 86 bool ScriptController::canAccessFromCurrentOrigin(Frame *frame) | 86 bool ScriptController::canAccessFromCurrentOrigin(Frame *frame) |
| 87 { | 87 { |
| 88 return !v8::Context::InContext() || BindingSecurity::shouldAllowAccessToFram
e(frame); | 88 return !v8::Context::InContext() || BindingSecurity::shouldAllowAccessToFram
e(frame); |
| 89 } | 89 } |
| 90 | 90 |
| 91 ScriptController::ScriptController(Frame* frame) | 91 ScriptController::ScriptController(Frame* frame) |
| 92 : m_frame(frame) | 92 : m_frame(frame) |
| 93 , m_sourceURL(0) | 93 , m_sourceURL(0) |
| 94 , m_isolate(v8::Isolate::GetCurrent()) | 94 , m_isolate(v8::Isolate::GetCurrent()) |
| 95 , m_windowShell(V8DOMWindowShell::create(frame, mainThreadNormalWorld(), m_i
solate)) | 95 , m_windowShell(V8WindowShell::create(frame, mainThreadNormalWorld(), m_isol
ate)) |
| 96 , m_paused(false) | 96 , m_paused(false) |
| 97 , m_wrappedWindowScriptNPObject(0) | 97 , m_wrappedWindowScriptNPObject(0) |
| 98 { | 98 { |
| 99 } | 99 } |
| 100 | 100 |
| 101 ScriptController::~ScriptController() | 101 ScriptController::~ScriptController() |
| 102 { | 102 { |
| 103 clearForClose(true); | 103 clearForClose(true); |
| 104 } | 104 } |
| 105 | 105 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 return result; | 247 return result; |
| 248 } | 248 } |
| 249 | 249 |
| 250 bool ScriptController::initializeMainWorld() | 250 bool ScriptController::initializeMainWorld() |
| 251 { | 251 { |
| 252 if (m_windowShell->isContextInitialized()) | 252 if (m_windowShell->isContextInitialized()) |
| 253 return false; | 253 return false; |
| 254 return windowShell(mainThreadNormalWorld())->isContextInitialized(); | 254 return windowShell(mainThreadNormalWorld())->isContextInitialized(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 V8DOMWindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world) | 257 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world) |
| 258 { | 258 { |
| 259 ASSERT(world); | 259 ASSERT(world); |
| 260 | 260 |
| 261 if (world->isMainWorld()) | 261 if (world->isMainWorld()) |
| 262 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; | 262 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; |
| 263 | 263 |
| 264 // FIXME: Remove this block. See comment with existingWindowShellWorkaroundW
orld(). | 264 // FIXME: Remove this block. See comment with existingWindowShellWorkaroundW
orld(). |
| 265 if (world == existingWindowShellWorkaroundWorld()) | 265 if (world == existingWindowShellWorkaroundWorld()) |
| 266 return m_windowShell.get(); | 266 return m_windowShell.get(); |
| 267 | 267 |
| 268 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); | 268 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); |
| 269 if (iter == m_isolatedWorlds.end()) | 269 if (iter == m_isolatedWorlds.end()) |
| 270 return 0; | 270 return 0; |
| 271 return iter->value->isContextInitialized() ? iter->value.get() : 0; | 271 return iter->value->isContextInitialized() ? iter->value.get() : 0; |
| 272 } | 272 } |
| 273 | 273 |
| 274 V8DOMWindowShell* ScriptController::windowShell(DOMWrapperWorld* world) | 274 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld* world) |
| 275 { | 275 { |
| 276 ASSERT(world); | 276 ASSERT(world); |
| 277 | 277 |
| 278 V8DOMWindowShell* shell = 0; | 278 V8WindowShell* shell = 0; |
| 279 if (world->isMainWorld()) | 279 if (world->isMainWorld()) |
| 280 shell = m_windowShell.get(); | 280 shell = m_windowShell.get(); |
| 281 else { | 281 else { |
| 282 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()
); | 282 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()
); |
| 283 if (iter != m_isolatedWorlds.end()) | 283 if (iter != m_isolatedWorlds.end()) |
| 284 shell = iter->value.get(); | 284 shell = iter->value.get(); |
| 285 else { | 285 else { |
| 286 OwnPtr<V8DOMWindowShell> isolatedWorldShell = V8DOMWindowShell::crea
te(m_frame, world, m_isolate); | 286 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); |
| 287 shell = isolatedWorldShell.get(); | 287 shell = isolatedWorldShell.get(); |
| 288 m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release())
; | 288 m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release())
; |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) { | 291 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) { |
| 292 if (world->isMainWorld()) { | 292 if (world->isMainWorld()) { |
| 293 // FIXME: Remove this if clause. See comment with existingWindowShel
lWorkaroundWorld(). | 293 // FIXME: Remove this if clause. See comment with existingWindowShel
lWorkaroundWorld(). |
| 294 m_frame->loader()->dispatchDidClearWindowObjectInWorld(existingWindo
wShellWorkaroundWorld()); | 294 m_frame->loader()->dispatchDidClearWindowObjectInWorld(existingWindo
wShellWorkaroundWorld()); |
| 295 } else | 295 } else |
| 296 m_frame->loader()->dispatchDidClearWindowObjectInWorld(world); | 296 m_frame->loader()->dispatchDidClearWindowObjectInWorld(world); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 | 533 |
| 534 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 534 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 535 { | 535 { |
| 536 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 536 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
| 537 } | 537 } |
| 538 | 538 |
| 539 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 539 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
| 540 { | 540 { |
| 541 v8::HandleScope handleScope; | 541 v8::HandleScope handleScope; |
| 542 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { | 542 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { |
| 543 V8DOMWindowShell* isolatedWorldShell = it->value.get(); | 543 V8WindowShell* isolatedWorldShell = it->value.get(); |
| 544 SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecur
ityOrigin(); | 544 SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecur
ityOrigin(); |
| 545 if (!origin) | 545 if (!origin) |
| 546 continue; | 546 continue; |
| 547 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); | 547 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); |
| 548 if (v8Context.IsEmpty()) | 548 if (v8Context.IsEmpty()) |
| 549 continue; | 549 continue; |
| 550 ScriptState* scriptState = ScriptState::forContext(v8Context); | 550 ScriptState* scriptState = ScriptState::forContext(v8Context); |
| 551 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig
in)); | 551 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig
in)); |
| 552 } | 552 } |
| 553 } | 553 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 692 |
| 693 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 693 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| 694 { | 694 { |
| 695 ASSERT(worldID > 0); | 695 ASSERT(worldID > 0); |
| 696 | 696 |
| 697 v8::HandleScope handleScope; | 697 v8::HandleScope handleScope; |
| 698 v8::Local<v8::Array> v8Results; | 698 v8::Local<v8::Array> v8Results; |
| 699 { | 699 { |
| 700 v8::HandleScope evaluateHandleScope; | 700 v8::HandleScope evaluateHandleScope; |
| 701 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); | 701 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); |
| 702 V8DOMWindowShell* isolatedWorldShell = windowShell(world.get()); | 702 V8WindowShell* isolatedWorldShell = windowShell(world.get()); |
| 703 | 703 |
| 704 if (!isolatedWorldShell->isContextInitialized()) | 704 if (!isolatedWorldShell->isContextInitialized()) |
| 705 return; | 705 return; |
| 706 | 706 |
| 707 v8::Local<v8::Context> context = isolatedWorldShell->context(); | 707 v8::Local<v8::Context> context = isolatedWorldShell->context(); |
| 708 v8::Context::Scope contextScope(context); | 708 v8::Context::Scope contextScope(context); |
| 709 v8::Local<v8::Array> resultArray = v8::Array::New(sources.size()); | 709 v8::Local<v8::Array> resultArray = v8::Array::New(sources.size()); |
| 710 | 710 |
| 711 for (size_t i = 0; i < sources.size(); ++i) { | 711 for (size_t i = 0; i < sources.size(); ++i) { |
| 712 v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[
i]); | 712 v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[
i]); |
| 713 if (evaluationResult.IsEmpty()) | 713 if (evaluationResult.IsEmpty()) |
| 714 evaluationResult = v8::Local<v8::Value>::New(v8::Undefined()); | 714 evaluationResult = v8::Local<v8::Value>::New(v8::Undefined()); |
| 715 resultArray->Set(i, evaluationResult); | 715 resultArray->Set(i, evaluationResult); |
| 716 } | 716 } |
| 717 | 717 |
| 718 v8Results = evaluateHandleScope.Close(resultArray); | 718 v8Results = evaluateHandleScope.Close(resultArray); |
| 719 } | 719 } |
| 720 | 720 |
| 721 if (results && !v8Results.IsEmpty()) { | 721 if (results && !v8Results.IsEmpty()) { |
| 722 for (size_t i = 0; i < v8Results->Length(); ++i) | 722 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 723 results->append(ScriptValue(v8Results->Get(i))); | 723 results->append(ScriptValue(v8Results->Get(i))); |
| 724 } | 724 } |
| 725 } | 725 } |
| 726 | 726 |
| 727 } // namespace WebCore | 727 } // namespace WebCore |
| OLD | NEW |