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));
646 return lookupOrCreateFunction<WindowFunc>(exec,p,this,entry->value,entry->params,entry->attr);
654 case Scroll: // compatibility
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;
839 if (isSafeScript(exec))
840 return ObjectImp::get(exec, p);
845 bool Window::hasProperty(ExecState *exec, const Identifier &p) const
847 // matches logic in get function above, but no need to handle numeric values (frame indices)
850 return p == "closed";
855 if (Lookup::findEntry(&WindowTable, p))
858 if (m_part->findFrame(p.qstring()))
861 if (!m_part->htmlDocument().all().namedItem(p.string()).isNull())
867 void Window::put(ExecState* exec, const Identifier &propertyName, const Value &value, int attr)
869 // Called by an internal KJS call (e.g. InterpreterImp's constructor) ?
870 // If yes, save time and jump directly to ObjectImp.
871 if ( (attr != None && attr != DontDelete)
872 // Same thing if we have a local override (e.g. "var location")
873 || ( ObjectImp::getDirect(propertyName) && isSafeScript(exec)) )
875 ObjectImp::put( exec, propertyName, value, attr );
879 const HashEntry* entry = Lookup::findEntry(&WindowTable, propertyName);
883 kdDebug(6070) << "Window("<<this<<")::put " << propertyName.qstring() << endl;
885 switch( entry->value ) {
887 String s = value.toString(exec);
888 m_part->setJSStatusBarText(s.value().qstring());
891 case DefaultStatus: {
892 String s = value.toString(exec);
893 m_part->setJSDefaultStatusBarText(s.value().qstring());
897 KHTMLPart* p = Window::retrieveActive(exec)->m_part;
899 QString dstUrl = p->htmlDocument().completeURL(value.toString(exec).string()).string();
900 if (!dstUrl.startsWith("javascript:", false) || isSafeScript(exec))
902 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
904 // We want a new history item if this JS was called via a user gesture
905 m_part->scheduleLocationChange(dstUrl, !userGesture, userGesture);
907 m_part->scheduleLocationChange(dstUrl, false /*don't lock history*/, userGesture);
914 if (isSafeScript(exec))
915 setListener(exec, DOM::EventImpl::ABORT_EVENT,value);
918 if (isSafeScript(exec))
919 setListener(exec, DOM::EventImpl::BLUR_EVENT,value);
922 if (isSafeScript(exec))
923 setListener(exec, DOM::EventImpl::CHANGE_EVENT,value);
926 if (isSafeScript(exec))
927 setListener(exec,DOM::EventImpl::KHTML_CLICK_EVENT,value);
930 if (isSafeScript(exec))
931 setListener(exec,DOM::EventImpl::KHTML_DBLCLICK_EVENT,value);
934 if (isSafeScript(exec))
935 setListener(exec,DOM::EventImpl::KHTML_DRAGDROP_EVENT,value);
938 if (isSafeScript(exec))
939 setListener(exec,DOM::EventImpl::KHTML_ERROR_EVENT,value);
942 if (isSafeScript(exec))
943 setListener(exec,DOM::EventImpl::FOCUS_EVENT,value);
946 if (isSafeScript(exec))
947 setListener(exec,DOM::EventImpl::KEYDOWN_EVENT,value);
950 if (isSafeScript(exec))
951 setListener(exec,DOM::EventImpl::KEYPRESS_EVENT,value);
954 if (isSafeScript(exec))
955 setListener(exec,DOM::EventImpl::KEYUP_EVENT,value);
958 if (isSafeScript(exec))
959 setListener(exec,DOM::EventImpl::LOAD_EVENT,value);
962 if (isSafeScript(exec))
963 setListener(exec,DOM::EventImpl::MOUSEDOWN_EVENT,value);
966 if (isSafeScript(exec))
967 setListener(exec,DOM::EventImpl::MOUSEMOVE_EVENT,value);
970 if (isSafeScript(exec))
971 setListener(exec,DOM::EventImpl::MOUSEOUT_EVENT,value);
974 if (isSafeScript(exec))
975 setListener(exec,DOM::EventImpl::MOUSEOVER_EVENT,value);
978 if (isSafeScript(exec))
979 setListener(exec,DOM::EventImpl::MOUSEUP_EVENT,value);
982 if (isSafeScript(exec))
983 setListener(exec,DOM::EventImpl::KHTML_MOVE_EVENT,value);
986 if (isSafeScript(exec))
987 setListener(exec,DOM::EventImpl::RESET_EVENT,value);
990 if (isSafeScript(exec))
991 setListener(exec,DOM::EventImpl::RESIZE_EVENT,value);
994 if (isSafeScript(exec))
995 setListener(exec,DOM::EventImpl::SCROLL_EVENT,value);
999 if (isSafeScript(exec))
1000 setListener(exec,DOM::EventImpl::SEARCH_EVENT,value);
1004 if (isSafeScript(exec))
1005 setListener(exec,DOM::EventImpl::SELECT_EVENT,value);
1008 if (isSafeScript(exec))
1009 setListener(exec,DOM::EventImpl::SUBMIT_EVENT,value);
1012 if (isSafeScript(exec))
1013 setListener(exec,DOM::EventImpl::UNLOAD_EVENT,value);
1016 if (isSafeScript(exec))
1018 m_part->setName( value.toString(exec).qstring() );
1020 m_part->setName( value.toString(exec).qstring().local8Bit().data() );
1027 if (isSafeScript(exec)) {
1028 //kdDebug(6070) << "Window("<<this<<")::put storing " << propertyName.qstring() << endl;
1029 ObjectImp::put(exec, propertyName, value, attr);
1033 bool Window::toBoolean(ExecState *) const
1035 return !m_part.isNull();
1038 int Window::installTimeout(const UString &handler, int t, bool singleShot)
1040 return winq->installTimeout(handler, t, singleShot);
1043 int Window::installTimeout(const Value &function, List &args, int t, bool singleShot)
1045 return winq->installTimeout(function, args, t, singleShot);
1048 void Window::clearTimeout(int timerId)
1050 winq->clearTimeout(timerId);
1054 bool Window::hasTimeouts()
1056 return winq->hasTimeouts();
1059 QMap<int, ScheduledAction*> *Window::pauseTimeouts(const void *key)
1061 return winq->pauseTimeouts(key);
1064 void Window::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key)
1066 return winq->resumeTimeouts(sa, key);
1070 void Window::scheduleClose()
1072 kdDebug(6070) << "Window::scheduleClose window.close() " << m_part << endl;
1075 KWQ(m_part)->scheduleClose();
1077 QTimer::singleShot( 0, winq, SLOT( timeoutClose() ) );
1081 static bool shouldLoadAsEmptyDocument(const KURL &url)
1083 return url.protocol().lower() == "about" || url.isEmpty();
1086 bool Window::isSafeScript(ExecState *exec) const
1088 if (m_part.isNull()) { // part deleted ? can't grant access
1089 kdDebug(6070) << "Window::isSafeScript: accessing deleted part !" << endl;
1092 KHTMLPart *activePart = static_cast<KJS::ScriptInterpreter *>( exec->dynamicInterpreter() )->part();
1094 kdDebug(6070) << "Window::isSafeScript: current interpreter's part is 0L!" << endl;
1097 if ( activePart == m_part ) // Not calling from another frame, no problem.
1100 // JS may be attempting to access the "window" object, which should be valid,
1101 // even if the document hasn't been constructed yet. If the document doesn't
1102 // exist yet allow JS to access the window object.
1103 if (!m_part->xmlDocImpl())
1106 DOM::DocumentImpl* thisDocument = m_part->xmlDocImpl();
1107 DOM::DocumentImpl* actDocument = activePart->xmlDocImpl();
1110 kdDebug(6070) << "Window::isSafeScript: active part has no document!" << endl;
1114 DOM::DOMString actDomain = actDocument->domain();
1116 // Always allow local pages to execute any JS.
1117 if (actDomain.isNull())
1120 DOM::DOMString thisDomain = thisDocument->domain();
1122 // if this document is being initially loaded as empty by its parent
1123 // or opener, allow access from any document in the same domain as
1124 // the parent or opener.
1125 if (shouldLoadAsEmptyDocument(m_part->url())) {
1126 KHTMLPart *ancestorPart = m_part->opener() ? m_part->opener() : m_part->parentPart();
1127 while (ancestorPart && shouldLoadAsEmptyDocument(ancestorPart->url())) {
1128 ancestorPart = ancestorPart->parentPart();
1132 thisDomain = ancestorPart->xmlDocImpl()->domain();
1135 //kdDebug(6070) << "current domain:" << actDomain.string() << ", frame domain:" << thisDomain.string() << endl;
1136 if ( actDomain == thisDomain )
1140 if (Interpreter::shouldPrintExceptions()) {
1141 printf("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
1142 thisDocument->URL().latin1(), actDocument->URL().latin1());
1144 message.sprintf("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains must match.\n",
1145 thisDocument->URL().latin1(), actDocument->URL().latin1());
1146 KWQ(m_part)->addMessageToConsole(message, 1, QString()); //fixme: provide a real line number and sourceurl
1150 kdWarning(6070) << "Javascript: access denied for current frame '" << actDomain.string() << "' to frame '" << thisDomain.string() << "'" << endl;
1154 void Window::setListener(ExecState *exec, int eventId, Value func)
1156 if (!isSafeScript(exec))
1158 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(m_part->htmlDocument().handle());
1162 doc->setHTMLWindowEventListener(eventId,getJSEventListener(func,true));
1165 Value Window::getListener(ExecState *exec, int eventId) const
1167 if (!isSafeScript(exec))
1169 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(m_part->htmlDocument().handle());
1173 DOM::EventListener *listener = doc->getHTMLWindowEventListener(eventId);
1174 if (listener && static_cast<JSEventListener*>(listener)->listenerObjImp())
1175 return static_cast<JSEventListener*>(listener)->listenerObj();
1181 JSEventListener *Window::getJSEventListener(const Value& val, bool html)
1183 // This function is so hot that it's worth coding it directly with imps.
1184 if (val.type() != ObjectType)
1186 ObjectImp *listenerObject = static_cast<ObjectImp *>(val.imp());
1188 JSEventListener *existingListener = jsEventListeners[listenerObject];
1189 if (existingListener)
1190 return existingListener;
1192 // Note that the JSEventListener constructor adds it to our jsEventListeners list
1193 return new JSEventListener(Object(listenerObject), Object(this), html);
1196 JSLazyEventListener *Window::getJSLazyEventListener(const QString& code, bool html, int lineNumber)
1198 return new JSLazyEventListener(code, Object(this), html, lineNumber);
1201 void Window::clear( ExecState *exec )
1203 KJS::Interpreter::lock();
1204 kdDebug(6070) << "Window::clear " << this << endl;
1206 winq = new WindowQObject(this);;
1207 // Get rid of everything, those user vars could hold references to DOM nodes
1208 deleteAllProperties( exec );
1209 // Really delete those properties, so that the DOM nodes get deref'ed
1210 KJS::Collector::collect();
1211 // Now recreate a working global object for the next URL that will use us
1212 KJS::Interpreter *interpreter = KJSProxy::proxy( m_part )->interpreter();
1213 interpreter->initGlobalObject();
1214 KJS::Interpreter::unlock();
1217 void Window::setCurrentEvent( DOM::Event *evt )
1220 //kdDebug(6070) << "Window " << this << " (part=" << m_part << ")::setCurrentEvent m_evt=" << evt << endl;
1223 Value WindowFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
1225 if (!thisObj.inherits(&Window::info)) {
1226 Object err = Error::create(exec,TypeError);
1227 exec->setException(err);
1230 Window *window = static_cast<Window *>(thisObj.imp());
1233 KHTMLPart *part = window->m_part;
1237 KHTMLView *widget = part->view();
1239 UString s = v.toString(exec);
1244 if (part && part->xmlDocImpl())
1245 part->xmlDocImpl()->updateRendering();
1247 KWQ(part)->runJavaScriptAlert(str);
1249 KMessageBox::error(widget, QStyleSheet::convertFromPlainText(str), "JavaScript");
1252 case Window::Confirm:
1253 if (part && part->xmlDocImpl())
1254 part->xmlDocImpl()->updateRendering();
1256 return Boolean(KWQ(part)->runJavaScriptConfirm(str));
1258 return Boolean((KMessageBox::warningYesNo(widget, QStyleSheet::convertFromPlainText(str), "JavaScript",
1259 i18n("OK"), i18n("Cancel")) == KMessageBox::Yes));
1261 case Window::Prompt:
1262 if (part && part->xmlDocImpl())
1263 part->xmlDocImpl()->updateRendering();
1266 ok = KWQ(part)->runJavaScriptPrompt(str, args.size() >= 2 ? args[1].toString(exec).qstring() : QString::null, str2);
1268 if (args.size() >= 2)
1269 str2 = QInputDialog::getText(i18n("Konqueror: Prompt"),
1270 QStyleSheet::convertFromPlainText(str),
1272 args[1].toString(exec).qstring(), &ok);
1274 str2 = QInputDialog::getText(i18n("Konqueror: Prompt"),
1275 QStyleSheet::convertFromPlainText(str),
1277 QString::null, &ok);
1280 return String(str2);
1285 KConfig *config = new KConfig("konquerorrc");
1286 config->setGroup("Java/JavaScript Settings");
1288 int policy = config->readUnsignedNumEntry( "WindowOpenPolicy", 0 ); // 0=allow, 1=ask, 2=deny, 3=smart
1290 int policy = config->readUnsignedNumEntry( part->settings(), "WindowOpenPolicy", 0 ); // 0=allow, 1=ask, 2=deny, 3=smart
1293 if ( policy == 1 ) {
1295 if ( KMessageBox::questionYesNo(widget,
1296 i18n( "This site is trying to open up a new browser "
1297 "window using Javascript.\n"
1298 "Do you want to allow this?" ),
1299 i18n( "Confirmation: Javascript Popup" ) ) == KMessageBox::Yes )
1302 } else if ( policy == 3 ) // smart
1304 // window.open disabled unless from a key/mouse event
1305 if (static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture())
1311 LOG(PopupBlocking, "Allowed JavaScript window open of %s", args[0].toString(exec).qstring().ascii());
1313 LOG(PopupBlocking, "Blocked JavaScript window open of %s", args[0].toString(exec).qstring().ascii());
1318 QString frameName = !args[1].isNull() && args[1].type() != UndefinedType ?
1319 args[1].toString(exec).qstring()
1320 : QString("_blank");
1322 if ( policy != 0 && !(part->findFrame(frameName) || frameName == "_top" || frameName == "_parent" || frameName == "_self")) {
1325 if (v.type() == UndefinedType)
1328 KParts::WindowArgs winargs;
1330 // scan feature argument
1333 if (!v.isNull() && v.type() != UndefinedType && v.toString(exec).size() > 0) {
1334 features = v.toString(exec).qstring();
1335 // specifying window params means false defaults
1336 winargs.menuBarVisible = false;
1337 winargs.toolBarsVisible = false;
1338 winargs.statusBarVisible = false;
1340 winargs.scrollbarsVisible = true;
1342 QStringList flist = QStringList::split(',', features);
1343 QStringList::ConstIterator it = flist.begin();
1344 while (it != flist.end()) {
1347 int pos = s.find('=');
1349 key = s.left(pos).stripWhiteSpace().lower();
1350 val = s.mid(pos + 1).stripWhiteSpace().lower();
1351 int spacePos = val.find(' ');
1352 if (spacePos != -1) {
1353 val = val.left(spacePos);
1356 int scnum = QApplication::desktop()->screenNumber(widget->topLevelWidget());
1358 QRect screen = QApplication::desktop()->screenGeometry(scnum);
1359 if (key == "left" || key == "screenx") {
1361 double d = val.toDouble(&ok);
1364 if (d < screen.x() || d > screen.right())
1365 d = screen.x(); // only safe choice until size is determined
1368 winargs.xSet = true;
1371 } else if (key == "top" || key == "screeny") {
1373 double d = val.toDouble(&ok);
1376 if (d < screen.y() || d > screen.bottom())
1377 d = screen.y(); // only safe choice until size is determined
1380 winargs.ySet = true;
1383 } else if (key == "height") {
1385 double d = val.toDouble(&ok);
1388 d += 2*qApp->style().pixelMetric( QStyle::PM_DefaultFrameWidth ) + 2;
1390 if (d > screen.height()) // should actually check workspace
1391 d = screen.height();
1394 winargs.height = (int)d;
1396 winargs.heightSet = true;
1399 } else if (key == "width") {
1401 double d = val.toDouble(&ok);
1404 d += 2*qApp->style().pixelMetric( QStyle::PM_DefaultFrameWidth ) + 2;
1406 if (d > screen.width()) // should actually check workspace
1410 winargs.width = (int)d;
1412 winargs.widthSet = true;
1420 // leaving away the value gives true
1421 key = s.stripWhiteSpace().lower();
1425 if (key == "menubar")
1426 winargs.menuBarVisible = (val == "1" || val == "yes");
1427 else if (key == "toolbar")
1428 winargs.toolBarsVisible = (val == "1" || val == "yes");
1429 else if (key == "location") // ### missing in WindowArgs
1430 winargs.toolBarsVisible = (val == "1" || val == "yes");
1431 else if (key == "status" || key == "statusbar")
1432 winargs.statusBarVisible = (val == "1" || val == "yes");
1433 else if (key == "resizable")
1434 winargs.resizable = (val == "1" || val == "yes");
1435 else if (key == "fullscreen")
1436 winargs.fullscreen = (val == "1" || val == "yes");
1438 else if (key == "scrollbars")
1439 winargs.scrollbarsVisible = !(val == "0" || val == "no");
1444 // prepare arguments
1448 KHTMLPart* p = Window::retrieveActive(exec)->m_part;
1450 url = p->htmlDocument().completeURL(str).string();
1453 KParts::URLArgs uargs;
1454 uargs.frameName = frameName;
1455 if ( uargs.frameName == "_top" )
1458 while ( part->parentPart() )
1459 part = part->parentPart();
1461 const Window* window = Window::retrieveWindow(part);
1462 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
1463 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1464 part->scheduleLocationChange(url.url(), false/*don't lock history*/, userGesture);
1466 return Window::retrieve(part);
1468 if ( uargs.frameName == "_parent" )
1471 if ( part->parentPart() )
1472 part = part->parentPart();
1474 const Window* window = Window::retrieveWindow(part);
1475 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
1476 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1477 part->scheduleLocationChange(url.url(), false/*don't lock history*/, userGesture);
1479 return Window::retrieve(part);
1481 uargs.serviceType = "text/html";
1483 // request window (new or existing if framename is set)
1484 KParts::ReadOnlyPart *newPart = 0L;
1485 emit part->browserExtension()->createNewWindow("", uargs,winargs,newPart);
1486 if (newPart && newPart->inherits("KHTMLPart")) {
1487 KHTMLPart *khtmlpart = static_cast<KHTMLPart*>(newPart);
1488 //qDebug("opener set to %p (this Window's part) in new Window %p (this Window=%p)",part,win,window);
1489 khtmlpart->setOpener(part);
1490 khtmlpart->setOpenedByJS(true);
1492 if (khtmlpart->document().isNull()) {
1493 DocumentImpl *oldDoc = part->xmlDocImpl();
1494 if (oldDoc && oldDoc->baseURL() != 0)
1495 khtmlpart->begin(oldDoc->baseURL());
1499 khtmlpart->write("<HTML><BODY>");
1503 kdDebug(6070) << "Setting domain to " << oldDoc->domain().string() << endl;
1504 khtmlpart->xmlDocImpl()->setDomain( oldDoc->domain(), true );
1505 khtmlpart->xmlDocImpl()->setBaseURL( oldDoc->baseURL() );
1509 if (!url.isEmpty()) {
1510 const Window* window = Window::retrieveWindow(part);
1511 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
1512 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1513 // FIXME: Need to pass referrer here.
1514 khtmlpart->scheduleLocationChange(url.url(), false, userGesture);
1518 uargs.serviceType = QString::null;
1519 if (uargs.frameName == "_blank")
1520 uargs.frameName = QString::null;
1522 // FIXME: need to pass referrer here
1523 emit khtmlpart->browserExtension()->openURLRequest(url,uargs);
1525 return Window::retrieve(khtmlpart); // global object
1535 case Window::ScrollBy:
1536 window->updateLayout();
1537 if(args.size() >= 2 && widget)
1538 widget->scrollBy(args[0].toInt32(exec), args[1].toInt32(exec));
1540 case Window::Scroll:
1541 case Window::ScrollTo:
1542 window->updateLayout();
1543 if(args.size() >= 2 && widget)
1544 widget->setContentsPos(args[0].toInt32(exec), args[1].toInt32(exec));
1546 case Window::MoveBy:
1547 if(args.size() >= 2 && widget)
1549 QWidget * tl = widget->topLevelWidget();
1550 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1551 QPoint dest = tl->pos() + QPoint( args[0].toInt32(exec), args[1].toInt32(exec) );
1552 // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1553 if ( dest.x() >= sg.x() && dest.y() >= sg.x() &&
1554 dest.x()+tl->width() <= sg.width()+sg.x() &&
1555 dest.y()+tl->height() <= sg.height()+sg.y() )
1559 case Window::MoveTo:
1560 if(args.size() >= 2 && widget)
1562 QWidget * tl = widget->topLevelWidget();
1563 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1564 QPoint dest( args[0].toInt32(exec)+sg.x(), args[1].toInt32(exec)+sg.y() );
1565 // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1566 if ( dest.x() >= sg.x() && dest.y() >= sg.y() &&
1567 dest.x()+tl->width() <= sg.width()+sg.x() &&
1568 dest.y()+tl->height() <= sg.height()+sg.y() )
1572 case Window::ResizeBy:
1573 if(args.size() >= 2 && widget)
1575 QWidget * tl = widget->topLevelWidget();
1576 QSize dest = tl->size() + QSize( args[0].toInt32(exec), args[1].toInt32(exec) );
1577 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1578 // Security check: within desktop limits and bigger than 100x100 (per spec)
1579 if ( tl->x()+dest.width() <= sg.x()+sg.width() &&
1580 tl->y()+dest.height() <= sg.y()+sg.height() &&
1581 dest.width() >= 100 && dest.height() >= 100 )
1583 // Take into account the window frame
1584 int deltaWidth = tl->frameGeometry().width() - tl->width();
1585 int deltaHeight = tl->frameGeometry().height() - tl->height();
1586 tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );
1590 case Window::ResizeTo:
1591 if(args.size() >= 2 && widget)
1593 QWidget * tl = widget->topLevelWidget();
1594 QSize dest = QSize( args[0].toInt32(exec), args[1].toInt32(exec) );
1595 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1596 // Security check: within desktop limits and bigger than 100x100 (per spec)
1597 if ( tl->x()+dest.width() <= sg.x()+sg.width() &&
1598 tl->y()+dest.height() <= sg.y()+sg.height() &&
1599 dest.width() >= 100 && dest.height() >= 100 )
1601 // Take into account the window frame
1602 int deltaWidth = tl->frameGeometry().width() - tl->width();
1603 int deltaHeight = tl->frameGeometry().height() - tl->height();
1604 tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );
1608 case Window::SetTimeout:
1609 if (!window->isSafeScript(exec))
1611 if (args.size() >= 2 && v.isA(StringType)) {
1612 int i = args[1].toInt32(exec);
1613 int r = (const_cast<Window*>(window))->installTimeout(s, i, true /*single shot*/);
1616 else if (args.size() >= 2 && v.isA(ObjectType) && Object::dynamicCast(v).implementsCall()) {
1617 Value func = args[0];
1618 int i = args[1].toInt32(exec);
1620 // All arguments after the second should go to the function
1621 // FIXME: could be more efficient
1622 List funcArgs = args.copyTail().copyTail();
1624 int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, true /*single shot*/);
1629 case Window::SetInterval:
1630 if (!window->isSafeScript(exec))
1632 if (args.size() >= 2 && v.isA(StringType)) {
1633 int i = args[1].toInt32(exec);
1634 int r = (const_cast<Window*>(window))->installTimeout(s, i, false);
1637 else if (args.size() >= 2 && !Object::dynamicCast(v).isNull() &&
1638 Object::dynamicCast(v).implementsCall()) {
1639 Value func = args[0];
1640 int i = args[1].toInt32(exec);
1642 // All arguments after the second should go to the function
1643 // FIXME: could be more efficient
1644 List funcArgs = args.copyTail().copyTail();
1646 int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, false);
1651 case Window::ClearTimeout:
1652 case Window::ClearInterval:
1653 if (!window->isSafeScript(exec))
1655 (const_cast<Window*>(window))->clearTimeout(v.toInt32(exec));
1659 widget->setActiveWindow();
1661 case Window::GetSelection:
1662 if (!window->isSafeScript(exec))
1664 return Value(window->selection());
1667 KWQ(part)->unfocusWindow();
1673 /* From http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm :
1674 The close method closes only windows opened by JavaScript using the open method.
1675 If you attempt to close any other window, a confirm is generated, which
1676 lets the user choose whether the window closes.
1677 This is a security feature to prevent "mail bombs" containing self.close().
1678 However, if the window has only one document (the current one) in its
1679 session history, the close is allowed without any confirm. This is a
1680 special case for one-off windows that need to open other windows and
1681 then dispose of themselves.
1683 if (!part->openedByJS())
1685 // To conform to the SPEC, we only ask if the window
1686 // has more than one entry in the history (NS does that too).
1687 History history(exec,part);
1688 if ( history.get( exec, lengthPropertyName ).toInt32(exec) <= 1
1690 // FIXME: How are we going to handle this?
1692 || KMessageBox::questionYesNo( window->part()->view(), i18n("Close window?"), i18n("Confirmation Required") ) == KMessageBox::Yes
1695 (const_cast<Window*>(window))->scheduleClose();
1699 (const_cast<Window*>(window))->scheduleClose();
1702 case Window::CaptureEvents:
1703 case Window::ReleaseEvents:
1704 // If anyone implements these, they need the safescript security check.
1705 if (!window->isSafeScript(exec))
1708 // Do nothing for now. These are NS-specific legacy calls.
1710 case Window::AddEventListener: {
1711 if (!window->isSafeScript(exec))
1713 JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
1715 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
1717 docimpl->addWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
1721 case Window::RemoveEventListener: {
1722 if (!window->isSafeScript(exec))
1724 JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
1726 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
1728 docimpl->removeWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
1737 void Window::updateLayout() const
1739 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(m_part->document().handle());
1741 docimpl->updateLayoutIgnorePendingStylesheets();
1746 ////////////////////// ScheduledAction ////////////////////////
1748 ScheduledAction::ScheduledAction(Object _func, List _args, bool _singleShot)
1750 //kdDebug(6070) << "ScheduledAction::ScheduledAction(isFunction) " << this << endl;
1754 singleShot = _singleShot;
1757 ScheduledAction::ScheduledAction(const QString &_code, bool _singleShot)
1759 //kdDebug(6070) << "ScheduledAction::ScheduledAction(!isFunction) " << this << endl;
1764 singleShot = _singleShot;
1767 void ScheduledAction::execute(Window *window)
1769 ScriptInterpreter *interpreter = static_cast<ScriptInterpreter *>(KJSProxy::proxy(window->m_part)->interpreter());
1771 interpreter->setProcessingTimerCallback(true);
1773 //kdDebug(6070) << "ScheduledAction::execute " << this << endl;
1775 if (func.implementsCall()) {
1777 Q_ASSERT( window->m_part );
1778 if ( window->m_part )
1780 KJS::Interpreter *interpreter = KJSProxy::proxy( window->m_part )->interpreter();
1781 ExecState *exec = interpreter->globalExec();
1782 Q_ASSERT( window == interpreter->globalObject().imp() );
1783 Object obj( window );
1784 Interpreter::lock();
1785 func.call(exec,obj,args); // note that call() creates its own execution state for the func call
1786 Interpreter::unlock();
1787 if ( exec->hadException() ) {
1789 Interpreter::lock();
1790 char *message = exec->exception().toObject(exec).get(exec, messagePropertyName).toString(exec).ascii();
1791 int lineNumber = exec->exception().toObject(exec).get(exec, "line").toInt32(exec);
1792 Interpreter::unlock();
1793 if (Interpreter::shouldPrintExceptions()) {
1794 printf("(timer):%s\n", message);
1796 KWQ(window->m_part)->addMessageToConsole(message, lineNumber, QString());
1798 exec->clearException();
1804 window->m_part->executeScript(code);
1807 // Update our document's rendering following the execution of the timeout callback.
1808 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(window->m_part->document().handle());
1809 doc->updateRendering();
1811 interpreter->setProcessingTimerCallback(false);
1814 ScheduledAction::~ScheduledAction()
1816 //kdDebug(6070) << "ScheduledAction::~ScheduledAction " << this << endl;
1819 ////////////////////// WindowQObject ////////////////////////
1821 WindowQObject::WindowQObject(Window *w)
1824 //kdDebug(6070) << "WindowQObject::WindowQObject " << this << endl;
1825 part = parent->m_part;
1826 connect( parent->m_part, SIGNAL( destroyed() ),
1827 this, SLOT( parentDestroyed() ) );
1830 WindowQObject::~WindowQObject()
1832 //kdDebug(6070) << "WindowQObject::~WindowQObject " << this << endl;
1833 parentDestroyed(); // reuse same code
1836 void WindowQObject::parentDestroyed()
1838 //kdDebug(6070) << "WindowQObject::parentDestroyed " << this << " we have " << scheduledActions.count() << " actions in the map" << endl;
1840 QMapIterator<int,ScheduledAction*> it;
1841 for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) {
1842 ScheduledAction *action = *it;
1843 //kdDebug(6070) << "WindowQObject::parentDestroyed deleting action " << action << endl;
1846 scheduledActions.clear();
1849 int WindowQObject::installTimeout(const UString &handler, int t, bool singleShot)
1851 //kdDebug(6070) << "WindowQObject::installTimeout " << this << " " << handler.ascii() << endl;
1852 int id = startTimer(t);
1853 ScheduledAction *action = new ScheduledAction(handler.qstring(),singleShot);
1854 scheduledActions.insert(id, action);
1855 //kdDebug(6070) << this << " got id=" << id << " action=" << action << " - now having " << scheduledActions.count() << " actions"<<endl;
1859 int WindowQObject::installTimeout(const Value &func, List args, int t, bool singleShot)
1861 Object objFunc = Object::dynamicCast( func );
1862 int id = startTimer(t);
1863 scheduledActions.insert(id, new ScheduledAction(objFunc,args,singleShot));
1867 QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key)
1869 QMapIterator<int,ScheduledAction*> it;
1871 QMap<int, KJS::ScheduledAction*>*pausedActions = new QMap<int, KJS::ScheduledAction*>;
1872 for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) {
1873 int timerId = it.key();
1874 pauseTimer (timerId, key);
1875 pausedActions->insert(timerId, it.data());
1877 scheduledActions.clear();
1878 return pausedActions;
1881 void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key)
1883 QMapIterator<int,ScheduledAction*> it;
1884 for (it = sa->begin(); it != sa->end(); ++it) {
1885 int timerId = it.key();
1886 scheduledActions.insert(timerId, it.data());
1889 resumeTimers (key, this);
1892 void WindowQObject::clearTimeout(int timerId, bool delAction)
1894 //kdDebug(6070) << "WindowQObject::clearTimeout " << this << " timerId=" << timerId << " delAction=" << delAction << endl;
1897 QMapIterator<int,ScheduledAction*> it = scheduledActions.find(timerId);
1898 if (it != scheduledActions.end()) {
1899 ScheduledAction *action = *it;
1900 scheduledActions.remove(it);
1906 void WindowQObject::timerEvent(QTimerEvent *e)
1908 QMapIterator<int,ScheduledAction*> it = scheduledActions.find(e->timerId());
1909 if (it != scheduledActions.end()) {
1910 ScheduledAction *action = *it;
1911 bool singleShot = action->singleShot;
1912 //kdDebug(6070) << "WindowQObject::timerEvent " << this << " action=" << action << " singleShot:" << singleShot << endl;
1914 // remove single shots installed by setTimeout()
1917 clearTimeout(e->timerId(),false);
1918 scheduledActions.remove(it);
1921 if (!parent->part().isNull())
1922 action->execute(parent);
1924 // It is important to test singleShot and not action->singleShot here - the
1925 // action could have been deleted already if not single shot and if the
1926 // JS code called by execute() calls clearTimeout().
1930 kdWarning(6070) << "WindowQObject::timerEvent this=" << this << " timer " << e->timerId()
1931 << " not found (" << scheduledActions.count() << " actions in map)" << endl;
1934 void WindowQObject::timeoutClose()
1936 if (!parent->part().isNull())
1938 //kdDebug(6070) << "WindowQObject::timeoutClose -> closing window" << endl;
1939 delete parent->m_part;
1944 bool WindowQObject::hasTimeouts()
1946 return scheduledActions.count();
1950 Value FrameArray::get(ExecState *exec, const Identifier &p) const
1953 kdDebug(6070) << "FrameArray::get " << p.qstring() << " part=" << (void*)part << endl;
1958 QPtrList<KParts::ReadOnlyPart> frames = part->frames();
1959 unsigned int len = frames.count();
1960 if (p == lengthPropertyName)
1962 else if (p== "location") // non-standard property, but works in NS and IE
1964 Object obj = Object::dynamicCast( Window::retrieve( part ) );
1965 if ( !obj.isNull() )
1966 return obj.get( exec, "location" );
1970 // check for the name or number
1971 KParts::ReadOnlyPart *frame = part->findFrame(p.qstring());
1974 unsigned int i = p.toArrayIndex(&ok);
1976 frame = frames.at(i);
1979 // we are potentially fetching a reference to a another Window object here.
1980 // i.e. we may be accessing objects from another interpreter instance.
1981 // Therefore we have to be a bit careful with memory managment.
1982 if (frame && frame->inherits("KHTMLPart")) {
1983 KHTMLPart *khtml = static_cast<KHTMLPart*>(frame);
1984 return Window::retrieve(khtml);
1987 return ObjectImp::get(exec, p);
1990 UString FrameArray::toString(ExecState *) const
1992 return "[object FrameArray]";
1995 ////////////////////// Location Object ////////////////////////
1997 const ClassInfo Location::info = { "Location", 0, 0, 0 };
1999 @begin LocationTable 11
2000 hash Location::Hash DontDelete
2001 host Location::Host DontDelete
2002 hostname Location::Hostname DontDelete
2003 href Location::Href DontDelete
2004 pathname Location::Pathname DontDelete
2005 port Location::Port DontDelete
2006 protocol Location::Protocol DontDelete
2007 search Location::Search DontDelete
2008 [[==]] Location::EqualEqual DontDelete|ReadOnly
2009 toString Location::ToString DontDelete|Function 0
2010 replace Location::Replace DontDelete|Function 1
2011 reload Location::Reload DontDelete|Function 0
2014 IMPLEMENT_PROTOFUNC(LocationFunc)
2015 Location::Location(KHTMLPart *p) : m_part(p)
2017 //kdDebug(6070) << "Location::Location " << this << " m_part=" << (void*)m_part << endl;
2020 Location::~Location()
2022 //kdDebug(6070) << "Location::~Location " << this << " m_part=" << (void*)m_part << endl;
2025 Value Location::get(ExecState *exec, const Identifier &p) const
2028 kdDebug(6070) << "Location::get " << p.qstring() << " m_part=" << (void*)m_part << endl;
2031 if (m_part.isNull())
2034 const Window* window = Window::retrieveWindow(m_part);
2035 if (!window || !window->isSafeScript(exec))
2038 KURL url = m_part->url();
2039 const HashEntry *entry = Lookup::findEntry(&LocationTable, p);
2041 switch (entry->value) {
2043 return String( url.ref().isNull() ? QString("") : "#" + url.ref() );
2045 UString str = url.host();
2047 str += ":" + QString::number((int)url.port());
2049 // Note: this is the IE spec. The NS spec swaps the two, it says
2050 // "The hostname property is the concatenation of the host and port properties, separated by a colon."
2054 return String( url.host() );
2057 return String( url.prettyURL()+"/" );
2059 return String( url.prettyURL() );
2061 return String( url.path().isEmpty() ? QString("/") : url.path() );
2063 return String( url.port() ? QString::number((int)url.port()) : QString::fromLatin1("") );
2065 return String( url.protocol()+":" );
2067 return String( url.query() );
2068 case EqualEqual: // [[==]]
2069 return String(toString(exec));
2071 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2073 // Look for overrides
2074 ValueImp * val = ObjectImp::getDirect(p);
2078 switch (entry->value) {
2080 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2082 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2088 void Location::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2091 kdDebug(6070) << "Location::put " << p.qstring() << " m_part=" << (void*)m_part << endl;
2093 if (m_part.isNull())
2096 QString str = v.toString(exec).qstring();
2097 KURL url = m_part->url();
2098 const HashEntry *entry = Lookup::findEntry(&LocationTable, p);
2100 switch (entry->value) {
2102 KHTMLPart* p = Window::retrieveActive(exec)->part();
2104 url = p->htmlDocument().completeURL( str ).string();
2113 QString host = str.left(str.find(":"));
2114 QString port = str.mid(str.find(":")+1);
2116 url.setPort(port.toUInt());
2126 url.setPort(str.toUInt());
2129 url.setProtocol(str);
2136 ObjectImp::put(exec, p, v, attr);
2140 const Window* window = Window::retrieveWindow(m_part);
2141 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
2142 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2144 // We want a new history item if this JS was called via a user gesture
2145 m_part->scheduleLocationChange(url.url(), !userGesture, userGesture);
2147 m_part->scheduleLocationChange(url.url(), false /*don't lock history*/, userGesture);
2152 Value Location::toPrimitive(ExecState *exec, Type) const
2154 return String(toString(exec));
2157 UString Location::toString(ExecState *) const
2159 if (!m_part->url().hasPath())
2160 return m_part->url().prettyURL()+"/";
2162 return m_part->url().prettyURL();
2165 Value LocationFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2167 if (!thisObj.inherits(&Location::info)) {
2168 Object err = Error::create(exec,TypeError);
2169 exec->setException(err);
2172 Location *location = static_cast<Location *>(thisObj.imp());
2173 KHTMLPart *part = location->part();
2176 Window* window = Window::retrieveWindow(part);
2177 if (!window->isSafeScript(exec) && id != Location::Replace)
2181 case Location::Replace:
2183 QString str = args[0].toString(exec).qstring();
2184 KHTMLPart* p = Window::retrieveActive(exec)->part();
2186 const Window* window = Window::retrieveWindow(part);
2187 if (!str.startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
2188 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2189 part->scheduleLocationChange(p->htmlDocument().completeURL(str).string(), true /*lock history*/, userGesture);
2194 case Location::Reload:
2196 const Window* window = Window::retrieveWindow(part);
2197 if (!part->url().url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
2198 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2199 part->scheduleLocationChange(part->url().url(), true/*lock history*/, userGesture);
2203 case Location::ToString:
2204 return String(location->toString(exec));
2207 kdDebug(6070) << "LocationFunc::tryExecute - no part!" << endl;
2211 ////////////////////// Selection Object ////////////////////////
2213 const ClassInfo Selection::info = { "Selection", 0, 0, 0 };
2215 @begin SelectionTable 19
2216 anchorNode Selection::AnchorNode DontDelete|ReadOnly
2217 anchorOffset Selection::AnchorOffset DontDelete|ReadOnly
2218 focusNode Selection::FocusNode DontDelete|ReadOnly
2219 focusOffset Selection::FocusOffset DontDelete|ReadOnly
2220 baseNode Selection::AnchorNode DontDelete|ReadOnly
2221 baseOffset Selection::AnchorOffset DontDelete|ReadOnly
2222 extentNode Selection::FocusNode DontDelete|ReadOnly
2223 extentOffset Selection::FocusOffset DontDelete|ReadOnly
2224 isCollapsed Selection::IsCollapsed DontDelete|ReadOnly
2225 type Selection::_Type DontDelete|ReadOnly
2226 [[==]] Selection::EqualEqual DontDelete|ReadOnly
2227 toString Selection::ToString DontDelete|Function 0
2228 collapse Selection::Collapse DontDelete|Function 2
2229 collapseToEnd Selection::CollapseToEnd DontDelete|Function 0
2230 collapseToStart Selection::CollapseToStart DontDelete|Function 0
2231 empty Selection::Empty DontDelete|Function 0
2232 setBaseAndExtent Selection::SetBaseAndExtent DontDelete|Function 4
2233 setPosition Selection::SetPosition DontDelete|Function 2
2234 modify Selection::Modify DontDelete|Function 3
2237 IMPLEMENT_PROTOFUNC(SelectionFunc)
2238 Selection::Selection(KHTMLPart *p) : m_part(p)
2240 //kdDebug(6070) << "Selection::Selection " << this << " m_part=" << (void*)m_part << endl;
2243 Selection::~Selection()
2245 //kdDebug(6070) << "Selection::~Selection " << this << " m_part=" << (void*)m_part << endl;
2248 Value Selection::get(ExecState *exec, const Identifier &p) const
2251 kdDebug(6070) << "Selection::get " << p.qstring() << " m_part=" << (void*)m_part << endl;
2254 if (m_part.isNull())
2257 const Window* window = Window::retrieveWindow(m_part);
2258 if (!window || !window->isSafeScript(exec))
2261 DocumentImpl *docimpl = m_part->xmlDocImpl();
2263 docimpl->updateLayoutIgnorePendingStylesheets();
2265 KURL url = m_part->url();
2266 const HashEntry *entry = Lookup::findEntry(&SelectionTable, p);
2268 switch (entry->value) {
2271 return getDOMNode(exec, Node(m_part->selection().base().node()));
2274 return Number(m_part->selection().base().offset());
2277 return getDOMNode(exec, Node(m_part->selection().extent().node()));
2280 return Number(m_part->selection().extent().offset());
2282 return Boolean(!m_part->selection().isRange());
2284 switch (m_part->selection().state()) {
2285 case khtml::Selection::NONE:
2286 return String("None");
2287 case khtml::Selection::CARET:
2288 return String("Caret");
2289 case khtml::Selection::RANGE:
2290 return String("Range");
2294 return String(toString(exec));
2296 return lookupOrCreateFunction<SelectionFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2298 // Look for overrides
2299 ValueImp * val = ObjectImp::getDirect(p);
2303 switch (entry->value) {
2306 case CollapseToStart:
2308 case SetBaseAndExtent:
2311 return lookupOrCreateFunction<SelectionFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2317 void Selection::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2321 Value Selection::toPrimitive(ExecState *exec, Type) const
2323 return String(toString(exec));
2326 UString Selection::toString(ExecState *) const
2328 if (!m_part->selection().isRange())
2330 return UString(m_part->selection().toRange().toString());
2333 Value SelectionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2335 if (!thisObj.inherits(&Selection::info)) {
2336 Object err = Error::create(exec,TypeError);
2337 exec->setException(err);
2340 Selection *selection = static_cast<Selection *>(thisObj.imp());
2341 KHTMLPart *part = selection->part();
2343 DocumentImpl *docimpl = part->xmlDocImpl();
2345 docimpl->updateLayoutIgnorePendingStylesheets();
2348 case Selection::Collapse:
2349 TypingCommand::closeTyping(part->lastEditCommand());
2350 part->setSelection(khtml::Selection(Position(KJS::toNode(args[0]).handle(), args[1].toInt32(exec))));
2352 case Selection::CollapseToEnd:
2353 TypingCommand::closeTyping(part->lastEditCommand());
2354 part->setSelection(khtml::Selection(part->selection().end()));
2356 case Selection::CollapseToStart:
2357 TypingCommand::closeTyping(part->lastEditCommand());
2358 part->setSelection(khtml::Selection(part->selection().start()));
2360 case Selection::Empty:
2361 TypingCommand::closeTyping(part->lastEditCommand());
2362 part->clearSelection();
2364 case Selection::SetBaseAndExtent: {
2365 TypingCommand::closeTyping(part->lastEditCommand());
2366 Position base(KJS::toNode(args[0]).handle(), args[1].toInt32(exec));
2367 Position extent(KJS::toNode(args[2]).handle(), args[3].toInt32(exec));
2368 part->setSelection(khtml::Selection(base, extent));
2371 case Selection::SetPosition:
2372 TypingCommand::closeTyping(part->lastEditCommand());
2373 part->setSelection(khtml::Selection(Position(KJS::toNode(args[0]).handle(), args[1].toInt32(exec))));
2375 case Selection::Modify: {
2376 TypingCommand::closeTyping(part->lastEditCommand());
2377 khtml::Selection s(part->selection());
2378 khtml::Selection::EAlter alter = khtml::Selection::MOVE;
2379 if (args[0].toString(exec).string().lower() == "extend")
2380 alter = khtml::Selection::EXTEND;
2381 DOMString directionString = args[1].toString(exec).string().lower();
2382 khtml::Selection::EDirection direction = khtml::Selection::FORWARD;
2383 if (directionString == "backward")
2384 direction = khtml::Selection::BACKWARD;
2385 else if (directionString == "left")
2386 direction = khtml::Selection::LEFT;
2387 if (directionString == "right")
2388 direction = khtml::Selection::RIGHT;
2389 khtml::ETextGranularity granularity = khtml::CHARACTER;
2390 DOMString granularityString = args[2].toString(exec).string().lower();
2391 if (granularityString == "word")
2392 granularity = khtml::WORD;
2393 else if (granularityString == "line")
2394 granularity = khtml::LINE;
2395 else if (granularityString == "pargraph")
2396 granularity = khtml::PARAGRAPH;
2397 s.modify(alter, direction, granularity);
2398 part->setSelection(s);
2406 ////////////////////// BarInfo Object ////////////////////////
2408 const ClassInfo BarInfo::info = { "BarInfo", 0, 0, 0 };
2410 @begin BarInfoTable 1
2411 visible BarInfo::Visible DontDelete|ReadOnly
2414 BarInfo::BarInfo(ExecState *exec, KHTMLPart *p, Type barType)
2415 : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype())
2425 Value BarInfo::get(ExecState *exec, const Identifier &p) const
2427 if (m_part.isNull())
2430 const HashEntry *entry = Lookup::findEntry(&BarInfoTable, p);
2431 if (entry && entry->value == Visible) {
2435 return Boolean(KWQ(m_part)->locationbarVisible());
2439 return Boolean(KWQ(m_part)->locationbarVisible());
2443 return Boolean(KWQ(m_part)->personalbarVisible());
2447 return Boolean(KWQ(m_part)->scrollbarsVisible());
2451 return Boolean(KWQ(m_part)->statusbarVisible());
2455 return Boolean(KWQ(m_part)->toolbarVisible());
2458 return Boolean(false);
2465 void BarInfo::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2469 ////////////////////// History Object ////////////////////////
2471 const ClassInfo History::info = { "History", 0, 0, 0 };
2473 @begin HistoryTable 4
2474 length History::Length DontDelete|ReadOnly
2475 back History::Back DontDelete|Function 0
2476 forward History::Forward DontDelete|Function 0
2477 go History::Go DontDelete|Function 1
2480 IMPLEMENT_PROTOFUNC(HistoryFunc)
2482 Value History::get(ExecState *exec, const Identifier &p) const
2484 return lookupGet<HistoryFunc,History,ObjectImp>(exec,p,&HistoryTable,this);
2487 Value History::getValueProperty(ExecState *, int token) const
2492 KParts::BrowserExtension *ext = part->browserExtension();
2496 KParts::BrowserInterface *iface = ext->browserInterface();
2500 QVariant length = iface->property( "historyLength" );
2502 if ( length.type() != QVariant::UInt )
2505 return Number( length.toUInt() );
2508 kdWarning() << "Unhandled token in History::getValueProperty : " << token << endl;
2513 UString History::toString(ExecState *exec) const
2515 return "[object History]";
2518 Value HistoryFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2520 if (!thisObj.inherits(&History::info)) {
2521 Object err = Error::create(exec,TypeError);
2522 exec->setException(err);
2525 History *history = static_cast<History *>(thisObj.imp());
2532 case History::Forward:
2536 steps = args[0].toInt32(exec);
2542 history->part->scheduleHistoryNavigation(steps);
2546 /////////////////////////////////////////////////////////////////////////////
2550 const ClassInfo Konqueror::info = { "Konqueror", 0, 0, 0 };
2552 bool Konqueror::hasProperty(ExecState *exec, const Identifier &p) const
2554 if ( p.qstring().startsWith( "goHistory" ) ) return false;
2559 Value Konqueror::get(ExecState *exec, const Identifier &p) const
2561 if ( p == "goHistory" || part->url().protocol() != "http" || part->url().host() != "localhost" )
2564 KParts::BrowserExtension *ext = part->browserExtension();
2566 KParts::BrowserInterface *iface = ext->browserInterface();
2568 QVariant prop = iface->property( p.qstring().latin1() );
2570 if ( prop.isValid() ) {
2571 switch( prop.type() ) {
2573 return Number( prop.toInt() );
2574 case QVariant::String:
2575 return String( prop.toString() );
2583 return /*Function*/( new KonquerorFunc(this, p.qstring().latin1() ) );
2586 Value KonquerorFunc::tryCall(ExecState *exec, Object &, const List &args)
2588 KParts::BrowserExtension *ext = konqueror->part->browserExtension();
2593 KParts::BrowserInterface *iface = ext->browserInterface();
2598 QCString n = m_name.data();
2600 iface->callMethod( n.data(), QVariant() );
2605 UString Konqueror::toString(ExecState *) const
2607 return UString("[object Konqueror]");
2611 /////////////////////////////////////////////////////////////////////////////
2613 #include "kjs_window.moc"