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.startsWith("javascript:", 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();
1457 const Window* window = Window::retrieveWindow(part);
1458 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
1459 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1460 part->scheduleLocationChange(url.url(), false/*don't lock history*/, userGesture);
1462 return Window::retrieve(part);
1464 if ( uargs.frameName == "_parent" )
1467 if ( part->parentPart() )
1468 part = part->parentPart();
1470 const Window* window = Window::retrieveWindow(part);
1471 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
1472 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1473 part->scheduleLocationChange(url.url(), false/*don't lock history*/, userGesture);
1475 return Window::retrieve(part);
1477 uargs.serviceType = "text/html";
1479 // request window (new or existing if framename is set)
1480 KParts::ReadOnlyPart *newPart = 0L;
1481 emit part->browserExtension()->createNewWindow("", uargs,winargs,newPart);
1482 if (newPart && newPart->inherits("KHTMLPart")) {
1483 KHTMLPart *khtmlpart = static_cast<KHTMLPart*>(newPart);
1484 //qDebug("opener set to %p (this Window's part) in new Window %p (this Window=%p)",part,win,window);
1485 khtmlpart->setOpener(part);
1486 khtmlpart->setOpenedByJS(true);
1488 if (khtmlpart->document().isNull()) {
1489 DocumentImpl *oldDoc = part->xmlDocImpl();
1490 if (oldDoc && oldDoc->baseURL() != 0)
1491 khtmlpart->begin(oldDoc->baseURL());
1495 khtmlpart->write("<HTML><BODY>");
1499 kdDebug(6070) << "Setting domain to " << oldDoc->domain().string() << endl;
1500 khtmlpart->xmlDocImpl()->setDomain( oldDoc->domain(), true );
1501 khtmlpart->xmlDocImpl()->setBaseURL( oldDoc->baseURL() );
1505 if (!url.isEmpty()) {
1506 const Window* window = Window::retrieveWindow(part);
1507 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
1508 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
1509 // FIXME: Need to pass referrer here.
1510 khtmlpart->scheduleLocationChange(url.url(), false, userGesture);
1514 uargs.serviceType = QString::null;
1515 if (uargs.frameName == "_blank")
1516 uargs.frameName = QString::null;
1518 // FIXME: need to pass referrer here
1519 emit khtmlpart->browserExtension()->openURLRequest(url,uargs);
1521 return Window::retrieve(khtmlpart); // global object
1531 case Window::ScrollBy:
1532 window->updateLayout();
1533 if(args.size() >= 2 && widget)
1534 widget->scrollBy(args[0].toInt32(exec), args[1].toInt32(exec));
1536 case Window::Scroll:
1537 case Window::ScrollTo:
1538 window->updateLayout();
1539 if(args.size() >= 2 && widget)
1540 widget->setContentsPos(args[0].toInt32(exec), args[1].toInt32(exec));
1542 case Window::MoveBy:
1543 if(args.size() >= 2 && widget)
1545 QWidget * tl = widget->topLevelWidget();
1546 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1547 QPoint dest = tl->pos() + QPoint( args[0].toInt32(exec), args[1].toInt32(exec) );
1548 // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1549 if ( dest.x() >= sg.x() && dest.y() >= sg.x() &&
1550 dest.x()+tl->width() <= sg.width()+sg.x() &&
1551 dest.y()+tl->height() <= sg.height()+sg.y() )
1555 case Window::MoveTo:
1556 if(args.size() >= 2 && widget)
1558 QWidget * tl = widget->topLevelWidget();
1559 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1560 QPoint dest( args[0].toInt32(exec)+sg.x(), args[1].toInt32(exec)+sg.y() );
1561 // Security check (the spec talks about UniversalBrowserWrite to disable this check...)
1562 if ( dest.x() >= sg.x() && dest.y() >= sg.y() &&
1563 dest.x()+tl->width() <= sg.width()+sg.x() &&
1564 dest.y()+tl->height() <= sg.height()+sg.y() )
1568 case Window::ResizeBy:
1569 if(args.size() >= 2 && widget)
1571 QWidget * tl = widget->topLevelWidget();
1572 QSize dest = tl->size() + QSize( args[0].toInt32(exec), args[1].toInt32(exec) );
1573 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1574 // Security check: within desktop limits and bigger than 100x100 (per spec)
1575 if ( tl->x()+dest.width() <= sg.x()+sg.width() &&
1576 tl->y()+dest.height() <= sg.y()+sg.height() &&
1577 dest.width() >= 100 && dest.height() >= 100 )
1579 // Take into account the window frame
1580 int deltaWidth = tl->frameGeometry().width() - tl->width();
1581 int deltaHeight = tl->frameGeometry().height() - tl->height();
1582 tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );
1586 case Window::ResizeTo:
1587 if(args.size() >= 2 && widget)
1589 QWidget * tl = widget->topLevelWidget();
1590 QSize dest = QSize( args[0].toInt32(exec), args[1].toInt32(exec) );
1591 QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));
1592 // Security check: within desktop limits and bigger than 100x100 (per spec)
1593 if ( tl->x()+dest.width() <= sg.x()+sg.width() &&
1594 tl->y()+dest.height() <= sg.y()+sg.height() &&
1595 dest.width() >= 100 && dest.height() >= 100 )
1597 // Take into account the window frame
1598 int deltaWidth = tl->frameGeometry().width() - tl->width();
1599 int deltaHeight = tl->frameGeometry().height() - tl->height();
1600 tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );
1604 case Window::SetTimeout:
1605 if (!window->isSafeScript(exec))
1607 if (args.size() >= 2 && v.isA(StringType)) {
1608 int i = args[1].toInt32(exec);
1609 int r = (const_cast<Window*>(window))->installTimeout(s, i, true /*single shot*/);
1612 else if (args.size() >= 2 && v.isA(ObjectType) && Object::dynamicCast(v).implementsCall()) {
1613 Value func = args[0];
1614 int i = args[1].toInt32(exec);
1616 // All arguments after the second should go to the function
1617 // FIXME: could be more efficient
1618 List funcArgs = args.copyTail().copyTail();
1620 int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, true /*single shot*/);
1625 case Window::SetInterval:
1626 if (!window->isSafeScript(exec))
1628 if (args.size() >= 2 && v.isA(StringType)) {
1629 int i = args[1].toInt32(exec);
1630 int r = (const_cast<Window*>(window))->installTimeout(s, i, false);
1633 else if (args.size() >= 2 && !Object::dynamicCast(v).isNull() &&
1634 Object::dynamicCast(v).implementsCall()) {
1635 Value func = args[0];
1636 int i = args[1].toInt32(exec);
1638 // All arguments after the second should go to the function
1639 // FIXME: could be more efficient
1640 List funcArgs = args.copyTail().copyTail();
1642 int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, false);
1647 case Window::ClearTimeout:
1648 case Window::ClearInterval:
1649 if (!window->isSafeScript(exec))
1651 (const_cast<Window*>(window))->clearTimeout(v.toInt32(exec));
1655 widget->setActiveWindow();
1657 case Window::GetSelection:
1658 if (!window->isSafeScript(exec))
1660 return Value(window->selection());
1663 KWQ(part)->unfocusWindow();
1669 /* From http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm :
1670 The close method closes only windows opened by JavaScript using the open method.
1671 If you attempt to close any other window, a confirm is generated, which
1672 lets the user choose whether the window closes.
1673 This is a security feature to prevent "mail bombs" containing self.close().
1674 However, if the window has only one document (the current one) in its
1675 session history, the close is allowed without any confirm. This is a
1676 special case for one-off windows that need to open other windows and
1677 then dispose of themselves.
1679 if (!part->openedByJS())
1681 // To conform to the SPEC, we only ask if the window
1682 // has more than one entry in the history (NS does that too).
1683 History history(exec,part);
1684 if ( history.get( exec, lengthPropertyName ).toInt32(exec) <= 1
1686 // FIXME: How are we going to handle this?
1688 || KMessageBox::questionYesNo( window->part()->view(), i18n("Close window?"), i18n("Confirmation Required") ) == KMessageBox::Yes
1691 (const_cast<Window*>(window))->scheduleClose();
1695 (const_cast<Window*>(window))->scheduleClose();
1698 case Window::CaptureEvents:
1699 case Window::ReleaseEvents:
1700 // If anyone implements these, they need the safescript security check.
1701 if (!window->isSafeScript(exec))
1704 // Do nothing for now. These are NS-specific legacy calls.
1706 case Window::AddEventListener: {
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->addWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
1717 case Window::RemoveEventListener: {
1718 if (!window->isSafeScript(exec))
1720 JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);
1722 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());
1724 docimpl->removeWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));
1733 void Window::updateLayout() const
1735 DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(m_part->document().handle());
1737 docimpl->updateLayoutIgnorePendingStylesheets();
1742 ////////////////////// ScheduledAction ////////////////////////
1744 ScheduledAction::ScheduledAction(Object _func, List _args, bool _singleShot)
1746 //kdDebug(6070) << "ScheduledAction::ScheduledAction(isFunction) " << this << endl;
1750 singleShot = _singleShot;
1753 ScheduledAction::ScheduledAction(const QString &_code, bool _singleShot)
1755 //kdDebug(6070) << "ScheduledAction::ScheduledAction(!isFunction) " << this << endl;
1760 singleShot = _singleShot;
1763 void ScheduledAction::execute(Window *window)
1765 ScriptInterpreter *interpreter = static_cast<ScriptInterpreter *>(KJSProxy::proxy(window->m_part)->interpreter());
1767 interpreter->setProcessingTimerCallback(true);
1769 //kdDebug(6070) << "ScheduledAction::execute " << this << endl;
1771 if (func.implementsCall()) {
1773 Q_ASSERT( window->m_part );
1774 if ( window->m_part )
1776 KJS::Interpreter *interpreter = KJSProxy::proxy( window->m_part )->interpreter();
1777 ExecState *exec = interpreter->globalExec();
1778 Q_ASSERT( window == interpreter->globalObject().imp() );
1779 Object obj( window );
1780 Interpreter::lock();
1781 func.call(exec,obj,args); // note that call() creates its own execution state for the func call
1782 Interpreter::unlock();
1783 if ( exec->hadException() ) {
1785 Interpreter::lock();
1786 char *message = exec->exception().toObject(exec).get(exec, messagePropertyName).toString(exec).ascii();
1787 int lineNumber = exec->exception().toObject(exec).get(exec, "line").toInt32(exec);
1788 Interpreter::unlock();
1789 if (Interpreter::shouldPrintExceptions()) {
1790 printf("(timer):%s\n", message);
1792 KWQ(window->m_part)->addMessageToConsole(message, lineNumber, QString());
1794 exec->clearException();
1800 window->m_part->executeScript(code);
1803 // Update our document's rendering following the execution of the timeout callback.
1804 DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(window->m_part->document().handle());
1805 doc->updateRendering();
1807 interpreter->setProcessingTimerCallback(false);
1810 ScheduledAction::~ScheduledAction()
1812 //kdDebug(6070) << "ScheduledAction::~ScheduledAction " << this << endl;
1815 ////////////////////// WindowQObject ////////////////////////
1817 WindowQObject::WindowQObject(Window *w)
1820 //kdDebug(6070) << "WindowQObject::WindowQObject " << this << endl;
1821 part = parent->m_part;
1822 connect( parent->m_part, SIGNAL( destroyed() ),
1823 this, SLOT( parentDestroyed() ) );
1826 WindowQObject::~WindowQObject()
1828 //kdDebug(6070) << "WindowQObject::~WindowQObject " << this << endl;
1829 parentDestroyed(); // reuse same code
1832 void WindowQObject::parentDestroyed()
1834 //kdDebug(6070) << "WindowQObject::parentDestroyed " << this << " we have " << scheduledActions.count() << " actions in the map" << endl;
1836 QMapIterator<int,ScheduledAction*> it;
1837 for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) {
1838 ScheduledAction *action = *it;
1839 //kdDebug(6070) << "WindowQObject::parentDestroyed deleting action " << action << endl;
1842 scheduledActions.clear();
1845 int WindowQObject::installTimeout(const UString &handler, int t, bool singleShot)
1847 //kdDebug(6070) << "WindowQObject::installTimeout " << this << " " << handler.ascii() << endl;
1848 int id = startTimer(t);
1849 ScheduledAction *action = new ScheduledAction(handler.qstring(),singleShot);
1850 scheduledActions.insert(id, action);
1851 //kdDebug(6070) << this << " got id=" << id << " action=" << action << " - now having " << scheduledActions.count() << " actions"<<endl;
1855 int WindowQObject::installTimeout(const Value &func, List args, int t, bool singleShot)
1857 Object objFunc = Object::dynamicCast( func );
1858 int id = startTimer(t);
1859 scheduledActions.insert(id, new ScheduledAction(objFunc,args,singleShot));
1863 QMap<int, ScheduledAction*> *WindowQObject::pauseTimeouts(const void *key)
1865 QMapIterator<int,ScheduledAction*> it;
1867 QMap<int, KJS::ScheduledAction*>*pausedActions = new QMap<int, KJS::ScheduledAction*>;
1868 for (it = scheduledActions.begin(); it != scheduledActions.end(); ++it) {
1869 int timerId = it.key();
1870 pauseTimer (timerId, key);
1871 pausedActions->insert(timerId, it.data());
1873 scheduledActions.clear();
1874 return pausedActions;
1877 void WindowQObject::resumeTimeouts(QMap<int, ScheduledAction*> *sa, const void *key)
1879 QMapIterator<int,ScheduledAction*> it;
1880 for (it = sa->begin(); it != sa->end(); ++it) {
1881 int timerId = it.key();
1882 scheduledActions.insert(timerId, it.data());
1885 resumeTimers (key, this);
1888 void WindowQObject::clearTimeout(int timerId, bool delAction)
1890 //kdDebug(6070) << "WindowQObject::clearTimeout " << this << " timerId=" << timerId << " delAction=" << delAction << endl;
1893 QMapIterator<int,ScheduledAction*> it = scheduledActions.find(timerId);
1894 if (it != scheduledActions.end()) {
1895 ScheduledAction *action = *it;
1896 scheduledActions.remove(it);
1902 void WindowQObject::timerEvent(QTimerEvent *e)
1904 QMapIterator<int,ScheduledAction*> it = scheduledActions.find(e->timerId());
1905 if (it != scheduledActions.end()) {
1906 ScheduledAction *action = *it;
1907 bool singleShot = action->singleShot;
1908 //kdDebug(6070) << "WindowQObject::timerEvent " << this << " action=" << action << " singleShot:" << singleShot << endl;
1910 // remove single shots installed by setTimeout()
1913 clearTimeout(e->timerId(),false);
1914 scheduledActions.remove(it);
1917 if (!parent->part().isNull())
1918 action->execute(parent);
1920 // It is important to test singleShot and not action->singleShot here - the
1921 // action could have been deleted already if not single shot and if the
1922 // JS code called by execute() calls clearTimeout().
1926 kdWarning(6070) << "WindowQObject::timerEvent this=" << this << " timer " << e->timerId()
1927 << " not found (" << scheduledActions.count() << " actions in map)" << endl;
1930 void WindowQObject::timeoutClose()
1932 if (!parent->part().isNull())
1934 //kdDebug(6070) << "WindowQObject::timeoutClose -> closing window" << endl;
1935 delete parent->m_part;
1940 bool WindowQObject::hasTimeouts()
1942 return scheduledActions.count();
1946 Value FrameArray::get(ExecState *exec, const Identifier &p) const
1949 kdDebug(6070) << "FrameArray::get " << p.qstring() << " part=" << (void*)part << endl;
1954 QPtrList<KParts::ReadOnlyPart> frames = part->frames();
1955 unsigned int len = frames.count();
1956 if (p == lengthPropertyName)
1958 else if (p== "location") // non-standard property, but works in NS and IE
1960 Object obj = Object::dynamicCast( Window::retrieve( part ) );
1961 if ( !obj.isNull() )
1962 return obj.get( exec, "location" );
1966 // check for the name or number
1967 KParts::ReadOnlyPart *frame = part->findFrame(p.qstring());
1970 unsigned int i = p.toArrayIndex(&ok);
1972 frame = frames.at(i);
1975 // we are potentially fetching a reference to a another Window object here.
1976 // i.e. we may be accessing objects from another interpreter instance.
1977 // Therefore we have to be a bit careful with memory managment.
1978 if (frame && frame->inherits("KHTMLPart")) {
1979 KHTMLPart *khtml = static_cast<KHTMLPart*>(frame);
1980 return Window::retrieve(khtml);
1983 return ObjectImp::get(exec, p);
1986 UString FrameArray::toString(ExecState *) const
1988 return "[object FrameArray]";
1991 ////////////////////// Location Object ////////////////////////
1993 const ClassInfo Location::info = { "Location", 0, 0, 0 };
1995 @begin LocationTable 11
1996 hash Location::Hash DontDelete
1997 host Location::Host DontDelete
1998 hostname Location::Hostname DontDelete
1999 href Location::Href DontDelete
2000 pathname Location::Pathname DontDelete
2001 port Location::Port DontDelete
2002 protocol Location::Protocol DontDelete
2003 search Location::Search DontDelete
2004 [[==]] Location::EqualEqual DontDelete|ReadOnly
2005 toString Location::ToString DontDelete|Function 0
2006 replace Location::Replace DontDelete|Function 1
2007 reload Location::Reload DontDelete|Function 0
2010 IMPLEMENT_PROTOFUNC(LocationFunc)
2011 Location::Location(KHTMLPart *p) : m_part(p)
2013 //kdDebug(6070) << "Location::Location " << this << " m_part=" << (void*)m_part << endl;
2016 Location::~Location()
2018 //kdDebug(6070) << "Location::~Location " << this << " m_part=" << (void*)m_part << endl;
2021 Value Location::get(ExecState *exec, const Identifier &p) const
2024 kdDebug(6070) << "Location::get " << p.qstring() << " m_part=" << (void*)m_part << endl;
2027 if (m_part.isNull())
2030 const Window* window = Window::retrieveWindow(m_part);
2031 if (!window || !window->isSafeScript(exec))
2034 KURL url = m_part->url();
2035 const HashEntry *entry = Lookup::findEntry(&LocationTable, p);
2037 switch (entry->value) {
2039 return String( url.ref().isNull() ? QString("") : "#" + url.ref() );
2041 UString str = url.host();
2043 str += ":" + QString::number((int)url.port());
2045 // Note: this is the IE spec. The NS spec swaps the two, it says
2046 // "The hostname property is the concatenation of the host and port properties, separated by a colon."
2050 return String( url.host() );
2053 return String( url.prettyURL()+"/" );
2055 return String( url.prettyURL() );
2057 return String( url.path().isEmpty() ? QString("/") : url.path() );
2059 return String( url.port() ? QString::number((int)url.port()) : QString::fromLatin1("") );
2061 return String( url.protocol()+":" );
2063 return String( url.query() );
2064 case EqualEqual: // [[==]]
2065 return String(toString(exec));
2067 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2069 // Look for overrides
2070 ValueImp * val = ObjectImp::getDirect(p);
2074 switch (entry->value) {
2076 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2078 return lookupOrCreateFunction<LocationFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2084 void Location::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2087 kdDebug(6070) << "Location::put " << p.qstring() << " m_part=" << (void*)m_part << endl;
2089 if (m_part.isNull())
2092 QString str = v.toString(exec).qstring();
2093 KURL url = m_part->url();
2094 const HashEntry *entry = Lookup::findEntry(&LocationTable, p);
2096 switch (entry->value) {
2098 KHTMLPart* p = Window::retrieveActive(exec)->part();
2100 url = p->htmlDocument().completeURL( str ).string();
2109 QString host = str.left(str.find(":"));
2110 QString port = str.mid(str.find(":")+1);
2112 url.setPort(port.toUInt());
2122 url.setPort(str.toUInt());
2125 url.setProtocol(str);
2132 ObjectImp::put(exec, p, v, attr);
2136 const Window* window = Window::retrieveWindow(m_part);
2137 if (!url.url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
2138 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2140 // We want a new history item if this JS was called via a user gesture
2141 m_part->scheduleLocationChange(url.url(), !userGesture, userGesture);
2143 m_part->scheduleLocationChange(url.url(), false /*don't lock history*/, userGesture);
2148 Value Location::toPrimitive(ExecState *exec, Type) const
2150 return String(toString(exec));
2153 UString Location::toString(ExecState *) const
2155 if (!m_part->url().hasPath())
2156 return m_part->url().prettyURL()+"/";
2158 return m_part->url().prettyURL();
2161 Value LocationFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2163 if (!thisObj.inherits(&Location::info)) {
2164 Object err = Error::create(exec,TypeError);
2165 exec->setException(err);
2168 Location *location = static_cast<Location *>(thisObj.imp());
2169 KHTMLPart *part = location->part();
2172 Window* window = Window::retrieveWindow(part);
2173 if (!window->isSafeScript(exec) && id != Location::Replace)
2177 case Location::Replace:
2179 QString str = args[0].toString(exec).qstring();
2180 KHTMLPart* p = Window::retrieveActive(exec)->part();
2182 const Window* window = Window::retrieveWindow(part);
2183 if (!str.startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
2184 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2185 part->scheduleLocationChange(p->htmlDocument().completeURL(str).string(), true /*lock history*/, userGesture);
2190 case Location::Reload:
2192 const Window* window = Window::retrieveWindow(part);
2193 if (!part->url().url().startsWith("javascript:", false) || (window && window->isSafeScript(exec))) {
2194 bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();
2195 part->scheduleLocationChange(part->url().url(), true/*lock history*/, userGesture);
2199 case Location::ToString:
2200 return String(location->toString(exec));
2203 kdDebug(6070) << "LocationFunc::tryExecute - no part!" << endl;
2207 ////////////////////// Selection Object ////////////////////////
2209 const ClassInfo Selection::info = { "Selection", 0, 0, 0 };
2211 @begin SelectionTable 19
2212 anchorNode Selection::AnchorNode DontDelete|ReadOnly
2213 anchorOffset Selection::AnchorOffset DontDelete|ReadOnly
2214 focusNode Selection::FocusNode DontDelete|ReadOnly
2215 focusOffset Selection::FocusOffset DontDelete|ReadOnly
2216 baseNode Selection::AnchorNode DontDelete|ReadOnly
2217 baseOffset Selection::AnchorOffset DontDelete|ReadOnly
2218 extentNode Selection::FocusNode DontDelete|ReadOnly
2219 extentOffset Selection::FocusOffset DontDelete|ReadOnly
2220 isCollapsed Selection::IsCollapsed DontDelete|ReadOnly
2221 type Selection::_Type DontDelete|ReadOnly
2222 [[==]] Selection::EqualEqual DontDelete|ReadOnly
2223 toString Selection::ToString DontDelete|Function 0
2224 collapse Selection::Collapse DontDelete|Function 2
2225 collapseToEnd Selection::CollapseToEnd DontDelete|Function 0
2226 collapseToStart Selection::CollapseToStart DontDelete|Function 0
2227 empty Selection::Empty DontDelete|Function 0
2228 setBaseAndExtent Selection::SetBaseAndExtent DontDelete|Function 4
2229 setPosition Selection::SetPosition DontDelete|Function 2
2230 modify Selection::Modify DontDelete|Function 3
2233 IMPLEMENT_PROTOFUNC(SelectionFunc)
2234 Selection::Selection(KHTMLPart *p) : m_part(p)
2236 //kdDebug(6070) << "Selection::Selection " << this << " m_part=" << (void*)m_part << endl;
2239 Selection::~Selection()
2241 //kdDebug(6070) << "Selection::~Selection " << this << " m_part=" << (void*)m_part << endl;
2244 Value Selection::get(ExecState *exec, const Identifier &p) const
2247 kdDebug(6070) << "Selection::get " << p.qstring() << " m_part=" << (void*)m_part << endl;
2250 if (m_part.isNull())
2253 const Window* window = Window::retrieveWindow(m_part);
2254 if (!window || !window->isSafeScript(exec))
2257 DocumentImpl *docimpl = m_part->xmlDocImpl();
2259 docimpl->updateLayoutIgnorePendingStylesheets();
2261 KURL url = m_part->url();
2262 const HashEntry *entry = Lookup::findEntry(&SelectionTable, p);
2264 switch (entry->value) {
2267 return getDOMNode(exec, Node(m_part->selection().base().node()));
2270 return Number(m_part->selection().base().offset());
2273 return getDOMNode(exec, Node(m_part->selection().extent().node()));
2276 return Number(m_part->selection().extent().offset());
2278 return Boolean(!m_part->selection().isRange());
2280 switch (m_part->selection().state()) {
2281 case khtml::Selection::NONE:
2282 return String("None");
2283 case khtml::Selection::CARET:
2284 return String("Caret");
2285 case khtml::Selection::RANGE:
2286 return String("Range");
2290 return String(toString(exec));
2292 return lookupOrCreateFunction<SelectionFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2294 // Look for overrides
2295 ValueImp * val = ObjectImp::getDirect(p);
2299 switch (entry->value) {
2302 case CollapseToStart:
2304 case SetBaseAndExtent:
2307 return lookupOrCreateFunction<SelectionFunc>(exec,p,this,entry->value,entry->params,entry->attr);
2313 void Selection::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2317 Value Selection::toPrimitive(ExecState *exec, Type) const
2319 return String(toString(exec));
2322 UString Selection::toString(ExecState *) const
2324 if (!m_part->selection().isRange())
2326 return UString(m_part->selection().toRange().toString());
2329 Value SelectionFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2331 if (!thisObj.inherits(&Selection::info)) {
2332 Object err = Error::create(exec,TypeError);
2333 exec->setException(err);
2336 Selection *selection = static_cast<Selection *>(thisObj.imp());
2337 KHTMLPart *part = selection->part();
2339 DocumentImpl *docimpl = part->xmlDocImpl();
2341 docimpl->updateLayoutIgnorePendingStylesheets();
2344 case Selection::Collapse:
2345 TypingCommand::closeTyping(part->lastEditCommand());
2346 part->setSelection(khtml::Selection(Position(KJS::toNode(args[0]).handle(), args[1].toInt32(exec))));
2348 case Selection::CollapseToEnd:
2349 TypingCommand::closeTyping(part->lastEditCommand());
2350 part->setSelection(khtml::Selection(part->selection().end()));
2352 case Selection::CollapseToStart:
2353 TypingCommand::closeTyping(part->lastEditCommand());
2354 part->setSelection(khtml::Selection(part->selection().start()));
2356 case Selection::Empty:
2357 TypingCommand::closeTyping(part->lastEditCommand());
2358 part->clearSelection();
2360 case Selection::SetBaseAndExtent: {
2361 TypingCommand::closeTyping(part->lastEditCommand());
2362 Position base(KJS::toNode(args[0]).handle(), args[1].toInt32(exec));
2363 Position extent(KJS::toNode(args[2]).handle(), args[3].toInt32(exec));
2364 part->setSelection(khtml::Selection(base, extent));
2367 case Selection::SetPosition:
2368 TypingCommand::closeTyping(part->lastEditCommand());
2369 part->setSelection(khtml::Selection(Position(KJS::toNode(args[0]).handle(), args[1].toInt32(exec))));
2371 case Selection::Modify: {
2372 TypingCommand::closeTyping(part->lastEditCommand());
2373 khtml::Selection s(part->selection());
2374 khtml::Selection::EAlter alter = khtml::Selection::MOVE;
2375 if (args[0].toString(exec).string().lower() == "extend")
2376 alter = khtml::Selection::EXTEND;
2377 DOMString directionString = args[1].toString(exec).string().lower();
2378 khtml::Selection::EDirection direction = khtml::Selection::FORWARD;
2379 if (directionString == "backward")
2380 direction = khtml::Selection::BACKWARD;
2381 else if (directionString == "left")
2382 direction = khtml::Selection::LEFT;
2383 if (directionString == "right")
2384 direction = khtml::Selection::RIGHT;
2385 khtml::ETextGranularity granularity = khtml::CHARACTER;
2386 DOMString granularityString = args[2].toString(exec).string().lower();
2387 if (granularityString == "word")
2388 granularity = khtml::WORD;
2389 else if (granularityString == "line")
2390 granularity = khtml::LINE;
2391 else if (granularityString == "pargraph")
2392 granularity = khtml::PARAGRAPH;
2393 s.modify(alter, direction, granularity);
2394 part->setSelection(s);
2402 ////////////////////// BarInfo Object ////////////////////////
2404 const ClassInfo BarInfo::info = { "BarInfo", 0, 0, 0 };
2406 @begin BarInfoTable 1
2407 visible BarInfo::Visible DontDelete|ReadOnly
2410 BarInfo::BarInfo(ExecState *exec, KHTMLPart *p, Type barType)
2411 : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype())
2421 Value BarInfo::get(ExecState *exec, const Identifier &p) const
2423 if (m_part.isNull())
2426 const HashEntry *entry = Lookup::findEntry(&BarInfoTable, p);
2427 if (entry && entry->value == Visible) {
2431 return Boolean(KWQ(m_part)->locationbarVisible());
2435 return Boolean(KWQ(m_part)->locationbarVisible());
2439 return Boolean(KWQ(m_part)->personalbarVisible());
2443 return Boolean(KWQ(m_part)->scrollbarsVisible());
2447 return Boolean(KWQ(m_part)->statusbarVisible());
2451 return Boolean(KWQ(m_part)->toolbarVisible());
2454 return Boolean(false);
2461 void BarInfo::put(ExecState *exec, const Identifier &p, const Value &v, int attr)
2465 ////////////////////// History Object ////////////////////////
2467 const ClassInfo History::info = { "History", 0, 0, 0 };
2469 @begin HistoryTable 4
2470 length History::Length DontDelete|ReadOnly
2471 back History::Back DontDelete|Function 0
2472 forward History::Forward DontDelete|Function 0
2473 go History::Go DontDelete|Function 1
2476 IMPLEMENT_PROTOFUNC(HistoryFunc)
2478 Value History::get(ExecState *exec, const Identifier &p) const
2480 return lookupGet<HistoryFunc,History,ObjectImp>(exec,p,&HistoryTable,this);
2483 Value History::getValueProperty(ExecState *, int token) const
2488 KParts::BrowserExtension *ext = part->browserExtension();
2492 KParts::BrowserInterface *iface = ext->browserInterface();
2496 QVariant length = iface->property( "historyLength" );
2498 if ( length.type() != QVariant::UInt )
2501 return Number( length.toUInt() );
2504 kdWarning() << "Unhandled token in History::getValueProperty : " << token << endl;
2509 UString History::toString(ExecState *exec) const
2511 return "[object History]";
2514 Value HistoryFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
2516 if (!thisObj.inherits(&History::info)) {
2517 Object err = Error::create(exec,TypeError);
2518 exec->setException(err);
2521 History *history = static_cast<History *>(thisObj.imp());
2528 case History::Forward:
2532 steps = args[0].toInt32(exec);
2538 history->part->scheduleHistoryNavigation(steps);
2542 /////////////////////////////////////////////////////////////////////////////
2546 const ClassInfo Konqueror::info = { "Konqueror", 0, 0, 0 };
2548 bool Konqueror::hasProperty(ExecState *exec, const Identifier &p) const
2550 if ( p.qstring().startsWith( "goHistory" ) ) return false;
2555 Value Konqueror::get(ExecState *exec, const Identifier &p) const
2557 if ( p == "goHistory" || part->url().protocol() != "http" || part->url().host() != "localhost" )
2560 KParts::BrowserExtension *ext = part->browserExtension();
2562 KParts::BrowserInterface *iface = ext->browserInterface();
2564 QVariant prop = iface->property( p.qstring().latin1() );
2566 if ( prop.isValid() ) {
2567 switch( prop.type() ) {
2569 return Number( prop.toInt() );
2570 case QVariant::String:
2571 return String( prop.toString() );
2579 return /*Function*/( new KonquerorFunc(this, p.qstring().latin1() ) );
2582 Value KonquerorFunc::tryCall(ExecState *exec, Object &, const List &args)
2584 KParts::BrowserExtension *ext = konqueror->part->browserExtension();
2589 KParts::BrowserInterface *iface = ext->browserInterface();
2594 QCString n = m_name.data();
2596 iface->callMethod( n.data(), QVariant() );
2601 UString Konqueror::toString(ExecState *) const
2603 return UString("[object Konqueror]");
2607 /////////////////////////////////////////////////////////////////////////////
2609 #include "kjs_window.moc"