1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2003 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <qstylesheet.h>
24 #include <qinputdialog.h>
25 #include <qpaintdevicemetrics.h>
26 #include <qapplication.h>
28 #include <kmessagebox.h>
30 #include <kparts/browserinterface.h>
32 #include <kwinmodule.h>
36 #include "rendering/render_canvas.h"
39 #include "KWQLogging.h"
40 #include "KWQKConfigBase.h"
42 #include <kjs/collector.h>
43 #include "kjs_proxy.h"
44 #include "kjs_window.h"
45 #include "kjs_navigator.h"
47 #include "kjs_range.h"
48 #include "kjs_traversal.h"
50 #include "kjs_events.h"
51 #include "xmlhttprequest.h"
52 #include "xmlserializer.h"
54 #include "khtmlview.h"
55 #include "khtml_part.h"
56 #include "dom/dom_string.h"
57 #include "dom/dom_node.h"
58 #include "editing/htmlediting.h"
59 #include "editing/selection.h"
60 #include "xml/dom2_eventsimpl.h"
61 #include "xml/dom_docimpl.h"
62 #include "xml/dom_position.h"
63 #include "html/html_documentimpl.h"
65 using DOM::DocumentImpl;
69 using khtml::TypingCommand;
75 ////////////////////// History Object ////////////////////////
77 class History : public ObjectImp {
78 friend class HistoryFunc;
80 History(ExecState *exec, KHTMLPart *p)
81 : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype()), part(p) { }
82 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
83 Value getValueProperty(ExecState *exec, int token) const;
84 virtual const ClassInfo* classInfo() const { return &info; }
85 static const ClassInfo info;
86 enum { Back, Forward, Go, Length };
87 virtual UString toString(ExecState *exec) const;
89 QGuardedPtr<KHTMLPart> part;
92 class FrameArray : public ObjectImp {
94 FrameArray(ExecState *exec, KHTMLPart *p)
95 : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype()), part(p) { }
96 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
97 virtual UString toString(ExecState *exec) const;
99 QGuardedPtr<KHTMLPart> part;
103 class KonquerorFunc : public DOMFunction {
105 KonquerorFunc(const Konqueror* k, const char* name)
106 : DOMFunction(), konqueror(k), m_name(name) { }
107 virtual Value tryCall(ExecState *exec, Object &thisObj, const List &args);
110 const Konqueror* konqueror;
116 #include "kjs_window.lut.h"
118 ////////////////////// Screen Object ////////////////////////
120 // table for screen object
123 height Screen::Height DontEnum|ReadOnly
124 width Screen::Width DontEnum|ReadOnly
125 colorDepth Screen::ColorDepth DontEnum|ReadOnly
126 pixelDepth Screen::PixelDepth DontEnum|ReadOnly
127 availLeft Screen::AvailLeft DontEnum|ReadOnly
128 availTop Screen::AvailTop DontEnum|ReadOnly
129 availHeight Screen::AvailHeight DontEnum|ReadOnly
130 availWidth Screen::AvailWidth DontEnum|ReadOnly
134 const ClassInfo Screen::info = { "Screen", 0, &ScreenTable, 0 };
136 // We set the object prototype so that toString is implemented
137 Screen::Screen(ExecState *exec)
138 : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype()) {}
140 Value Screen::get(ExecState *exec, const Identifier &p) const
143 kdDebug(6070) << "Screen::get " << p.qstring() << endl;
145 return lookupGetValue<Screen,ObjectImp>(exec,p,&ScreenTable,this);
148 Value Screen::getValueProperty(ExecState *exec, int token) const
151 QWidget *thisWidget = Window::retrieveActive(exec)->part()->view();
152 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(thisWidget));
156 return Number(sg.height());
158 return Number(sg.width());
161 QPaintDeviceMetrics m(QApplication::desktop());
162 return Number(m.depth());
165 QRect clipped = info.workArea().intersect(sg);
166 return Number(clipped.x()-sg.x());
169 QRect clipped = info.workArea().intersect(sg);
170 return Number(clipped.y()-sg.y());
173 QRect clipped = info.workArea().intersect(sg);
174 return Number(clipped.height());
177 QRect clipped = info.workArea().intersect(sg);
178 return Number(clipped.width());
181 kdWarning() << "Screen::getValueProperty unhandled token " << token << endl;
186 ////////////////////// Window Object ////////////////////////
188 const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
191 @begin WindowTable 91
192 closed Window::Closed DontDelete|ReadOnly
193 crypto Window::Crypto DontDelete|ReadOnly
194 defaultStatus Window::DefaultStatus DontDelete
195 defaultstatus Window::DefaultStatus DontDelete
196 status Window::Status DontDelete
197 document Window::Document DontDelete|ReadOnly
198 Node Window::Node DontDelete
199 Event Window::EventCtor DontDelete
200 Range Window::Range DontDelete
201 NodeFilter Window::NodeFilter DontDelete
202 DOMException Window::DOMException DontDelete
203 CSSRule Window::CSSRule DontDelete
204 frames Window::Frames DontDelete|ReadOnly
205 history Window::_History DontDelete|ReadOnly
206 event Window::Event DontDelete
207 innerHeight Window::InnerHeight DontDelete|ReadOnly
208 innerWidth Window::InnerWidth DontDelete|ReadOnly
209 length Window::Length DontDelete|ReadOnly
210 location Window::_Location DontDelete
211 locationbar Window::Locationbar DontDelete
212 name Window::Name DontDelete
213 navigator Window::_Navigator DontDelete|ReadOnly
214 clientInformation Window::ClientInformation DontDelete|ReadOnly
215 konqueror Window::_Konqueror DontDelete|ReadOnly
216 menubar Window::Menubar DontDelete|ReadOnly
217 offscreenBuffering Window::OffscreenBuffering DontDelete|ReadOnly
218 opener Window::Opener DontDelete|ReadOnly
219 outerHeight Window::OuterHeight DontDelete|ReadOnly
220 outerWidth Window::OuterWidth DontDelete|ReadOnly
221 pageXOffset Window::PageXOffset DontDelete|ReadOnly
222 pageYOffset Window::PageYOffset DontDelete|ReadOnly
223 parent Window::Parent DontDelete|ReadOnly
224 personalbar Window::Personalbar DontDelete|ReadOnly
225 screenX Window::ScreenX DontDelete|ReadOnly
226 screenY Window::ScreenY DontDelete|ReadOnly
227 screenLeft Window::ScreenLeft DontDelete|ReadOnly
228 screenTop Window::ScreenTop DontDelete|ReadOnly
229 scrollbars Window::Scrollbars DontDelete|ReadOnly
230 statusbar Window::Statusbar DontDelete|ReadOnly
231 toolbar Window::Toolbar DontDelete|ReadOnly
232 scroll Window::Scroll DontDelete|Function 2
233 scrollBy Window::ScrollBy DontDelete|Function 2
234 scrollTo Window::ScrollTo DontDelete|Function 2
235 scrollX Window::ScrollX DontDelete|ReadOnly
236 scrollY Window::ScrollY DontDelete|ReadOnly
237 moveBy Window::MoveBy DontDelete|Function 2
238 moveTo Window::MoveTo DontDelete|Function 2
239 resizeBy Window::ResizeBy DontDelete|Function 2
240 resizeTo Window::ResizeTo DontDelete|Function 2
241 self Window::Self DontDelete|ReadOnly
242 window Window::_Window DontDelete|ReadOnly
243 top Window::Top DontDelete|ReadOnly
244 screen Window::_Screen DontDelete|ReadOnly
245 Image Window::Image DontDelete|ReadOnly
246 Option Window::Option DontDelete|ReadOnly
247 XMLHttpRequest Window::XMLHttpRequest DontDelete|ReadOnly
248 XMLSerializer Window::XMLSerializer DontDelete|ReadOnly
249 alert Window::Alert DontDelete|Function 1
250 confirm Window::Confirm DontDelete|Function 1
251 prompt Window::Prompt DontDelete|Function 2
252 open Window::Open DontDelete|Function 3
253 print Window::Print DontDelete|Function 2
254 setTimeout Window::SetTimeout DontDelete|Function 2
255 clearTimeout Window::ClearTimeout DontDelete|Function 1
256 focus Window::Focus DontDelete|Function 0
257 getSelection Window::GetSelection DontDelete|Function 0
258 blur Window::Blur DontDelete|Function 0
259 close Window::Close DontDelete|Function 0
260 setInterval Window::SetInterval DontDelete|Function 2
261 clearInterval Window::ClearInterval DontDelete|Function 1
262 captureEvents Window::CaptureEvents DontDelete|Function 0
263 releaseEvents Window::ReleaseEvents DontDelete|Function 0
264 # Warning, when adding a function to this object you need to add a case in Window::get
265 addEventListener Window::AddEventListener DontDelete|Function 3
266 removeEventListener Window::RemoveEventListener DontDelete|Function 3
267 onabort Window::Onabort DontDelete
268 onblur Window::Onblur DontDelete
269 onchange Window::Onchange DontDelete
270 onclick Window::Onclick DontDelete
271 ondblclick Window::Ondblclick DontDelete
272 ondragdrop Window::Ondragdrop DontDelete
273 onerror Window::Onerror DontDelete
274 onfocus Window::Onfocus DontDelete
275 onkeydown Window::Onkeydown DontDelete
276 onkeypress Window::Onkeypress DontDelete
277 onkeyup Window::Onkeyup DontDelete
278 onload Window::Onload DontDelete
279 onmousedown Window::Onmousedown DontDelete
280 onmousemove Window::Onmousemove DontDelete
281 onmouseout Window::Onmouseout DontDelete
282 onmouseover Window::Onmouseover DontDelete
283 onmouseup Window::Onmouseup DontDelete
284 onmove Window::Onmove DontDelete
285 onreset Window::Onreset DontDelete
286 onresize Window::Onresize DontDelete
287 onscroll Window::Onscroll DontDelete
288 onsearch Window::Onsearch DontDelete
289 onselect Window::Onselect DontDelete
290 onsubmit Window::Onsubmit DontDelete
291 onunload Window::Onunload DontDelete
294 IMPLEMENT_PROTOFUNC(WindowFunc)
296 Window::Window(KHTMLPart *p)
297 : ObjectImp(/*no proto*/)
312 winq = new WindowQObject(this);
313 //kdDebug(6070) << "Window::Window this=" << this << " part=" << m_part << " " << m_part->name() << endl;
318 kdDebug(6070) << "Window::~Window this=" << this << " part=" << m_part << endl;
322 Window *Window::retrieveWindow(KHTMLPart *p)
324 Object obj = Object::dynamicCast( retrieve( p ) );
326 // obj should never be null, except when javascript has been disabled in that part.
327 if ( p && p->jScriptEnabled() )
329 assert( !obj.isNull() );
331 assert( dynamic_cast<KJS::Window*>(obj.imp()) ); // type checking
335 if ( obj.isNull() ) // JS disabled
337 return static_cast<KJS::Window*>(obj.imp());
340 Window *Window::retrieveActive(ExecState *exec)
342 ValueImp *imp = exec->dynamicInterpreter()->globalObject().imp();
345 assert( dynamic_cast<KJS::Window*>(imp) );
347 return static_cast<KJS::Window*>(imp);
350 Value Window::retrieve(KHTMLPart *p)
353 KJSProxy *proxy = KJSProxy::proxy( p );
356 kdDebug(6070) << "Window::retrieve part=" << p << " interpreter=" << proxy->interpreter() << " window=" << proxy->interpreter()->globalObject().imp() << endl;
358 return proxy->interpreter()->globalObject(); // the Global object is the "window"
360 return Undefined(); // This can happen with JS disabled on the domain of that window
363 Location *Window::location() const
366 const_cast<Window*>(this)->loc = new Location(m_part);
370 Selection *Window::selection() const
373 const_cast<Window*>(this)->m_selection = new Selection(m_part);
377 BarInfo *Window::locationbar(ExecState *exec) const
380 const_cast<Window*>(this)->m_locationbar = new BarInfo(exec, m_part, BarInfo::Locationbar);
381 return m_locationbar;
384 BarInfo *Window::menubar(ExecState *exec) const
387 const_cast<Window*>(this)->m_menubar = new BarInfo(exec, m_part, BarInfo::Menubar);
391 BarInfo *Window::personalbar(ExecState *exec) const
394 const_cast<Window*>(this)->m_personalbar = new BarInfo(exec, m_part, BarInfo::Personalbar);
395 return m_personalbar;
398 BarInfo *Window::statusbar(ExecState *exec) const
401 const_cast<Window*>(this)->m_statusbar = new BarInfo(exec, m_part, BarInfo::Statusbar);
405 BarInfo *Window::toolbar(ExecState *exec) const
408 const_cast<Window*>(this)->m_toolbar = new BarInfo(exec, m_part, BarInfo::Toolbar);
412 BarInfo *Window::scrollbars(ExecState *exec) const
415 const_cast<Window*>(this)->m_scrollbars = new BarInfo(exec, m_part, BarInfo::Scrollbars);
419 // reference our special objects during garbage collection
423 if (screen && !screen->marked())
425 if (history && !history->marked())
427 if (frames && !frames->marked())
429 //kdDebug(6070) << "Window::mark " << this << " marking loc=" << loc << endl;
430 if (loc && !loc->marked())
432 if (m_selection && !m_selection->marked())
434 if (m_locationbar && !m_locationbar->marked())
435 m_locationbar->mark();
436 if (m_menubar && !m_menubar->marked())
438 if (m_personalbar && !m_personalbar->marked())
439 m_personalbar->mark();
440 if (m_scrollbars && !m_scrollbars->marked())
441 m_scrollbars->mark();
442 if (m_statusbar && !m_statusbar->marked())
444 if (m_toolbar && !m_toolbar->marked())
448 UString Window::toString(ExecState *) const
450 return "[object Window]";
453 Value Window::get(ExecState *exec, const Identifier &p) const
456 kdDebug(6070) << "Window("<<this<<")::get " << p.qstring() << endl;
459 return Boolean(m_part.isNull());
461 // we don't want any properties other than "closed" on a closed window
465 // Look for overrides first
466 ValueImp * val = ObjectImp::getDirect(p);
468 //kdDebug(6070) << "Window::get found dynamic property '" << p.ascii() << "'" << endl;
469 if (isSafeScript(exec))
473 const HashEntry* entry = Lookup::findEntry(&WindowTable, p);
476 //kdDebug(6070) << "token: " << entry->value << endl;
477 switch( entry->value ) {
479 return Undefined(); // ###
481 return String(UString(m_part->jsDefaultStatusBarText()));
483 return String(UString(m_part->jsStatusBarText()));
485 if (isSafeScript(exec))
487 if (m_part->document().isNull()) {
489 KWQ(m_part)->createEmptyDocument();
491 kdDebug(6070) << "Document.write: adding <HTML><BODY> to create document" << endl;
493 m_part->write("<HTML><BODY>");
496 Value val = getDOMNode(exec,m_part->document());
502 return getNodeConstructor(exec);
504 return getRangeConstructor(exec);
506 return getNodeFilterConstructor(exec);
508 return getDOMExceptionConstructor(exec);
510 return getCSSRuleConstructor(exec);
512 return getEventConstructor(exec);
514 return Value(frames ? frames :
515 (const_cast<Window*>(this)->frames = new FrameArray(exec,m_part)));
517 return Value(history ? history :
518 (const_cast<Window*>(this)->history = new History(exec,m_part)));
522 return getDOMEvent(exec,*m_evt);
525 kdWarning(6070) << "window(" << this << "," << m_part->name() << ").event, no event!" << endl;
533 return Number(m_part->view()->visibleHeight());
538 return Number(m_part->view()->visibleWidth());
540 return Number(m_part->frames().count());
542 return Value(location());
544 return String(m_part->name());
546 case ClientInformation: {
547 // Store the navigator in the object so we get the same one each time.
548 Navigator *n = new Navigator(exec, m_part);
549 const_cast<Window *>(this)->putDirect("navigator", n, DontDelete|ReadOnly);
550 const_cast<Window *>(this)->putDirect("clientInformation", n, DontDelete|ReadOnly);
555 return Value(new Konqueror(m_part));
558 return Value(locationbar(exec));
560 return Value(menubar(exec));
561 case OffscreenBuffering:
562 return Boolean(true);
564 if (!m_part->opener())
565 return Null(); // ### a null Window might be better, but == null
566 else // doesn't work yet
567 return retrieve(m_part->opener());
573 KWin::Info inf = KWin::info(m_part->view()->topLevelWidget()->winId());
574 return Number(entry->value == OuterHeight ?
575 inf.geometry.height() : inf.geometry.width());
581 return Number(m_part->view()->contentsX());
586 return Number(m_part->view()->contentsY());
588 return Value(retrieve(m_part->parentPart() ? m_part->parentPart() : (KHTMLPart*)m_part));
590 return Value(personalbar(exec));
595 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(m_part->view()));
596 return Number(m_part->view()->mapToGlobal(QPoint(0,0)).x() + sg.x());
602 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(m_part->view()));
603 return Number(m_part->view()->mapToGlobal(QPoint(0,0)).y() + sg.y());
609 return Number(m_part->view()->contentsX());
615 return Number(m_part->view()->contentsY());
618 return Value(scrollbars(exec));
620 return Value(statusbar(exec));
622 return Value(toolbar(exec));
625 return Value(retrieve(m_part));
627 KHTMLPart *p = m_part;
628 while (p->parentPart())
630 return Value(retrieve(p));
633 return Value(screen ? screen :
634 (const_cast<Window*>(this)->screen = new Screen(exec)));
636 return Value(new ImageConstructorImp(exec, m_part->document()));
638 return Value(new OptionConstructorImp(exec, m_part->document()));
640 return Value(new XMLHttpRequestConstructorImp(exec, m_part->document()));
642 return Value(new XMLSerializerConstructorImp(exec));
653 case Scroll: // compatibility
660 return lookupOrCreateFunction<WindowFunc>(exec,p,this,entry->value,entry->params,entry->attr);
663 case AddEventListener:
664 case RemoveEventListener:
670 if (isSafeScript(exec))
671 return lookupOrCreateFunction<WindowFunc>(exec,p,this,entry->value,entry->params,entry->attr);
675 if (isSafeScript(exec))
676 return getListener(exec,DOM::EventImpl::ABORT_EVENT);
680 if (isSafeScript(exec))
681 return getListener(exec,DOM::EventImpl::BLUR_EVENT);
685 if (isSafeScript(exec))
686 return getListener(exec,DOM::EventImpl::CHANGE_EVENT);
690 if (isSafeScript(exec))
691 return getListener(exec,DOM::EventImpl::KHTML_CLICK_EVENT);
695 if (isSafeScript(exec))
696 return getListener(exec,DOM::EventImpl::KHTML_DBLCLICK_EVENT);
700 if (isSafeScript(exec))
701 return getListener(exec,DOM::EventImpl::KHTML_DRAGDROP_EVENT);
705 if (isSafeScript(exec))
706 return getListener(exec,DOM::EventImpl::KHTML_ERROR_EVENT);
710 if (isSafeScript(exec))
711 return getListener(exec,DOM::EventImpl::FOCUS_EVENT);
715 if (isSafeScript(exec))
716 return getListener(exec,DOM::EventImpl::KEYDOWN_EVENT);
720 if (isSafeScript(exec))
721 return getListener(exec,DOM::EventImpl::KEYPRESS_EVENT);
725 if (isSafeScript(exec))
726 return getListener(exec,DOM::EventImpl::KEYUP_EVENT);
730 if (isSafeScript(exec))
731 return getListener(exec,DOM::EventImpl::LOAD_EVENT);
735 if (isSafeScript(exec))
736 return getListener(exec,DOM::EventImpl::MOUSEDOWN_EVENT);
740 if (isSafeScript(exec))
741 return getListener(exec,DOM::EventImpl::MOUSEMOVE_EVENT);
745 if (isSafeScript(exec))
746 return getListener(exec,DOM::EventImpl::MOUSEOUT_EVENT);
750 if (isSafeScript(exec))
751 return getListener(exec,DOM::EventImpl::MOUSEOVER_EVENT);
755 if (isSafeScript(exec))
756 return getListener(exec,DOM::EventImpl::MOUSEUP_EVENT);
760 if (isSafeScript(exec))
761 return getListener(exec,DOM::EventImpl::KHTML_MOVE_EVENT);
765 if (isSafeScript(exec))
766 return getListener(exec,DOM::EventImpl::RESET_EVENT);
770 if (isSafeScript(exec))
771 return getListener(exec,DOM::EventImpl::RESIZE_EVENT);
775 if (isSafeScript(exec))
776 return getListener(exec,DOM::EventImpl::SCROLL_EVENT);
781 if (isSafeScript(exec))
782 return getListener(exec,DOM::EventImpl::SEARCH_EVENT);
787 if (isSafeScript(exec))
788 return getListener(exec,DOM::EventImpl::SELECT_EVENT);
792 if (isSafeScript(exec))
793 return getListener(exec,DOM::EventImpl::SUBMIT_EVENT);
797 if (isSafeScript(exec))
798 return getListener(exec,DOM::EventImpl::UNLOAD_EVENT);
804 KHTMLPart *kp = m_part->findFrame( p.qstring() );
806 return Value(retrieve(kp));
808 // allow window[1] or parent[1] etc. (#56983)
810 unsigned int i = p.toArrayIndex(&ok);
812 QPtrList<KParts::ReadOnlyPart> frames = m_part->frames();
813 unsigned int len = frames.count();
815 KParts::ReadOnlyPart* frame = frames.at(i);
816 if (frame && frame->inherits("KHTMLPart")) {
817 KHTMLPart *khtml = static_cast<KHTMLPart*>(frame);
818 return Window::retrieve(khtml);
823 // allow shortcuts like 'Image1' instead of document.images.Image1
824 if (isSafeScript(exec) &&
825 m_part->document().isHTMLDocument()) { // might be XML
826 DOM::HTMLCollection coll = m_part->htmlDocument().all();
827 DOM::HTMLElement element = coll.namedItem(p.string());
828 if (!element.isNull()) {
829 return getDOMNode(exec,element);
833 // This isn't necessarily a bug. Some code uses if(!window.blah) window.blah=1
834 // But it can also mean something isn't loaded or implemented, hence the WARNING to help grepping.
836 kdDebug(6070) << "WARNING: Window::get property not found: " << p.qstring() << endl;
841 bool Window::hasProperty(ExecState *exec, const Identifier &p) const
843 // matches logic in get function above, but no need to handle numeric values (frame indices)
846 return p == "closed";
851 if (Lookup::findEntry(&WindowTable, p))
854 if (m_part->findFrame(p.qstring()))
857 if (!m_part->htmlDocument().all().namedItem(p.string()).isNull())
863 void Window::put(ExecState* exec, const Identifier &propertyName, const Value &value, int attr)
865 // Called by an internal KJS call (e.g. InterpreterImp's constructor) ?
866 // If yes, save time and jump directly to ObjectImp.
867 if ( (attr != None && attr != DontDelete)
868 // Same thing if we have a local override (e.g. "var location")
869 || ( ObjectImp::getDirect(propertyName) && isSafeScript(exec)) )
871 ObjectImp::put( exec, propertyName, value, attr );
875 const HashEntry* entry = Lookup::findEntry(&WindowTable, propertyName);
879 kdDebug(6070) << "Window("<<this<<")::put " << propertyName.qstring() << endl;
881 switch( entry->value ) {
883 String s = value.toString(exec);
884 m_part->setJSStatusBarText(s.value().qstring());
887 case DefaultStatus: {
888 String s = value.toString(exec);
889 m_part->setJSDefaultStatusBarText(s.value().qstring());
893 KHTMLPart* p = Window::retrieveActive(exec)->m_part;
895 QString dstUrl = p->htmlDocument().completeURL(value.toString(exec).string()).string();
896 if (dstUrl.find("javascript:", 0, false) || isSafeScript(exec))
898 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
900 // We want a new history item if this JS was called via a user gesture
901 m_part->scheduleLocationChange(dstUrl, !userGesture, userGesture);
903 m_part->scheduleLocationChange(dstUrl, false /*don't lock history*/, userGesture);
910 if (isSafeScript(exec))
911 setListener(exec, DOM::EventImpl::ABORT_EVENT,value);
914 if (isSafeScript(exec))
915 setListener(exec, DOM::EventImpl::BLUR_EVENT,value);
918 if (isSafeScript(exec))
919 setListener(exec, DOM::EventImpl::CHANGE_EVENT,value);
922 if (isSafeScript(exec))
923 setListener(exec,DOM::EventImpl::KHTML_CLICK_EVENT,value);
926 if (isSafeScript(exec))
927 setListener(exec,DOM::EventImpl::KHTML_DBLCLICK_EVENT,value);
930 if (isSafeScript(exec))
931 setListener(exec,DOM::EventImpl::KHTML_DRAGDROP_EVENT,value);
934 if (isSafeScript(exec))
935 setListener(exec,DOM::EventImpl::KHTML_ERROR_EVENT,value);
938 if (isSafeScript(exec))
939 setListener(exec,DOM::EventImpl::FOCUS_EVENT,value);
942 if (isSafeScript(exec))
943 setListener(exec,DOM::EventImpl::KEYDOWN_EVENT,value);
946 if (isSafeScript(exec))
947 setListener(exec,DOM::EventImpl::KEYPRESS_EVENT,value);
950 if (isSafeScript(exec))
951 setListener(exec,DOM::EventImpl::KEYUP_EVENT,value);
954 if (isSafeScript(exec))
955 setListener(exec,DOM::EventImpl::LOAD_EVENT,value);
958 if (isSafeScript(exec))
959 setListener(exec,DOM::EventImpl::MOUSEDOWN_EVENT,value);
962 if (isSafeScript(exec))
963 setListener(exec,DOM::EventImpl::MOUSEMOVE_EVENT,value);
966 if (isSafeScript(exec))
967 setListener(exec,DOM::EventImpl::MOUSEOUT_EVENT,value);
970 if (isSafeScript(exec))
971 setListener(exec,DOM::EventImpl::MOUSEOVER_EVENT,value);
974 if (isSafeScript(exec))
975 setListener(exec,DOM::EventImpl::MOUSEUP_EVENT,value);
978 if (isSafeScript(exec))
979 setListener(exec,DOM::EventImpl::KHTML_MOVE_EVENT,value);
982 if (isSafeScript(exec))
983 setListener(exec,DOM::EventImpl::RESET_EVENT,value);
986 if (isSafeScript(exec))
987 setListener(exec,DOM::EventImpl::RESIZE_EVENT,value);
990 if (isSafeScript(exec))
991 setListener(exec,DOM::EventImpl::SCROLL_EVENT,value);
995 if (isSafeScript(exec))
996 setListener(exec,DOM::EventImpl::SEARCH_EVENT,value);
1000 if (isSafeScript(exec))
1001 setListener(exec,DOM::EventImpl::SELECT_EVENT,value);
1004 if (isSafeScript(exec))
1005 setListener(exec,DOM::EventImpl::SUBMIT_EVENT,value);
1008 if (isSafeScript(exec))
1009 setListener(exec,DOM::EventImpl::UNLOAD_EVENT,value);
1012 if (isSafeScript(exec))
1014 m_part->setName( value.toString(exec).qstring() );
1016 m_part->setName( value.toString(exec).qstring().local8Bit().data() );
1023 if (isSafeScript(exec)) {
1024 //kdDebug(6070) << "Window("<<this<<")::put storing " << propertyName.qstring() << endl;
1025 ObjectImp::put(exec, propertyName, value, attr);
1029 bool Window::toBoolean(ExecState *) const
1031 return !m_part.isNull();
1034 int Window::installTimeout(const UString &handler, int t, bool singleShot)
1036 return winq->installTimeout(handler, t, singleShot);
1039 int Window::installTimeout(const Value &function, List &args, int t, bool singleShot)
1041 return winq->installTimeout(function, args, t, singleShot);
1044 void Window::clearTimeout(int timerId)
1046 winq->clearTimeout(timerId);
1050 bool Window::hasTimeouts()
1052 return winq->hasTimeouts();
1055 QMap<int, ScheduledAction*> *Window::pauseTimeouts(const void *key)
1057 return winq->pauseTimeouts(key);
1060 void Window::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key)
1062 return winq->resumeTimeouts(sa, key);
1066 void Window::scheduleClose()
1068 kdDebug(6070) << "Window::scheduleClose window.close() " << m_part << endl;
1071 KWQ(m_part)->scheduleClose();
1073 QTimer::singleShot( 0, winq, SLOT( timeoutClose() ) );
1077 static bool shouldLoadAsEmptyDocument(const KURL &url)
1079 return url.protocol().lower() == "about" || url.isEmpty();
1082 bool Window::isSafeScript(ExecState *exec) const
1084 if (m_part.isNull()) { // part deleted ? can't grant access
1085 kdDebug(6070) << "Window::isSafeScript: accessing deleted part !" << endl;
1088 KHTMLPart *activePart = static_cast<KJS::ScriptInterpreter *>( exec->dynamicInterpreter() )->part();
1090 kdDebug(6070) << "Window::isSafeScript: current interpreter's part is 0L!" << endl;
1093 if ( activePart == m_part ) // Not calling from another frame, no problem.
1096 // JS may be attempting to access the "window" object, which should be valid,
1097 // even if the document hasn't been constructed yet. If the document doesn't
1098 // exist yet allow JS to access the window object.
1099 if (!m_part->xmlDocImpl())
1102 DOM::DocumentImpl* thisDocument = m_part->xmlDocImpl();
1103 DOM::DocumentImpl* actDocument = activePart->xmlDocImpl();
1106 kdDebug(6070) << "Window::isSafeScript: active part has no document!" << endl;
1110 DOM::DOMString actDomain = actDocument->domain();
1112 // Always allow local pages to execute any JS.
1113 if (actDomain.isNull())
1116 DOM::DOMString thisDomain = thisDocument->domain();
1118 // if this document is being initially loaded as empty by its parent
1119 // or opener, allow access from any document in the same domain as
1120 // the parent or opener.
1121 if (shouldLoadAsEmptyDocument(m_part->url())) {
1122 KHTMLPart *ancestorPart = m_part->opener() ? m_part->opener() : m_part->parentPart();
1123 while (ancestorPart && shouldLoadAsEmptyDocument(ancestorPart->url())) {
1124 ancestorPart = ancestorPart->parentPart();
1128 thisDomain = ancestorPart->xmlDocImpl()->domain();
1131 //kdDebug(6070) << "current domain:" << actDomain.string() << ", frame domain:" << thisDomain.string() << endl;
1132 if ( actDomain == thisDomain )
1136 if (Interpreter::shouldPrintExceptions()) {
1137 printf("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
1138 thisDocument->URL().latin1(), actDocument->URL().latin1());
1140 message.sprintf("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
1141 thisDocument->URL().latin1(), actDocument->URL().latin1());
1142 KWQ(m_part)->addMessageToConsole(message, 1, QString()); //fixme: provide a real line number and sourceurl
1146 kdWarning(6070) << "Javascript: access denied for current frame '" << actDomain.string() << "' to frame '" << thisDomain.string() << "'" << endl;
1150 void Window::setListener(ExecState *exec, int eventId, Value func)
1152 if (!isSafeScript(exec))
1154 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(m_part->htmlDocument().handle());
1158 doc->setHTMLWindowEventListener(eventId,getJSEventListener(func,true));
1161 Value Window::getListener(ExecState *exec, int eventId) const
1163 if (!isSafeScript(exec))
1165 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(m_part->htmlDocument().handle());
1169 DOM::EventListener *listener = doc->getHTMLWindowEventListener(eventId);
1170 if (listener && static_cast<JSEventListener*>(listener)->listenerObjImp())
1171 return static_cast<JSEventListener*>(listener)->listenerObj();
1177 JSEventListener *Window::getJSEventListener(const Value& val, bool html)
1179 // This function is so hot that it's worth coding it directly with imps.
1180 if (val.type() != ObjectType)
1182 ObjectImp *listenerObject = static_cast<ObjectImp *>(val.imp());
1184 JSEventListener *existingListener = jsEventListeners[listenerObject];
1185 if (existingListener)
1186 return existingListener;
1188 // Note that the JSEventListener constructor adds it to our jsEventListeners list
1189 return new JSEventListener(Object(listenerObject), Object(this), html);
1192 JSLazyEventListener *Window::getJSLazyEventListener(const QString& code, bool html, int lineNumber)
1194 return new JSLazyEventListener(code, Object(this), html, lineNumber);
1197 void Window::clear( ExecState *exec )
1199 KJS::Interpreter::lock();
1200 kdDebug(6070) << "Window::clear " << this << endl;
1202 winq = new WindowQObject(this);;
1203 // Get rid of everything, those user vars could hold references to DOM nodes
1204 deleteAllProperties( exec );
1205 // Really delete those properties, so that the DOM nodes get deref'ed
1206 KJS::Collector::collect();
1207 // Now recreate a working global object for the next URL that will use us
1208 KJS::Interpreter *interpreter = KJSProxy::proxy( m_part )->interpreter();
1209 interpreter->initGlobalObject();
1210 KJS::Interpreter::unlock();
1213 void Window::setCurrentEvent( DOM::Event *evt )
1216 //kdDebug(6070) << "Window " << this << " (part=" << m_part << ")::setCurrentEvent m_evt=" << evt << endl;
1219 Value WindowFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
1221 if (!thisObj.inherits(&Window::info)) {
1222 Object err = Error::create(exec,TypeError);
1223 exec->setException(err);
1226 Window *window = static_cast<Window *>(thisObj.imp());
1229 KHTMLPart *part = window->m_part;
1233 KHTMLView *widget = part->view();
1235 UString s = v.toString(exec);
1240 if (part && part->xmlDocImpl())
1241 part->xmlDocImpl()->updateRendering();
1243 KWQ(part)->runJavaScriptAlert(str);
1245 KMessageBox::error(widget, QStyleSheet::convertFromPlainText(str), "JavaScript");
1248 case Window::Confirm:
1249 if (part && part->xmlDocImpl())
1250 part->xmlDocImpl()->updateRendering();
1252 return Boolean(KWQ(part)->runJavaScriptConfirm(str));
1254 return Boolean((KMessageBox::warningYesNo(widget, QStyleSheet::convertFromPlainText(str), "JavaScript",
1255 i18n("OK"), i18n("Cancel")) == KMessageBox::Yes));
1257 case Window::Prompt:
1258 if (part && part->xmlDocImpl())
1259 part->xmlDocImpl()->updateRendering();
1262 ok = KWQ(part)->runJavaScriptPrompt(str, args.size() >= 2 ? args[1].toString(exec).qstring() : QString::null, str2);
1264 if (args.size() >= 2)
1265 str2 = QInputDialog::getText(i18n("Konqueror: Prompt"),
1266 QStyleSheet::convertFromPlainText(str),
1268 args[1].toString(exec).qstring(), &ok);
1270 str2 = QInputDialog::getText(i18n("Konqueror: Prompt"),
1271 QStyleSheet::convertFromPlainText(str),
1273 QString::null, &ok);
1276 return String(str2);
1281 KConfig *config = new KConfig("konquerorrc");
1282 config->setGroup("Java/JavaScript Settings");
1284 int policy = config->readUnsignedNumEntry( "WindowOpenPolicy", 0 ); // 0=allow, 1=ask, 2=deny, 3=smart
1286 int policy = config->readUnsignedNumEntry( part->settings(), "WindowOpenPolicy", 0 ); // 0=allow, 1=ask, 2=deny, 3=smart
1289 if ( policy == 1 ) {
1291 if ( KMessageBox::questionYesNo(widget,
1292 i18n( "This site is trying to open up a new browser "
1293 "window using Javascript.\n"
1294 "Do you want to allow this?" ),
1295 i18n( "Confirmation: Javascript Popup" ) ) == KMessageBox::Yes )
1298 } else if ( policy == 3 ) // smart
1300 // window.open disabled unless from a key/mouse event
1301 if (static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture())
1307 LOG(PopupBlocking, "Allowed JavaScript window open of %s", args[0].toString(exec).qstring().ascii());
1309 LOG(PopupBlocking, "Blocked JavaScript window open of %s", args[0].toString(exec).qstring().ascii());
1314 QString frameName = !args[1].isNull() && args[1].type() != UndefinedType ?
1315 args[1].toString(exec).qstring()
1316 : QString("_blank");
1318 if ( policy != 0 && !(part->findFrame(frameName) || frameName == "_top" || frameName == "_parent" || frameName == "_self")) {
1321 if (v.type() == UndefinedType)
1324 KParts::WindowArgs winargs;
1326 // scan feature argument
1329 if (!v.isNull() && v.type() != UndefinedType && v.toString(exec).size() > 0) {
1330 features = v.toString(exec).qstring();
1331 // specifying window params means false defaults
1332 winargs.menuBarVisible = false;
1333 winargs.toolBarsVisible = false;
1334 winargs.statusBarVisible = false;
1336 winargs.scrollbarsVisible = true;
1338 QStringList flist = QStringList::split(',', features);
1339 QStringList::ConstIterator it = flist.begin();
1340 while (it != flist.end()) {
1343 int pos = s.find('=');
1345 key = s.left(pos).stripWhiteSpace().lower();
1346 val = s.mid(pos + 1).stripWhiteSpace().lower();
1347 int spacePos = val.find(' ');
1348 if (spacePos != -1) {
1349 val = val.left(spacePos);
1352 int scnum = QApplication::desktop()->screenNumber(widget->topLevelWidget());
1354 QRect screen = QApplication::desktop()->screenGeometry(scnum);
1355 if (key == "left" || key == "screenx") {
1357 double d = val.toDouble(&ok);
1360 if (d < screen.x() || d > screen.right())
1361 d = screen.x(); // only safe choice until size is determined
1364 winargs.xSet = true;
1367 } else if (key == "top" || key == "screeny") {
1369 double d = val.toDouble(&ok);
1372 if (d < screen.y() || d > screen.bottom())
1373 d = screen.y(); // only safe choice until size is determined
1376 winargs.ySet = true;
1379 } else if (key == "height") {
1381 double d = val.toDouble(&ok);
1384 d += 2*qApp->style().pixelMetric( QStyle::PM_DefaultFrameWidth ) + 2;
1386 if (d > screen.height()) // should actually check workspace
1387 d = screen.height();
1390 winargs.height = (int)d;
1392 winargs.heightSet = true;
1395 } else if (key == "width") {
1397 double d = val.toDouble(&ok);
1400 d += 2*qApp->style().pixelMetric( QStyle::PM_DefaultFrameWidth ) + 2;
1402 if (d > screen.width()) // should actually check workspace
1406 winargs.width = (int)d;
1408 winargs.widthSet = true;
1416 // leaving away the value gives true
1417 key = s.stripWhiteSpace().lower();
1421 if (key == "menubar")
1422 winargs.menuBarVisible = (val == "1" || val == "yes");
1423 else if (key == "toolbar")
1424 winargs.toolBarsVisible = (val == "1" || val == "yes");
1425 else if (key == "location") // ### missing in WindowArgs
1426 winargs.toolBarsVisible = (val == "1" || val == "yes");
1427 else if (key == "status" || key == "statusbar")
1428 winargs.statusBarVisible = (val == "1" || val == "yes");
1429 else if (key == "resizable")
1430 winargs.resizable = (val == "1" || val == "yes");
1431 else if (key == "fullscreen")
1432 winargs.fullscreen = (val == "1" || val == "yes");
1434 else if (key == "scrollbars")
1435 winargs.scrollbarsVisible = !(val == "0" || val == "no");
1440 // prepare arguments
1444 KHTMLPart* p = Window::retrieveActive(exec)->m_part;
1446 url = p->htmlDocument().completeURL(str).string();
1449 KParts::URLArgs uargs;
1450 uargs.frameName = frameName;
1451 if ( uargs.frameName == "_top" )
1454 while ( part->parentPart() )
1455 part = part->parentPart();
1456 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1457 part->scheduleLocationChange(url.url(), false/*don't lock history*/, userGesture);
1458 return Window::retrieve(part);
1460 if ( uargs.frameName == "_parent" )
1463 if ( part->parentPart() )
1464 part = part->parentPart();
1465 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1466 part->scheduleLocationChange(url.url(), false/*don't lock history*/, userGesture);
1467 return Window::retrieve(part);
1469 uargs.serviceType = "text/html";
1471 // request window (new or existing if framename is set)
1472 KParts::ReadOnlyPart *newPart = 0L;
1473 emit part->browserExtension()->createNewWindow("", uargs,winargs,newPart);
1474 if (newPart && newPart->inherits("KHTMLPart")) {
1475 KHTMLPart *khtmlpart = static_cast<KHTMLPart*>(newPart);
1476 //qDebug("opener set to %p (this Window's part) in new Window %p (this Window=%p)",part,win,window);
1477 khtmlpart->setOpener(part);
1478 khtmlpart->setOpenedByJS(true);
1480 if (khtmlpart->document().isNull()) {
1481 DocumentImpl *oldDoc = part->xmlDocImpl();
1482 if (oldDoc && oldDoc->baseURL() != 0)
1483 khtmlpart->begin(oldDoc->baseURL());
1487 khtmlpart->write("<HTML><BODY>");
1491 kdDebug(6070) << "Setting domain to " << oldDoc->domain().string() << endl;
1492 khtmlpart->xmlDocImpl()->setDomain( oldDoc->domain(), true );
1493 khtmlpart->xmlDocImpl()->setBaseURL( oldDoc->baseURL() );
1497 if (!url.isEmpty()) {
1498 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1499 // FIXME: Need to pass referrer here.
1500 khtmlpart->scheduleLocationChange(url.url(), false, userGesture);
1503 uargs.serviceType = QString::null;
1504 if (uargs.frameName == "_blank")
1505 uargs.frameName = QString::null;
1507 // FIXME: need to pass referrer here
1508 emit khtmlpart->browserExtension()->openURLRequest(url,uargs);
1510 return Window::retrieve(khtmlpart); // global object
1520 case Window::ScrollBy:
1521 window->updateLayout();
1522 if(args.size() >= 2 && widget)
1523 widget->scrollBy(args[0].toInt32(exec), args[1].toInt32(exec));
1525 case Window::Scroll:
1526 case Window::ScrollTo:
1527 window->updateLayout();
1528 if(args.size() >= 2 && widget)
1529 widget->setContentsPos(args[0].toInt32(exec), args[1].toInt32(exec));
1531 case Window::MoveBy:
1532 if(args.size() >= 2 && widget)
1534 QWidget * tl = widget->topLevelWidget();
1535 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1536 QPoint dest = tl->pos() + QPoint( args[0].toInt32(exec), args[1].toInt32(exec) );
1537 // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1538 if ( dest.x() >= sg.x() && dest.y() >= sg.x() &&
1539 dest.x()+tl->width() <= sg.width()+sg.x() &&
1540 dest.y()+tl->height() <= sg.height()+sg.y() )
1544 case Window::MoveTo:
1545 if(args.size() >= 2 && widget)
1547 QWidget * tl = widget->topLevelWidget();
1548 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1549 QPoint dest( args[0].toInt32(exec)+sg.x(), args[1].toInt32(exec)+sg.y() );
1550 // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1551 if ( dest.x() >= sg.x() && dest.y() >= sg.y() &&
1552 dest.x()+tl->width() <= sg.width()+sg.x() &&
1553 dest.y()+tl->height() <= sg.height()+sg.y() )
1557 case Window::ResizeBy:
1558 if(args.size() >= 2 && widget)
1560 QWidget * tl = widget->topLevelWidget();
1561 QSize dest = tl->size() + QSize( args[0].toInt32(exec), args[1].toInt32(exec) );
1562 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1563 // Security check: within desktop limits and bigger than 100x100 (per spec)
1564 if ( tl->x()+dest.width() <= sg.x()+sg.width() &&
1565 tl->y()+dest.height() <= sg.y()+sg.height() &&
1566 dest.width() >= 100 && dest.height() >= 100 )
1568 // Take into account the window frame
1569 int deltaWidth = tl->frameGeometry().width() - tl->width();
1570 int deltaHeight = tl->frameGeometry().height() - tl->height();
1571 tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );
1575 case Window::ResizeTo:
1576 if(args.size() >= 2 && widget)
1578 QWidget * tl = widget->topLevelWidget();
1579 QSize dest = QSize( args[0].toInt32(exec), args[1].toInt32(exec) );
1580 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1581 // Security check: within desktop limits and bigger than 100x100 (per spec)
1582 if ( tl->x()+dest.width() <= sg.x()+sg.width() &&
1583 tl->y()+dest.height() <= sg.y()+sg.height() &&
1584 dest.width() >= 100 && dest.height() >= 100 )
1586 // Take into account the window frame
1587 int deltaWidth = tl->frameGeometry().width() - tl->width();
1588 int deltaHeight = tl->frameGeometry().height() - tl->height();
1589 tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );
1593 case Window::SetTimeout:
1594 if (!window->isSafeScript(exec))
1596 if (args.size() >= 2 && v.isA(StringType)) {
1597 int i = args[1].toInt32(exec);
1598 int r = (const_cast<Window*>(window))->installTimeout(s, i, true /*single shot*/);
1601 else if (args.size() >= 2 && v.isA(ObjectType) && Object::dynamicCast(v).implementsCall()) {
1602 Value func = args[0];
1603 int i = args[1].toInt32(exec);
1605 // All arguments after the second should go to the function
1606 // FIXME: could be more efficient
1607 List funcArgs = args.copyTail().copyTail();
1609 int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, true /*single shot*/);
1614 case Window::SetInterval:
1615 if (!window->isSafeScript(exec))
1617 if (args.size() >= 2 && v.isA(StringType)) {
1618 int i = args[1].toInt32(exec);
1619 int r = (const_cast<Window*>(window))->installTimeout(s, i, false);
1622 else if (args.size() >= 2 && !Object::dynamicCast(v).isNull() &&
1623 Object::dynamicCast(v).implementsCall()) {
1624 Value func = args[0];
1625 int i = args[1].toInt32(exec);
1627 // All arguments after the second should go to the function
1628 // FIXME: could be more efficient
1629 List funcArgs = args.copyTail().copyTail();
1631 int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, false);
1636 case Window::ClearTimeout:
1637 case Window::ClearInterval:
1638 if (!window->isSafeScript(exec))
1640 (const_cast<Window*>(window))->clearTimeout(v.toInt32(exec));
1644 widget->setActiveWindow();
1646 case Window::GetSelection:
1647 if (!window->isSafeScript(exec))
1649 return Value(window->selection());
1652 KWQ(part)->unfocusWindow();
1658 /* From http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm :
1659 The close method closes only windows opened by JavaScript using the open method.
1660 If you attempt to close any other window, a confirm is generated, which
1661 lets the user choose whether the window closes.
1662 This is a security feature to prevent "mail bombs" containing self.close().
1663 However, if the window has only one document (the current one) in its
1664 session history, the close is allowed without any confirm. This is a
1665 special case for one-off windows that need to open other windows and
1666 then dispose of themselves.
1668 if (!part->openedByJS())
1670 // To conform to the SPEC, we only ask if the window
1671 // has more than one entry in the history (NS does that too).
1672 History history(exec,part);
1673 if ( history.get( exec, lengthPropertyName ).toInt32(exec) <= 1
1675 // FIXME: How are we going to handle this?
1677 || KMessageBox::questionYesNo( window->part()->view(), i18n("Close window?"), i18n("Confirmation Required") ) == KMessageBox::Yes
1680 (const_cast<Window*>(window))->scheduleClose();
1684 (const_cast<Window*>(window))->scheduleClose();
1687 case Window::CaptureEvents:
1688 case Window::ReleaseEvents:
1689 // If anyone implements these, they need the safescript security check.
1690 if (!window->isSafeScript(exec))
1693 // Do nothing for now. These are NS-specific legacy calls.
1695 case Window::AddEventListener: {
1696 if (!window->isSafeScript(exec))
1698 JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
1700 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
1702 docimpl->addWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
1706 case Window::RemoveEventListener: {
1707 if (!window->isSafeScript(exec))
1709 JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
1711 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
1713 docimpl->removeWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
1722 void Window::updateLayout() const
1724 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(m_part->document().handle());
1726 docimpl->updateLayoutIgnorePendingStylesheets();
1731 ////////////////////// ScheduledAction ////////////////////////
1733 ScheduledAction::ScheduledAction(Object _func, List _args, bool _singleShot)
1735 //kdDebug(6070) << "ScheduledAction::ScheduledAction(isFunction) " << this << endl;
1739 singleShot = _singleShot;
1742 ScheduledAction::ScheduledAction(const QString &_code, bool _singleShot)
1744 //kdDebug(6070) << "ScheduledAction::ScheduledAction(!isFunction) " << this << endl;
1749 singleShot = _singleShot;
1752 void ScheduledAction::execute(Window *window)
1754 ScriptInterpreter *interpreter = static_cast<ScriptInterpreter *>(KJSProxy::proxy(window->m_part)->interpreter());
1756 interpreter->setProcessingTimerCallback(true);
1758 //kdDebug(6070) << "ScheduledAction::execute " << this << endl;
1760 if (func.implementsCall()) {
1762 Q_ASSERT( window->m_part );
1763 if ( window->m_part )
1765 KJS::Interpreter *interpreter = KJSProxy::proxy( window->m_part )->interpreter();
1766 ExecState *exec = interpreter->globalExec();
1767 Q_ASSERT( window == interpreter->globalObject().imp() );
1768 Object obj( window );
1769 Interpreter::lock();
1770 func.call(exec,obj,args); // note that call() creates its own execution state for the func call
1771 Interpreter::unlock();
1772 if ( exec->hadException() ) {
1774 Interpreter::lock();
1775 char *message = exec->exception().toObject(exec).get(exec, messagePropertyName).toString(exec).ascii();
1776 int lineNumber = exec->exception().toObject(exec).get(exec, "line").toInt32(exec);
1777 Interpreter::unlock();
1778 if (Interpreter::shouldPrintExceptions()) {
1779 printf("(timer):%s\n", message);
1781 KWQ(window->m_part)->addMessageToConsole(message, lineNumber, QString());
1783 exec->clearException();
1789 window->m_part->executeScript(code);
1792 // Update our document's rendering following the execution of the timeout callback.
1793 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(window->m_part->document().handle());
1794 doc->updateRendering();
1796 interpreter->setProcessingTimerCallback(false);
1799 ScheduledAction::~ScheduledAction()
1801 //kdDebug(6070) << "ScheduledAction::~ScheduledAction " << this << endl;
1804 ////////////////////// WindowQObject ////////////////////////
1806 WindowQObject::WindowQObject(Window *w)
1809 //kdDebug(6070) << "WindowQObject::WindowQObject " << this << endl;
1810 part = parent->m_part;
1811 connect( parent->m_part, SIGNAL( destroyed() ),
1812 this, SLOT( parentDestroyed() ) );
1815 WindowQObject::~WindowQObject()
1817 //kdDebug(6070) << "WindowQObject::~WindowQObject " << this << endl;
1818 parentDestroyed(); // reuse same code
1821 void WindowQObject::parentDestroyed()
1823 //kdDebug(6070) << "WindowQObject::parentDestroyed " << this << " we have " << scheduledActions.count() << " actions in the map" << endl;
1825 QMapIterator<int,ScheduledAction*> it;
1826 for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) {
1827 ScheduledAction *action = *it;
1828 //kdDebug(6070) << "WindowQObject::parentDestroyed deleting action " << action << endl;
1831 scheduledActions.clear();
1834 int WindowQObject::installTimeout(const UString &handler, int t, bool singleShot)
1836 //kdDebug(6070) << "WindowQObject::installTimeout " << this << " " << handler.ascii() << endl;
1837 int id = startTimer(t);
1838 ScheduledAction *action = new ScheduledAction(handler.qstring(),singleShot);
1839 scheduledActions.insert(id, action);
1840 //kdDebug(6070) << this << " got id=" << id << " action=" << action << " - now having " << scheduledActions.count() << " actions"<<endl;
1844 int WindowQObject::installTimeout(const Value &func, List args, int t, bool singleShot)
1846 Object objFunc = Object::dynamicCast( func );
1847 int id = startTimer(t);
1848 scheduledActions.insert(id, new ScheduledAction(objFunc,args,singleShot));
1852 QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key)
1854 QMapIterator<int,ScheduledAction*> it;
1856 QMap<int, KJS::ScheduledAction*>*pausedActions = new QMap<int, KJS::ScheduledAction*>;
1857 for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) {
1858 int timerId = it.key();
1859 pauseTimer (timerId, key);
1860 pausedActions->insert(timerId, it.data());
1862 scheduledActions.clear();
1863 return pausedActions;
1866 void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key)
1868 QMapIterator<int,ScheduledAction*> it;
1869 for (it = sa->begin(); it != sa->end(); ++it) {
1870 int timerId = it.key();
1871 scheduledActions.insert(timerId, it.data());
1874 resumeTimers (key, this);
1877 void WindowQObject::clearTimeout(int timerId, bool delAction)
1879 //kdDebug(6070) << "WindowQObject::clearTimeout " << this << " timerId=" << timerId << " delAction=" << delAction << endl;
1882 QMapIterator<int,ScheduledAction*> it = scheduledActions.find(timerId);
1883 if (it != scheduledActions.end()) {
1884 ScheduledAction *action = *it;
1885 scheduledActions.remove(it);
1891 void WindowQObject::timerEvent(QTimerEvent *e)
1893 QMapIterator<int,ScheduledAction*> it = scheduledActions.find(e->timerId());
1894 if (it != scheduledActions.end()) {
1895 ScheduledAction *action = *it;
1896 bool singleShot = action->singleShot;
1897 //kdDebug(6070) << "WindowQObject::timerEvent " << this << " action=" << action << " singleShot:" << singleShot << endl;
1899 // remove single shots installed by setTimeout()
1902 clearTimeout(e->timerId(),false);
1903 scheduledActions.remove(it);
1906 if (!parent->part().isNull())
1907 action->execute(parent);
1909 // It is important to test singleShot and not action->singleShot here - the
1910 // action could have been deleted already if not single shot and if the
1911 // JS code called by execute() calls clearTimeout().
1915 kdWarning(6070) << "WindowQObject::timerEvent this=" << this << " timer " << e->timerId()
1916 << " not found (" << scheduledActions.count() << " actions in map)" << endl;
1919 void WindowQObject::timeoutClose()
1921 if (!parent->part().isNull())
1923 //kdDebug(6070) << "WindowQObject::timeoutClose -> closing window" << endl;
1924 delete parent->m_part;
1929 bool WindowQObject::hasTimeouts()
1931 return scheduledActions.count();
1935 Value FrameArray::get(ExecState *exec, const Identifier &p) const
1938 kdDebug(6070) << "FrameArray::get " << p.qstring() << " part=" << (void*)part << endl;
1943 QPtrList<KParts::ReadOnlyPart> frames = part->frames();
1944 unsigned int len = frames.count();
1945 if (p == lengthPropertyName)
1947 else if (p== "location") // non-standard property, but works in NS and IE
1949 Object obj = Object::dynamicCast( Window::retrieve( part ) );
1950 if ( !obj.isNull() )
1951 return obj.get( exec, "location" );
1955 // check for the name or number
1956 KParts::ReadOnlyPart *frame = part->findFrame(p.qstring());
1959 unsigned int i = p.toArrayIndex(&ok);
1961 frame = frames.at(i);
1964 // we are potentially fetching a reference to a another Window object here.
1965 // i.e. we may be accessing objects from another interpreter instance.
1966 // Therefore we have to be a bit careful with memory managment.
1967 if (frame && frame->inherits("KHTMLPart")) {
1968 KHTMLPart *khtml = static_cast<KHTMLPart*>(frame);
1969 return Window::retrieve(khtml);
1972 return ObjectImp::get(exec, p);
1975 UString FrameArray::toString(ExecState *) const
1977 return "[object FrameArray]";
1980 ////////////////////// Location Object ////////////////////////
1982 const ClassInfo Location::info = { "Location", 0, 0, 0 };
1984 @begin LocationTable 11
1985 hash Location::Hash DontDelete
1986 host Location::Host DontDelete
1987 hostname Location::Hostname DontDelete
1988 href Location::Href DontDelete
1989 pathname Location::Pathname DontDelete
1990 port Location::Port DontDelete
1991 protocol Location::Protocol DontDelete
1992 search Location::Search DontDelete
1993 [[==]] Location::EqualEqual DontDelete|ReadOnly
1994 toString Location::ToString DontDelete|Function 0
1995 replace Location::Replace DontDelete|Function 1
1996 reload Location::Reload DontDelete|Function 0
1999 IMPLEMENT_PROTOFUNC(LocationFunc)
2000 Location::Location(KHTMLPart *p) : m_part(p)
2002 //kdDebug(6070) << "Location::Location " << this << " m_part=" << (void*)m_part << endl;
2005 Location::~Location()
2007 //kdDebug(6070) << "Location::~Location " << this << " m_part=" << (void*)m_part << endl;
2010 Value Location::get(ExecState *exec, const Identifier &p) const
2013 kdDebug(6070) << "Location::get " << p.qstring() << " m_part=" << (void*)m_part << endl;
2016 if (m_part.isNull())
2019 const Window* window = Window::retrieveWindow(m_part);
2020 if (!window || !window->isSafeScript(exec))
2023 KURL url = m_part->url();
2024 const HashEntry *entry = Lookup::findEntry(&LocationTable, p);
2026 switch (entry->value) {
2028 return String( url.ref().isNull() ? QString("") : "#" + url.ref() );
2030 UString str = url.host();
2032 str += ":" + QString::number((int)url.port());
2034 // Note: this is the IE spec. The NS spec swaps the two, it says
2035 // "The hostname property is the concatenation of the host and port properties, separated by a colon."
2039 return String( url.host() );
2042 return String( url.prettyURL()+"/" );
2044 return String( url.prettyURL() );
2046 return String( url.path().isEmpty() ? QString("/") : url.path() );
2048 return String( url.port() ? QString::number((int)url.port()) : QString::fromLatin1("") );
2050 return String( url.protocol()+":" );
2052 return String( url.query() );
2053 case EqualEqual: // [[==]]
2054 return String(toString(exec));
2056 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2058 // Look for overrides
2059 ValueImp * val = ObjectImp::getDirect(p);
2063 switch (entry->value) {
2065 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2067 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2073 void Location::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2076 kdDebug(6070) << "Location::put " << p.qstring() << " m_part=" << (void*)m_part << endl;
2078 if (m_part.isNull())
2081 QString str = v.toString(exec).qstring();
2082 KURL url = m_part->url();
2083 const HashEntry *entry = Lookup::findEntry(&LocationTable, p);
2085 switch (entry->value) {
2087 KHTMLPart* p = Window::retrieveActive(exec)->part();
2089 url = p->htmlDocument().completeURL( str ).string();
2098 QString host = str.left(str.find(":"));
2099 QString port = str.mid(str.find(":")+1);
2101 url.setPort(port.toUInt());
2111 url.setPort(str.toUInt());
2114 url.setProtocol(str);
2121 ObjectImp::put(exec, p, v, attr);
2124 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2126 // We want a new history item if this JS was called via a user gesture
2127 m_part->scheduleLocationChange(url.url(), !userGesture, userGesture);
2129 m_part->scheduleLocationChange(url.url(), false /*don't lock history*/, userGesture);
2133 Value Location::toPrimitive(ExecState *exec, Type) const
2135 return String(toString(exec));
2138 UString Location::toString(ExecState *) const
2140 if (!m_part->url().hasPath())
2141 return m_part->url().prettyURL()+"/";
2143 return m_part->url().prettyURL();
2146 Value LocationFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2148 if (!thisObj.inherits(&Location::info)) {
2149 Object err = Error::create(exec,TypeError);
2150 exec->setException(err);
2153 Location *location = static_cast<Location *>(thisObj.imp());
2154 KHTMLPart *part = location->part();
2157 Window* window = Window::retrieveWindow(part);
2158 if (!window->isSafeScript(exec) && id != Location::Replace)
2162 case Location::Replace:
2164 QString str = args[0].toString(exec).qstring();
2165 KHTMLPart* p = Window::retrieveActive(exec)->part();
2167 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2168 part->scheduleLocationChange(p->htmlDocument().completeURL(str).string(), true /*lock history*/, userGesture);
2172 case Location::Reload:
2174 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2175 part->scheduleLocationChange(part->url().url(), true/*lock history*/, userGesture);
2178 case Location::ToString:
2179 return String(location->toString(exec));
2182 kdDebug(6070) << "LocationFunc::tryExecute - no part!" << endl;
2186 ////////////////////// Selection Object ////////////////////////
2188 const ClassInfo Selection::info = { "Selection", 0, 0, 0 };
2190 @begin SelectionTable 19
2191 anchorNode Selection::AnchorNode DontDelete|ReadOnly
2192 anchorOffset Selection::AnchorOffset DontDelete|ReadOnly
2193 focusNode Selection::FocusNode DontDelete|ReadOnly
2194 focusOffset Selection::FocusOffset DontDelete|ReadOnly
2195 baseNode Selection::AnchorNode DontDelete|ReadOnly
2196 baseOffset Selection::AnchorOffset DontDelete|ReadOnly
2197 extentNode Selection::FocusNode DontDelete|ReadOnly
2198 extentOffset Selection::FocusOffset DontDelete|ReadOnly
2199 isCollapsed Selection::IsCollapsed DontDelete|ReadOnly
2200 type Selection::_Type DontDelete|ReadOnly
2201 [[==]] Selection::EqualEqual DontDelete|ReadOnly
2202 toString Selection::ToString DontDelete|Function 0
2203 collapse Selection::Collapse DontDelete|Function 2
2204 collapseToEnd Selection::CollapseToEnd DontDelete|Function 0
2205 collapseToStart Selection::CollapseToStart DontDelete|Function 0
2206 empty Selection::Empty DontDelete|Function 0
2207 setBaseAndExtent Selection::SetBaseAndExtent DontDelete|Function 4
2208 setPosition Selection::SetPosition DontDelete|Function 2
2209 modify Selection::Modify DontDelete|Function 3
2212 IMPLEMENT_PROTOFUNC(SelectionFunc)
2213 Selection::Selection(KHTMLPart *p) : m_part(p)
2215 //kdDebug(6070) << "Selection::Selection " << this << " m_part=" << (void*)m_part << endl;
2218 Selection::~Selection()
2220 //kdDebug(6070) << "Selection::~Selection " << this << " m_part=" << (void*)m_part << endl;
2223 Value Selection::get(ExecState *exec, const Identifier &p) const
2226 kdDebug(6070) << "Selection::get " << p.qstring() << " m_part=" << (void*)m_part << endl;
2229 if (m_part.isNull())
2232 const Window* window = Window::retrieveWindow(m_part);
2233 if (!window || !window->isSafeScript(exec))
2236 DocumentImpl *docimpl = m_part->xmlDocImpl();
2238 docimpl->updateLayoutIgnorePendingStylesheets();
2240 KURL url = m_part->url();
2241 const HashEntry *entry = Lookup::findEntry(&SelectionTable, p);
2243 switch (entry->value) {
2246 return getDOMNode(exec, Node(m_part->selection().base().node()));
2249 return Number(m_part->selection().base().offset());
2252 return getDOMNode(exec, Node(m_part->selection().extent().node()));
2255 return Number(m_part->selection().extent().offset());
2257 return Boolean(!m_part->selection().isRange());
2259 switch (m_part->selection().state()) {
2260 case khtml::Selection::NONE:
2261 return String("None");
2262 case khtml::Selection::CARET:
2263 return String("Caret");
2264 case khtml::Selection::RANGE:
2265 return String("Range");
2269 return String(toString(exec));
2271 return lookupOrCreateFunction<SelectionFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2273 // Look for overrides
2274 ValueImp * val = ObjectImp::getDirect(p);
2278 switch (entry->value) {
2281 case CollapseToStart:
2283 case SetBaseAndExtent:
2286 return lookupOrCreateFunction<SelectionFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2292 void Selection::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2296 Value Selection::toPrimitive(ExecState *exec, Type) const
2298 return String(toString(exec));
2301 UString Selection::toString(ExecState *) const
2303 if (!m_part->selection().isRange())
2305 return UString(m_part->selection().toRange().toString());
2308 Value SelectionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2310 if (!thisObj.inherits(&Selection::info)) {
2311 Object err = Error::create(exec,TypeError);
2312 exec->setException(err);
2315 Selection *selection = static_cast<Selection *>(thisObj.imp());
2316 KHTMLPart *part = selection->part();
2318 DocumentImpl *docimpl = part->xmlDocImpl();
2320 docimpl->updateLayoutIgnorePendingStylesheets();
2323 case Selection::Collapse:
2324 TypingCommand::closeTyping(part->lastEditCommand());
2325 part->setSelection(khtml::Selection(Position(KJS::toNode(args[0]).handle(), args[1].toInt32(exec))));
2327 case Selection::CollapseToEnd:
2328 TypingCommand::closeTyping(part->lastEditCommand());
2329 part->setSelection(khtml::Selection(part->selection().end()));
2331 case Selection::CollapseToStart:
2332 TypingCommand::closeTyping(part->lastEditCommand());
2333 part->setSelection(khtml::Selection(part->selection().start()));
2335 case Selection::Empty:
2336 TypingCommand::closeTyping(part->lastEditCommand());
2337 part->clearSelection();
2339 case Selection::SetBaseAndExtent: {
2340 TypingCommand::closeTyping(part->lastEditCommand());
2341 Position base(KJS::toNode(args[0]).handle(), args[1].toInt32(exec));
2342 Position extent(KJS::toNode(args[2]).handle(), args[3].toInt32(exec));
2343 part->setSelection(khtml::Selection(base, extent));
2346 case Selection::SetPosition:
2347 TypingCommand::closeTyping(part->lastEditCommand());
2348 part->setSelection(khtml::Selection(Position(KJS::toNode(args[0]).handle(), args[1].toInt32(exec))));
2350 case Selection::Modify: {
2351 TypingCommand::closeTyping(part->lastEditCommand());
2352 khtml::Selection s(part->selection());
2353 khtml::Selection::EAlter alter = khtml::Selection::MOVE;
2354 if (args[0].toString(exec).string().lower() == "extend")
2355 alter = khtml::Selection::EXTEND;
2356 DOMString directionString = args[1].toString(exec).string().lower();
2357 khtml::Selection::EDirection direction = khtml::Selection::FORWARD;
2358 if (directionString == "backward")
2359 direction = khtml::Selection::BACKWARD;
2360 else if (directionString == "left")
2361 direction = khtml::Selection::LEFT;
2362 if (directionString == "right")
2363 direction = khtml::Selection::RIGHT;
2364 khtml::ETextGranularity granularity = khtml::CHARACTER;
2365 DOMString granularityString = args[2].toString(exec).string().lower();
2366 if (granularityString == "word")
2367 granularity = khtml::WORD;
2368 else if (granularityString == "line")
2369 granularity = khtml::LINE;
2370 else if (granularityString == "pargraph")
2371 granularity = khtml::PARAGRAPH;
2372 s.modify(alter, direction, granularity);
2373 part->setSelection(s);
2381 ////////////////////// BarInfo Object ////////////////////////
2383 const ClassInfo BarInfo::info = { "BarInfo", 0, 0, 0 };
2385 @begin BarInfoTable 1
2386 visible BarInfo::Visible DontDelete|ReadOnly
2389 BarInfo::BarInfo(ExecState *exec, KHTMLPart *p, Type barType)
2390 : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype())
2400 Value BarInfo::get(ExecState *exec, const Identifier &p) const
2402 if (m_part.isNull())
2405 const HashEntry *entry = Lookup::findEntry(&BarInfoTable, p);
2406 if (entry && entry->value == Visible) {
2410 return Boolean(KWQ(m_part)->locationbarVisible());
2414 return Boolean(KWQ(m_part)->locationbarVisible());
2418 return Boolean(KWQ(m_part)->personalbarVisible());
2422 return Boolean(KWQ(m_part)->scrollbarsVisible());
2426 return Boolean(KWQ(m_part)->statusbarVisible());
2430 return Boolean(KWQ(m_part)->toolbarVisible());
2433 return Boolean(false);
2440 void BarInfo::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2444 ////////////////////// History Object ////////////////////////
2446 const ClassInfo History::info = { "History", 0, 0, 0 };
2448 @begin HistoryTable 4
2449 length History::Length DontDelete|ReadOnly
2450 back History::Back DontDelete|Function 0
2451 forward History::Forward DontDelete|Function 0
2452 go History::Go DontDelete|Function 1
2455 IMPLEMENT_PROTOFUNC(HistoryFunc)
2457 Value History::get(ExecState *exec, const Identifier &p) const
2459 return lookupGet<HistoryFunc,History,ObjectImp>(exec,p,&HistoryTable,this);
2462 Value History::getValueProperty(ExecState *, int token) const
2467 KParts::BrowserExtension *ext = part->browserExtension();
2471 KParts::BrowserInterface *iface = ext->browserInterface();
2475 QVariant length = iface->property( "historyLength" );
2477 if ( length.type() != QVariant::UInt )
2480 return Number( length.toUInt() );
2483 kdWarning() << "Unhandled token in History::getValueProperty : " << token << endl;
2488 UString History::toString(ExecState *exec) const
2490 return "[object History]";
2493 Value HistoryFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2495 if (!thisObj.inherits(&History::info)) {
2496 Object err = Error::create(exec,TypeError);
2497 exec->setException(err);
2500 History *history = static_cast<History *>(thisObj.imp());
2507 case History::Forward:
2511 steps = args[0].toInt32(exec);
2517 history->part->scheduleHistoryNavigation(steps);
2521 /////////////////////////////////////////////////////////////////////////////
2525 const ClassInfo Konqueror::info = { "Konqueror", 0, 0, 0 };
2527 bool Konqueror::hasProperty(ExecState *exec, const Identifier &p) const
2529 if ( p.qstring().startsWith( "goHistory" ) ) return false;
2534 Value Konqueror::get(ExecState *exec, const Identifier &p) const
2536 if ( p == "goHistory" || part->url().protocol() != "http" || part->url().host() != "localhost" )
2539 KParts::BrowserExtension *ext = part->browserExtension();
2541 KParts::BrowserInterface *iface = ext->browserInterface();
2543 QVariant prop = iface->property( p.qstring().latin1() );
2545 if ( prop.isValid() ) {
2546 switch( prop.type() ) {
2548 return Number( prop.toInt() );
2549 case QVariant::String:
2550 return String( prop.toString() );
2558 return /*Function*/( new KonquerorFunc(this, p.qstring().latin1() ) );
2561 Value KonquerorFunc::tryCall(ExecState *exec, Object &, const List &args)
2563 KParts::BrowserExtension *ext = konqueror->part->browserExtension();
2568 KParts::BrowserInterface *iface = ext->browserInterface();
2573 QCString n = m_name.data();
2575 iface->callMethod( n.data(), QVariant() );
2580 UString Konqueror::toString(ExecState *) const
2582 return UString("[object Konqueror]");
2586 /////////////////////////////////////////////////////////////////////////////
2588 #include "kjs_window.moc"