JSValueRef WebFrame::computedStyleIncludingVisitedInfo(JSObjectRef element) { if (!m_coreFrame) return 0; #if USE(JSC) JSDOMWindow* globalObject = m_coreFrame->script()->globalObject(mainThreadNormalWorld()); ExecState* exec = globalObject->globalExec(); if (!toJS(element)->inherits(&JSElement::s_info)) return JSValueMakeUndefined(toRef(exec)); RefPtr<CSSComputedStyleDeclaration> style = CSSComputedStyleDeclaration::create(static_cast<JSElement*>(toJS(element))->impl(), true); JSLock lock(SilenceAssertionsOnly); return toRef(exec, toJS(exec, globalObject, style.get())); #elif USE(V8) v8::HandleScope handleScope; Element* webElement = V8Element::toNative(toV8(element)); if (!webElement) return 0; v8::Handle<v8::Value> wrapper = V8CSSStyleDeclaration::wrap(CSSComputedStyleDeclaration::create(webElement, true).leakRef(), 0); if (wrapper.IsEmpty()) return 0; return toRef(wrapper); #endif }
void QWebFrameAdapter::addToJavaScriptWindowObject(const QString& name, QObject* object, ValueOwnership ownership) { if (!pageAdapter->settings->testAttribute(QWebSettings::JavascriptEnabled)) return; JSC::Bindings::QtInstance::ValueOwnership valueOwnership = static_cast<JSC::Bindings::QtInstance::ValueOwnership>(ownership); JSDOMWindow* window = toJSDOMWindow(frame, mainThreadNormalWorld()); JSC::Bindings::RootObject* root; if (valueOwnership == JSC::Bindings::QtInstance::QtOwnership) root = frame->script()->cacheableBindingRootObject(); else root = frame->script()->bindingRootObject(); if (!window) { qDebug() << "Warning: couldn't get window object"; return; } if (!root) { qDebug() << "Warning: couldn't get root object"; return; } JSC::ExecState* exec = window->globalExec(); JSC::JSLockHolder lock(exec); JSC::JSObject* runtimeObject = JSC::Bindings::QtInstance::getQtInstance(object, root, valueOwnership)->createRuntimeObject(exec); JSC::PutPropertySlot slot; window->methodTable()->put(window, exec, JSC::Identifier(&exec->globalData(), reinterpret_cast_ptr<const UChar*>(name.constData()), name.length()), runtimeObject, slot); }
JSObject* ScriptController::jsObjectForPluginElement(HTMLPlugInElement* plugin) { // Can't create JSObjects when JavaScript is disabled if (!canExecuteScripts(NotAboutToExecuteScript)) return 0; // Create a JSObject bound to this element JSDOMWindow* globalObj = globalObject(pluginWorld()); JSLockHolder lock(globalObj->globalExec()); // FIXME: is normal okay? - used for NP plugins? JSValue jsElementValue = toJS(globalObj->globalExec(), globalObj, plugin); if (!jsElementValue || !jsElementValue.isObject()) return 0; return jsElementValue.getObject(); }
PassRefPtr<JSLazyEventListener> createAttributeEventListener(Node* node, Attribute* attr) { ASSERT(node); Frame* frame = node->document()->frame(); if (!frame) return 0; ScriptController* scriptController = frame->script(); if (!scriptController->isEnabled()) return 0; if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { // This script is not safe to execute. return 0; } JSDOMWindow* globalObject = scriptController->globalObject(); // Ensure that 'node' has a JavaScript wrapper to mark the event listener we're creating. { JSLock lock(SilenceAssertionsOnly); // FIXME: Should pass the global object associated with the node toJS(globalObject->globalExec(), globalObject, node); } return JSLazyEventListener::create(attr->localName().string(), eventParameterName(node->isSVGElement()), attr->value(), globalObject, node, scriptController->eventHandlerLineNumber()); }
int MDNativeBindingManager::registerNativeJSObjectsToContext(ScriptController *script, DOMWrapperWorld* world) { DOMWrapperWorld* nativeWorld = (world)? world : mainThreadNormalWorld(); JSDOMWindow* window = (script->globalObject(nativeWorld)); //toJSDOMWindow JSContextRef context = reinterpret_cast<JSContextRef>(window->globalExec()); JSObjectRef globalObject = JSContextGetGlobalObject(context); IMDNativeBindingObject *object = NULL; size_t size = m_jsTable.size(); for (size_t i=0; i<size; i++) { object = m_jsTable.at(i); JSStringRef propertyName = object->propertyName(); //entry->m_propertyName; JSObjectSetProperty( context, globalObject, propertyName, object->propertyValue(context), kJSPropertyAttributeDontEnum | kJSPropertyAttributeDontDelete, NULL); JSStringRelease(propertyName); } return 0; }
// FIXME: Revisit the creation of this class and make sure this is the best way to approach it. void attachExtensionObjectToFrame(Frame* frame, WebPageClient* client) { JSC::JSLock lock(JSC::SilenceAssertionsOnly); JSDOMWindow* window = frame->script()->windowShell(mainThreadNormalWorld())->window(); JSC::ExecState* exec = window->globalExec(); JSContextRef scriptCtx = toRef(exec); JSClassDefinition definition = kJSClassDefinitionEmpty; definition.staticValues = clientExtensionStaticValues; definition.staticFunctions = clientExtensionStaticFunctions; definition.initialize = clientExtensionInitialize; definition.finalize = clientExtensionFinalize; JSClassRef clientClass = JSClassCreate(&definition); JSObjectRef clientClassObject = JSObjectMake(scriptCtx, clientClass, 0); JSObjectSetPrivate(clientClassObject, reinterpret_cast<void*>(client)); JSC::UString name("qnx"); JSC::PutPropertySlot slot; window->put(window, exec, JSC::Identifier(exec, name), toJS(clientClassObject), slot); JSClassRelease(clientClass); }
JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleRangeHandle* rangeHandle, InjectedBundleScriptWorld* world) { JSDOMWindow* globalObject = m_coreFrame->script()->globalObject(world->coreWorld()); ExecState* exec = globalObject->globalExec(); JSLock lock(SilenceAssertionsOnly); return toRef(exec, toJS(exec, globalObject, rangeHandle->coreRange())); }
JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleRangeHandle* rangeHandle, InjectedBundleScriptWorld* world) { if (!m_coreFrame) return 0; JSDOMWindow* globalObject = m_coreFrame->script().globalObject(world->coreWorld()); ExecState* exec = globalObject->globalExec(); JSLockHolder lock(exec); return toRef(exec, toJS(exec, globalObject, rangeHandle->coreRange())); }
void WebFrame::addToJSWindowObject(const char* name, void *object) { KJS::JSLock lock(false); JSDOMWindow *window = toJSDOMWindow(core(this)); if (!window) return; KJS::Bindings::RootObject *root = core(this)->bindingRootObject(); KJS::ExecState* exec = window->globalExec(); KJS::JSObject *runtimeObject = KJS::Bindings::Instance::createRuntimeObject(exec, KJS::Bindings::BalInstance::create(static_cast<BalObject*>(object), root)); window->put(exec, KJS::Identifier(exec, name), runtimeObject); }
void DumpRenderTreeSupportQt::resetInternalsObject(QWebFrameAdapter* adapter) { WebCore::Frame* coreFrame = adapter->frame; JSDOMWindow* window = toJSDOMWindow(coreFrame, mainThreadNormalWorld()); Q_ASSERT(window); JSC::ExecState* exec = window->globalExec(); Q_ASSERT(exec); JSC::JSLockHolder lock(exec); JSContextRef context = toRef(exec); WebCoreTestSupport::resetInternalsObject(context); }
JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleNodeHandle* nodeHandle, InjectedBundleScriptWorld* world) { #if 0 //CMP_ERROR_TODO InjectedBundle if (!m_coreFrame) return 0; JSDOMWindow* globalObject = m_coreFrame->script().globalObject(world->coreWorld()); ExecState* exec = globalObject->globalExec(); JSLockHolder lock(exec); return toRef(exec, toJS(exec, globalObject, nodeHandle->coreNode())); #else return 0; #endif }
JSValueRef WebFrame::computedStyleIncludingVisitedInfo(JSObjectRef element) { if (!m_coreFrame) return 0; JSDOMWindow* globalObject = m_coreFrame->script()->globalObject(mainThreadNormalWorld()); ExecState* exec = globalObject->globalExec(); if (!toJS(element)->inherits(&JSElement::s_info)) return JSValueMakeUndefined(toRef(exec)); RefPtr<CSSComputedStyleDeclaration> style = computedStyle(static_cast<JSElement*>(toJS(element))->impl(), true); JSLock lock(SilenceAssertionsOnly); return toRef(exec, toJS(exec, globalObject, style.get())); }
void DumpRenderTreeSupportQt::injectInternalsObject(QWebFrame* frame) { WebCore::Frame* coreFrame = QWebFramePrivate::core(frame); #if USE(JSC) JSC::JSLock lock(JSC::SilenceAssertionsOnly); JSDOMWindow* window = toJSDOMWindow(coreFrame, mainThreadNormalWorld()); Q_ASSERT(window); JSC::ExecState* exec = window->globalExec(); Q_ASSERT(exec); JSContextRef context = toRef(exec); WebCoreTestSupport::injectInternalsObject(context); #elif USE(V8) WebCoreTestSupport::injectInternalsObject(V8Proxy::mainWorldContext(coreFrame)); #endif }
/*! \fn void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership own) \overload Make \a object available under \a name from within the frame's JavaScript context. The \a object will be inserted as a child of the frame's window object. Qt properties will be exposed as JavaScript properties and slots as JavaScript methods. If you want to ensure that your QObjects remain accessible after loading a new URL, you should add them in a slot connected to the javaScriptWindowObjectCleared() signal. The ownership of \a object is specified using \a own. */ void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership) { JSC::JSLock lock(false); JSDOMWindow* window = toJSDOMWindow(d->frame); JSC::Bindings::RootObject* root = d->frame->script()->bindingRootObject(); if (!window) { qDebug() << "Warning: couldn't get window object"; return; } JSC::ExecState* exec = window->globalExec(); JSC::JSObject*runtimeObject = JSC::Bindings::Instance::createRuntimeObject(exec, JSC::Bindings::QtInstance::getQtInstance(object, root, ownership)); JSC::PutPropertySlot slot; window->put(exec, JSC::Identifier(exec, (const UChar *) name.constData(), name.length()), runtimeObject, slot); }
JSValueRef WebFrame::jsWrapperForWorld(InjectedBundleRangeHandle* rangeHandle, InjectedBundleScriptWorld* world) { if (!m_coreFrame) return 0; #if USE(JSC) JSDOMWindow* globalObject = m_coreFrame->script()->globalObject(world->coreWorld()); ExecState* exec = globalObject->globalExec(); JSLock lock(SilenceAssertionsOnly); return toRef(exec, toJS(exec, globalObject, rangeHandle->coreRange())); #elif USE(V8) v8::HandleScope handleScope; v8::Handle<v8::Value> wrapper = toV8(rangeHandle->coreRange()); if (wrapper.IsEmpty()) return 0; return toRef(wrapper); #endif }
void WebFrame::addToJSWindowObject(const char* name, void *object) { JSC::JSLock lock(false); JSDOMWindow *window = toJSDOMWindow(core(this)); if (!window) return; JSC::Bindings::RootObject *root = core(this)->script()->bindingRootObject(); JSC::ExecState* exec = window->globalExec(); JSC::PropertySlot pr; if (!window->getOwnPropertySlot(exec, JSC::Identifier(exec, name), pr)) { //printf("addToJSWindowObject %p name =%s ok \n", core(this), name); //JSC::JSObject *runtimeObject = JSC::Bindings::Instance::createRuntimeObject(exec, JSC::Bindings::BalInstance::create(static_cast<BalObject*>(object), root)); JSC::JSObject *runtimeObject = JSC::Bindings::Instance::createRuntimeObject(exec, JSC::Bindings::BalInstance::getBalInstance(static_cast<BalObject*>(object), root)); JSC::PutPropertySlot prop; window->put(exec, JSC::Identifier(exec, name), runtimeObject, prop); } }
NPObject* ScriptController::windowScriptNPObject() { if (!m_windowScriptNPObject) { if (canExecuteScripts(NotAboutToExecuteScript)) { // JavaScript is enabled, so there is a JavaScript window object. // Return an NPObject bound to the window object. JSDOMWindow* win = windowShell(pluginWorld())->window(); ASSERT(win); JSC::JSLockHolder lock(win->globalExec()); Bindings::RootObject* root = bindingRootObject(); m_windowScriptNPObject = _NPN_CreateScriptObject(0, win, root); } else { // JavaScript is not enabled, so we cannot bind the NPObject to the JavaScript window object. // Instead, we create an NPObject of a different class, one which is not bound to a JavaScript object. m_windowScriptNPObject = _NPN_CreateNoScriptObject(); } } return m_windowScriptNPObject; }
/*! \fn void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership own) \overload Make \a object available under \a name from within the frame's JavaScript context. The \a object will be inserted as a child of the frame's window object. Qt properties will be exposed as JavaScript properties and slots as JavaScript methods. If you want to ensure that your QObjects remain accessible after loading a new URL, you should add them in a slot connected to the javaScriptWindowObjectCleared() signal. If Javascript is not enabled for this page, then this method does nothing. The ownership of \a object is specified using \a own. */ void QWebFrame::addToJavaScriptWindowObject(const QString &name, QObject *object, QScriptEngine::ValueOwnership ownership) { if (!page()->settings()->testAttribute(QWebSettings::JavascriptEnabled)) return; JSC::JSLock lock(JSC::SilenceAssertionsOnly); JSDOMWindow* window = toJSDOMWindow(d->frame, mainThreadNormalWorld()); JSC::Bindings::RootObject* root = d->frame->script()->bindingRootObject(); if (!window) { qDebug() << "Warning: couldn't get window object"; return; } JSC::ExecState* exec = window->globalExec(); JSC::JSObject* runtimeObject = JSC::Bindings::QtInstance::getQtInstance(object, root, ownership)->createRuntimeObject(exec); JSC::PutPropertySlot slot; window->put(exec, JSC::Identifier(exec, (const UChar *) name.constData(), name.length()), runtimeObject, slot); }
void PagePopupBlackBerry::installDOMFunction(Frame* frame) { JSDOMWindow* window = toJSDOMWindow(frame, mainThreadNormalWorld()); ASSERT(window); JSC::ExecState* exec = window->globalExec(); ASSERT(exec); JSC::JSLockHolder lock(exec); JSContextRef context = ::toRef(exec); JSObjectRef globalObject = JSContextGetGlobalObject(context); JSStringRef functionName = JSStringCreateWithUTF8CString( "setValueAndClosePopup"); JSObjectRef function = JSObjectMakeFunctionWithCallback(context, functionName, setValueAndClosePopupCallback); JSObjectSetProperty(context, globalObject, functionName, function, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0); // Register client into DOM JSClassDefinition definition = kJSClassDefinitionEmpty; definition.staticValues = popUpExtensionStaticValues; definition.staticFunctions = popUpExtensionStaticFunctions; definition.initialize = popUpExtensionInitialize; definition.finalize = popUpExtensionFinalize; JSClassRef clientClass = JSClassCreate(&definition); JSObjectRef clientClassObject = JSObjectMake(context, clientClass, 0); // Add a reference. See popUpExtensionFinalize. m_sharedClientPointer->ref(); JSObjectSetPrivate(clientClassObject, m_sharedClientPointer.get()); String name("popUp"); JSC::PutPropertySlot slot; window->put(window, exec, JSC::Identifier(exec, name), toJS(clientClassObject), slot); JSClassRelease(clientClass); }
bool WebFrame::stringByEvaluatingJavaScriptInScriptWorld(WebScriptWorld* world, void* jsGlobalObject, const char* script, const char** evaluationResult) { if (!world || !jsGlobalObject || !evaluationResult) return false; *evaluationResult = 0; Frame* coreFrame = core(this); JSObjectRef globalObjectRef = reinterpret_cast<JSObjectRef>(jsGlobalObject); String string = String(script); // Start off with some guess at a frame and a global object, we'll try to do better...! JSDOMWindow* anyWorldGlobalObject = coreFrame->script()->globalObject(mainThreadNormalWorld()); // The global object is probably a shell object? - if so, we know how to use this! JSC::JSObject* globalObjectObj = toJS(globalObjectRef); if (!strcmp(globalObjectObj->classInfo()->className, "JSDOMWindowShell")) anyWorldGlobalObject = static_cast<JSDOMWindowShell*>(globalObjectObj)->window(); // Get the frame from the global object we've settled on. Frame* frame = anyWorldGlobalObject->impl()->frame(); ASSERT(frame->document()); JSC::JSValue result = frame->script()->executeScriptInWorld(world->world(), string, true).jsValue(); if (!frame) // In case the script removed our frame from the page. return true; // This bizarre set of rules matches behavior from WebKit for Safari 2.0. // If you don't like it, use -[WebScriptObject evaluateWebScript:] or // JSEvaluateScript instead, since they have less surprising semantics. if (!result || !result.isBoolean() && !result.isString() && !result.isNumber()) return true; JSC::JSLock lock(JSC::SilenceAssertionsOnly); String resultString = ustringToString(result.toString(anyWorldGlobalObject->globalExec())); *evaluationResult = strdup(resultString.utf8().data()); return true; }
void DumpRenderTreeSupportQt::getJSWindowObject(QWebFrameAdapter* adapter, JSContextRef* context, JSObjectRef* object) { JSDOMWindow* window = toJSDOMWindow(adapter->frame, mainThreadNormalWorld()); *object = toRef(window); *context = toRef(window->globalExec()); }
void JSAbstractEventListener::handleEvent(Event* event, bool isWindowEvent) { JSObject* listener = listenerObj(); if (!listener) return; JSDOMWindow* window = this->window(); // Null check as clearWindow() can clear this and we still get called back by // xmlhttprequest objects. See http://bugs.webkit.org/show_bug.cgi?id=13275 if (!window) return; Frame* frame = window->impl()->frame(); if (!frame) return; ScriptController* script = frame->script(); if (!script->isEnabled() || script->isPaused()) return; JSLock lock(false); ExecState* exec = window->globalExec(); JSValue* handleEventFunction = listener->get(exec, Identifier(exec, "handleEvent")); CallData callData; CallType callType = handleEventFunction->getCallData(callData); if (callType == CallTypeNone) { handleEventFunction = 0; callType = listener->getCallData(callData); } if (callType != CallTypeNone) { ref(); ArgList args; args.append(toJS(exec, event)); Event* savedEvent = window->currentEvent(); window->setCurrentEvent(event); JSValue* retval; if (handleEventFunction) { window->startTimeoutCheck(); retval = call(exec, handleEventFunction, callType, callData, listener, args); } else { JSValue* thisValue; if (isWindowEvent) thisValue = window->shell(); else thisValue = toJS(exec, event->currentTarget()); window->startTimeoutCheck(); retval = call(exec, listener, callType, callData, thisValue, args); } window->stopTimeoutCheck(); window->setCurrentEvent(savedEvent); if (exec->hadException()) frame->domWindow()->console()->reportCurrentException(exec); else { if (!retval->isUndefinedOrNull() && event->storesResultAsString()) event->storeResult(retval->toString(exec)); if (m_isHTML) { bool retvalbool; if (retval->getBoolean(retvalbool) && !retvalbool) event->preventDefault(); } } Document::updateDocumentsRendering(); deref(); } }