bool JSDOMWindow::deletePropertyByIndex(JSCell* cell, ExecState* exec, unsigned propertyName) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(cell); // Only allow deleting properties by frames in the same origin. if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), ThrowSecurityError)) return false; return Base::deletePropertyByIndex(thisObject, exec, propertyName); }
bool InjectedScriptHost::canAccessInspectedWindow(ScriptState* scriptState) { JSLock lock(SilenceAssertionsOnly); JSDOMWindow* inspectedWindow = toJSDOMWindow(scriptState->lexicalGlobalObject()); if (!inspectedWindow) return false; return inspectedWindow->allowsAccessFromNoErrorMessage(scriptState); }
static Page* toPage(JSGlobalObject* globalObject) { ASSERT_ARG(globalObject, globalObject); JSDOMWindow* window = asJSDOMWindow(globalObject); Frame* frame = window->impl()->frame(); return frame ? frame->page() : 0; }
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())); }
bool JSDOMWindow::deleteProperty(JSCell* cell, ExecState* exec, PropertyName propertyName) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(cell); // Only allow deleting properties by frames in the same origin. if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObject->impl())) return false; return Base::deleteProperty(thisObject, exec, propertyName); }
uint32_t JSDOMWindow::getEnumerableLength(ExecState* exec, JSObject* object) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object); // Only allow the window to enumerated by frames in the same origin. if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObject->wrapped())) return 0; return Base::getEnumerableLength(exec, thisObject); }
void JSDOMWindow::getStructurePropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object); // Only allow the window to enumerated by frames in the same origin. if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObject->wrapped())) return; Base::getStructurePropertyNames(thisObject, exec, propertyNames, mode); }
inline void DialogHandler::dialogCreated(DOMWindow* dialog) { m_frame = dialog->frame(); // FIXME: This looks like a leak between the normal world and an isolated // world if dialogArguments comes from an isolated world. JSDOMWindow* globalObject = toJSDOMWindow(m_frame.get(), normalWorld(m_exec->globalData())); if (JSValue dialogArguments = m_exec->argument(1)) globalObject->putDirect(m_exec->globalData(), Identifier(m_exec, "dialogArguments"), dialogArguments); }
bool InspectorController::canAccessInspectedScriptState(JSC::ExecState* scriptState) const { JSLockHolder lock(scriptState); JSDOMWindow* inspectedWindow = toJSDOMWindow(scriptState->lexicalGlobalObject()); if (!inspectedWindow) return false; return BindingSecurity::shouldAllowAccessToDOMWindow(scriptState, inspectedWindow->wrapped(), DoNotReportSecurityError); }
void JSDOMWindow::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object); if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), DoNotReportSecurityError)) { if (mode.includeDontEnumProperties()) addCrossOriginWindowPropertyNames(*exec, propertyNames); return; } Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode); }
void ScriptController::attachDebugger(JSDOMWindowShell* shell, JSC::Debugger* debugger) { if (!shell) return; JSDOMWindow* globalObject = shell->window(); if (debugger) debugger->attach(globalObject); else if (JSC::Debugger* currentDebugger = globalObject->debugger()) currentDebugger->detach(globalObject); }
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 ScriptController::attachDebugger(JSDOMWindowShell* shell, JSC::Debugger* debugger) { if (!shell) return; JSDOMWindow* globalObject = shell->window(); JSLockHolder lock(globalObject->vm()); if (debugger) debugger->attach(globalObject); else if (JSC::Debugger* currentDebugger = globalObject->debugger()) currentDebugger->detach(globalObject, JSC::Debugger::TerminatingDebuggingSession); }
void JSDOMWindow::visitChildren(JSCell* cell, SlotVisitor& visitor) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(cell); ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info); COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag); ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren()); Base::visitChildren(thisObject, visitor); thisObject->impl()->visitJSEventListeners(visitor); if (Frame* frame = thisObject->impl()->frame()) visitor.addOpaqueRoot(frame); }
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(); }
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); }
bool JSDOMWindow::defineOwnProperty(JSC::JSObject* object, JSC::ExecState* exec, JSC::PropertyName propertyName, const JSC::PropertyDescriptor& descriptor, bool shouldThrow) { JSDOMWindow* thisObject = jsCast<JSDOMWindow*>(object); // Only allow defining properties in this way by frames in the same origin, as it allows setters to be introduced. if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, thisObject->wrapped(), ThrowSecurityError)) return false; // Don't allow shadowing location using accessor properties. if (descriptor.isAccessorDescriptor() && propertyName == Identifier::fromString(exec, "location")) return false; return Base::defineOwnProperty(thisObject, exec, propertyName, descriptor, shouldThrow); }
// Helper for window.open() and window.showModalDialog() static Frame* createWindow(ExecState* exec, Frame* lexicalFrame, Frame* dynamicFrame, Frame* openerFrame, const String& url, const String& frameName, const WindowFeatures& windowFeatures, JSValue dialogArgs) { ASSERT(lexicalFrame); ASSERT(dynamicFrame); ResourceRequest request; // For whatever reason, Firefox uses the dynamicGlobalObject to determine // the outgoingReferrer. We replicate that behavior here. String referrer = dynamicFrame->loader()->outgoingReferrer(); request.setHTTPReferrer(referrer); FrameLoader::addHTTPOriginIfNeeded(request, dynamicFrame->loader()->outgoingOrigin()); FrameLoadRequest frameRequest(request, frameName); // FIXME: It's much better for client API if a new window starts with a URL, here where we // know what URL we are going to open. Unfortunately, this code passes the empty string // for the URL, but there's a reason for that. Before loading we have to set up the opener, // openedByDOM, and dialogArguments values. Also, to decide whether to use the URL we currently // do an allowsAccessFrom call using the window we create, which can't be done before creating it. // We'd have to resolve all those issues to pass the URL instead of "". bool created; // We pass the opener frame for the lookupFrame in case the active frame is different from // the opener frame, and the name references a frame relative to the opener frame. Frame* newFrame = createWindow(lexicalFrame, openerFrame, frameRequest, windowFeatures, created); if (!newFrame) return 0; newFrame->loader()->setOpener(openerFrame); newFrame->page()->setOpenedByDOM(); // FIXME: If a window is created from an isolated world, what are the consequences of this? 'dialogArguments' only appears back in the normal world? JSDOMWindow* newWindow = toJSDOMWindow(newFrame, normalWorld(exec->globalData())); if (dialogArgs) newWindow->putDirect(Identifier(exec, "dialogArguments"), dialogArgs); if (!protocolIsJavaScript(url) || newWindow->allowsAccessFrom(exec)) { KURL completedURL = url.isEmpty() ? KURL(ParsedURLString, "") : completeURL(exec, url); bool userGesture = processingUserGesture(); if (created) newFrame->loader()->changeLocation(completedURL, referrer, false, false, userGesture); else if (!url.isEmpty()) newFrame->redirectScheduler()->scheduleLocationChange(completedURL.string(), referrer, !lexicalFrame->script()->anyPageIsProcessingUserGesture(), false, userGesture); } return newFrame; }
JSValuePtr windowProtoFuncShowModalDialog(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args) { JSDOMWindow* window = toJSDOMWindow(thisValue); if (!window) return throwError(exec, TypeError); if (!window->allowsAccessFrom(exec)) return jsUndefined(); Frame* frame = window->impl()->frame(); if (!frame) return jsUndefined(); return showModalDialog(exec, frame, valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0)), args.at(exec, 1), valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 2))); }
ScriptCachedFrameData::ScriptCachedFrameData(Frame& frame) { JSLockHolder lock(JSDOMWindowBase::commonVM()); 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->value->window(); m_windows.add(iter->key.get(), Strong<JSDOMWindow>(window->vm(), window)); } scriptController.attachDebugger(0); }
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); }
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 }
void ScheduledAction::execute(Document* document) { JSDOMWindow* window = toJSDOMWindow(document->frame(), m_isolatedWorld.get()); if (!window) return; RefPtr<Frame> frame = window->impl()->frame(); if (!frame || !frame->script()->canExecuteScripts(AboutToExecuteScript)) return; if (m_function) executeFunctionInContext(window, window->shell(), document); else frame->script()->executeScriptInWorld(m_isolatedWorld.get(), m_code); }
ScriptCachedFrameData::ScriptCachedFrameData(Frame& frame) { JSLockHolder lock(JSDOMWindowBase::commonVM()); ScriptController& scriptController = frame.script(); Vector<JSC::Strong<JSDOMWindowShell>> windowShells = scriptController.windowShells(); for (size_t i = 0; i < windowShells.size(); ++i) { JSDOMWindowShell* windowShell = windowShells[i].get(); JSDOMWindow* window = windowShell->window(); m_windows.add(&windowShell->world(), Strong<JSDOMWindow>(window->vm(), window)); window->setConsoleClient(nullptr); } scriptController.attachDebugger(nullptr); }
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 JSLock lock(SilenceAssertionsOnly); JSDOMWindow* globalObj = globalObject(pluginWorld()); // FIXME: is normal okay? - used for NP plugins? JSValue jsElementValue = toJS(globalObj->globalExec(), globalObj, plugin); if (!jsElementValue || !jsElementValue.isObject()) return 0; return jsElementValue.getObject(); }
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())); }
JSValue JSLocation::reload(ExecState* exec, const ArgList&) { Frame* frame = impl()->frame(); if (!frame) return jsUndefined(); JSDOMWindow* window = toJSDOMWindow(frame); if (!window->allowsAccessFrom(exec)) return jsUndefined(); if (!frame->loader()->url().protocolIs("javascript") || (window && window->allowsAccessFrom(exec))) { bool userGesture = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame()->script()->processingUserGesture(); frame->loader()->scheduleRefresh(userGesture); } return jsUndefined(); }
static Frame* createWindow(ExecState* exec, Frame* openerFrame, const String& url, const String& frameName, const WindowFeatures& windowFeatures, JSValuePtr dialogArgs) { Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); ASSERT(activeFrame); ResourceRequest request; request.setHTTPReferrer(activeFrame->loader()->outgoingReferrer()); FrameLoader::addHTTPOriginIfNeeded(request, activeFrame->loader()->outgoingOrigin()); FrameLoadRequest frameRequest(request, frameName); // FIXME: It's much better for client API if a new window starts with a URL, here where we // know what URL we are going to open. Unfortunately, this code passes the empty string // for the URL, but there's a reason for that. Before loading we have to set up the opener, // openedByDOM, and dialogArguments values. Also, to decide whether to use the URL we currently // do an allowsAccessFrom call using the window we create, which can't be done before creating it. // We'd have to resolve all those issues to pass the URL instead of "". bool created; // We pass in the opener frame here so it can be used for looking up the frame name, in case the active frame // is different from the opener frame, and the name references a frame relative to the opener frame, for example // "_self" or "_parent". Frame* newFrame = activeFrame->loader()->createWindow(openerFrame->loader(), frameRequest, windowFeatures, created); if (!newFrame) return 0; newFrame->loader()->setOpener(openerFrame); newFrame->loader()->setOpenedByDOM(); JSDOMWindow* newWindow = toJSDOMWindow(newFrame); if (dialogArgs) newWindow->putDirect(Identifier(exec, "dialogArguments"), dialogArgs); if (!protocolIs(url, "javascript") || newWindow->allowsAccessFrom(exec)) { KURL completedURL = url.isEmpty() ? KURL("") : activeFrame->document()->completeURL(url); bool userGesture = activeFrame->script()->processingUserGesture(); if (created) newFrame->loader()->changeLocation(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture); else if (!url.isEmpty()) newFrame->loader()->scheduleLocationChange(completedURL.string(), activeFrame->loader()->outgoingReferrer(), false, userGesture); } return newFrame; }
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); }