NS_IMETHODIMP nsPluginArray::NamedItem(const nsAString& aName, nsIDOMPlugin** aReturn) { NS_PRECONDITION(nsnull != aReturn, "null arg"); *aReturn = nsnull; if (!AllowPlugins()) return NS_OK; if (mPluginArray == nsnull) { nsresult rv = GetPlugins(); if (rv != NS_OK) return rv; } for (PRUint32 i = 0; i < mPluginCount; i++) { nsAutoString pluginName; nsIDOMPlugin* plugin = mPluginArray[i]; if (plugin->GetName(pluginName) == NS_OK) { if (pluginName.Equals(aName)) { *aReturn = plugin; NS_IF_ADDREF(plugin); break; } } } return NS_OK; }
IFXRESULT IFXOSFileIterator::GetPlugins( IFXString *subPath ) { IFXRESULT result = IFX_OK; WIN32_FIND_DATA data; BOOL res = FALSE; HANDLE hdl; IFXString tempPath; // find and store all files in this dir ProcessDir( subPath ); // now process subdirs IFXString localPath( m_pluginLocation ); localPath.Concatenate( subPath ); localPath.Concatenate( IFXOSFI_EXTALL ); hdl = FindFirstFile( localPath.Raw(), &data ); // if there are no any file/directory then skip next block if( INVALID_HANDLE_VALUE != hdl ) { // keep searching while there are any files/directories do { // create full path to the found object tempPath.Assign( &m_pluginLocation ); tempPath.Concatenate( subPath ); tempPath.Concatenate( data.cFileName ); // we already found and stored all files we wanted, so check if found object is // a) a directory, // b) its nesting doesn't exceed the limitation (IFXOSFI_MAXDEPTH), // c) its name isn't a "." or ".." if( IsDir( &tempPath ) > 0 && m_depth < IFXOSFI_MAXDEPTH && wcscmp( data.cFileName, IFXOSFI_CURRDIR ) && wcscmp( data.cFileName, IFXOSFI_UPPRDIR ) ) { // we have found a directory and we want to look in it, so // create its relative path: tempPath.Assign( subPath ); tempPath.Concatenate( data.cFileName ); tempPath.Concatenate( L"\\" ); // increment the depth (nesting) m_depth++; // step inside GetPlugins( &tempPath ); // decrement the depth (nesting) m_depth--; } // find next file/directory res = FindNextFile( hdl, &data ); } while( res ); // close handle FindClose( hdl ); } return result; }
/************************************************************************ * * Process all sub-directories and all files. * ************************************************************************/ IFXRESULT IFXOSFileIterator::GetPlugins( IFXString& rPlugins, U32& rPluginCount ) { IFXString empty(L""); // start iteration thru this directory and all subdirectories // (except ones that exceed nesting limitation defined by IFXOSFI_MAXDEPTH) IFXRESULT res = GetPlugins( &empty ); if( IFXSUCCESS( res ) ) { // output plugin names rPlugins.Assign( &m_plugins ); // output plugins count rPluginCount = m_count; } else { // if error then clean the output string m_plugins.Clear(); } // return reference to string with plugins' names return res; }
nsIDOMPlugin* nsPluginArray::GetItemAt(PRUint32 aIndex, nsresult* aResult) { *aResult = NS_OK; if (!AllowPlugins()) return nsnull; if (mPluginArray == nsnull) { *aResult = GetPlugins(); if (*aResult != NS_OK) return nsnull; } return aIndex < mPluginCount ? mPluginArray[aIndex] : nsnull; }
NS_IMETHODIMP nsPluginArray::Item(PRUint32 aIndex, nsIDOMPlugin** aReturn) { NS_PRECONDITION(nsnull != aReturn, "null arg"); *aReturn = nsnull; if (!AllowPlugins()) return NS_OK; if (mPluginArray == nsnull) { nsresult rv = GetPlugins(); if (rv != NS_OK) return rv; } if (aIndex < mPluginCount) { *aReturn = mPluginArray[aIndex]; NS_IF_ADDREF(*aReturn); } return NS_OK; }
nsIDOMPlugin* nsPluginArray::GetNamedItem(const nsAString& aName, nsresult* aResult) { *aResult = NS_OK; if (!AllowPlugins()) return nsnull; if (mPluginArray == nsnull) { *aResult = GetPlugins(); if (*aResult != NS_OK) return nsnull; } for (PRUint32 i = 0; i < mPluginCount; i++) { nsAutoString pluginName; nsIDOMPlugin* plugin = mPluginArray[i]; if (plugin->GetName(pluginName) == NS_OK && pluginName.Equals(aName)) { return plugin; } } return nsnull; }