v8::Local<v8::Context> toV8Context(v8::Isolate* isolate, Frame* frame, DOMWrapperWorld* world) { ASSERT(frame); v8::Local<v8::Context> context = frame->script().windowShell(world)->context(); if (context.IsEmpty()) return v8::Local<v8::Context>(); Frame* attachedFrame= toFrameIfNotDetached(context); return frame == attachedFrame ? context : v8::Local<v8::Context>(); }
v8::Local<v8::Context> ScriptController::currentWorldContext() { if (V8DOMWindowShell* isolatedShell = V8DOMWindowShell::getEntered()) { v8::Persistent<v8::Context> context = isolatedShell->context(); if (context.IsEmpty() || m_frame != toFrameIfNotDetached(context)) return v8::Local<v8::Context>(); return v8::Local<v8::Context>::New(context); } windowShell()->initializeIfNeeded(); return v8::Local<v8::Context>::New(windowShell()->context()); }
void V8WrapperInstantiationScope::securityCheck(v8::Isolate* isolate, v8::Local<v8::Context> contextForWrapper) { if (m_context.IsEmpty()) return; // If the context is different, we need to make sure that the current // context has access to the creation context. Frame* frame = toFrameIfNotDetached(contextForWrapper); if (!frame) return; const DOMWrapperWorld& currentWorld = DOMWrapperWorld::world(m_context); RELEASE_ASSERT(currentWorld.worldId() == DOMWrapperWorld::world(contextForWrapper).worldId()); if (currentWorld.isMainWorld()) { RELEASE_ASSERT(BindingSecurity::shouldAllowAccessToFrame(isolate, callingDOMWindow(isolate), frame, DoNotReportSecurityError)); } }
v8::Local<v8::Context> ScriptController::currentWorldContext() { if (!isolate()->InContext()) return contextForWorld(*this, mainThreadNormalWorld()); v8::Handle<v8::Context> context = isolate()->GetEnteredContext(); DOMWrapperWorld* isolatedWorld = DOMWrapperWorld::isolatedWorld(context); if (!isolatedWorld) return contextForWorld(*this, mainThreadNormalWorld()); Frame* frame = toFrameIfNotDetached(context); if (m_frame == frame) return v8::Local<v8::Context>::New(m_isolate, context); return contextForWorld(*this, isolatedWorld); }
bool handleOutOfMemory() { v8::Local<v8::Context> context = v8::Isolate::GetCurrent()->GetCurrentContext(); if (!context->HasOutOfMemoryException()) return false; // Warning, error, disable JS for this frame? Frame* frame = toFrameIfNotDetached(context); if (!frame) return true; frame->script().clearForOutOfMemory(); frame->loader().client()->didExhaustMemoryAvailableForScript(); if (Settings* settings = frame->settings()) settings->setScriptEnabled(false); return true; }
v8::Local<v8::Context> ScriptController::currentWorldContext() { if (!v8::Context::InContext()) return contextForWorld(this, mainThreadNormalWorld()); v8::Handle<v8::Context> context = v8::Context::GetEntered(); DOMWrapperWorld* isolatedWorld = DOMWrapperWorld::isolated(context); if (!isolatedWorld) return contextForWorld(this, mainThreadNormalWorld()); Frame* frame = toFrameIfNotDetached(context); if (!m_frame) return v8::Local<v8::Context>(); if (m_frame == frame) return v8::Local<v8::Context>::New(context); // FIXME: Need to handle weak isolated worlds correctly. if (isolatedWorld->createdFromUnitializedWorld()) return v8::Local<v8::Context>(); return contextForWorld(this, isolatedWorld); }
static LocalFrame* retrieveFrameWithGlobalObjectCheck(v8::Local<v8::Context> context) { return toLocalFrame(toFrameIfNotDetached(context)); }