⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kjs_navigator.cpp

📁 手机浏览器源码程序,功能强大
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    return Value();
  }
}

/*******************************************************************/

PluginBase::PluginBase(ExecState *exec)
  : ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype() )
{
    createPluginList();
    m_refCount++;
}

PluginBase::~PluginBase()
{
    m_refCount--;
    if ( m_refCount==0 ) {
        delete plugins;
        delete mimes;
        plugins = 0;
        mimes = 0;
    }
}
#if NOKIA_CHANGES
void PluginBase::refresh(ExecState *exec, bool reload)
#else	
void PluginBase::refresh(bool reload)
#endif
{
    delete plugins;
    delete mimes;
    plugins = 0;
    mimes = 0;
#if NOKIA_CHANGES
	ValueImp *imp = exec->dynamicInterpreter()->globalObject().imp();
	if(imp)	{
		Window* window = static_cast<KJS::Window*>(imp);
		RefreshPlugins(reload, KWQ(window->part()));
	}
#else
#if APPLE_CHANGES 
    RefreshPlugins(reload);
#endif
#endif
    //Reload the plugin list
    createPluginList();
}

void PluginBase::createPluginList()
{
   if ( !plugins ) {
        plugins = new QPtrList<PluginInfo>;
        mimes = new QPtrList<MimeClassInfo>;
        plugins->setAutoDelete( true );
        mimes->setAutoDelete( true );

        // read configuration
        KConfig c(KGlobal::dirs()->saveLocation("data","nsplugins")+"/pluginsinfo");
        unsigned num = (unsigned int)c.readNumEntry("number");
        for ( unsigned n=0; n<num; n++ ) {

            c.setGroup( QString::number(n) );
            PluginInfo *plugin = new PluginInfo;

            plugin->name = c.readEntry("name");
            plugin->file = c.readEntry("file");
            plugin->desc = c.readEntry("description");

            //kdDebug(6070) << "plugin : " << plugin->name << " - " << plugin->desc << endl;

            plugins->append( plugin );

            // get mime types from string
            QStringList types = QStringList::split( ';', c.readEntry("mime") );
            QStringList::Iterator type;
            for ( type=types.begin(); type!=types.end(); ++type ) {

                // get mime information
                MimeClassInfo *mime = new MimeClassInfo;
                QStringList tokens = QStringList::split(':', *type, TRUE);
                QStringList::Iterator token;

                token = tokens.begin();
                if (token == tokens.end()) {
                    delete mime;
                    continue;
                }
                mime->type = (*token).lower();
                //kdDebug(6070) << "mime->type=" << mime->type << endl;
                ++token;

                if (token == tokens.end()) {
                    delete mime;
                    continue;
                }
                mime->suffixes = *token;
                ++token;

                if (token == tokens.end()) {
                    delete mime;
                    continue;
                }
                mime->desc = *token;
                ++token;

                mime->plugin = plugin;

                mimes->append( mime );
                plugin->mimes.append( mime );
            }
        }
    }

}


/*******************************************************************/
IMPLEMENT_PROTOFUNC(PluginsFunc)

Value Plugins::get(ExecState *exec, const Identifier &propertyName) const
{
#ifdef KJS_VERBOSE
  kdDebug(6070) << "Plugins::get " << propertyName.qstring() << endl;
#endif
    if (propertyName == "refresh")
      return lookupOrCreateFunction<PluginsFunc>(exec,propertyName,this,0,0,DontDelete|Function);
    else if ( propertyName ==lengthPropertyName )
      return Number(plugins->count());
    else {

        // plugins[#]
        bool ok;
        unsigned int i = propertyName.toULong(&ok);
        if( ok && i<plugins->count() )
            return Value( new Plugin( exec, plugins->at(i) ) );

        // plugin[name]
        for ( PluginInfo *pl = plugins->first(); pl!=0; pl = plugins->next() ) {
            if ( pl->name==propertyName.qstring() )
                return Value( new Plugin( exec, pl ) );
        }
    }

    return PluginBase::get(exec, propertyName);
}

/*******************************************************************/

Value MimeTypes::get(ExecState *exec, const Identifier &propertyName) const
{
#ifdef KJS_VERBOSE
  kdDebug(6070) << "MimeTypes::get " << propertyName.qstring() << endl;
#endif
    if( propertyName==lengthPropertyName )
        return Number( mimes->count() );
    else {

        // mimeTypes[#]
        bool ok;
        unsigned int i = propertyName.toULong(&ok);
        if( ok && i<mimes->count() )
            return Value( new MimeType( exec, mimes->at(i) ) );

        // mimeTypes[name]
        //kdDebug(6070) << "MimeTypes[" << propertyName.ascii() << "]" << endl;
        for ( MimeClassInfo *m=mimes->first(); m!=0; m=mimes->next() ) {
            //kdDebug(6070) << "m->type=" << m->type.ascii() << endl;
            if ( m->type == propertyName.qstring() )
                return Value( new MimeType( exec, m ) );
        }
    }

    return PluginBase::get(exec, propertyName);
}


/************************************************************************/

Value Plugin::get(ExecState *exec, const Identifier &propertyName) const
{
#ifdef KJS_VERBOSE
  kdDebug(6070) << "Plugin::get " << propertyName.qstring() << endl;
#endif
    if ( propertyName=="name" )
        return String( m_info->name );
    else if ( propertyName == "filename" )
        return String( m_info->file );
    else if ( propertyName == "description" )
        return String( m_info->desc );
    else if ( propertyName == lengthPropertyName )
        return Number( m_info->mimes.count() );
    else {

        // plugin[#]
        bool ok;
        unsigned int i = propertyName.toULong(&ok);
        //kdDebug(6070) << "Plugin::get plugin[" << i << "]" << endl;
        if( ok && i<m_info->mimes.count() )
        {
            //kdDebug(6070) << "returning mimetype " << m_info->mimes.at(i)->type << endl;
            return Value(new MimeType(exec, m_info->mimes.at(i)));
        }

        // plugin["name"]
        for ( MimeClassInfo *m=m_info->mimes.first();
              m!=0; m=m_info->mimes.next() ) {
            if ( m->type==propertyName.qstring() )
                return Value(new MimeType(exec, m));
        }

    }

    return ObjectImp::get(exec,propertyName);
}


/*****************************************************************************/

Value MimeType::get(ExecState *exec, const Identifier &propertyName) const
{
#ifdef KJS_VERBOSE
  kdDebug(6070) << "MimeType::get " << propertyName.qstring() << endl;
#endif
    if ( propertyName == "type" )
        return String( m_info->type );
    else if ( propertyName == "suffixes" )
        return String( m_info->suffixes );
    else if ( propertyName == "description" )
        return String( m_info->desc );
    else if ( propertyName == "enabledPlugin" )
        return Value(new Plugin(exec, m_info->plugin));

    return ObjectImp::get(exec,propertyName);
}


Value PluginsFunc::tryCall(ExecState *exec, Object &, const List &args)
{
#ifdef NOKIA_CHANGES
	PluginBase(exec).refresh(exec, args[0].toBoolean(exec));
#else
    PluginBase(exec).refresh(args[0].toBoolean(exec));
#endif

    return Undefined();
}


Value NavigatorFunc::tryCall(ExecState *exec, Object &thisObj, const List &)
{
  if (!thisObj.inherits(&KJS::Navigator::info)) {
    Object err = Error::create(exec,TypeError);
    exec->setException(err);
    return err;
  }
  Navigator *nav = static_cast<Navigator *>(thisObj.imp());
  // javaEnabled()
  return Boolean(nav->part()->javaEnabled());
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -