| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 230 |
| 231 if (world->isMainWorld()) | 231 if (world->isMainWorld()) |
| 232 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; | 232 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; |
| 233 | 233 |
| 234 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); | 234 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()); |
| 235 if (iter == m_isolatedWorlds.end()) | 235 if (iter == m_isolatedWorlds.end()) |
| 236 return 0; | 236 return 0; |
| 237 return iter->value->isContextInitialized() ? iter->value.get() : 0; | 237 return iter->value->isContextInitialized() ? iter->value.get() : 0; |
| 238 } | 238 } |
| 239 | 239 |
| 240 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld* world) | 240 V8WindowShell* ScriptController::windowShell(PassRefPtr<DOMWrapperWorld> prpWorl
d) |
| 241 { | 241 { |
| 242 RefPtr<DOMWrapperWorld> world = prpWorld; |
| 242 ASSERT(world); | 243 ASSERT(world); |
| 243 | 244 |
| 244 V8WindowShell* shell = 0; | 245 V8WindowShell* shell = 0; |
| 245 if (world->isMainWorld()) | 246 if (world->isMainWorld()) |
| 246 shell = m_windowShell.get(); | 247 shell = m_windowShell.get(); |
| 247 else { | 248 else { |
| 248 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()
); | 249 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId()
); |
| 249 if (iter != m_isolatedWorlds.end()) | 250 if (iter != m_isolatedWorlds.end()) |
| 250 shell = iter->value.get(); | 251 shell = iter->value.get(); |
| 251 else { | 252 else { |
| 252 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); | 253 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); |
| 253 shell = isolatedWorldShell.get(); | 254 shell = isolatedWorldShell.get(); |
| 254 m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release())
; | 255 m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release())
; |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) | 258 if (!shell->isContextInitialized() && shell->initializeIfNeeded()) |
| 258 m_frame->loader().dispatchDidClearWindowObjectInWorld(world); | 259 m_frame->loader().dispatchDidClearWindowObjectInWorld(world.get()); |
| 259 return shell; | 260 return shell; |
| 260 } | 261 } |
| 261 | 262 |
| 262 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() | 263 bool ScriptController::shouldBypassMainWorldContentSecurityPolicy() |
| 263 { | 264 { |
| 264 DOMWrapperWorld* world = DOMWrapperWorld::current(m_isolate); | 265 DOMWrapperWorld* world = DOMWrapperWorld::current(m_isolate); |
| 265 if (world && world->isIsolatedWorld()) | 266 if (world && world->isIsolatedWorld()) |
| 266 return world->isolatedWorldHasContentSecurityPolicy(); | 267 return world->isolatedWorldHasContentSecurityPolicy(); |
| 267 return false; | 268 return false; |
| 268 } | 269 } |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 } | 622 } |
| 622 | 623 |
| 623 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) | 624 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results) |
| 624 { | 625 { |
| 625 ASSERT(worldID > 0); | 626 ASSERT(worldID > 0); |
| 626 | 627 |
| 627 v8::HandleScope handleScope(m_isolate); | 628 v8::HandleScope handleScope(m_isolate); |
| 628 v8::Local<v8::Array> v8Results; | 629 v8::Local<v8::Array> v8Results; |
| 629 { | 630 { |
| 630 v8::EscapableHandleScope evaluateHandleScope(m_isolate); | 631 v8::EscapableHandleScope evaluateHandleScope(m_isolate); |
| 631 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(wor
ldID, extensionGroup); | 632 V8WindowShell* isolatedWorldShell = windowShell(DOMWrapperWorld::ensureI
solatedWorld(worldID, extensionGroup)); |
| 632 V8WindowShell* isolatedWorldShell = windowShell(world.get()); | |
| 633 | 633 |
| 634 if (!isolatedWorldShell->isContextInitialized()) | 634 if (!isolatedWorldShell->isContextInitialized()) |
| 635 return; | 635 return; |
| 636 | 636 |
| 637 v8::Local<v8::Context> context = isolatedWorldShell->context(); | 637 v8::Local<v8::Context> context = isolatedWorldShell->context(); |
| 638 v8::Context::Scope contextScope(context); | 638 v8::Context::Scope contextScope(context); |
| 639 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.siz
e()); | 639 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.siz
e()); |
| 640 | 640 |
| 641 for (size_t i = 0; i < sources.size(); ++i) { | 641 for (size_t i = 0; i < sources.size(); ++i) { |
| 642 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(
context, sources[i]); | 642 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(
context, sources[i]); |
| 643 if (evaluationResult.IsEmpty()) | 643 if (evaluationResult.IsEmpty()) |
| 644 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Unde
fined(m_isolate)); | 644 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Unde
fined(m_isolate)); |
| 645 resultArray->Set(i, evaluationResult); | 645 resultArray->Set(i, evaluationResult); |
| 646 } | 646 } |
| 647 | 647 |
| 648 v8Results = evaluateHandleScope.Escape(resultArray); | 648 v8Results = evaluateHandleScope.Escape(resultArray); |
| 649 } | 649 } |
| 650 | 650 |
| 651 if (results && !v8Results.IsEmpty()) { | 651 if (results && !v8Results.IsEmpty()) { |
| 652 for (size_t i = 0; i < v8Results->Length(); ++i) | 652 for (size_t i = 0; i < v8Results->Length(); ++i) |
| 653 results->append(ScriptValue(v8Results->Get(i), m_isolate)); | 653 results->append(ScriptValue(v8Results->Get(i), m_isolate)); |
| 654 } | 654 } |
| 655 } | 655 } |
| 656 | 656 |
| 657 } // namespace WebCore | 657 } // namespace WebCore |
| OLD | NEW |