File indexing completed on 2024-04-28 15:23:14

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (c) 2003 George Staikos (staikos@kde.org)
0004  *
0005  *  This library is free software; you can redistribute it and/or
0006  *  modify it under the terms of the GNU Library General Public
0007  *  License as published by the Free Software Foundation; either
0008  *  version 2 of the License, or (at your option) any later version.
0009  *
0010  *  This library is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  *  Library General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU Library General Public
0016  *  License along with this library; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #include "kjs_mozilla.h"
0021 #include "kjs_mozilla.lut.h"
0022 
0023 
0024 #include <klocalizedstring.h>
0025 #include "khtml_debug.h"
0026 
0027 #include <kjs/lookup.h>
0028 #include <khtml_part.h>
0029 
0030 using namespace KJS;
0031 
0032 namespace KJS
0033 {
0034 
0035 const ClassInfo MozillaSidebarExtension::info = { "sidebar", nullptr, &MozillaSidebarExtensionTable, nullptr };
0036 /*
0037 @begin MozillaSidebarExtensionTable 1
0038   addPanel  MozillaSidebarExtension::addPanel   DontDelete|Function 0
0039 @end
0040 */
0041 }
0042 KJS_IMPLEMENT_PROTOFUNC(MozillaSidebarExtensionFunc)
0043 
0044 MozillaSidebarExtension::MozillaSidebarExtension(ExecState *exec, KHTMLPart *p)
0045     : m_part(p)
0046 {
0047     setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
0048 }
0049 
0050 bool MozillaSidebarExtension::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot)
0051 {
0052 #ifdef KJS_VERBOSE
0053     qCDebug(KHTML_LOG) << "MozillaSidebarExtension::get " << propertyName.ascii();
0054 #endif
0055     return getStaticPropertySlot<MozillaSidebarExtensionFunc, MozillaSidebarExtension, JSObject>
0056            (exec, &MozillaSidebarExtensionTable, this, propertyName, slot);
0057 }
0058 
0059 JSValue *MozillaSidebarExtension::getValueProperty(ExecState *exec, int token) const
0060 {
0061     Q_UNUSED(exec);
0062     switch (token) {
0063     default:
0064         // qCDebug(KHTML_LOG) << "WARNING: Unhandled token in MozillaSidebarExtension::getValueProperty : " << token;
0065         return jsNull();
0066     }
0067 }
0068 
0069 JSValue *MozillaSidebarExtensionFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
0070 {
0071     KJS_CHECK_THIS(KJS::MozillaSidebarExtension, thisObj);
0072     MozillaSidebarExtension *mse = static_cast<MozillaSidebarExtension *>(thisObj);
0073 
0074     KHTMLPart *part = mse->part();
0075     if (!part) {
0076         return jsUndefined();
0077     }
0078 
0079     // addPanel()  id == 0
0080     KParts::BrowserExtension *ext = part->browserExtension();
0081     if (ext) {
0082         QString url, name;
0083         if (args.size() == 1) {  // I've seen this, don't know if it's legal.
0084             name.clear();
0085             url = args[0]->toString(exec).qstring();
0086         } else if (args.size() == 2 || args.size() == 3) {
0087             name = args[0]->toString(exec).qstring();
0088             url = args[1]->toString(exec).qstring();
0089             // 2 is the "CURL" which I don't understand and don't think we need.
0090         } else {
0091             return jsBoolean(false);
0092         }
0093         emit ext->addWebSideBar(QUrl(url), name);
0094         return jsBoolean(true);
0095     }
0096 
0097     return jsUndefined();
0098 }
0099