📄 jsdomwindowbase.cpp
字号:
unsigned i = propertyName.toArrayIndex(&ok); if (ok && i < impl()->frame()->tree()->childCount()) { slot.setCustomIndex(this, i, indexGetter); return true; } if (!allowsAccessFrom(exec)) { slot.setUndefined(); return true; } // Allow shortcuts like 'Image1' instead of document.images.Image1 Document* document = impl()->frame()->document(); if (document->isHTMLDocument()) { AtomicStringImpl* atomicPropertyName = AtomicString::find(propertyName); if (atomicPropertyName && (static_cast<HTMLDocument*>(document)->hasNamedItem(atomicPropertyName) || document->hasElementWithId(atomicPropertyName))) { slot.setCustom(this, namedItemGetter); return true; } } return Base::getOwnPropertySlot(exec, propertyName, slot);}void JSDOMWindowBase::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot){ const HashEntry* entry = JSDOMWindowBaseTable.entry(exec, propertyName); if (entry) { if (entry->attributes() & Function) { if (allowsAccessFrom(exec)) Base::put(exec, propertyName, value, slot); return; } if (entry->attributes() & ReadOnly) return; } if (allowsAccessFrom(exec)) Base::put(exec, propertyName, value, slot);}String JSDOMWindowBase::crossDomainAccessErrorMessage(const JSGlobalObject* other) const{ KURL originURL = asJSDOMWindow(other)->impl()->url(); KURL targetURL = impl()->frame()->document()->url(); if (originURL.isNull() || targetURL.isNull()) return String(); // FIXME: this error message should contain more specifics of why the same origin check has failed. return String::format("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains, protocols and ports must match.\n", targetURL.string().utf8().data(), originURL.string().utf8().data());}void JSDOMWindowBase::printErrorMessage(const String& message) const{ if (message.isEmpty()) return; Frame* frame = impl()->frame(); if (!frame) return; Settings* settings = frame->settings(); if (!settings) return; if (settings->privateBrowsingEnabled()) return; impl()->console()->addMessage(JSMessageSource, ErrorMessageLevel, message, 1, String()); // FIXME: provide a real line number and source URL.}ExecState* JSDOMWindowBase::globalExec(){ // We need to make sure that any script execution happening in this // frame does not destroy it if (Frame *frame = impl()->frame()) frame->keepAlive(); return Base::globalExec();}bool JSDOMWindowBase::supportsProfiling() const{ Frame* frame = impl()->frame(); if (!frame) return false; Page* page = frame->page(); if (!page) return false; return page->inspectorController()->profilerEnabled();}bool JSDOMWindowBase::shouldInterruptScript() const{ ASSERT(impl()->frame()); Page* page = impl()->frame()->page(); // See <rdar://problem/5479443>. We don't think that page can ever be NULL // in this case, but if it is, we've gotten into a state where we may have // hung the UI, with no way to ask the client whether to cancel execution. // For now, our solution is just to cancel execution no matter what, // ensuring that we never hang. We might want to consider other solutions // if we discover problems with this one. ASSERT(page); if (!page) return true; return page->chrome()->shouldInterruptJavaScript();}void JSDOMWindowBase::clearHelperObjectProperties(){ setCurrentEvent(0);}void JSDOMWindowBase::clear(){ JSLock lock(false); if (d()->returnValueSlot && !*d()->returnValueSlot) *d()->returnValueSlot = getDirect(Identifier(globalExec(), "returnValue")); clearHelperObjectProperties();}JSObject* JSDOMWindowBase::toThisObject(ExecState*) const{ return shell();}JSDOMWindowShell* JSDOMWindowBase::shell() const{ return d()->shell;}JSGlobalData* JSDOMWindowBase::commonJSGlobalData(){ static JSGlobalData* globalData; if (!globalData) { globalData = JSGlobalData::createLeaked().releaseRef(); globalData->timeoutChecker.setTimeoutInterval(10000); // 10 seconds } return globalData;}} // namespace WebCoreusing namespace WebCore;JSValuePtr windowProtoFuncOpen(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(); Frame* activeFrame = asJSDOMWindow(exec->dynamicGlobalObject())->impl()->frame(); if (!activeFrame) return jsUndefined(); Page* page = frame->page(); String urlString = valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 0)); AtomicString frameName = args.at(exec, 1).isUndefinedOrNull() ? "_blank" : AtomicString(args.at(exec, 1).toString(exec)); // Because FrameTree::find() returns true for empty strings, we must check for empty framenames. // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker. if (!allowPopUp(exec) && (frameName.isEmpty() || !frame->tree()->find(frameName))) return jsUndefined(); // Get the target frame for the special cases of _top and _parent. In those // cases, we can schedule a location change right now and return early. bool topOrParent = false; if (frameName == "_top") { frame = frame->tree()->top(); topOrParent = true; } else if (frameName == "_parent") { if (Frame* parent = frame->tree()->parent()) frame = parent; topOrParent = true; } if (topOrParent) { if (!activeFrame->loader()->shouldAllowNavigation(frame)) return jsUndefined(); String completedURL; if (!urlString.isEmpty()) completedURL = activeFrame->document()->completeURL(urlString).string(); const JSDOMWindow* targetedWindow = toJSDOMWindow(frame); if (!completedURL.isEmpty() && (!protocolIs(completedURL, "javascript") || (targetedWindow && targetedWindow->allowsAccessFrom(exec)))) { bool userGesture = activeFrame->script()->processingUserGesture(); frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), !activeFrame->script()->anyPageIsProcessingUserGesture(), false, userGesture); } return toJS(exec, frame->domWindow()); } // In the case of a named frame or a new window, we'll use the createWindow() helper WindowFeatures windowFeatures(valueToStringWithUndefinedOrNullCheck(exec, args.at(exec, 2))); FloatRect windowRect(windowFeatures.xSet ? windowFeatures.x : 0, windowFeatures.ySet ? windowFeatures.y : 0, windowFeatures.widthSet ? windowFeatures.width : 0, windowFeatures.heightSet ? windowFeatures.height : 0); DOMWindow::adjustWindowRect(screenAvailableRect(page ? page->mainFrame()->view() : 0), windowRect, windowRect); windowFeatures.x = windowRect.x(); windowFeatures.y = windowRect.y(); windowFeatures.height = windowRect.height(); windowFeatures.width = windowRect.width(); frame = createWindow(exec, frame, urlString, frameName, windowFeatures, noValue()); if (!frame) return jsUndefined(); return toJS(exec, frame->domWindow()); // global object}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)));}JSValuePtr windowProtoFuncNotImplemented(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList&){ if (!toJSDOMWindow(thisValue)) return throwError(exec, TypeError); return jsUndefined();}namespace WebCore {void JSDOMWindowBase::setReturnValueSlot(JSValuePtr* slot){ d()->returnValueSlot = slot;}////////////////////// timeouts ////////////////////////int JSDOMWindowBase::installTimeout(ScheduledAction* a, int t, bool singleShot){ return DOMTimer::install(scriptExecutionContext(), a, t, singleShot);}int JSDOMWindowBase::installTimeout(const UString& handler, int t, bool singleShot){ return installTimeout(new ScheduledAction(handler), t, singleShot);}int JSDOMWindowBase::installTimeout(ExecState* exec, JSValuePtr func, const ArgList& args, int t, bool singleShot){ return installTimeout(new ScheduledAction(exec, func, args), t, singleShot);}void JSDOMWindowBase::removeTimeout(int timeoutId){ DOMTimer::removeById(scriptExecutionContext(), timeoutId);}void JSDOMWindowBase::disconnectFrame(){}JSValuePtr toJS(ExecState*, DOMWindow* domWindow){ if (!domWindow) return jsNull(); Frame* frame = domWindow->frame(); if (!frame) return jsNull(); return frame->script()->windowShell();}JSDOMWindow* toJSDOMWindow(Frame* frame){ if (!frame) return 0; return frame->script()->windowShell()->window();}JSDOMWindow* toJSDOMWindow(JSValuePtr value){ if (!value.isObject()) return 0; const ClassInfo* classInfo = asObject(value)->classInfo(); if (classInfo == &JSDOMWindow::s_info) return static_cast<JSDOMWindow*>(asObject(value)); if (classInfo == &JSDOMWindowShell::s_info) return static_cast<JSDOMWindowShell*>(asObject(value))->window(); return 0;}} // namespace WebCore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -