📄 kjs_window.cpp
字号:
case Window::GetSelection: if (!window->isSafeScript(exec)) return Undefined(); return Value(window->selection()); case Window::Blur:#if APPLE_CHANGES KWQ(part)->unfocusWindow();#else // TODO#endif return Undefined(); case Window::Close: /* From http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm : The close method closes only windows opened by JavaScript using the open method. If you attempt to close any other window, a confirm is generated, which lets the user choose whether the window closes. This is a security feature to prevent "mail bombs" containing self.close(). However, if the window has only one document (the current one) in its session history, the close is allowed without any confirm. This is a special case for one-off windows that need to open other windows and then dispose of themselves. */ if (!part->openedByJS()) { // To conform to the SPEC, we only ask if the window // has more than one entry in the history (NS does that too). History history(exec,part); if ( history.get( exec, lengthPropertyName ).toInt32(exec) <= 1#if APPLE_CHANGES // FIXME: How are we going to handle this?#else || KMessageBox::questionYesNo( window->part()->view(), i18n("Close window?"), i18n("Confirmation Required") ) == KMessageBox::Yes#endif ) (const_cast<Window*>(window))->scheduleClose(); } else { (const_cast<Window*>(window))->scheduleClose(); } return Undefined(); case Window::CaptureEvents: case Window::ReleaseEvents: // If anyone implements these, they need the safescript security check. if (!window->isSafeScript(exec)) return Undefined(); // Do nothing for now. These are NS-specific legacy calls. break; case Window::AddEventListener: { if (!window->isSafeScript(exec)) return Undefined(); JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]); if (listener) { DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle()); docimpl->addWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec)); } return Undefined(); } case Window::RemoveEventListener: { if (!window->isSafeScript(exec)) return Undefined(); JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]); if (listener) { DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle()); docimpl->removeWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec)); } return Undefined(); } } return Undefined();}void Window::updateLayout() const{ DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(m_part->document().handle()); if (docimpl) { docimpl->updateLayout(); }}////////////////////// ScheduledAction ////////////////////////ScheduledAction::ScheduledAction(Object _func, List _args, bool _singleShot){ //kdDebug(6070) << "ScheduledAction::ScheduledAction(isFunction) " << this << endl; func = _func; args = _args; isFunction = true; singleShot = _singleShot;}ScheduledAction::ScheduledAction(const QString &_code, bool _singleShot){ //kdDebug(6070) << "ScheduledAction::ScheduledAction(!isFunction) " << this << endl; //func = 0; //args = 0; code = _code; isFunction = false; singleShot = _singleShot;}void ScheduledAction::execute(Window *window){ ScriptInterpreter *interpreter = static_cast<ScriptInterpreter *>(KJSProxy::proxy(window->m_part)->interpreter()); interpreter->setProcessingTimerCallback(true); //kdDebug(6070) << "ScheduledAction::execute " << this << endl; if (isFunction) { if (func.implementsCall()) { // #### check this Q_ASSERT( window->m_part ); if ( window->m_part ) { KJS::Interpreter *interpreter = KJSProxy::proxy( window->m_part )->interpreter(); ExecState *exec = interpreter->globalExec(); Q_ASSERT( window == interpreter->globalObject().imp() ); Object obj( window ); Interpreter::lock(); func.call(exec,obj,args); // note that call() creates its own execution state for the func call Interpreter::unlock(); if ( exec->hadException() ) {#if APPLE_CHANGES Interpreter::lock(); char *message = exec->exception().toObject(exec).get(exec, messagePropertyName).toString(exec).ascii(); int lineNumber = exec->exception().toObject(exec).get(exec, "line").toInt32(exec); Interpreter::unlock(); if (Interpreter::shouldPrintExceptions()) { printf("(timer):%s\n", message); } KWQ(window->m_part)->addMessageToConsole(message, lineNumber, QString());#endif exec->clearException(); } } } } else { window->m_part->executeScript(code); } // Update our document's rendering following the execution of the timeout callback. DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(window->m_part->document().handle()); doc->updateRendering(); interpreter->setProcessingTimerCallback(false);}ScheduledAction::~ScheduledAction(){ //kdDebug(6070) << "ScheduledAction::~ScheduledAction " << this << endl;}////////////////////// WindowQObject ////////////////////////WindowQObject::WindowQObject(Window *w) : parent(w){ QOBJECT_TYPE(KJS::WindowQObject); //kdDebug(6070) << "WindowQObject::WindowQObject " << this << endl; part = parent->m_part; connect( parent->m_part, SIGNAL( destroyed() ), this, SLOT( parentDestroyed() ) );}WindowQObject::~WindowQObject(){ //kdDebug(6070) << "WindowQObject::~WindowQObject " << this << endl; parentDestroyed(); // reuse same code}void WindowQObject::parentDestroyed(){ //kdDebug(6070) << "WindowQObject::parentDestroyed " << this << " we have " << scheduledActions.count() << " actions in the map" << endl; killTimers(); QMapIterator<int,ScheduledAction*> it; for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) { ScheduledAction *action = *it; //kdDebug(6070) << "WindowQObject::parentDestroyed deleting action " << action << endl; delete action; } scheduledActions.clear();}int WindowQObject::installTimeout(const UString &handler, int t, bool singleShot){ //kdDebug(6070) << "WindowQObject::installTimeout " << this << " " << handler.ascii() << endl; int id = startTimer(t); ScheduledAction *action = new ScheduledAction(handler.qstring(),singleShot); scheduledActions.insert(id, action); //kdDebug(6070) << this << " got id=" << id << " action=" << action << " - now having " << scheduledActions.count() << " actions"<<endl; return id;}int WindowQObject::installTimeout(const Value &func, List args, int t, bool singleShot){ Object objFunc = Object::dynamicCast( func ); int id = startTimer(t); scheduledActions.insert(id, new ScheduledAction(objFunc,args,singleShot)); return id;}QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key){ QMapIterator<int,ScheduledAction*> it; QMap<int, KJS::ScheduledAction*>*pausedActions = new QMap<int, KJS::ScheduledAction*>; for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) { int timerId = it.key(); pauseTimer (timerId, key); pausedActions->insert(timerId, it.data()); } scheduledActions.clear(); return pausedActions;}void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key){ QMapIterator<int,ScheduledAction*> it; for (it = sa->begin(); it != sa->end(); ++it) { int timerId = it.key(); scheduledActions.insert(timerId, it.data()); } sa->clear(); resumeTimers (key, this);}void WindowQObject::clearTimeout(int timerId, bool delAction){ //kdDebug(6070) << "WindowQObject::clearTimeout " << this << " timerId=" << timerId << " delAction=" << delAction << endl; killTimer(timerId); if (delAction) { QMapIterator<int,ScheduledAction*> it = scheduledActions.find(timerId); if (it != scheduledActions.end()) { ScheduledAction *action = *it; scheduledActions.remove(it); delete action; } }}void WindowQObject::timerEvent(QTimerEvent *e){ QMapIterator<int,ScheduledAction*> it = scheduledActions.find(e->timerId()); if (it != scheduledActions.end()) { ScheduledAction *action = *it; bool singleShot = action->singleShot; //kdDebug(6070) << "WindowQObject::timerEvent " << this << " action=" << action << " singleShot:" << singleShot << endl; // remove single shots installed by setTimeout() if (singleShot) { clearTimeout(e->timerId(),false); scheduledActions.remove(it); } if (!parent->part().isNull()) action->execute(parent); // It is important to test singleShot and not action->singleShot here - the // action could have been deleted already if not single shot and if the // JS code called by execute() calls clearTimeout(). if (singleShot) delete action; } else kdWarning(6070) << "WindowQObject::timerEvent this=" << this << " timer " << e->timerId() << " not found (" << scheduledActions.count() << " actions in map)" << endl;}void WindowQObject::timeoutClose(){ if (!parent->part().isNull()) { //kdDebug(6070) << "WindowQObject::timeoutClose -> closing window" << endl; delete parent->m_part; }}#if APPLE_CHANGESbool WindowQObject::hasTimeouts(){ return scheduledActions.count();}#endifValue FrameArray::get(ExecState *exec, const Identifier &p) const{#ifdef KJS_VERBOSE kdDebug(6070) << "FrameArray::get " << p.qstring() << " part=" << (void*)part << endl;#endif if (part.isNull()) return Undefined(); QPtrList<KParts::ReadOnlyPart> frames = part->frames(); unsigned int len = frames.count(); if (p == lengthPropertyName) return Number(len); else if (p== "location") // non-standard property, but works in NS and IE { Object obj = Object::dynamicCast( Window::retrieve( part ) ); if ( !obj.isNull() ) return obj.get( exec, "location" ); return Undefined(); } // check for the name or number KParts::ReadOnlyPart *frame = part->findFrame(p.qstring()); if (!frame) { bool ok; unsigned int i = p.toArrayIndex(&ok); if (ok && i < len) frame = frames.at(i); } // we are potentially fetching a reference to a another Window object here. // i.e. we may be accessing objects from another interpreter instance. // Therefore we have to be a bit careful with memory managment. if (frame && frame->inherits("KHTMLPart")) { KHTMLPart *khtml = static_cast<KHTMLPart*>(frame); return Window::retrieve(khtml); } return ObjectImp::get(exec, p);}UString FrameArray::toString(ExecState *) const{ return "[object FrameArray]";}////////////////////// Location Object ////////////////////////const ClassInfo Location::info = { "Location", 0, 0, 0 };/*@begin LocationTable 11 hash Location::Hash DontDelete host Location::Host DontDelete hostname Location::Hostname DontDelete href Location::Href DontDelete pathname Location::Pathname DontDelete port Location::Port DontDelete protocol Location::Protocol DontDelete search Location::Search DontDelete [[==]] Location::EqualEqual DontDelete|ReadOnly toString Location::ToString DontDelete|Function 0 replace Location::Replace DontDelete|Function 1 reload Location::Reload DontDelete|Function 0@end*/IMPLEMENT_PROTOFUNC(LocationFunc)Location::Location(KHTMLPart *p) : m_part(p){ //kdDebug(6070) << "Location::Location " << this << " m_part=" << (void*)m_part << endl;}Location::~Location(){ //kdDebug(6070) << "Location::~Location " << this << " m_part=" << (void*)m_part << endl;}Value Location::get(ExecState *exec, const Identifier &p) const{#ifdef KJS_VERBOSE kdDebug(6070) << "Location::get " << p.qstring() << " m_part=" << (void*)m_part << endl;#endif if (m_part.isNull()) return Undefined(); const Window* window = Window::retrieveWindow(m_part); if (!window || !window->isSafeScript(exec)) return Undefined(); KURL url = m_part->url(); const HashEntry *entry = Lookup::findEntry(&LocationTable, p); if (entry) switch (entry->value) { case Hash: return String( url.ref().isNull() ? QString("") : "#" + url.ref() ); case Host: { UString str = url.host(); if (url.port()) str += ":" + QString::number((int)url.port()); return String(str); // Note: this is the IE spec. The NS spec swaps the two, it s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -