2002-05-01 06:01:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-05-01 06:01:50 +04:00
|
|
|
|
2001-11-17 18:22:46 +03:00
|
|
|
#include "nsPluginDirServiceProvider.h"
|
2002-05-01 06:01:50 +04:00
|
|
|
|
2001-11-17 18:22:46 +03:00
|
|
|
#include "nsCRT.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2002-04-27 09:33:09 +04:00
|
|
|
#include "nsDependentString.h"
|
2003-05-28 01:14:55 +04:00
|
|
|
#include "nsArrayEnumerator.h"
|
2012-04-04 08:09:20 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2001-11-17 18:22:46 +03:00
|
|
|
|
2011-02-18 00:18:53 +03:00
|
|
|
#include <windows.h>
|
|
|
|
#include "nsIWindowsRegKey.h"
|
|
|
|
|
2012-04-04 08:09:20 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2001-11-17 18:22:46 +03:00
|
|
|
//*****************************************************************************
|
|
|
|
// nsPluginDirServiceProvider::Constructor/Destructor
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
nsPluginDirServiceProvider::nsPluginDirServiceProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginDirServiceProvider::~nsPluginDirServiceProvider()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsPluginDirServiceProvider::nsISupports
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsPluginDirServiceProvider,
|
|
|
|
nsIDirectoryServiceProvider)
|
2001-11-17 18:22:46 +03:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// nsPluginDirServiceProvider::nsIDirectoryServiceProvider
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsPluginDirServiceProvider::GetFile(const char *charProp, bool *persistant,
|
2005-03-22 19:48:58 +03:00
|
|
|
nsIFile **_retval)
|
2001-11-17 18:22:46 +03:00
|
|
|
{
|
2009-03-09 08:07:00 +03:00
|
|
|
NS_ENSURE_ARG(charProp);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2011-09-30 10:02:59 +04:00
|
|
|
*persistant = false;
|
2002-05-01 06:01:50 +04:00
|
|
|
|
2016-11-15 09:20:44 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2001-11-17 18:22:46 +03:00
|
|
|
}
|
2002-05-01 06:01:50 +04:00
|
|
|
|
2003-05-28 01:14:55 +04:00
|
|
|
nsresult
|
|
|
|
nsPluginDirServiceProvider::GetPLIDDirectories(nsISimpleEnumerator **aEnumerator)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aEnumerator);
|
2012-07-30 18:20:58 +04:00
|
|
|
*aEnumerator = nullptr;
|
2003-05-28 01:14:55 +04:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMArray<nsIFile> dirs;
|
2003-05-28 01:14:55 +04:00
|
|
|
|
2011-02-18 00:18:53 +03:00
|
|
|
GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER, dirs);
|
|
|
|
GetPLIDDirectoriesWithRootKey(nsIWindowsRegKey::ROOT_KEY_LOCAL_MACHINE, dirs);
|
2007-04-03 19:56:31 +04:00
|
|
|
|
|
|
|
return NS_NewArrayEnumerator(aEnumerator, dirs);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsPluginDirServiceProvider::GetPLIDDirectoriesWithRootKey(uint32_t aKey, nsCOMArray<nsIFile> &aDirs)
|
2007-04-03 19:56:31 +04:00
|
|
|
{
|
2011-02-18 00:18:53 +03:00
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey =
|
|
|
|
do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
|
|
|
NS_ENSURE_TRUE(regKey, NS_ERROR_FAILURE);
|
2003-05-28 01:14:55 +04:00
|
|
|
|
2011-02-18 00:18:53 +03:00
|
|
|
nsresult rv = regKey->Open(aKey,
|
|
|
|
NS_LITERAL_STRING("Software\\MozillaPlugins"),
|
|
|
|
nsIWindowsRegKey::ACCESS_READ);
|
2013-04-03 18:24:03 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-05-28 01:14:55 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = 0;
|
2011-02-18 00:18:53 +03:00
|
|
|
regKey->GetChildCount(&childCount);
|
2003-05-28 01:14:55 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < childCount; ++index) {
|
2011-02-18 00:18:53 +03:00
|
|
|
nsAutoString childName;
|
|
|
|
rv = regKey->GetChildName(index, childName);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> childKey;
|
|
|
|
rv = regKey->OpenChild(childName, nsIWindowsRegKey::ACCESS_QUERY_VALUE,
|
|
|
|
getter_AddRefs(childKey));
|
|
|
|
if (NS_SUCCEEDED(rv) && childKey) {
|
|
|
|
nsAutoString path;
|
|
|
|
rv = childKey->ReadStringValue(NS_LITERAL_STRING("Path"), path);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> localFile;
|
2011-09-30 10:02:59 +04:00
|
|
|
if (NS_SUCCEEDED(NS_NewLocalFile(path, true,
|
2011-02-18 00:18:53 +03:00
|
|
|
getter_AddRefs(localFile))) &&
|
|
|
|
localFile) {
|
|
|
|
// Some vendors use a path directly to the DLL so chop off
|
|
|
|
// the filename
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isDir = false;
|
2011-02-18 00:18:53 +03:00
|
|
|
if (NS_SUCCEEDED(localFile->IsDirectory(&isDir)) && !isDir) {
|
|
|
|
nsCOMPtr<nsIFile> temp;
|
|
|
|
localFile->GetParent(getter_AddRefs(temp));
|
|
|
|
if (temp)
|
2012-06-06 06:08:30 +04:00
|
|
|
localFile = temp;
|
2003-05-28 01:14:55 +04:00
|
|
|
}
|
|
|
|
|
2011-02-18 00:18:53 +03:00
|
|
|
// Now we check to make sure it's actually on disk and
|
|
|
|
// To see if we already have this directory in the array
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isFileThere = false;
|
|
|
|
bool isDupEntry = false;
|
2011-02-18 00:18:53 +03:00
|
|
|
if (NS_SUCCEEDED(localFile->Exists(&isFileThere)) && isFileThere) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t c = aDirs.Count();
|
|
|
|
for (int32_t i = 0; i < c; i++) {
|
2011-02-18 00:18:53 +03:00
|
|
|
nsIFile *dup = static_cast<nsIFile*>(aDirs[i]);
|
|
|
|
if (dup &&
|
|
|
|
NS_SUCCEEDED(dup->Equals(localFile, &isDupEntry)) &&
|
|
|
|
isDupEntry) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDupEntry) {
|
|
|
|
aDirs.AppendObject(localFile);
|
|
|
|
}
|
2003-05-28 01:14:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-03 19:56:31 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2003-05-28 01:14:55 +04:00
|
|
|
}
|