| 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 * Copyright (C) 2014 Opera Software ASA. All rights reserved. | 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "bindings/core/v8/ScriptSourceCode.h" | 39 #include "bindings/core/v8/ScriptSourceCode.h" |
| 40 #include "bindings/core/v8/ScriptValue.h" | 40 #include "bindings/core/v8/ScriptValue.h" |
| 41 #include "bindings/core/v8/V8Binding.h" | 41 #include "bindings/core/v8/V8Binding.h" |
| 42 #include "bindings/core/v8/V8Event.h" | 42 #include "bindings/core/v8/V8Event.h" |
| 43 #include "bindings/core/v8/V8GCController.h" | 43 #include "bindings/core/v8/V8GCController.h" |
| 44 #include "bindings/core/v8/V8HTMLElement.h" | 44 #include "bindings/core/v8/V8HTMLElement.h" |
| 45 #include "bindings/core/v8/V8NPObject.h" | 45 #include "bindings/core/v8/V8NPObject.h" |
| 46 #include "bindings/core/v8/V8PerContextData.h" | 46 #include "bindings/core/v8/V8PerContextData.h" |
| 47 #include "bindings/core/v8/V8ScriptRunner.h" | 47 #include "bindings/core/v8/V8ScriptRunner.h" |
| 48 #include "bindings/core/v8/V8Window.h" | 48 #include "bindings/core/v8/V8Window.h" |
| 49 #include "bindings/core/v8/V8WindowShell.h" | 49 #include "bindings/core/v8/WindowProxy.h" |
| 50 #include "bindings/core/v8/npruntime_impl.h" | 50 #include "bindings/core/v8/npruntime_impl.h" |
| 51 #include "bindings/core/v8/npruntime_priv.h" | 51 #include "bindings/core/v8/npruntime_priv.h" |
| 52 #include "core/dom/Document.h" | 52 #include "core/dom/Document.h" |
| 53 #include "core/dom/Node.h" | 53 #include "core/dom/Node.h" |
| 54 #include "core/dom/ScriptableDocumentParser.h" | 54 #include "core/dom/ScriptableDocumentParser.h" |
| 55 #include "core/events/Event.h" | 55 #include "core/events/Event.h" |
| 56 #include "core/events/EventListener.h" | 56 #include "core/events/EventListener.h" |
| 57 #include "core/frame/LocalDOMWindow.h" | 57 #include "core/frame/LocalDOMWindow.h" |
| 58 #include "core/frame/LocalFrame.h" | 58 #include "core/frame/LocalFrame.h" |
| 59 #include "core/frame/Settings.h" | 59 #include "core/frame/Settings.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 87 if (!frame) | 87 if (!frame) |
| 88 return false; | 88 return false; |
| 89 v8::Isolate* isolate = toIsolate(frame); | 89 v8::Isolate* isolate = toIsolate(frame); |
| 90 return !isolate->InContext() || BindingSecurity::shouldAllowAccessToFrame(is
olate, frame); | 90 return !isolate->InContext() || BindingSecurity::shouldAllowAccessToFrame(is
olate, frame); |
| 91 } | 91 } |
| 92 | 92 |
| 93 ScriptController::ScriptController(LocalFrame* frame) | 93 ScriptController::ScriptController(LocalFrame* frame) |
| 94 : m_frame(frame) | 94 : m_frame(frame) |
| 95 , m_sourceURL(0) | 95 , m_sourceURL(0) |
| 96 , m_isolate(v8::Isolate::GetCurrent()) | 96 , m_isolate(v8::Isolate::GetCurrent()) |
| 97 , m_windowShell(V8WindowShell::create(frame, DOMWrapperWorld::mainWorld(), m
_isolate)) | 97 , m_windowProxy(WindowProxy::create(frame, DOMWrapperWorld::mainWorld(), m_i
solate)) |
| 98 , m_windowScriptNPObject(0) | 98 , m_windowScriptNPObject(0) |
| 99 { | 99 { |
| 100 } | 100 } |
| 101 | 101 |
| 102 ScriptController::~ScriptController() | 102 ScriptController::~ScriptController() |
| 103 { | 103 { |
| 104 // V8WindowShell::clearForClose() must be invoked before destruction starts. | 104 // WindowProxy::clearForClose() must be invoked before destruction starts. |
| 105 ASSERT(!m_windowShell->isContextInitialized()); | 105 ASSERT(!m_windowProxy->isContextInitialized()); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ScriptController::clearScriptObjects() | 108 void ScriptController::clearScriptObjects() |
| 109 { | 109 { |
| 110 PluginObjectMap::iterator it = m_pluginObjects.begin(); | 110 PluginObjectMap::iterator it = m_pluginObjects.begin(); |
| 111 for (; it != m_pluginObjects.end(); ++it) { | 111 for (; it != m_pluginObjects.end(); ++it) { |
| 112 _NPN_UnregisterObject(it->value); | 112 _NPN_UnregisterObject(it->value); |
| 113 _NPN_ReleaseObject(it->value); | 113 _NPN_ReleaseObject(it->value); |
| 114 } | 114 } |
| 115 m_pluginObjects.clear(); | 115 m_pluginObjects.clear(); |
| 116 | 116 |
| 117 if (m_windowScriptNPObject) { | 117 if (m_windowScriptNPObject) { |
| 118 // Dispose of the underlying V8 object before releasing our reference | 118 // Dispose of the underlying V8 object before releasing our reference |
| 119 // to it, so that if a plugin fails to release it properly we will | 119 // to it, so that if a plugin fails to release it properly we will |
| 120 // only leak the NPObject wrapper, not the object, its document, or | 120 // only leak the NPObject wrapper, not the object, its document, or |
| 121 // anything else they reference. | 121 // anything else they reference. |
| 122 disposeUnderlyingV8Object(m_windowScriptNPObject, m_isolate); | 122 disposeUnderlyingV8Object(m_windowScriptNPObject, m_isolate); |
| 123 _NPN_ReleaseObject(m_windowScriptNPObject); | 123 _NPN_ReleaseObject(m_windowScriptNPObject); |
| 124 m_windowScriptNPObject = 0; | 124 m_windowScriptNPObject = 0; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 void ScriptController::clearForClose() | 128 void ScriptController::clearForClose() |
| 129 { | 129 { |
| 130 double start = currentTime(); | 130 double start = currentTime(); |
| 131 m_windowShell->clearForClose(); | 131 m_windowProxy->clearForClose(); |
| 132 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 132 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 133 iter->value->clearForClose(); | 133 iter->value->clearForClose(); |
| 134 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearForClose", (currentTime() - start) * 1000, 0, 10000, 50); | 134 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearForClose", (currentTime() - start) * 1000, 0, 10000, 50); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void ScriptController::updateSecurityOrigin(SecurityOrigin* origin) | 137 void ScriptController::updateSecurityOrigin(SecurityOrigin* origin) |
| 138 { | 138 { |
| 139 m_windowShell->updateSecurityOrigin(origin); | 139 m_windowProxy->updateSecurityOrigin(origin); |
| 140 } | 140 } |
| 141 | 141 |
| 142 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) | 142 v8::Local<v8::Value> ScriptController::callFunction(v8::Handle<v8::Function> fun
ction, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]) |
| 143 { | 143 { |
| 144 // Keep LocalFrame (and therefore ScriptController) alive. | 144 // Keep LocalFrame (and therefore ScriptController) alive. |
| 145 RefPtr<LocalFrame> protect(m_frame); | 145 RefPtr<LocalFrame> protect(m_frame); |
| 146 return ScriptController::callFunction(m_frame->document(), function, receive
r, argc, info, m_isolate); | 146 return ScriptController::callFunction(m_frame->document(), function, receive
r, argc, info, m_isolate); |
| 147 } | 147 } |
| 148 | 148 |
| 149 v8::Local<v8::Value> ScriptController::callFunction(ExecutionContext* context, v
8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::
Handle<v8::Value> info[], v8::Isolate* isolate) | 149 v8::Local<v8::Value> ScriptController::callFunction(ExecutionContext* context, v
8::Handle<v8::Function> function, v8::Handle<v8::Value> receiver, int argc, v8::
Handle<v8::Value> info[], v8::Isolate* isolate) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 InspectorInstrumentation::didEvaluateScript(cookie); | 197 InspectorInstrumentation::didEvaluateScript(cookie); |
| 198 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); | 198 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update
Counters", "data", InspectorUpdateCountersEvent::data()); |
| 199 | 199 |
| 200 return result; | 200 return result; |
| 201 } | 201 } |
| 202 | 202 |
| 203 bool ScriptController::initializeMainWorld() | 203 bool ScriptController::initializeMainWorld() |
| 204 { | 204 { |
| 205 if (m_windowShell->isContextInitialized()) | 205 if (m_windowProxy->isContextInitialized()) |
| 206 return false; | 206 return false; |
| 207 return windowShell(DOMWrapperWorld::mainWorld())->isContextInitialized(); | 207 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 V8WindowShell* ScriptController::existingWindowShell(DOMWrapperWorld& world) | 210 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) |
| 211 { | 211 { |
| 212 if (world.isMainWorld()) | 212 if (world.isMainWorld()) |
| 213 return m_windowShell->isContextInitialized() ? m_windowShell.get() : 0; | 213 return m_windowProxy->isContextInitialized() ? m_windowProxy.get() : 0; |
| 214 | 214 |
| 215 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); | 215 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId()); |
| 216 if (iter == m_isolatedWorlds.end()) | 216 if (iter == m_isolatedWorlds.end()) |
| 217 return 0; | 217 return 0; |
| 218 return iter->value->isContextInitialized() ? iter->value.get() : 0; | 218 return iter->value->isContextInitialized() ? iter->value.get() : 0; |
| 219 } | 219 } |
| 220 | 220 |
| 221 V8WindowShell* ScriptController::windowShell(DOMWrapperWorld& world) | 221 WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) |
| 222 { | 222 { |
| 223 V8WindowShell* shell = 0; | 223 WindowProxy* windowProxy = 0; |
| 224 if (world.isMainWorld()) { | 224 if (world.isMainWorld()) { |
| 225 shell = m_windowShell.get(); | 225 windowProxy = m_windowProxy.get(); |
| 226 } else { | 226 } else { |
| 227 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; | 227 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world.worldId())
; |
| 228 if (iter != m_isolatedWorlds.end()) { | 228 if (iter != m_isolatedWorlds.end()) { |
| 229 shell = iter->value.get(); | 229 windowProxy = iter->value.get(); |
| 230 } else { | 230 } else { |
| 231 OwnPtr<V8WindowShell> isolatedWorldShell = V8WindowShell::create(m_f
rame, world, m_isolate); | 231 OwnPtr<WindowProxy> isolatedWorldWindowProxy = WindowProxy::create(m
_frame, world, m_isolate); |
| 232 shell = isolatedWorldShell.get(); | 232 windowProxy = isolatedWorldWindowProxy.get(); |
| 233 m_isolatedWorlds.set(world.worldId(), isolatedWorldShell.release()); | 233 m_isolatedWorlds.set(world.worldId(), isolatedWorldWindowProxy.relea
se()); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 if (!shell->isContextInitialized() && shell->initializeIfNeeded() && world.i
sMainWorld()) | 236 if (!windowProxy->isContextInitialized() && windowProxy->initializeIfNeeded(
) && world.isMainWorld()) |
| 237 m_frame->loader().dispatchDidClearWindowObjectInMainWorld(); | 237 m_frame->loader().dispatchDidClearWindowObjectInMainWorld(); |
| 238 return shell; | 238 return windowProxy; |
| 239 } | 239 } |
| 240 | 240 |
| 241 bool ScriptController::shouldBypassMainWorldCSP() | 241 bool ScriptController::shouldBypassMainWorldCSP() |
| 242 { | 242 { |
| 243 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); | 243 v8::Handle<v8::Context> context = m_isolate->GetCurrentContext(); |
| 244 if (context.IsEmpty() || !toDOMWindow(context)) | 244 if (context.IsEmpty() || !toDOMWindow(context)) |
| 245 return false; | 245 return false; |
| 246 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate); | 246 DOMWrapperWorld& world = DOMWrapperWorld::current(m_isolate); |
| 247 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy
() : false; | 247 return world.isIsolatedWorld() ? world.isolatedWorldHasContentSecurityPolicy
() : false; |
| 248 } | 248 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 264 | 264 |
| 265 ScriptState::Scope scope(scriptState); | 265 ScriptState::Scope scope(scriptState); |
| 266 v8::Handle<v8::Object> value = createV8ObjectForNPObject(object, 0, m_isolat
e); | 266 v8::Handle<v8::Object> value = createV8ObjectForNPObject(object, 0, m_isolat
e); |
| 267 | 267 |
| 268 // Attach to the global object. | 268 // Attach to the global object. |
| 269 scriptState->context()->Global()->Set(v8String(m_isolate, key), value); | 269 scriptState->context()->Global()->Set(v8String(m_isolate, key), value); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void ScriptController::enableEval() | 272 void ScriptController::enableEval() |
| 273 { | 273 { |
| 274 if (!m_windowShell->isContextInitialized()) | 274 if (!m_windowProxy->isContextInitialized()) |
| 275 return; | 275 return; |
| 276 v8::HandleScope handleScope(m_isolate); | 276 v8::HandleScope handleScope(m_isolate); |
| 277 m_windowShell->context()->AllowCodeGenerationFromStrings(true); | 277 m_windowProxy->context()->AllowCodeGenerationFromStrings(true); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void ScriptController::disableEval(const String& errorMessage) | 280 void ScriptController::disableEval(const String& errorMessage) |
| 281 { | 281 { |
| 282 if (!m_windowShell->isContextInitialized()) | 282 if (!m_windowProxy->isContextInitialized()) |
| 283 return; | 283 return; |
| 284 v8::HandleScope handleScope(m_isolate); | 284 v8::HandleScope handleScope(m_isolate); |
| 285 v8::Local<v8::Context> v8Context = m_windowShell->context(); | 285 v8::Local<v8::Context> v8Context = m_windowProxy->context(); |
| 286 v8Context->AllowCodeGenerationFromStrings(false); | 286 v8Context->AllowCodeGenerationFromStrings(false); |
| 287 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e
rrorMessage)); | 287 v8Context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, e
rrorMessage)); |
| 288 } | 288 } |
| 289 | 289 |
| 290 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper(
Widget* widget) | 290 PassRefPtr<SharedPersistent<v8::Object> > ScriptController::createPluginWrapper(
Widget* widget) |
| 291 { | 291 { |
| 292 ASSERT(widget); | 292 ASSERT(widget); |
| 293 | 293 |
| 294 if (!widget->isPluginView()) | 294 if (!widget->isPluginView()) |
| 295 return nullptr; | 295 return nullptr; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 409 |
| 410 ScriptState::Scope scope(scriptState); | 410 ScriptState::Scope scope(scriptState); |
| 411 LocalDOMWindow* window = m_frame->domWindow(); | 411 LocalDOMWindow* window = m_frame->domWindow(); |
| 412 v8::Handle<v8::Value> v8plugin = toV8(plugin, scriptState->context()->Global
(), scriptState->isolate()); | 412 v8::Handle<v8::Value> v8plugin = toV8(plugin, scriptState->context()->Global
(), scriptState->isolate()); |
| 413 if (!v8plugin->IsObject()) | 413 if (!v8plugin->IsObject()) |
| 414 return createNoScriptObject(); | 414 return createNoScriptObject(); |
| 415 | 415 |
| 416 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow, scriptState->isolate()); | 416 return npCreateV8ScriptObject(0, v8::Handle<v8::Object>::Cast(v8plugin), win
dow, scriptState->isolate()); |
| 417 } | 417 } |
| 418 | 418 |
| 419 void ScriptController::clearWindowShell() | 419 void ScriptController::clearWindowProxy() |
| 420 { | 420 { |
| 421 double start = currentTime(); | 421 double start = currentTime(); |
| 422 // V8 binding expects ScriptController::clearWindowShell only be called | 422 // V8 binding expects ScriptController::clearWindowProxy only be called |
| 423 // when a frame is loading a new page. This creates a new context for the ne
w page. | 423 // when a frame is loading a new page. This creates a new context for the ne
w page. |
| 424 | 424 |
| 425 // The V8 context must be available for |clearScriptObjects()|. | 425 // The V8 context must be available for |clearScriptObjects()|. |
| 426 // The below call must be before |clearForNavigation()| which disposes the V
8 context. | 426 // The below call must be before |clearForNavigation()| which disposes the V
8 context. |
| 427 clearScriptObjects(); | 427 clearScriptObjects(); |
| 428 m_windowShell->clearForNavigation(); | 428 m_windowProxy->clearForNavigation(); |
| 429 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) | 429 for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin(); iter != m_i
solatedWorlds.end(); ++iter) |
| 430 iter->value->clearForNavigation(); | 430 iter->value->clearForNavigation(); |
| 431 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearWindowShell", (currentTime() - start) * 1000, 0, 10000, 50); | 431 blink::Platform::current()->histogramCustomCounts("WebCore.ScriptController.
clearWindowProxy", (currentTime() - start) * 1000, 0, 10000, 50); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) | 434 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool value) |
| 435 { | 435 { |
| 436 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); | 436 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::ma
xCallStackSizeToCapture, stackTraceOptions); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) | 439 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, Se
curityOrigin*> >& result) |
| 440 { | 440 { |
| 441 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { | 441 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isola
tedWorlds.end(); ++it) { |
| 442 V8WindowShell* isolatedWorldShell = it->value.get(); | 442 WindowProxy* isolatedWorldWindowProxy = it->value.get(); |
| 443 SecurityOrigin* origin = isolatedWorldShell->world().isolatedWorldSecuri
tyOrigin(); | 443 SecurityOrigin* origin = isolatedWorldWindowProxy->world().isolatedWorld
SecurityOrigin(); |
| 444 if (!origin) | 444 if (!origin) |
| 445 continue; | 445 continue; |
| 446 if (!isolatedWorldShell->isContextInitialized()) | 446 if (!isolatedWorldWindowProxy->isContextInitialized()) |
| 447 continue; | 447 continue; |
| 448 result.append(std::pair<ScriptState*, SecurityOrigin*>(isolatedWorldShel
l->scriptState(), origin)); | 448 result.append(std::pair<ScriptState*, SecurityOrigin*>(isolatedWorldWind
owProxy->scriptState(), origin)); |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 void ScriptController::setWorldDebugId(int worldId, int debuggerId) | 452 void ScriptController::setWorldDebugId(int worldId, int debuggerId) |
| 453 { | 453 { |
| 454 ASSERT(debuggerId > 0); | 454 ASSERT(debuggerId > 0); |
| 455 bool isMainWorld = worldId == MainWorldId; | 455 bool isMainWorld = worldId == MainWorldId; |
| 456 V8WindowShell* shell = 0; | 456 WindowProxy* windowProxy = 0; |
| 457 if (isMainWorld) { | 457 if (isMainWorld) { |
| 458 shell = m_windowShell.get(); | 458 windowProxy = m_windowProxy.get(); |
| 459 } else { | 459 } else { |
| 460 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); | 460 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); |
| 461 if (iter != m_isolatedWorlds.end()) | 461 if (iter != m_isolatedWorlds.end()) |
| 462 shell = iter->value.get(); | 462 windowProxy = iter->value.get(); |
| 463 } | 463 } |
| 464 if (!shell || !shell->isContextInitialized()) | 464 if (!windowProxy || !windowProxy->isContextInitialized()) |
| 465 return; | 465 return; |
| 466 v8::HandleScope scope(m_isolate); | 466 v8::HandleScope scope(m_isolate); |
| 467 v8::Local<v8::Context> context = shell->context(); | 467 v8::Local<v8::Context> context = windowProxy->context(); |
| 468 const char* worldName = isMainWorld ? "page" : "injected"; | 468 const char* worldName = isMainWorld ? "page" : "injected"; |
| 469 V8PerContextDebugData::setContextDebugData(context, worldName, debuggerId); | 469 V8PerContextDebugData::setContextDebugData(context, worldName, debuggerId); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void ScriptController::updateDocument() | 472 void ScriptController::updateDocument() |
| 473 { | 473 { |
| 474 // For an uninitialized main window shell, do not incur the cost of context
initialization. | 474 // For an uninitialized main window windowProxy, do not incur the cost of co
ntext initialization. |
| 475 if (!m_windowShell->isGlobalInitialized()) | 475 if (!m_windowProxy->isGlobalInitialized()) |
| 476 return; | 476 return; |
| 477 | 477 |
| 478 if (!initializeMainWorld()) | 478 if (!initializeMainWorld()) |
| 479 windowShell(DOMWrapperWorld::mainWorld())->updateDocument(); | 479 windowProxy(DOMWrapperWorld::mainWorld())->updateDocument(); |
| 480 } | 480 } |
| 481 | 481 |
| 482 void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& nam
e) | 482 void ScriptController::namedItemAdded(HTMLDocument* doc, const AtomicString& nam
e) |
| 483 { | 483 { |
| 484 windowShell(DOMWrapperWorld::mainWorld())->namedItemAdded(doc, name); | 484 windowProxy(DOMWrapperWorld::mainWorld())->namedItemAdded(doc, name); |
| 485 } | 485 } |
| 486 | 486 |
| 487 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& n
ame) | 487 void ScriptController::namedItemRemoved(HTMLDocument* doc, const AtomicString& n
ame) |
| 488 { | 488 { |
| 489 windowShell(DOMWrapperWorld::mainWorld())->namedItemRemoved(doc, name); | 489 windowProxy(DOMWrapperWorld::mainWorld())->namedItemRemoved(doc, name); |
| 490 } | 490 } |
| 491 | 491 |
| 492 static bool isInPrivateScriptIsolateWorld(v8::Isolate* isolate) | 492 static bool isInPrivateScriptIsolateWorld(v8::Isolate* isolate) |
| 493 { | 493 { |
| 494 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); | 494 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); |
| 495 return !context.IsEmpty() && toDOMWindow(context) && DOMWrapperWorld::curren
t(isolate).isPrivateScriptIsolatedWorld(); | 495 return !context.IsEmpty() && toDOMWindow(context) && DOMWrapperWorld::curren
t(isolate).isPrivateScriptIsolatedWorld(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reaso
n) | 498 bool ScriptController::canExecuteScripts(ReasonForCallingCanExecuteScripts reaso
n) |
| 499 { | 499 { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 return v8::Local<v8::Value>(); | 615 return v8::Local<v8::Value>(); |
| 616 | 616 |
| 617 return handleScope.Escape(object); | 617 return handleScope.Escape(object); |
| 618 } | 618 } |
| 619 | 619 |
| 620 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) | 620 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc
riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res
ults) |
| 621 { | 621 { |
| 622 ASSERT(worldID > 0); | 622 ASSERT(worldID > 0); |
| 623 | 623 |
| 624 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID
, extensionGroup); | 624 RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldID
, extensionGroup); |
| 625 V8WindowShell* isolatedWorldShell = windowShell(*world); | 625 WindowProxy* isolatedWorldWindowProxy = windowProxy(*world); |
| 626 if (!isolatedWorldShell->isContextInitialized()) | 626 if (!isolatedWorldWindowProxy->isContextInitialized()) |
| 627 return; | 627 return; |
| 628 | 628 |
| 629 ScriptState* scriptState = isolatedWorldShell->scriptState(); | 629 ScriptState* scriptState = isolatedWorldWindowProxy->scriptState(); |
| 630 v8::EscapableHandleScope handleScope(scriptState->isolate()); | 630 v8::EscapableHandleScope handleScope(scriptState->isolate()); |
| 631 ScriptState::Scope scope(scriptState); | 631 ScriptState::Scope scope(scriptState); |
| 632 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.size())
; | 632 v8::Local<v8::Array> resultArray = v8::Array::New(m_isolate, sources.size())
; |
| 633 | 633 |
| 634 for (size_t i = 0; i < sources.size(); ++i) { | 634 for (size_t i = 0; i < sources.size(); ++i) { |
| 635 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); | 635 v8::Local<v8::Value> evaluationResult = executeScriptAndReturnValue(scri
ptState->context(), sources[i]); |
| 636 if (evaluationResult.IsEmpty()) | 636 if (evaluationResult.IsEmpty()) |
| 637 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Undefine
d(m_isolate)); | 637 evaluationResult = v8::Local<v8::Value>::New(m_isolate, v8::Undefine
d(m_isolate)); |
| 638 resultArray->Set(i, evaluationResult); | 638 resultArray->Set(i, evaluationResult); |
| 639 } | 639 } |
| 640 | 640 |
| 641 if (results) { | 641 if (results) { |
| 642 for (size_t i = 0; i < resultArray->Length(); ++i) | 642 for (size_t i = 0; i < resultArray->Length(); ++i) |
| 643 results->append(handleScope.Escape(resultArray->Get(i))); | 643 results->append(handleScope.Escape(resultArray->Get(i))); |
| 644 } | 644 } |
| 645 } | 645 } |
| 646 | 646 |
| 647 } // namespace blink | 647 } // namespace blink |
| OLD | NEW |