v8::Persistent<v8::Context> V8Proxy::createNewContext(v8::Handle<v8::Object> global, int extensionGroup) { v8::Persistent<v8::Context> result; // The activeDocumentLoader pointer could be NULL during frame shutdown. if (!m_frame->loader()->activeDocumentLoader()) return result; // Create a new environment using an empty template for the shadow // object. Reuse the global object if one has been created earlier. v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate(); if (globalTemplate.IsEmpty()) return result; // Install a security handler with V8. globalTemplate->SetAccessCheckCallbacks(V8Custom::v8DOMWindowNamedSecurityCheck, V8Custom::v8DOMWindowIndexedSecurityCheck, v8::Integer::New(V8ClassIndex::DOMWINDOW)); // Used to avoid sleep calls in unload handlers. if (!registeredExtensionWithV8(DateExtension::get())) registerExtension(DateExtension::get(), String()); // Dynamically tell v8 about our extensions now. OwnArrayPtr<const char*> extensionNames(new const char*[m_extensions.size()]); int index = 0; for (size_t i = 0; i < m_extensions.size(); ++i) { if (m_extensions[i].group && m_extensions[i].group != extensionGroup) continue; // Note: we check the loader URL here instead of the document URL // because we might be currently loading an URL into a blank page. // See http://code.google.com/p/chromium/issues/detail?id=10924 if (m_extensions[i].scheme.length() > 0 && (m_extensions[i].scheme != m_frame->loader()->activeDocumentLoader()->url().protocol() || m_extensions[i].scheme != m_frame->page()->mainFrame()->loader()->activeDocumentLoader()->url().protocol())) continue; extensionNames[index++] = m_extensions[i].extension->name(); } v8::ExtensionConfiguration extensions(index, extensionNames.get()); result = v8::Context::New(&extensions, globalTemplate, global); return result; }
void V8Proxy::registerExtensionWithV8(v8::Extension* extension) { // If the extension exists in our list, it was already registered with V8. if (!registeredExtensionWithV8(extension)) v8::RegisterExtension(extension); }