| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 v8::RegisterExtension(extension); | 448 v8::RegisterExtension(extension); |
| 449 registeredExtensions().append(extension); | 449 registeredExtensions().append(extension); |
| 450 } | 450 } |
| 451 | 451 |
| 452 static NPObject* createNoScriptObject() | 452 static NPObject* createNoScriptObject() |
| 453 { | 453 { |
| 454 notImplemented(); | 454 notImplemented(); |
| 455 return 0; | 455 return 0; |
| 456 } | 456 } |
| 457 | 457 |
| 458 static NPObject* createScriptObject(Frame* frame) | 458 static NPObject* createScriptObject(Frame* frame, v8::Isolate* isolate) |
| 459 { | 459 { |
| 460 v8::HandleScope handleScope; | 460 v8::HandleScope handleScope(isolate); |
| 461 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(frame
); | 461 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(frame
); |
| 462 if (v8Context.IsEmpty()) | 462 if (v8Context.IsEmpty()) |
| 463 return createNoScriptObject(); | 463 return createNoScriptObject(); |
| 464 | 464 |
| 465 v8::Context::Scope scope(v8Context); | 465 v8::Context::Scope scope(v8Context); |
| 466 DOMWindow* window = frame->domWindow(); | 466 DOMWindow* window = frame->domWindow(); |
| 467 v8::Handle<v8::Value> global = toV8(window, v8::Handle<v8::Object>(), v8Cont
ext->GetIsolate()); | 467 v8::Handle<v8::Value> global = toV8(window, v8::Handle<v8::Object>(), v8Cont
ext->GetIsolate()); |
| 468 ASSERT(global->IsObject()); | 468 ASSERT(global->IsObject()); |
| 469 | 469 |
| 470 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(global), windo
w); | 470 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(global), windo
w); |
| 471 } | 471 } |
| 472 | 472 |
| 473 NPObject* ScriptController::windowScriptNPObject() | 473 NPObject* ScriptController::windowScriptNPObject() |
| 474 { | 474 { |
| 475 if (m_windowScriptNPObject) | 475 if (m_windowScriptNPObject) |
| 476 return m_windowScriptNPObject; | 476 return m_windowScriptNPObject; |
| 477 | 477 |
| 478 if (canExecuteScripts(NotAboutToExecuteScript)) { | 478 if (canExecuteScripts(NotAboutToExecuteScript)) { |
| 479 // JavaScript is enabled, so there is a JavaScript window object. | 479 // JavaScript is enabled, so there is a JavaScript window object. |
| 480 // Return an NPObject bound to the window object. | 480 // Return an NPObject bound to the window object. |
| 481 m_windowScriptNPObject = createScriptObject(m_frame); | 481 m_windowScriptNPObject = createScriptObject(m_frame, m_isolate); |
| 482 _NPN_RegisterObject(m_windowScriptNPObject, 0); | 482 _NPN_RegisterObject(m_windowScriptNPObject, 0); |
| 483 } else { | 483 } else { |
| 484 // JavaScript is not enabled, so we cannot bind the NPObject to the | 484 // JavaScript is not enabled, so we cannot bind the NPObject to the |
| 485 // JavaScript window object. Instead, we create an NPObject of a | 485 // JavaScript window object. Instead, we create an NPObject of a |
| 486 // different class, one which is not bound to a JavaScript object. | 486 // different class, one which is not bound to a JavaScript object. |
| 487 m_windowScriptNPObject = createNoScriptObject(); | 487 m_windowScriptNPObject = createNoScriptObject(); |
| 488 } | 488 } |
| 489 return m_windowScriptNPObject; | 489 return m_windowScriptNPObject; |
| 490 } | 490 } |
| 491 | 491 |
| 492 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) | 492 NPObject* ScriptController::createScriptObjectForPluginElement(HTMLPlugInElement
* plugin) |
| 493 { | 493 { |
| 494 // Can't create NPObjects when JavaScript is disabled. | 494 // Can't create NPObjects when JavaScript is disabled. |
| 495 if (!canExecuteScripts(NotAboutToExecuteScript)) | 495 if (!canExecuteScripts(NotAboutToExecuteScript)) |
| 496 return createNoScriptObject(); | 496 return createNoScriptObject(); |
| 497 | 497 |
| 498 v8::HandleScope handleScope; | 498 v8::HandleScope handleScope(m_isolate); |
| 499 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); | 499 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); |
| 500 if (v8Context.IsEmpty()) | 500 if (v8Context.IsEmpty()) |
| 501 return createNoScriptObject(); | 501 return createNoScriptObject(); |
| 502 v8::Context::Scope scope(v8Context); | 502 v8::Context::Scope scope(v8Context); |
| 503 | 503 |
| 504 DOMWindow* window = m_frame->domWindow(); | 504 DOMWindow* window = m_frame->domWindow(); |
| 505 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); | 505 v8::Handle<v8::Value> v8plugin = toV8(plugin, v8::Handle<v8::Object>(), v8Co
ntext->GetIsolate()); |
| 506 if (!v8plugin->IsObject()) | 506 if (!v8plugin->IsObject()) |
| 507 return createNoScriptObject(); | 507 return createNoScriptObject(); |
| 508 | 508 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 521 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); | 521 HistogramSupport::histogramCustomCounts("WebCore.ScriptController.clearWindo
wShell", (currentTime() - start) * 1000, 0, 10000, 50); |
| 522 } | 522 } |
| 523 | 523 |
| 524 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 524 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 525 { | 525 { |
| 526 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 526 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
| 527 } | 527 } |
| 528 | 528 |
| 529 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 529 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
| 530 { | 530 { |
| 531 v8::HandleScope handleScope; | 531 v8::HandleScope handleScope(m_isolate); |
| 532 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { | 532 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { |
| 533 V8WindowShell* isolatedWorldShell = it->value.get(); | 533 V8WindowShell* isolatedWorldShell = it->value.get(); |
| 534 SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecur
ityOrigin(); | 534 SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecur
ityOrigin(); |
| 535 if (!origin) | 535 if (!origin) |
| 536 continue; | 536 continue; |
| 537 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); | 537 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); |
| 538 if (v8Context.IsEmpty()) | 538 if (v8Context.IsEmpty()) |
| 539 continue; | 539 continue; |
| 540 ScriptState* scriptState = ScriptState::forContext(v8Context); | 540 ScriptState* scriptState = ScriptState::forContext(v8Context); |
| 541 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig
in)); | 541 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig
in)); |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 | 544 |
| 545 bool ScriptController::setContextDebugId(int debugId) | 545 bool ScriptController::setContextDebugId(int debugId) |
| 546 { | 546 { |
| 547 ASSERT(debugId > 0); | 547 ASSERT(debugId > 0); |
| 548 if (!m_windowShell->isContextInitialized()) | 548 if (!m_windowShell->isContextInitialized()) |
| 549 return false; | 549 return false; |
| 550 v8::HandleScope scope; | 550 v8::HandleScope scope(m_isolate); |
| 551 v8::Local<v8::Context> context = m_windowShell->context(); | 551 v8::Local<v8::Context> context = m_windowShell->context(); |
| 552 return V8PerContextDebugData::setContextDebugData(context, "page", debugId); | 552 return V8PerContextDebugData::setContextDebugData(context, "page", debugId); |
| 553 } | 553 } |
| 554 | 554 |
| 555 int ScriptController::contextDebugId(v8::Handle<v8::Context> context) | 555 int ScriptController::contextDebugId(v8::Handle<v8::Context> context) |
| 556 { | 556 { |
| 557 return V8PerContextDebugData::contextDebugId(context); | 557 return V8PerContextDebugData::contextDebugId(context); |
| 558 } | 558 } |
| 559 | 559 |
| 560 void ScriptController::updateDocument() | 560 void ScriptController::updateDocument() |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 loader->replaceDocument(scriptResult, ownerDocument.get()); | 656 loader->replaceDocument(scriptResult, ownerDocument.get()); |
| 657 return true; | 657 return true; |
| 658 } | 658 } |
| 659 | 659 |
| 660 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
ourceCode, AccessControlStatus corsStatus) | 660 ScriptValue ScriptController::executeScriptInMainWorld(const ScriptSourceCode& s
ourceCode, AccessControlStatus corsStatus) |
| 661 { | 661 { |
| 662 String sourceURL = sourceCode.url(); | 662 String sourceURL = sourceCode.url(); |
| 663 const String* savedSourceURL = m_sourceURL; | 663 const String* savedSourceURL = m_sourceURL; |
| 664 m_sourceURL = &sourceURL; | 664 m_sourceURL = &sourceURL; |
| 665 | 665 |
| 666 v8::HandleScope handleScope; | 666 v8::HandleScope handleScope(m_isolate); |
| 667 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); | 667 v8::Handle<v8::Context> v8Context = ScriptController::mainWorldContext(m_fra
me); |
| 668 if (v8Context.IsEmpty()) | 668 if (v8Context.IsEmpty()) |
| 669 return ScriptValue(); | 669 return ScriptValue(); |
| 670 | 670 |
| 671 RefPtr<Frame> protect(m_frame); | 671 RefPtr<Frame> protect(m_frame); |
| 672 if (m_frame->loader()->stateMachine()->isDisplayingInitialEmptyDocument()) | 672 if (m_frame->loader()->stateMachine()->isDisplayingInitialEmptyDocument()) |
| 673 m_frame->loader()->didAccessInitialDocument(); | 673 m_frame->loader()->didAccessInitialDocument(); |
| 674 | 674 |
| 675 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio
n::preprocess(m_frame, sourceCode); | 675 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio
n::preprocess(m_frame, sourceCode); |
| 676 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma
ybeProcessedSourceCode : sourceCode; | 676 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma
ybeProcessedSourceCode : sourceCode; |
| 677 | 677 |
| 678 v8::Context::Scope scope(v8Context); | 678 v8::Context::Scope scope(v8Context); |
| 679 v8::Local<v8::Value> object = compileAndRunScript(sourceCodeToCompile, corsS
tatus); | 679 v8::Local<v8::Value> object = compileAndRunScript(sourceCodeToCompile, corsS
tatus); |
| 680 | 680 |
| 681 m_sourceURL = savedSourceURL; | 681 m_sourceURL = savedSourceURL; |
| 682 | 682 |
| 683 if (object.IsEmpty()) | 683 if (object.IsEmpty()) |
| 684 return ScriptValue(); | 684 return ScriptValue(); |
| 685 | 685 |
| 686 return ScriptValue(object); | 686 return ScriptValue(object); |
| 687 } | 687 } |
| 688 | 688 |
| 689 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 689 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| 690 { | 690 { |
| 691 ASSERT(worldID > 0); | 691 ASSERT(worldID > 0); |
| 692 | 692 |
| 693 v8::HandleScope handleScope; | 693 v8::HandleScope handleScope(m_isolate); |
| 694 v8::Local<v8::Array> v8Results; | 694 v8::Local<v8::Array> v8Results; |
| 695 { | 695 { |
| 696 v8::HandleScope evaluateHandleScope; | 696 v8::HandleScope evaluateHandleScope(m_isolate); |
| 697 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); | 697 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); |
| 698 V8WindowShell* isolatedWorldShell = windowShell(world.get()); | 698 V8WindowShell* isolatedWorldShell = windowShell(world.get()); |
| 699 | 699 |
| 700 if (!isolatedWorldShell->isContextInitialized()) | 700 if (!isolatedWorldShell->isContextInitialized()) |
| 701 return; | 701 return; |
| 702 | 702 |
| 703 v8::Local<v8::Context> context = isolatedWorldShell->context(); | 703 v8::Local<v8::Context> context = isolatedWorldShell->context(); |
| 704 v8::Context::Scope contextScope(context); | 704 v8::Context::Scope contextScope(context); |
| 705 v8::Local<v8::Array> resultArray = v8::Array::New(sources.size()); | 705 v8::Local<v8::Array> resultArray = v8::Array::New(sources.size()); |
| 706 | 706 |
| 707 for (size_t i = 0; i < sources.size(); ++i) { | 707 for (size_t i = 0; i < sources.size(); ++i) { |
| 708 v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[
i]); | 708 v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[
i]); |
| 709 if (evaluationResult.IsEmpty()) | 709 if (evaluationResult.IsEmpty()) |
| 710 evaluationResult = v8::Local<v8::Value>::New(v8::Undefined()); | 710 evaluationResult = v8::Local<v8::Value>::New(v8::Undefined()); |
| 711 resultArray->Set(i, evaluationResult); | 711 resultArray->Set(i, evaluationResult); |
| 712 } | 712 } |
| 713 | 713 |
| 714 v8Results = evaluateHandleScope.Close(resultArray); | 714 v8Results = evaluateHandleScope.Close(resultArray); |
| 715 } | 715 } |
| 716 | 716 |
| 717 if (results && !v8Results.IsEmpty()) { | 717 if (results && !v8Results.IsEmpty()) { |
| 718 for (size_t i = 0; i < v8Results->Length(); ++i) | 718 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 719 results->append(ScriptValue(v8Results->Get(i))); | 719 results->append(ScriptValue(v8Results->Get(i))); |
| 720 } | 720 } |
| 721 } | 721 } |
| 722 | 722 |
| 723 } // namespace WebCore | 723 } // namespace WebCore |
| OLD | NEW |