void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrame* frame, int worldID, const QString& script) { QWebScriptWorld* scriptWorld; if (!worldID) { scriptWorld = new QWebScriptWorld(); } else if (!m_worldMap.contains(worldID)) { scriptWorld = new QWebScriptWorld(); m_worldMap.insert(worldID, scriptWorld); } else scriptWorld = m_worldMap.value(worldID); WebCore::Frame* coreFrame = QWebFramePrivate::core(frame); ScriptController* proxy = coreFrame->script(); if (!proxy) return; #if USE(JSC) proxy->executeScriptInWorld(scriptWorld->world(), script, true); #elif USE(V8) ScriptSourceCode source(script); Vector<ScriptSourceCode> sources; sources.append(source); proxy->evaluateInIsolatedWorld(0, sources, true); #endif }
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()); }
PassRefPtr<JSLazyEventListener> createAttributeEventListener(Node* node, Attribute* attr) { ASSERT(node); ASSERT(attr); if (attr->isNull()) return 0; int lineNumber = 1; String sourceURL; // FIXME: We should be able to provide accurate source information for frameless documents, too (e.g. for importing nodes from XMLHttpRequest.responseXML). if (Frame* frame = node->document()->frame()) { ScriptController* scriptController = frame->script(); if (!scriptController->canExecuteScripts(AboutToExecuteScript)) return 0; if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { // This script is not safe to execute. return 0; } lineNumber = scriptController->eventHandlerLineNumber(); sourceURL = node->document()->url().string(); } return JSLazyEventListener::create(attr->localName().string(), eventParameterName(node->isSVGElement()), attr->value(), node, sourceURL, lineNumber, 0, mainThreadNormalWorld()); }
bool ScriptController::processingUserGesture() { ExecState* exec = JSMainThreadExecState::currentState(); Frame* frame = exec ? toDynamicFrame(exec) : 0; // No script is running, so it is user-initiated unless the gesture stack // explicitly says it is not. if (!frame) return UserGestureIndicator::getUserGestureState() != DefinitelyNotProcessingUserGesture; // FIXME: We check the plugin popup flag and javascript anchor navigation // from the dynamic frame becuase they should only be initiated on the // dynamic frame in which execution began if they do happen. ScriptController* scriptController = frame->script(); ASSERT(scriptController); if (scriptController->allowPopupsFromPlugin() || scriptController->isJavaScriptAnchorNavigation()) return true; // If a DOM event is being processed, check that it was initiated by the user // and that it is in the whitelist of event types allowed to generate pop-ups. if (JSDOMWindowShell* shell = scriptController->existingWindowShell(currentWorld(exec))) if (Event* event = shell->window()->currentEvent()) return event->fromUserGesture(); return UserGestureIndicator::processingUserGesture(); }
PassRefPtr<JSLazyEventListener> createAttributeEventListener(Frame* frame, Attribute* attr) { if (!frame) return 0; ASSERT(attr); if (attr->isNull()) return 0; int lineNumber = 1; String sourceURL; ScriptController* scriptController = frame->script(); if (!scriptController->canExecuteScripts(AboutToExecuteScript)) return 0; if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { // This script is not safe to execute. return 0; } lineNumber = scriptController->eventHandlerLineNumber(); sourceURL = frame->document()->url().string(); JSObject* wrapper = toJSDOMWindow(frame, mainThreadNormalWorld()); return JSLazyEventListener::create(attr->localName().string(), eventParameterName(frame->document()->isSVGDocument()), attr->value(), 0, sourceURL, lineNumber, wrapper, mainThreadNormalWorld()); }
void ScriptCachedFrameData::restore(Frame* frame) { JSLockHolder lock(JSDOMWindowBase::commonJSGlobalData()); ScriptController* scriptController = frame->script(); ScriptController::ShellMap& windowShells = scriptController->m_windowShells; ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end(); for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) { DOMWrapperWorld* world = iter->first.get(); JSDOMWindowShell* windowShell = iter->second.get(); if (JSDOMWindow* window = m_windows.get(world).get()) windowShell->setWindow(window->globalData(), window); else { DOMWindow* domWindow = frame->document()->domWindow(); if (windowShell->window()->impl() == domWindow) continue; windowShell->setWindow(domWindow); if (Page* page = frame->page()) { scriptController->attachDebugger(windowShell, page->debugger()); windowShell->window()->setProfileGroup(page->group().identifier()); } } } }
PassRefPtr<V8LazyEventListener> createAttributeEventListener(Frame* frame, Attribute* attr) { if (!frame) return 0; ASSERT(attr); if (attr->isNull()) return 0; int lineNumber = 1; int columnNumber = 0; String sourceURL; ScriptController* scriptController = frame->script(); if (!scriptController->canExecuteScripts(AboutToExecuteScript)) return 0; if (!scriptController->xssAuditor()->canCreateInlineEventListener(attr->localName().string(), attr->value())) { // This script is not safe to execute. return 0; } if (frame->document()->tokenizer()) { // FIXME: Change to use script->eventHandlerLineNumber() when implemented. lineNumber = frame->document()->tokenizer()->lineNumber(); columnNumber = frame->document()->tokenizer()->columnNumber(); } sourceURL = frame->document()->url().string(); return V8LazyEventListener::create(attr->localName().string(), frame->document()->isSVGDocument(), attr->value(), sourceURL, lineNumber, columnNumber, WorldContextHandle(UseMainWorld)); }
CachedPage::CachedPage(Page* page) : m_timeStamp(0) , m_document(page->mainFrame()->document()) , m_view(page->mainFrame()->view()) , m_mousePressNode(page->mainFrame()->eventHandler()->mousePressNode()) , m_URL(page->mainFrame()->loader()->url()) { #ifndef NDEBUG cachedPageCounter.increment(); #endif m_document->documentWillBecomeInactive(); Frame* mainFrame = page->mainFrame(); mainFrame->clearTimers(); JSLock lock(false); ScriptController* proxy = mainFrame->script(); if (proxy->haveWindowShell()) { m_window = proxy->windowShell()->window(); m_window->pauseTimeouts(m_pausedTimeouts); } m_document->setInPageCache(true); }
JSObject* JSLazyEventListener::initializeJSFunction(ScriptExecutionContext* executionContext) const { ASSERT(executionContext); ASSERT(executionContext->isDocument()); if (!executionContext) return 0; Document* document = static_cast<Document*>(executionContext); if (!document->frame()) return 0; if (!document->contentSecurityPolicy()->allowInlineEventHandlers()) return 0; ScriptController* script = document->frame()->script(); if (!script->canExecuteScripts(AboutToExecuteScript) || script->isPaused()) return 0; JSDOMGlobalObject* globalObject = toJSDOMGlobalObject(executionContext, isolatedWorld()); if (!globalObject) return 0; ExecState* exec = globalObject->globalExec(); MarkedArgumentBuffer args; args.append(jsNontrivialString(exec, stringToUString(m_eventParameterName))); args.append(jsString(exec, m_code)); JSObject* jsFunction = constructFunctionSkippingEvalEnabledCheck(exec, exec->lexicalGlobalObject(), args, Identifier(exec, stringToUString(m_functionName)), stringToUString(m_sourceURL), m_position); // FIXME: is globalExec ok? if (exec->hadException()) { reportCurrentException(exec); exec->clearException(); return 0; } JSFunction* listenerAsFunction = jsCast<JSFunction*>(jsFunction); if (m_originalNode) { if (!wrapper()) { // 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 setWrapper(exec->globalData(), asObject(toJS(exec, globalObject, m_originalNode))); } // Add the event's home element to the scope // (and the document, and the form - see JSHTMLElement::eventHandlerScope) listenerAsFunction->setScope(exec->globalData(), jsCast<JSNode*>(wrapper())->pushEventHandlerScope(exec, listenerAsFunction->scope())); } // Since we only parse once, there's no need to keep data used for parsing around anymore. m_functionName = String(); m_code = String(); m_eventParameterName = String(); m_sourceURL = String(); return jsFunction; }
ScriptCachedPageData::ScriptCachedPageData(Page* page) { JSLock lock(false); ScriptController* scriptController = page->mainFrame()->script(); if (scriptController->haveWindowShell()) { m_window = scriptController->windowShell()->window(); } }
ScriptCachedFrameData::ScriptCachedFrameData(Frame* frame) { JSLock lock(SilenceAssertionsOnly); ScriptController* scriptController = frame->script(); if (scriptController->haveWindowShell()) { m_window = scriptController->windowShell()->window(); scriptController->attachDebugger(0); } }
void JSLazyEventListener::parseCode() const { if (m_parsed) return; if (m_globalObject->scriptExecutionContext()->isDocument()) { JSDOMWindow* window = static_cast<JSDOMWindow*>(m_globalObject); Frame* frame = window->impl()->frame(); if (!frame) return; // FIXME: Is this check needed for non-Document contexts? ScriptController* script = frame->script(); if (!script->isEnabled() || script->isPaused()) return; } m_parsed = true; ExecState* exec = m_globalObject->globalExec(); MarkedArgumentBuffer args; UString sourceURL(m_globalObject->scriptExecutionContext()->url().string()); args.append(jsNontrivialString(exec, m_eventParameterName)); args.append(jsString(exec, m_code)); // FIXME: Passing the document's URL to construct is not always correct, since this event listener might // have been added with setAttribute from a script, and we should pass String() in that case. m_jsFunction = constructFunction(exec, args, Identifier(exec, m_functionName), sourceURL, m_lineNumber); // FIXME: is globalExec ok? JSFunction* listenerAsFunction = static_cast<JSFunction*>(m_jsFunction); if (exec->hadException()) { exec->clearException(); // failed to parse, so let's just make this listener a no-op m_jsFunction = 0; } else if (m_originalNode) { // Add the event's home element to the scope // (and the document, and the form - see JSHTMLElement::eventHandlerScope) ScopeChain scope = listenerAsFunction->scope(); JSValue thisObj = toJS(exec, m_originalNode); if (thisObj.isObject()) { static_cast<JSNode*>(asObject(thisObj))->pushEventHandlerScope(exec, scope); listenerAsFunction->setScope(scope); } } // Since we only parse once, there's no need to keep data used for parsing around anymore. m_functionName = String(); m_code = String(); m_eventParameterName = String(); }
/*! Evaluates the JavaScript defined by \a scriptSource using this frame as context and returns the result of the last executed statement. \sa addToJavaScriptWindowObject(), javaScriptWindowObjectCleared() */ QVariant QWebFrame::evaluateJavaScript(const QString& scriptSource) { ScriptController *proxy = d->frame->script(); QVariant rc; if (proxy) { JSC::JSValuePtr v = proxy->evaluate(ScriptSourceCode(scriptSource)).jsValue(); if (v) { int distance = 0; rc = JSC::Bindings::convertValueToQVariant(proxy->globalObject()->globalExec(), v, QMetaType::Void, &distance); } } return rc; }
void ScriptController::TerminateAll() { m_mutexRunning.Lock(); for (RunningScripts::iterator it = m_RunningScripts.begin(); it != m_RunningScripts.end(); it++) { ScriptController* pScript = *it; if (pScript->m_hProcess && !pScript->m_bDetached) { pScript->Terminate(); } } m_mutexRunning.Unlock(); }
Script* ScriptTarget::addScript(const char* path) { ScriptController* sc = Game::getInstance()->getScriptController(); // Load the script Script* script = sc->loadScript(path, Script::PROTECTED); if (!script) return NULL; // Attach the script ScriptEntry* se = new ScriptEntry(script); if (_scripts) { ScriptEntry* last = _scripts; while (last->next) last = last->next; last->next = se; se->prev = last; } else { _scripts = se; } // Inspect the loaded script for event functions that are supported by this ScriptTarget. // TODO: We'll need to re-load eventCallbacks when EventRegistries change for this ScriptObject. RegistryEntry* re = _scriptRegistries; while (re) { std::vector<Event*>& events = re->registry->_events; for (size_t i = 0, count = events.size(); i < count; ++i) { const Event* event = events[i]; if (sc->functionExists(event->name.c_str(), script)) { if (!_scriptCallbacks) _scriptCallbacks = new std::map<const Event*, std::vector<CallbackFunction>>(); (*_scriptCallbacks)[event].push_back(CallbackFunction(script, event->name.c_str())); } } re = re->next; } // Automatically call the 'attached' event if it is defined within the script if (sc->functionExists("attached", script)) { sc->executeFunction<void>(script, "attached", "<ScriptTarget>", NULL, (void*)this); } return script; }
ScriptCachedFrameData::ScriptCachedFrameData(Frame* frame) { JSLockHolder lock(JSDOMWindowBase::commonJSGlobalData()); ScriptController* scriptController = frame->script(); ScriptController::ShellMap& windowShells = scriptController->m_windowShells; ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end(); for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) { JSDOMWindow* window = iter->second->window(); m_windows.add(iter->first.get(), Strong<JSDOMWindow>(window->globalData(), window)); } scriptController->attachDebugger(0); }
QVariant QWebFrameAdapter::evaluateJavaScript(const QString &scriptSource) { ScriptController* scriptController = frame->script(); QVariant rc; if (scriptController) { int distance = 0; ScriptValue value = scriptController->executeScript(ScriptSourceCode(scriptSource)); JSC::ExecState* exec = scriptController->globalObject(mainThreadNormalWorld())->globalExec(); JSValueRef* ignoredException = 0; JSC::JSLock::lock(exec); JSValueRef valueRef = toRef(exec, value.jsValue()); JSC::JSLock::unlock(exec); rc = JSC::Bindings::convertValueToQVariant(toRef(exec), valueRef, QMetaType::Void, &distance, ignoredException); } return rc; }
ScriptPreprocessor::ScriptPreprocessor(const ScriptSourceCode& preprocessorSourceCode, ScriptController& controller, PageConsole& console) : m_isPreprocessing(false) { v8::TryCatch tryCatch; tryCatch.SetVerbose(true); Vector<ScriptSourceCode> sources; sources.append(preprocessorSourceCode); Vector<ScriptValue> scriptResults; controller.executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorldId, sources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults); if (scriptResults.size() != 1) { console.addMessage(JSMessageSource, ErrorMessageLevel, "ScriptPreprocessor internal error, one ScriptSourceCode must give exactly one result."); return; } ScriptValue preprocessorFunction = scriptResults[0]; if (!preprocessorFunction.isFunction()) { console.addMessage(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function."); return; } m_world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWorldId, DOMWrapperWorld::mainWorldExtensionGroup); v8::Local<v8::Context> context = m_world->context(controller); m_isolate = context->GetIsolate(); m_context.set(m_isolate, context); m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction.v8Value())); }
PassRefPtr<JSLazyEventListener> createAttributeEventListener(Frame* frame, const QualifiedName& name, const AtomicString& value) { if (!frame) return 0; if (value.isNull()) return 0; ScriptController* scriptController = frame->script(); if (!scriptController->canExecuteScripts(AboutToExecuteScript)) return 0; TextPosition position = scriptController->eventHandlerPosition(); String sourceURL = frame->document()->url().string(); JSObject* wrapper = toJSDOMWindow(frame, mainThreadNormalWorld()); return JSLazyEventListener::create(name.localName().string(), eventParameterName(frame->document()->isSVGDocument()), value, 0, sourceURL, position, wrapper, mainThreadNormalWorld()); }
void ScheduledAction::execute(ScriptExecutionContext* context) { if (context->isDocument()) { Frame* frame = static_cast<Document*>(context)->frame(); ScriptController* scriptController = frame->script(); if (!scriptController->canExecuteScripts(NotAboutToExecuteScript)) return; V8Proxy* proxy = V8Proxy::retrieve(frame); execute(proxy); } #if ENABLE(WORKERS) else { ASSERT(context->isWorkerContext()); execute(static_cast<WorkerContext*>(context)); } #endif }
ScriptCachedFrameData::ScriptCachedFrameData(Frame* frame) : m_domWindow(0) { JSLock lock(SilenceAssertionsOnly); ScriptController* scriptController = frame->script(); ScriptController::ShellMap& windowShells = scriptController->m_windowShells; ScriptController::ShellMap::iterator windowShellsEnd = windowShells.end(); for (ScriptController::ShellMap::iterator iter = windowShells.begin(); iter != windowShellsEnd; ++iter) { JSDOMWindow* window = iter->second->window(); m_windows.add(iter->first.get(), window); m_domWindow = window->impl(); } scriptController->attachDebugger(0); }
void ScriptCachedPageData::restore(Page* page) { Frame* mainFrame = page->mainFrame(); JSLock lock(false); ScriptController* scriptController = mainFrame->script(); if (scriptController->haveWindowShell()) { JSDOMWindowShell* windowShell = scriptController->windowShell(); if (m_window) { windowShell->setWindow(m_window.get()); } else { windowShell->setWindow(mainFrame->domWindow()); scriptController->attachDebugger(page->debugger()); windowShell->window()->setProfileGroup(page->group().identifier()); } } }
void ScriptCachedFrameData::restore(Frame* frame) { Page* page = frame->page(); JSLock lock(SilenceAssertionsOnly); ScriptController* scriptController = frame->script(); if (scriptController->haveWindowShell()) { JSDOMWindowShell* windowShell = scriptController->windowShell(); if (m_window) { windowShell->setWindow(m_window.get()); } else { windowShell->setWindow(frame->domWindow()); scriptController->attachDebugger(page->debugger()); windowShell->window()->setProfileGroup(page->group().identifier()); } } }
bool InspectorClient::doDispatchMessageOnFrontendPage(Page* frontendPage, const String& message) { if (!frontendPage) return false; Frame* frame = frontendPage->mainFrame(); if (!frame) return false; ScriptController* scriptController = frame->script(); if (!scriptController) return false; String dispatchToFrontend = "InspectorFrontendAPI.dispatchMessageAsync(" + message + ");"; // FIXME: This should execute the script in the appropriate world. scriptController->evaluate(ScriptSourceCode(dispatchToFrontend)); return true; }
void DumpRenderTreeSupportQt::evaluateScriptInIsolatedWorld(QWebFrameAdapter *adapter, int worldID, const QString& script) { QWebScriptWorld* scriptWorld; if (!worldID) { scriptWorld = new QWebScriptWorld(); } else if (!m_worldMap.contains(worldID)) { scriptWorld = new QWebScriptWorld(); m_worldMap.insert(worldID, scriptWorld); } else scriptWorld = m_worldMap.value(worldID); WebCore::Frame* coreFrame = adapter->frame; ScriptController* proxy = coreFrame->script(); if (!proxy) return; proxy->executeScriptInWorld(scriptWorld->world(), script, true); }
bool InspectorClient::sendMessageToFrontend(const String& message) { if (!m_frontendPage) return false; Frame* frame = m_frontendPage->mainFrame(); if (!frame) return false; ScriptController* scriptController = frame->script(); if (!scriptController) return false; String dispatchToFrontend("WebInspector.dispatchMessageFromBackend("); dispatchToFrontend += message; dispatchToFrontend += ");"; scriptController->executeScript(dispatchToFrontend); return true; }
PassRefPtr<JSLazyEventListener> createAttributeEventListener(Frame* frame, Attribute* attr) { 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; } // 'globalObject' is the JavaScript wrapper that will mark the event listener we're creating. JSDOMWindow* globalObject = scriptController->globalObject(); return JSLazyEventListener::create(attr->localName().string(), eventParameterName(frame->document()->isSVGDocument()), attr->value(), globalObject, 0, scriptController->eventHandlerLineNumber()); }
PassRefPtr<JSLazyEventListener> createAttributeEventListener(Node* node, const QualifiedName& name, const AtomicString& value) { ASSERT(node); if (value.isNull()) return 0; TextPosition position = TextPosition::minimumPosition(); String sourceURL; // FIXME: We should be able to provide accurate source information for frameless documents, too (e.g. for importing nodes from XMLHttpRequest.responseXML). if (Frame* frame = node->document()->frame()) { ScriptController* scriptController = frame->script(); if (!scriptController->canExecuteScripts(AboutToExecuteScript)) return 0; position = scriptController->eventHandlerPosition(); sourceURL = node->document()->url().string(); } return JSLazyEventListener::create(name.localName().string(), eventParameterName(node->isSVGElement()), value, node, sourceURL, position, 0, mainThreadNormalWorld()); }
int lua_ScriptController_loadUrl(lua_State* state) { // Get the number of parameters. int paramCount = lua_gettop(state); // Attempt to match the parameters to a valid binding. switch (paramCount) { case 2: { if ((lua_type(state, 1) == LUA_TUSERDATA) && (lua_type(state, 2) == LUA_TSTRING || lua_type(state, 2) == LUA_TNIL)) { // Get parameter 1 off the stack. const char* param1 = ScriptUtil::getString(2, false); ScriptController* instance = getInstance(state); std::string result = instance->loadUrl(param1); // Push the return value onto the stack. lua_pushstring(state, result.c_str()); return 1; } else { lua_pushstring(state, "lua_ScriptController_loadUrl - Failed to match the given parameters to a valid function signature."); lua_error(state); } break; } default: { lua_pushstring(state, "Invalid number of parameters (expected 2)."); lua_error(state); break; } } return 0; }
void CachedPage::restore(Page* page) { ASSERT(m_document->view() == m_view); Frame* mainFrame = page->mainFrame(); JSLock lock(false); ScriptController* proxy = mainFrame->script(); if (proxy->haveWindowShell()) { JSDOMWindowShell* windowShell = proxy->windowShell(); if (m_window) { windowShell->setWindow(m_window.get()); windowShell->window()->resumeTimeouts(m_pausedTimeouts); } else { windowShell->setWindow(mainFrame->domWindow()); proxy->attachDebugger(page->debugger()); windowShell->window()->setProfileGroup(page->group().identifier()); } } #if ENABLE(SVG) if (m_document && m_document->svgExtensions()) m_document->accessSVGExtensions()->unpauseAnimations(); #endif mainFrame->animation()->resumeAnimations(m_document.get()); mainFrame->eventHandler()->setMousePressNode(mousePressNode()); // Restore the focus appearance for the focused element. // FIXME: Right now we don't support pages w/ frames in the b/f cache. This may need to be tweaked when we add support for that. Document* focusedDocument = page->focusController()->focusedOrMainFrame()->document(); if (Node* node = focusedDocument->focusedNode()) { if (node->isElementNode()) static_cast<Element*>(node)->updateFocusAppearance(true); } }