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