TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kjs_navigator.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. // -*- c-basic-offset: 2 -*-
  2. /*
  3. * This file is part of the KDE libraries
  4. * Copyright (C) 2000 Harri Porten (porten@kde.org)
  5. * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org)
  6. * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org)
  7. * Copyright (C) 2003 Apple Computer, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Library General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Library General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Library General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <klocale.h>
  24. #include <kstandarddirs.h>
  25. #include <tdeconfig.h>
  26. #include <kdebug.h>
  27. #include <tdeio/kprotocolmanager.h>
  28. #include <tdeio/kmimetype.h>
  29. #include <tdeio/kservice.h>
  30. #include <tdeio/ktrader.h>
  31. #include "kjs_navigator.h"
  32. #include "kjs/lookup.h"
  33. #include "kjs_binding.h"
  34. #include "tdehtml_part.h"
  35. #include <sys/utsname.h>
  36. #include "kjs_navigator.lut.h"
  37. using namespace KJS;
  38. namespace KJS {
  39. // All objects that need plugin info must inherit from PluginBase
  40. // Its ctor and dtor take care of the refcounting on the static lists.
  41. class PluginBase : public ObjectImp {
  42. public:
  43. PluginBase(ExecState *exec, bool loadPluginInfo);
  44. virtual ~PluginBase();
  45. struct MimeClassInfo;
  46. struct PluginInfo;
  47. struct MimeClassInfo {
  48. TQString type;
  49. TQString desc;
  50. TQString suffixes;
  51. PluginInfo *plugin;
  52. };
  53. struct PluginInfo {
  54. TQString name;
  55. TQString file;
  56. TQString desc;
  57. TQPtrList<MimeClassInfo> mimes;
  58. };
  59. static TQPtrList<PluginInfo> *plugins;
  60. static TQPtrList<MimeClassInfo> *mimes;
  61. private:
  62. static int m_refCount;
  63. };
  64. class Plugins : public PluginBase {
  65. public:
  66. Plugins(ExecState *exec, bool pluginsEnabled)
  67. : PluginBase(exec, pluginsEnabled),
  68. m_pluginsEnabled(pluginsEnabled) {};
  69. virtual Value get(ExecState *exec, const Identifier &propertyName) const;
  70. Value getValueProperty(ExecState *exec, int token) const;
  71. virtual const ClassInfo* classInfo() const { return &info; }
  72. static const ClassInfo info;
  73. Value pluginByName( ExecState* exec, const TQString& name ) const;
  74. bool pluginsEnabled() const { return m_pluginsEnabled; };
  75. private:
  76. bool m_pluginsEnabled;
  77. };
  78. class MimeTypes : public PluginBase {
  79. public:
  80. MimeTypes(ExecState *exec, bool pluginsEnabled)
  81. : PluginBase(exec, pluginsEnabled),
  82. m_pluginsEnabled(pluginsEnabled) {};
  83. virtual Value get(ExecState *exec, const Identifier &propertyName) const;
  84. virtual const ClassInfo* classInfo() const { return &info; }
  85. static const ClassInfo info;
  86. Value getValueProperty(ExecState *exec, int token) const;
  87. Value mimeTypeByName( ExecState* exec, const TQString& name ) const;
  88. bool pluginsEnabled() const { return m_pluginsEnabled; };
  89. private:
  90. bool m_pluginsEnabled;
  91. };
  92. class Plugin : public PluginBase {
  93. public:
  94. Plugin( ExecState *exec, PluginBase::PluginInfo *info )
  95. : PluginBase( exec, true )
  96. { m_info = info; };
  97. virtual Value get(ExecState *exec, const Identifier &propertyName) const;
  98. virtual const ClassInfo* classInfo() const { return &info; }
  99. static const ClassInfo info;
  100. Value mimeByName(ExecState* exec, const TQString& name ) const;
  101. Value getValueProperty(ExecState *exec, int token) const;
  102. PluginBase::PluginInfo *pluginInfo() const { return m_info; }
  103. private:
  104. PluginBase::PluginInfo *m_info;
  105. };
  106. class MimeType : public PluginBase {
  107. public:
  108. MimeType( ExecState *exec, PluginBase::MimeClassInfo *info )
  109. : PluginBase( exec, true )
  110. { m_info = info; };
  111. virtual Value get(ExecState *exec, const Identifier &propertyName) const;
  112. virtual const ClassInfo* classInfo() const { return &info; }
  113. static const ClassInfo info;
  114. Value getValueProperty(ExecState *exec, int token) const;
  115. private:
  116. PluginBase::MimeClassInfo *m_info;
  117. };
  118. }
  119. TQPtrList<PluginBase::PluginInfo> *KJS::PluginBase::plugins = 0;
  120. TQPtrList<PluginBase::MimeClassInfo> *KJS::PluginBase::mimes = 0;
  121. int KJS::PluginBase::m_refCount = 0;
  122. const ClassInfo Navigator::info = { "Navigator", 0, &NavigatorTable, 0 };
  123. /*
  124. @begin NavigatorTable 12
  125. appCodeName Navigator::AppCodeName DontDelete|ReadOnly
  126. appName Navigator::AppName DontDelete|ReadOnly
  127. appVersion Navigator::AppVersion DontDelete|ReadOnly
  128. language Navigator::Language DontDelete|ReadOnly
  129. userAgent Navigator::UserAgent DontDelete|ReadOnly
  130. userLanguage Navigator::UserLanguage DontDelete|ReadOnly
  131. browserLanguage Navigator::BrowserLanguage DontDelete|ReadOnly
  132. platform Navigator::Platform DontDelete|ReadOnly
  133. cpuClass Navigator::CpuClass DontDelete|ReadOnly
  134. plugins Navigator::_Plugins DontDelete|ReadOnly
  135. mimeTypes Navigator::_MimeTypes DontDelete|ReadOnly
  136. product Navigator::Product DontDelete|ReadOnly
  137. vendor Navigator::Vendor DontDelete|ReadOnly
  138. productSub Navigator::ProductSub DontDelete|ReadOnly
  139. cookieEnabled Navigator::CookieEnabled DontDelete|ReadOnly
  140. javaEnabled Navigator::JavaEnabled DontDelete|Function 0
  141. @end
  142. */
  143. IMPLEMENT_PROTOFUNC_DOM(NavigatorFunc)
  144. Navigator::Navigator(ExecState *exec, TDEHTMLPart *p)
  145. : ObjectImp(exec->interpreter()->builtinObjectPrototype()), m_part(p) { }
  146. Value Navigator::get(ExecState *exec, const Identifier &propertyName) const
  147. {
  148. #ifdef KJS_VERBOSE
  149. kdDebug(6070) << "Navigator::get " << propertyName.ascii() << endl;
  150. #endif
  151. return lookupGet<NavigatorFunc,Navigator,ObjectImp>(exec,propertyName,&NavigatorTable,this);
  152. }
  153. Value Navigator::getValueProperty(ExecState *exec, int token) const
  154. {
  155. KURL url = m_part->url();
  156. TQString userAgent = url.host();
  157. if (userAgent.isEmpty())
  158. userAgent = "localhost";
  159. userAgent = KProtocolManager::userAgentForHost(userAgent);
  160. switch (token) {
  161. case AppCodeName:
  162. return String("Mozilla");
  163. case AppName:
  164. // If we find "Mozilla" but not "(compatible, ...)" we are a real Netscape
  165. if (userAgent.find(TQString::fromLatin1("Mozilla")) >= 0 &&
  166. userAgent.find(TQString::fromLatin1("compatible")) == -1)
  167. {
  168. //kdDebug() << "appName -> Mozilla" << endl;
  169. return String("Netscape");
  170. }
  171. if (userAgent.find(TQString::fromLatin1("Microsoft")) >= 0 ||
  172. userAgent.find(TQString::fromLatin1("MSIE")) >= 0)
  173. {
  174. //kdDebug() << "appName -> IE" << endl;
  175. return String("Microsoft Internet Explorer");
  176. }
  177. //kdDebug() << "appName -> Konqueror" << endl;
  178. return String("Konqueror");
  179. case AppVersion:
  180. // We assume the string is something like Mozilla/version (properties)
  181. return String(userAgent.mid(userAgent.find('/') + 1));
  182. case Product:
  183. // We are pretending to be Mozilla or Safari
  184. if (userAgent.find(TQString::fromLatin1("Mozilla")) >= 0 &&
  185. userAgent.find(TQString::fromLatin1("compatible")) == -1)
  186. {
  187. return String("Gecko");
  188. }
  189. // When spoofing as IE, we use Undefined().
  190. if (userAgent.find(TQString::fromLatin1("Microsoft")) >= 0 ||
  191. userAgent.find(TQString::fromLatin1("MSIE")) >= 0)
  192. {
  193. return Undefined();
  194. }
  195. // We are acting straight
  196. return String("Konqueror/tdehtml");
  197. case ProductSub:
  198. {
  199. int ix = userAgent.find("Gecko");
  200. if (ix >= 0 && userAgent.length() >= (uint)ix+14 && userAgent.unicode()[ix+5] == TQChar('/') &&
  201. userAgent.find(TQRegExp("\\d{8}"), ix+6) == ix+6)
  202. {
  203. // We have Gecko/<productSub> in the UA string
  204. return String(userAgent.mid(ix+6, 8));
  205. }
  206. else if (ix >= 0)
  207. {
  208. return String("20040107");
  209. }
  210. }
  211. return Undefined();
  212. case Vendor:
  213. return String("KDE");
  214. case BrowserLanguage:
  215. case Language:
  216. case UserLanguage:
  217. return String(TDEGlobal::locale()->language());
  218. case UserAgent:
  219. return String(userAgent);
  220. case Platform:
  221. // yet another evil hack, but necessary to spoof some sites...
  222. if ( (userAgent.find(TQString::fromLatin1("Win"),0,false)>=0) )
  223. return String(TQString::fromLatin1("Win32"));
  224. else if ( (userAgent.find(TQString::fromLatin1("Macintosh"),0,false)>=0) ||
  225. (userAgent.find(TQString::fromLatin1("Mac_PowerPC"),0,false)>=0) )
  226. return String(TQString::fromLatin1("MacPPC"));
  227. else
  228. {
  229. struct utsname name;
  230. int ret = uname(&name);
  231. if ( ret >= 0 )
  232. return String(TQString(TQString::fromLatin1("%1 %1 X11").arg(name.sysname).arg(name.machine)));
  233. else // can't happen
  234. return String(TQString(TQString::fromLatin1("Unix X11")));
  235. }
  236. case CpuClass:
  237. {
  238. struct utsname name;
  239. int ret = uname(&name);
  240. if ( ret >= 0 )
  241. return String(name.machine);
  242. else // can't happen
  243. return String("x86");
  244. }
  245. case _Plugins:
  246. return Value(new Plugins(exec, m_part->pluginsEnabled()));
  247. case _MimeTypes:
  248. return Value(new MimeTypes(exec, m_part->pluginsEnabled()));
  249. case CookieEnabled:
  250. return Boolean(true); /// ##### FIXME
  251. default:
  252. kdDebug(6070) << "WARNING: Unhandled token in DOMEvent::getValueProperty : " << token << endl;
  253. return Value();
  254. }
  255. }
  256. /*******************************************************************/
  257. PluginBase::PluginBase(ExecState *exec, bool loadPluginInfo)
  258. : ObjectImp(exec->interpreter()->builtinObjectPrototype() )
  259. {
  260. if ( loadPluginInfo && !plugins ) {
  261. plugins = new TQPtrList<PluginInfo>;
  262. mimes = new TQPtrList<MimeClassInfo>;
  263. plugins->setAutoDelete( true );
  264. mimes->setAutoDelete( true );
  265. // read in using TDETrader
  266. TDETrader::OfferList offers = TDETrader::self()->query("Browser/View");
  267. TDETrader::OfferList::iterator it;
  268. for ( it = offers.begin(); it != offers.end(); ++it ) {
  269. TQVariant pluginsinfo = (**it).property( "X-TDE-BrowserView-PluginsInfo" );
  270. if ( !pluginsinfo.isValid() ) {
  271. // <backwards compatible>
  272. if ((**it).library() == TQString("libnsplugin"))
  273. pluginsinfo = TQVariant("nsplugins/pluginsinfo");
  274. else
  275. // </backwards compatible>
  276. continue;
  277. }
  278. // read configuration
  279. TDEConfig kc( locate ("data", pluginsinfo.toString()) );
  280. unsigned num = (unsigned int) kc.readNumEntry("number");
  281. for ( unsigned n = 0; n < num; n++ ) {
  282. kc.setGroup( TQString::number(n) );
  283. PluginInfo *plugin = new PluginInfo;
  284. plugin->name = kc.readEntry("name");
  285. plugin->file = kc.readPathEntry("file");
  286. plugin->desc = kc.readEntry("description");
  287. plugins->append( plugin );
  288. // get mime types from string
  289. TQStringList types = TQStringList::split( ';', kc.readEntry("mime") );
  290. TQStringList::Iterator type;
  291. for ( type=types.begin(); type!=types.end(); ++type ) {
  292. // get mime information
  293. TQStringList tokens = TQStringList::split(':', *type, true);
  294. if ( tokens.count() < 3 ) // we need 3 items
  295. continue;
  296. MimeClassInfo *mime = new MimeClassInfo;
  297. TQStringList::Iterator token = tokens.begin();
  298. mime->type = (*token).lower();
  299. //kdDebug(6070) << "mime->type=" << mime->type << endl;
  300. ++token;
  301. mime->suffixes = *token;
  302. ++token;
  303. mime->desc = *token;
  304. ++token;
  305. mime->plugin = plugin;
  306. mimes->append( mime );
  307. plugin->mimes.append( mime );
  308. }
  309. }
  310. }
  311. }
  312. m_refCount++;
  313. }
  314. PluginBase::~PluginBase()
  315. {
  316. m_refCount--;
  317. if ( m_refCount==0 ) {
  318. delete plugins;
  319. delete mimes;
  320. plugins = 0;
  321. mimes = 0;
  322. }
  323. }
  324. /*******************************************************************/
  325. const ClassInfo Plugins::info = { "PluginArray", 0, &PluginsTable, 0 };
  326. /*
  327. @begin PluginsTable 4
  328. length Plugins_Length DontDelete|ReadOnly
  329. refresh Plugins_Refresh DontDelete|Function 0
  330. item Plugins_Item DontDelete|Function 1
  331. namedItem Plugins_NamedItem DontDelete|Function 1
  332. @end
  333. */
  334. IMPLEMENT_PROTOFUNC_DOM(PluginsFunc)
  335. Value Plugins::get(ExecState *exec, const Identifier &propertyName) const
  336. {
  337. #ifdef KJS_VERBOSE
  338. kdDebug(6070) << "Plugins::get " << propertyName.qstring() << endl;
  339. #endif
  340. if (!pluginsEnabled()) {
  341. if (propertyName == lengthPropertyName )
  342. return Number(0);
  343. } else {
  344. if ( propertyName == lengthPropertyName )
  345. return Number(plugins->count());
  346. // plugins[#]
  347. bool ok;
  348. unsigned int i = propertyName.toULong(&ok);
  349. if( ok && i<plugins->count() )
  350. return Value( new Plugin( exec, plugins->at(i) ) );
  351. // plugin[name]
  352. Value val = pluginByName( exec, propertyName.qstring() );
  353. if (!val.isA(UndefinedType))
  354. return val;
  355. }
  356. return lookupGet<PluginsFunc,Plugins,ObjectImp>(exec,propertyName,&PluginsTable,this);
  357. }
  358. Value Plugins::pluginByName( ExecState* exec, const TQString& name ) const
  359. {
  360. Q_ASSERT(plugins);
  361. for ( PluginInfo *pl = plugins->first(); pl!=0; pl = plugins->next() ) {
  362. if ( pl->name == name )
  363. return Value( new Plugin( exec, pl ) );
  364. }
  365. return Undefined();
  366. }
  367. Value Plugins::getValueProperty(ExecState* /*exec*/, int token) const
  368. {
  369. kdDebug(6070) << "WARNING: Unhandled token in Plugins::getValueProperty : " << token << endl;
  370. return Undefined();
  371. }
  372. Value PluginsFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
  373. {
  374. KJS_CHECK_THIS( KJS::Plugins, thisObj );
  375. KJS::Plugins* base = static_cast<KJS::Plugins *>(thisObj.imp());
  376. if (!base->pluginsEnabled()) {
  377. if (id == Plugins_Refresh || //## TODO
  378. id == Plugins_Item ||
  379. id == Plugins_NamedItem)
  380. return Undefined();
  381. } else {
  382. switch( id ) {
  383. case Plugins_Refresh:
  384. return Undefined(); //## TODO
  385. case Plugins_Item:
  386. {
  387. bool ok;
  388. unsigned int i = args[0].toString(exec).toArrayIndex(&ok);
  389. if( ok && i<base->plugins->count() )
  390. return Value( new Plugin( exec, base->plugins->at(i) ) );
  391. return Undefined();
  392. }
  393. case Plugins_NamedItem:
  394. UString s = args[0].toString(exec);
  395. return base->pluginByName( exec, s.qstring() );
  396. }
  397. }
  398. kdDebug(6070) << "WARNING: Unhandled token in PluginsFunc::tryCall : " << id << endl;
  399. return Undefined();
  400. }
  401. /*******************************************************************/
  402. const ClassInfo MimeTypes::info = { "MimeTypeArray", 0, &MimeTypesTable, 0 };
  403. /*
  404. @begin MimeTypesTable 3
  405. length MimeTypes_Length DontDelete|ReadOnly
  406. item MimeTypes_Item DontDelete|Function 1
  407. namedItem MimeTypes_NamedItem DontDelete|Function 1
  408. @end
  409. */
  410. IMPLEMENT_PROTOFUNC_DOM(MimeTypesFunc)
  411. Value MimeTypes::get(ExecState *exec, const Identifier &propertyName) const
  412. {
  413. #ifdef KJS_VERBOSE
  414. kdDebug(6070) << "MimeTypes::get " << propertyName.qstring() << endl;
  415. #endif
  416. if (!pluginsEnabled()) {
  417. if (propertyName == lengthPropertyName )
  418. return Number(0);
  419. } else {
  420. if( propertyName==lengthPropertyName )
  421. return Number( mimes->count() );
  422. // mimeTypes[#]
  423. bool ok;
  424. unsigned int i = propertyName.toULong(&ok);
  425. if( ok && i<mimes->count() )
  426. return Value( new MimeType( exec, mimes->at(i) ) );
  427. // mimeTypes[name]
  428. Value val = mimeTypeByName( exec, propertyName.qstring() );
  429. if (!val.isA(UndefinedType))
  430. return val;
  431. }
  432. return lookupGet<MimeTypesFunc,MimeTypes,ObjectImp>(exec,propertyName,&MimeTypesTable,this);
  433. }
  434. Value MimeTypes::mimeTypeByName( ExecState* exec, const TQString& name ) const
  435. {
  436. //kdDebug(6070) << "MimeTypes[" << name << "]" << endl;
  437. Q_ASSERT(mimes);
  438. for ( MimeClassInfo *m = mimes->first(); m!=0; m = mimes->next() ) {
  439. if ( m->type == name )
  440. return Value( new MimeType( exec, m ) );
  441. }
  442. return Undefined();
  443. }
  444. Value MimeTypes::getValueProperty(ExecState* /*exec*/, int token) const
  445. {
  446. kdDebug(6070) << "WARNING: Unhandled token in MimeTypes::getValueProperty : " << token << endl;
  447. return Undefined();
  448. }
  449. Value MimeTypesFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
  450. {
  451. KJS_CHECK_THIS( KJS::MimeTypes, thisObj );
  452. KJS::MimeTypes* base = static_cast<KJS::MimeTypes *>(thisObj.imp());
  453. if (!base->pluginsEnabled()) {
  454. if (id == MimeTypes_Item ||
  455. id == MimeTypes_NamedItem)
  456. return Undefined();
  457. } else {
  458. switch( id ) {
  459. case MimeTypes_Item:
  460. {
  461. bool ok;
  462. unsigned int i = args[0].toString(exec).toArrayIndex(&ok);
  463. if( ok && i<base->mimes->count() )
  464. return Value( new MimeType( exec, base->mimes->at(i) ) );
  465. return Undefined();
  466. }
  467. case MimeTypes_NamedItem:
  468. UString s = args[0].toString(exec);
  469. return base->mimeTypeByName( exec, s.qstring() );
  470. }
  471. }
  472. kdDebug(6070) << "WARNING: Unhandled token in MimeTypesFunc::tryCall : " << id << endl;
  473. return Undefined();
  474. }
  475. /************************************************************************/
  476. const ClassInfo Plugin::info = { "Plugin", 0, &PluginTable, 0 };
  477. /*
  478. @begin PluginTable 7
  479. name Plugin_Name DontDelete|ReadOnly
  480. filename Plugin_FileName DontDelete|ReadOnly
  481. description Plugin_Description DontDelete|ReadOnly
  482. length Plugin_Length DontDelete|ReadOnly
  483. item Plugin_Item DontDelete|Function 1
  484. namedItem Plugin_NamedItem DontDelete|Function 1
  485. @end
  486. */
  487. IMPLEMENT_PROTOFUNC_DOM(PluginFunc)
  488. Value Plugin::get(ExecState *exec, const Identifier &propertyName) const
  489. {
  490. #ifdef KJS_VERBOSE
  491. kdDebug(6070) << "Plugin::get " << propertyName.qstring() << endl;
  492. #endif
  493. if ( propertyName == lengthPropertyName )
  494. return Number( m_info->mimes.count() );
  495. // plugin[#]
  496. bool ok;
  497. unsigned int i = propertyName.toULong(&ok);
  498. //kdDebug(6070) << "Plugin::get plugin[" << i << "]" << endl;
  499. if( ok && i<m_info->mimes.count() )
  500. {
  501. //kdDebug(6070) << "returning mimetype " << m_info->mimes.at(i)->type << endl;
  502. return Value(new MimeType(exec, m_info->mimes.at(i)));
  503. }
  504. // plugin["name"]
  505. Value val = mimeByName( exec, propertyName.qstring() );
  506. if (!val.isA(UndefinedType))
  507. return val;
  508. return lookupGet<PluginFunc,Plugin,ObjectImp>(exec, propertyName, &PluginTable, this );
  509. }
  510. Value Plugin::mimeByName(ExecState* exec, const TQString& name) const
  511. {
  512. for ( PluginBase::MimeClassInfo *m = m_info->mimes.first();
  513. m != 0; m = m_info->mimes.next() ) {
  514. if ( m->type == name )
  515. return Value(new MimeType(exec, m));
  516. }
  517. return Undefined();
  518. }
  519. Value Plugin::getValueProperty(ExecState* /*exec*/, int token) const
  520. {
  521. switch( token ) {
  522. case Plugin_Name:
  523. return String( m_info->name );
  524. case Plugin_FileName:
  525. return String( m_info->file );
  526. case Plugin_Description:
  527. return String( m_info->desc );
  528. default:
  529. kdDebug(6070) << "WARNING: Unhandled token in Plugin::getValueProperty : " << token << endl;
  530. return Undefined();
  531. }
  532. }
  533. Value PluginFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
  534. {
  535. KJS_CHECK_THIS( KJS::Plugin, thisObj );
  536. KJS::Plugin* plugin = static_cast<KJS::Plugin *>(thisObj.imp());
  537. switch( id ) {
  538. case Plugin_Item:
  539. {
  540. bool ok;
  541. unsigned int i = args[0].toString(exec).toArrayIndex(&ok);
  542. if( ok && i< plugin->pluginInfo()->mimes.count() )
  543. return Value( new MimeType( exec, plugin->pluginInfo()->mimes.at(i) ) );
  544. return Undefined();
  545. }
  546. case Plugin_NamedItem:
  547. {
  548. UString s = args[0].toString(exec);
  549. return plugin->mimeByName( exec, s.qstring() );
  550. }
  551. default:
  552. kdDebug(6070) << "WARNING: Unhandled token in PluginFunc::tryCall : " << id << endl;
  553. return Undefined();
  554. }
  555. }
  556. /*****************************************************************************/
  557. const ClassInfo MimeType::info = { "MimeType", 0, &MimeTypeTable, 0 };
  558. /*
  559. @begin MimeTypeTable 4
  560. description MimeType_Description DontDelete|ReadOnly
  561. enabledPlugin MimeType_EnabledPlugin DontDelete|ReadOnly
  562. suffixes MimeType_Suffixes DontDelete|ReadOnly
  563. type MimeType_Type DontDelete|ReadOnly
  564. @end
  565. */
  566. Value MimeType::get(ExecState *exec, const Identifier &propertyName) const
  567. {
  568. #ifdef KJS_VERBOSE
  569. kdDebug(6070) << "MimeType::get " << propertyName.qstring() << endl;
  570. #endif
  571. return lookupGetValue<MimeType,ObjectImp>(exec, propertyName, &MimeTypeTable, this );
  572. }
  573. Value MimeType::getValueProperty(ExecState* exec, int token) const
  574. {
  575. switch( token ) {
  576. case MimeType_Type:
  577. return String( m_info->type );
  578. case MimeType_Suffixes:
  579. return String( m_info->suffixes );
  580. case MimeType_Description:
  581. return String( m_info->desc );
  582. case MimeType_EnabledPlugin:
  583. return Value(new Plugin(exec, m_info->plugin));
  584. default:
  585. kdDebug(6070) << "WARNING: Unhandled token in MimeType::getValueProperty : " << token << endl;
  586. return Undefined();
  587. }
  588. }
  589. Value NavigatorFunc::tryCall(ExecState *exec, Object &thisObj, const List &)
  590. {
  591. KJS_CHECK_THIS( KJS::Navigator, thisObj );
  592. Navigator *nav = static_cast<Navigator *>(thisObj.imp());
  593. // javaEnabled()
  594. return Boolean(nav->part()->javaEnabled());
  595. }