[PATCH] window.external.addFavorite(url[,title])
Alexander Kellett
lypanov at kde.org
Thu Jul 10 22:32:05 BST 2003
here's a patch to add window.external.addFavorite(url[,title])
any comments?
cheers,
Alex
-------------- next part --------------
Index: khtml_part.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.h,v
retrieving revision 1.219
diff -u -p -B -w -r1.219 khtml_part.h
--- khtml_part.h 23 Jun 2003 02:31:24 -0000 1.219
+++ khtml_part.h 10 Jul 2003 21:25:00 -0000
@@ -82,6 +82,7 @@ namespace khtml
namespace KJS {
class Window;
class WindowFunc;
+ class ExternalFunc;
class JSEventListener;
class DOMDocument;
class SourceFile;
@@ -167,6 +168,7 @@ class KHTMLPart : public KParts::ReadOnl
friend class khtml::RenderPartObject;
friend class KJS::Window;
friend class KJS::WindowFunc;
+ friend class KJS::ExternalFunc;
friend class KJS::JSEventListener;
friend class KJS::DOMDocument;
friend class KJS::SourceFile;
Index: khtmlview.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.h,v
retrieving revision 1.180
diff -u -p -B -w -r1.180 khtmlview.h
--- khtmlview.h 17 May 2003 22:12:57 -0000 1.180
+++ khtmlview.h 10 Jul 2003 21:25:00 -0000
@@ -48,6 +48,7 @@ namespace DOM {
namespace KJS {
class WindowFunc;
+ class ExternalFunc;
}
namespace khtml {
@@ -90,6 +91,7 @@ class KHTMLView : public QScrollView
friend class khtml::CSSStyleSelector;
friend class khtml::LineEditWidget;
friend class KJS::WindowFunc;
+ friend class KJS::ExternalFunc;
friend void khtml::applyRule(DOM::CSSProperty *prop);
Index: ecma/kjs_window.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.cpp,v
retrieving revision 1.342
diff -u -p -B -w -r1.342 kjs_window.cpp
--- ecma/kjs_window.cpp 26 Jun 2003 22:34:55 -0000 1.342
+++ ecma/kjs_window.cpp 10 Jul 2003 21:25:01 -0000
@@ -31,6 +31,7 @@
#include <kparts/browserinterface.h>
#include <kwin.h>
#include <kwinmodule.h>
+#include <kbookmarkmanager.h>
#include <kglobalsettings.h>
#include <assert.h>
#include <qstyle.h>
@@ -58,8 +59,6 @@ using namespace KJS;
namespace KJS {
-////////////////////// History Object ////////////////////////
-
class History : public ObjectImp {
friend class HistoryFunc;
public:
@@ -74,6 +73,19 @@ namespace KJS {
QGuardedPtr<KHTMLPart> part;
};
+ class External : public ObjectImp {
+ friend class ExternalFunc;
+ public:
+ External(ExecState *exec, KHTMLPart *p)
+ : ObjectImp(exec->interpreter()->builtinObjectPrototype()), part(p) { }
+ virtual Value get(ExecState *exec, const Identifier &propertyName) const;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+ enum { AddFavorite };
+ private:
+ QGuardedPtr<KHTMLPart> part;
+ };
+
class FrameArray : public ObjectImp {
public:
FrameArray(ExecState *exec, KHTMLPart *p)
@@ -187,6 +199,7 @@ const ClassInfo Window::info = { "Window
CSSRule Window::CSSRule DontDelete
frames Window::Frames DontDelete|ReadOnly
history Window::_History DontDelete|ReadOnly
+ external Window::_External DontDelete|ReadOnly
event Window::Event DontDelete|ReadOnly
innerHeight Window::InnerHeight DontDelete|ReadOnly
innerWidth Window::InnerWidth DontDelete|ReadOnly
@@ -270,7 +283,7 @@ const ClassInfo Window::info = { "Window
IMPLEMENT_PROTOFUNC_DOM(WindowFunc)
Window::Window(KHTMLPart *p)
- : ObjectImp(/*no proto*/), m_part(p), screen(0), history(0), m_frames(0), loc(0), m_evt(0)
+ : ObjectImp(/*no proto*/), m_part(p), screen(0), history(0), external(0), m_frames(0), loc(0), m_evt(0)
{
winq = new WindowQObject(this);
//kdDebug(6070) << "Window::Window this=" << this << " part=" << m_part << " " << m_part->name() << endl;
@@ -348,6 +361,8 @@ void Window::mark()
screen->mark();
if (history && !history->marked())
history->mark();
+ if (external && !external->marked())
+ external->mark();
if (m_frames && !m_frames->marked())
m_frames->mark();
//kdDebug(6070) << "Window::mark " << this << " marking loc=" << loc << endl;
@@ -483,6 +498,10 @@ Value Window::get(ExecState *exec, const
return Value(history ? history :
(const_cast<Window*>(this)->history = new History(exec,m_part)));
+ case _External:
+ return Value(external ? external :
+ (const_cast<Window*>(this)->external = new External(exec,m_part)));
+
case Event:
if (m_evt)
return getDOMEvent(exec,*m_evt);
@@ -1937,6 +1956,66 @@ Value LocationFunc::tryCall(ExecState *e
case Location::ToString:
return String(location->toString(exec));
}
+ return Undefined();
+}
+
+////////////////////// External Object ////////////////////////
+
+const ClassInfo External::info = { "External", 0, 0, 0 };
+/*
+ at begin ExternalTable 4
+ addFavorite External::AddFavorite DontDelete|Function 1
+ at end
+*/
+IMPLEMENT_PROTOFUNC_DOM(ExternalFunc)
+
+Value External::get(ExecState *exec, const Identifier &p) const
+{
+ return lookupGetFunction<ExternalFunc,ObjectImp>(exec,p,&ExternalTable,this);
+}
+
+Value ExternalFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
+{
+ KJS_CHECK_THIS( External, thisObj );
+ External *external = static_cast<External *>(thisObj.imp());
+
+ KHTMLPart *part = external->part;
+ if (!part)
+ return Undefined();
+
+ KHTMLView *widget = part->view();
+
+ switch (id) {
+ case External::AddFavorite:
+ {
+ if (!widget->dialogsAllowed())
+ return Undefined();
+ part->xmlDocImpl()->updateRendering();
+ if (args.size() != 1 && args.size() != 2)
+ return Undefined();
+
+ QString url = args[0].toString(exec).qstring();
+ QString title;
+ if (args.size() == 2)
+ title = args[1].toString(exec).qstring();
+
+ QString question =
+ i18n("Should a bookmark pointed to the location \"%1\" %2 to your collection?")
+ .arg(url).arg(title.isEmpty()?"":i18n("titled \"%2\"").arg(title));
+ if (KMessageBox::warningYesNo(
+ widget, question,
+ "JavaScript Attempted Bookmark Insert",
+ i18n("Insert"), i18n("Disallow")) == KMessageBox::Yes)
+ {
+ KBookmarkManager *mgr = KBookmarkManager::userBookmarksManager();
+ mgr->addBookmarkDialog(url,title);
+ }
+ break;
+ }
+ default:
+ return Undefined();
+ }
+
return Undefined();
}
Index: ecma/kjs_window.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.h,v
retrieving revision 1.98
diff -u -p -B -w -r1.98 kjs_window.h
--- ecma/kjs_window.h 17 May 2003 22:12:58 -0000 1.98
+++ ecma/kjs_window.h 10 Jul 2003 21:25:02 -0000
@@ -40,6 +40,7 @@ namespace KJS {
class WindowQObject;
class Location;
class History;
+ class External;
class FrameArray;
class JSEventListener;
@@ -115,7 +116,7 @@ namespace KJS {
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
- NodeFilter, DOMException, CSSRule, Frames, _History, Event, InnerHeight,
+ NodeFilter, DOMException, CSSRule, Frames, _History, _External, Event, InnerHeight,
InnerWidth, Length, _Location, Name, _Navigator, _Konqueror, ClientInformation,
OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
@@ -144,6 +145,7 @@ namespace KJS {
QGuardedPtr<KHTMLPart> m_part;
Screen *screen;
History *history;
+ External *external;
FrameArray *m_frames;
Location *loc;
DOM::Event *m_evt;
Index: ecma/kjs_window.lut.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.lut.h,v
retrieving revision 1.13
diff -u -p -B -w -r1.13 kjs_window.lut.h
--- ecma/kjs_window.lut.h 11 Mar 2003 14:48:28 -0000 1.13
+++ ecma/kjs_window.lut.h 10 Jul 2003 21:25:02 -0000
@@ -110,7 +110,7 @@ static const struct HashEntry WindowTabl
{ "onunload", Window::Onunload, DontDelete, 0, 0 },
{ "onmousemove", Window::Onmousemove, DontDelete, 0, 0 },
{ "addEventListener", Window::AddEventListener, DontDelete|Function, 3, &WindowTableEntries[107] },
- { 0, 0, 0, 0, 0 },
+ { "external", Window::_External, DontDelete|ReadOnly, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ "open", Window::Open, DontDelete|Function, 3, 0 },
{ "defaultstatus", Window::DefaultStatus, DontDelete, 0, &WindowTableEntries[95] },
@@ -171,6 +171,21 @@ static const struct HashEntry LocationTa
};
static const struct HashTable LocationTable = { 2, 16, LocationTableEntries, 11 };
+
+} // namespace
+
+using namespace KJS;
+
+namespace KJS {
+
+static const struct HashEntry ExternalTableEntries[] = {
+ { 0, 0, 0, 0, 0 },
+ { "addFavorite", External::AddFavorite, DontDelete|Function, 1, 0 },
+ { 0, 0, 0, 0, 0 },
+ { 0, 0, 0, 0, 0 }
+};
+
+static const struct HashTable ExternalTable = { 2, 4, ExternalTableEntries, 4 };
} // namespace
More information about the kfm-devel
mailing list