| 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 return ScriptValue(object); | 319 return ScriptValue(object); |
| 320 } | 320 } |
| 321 | 321 |
| 322 bool ScriptController::initializeMainWorld() | 322 bool ScriptController::initializeMainWorld() |
| 323 { | 323 { |
| 324 if (m_windowShell->isContextInitialized()) | 324 if (m_windowShell->isContextInitialized()) |
| 325 return false; | 325 return false; |
| 326 return windowShell(mainThreadNormalWorld())->isContextInitialized(); | 326 return windowShell(mainThreadNormalWorld())->isContextInitialized(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // FIXME: Remove this function. There is currently an issue with the inspector r
elated to the call to dispatchDidClearWindowObjectInWorld in ScriptController::w
indowShell. | |
| 330 static DOMWrapperWorld* existingWindowShellWorkaroundWorld() | |
| 331 { | |
| 332 DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, world, (DOMWrapperWorld::create
UninitializedWorld())); | |
| 333 return world.get(); | |
| 334 } | |
| 335 | |
| 336 V8DOMWindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world) | 329 V8DOMWindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world) |
| 337 { | 330 { |
| 338 ASSERT(world); | 331 ASSERT(world); |
| 339 | 332 |
| 340 if (world->isMainWorld()) | 333 if (world->isMainWorld()) |
| 341 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; | 334 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; |
| 342 | 335 |
| 343 // FIXME: Remove this block. See comment with existingWindowShellWorkaroundW
orld(). | 336 // FIXME: Remove this block. See comment with existingWindowShellWorkaroundW
orld(). |
| 344 if (world->worldId() == DOMWrapperWorld::uninitializedWorldId) { | 337 if (world == existingWindowShellWorkaroundWorld()) |
| 345 ASSERT(world == existingWindowShellWorkaroundWorld()); | |
| 346 return m_windowShell.get(); | 338 return m_windowShell.get(); |
| 347 } | |
| 348 | 339 |
| 349 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); | 340 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); |
| 350 if (iter == m_isolatedWorlds.end()) | 341 if (iter == m_isolatedWorlds.end()) |
| 351 return 0; | 342 return 0; |
| 352 return iter->value->isContextInitialized() ? iter->value.get() : 0; | 343 return iter->value->isContextInitialized() ? iter->value.get() : 0; |
| 353 } | 344 } |
| 354 | 345 |
| 355 V8DOMWindowShell* ScriptController::windowShell(DOMWrapperWorld* world) | 346 V8DOMWindowShell* ScriptController::windowShell(DOMWrapperWorld* world) |
| 356 { | 347 { |
| 357 ASSERT(world); | 348 ASSERT(world); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 374 // FIXME: Remove this if clause. See comment with existingWindowShel
lWorkaroundWorld(). | 365 // FIXME: Remove this if clause. See comment with existingWindowShel
lWorkaroundWorld(). |
| 375 m_frame->loader()->dispatchDidClearWindowObjectInWorld(existingWindo
wShellWorkaroundWorld()); | 366 m_frame->loader()->dispatchDidClearWindowObjectInWorld(existingWindo
wShellWorkaroundWorld()); |
| 376 } else | 367 } else |
| 377 m_frame->loader()->dispatchDidClearWindowObjectInWorld(world); | 368 m_frame->loader()->dispatchDidClearWindowObjectInWorld(world); |
| 378 } | 369 } |
| 379 return shell; | 370 return shell; |
| 380 } | 371 } |
| 381 | 372 |
| 382 void ScriptController::evaluateInIsolatedWorld(int worldID, const Vector<ScriptS
ourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 373 void ScriptController::evaluateInIsolatedWorld(int worldID, const Vector<ScriptS
ourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| 383 { | 374 { |
| 384 // Except in the test runner, worldID should be non 0 as it conflicts with t
he mainWorldId. | 375 ASSERT(worldID > 0); |
| 385 // FIXME: Change the test runner to perform this swap and make this an ASSER
T. | |
| 386 if (UNLIKELY(!worldID)) | |
| 387 worldID = DOMWrapperWorld::uninitializedWorldId; | |
| 388 | 376 |
| 389 v8::HandleScope handleScope; | 377 v8::HandleScope handleScope; |
| 390 v8::Local<v8::Array> v8Results; | 378 v8::Local<v8::Array> v8Results; |
| 391 { | 379 { |
| 392 v8::HandleScope evaluateHandleScope; | 380 v8::HandleScope evaluateHandleScope; |
| 393 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); | 381 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); |
| 394 V8DOMWindowShell* isolatedWorldShell = windowShell(world.get()); | 382 V8DOMWindowShell* isolatedWorldShell = windowShell(world.get()); |
| 395 | 383 |
| 396 if (!isolatedWorldShell->isContextInitialized()) | 384 if (!isolatedWorldShell->isContextInitialized()) |
| 397 return; | 385 return; |
| 398 | 386 |
| 399 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolatedWor
ldShell->context()); | 387 v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolatedWor
ldShell->context()); |
| 400 v8::Context::Scope contextScope(context); | 388 v8::Context::Scope contextScope(context); |
| 401 v8::Local<v8::Array> resultArray = v8::Array::New(sources.size()); | 389 v8::Local<v8::Array> resultArray = v8::Array::New(sources.size()); |
| 402 | 390 |
| 403 for (size_t i = 0; i < sources.size(); ++i) { | 391 for (size_t i = 0; i < sources.size(); ++i) { |
| 404 v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[
i]); | 392 v8::Local<v8::Value> evaluationResult = compileAndRunScript(sources[
i]); |
| 405 if (evaluationResult.IsEmpty()) | 393 if (evaluationResult.IsEmpty()) |
| 406 evaluationResult = v8::Local<v8::Value>::New(v8::Undefined()); | 394 evaluationResult = v8::Local<v8::Value>::New(v8::Undefined()); |
| 407 resultArray->Set(i, evaluationResult); | 395 resultArray->Set(i, evaluationResult); |
| 408 } | 396 } |
| 409 | 397 |
| 410 // Mark temporary shell for weak destruction. | |
| 411 if (worldID == DOMWrapperWorld::uninitializedWorldId) { | |
| 412 isolatedWorldShell->destroyIsolatedShell(); | |
| 413 m_isolatedWorlds.remove(world->worldId()); | |
| 414 } | |
| 415 | |
| 416 v8Results = evaluateHandleScope.Close(resultArray); | 398 v8Results = evaluateHandleScope.Close(resultArray); |
| 417 } | 399 } |
| 418 | 400 |
| 419 if (results && !v8Results.IsEmpty()) { | 401 if (results && !v8Results.IsEmpty()) { |
| 420 for (size_t i = 0; i < v8Results->Length(); ++i) | 402 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 421 results->append(ScriptValue(v8Results->Get(i))); | 403 results->append(ScriptValue(v8Results->Get(i))); |
| 422 } | 404 } |
| 423 } | 405 } |
| 424 | 406 |
| 425 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() | 407 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 456 if (!isolatedWorld) | 438 if (!isolatedWorld) |
| 457 return contextForWorld(this, mainThreadNormalWorld()); | 439 return contextForWorld(this, mainThreadNormalWorld()); |
| 458 | 440 |
| 459 Frame* frame = toFrameIfNotDetached(context); | 441 Frame* frame = toFrameIfNotDetached(context); |
| 460 if (!m_frame) | 442 if (!m_frame) |
| 461 return v8::Local<v8::Context>(); | 443 return v8::Local<v8::Context>(); |
| 462 | 444 |
| 463 if (m_frame == frame) | 445 if (m_frame == frame) |
| 464 return v8::Local<v8::Context>::New(context); | 446 return v8::Local<v8::Context>::New(context); |
| 465 | 447 |
| 466 // FIXME: Need to handle weak isolated worlds correctly. | |
| 467 if (isolatedWorld->createdFromUnitializedWorld()) | |
| 468 return v8::Local<v8::Context>(); | |
| 469 | |
| 470 return contextForWorld(this, isolatedWorld); | 448 return contextForWorld(this, isolatedWorld); |
| 471 } | 449 } |
| 472 | 450 |
| 473 v8::Local<v8::Context> ScriptController::mainWorldContext() | 451 v8::Local<v8::Context> ScriptController::mainWorldContext() |
| 474 { | 452 { |
| 475 return contextForWorld(this, mainThreadNormalWorld()); | 453 return contextForWorld(this, mainThreadNormalWorld()); |
| 476 } | 454 } |
| 477 | 455 |
| 478 v8::Local<v8::Context> ScriptController::mainWorldContext(Frame* frame) | 456 v8::Local<v8::Context> ScriptController::mainWorldContext(Frame* frame) |
| 479 { | 457 { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 | 790 |
| 813 // DocumentWriter::replaceDocument can cause the DocumentLoader to get d
eref'ed and possible destroyed, | 791 // DocumentWriter::replaceDocument can cause the DocumentLoader to get d
eref'ed and possible destroyed, |
| 814 // so protect it with a RefPtr. | 792 // so protect it with a RefPtr. |
| 815 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) | 793 if (RefPtr<DocumentLoader> loader = m_frame->document()->loader()) |
| 816 loader->writer()->replaceDocument(scriptResult, ownerDocument.get())
; | 794 loader->writer()->replaceDocument(scriptResult, ownerDocument.get())
; |
| 817 } | 795 } |
| 818 return true; | 796 return true; |
| 819 } | 797 } |
| 820 | 798 |
| 821 } // namespace WebCore | 799 } // namespace WebCore |
| OLD | NEW |