| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 return result; | 202 return result; |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool ScriptController::initializeMainWorld() | 205 bool ScriptController::initializeMainWorld() |
| 206 { | 206 { |
| 207 if (m_windowShell->isContextInitialized()) | 207 if (m_windowShell->isContextInitialized()) |
| 208 return false; | 208 return false; |
| 209 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized(); | 209 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld& world) | 212 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld* world) |
| 213 { | 213 { |
| 214 if (world.isMainWorld()) | 214 ASSERT(world); |
| 215 |
| 216 if (world->isMainWorld()) |
| 215 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; | 217 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; |
| 216 | 218 |
| 217 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | 219 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); |
| 218 if (iter == m_isolatedWorlds.end()) | 220 if (iter == m_isolatedWorlds.end()) |
| 219 return 0; | 221 return 0; |
| 220 return iter->value->isContextInitialized() ? iter->value.get() : 0; | 222 return iter->value->isContextInitialized() ? iter->value.get() : 0; |
| 221 } | 223 } |
| 222 | 224 |
| 223 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld& world) | 225 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld* world) |
| 224 { | 226 { |
| 227 ASSERT(world); |
| 228 |
| 225 V8WindowShell* shell = 0; | 229 V8WindowShell* shell = 0; |
| 226 if (world.isMainWorld()) | 230 if (world->isMainWorld()) |
| 227 shell = m_windowShell.get(); | 231 shell = m_windowShell.get(); |
| 228 else { | 232 else { |
| 229 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; | 233 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()
); |
| 230 if (iter != m_isolatedWorlds.end()) | 234 if (iter != m_isolatedWorlds.end()) |
| 231 shell = iter->value.get(); | 235 shell = iter->value.get(); |
| 232 else { | 236 else { |
| 233 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); | 237 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); |
| 234 shell = isolatedWorldShell.get(); | 238 shell = isolatedWorldShell.get(); |
| 235 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release()); | 239 m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release())
; |
| 236 } | 240 } |
| 237 } | 241 } |
| 238 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) | 242 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) |
| 239 m_frame->loader().dispatchDidClearWindowObjectInWorld(world); | 243 m_frame->loader().dispatchDidClearWindowObjectInWorld(world); |
| 240 return shell; | 244 return shell; |
| 241 } | 245 } |
| 242 | 246 |
| 243 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() | 247 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() |
| 244 { | 248 { |
| 245 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); | 249 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); |
| 246 if (context.IsEmpty() || !toDOMWindow(context)) | 250 if (context.IsEmpty() || !toDOMWindow(context)) |
| 247 return false; | 251 return false; |
| 248 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate); | 252 DOMWrapperWorld* world = DOMWrapperWorld::current(m_isolate); |
| 249 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy
() : false; | 253 return world->isIsolatedWorld() ? world->isolatedWorldHasContentSecurityPoli
cy() : false; |
| 250 } | 254 } |
| 251 | 255 |
| 252 TextPosition ScriptController::eventHandlerPosition() const | 256 TextPosition ScriptController::eventHandlerPosition() const |
| 253 { | 257 { |
| 254 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa
rser(); | 258 ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentPa
rser(); |
| 255 if (parser) | 259 if (parser) |
| 256 return parser->textPosition(); | 260 return parser->textPosition(); |
| 257 return TextPosition::minimumPosition(); | 261 return TextPosition::minimumPosition(); |
| 258 } | 262 } |
| 259 | 263 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 442 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 439 { | 443 { |
| 440 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 444 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
| 441 } | 445 } |
| 442 | 446 |
| 443 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 447 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
| 444 { | 448 { |
| 445 v8::HandleScope handleScope(m_isolate); | 449 v8::HandleScope handleScope(m_isolate); |
| 446 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { | 450 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { |
| 447 V8WindowShell* isolatedWorldShell = it->value.get(); | 451 V8WindowShell* isolatedWorldShell = it->value.get(); |
| 448 SecurityOrigin* origin = isolatedWorldShell->world().isolatedWorldSecuri
tyOrigin(); | 452 SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecur
ityOrigin(); |
| 449 if (!origin) | 453 if (!origin) |
| 450 continue; | 454 continue; |
| 451 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); | 455 v8::Local<v8::Context> v8Context = isolatedWorldShell->context(); |
| 452 if (v8Context.IsEmpty()) | 456 if (v8Context.IsEmpty()) |
| 453 continue; | 457 continue; |
| 454 ScriptState* scriptState = ScriptState::forContext(v8Context); | 458 ScriptState* scriptState = ScriptState::forContext(v8Context); |
| 455 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig
in)); | 459 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, orig
in)); |
| 456 } | 460 } |
| 457 } | 461 } |
| 458 | 462 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 608 |
| 605 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 609 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| 606 { | 610 { |
| 607 ASSERT(worldID > 0); | 611 ASSERT(worldID > 0); |
| 608 | 612 |
| 609 v8::HandleScope handleScope(m_isolate); | 613 v8::HandleScope handleScope(m_isolate); |
| 610 v8::Local<v8::Array> v8Results; | 614 v8::Local<v8::Array> v8Results; |
| 611 { | 615 { |
| 612 v8::EscapableHandleScope evaluateHandleScope(m_isolate); | 616 v8::EscapableHandleScope evaluateHandleScope(m_isolate); |
| 613 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); | 617 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); |
| 614 V8WindowShell* isolatedWorldShell = windowShell(*world); | 618 V8WindowShell* isolatedWorldShell = windowShell(world.get()); |
| 615 | 619 |
| 616 if (!isolatedWorldShell->isContextInitialized()) | 620 if (!isolatedWorldShell->isContextInitialized()) |
| 617 return; | 621 return; |
| 618 | 622 |
| 619 v8::Local<v8::Context> context = isolatedWorldShell->context(); | 623 v8::Local<v8::Context> context = isolatedWorldShell->context(); |
| 620 v8::Context::Scope contextScope(context); | 624 v8::Context::Scope contextScope(context); |
| 621 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.siz
e()); | 625 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.siz
e()); |
| 622 | 626 |
| 623 for (size_t i = 0; i < sources.size(); ++i) { | 627 for (size_t i = 0; i < sources.size(); ++i) { |
| 624 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(
context, sources[i]); | 628 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(
context, sources[i]); |
| 625 if (evaluationResult.IsEmpty()) | 629 if (evaluationResult.IsEmpty()) |
| 626 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Unde
fined(m_isolate)); | 630 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Unde
fined(m_isolate)); |
| 627 resultArray->Set(i, evaluationResult); | 631 resultArray->Set(i, evaluationResult); |
| 628 } | 632 } |
| 629 | 633 |
| 630 v8Results = evaluateHandleScope.Escape(resultArray); | 634 v8Results = evaluateHandleScope.Escape(resultArray); |
| 631 } | 635 } |
| 632 | 636 |
| 633 if (results && !v8Results.IsEmpty()) { | 637 if (results && !v8Results.IsEmpty()) { |
| 634 for (size_t i = 0; i < v8Results->Length(); ++i) | 638 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 635 results->append(ScriptValue(v8Results->Get(i), m_isolate)); | 639 results->append(ScriptValue(v8Results->Get(i), m_isolate)); |
| 636 } | 640 } |
| 637 } | 641 } |
| 638 | 642 |
| 639 } // namespace WebCore | 643 } // namespace WebCore |
| OLD | NEW |