本文整理汇总了C++中NS_NewLocalFile函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_NewLocalFile函数的具体用法?C++ NS_NewLocalFile怎么用?C++ NS_NewLocalFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_NewLocalFile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: NS_WARNING
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
{
if (NS_IsMozAliasSound(aSoundAlias)) {
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
uint32_t eventId;
if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG))
eventId = EVENT_ALERT_DIALOG_OPEN;
else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG))
eventId = EVENT_CONFIRM_DIALOG_OPEN;
else if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
eventId = EVENT_NEW_MAIL_RECEIVED;
else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_EXECUTE))
eventId = EVENT_MENU_EXECUTE;
else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_POPUP))
eventId = EVENT_MENU_POPUP;
else
return NS_OK;
return PlayEventSound(eventId);
}
nsresult rv;
nsCOMPtr <nsIURI> fileURI;
// create a nsIFile and then a nsIFileURL from that
nsCOMPtr <nsIFile> soundFile;
rv = NS_NewLocalFile(aSoundAlias, true,
getter_AddRefs(soundFile));
NS_ENSURE_SUCCESS(rv,rv);
rv = NS_NewFileURI(getter_AddRefs(fileURI), soundFile);
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI,&rv);
NS_ENSURE_SUCCESS(rv,rv);
rv = Play(fileURL);
return rv;
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:39,代码来源:nsSound.cpp
示例2: GetWindowsFolder
//----------------------------------------------------------------------------------------
static nsresult GetWindowsFolder(int folder, nsILocalFile** aFile)
//----------------------------------------------------------------------------------------
{
#ifdef WINCE
#define SHGetSpecialFolderPathW SHGetSpecialFolderPath
#ifndef WINCE_WINDOWS_MOBILE
if (folder == CSIDL_APPDATA || folder == CSIDL_LOCAL_APPDATA)
folder = CSIDL_PROFILE;
#endif
#endif
WCHAR path_orig[MAX_PATH + 3];
WCHAR *path = path_orig+1;
HRESULT result = SHGetSpecialFolderPathW(NULL, path, folder, true);
if (!SUCCEEDED(result))
return NS_ERROR_FAILURE;
// Append the trailing slash
int len = wcslen(path);
if (len > 1 && path[len - 1] != L'\\')
{
path[len] = L'\\';
path[++len] = L'\0';
}
#if defined(WINCE) && !defined(WINCE_WINDOWS_MOBILE)
// sometimes CSIDL_PROFILE shows up without a root slash
if (folder == CSIDL_PROFILE && path[0] != '\\') {
path_orig[0] = '\\';
path = path_orig;
len++;
}
#endif
return NS_NewLocalFile(nsDependentString(path, len), PR_TRUE, aFile);
}
开发者ID:sahlberg,项目名称:timberwolf,代码行数:39,代码来源:SpecialSystemDirectory.cpp
示例3: NS_NewLocalFile
void nsBrowserListener::GetProperty(nsIPersistentProperties **prop,nsACString &fileName)
{
nsresult rv;
nsCOMPtr<nsIPersistentProperties> tmpprop=do_CreateInstance("@mozilla.org/persistent-properties;1", &rv);
if (NS_FAILED(rv))
{
LOG<<"Get properties Error:"<<rv<<"\n";
}
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(fileName), PR_FALSE,
getter_AddRefs(file));
if (NS_FAILED(rv))
return ;
nsCOMPtr<nsIInputStream> fistream;
rv=NS_NewLocalFileInputStream(getter_AddRefs(fistream), file);
if (NS_FAILED(rv))
{
return ;
}
tmpprop->Load(fistream);
*prop=tmpprop;
NS_ADDREF(*prop);
}
开发者ID:firememory,项目名称:dfwbi,代码行数:23,代码来源:BrowserListener.cpp
示例4: NS_LITERAL_STRING
nsresult
MediaEngineDefaultVideoSource::Snapshot(uint32_t aDuration, nsIDOMFile** aFile)
{
*aFile = nullptr;
#ifndef MOZ_WIDGET_ANDROID
return NS_ERROR_NOT_IMPLEMENTED;
#else
if (!AndroidBridge::Bridge()) {
return NS_ERROR_UNEXPECTED;
}
nsAutoString filePath;
AndroidBridge::Bridge()->ShowFilePickerForMimeType(filePath, NS_LITERAL_STRING("image/*"));
nsCOMPtr<nsIFile> file;
nsresult rv = NS_NewLocalFile(filePath, false, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(*aFile = new nsDOMFileFile(file));
return NS_OK;
#endif
}
开发者ID:sandhua,项目名称:gecko-dev,代码行数:23,代码来源:MediaEngineDefault.cpp
示例5: GetFileBase
static bool
GetFileBase(const nsAString& aPluginPath,
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
nsCOMPtr<nsIFile>& aLibDirectory,
#endif
nsCOMPtr<nsIFile>& aFileBase,
nsAutoString& aBaseName)
{
nsresult rv = NS_NewLocalFile(aPluginPath,
true, getter_AddRefs(aFileBase));
if (NS_FAILED(rv)) {
return false;
}
#if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
if (NS_FAILED(aFileBase->Clone(getter_AddRefs(aLibDirectory)))) {
return false;
}
#endif
nsCOMPtr<nsIFile> parent;
rv = aFileBase->GetParent(getter_AddRefs(parent));
if (NS_FAILED(rv)) {
return false;
}
nsAutoString parentLeafName;
rv = parent->GetLeafName(parentLeafName);
if (NS_FAILED(rv)) {
return false;
}
aBaseName = Substring(parentLeafName,
4,
parentLeafName.Length() - 1);
return true;
}
开发者ID:JasonJinCn,项目名称:gecko-dev,代码行数:37,代码来源:GMPChild.cpp
示例6: NS_ENSURE_ARG
NS_IMETHODIMP
nsPluginDirServiceProvider::GetFile(const char *charProp, PRBool *persistant,
nsIFile **_retval)
{
nsCOMPtr<nsILocalFile> localFile;
nsresult rv = NS_ERROR_FAILURE;
NS_ENSURE_ARG(charProp);
*_retval = nsnull;
*persistant = PR_FALSE;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return NS_ERROR_FAILURE;
if (nsCRT::strcmp(charProp, NS_WIN_4DOTX_SCAN_KEY) == 0) {
// Check our prefs to see if scanning the 4.x folder has been
// explictly overriden failure to get the pref is okay, we'll do
// what we've been doing -- a filtered scan
PRBool bScan4x;
if (NS_SUCCEEDED(prefs->GetBoolPref(NS_WIN_4DOTX_SCAN_KEY, &bScan4x)) &&
!bScan4x) {
return NS_ERROR_FAILURE;
}
// Look for the plugin folder that the user has in their
// Communicator 4x install
HKEY keyloc;
long result;
DWORD type;
WCHAR szKey[_MAX_PATH] = L"Software\\Netscape\\Netscape Navigator";
WCHAR path[_MAX_PATH];
result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &keyloc);
if (result == ERROR_SUCCESS) {
WCHAR current_version[80];
DWORD length = NS_ARRAY_LENGTH(current_version);
result = ::RegQueryValueExW(keyloc, L"CurrentVersion", NULL, &type,
(LPBYTE)¤t_version, &length);
::RegCloseKey(keyloc);
wcscat(szKey, L"\\");
wcscat(szKey, current_version);
wcscat(szKey, L"\\Main");
result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &keyloc);
if (result == ERROR_SUCCESS) {
DWORD pathlen = NS_ARRAY_LENGTH(path);
result = ::RegQueryValueExW(keyloc, L"Plugins Directory", NULL, &type,
(LPBYTE)&path, &pathlen);
if (result == ERROR_SUCCESS) {
rv = NS_NewLocalFile(nsDependentString(path),
PR_TRUE, getter_AddRefs(localFile));
}
::RegCloseKey(keyloc);
}
}
} else if (nsCRT::strcmp(charProp, NS_WIN_JRE_SCAN_KEY) == 0) {
nsXPIDLCString strVer;
if (NS_FAILED(prefs->GetCharPref(charProp, getter_Copies(strVer))))
return NS_ERROR_FAILURE;
verBlock minVer;
TranslateVersionStr(NS_ConvertASCIItoUTF16(strVer).get(), &minVer);
// Look for the Java OJI plugin via the JRE install path
HKEY baseloc;
HKEY keyloc;
HKEY entryloc;
FILETIME modTime;
DWORD type;
DWORD index = 0;
DWORD numChars = _MAX_PATH;
DWORD pathlen;
verBlock maxVer;
ClearVersion(&maxVer);
WCHAR curKey[_MAX_PATH] = L"Software\\JavaSoft\\Java Runtime Environment";
WCHAR path[_MAX_PATH];
// Add + 15 to prevent buffer overrun when adding \bin (+ optionally
// \new_plugin)
#define JAVA_PATH_SIZE _MAX_PATH + 15
WCHAR newestPath[JAVA_PATH_SIZE];
const WCHAR mozPath[_MAX_PATH] = L"Software\\mozilla.org\\Mozilla";
WCHAR browserJavaVersion[_MAX_PATH];
newestPath[0] = 0;
LONG result = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, curKey, 0, KEY_READ,
&baseloc);
if (ERROR_SUCCESS != result)
return NS_ERROR_FAILURE;
// Look for "BrowserJavaVersion"
if (ERROR_SUCCESS != ::RegQueryValueExW(baseloc, L"BrowserJavaVersion", NULL,
NULL, (LPBYTE)&browserJavaVersion,
&numChars))
browserJavaVersion[0] = 0;
//.........这里部分代码省略.........
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:101,代码来源:nsPluginDirServiceProvider.cpp
示例7: MOZ_ASSERT
void
GeckoMediaPluginServiceParent::RemoveOnGMPThread(const nsAString& aDirectory,
const bool aDeleteFromDisk,
const bool aCanDefer)
{
MOZ_ASSERT(NS_GetCurrentThread() == mGMPThread);
LOGD(("%s::%s: %s", __CLASS__, __FUNCTION__, NS_LossyConvertUTF16toASCII(aDirectory).get()));
nsCOMPtr<nsIFile> directory;
nsresult rv = NS_NewLocalFile(aDirectory, false, getter_AddRefs(directory));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
// Plugin destruction can modify |mPlugins|. Put them aside for now and
// destroy them once we're done with |mPlugins|.
nsTArray<nsRefPtr<GMPParent>> deadPlugins;
bool inUse = false;
MutexAutoLock lock(mMutex);
for (size_t i = mPlugins.Length() - 1; i < mPlugins.Length(); i--) {
nsCOMPtr<nsIFile> pluginpath = mPlugins[i]->GetDirectory();
bool equals;
if (NS_FAILED(directory->Equals(pluginpath, &equals)) || !equals) {
continue;
}
nsRefPtr<GMPParent> gmp = mPlugins[i];
if (aDeleteFromDisk && gmp->State() != GMPStateNotLoaded) {
// We have to wait for the child process to release its lib handle
// before we can delete the GMP.
inUse = true;
gmp->MarkForDeletion();
if (!mPluginsWaitingForDeletion.Contains(aDirectory)) {
mPluginsWaitingForDeletion.AppendElement(aDirectory);
}
}
if (gmp->State() == GMPStateNotLoaded || !aCanDefer) {
// GMP not in use or shutdown is being forced; can shut it down now.
deadPlugins.AppendElement(gmp);
mPlugins.RemoveElementAt(i);
}
}
{
MutexAutoUnlock unlock(mMutex);
for (auto& gmp : deadPlugins) {
gmp->AbortAsyncShutdown();
gmp->CloseActive(true);
}
}
if (aDeleteFromDisk && !inUse) {
if (NS_SUCCEEDED(directory->Remove(true))) {
mPluginsWaitingForDeletion.RemoveElement(aDirectory);
NS_DispatchToMainThread(new NotifyObserversTask("gmp-directory-deleted",
nsString(aDirectory)),
NS_DISPATCH_NORMAL);
}
}
}
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:63,代码来源:GMPServiceParent.cpp
示例8: GetSpecialSystemDirectory
nsresult
GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
nsIFile** aFile)
{
#if defined(XP_WIN)
WCHAR path[MAX_PATH];
#else
char path[MAXPATHLEN];
#endif
switch (aSystemSystemDirectory)
{
case OS_CurrentWorkingDirectory:
#if defined(XP_WIN)
if (!_wgetcwd(path, MAX_PATH))
return NS_ERROR_FAILURE;
return NS_NewLocalFile(nsDependentString(path),
true,
aFile);
#elif defined(XP_OS2)
if (DosQueryPathInfo( ".", FIL_QUERYFULLNAME, path, MAXPATHLEN))
return NS_ERROR_FAILURE;
#else
if(!getcwd(path, MAXPATHLEN))
return NS_ERROR_FAILURE;
#endif
#if !defined(XP_WIN)
return NS_NewNativeLocalFile(nsDependentCString(path),
true,
aFile);
#endif
case OS_DriveDirectory:
#if defined (XP_WIN)
{
PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH);
if (len == 0)
break;
if (path[1] == PRUnichar(':') && path[2] == PRUnichar('\\'))
path[3] = 0;
return NS_NewLocalFile(nsDependentString(path),
true,
aFile);
}
#elif defined(XP_OS2)
{
ULONG ulBootDrive = 0;
char buffer[] = " :\\OS2\\";
DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
&ulBootDrive, sizeof ulBootDrive);
buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
return NS_NewNativeLocalFile(nsDependentCString(buffer),
true,
aFile);
}
#else
return NS_NewNativeLocalFile(nsDependentCString("/"),
true,
aFile);
#endif
case OS_TemporaryDirectory:
#if defined (XP_WIN)
{
DWORD len = ::GetTempPathW(MAX_PATH, path);
if (len == 0)
break;
return NS_NewLocalFile(nsDependentString(path, len),
true,
aFile);
}
#elif defined(XP_OS2)
{
char *tPath = PR_GetEnv("TMP");
if (!tPath || !*tPath) {
tPath = PR_GetEnv("TEMP");
if (!tPath || !*tPath) {
// if an OS/2 system has neither TMP nor TEMP defined
// then it is severely broken, so this will never happen.
return NS_ERROR_UNEXPECTED;
}
}
nsCString tString = nsDependentCString(tPath);
if (tString.Find("/", false, 0, -1)) {
tString.ReplaceChar('/','\\');
}
return NS_NewNativeLocalFile(tString, true, aFile);
}
#elif defined(MOZ_WIDGET_COCOA)
{
return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
}
#elif defined(XP_UNIX)
{
static const char *tPath = nullptr;
//.........这里部分代码省略.........
开发者ID:FunkyVerb,项目名称:devtools-window,代码行数:101,代码来源:SpecialSystemDirectory.cpp
示例9: switch
bool
DeviceStorageRequestChild::Recv__delete__(const DeviceStorageResponseValue& aValue)
{
switch (aValue.type()) {
case DeviceStorageResponseValue::TErrorResponse:
{
ErrorResponse r = aValue;
mRequest->FireError(r.error());
break;
}
case DeviceStorageResponseValue::TSuccessResponse:
{
jsval result = StringToJsval(mRequest->GetOwner(), mFile->mPath);
mRequest->FireSuccess(result);
break;
}
case DeviceStorageResponseValue::TBlobResponse:
{
BlobResponse r = aValue;
BlobChild* actor = static_cast<BlobChild*>(r.blobChild());
nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
jsval result = InterfaceToJsval(mRequest->GetOwner(), blob, &NS_GET_IID(nsIDOMBlob));
mRequest->FireSuccess(result);
break;
}
case DeviceStorageResponseValue::TStatStorageResponse:
{
StatStorageResponse r = aValue;
nsRefPtr<nsIDOMDeviceStorageStat> domstat = new nsDOMDeviceStorageStat(r.freeBytes(), r.totalBytes(), r.mountState());
jsval result = InterfaceToJsval(mRequest->GetOwner(), domstat, &NS_GET_IID(nsIDOMDeviceStorageStat));
mRequest->FireSuccess(result);
break;
}
case DeviceStorageResponseValue::TEnumerationResponse:
{
EnumerationResponse r = aValue;
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
uint32_t count = r.paths().Length();
for (uint32_t i = 0; i < count; i++) {
nsCOMPtr<nsIFile> f;
nsresult rv = NS_NewLocalFile(r.paths()[i].fullpath(), false, getter_AddRefs(f));
if (NS_FAILED(rv)) {
continue;
}
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(r.paths()[i].type(), f);
dsf->SetPath(r.paths()[i].name());
cursor->mFiles.AppendElement(dsf);
}
nsCOMPtr<ContinueCursorEvent> event = new ContinueCursorEvent(cursor);
NS_DispatchToMainThread(event);
break;
}
default:
{
NS_RUNTIMEABORT("not reached");
break;
}
}
return true;
}
开发者ID:ChicoTeam,项目名称:mozilla-central,代码行数:71,代码来源:DeviceStorageRequestChild.cpp
示例10: while
nsresult
nsPluginDirServiceProvider::GetPLIDDirectoriesWithHKEY(HKEY aKey, nsCOMArray<nsILocalFile> &aDirs)
{
WCHAR subkey[_MAX_PATH] = L"Software\\MozillaPlugins";
HKEY baseloc;
if (ERROR_SUCCESS != ::RegOpenKeyExW(aKey, subkey, 0, KEY_READ, &baseloc))
return NS_ERROR_FAILURE;
DWORD index = 0;
DWORD subkeylen = _MAX_PATH;
FILETIME modTime;
while (ERROR_SUCCESS == ::RegEnumKeyExW(baseloc, index++, subkey, &subkeylen,
NULL, NULL, NULL, &modTime)) {
subkeylen = _MAX_PATH;
HKEY keyloc;
if (ERROR_SUCCESS == ::RegOpenKeyExW(baseloc, subkey, 0, KEY_QUERY_VALUE,
&keyloc)) {
DWORD type;
WCHAR path[_MAX_PATH];
DWORD pathlen = NS_ARRAY_LENGTH(path);
if (ERROR_SUCCESS == ::RegQueryValueExW(keyloc, L"Path", NULL, &type,
(LPBYTE)&path, &pathlen)) {
nsCOMPtr<nsILocalFile> localFile;
if (NS_SUCCEEDED(NS_NewLocalFile(nsDependentString(path), PR_TRUE,
getter_AddRefs(localFile))) &&
localFile)
{
// Some vendors use a path directly to the DLL so chop off
// the filename
PRBool isDir = PR_FALSE;
if (NS_SUCCEEDED(localFile->IsDirectory(&isDir)) && !isDir) {
nsCOMPtr<nsIFile> temp;
localFile->GetParent(getter_AddRefs(temp));
if (temp)
localFile = do_QueryInterface(temp);
}
// Now we check to make sure it's actually on disk and
// To see if we already have this directory in the array
PRBool isFileThere = PR_FALSE;
PRBool isDupEntry = PR_FALSE;
if (NS_SUCCEEDED(localFile->Exists(&isFileThere)) && isFileThere) {
PRInt32 c = aDirs.Count();
for (PRInt32 i = 0; i < c; i++) {
nsIFile *dup = static_cast<nsIFile*>(aDirs[i]);
if (dup &&
NS_SUCCEEDED(dup->Equals(localFile, &isDupEntry)) &&
isDupEntry) {
break;
}
}
if (!isDupEntry) {
aDirs.AppendObject(localFile);
}
}
}
}
::RegCloseKey(keyloc);
}
}
::RegCloseKey(baseloc);
return NS_OK;
}
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:67,代码来源:nsPluginDirServiceProvider.cpp
示例11: TestPermissions
//.........这里部分代码省略.........
fail("NTFS Permissions: LocalAlloc Error");
return NS_ERROR_FAILURE;
}
if (!InitializeSecurityDescriptor(dirSD,
SECURITY_DESCRIPTOR_REVISION))
{
fail("NTFS Permissions: InitializeSecurityDescriptor Error");
return NS_ERROR_FAILURE;
}
// Add the ACL to the security descriptor.
if (!SetSecurityDescriptorDacl(dirSD, true, dirACL, false))
{
fail("NTFS Permissions: SetSecurityDescriptorDacl Error");
return NS_ERROR_FAILURE;
}
// Initialize a security attributes structure.
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = dirSD;
sa.bInheritHandle = false;
// Create and open first temporary directory
if(!CreateDirectoryW(L".\\NTFSPERMTEMP1", &sa))
{
fail("NTFS Permissions: Creating Temporary Directory");
return NS_ERROR_FAILURE;
}
GetFullPathNameW((LPCWSTR)L".\\NTFSPERMTEMP1", MAX_PATH, dir1Path, NULL);
rv = NS_NewLocalFile(nsEmbedString(dir1Path), false,
getter_AddRefs(tempDirectory1));
if (NS_FAILED(rv))
{
fail("NTFS Permissions: Opening Temporary Directory 1");
return rv;
}
// Create and open temporary file
tempFileHandle = CreateFileW(L".\\NTFSPERMTEMP1\\NTFSPerm.tmp",
GENERIC_READ | GENERIC_WRITE,
0,
NULL, //default security
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(tempFileHandle == INVALID_HANDLE_VALUE)
{
fail("NTFS Permissions: Creating Temporary File");
return NS_ERROR_FAILURE;
}
CloseHandle(tempFileHandle);
GetFullPathNameW((LPCWSTR)L".\\NTFSPERMTEMP1\\NTFSPerm.tmp",
MAX_PATH, filePath, NULL);
rv = NS_NewLocalFile(nsEmbedString(filePath), false,
getter_AddRefs(tempFile));
if (NS_FAILED(rv))
{
开发者ID:Anachid,项目名称:mozilla-central,代码行数:67,代码来源:TestNTFSPermissions.cpp
示例12: MOZ_COUNT_CTOR
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams)
{
MOZ_COUNT_CTOR(DeviceStorageRequestParent);
switch (aParams.type()) {
case DeviceStorageParams::TDeviceStorageAddParams:
{
DeviceStorageAddParams p = aParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
BlobParent* bp = static_cast<BlobParent*>(p.blobParent());
nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob();
nsCOMPtr<nsIInputStream> stream;
blob->GetInternalStream(getter_AddRefs(stream));
nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
case DeviceStorageParams::TDeviceStorageGetParams:
{
DeviceStorageGetParams p = aParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
dsf->SetPath(p.name());
nsRefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
case DeviceStorageParams::TDeviceStorageDeleteParams:
{
DeviceStorageDeleteParams p = aParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
case DeviceStorageParams::TDeviceStorageStatParams:
{
DeviceStorageStatParams p = aParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
nsRefPtr<StatFileEvent> r = new StatFileEvent(this, dsf);
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
case DeviceStorageParams::TDeviceStorageEnumerationParams:
{
DeviceStorageEnumerationParams p = aParams;
nsCOMPtr<nsIFile> f;
NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f));
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f);
nsRefPtr<CancelableRunnable> r = new EnumerateFileEvent(this, dsf, p.since());
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
NS_ASSERTION(target, "Must have stream transport service");
target->Dispatch(r, NS_DISPATCH_NORMAL);
break;
}
default:
{
NS_RUNTIMEABORT("not reached");
break;
}
}
}
开发者ID:eric30,项目名称:mozilla-central-1,代码行数:99,代码来源:DeviceStorageRequestParent.cpp
示例13: defined
//----------------------------------------------------------------------------------------
// GetProductDirectory - Gets the directory which contains the application data folder
//
// UNIX : ~/.mozilla/
// WIN : <Application Data folder on user's machine>\Mozilla
// Mac : :Documents:Mozilla:
//----------------------------------------------------------------------------------------
NS_METHOD
nsAppFileLocationProvider::GetProductDirectory(nsIFile** aLocalFile,
bool aLocal)
{
if (NS_WARN_IF(!aLocalFile)) {
return NS_ERROR_INVALID_ARG;
}
nsresult rv;
bool exists;
nsCOMPtr<nsIFile> localDir;
#if defined(MOZ_WIDGET_COCOA)
FSRef fsRef;
OSType folderType = aLocal ? (OSType)kCachedDataFolderType :
(OSType)kDomainLibraryFolderType;
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
if (err) {
return NS_ERROR_FAILURE;
}
NS_NewLocalFile(EmptyString(), true, getter_AddRefs(localDir));
if (!localDir) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
rv = localDirMac->InitWithFSRef(&fsRef);
if (NS_FAILED(rv)) {
return rv;
}
#elif defined(XP_WIN)
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
const char* prop = aLocal ? NS_WIN_LOCAL_APPDATA_DIR : NS_WIN_APPDATA_DIR;
rv = directoryService->Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(localDir));
if (NS_FAILED(rv)) {
return rv;
}
#elif defined(XP_UNIX)
rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), true,
getter_AddRefs(localDir));
if (NS_FAILED(rv)) {
return rv;
}
#else
#error dont_know_how_to_get_product_dir_on_your_platform
#endif
rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
if (NS_FAILED(rv)) {
return rv;
}
rv = localDir->Exists(&exists);
if (NS_SUCCEEDED(rv) && !exists) {
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
}
if (NS_FAILED(rv)) {
return rv;
}
localDir.forget(aLocalFile);
return rv;
}
开发者ID:MekliCZ,项目名称:positron,代码行数:75,代码来源:nsAppFileLocationProvider.cpp
示例14: GetSpecialSystemDirectory
nsresult
GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
nsIFile** aFile)
{
#if defined(XP_WIN)
WCHAR path[MAX_PATH];
#else
char path[MAXPATHLEN];
#endif
switch (aSystemSystemDirectory)
{
case OS_CurrentWorkingDirectory:
#if defined(XP_WIN)
if (!_wgetcwd(path, MAX_PATH))
return NS_ERROR_FAILURE;
return NS_NewLocalFile(nsDependentString(path),
true,
aFile);
#else
if(!getcwd(path, MAXPATHLEN))
return NS_ERROR_FAILURE;
#endif
#if !defined(XP_WIN)
return NS_NewNativeLocalFile(nsDependentCString(path),
true,
aFile);
#endif
case OS_DriveDirectory:
#if defined (XP_WIN)
{
int32_t len = ::GetWindowsDirectoryW(path, MAX_PATH);
if (len == 0)
break;
if (path[1] == PRUnichar(':') && path[2] == PRUnichar('\\'))
path[3] = 0;
return NS_NewLocalFile(nsDependentString(path),
true,
aFile);
}
#else
return NS_NewNativeLocalFile(nsDependentCString("/"),
true,
aFile);
#endif
case OS_TemporaryDirectory:
#if defined (XP_WIN)
{
DWORD len = ::GetTempPathW(MAX_PATH, path);
if (len == 0)
break;
return NS_NewLocalFile(nsDependentString(path, len),
true,
aFile);
}
#elif defined(MOZ_WIDGET_COCOA)
{
return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
}
#elif defined(XP_UNIX)
{
static const char *tPath = nullptr;
if (!tPath) {
tPath = PR_GetEnv("PANDORATMP");
if (!tPath) {
tPath = PR_GetEnv("TMPDIR");
if (!tPath || !*tPath) {
tPath = PR_GetEnv("TMP");
if (!tPath || !*tPath) {
tPath = PR_GetEnv("TEMP");
if (!tPath || !*tPath) {
tPath = "/tmp/";
}
}
}
}
}
return NS_NewNativeLocalFile(nsDependentCString(tPath),
true,
aFile);
}
#else
break;
#endif
#if defined (XP_WIN)
case Win_SystemDirectory:
{
int32_t len = ::GetSystemDirectoryW(path, MAX_PATH);
// Need enough space to add the trailing backslash
if (!len || len > MAX_PATH - 2)
break;
path[len] = L'\\';
path[++len] = L'\0';
//.........这里部分代码省略.........
开发者ID:dimag0g,项目名称:Pale-Moon,代码行数:101,代码来源:SpecialSystemDirectory.cpp
示例15: NS_ENSURE_ARG_POINTER
//----------------------------------------------------------------------------------------
// GetProductDirectory - Gets the directory which contains the application data folder
//
// UNIX : ~/.mozilla/
// WIN : <Application Data folder on user's machine>\Mozilla
// Mac : :Documents:Mozilla:
//----------------------------------------------------------------------------------------
NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFile, PRBool aLocal)
{
NS_ENSURE_ARG_POINTER(aLocalFile);
nsresult rv;
PRBool exists;
nsCOMPtr<nsILocalFile> localDir;
#if defined(XP_MACOSX)
FSRef fsRef;
OSType folderType = aLocal ? kCachedDataFolderType : kDomainLibraryFolderType;
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
if (err) return NS_ERROR_FAILURE;
NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localDir));
if (!localDir) return NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFileMac> localDirMac(do_QueryInterface(localDir));
rv = localDirMac->InitWithFSRef(&fsRef);
if (NS_FAILED(rv)) return rv;
#elif defined(XP_OS2)
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = directoryService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
if (NS_FAILED(rv)) return rv;
#elif defined(XP_WIN)
nsCOMPtr<nsIProperties> directoryService =
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
const char* prop = aLocal ? NS_WIN_LOCAL_APPDATA_DIR : NS_WIN_APPDATA_DIR;
rv = directoryService->Get(prop, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
if (NS_SUCCEEDED(rv))
rv = localDir->Exists(&exists);
if (NS_FAILED(rv) || !exists)
{
// On some Win95 machines, NS_WIN_APPDATA_DIR does not exist - revert to NS_WIN_WINDOWS_DIR
localDir = nsnull;
rv = directoryService->Get(NS_WIN_WINDOWS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir));
}
if (NS_FAILED(rv)) return rv;
#elif defined(XP_UNIX)
rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), PR_TRUE, getter_AddRefs(localDir));
if (NS_FAILED(rv)) return rv;
#elif defined(XP_BEOS)
char path[MAXPATHLEN];
find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, path, MAXPATHLEN);
// Need enough space to add the trailing backslash
int len = strlen(path);
if (len > MAXPATHLEN-2)
return NS_ERROR_FAILURE;
path[len] = '/';
path[len+1] = '\0';
rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_TRUE, getter_AddRefs(localDir));
if (NS_FAILED(rv)) return rv;
#else
#error dont_know_how_to_get_product_dir_on_your_platform
#endif
rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR);
if (NS_FAILED(rv)) return rv;
rv = localDir->Exists(&exists);
if (NS_SUCCEEDED(rv) && !exists)
rv = localDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
if (NS_FAILED(rv)) return rv;
*aLocalFile = localDir;
NS_ADDREF(*aLocalFile);
return rv;
}
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:78,代码来源:nsAppFileLocationProvider.cpp
示例16: PR_NewLock
nsresult
MediaEngineWebRTCVideoSource::Snapshot(PRUint32 aDuration, nsIDOMFile** aFile)
{
/**
* To get a Snapshot we do the following:
* - Set a condition variable (mInSnapshotMode) to true
* - Attach the external renderer and start the camera
* - Wait for the condition variable to change to false
*
* Starting the camera has the effect of invoking DeliverFrame() when
* the first frame arrives from the camera. We only need one frame for
* GetCaptureDeviceSnapshot to work, so we immediately set the condition
* variable to false and notify this method.
*
* This causes the current thread to continue (PR_CondWaitVar will return),
* at which point we can grab a snapshot, convert it to a file and
* return from this function after cleaning up the temporary stream object
* and caling Stop() on the media source.
*/
*aFile = nsnull;
if (!mInitDone || mState != kAllocated) {
return NS_ERROR_FAILURE;
}
mSnapshotLock = PR_NewLock();
mSnapshotCondVar = PR_NewCondVar(mSnapshotLock);
PR_Lock(mSnapshotLock);
mInSnapshotMode = true;
// Start the rendering (equivalent to calling Start(), but without a track).
int error = 0;
if (!mInitDone || mState != kAllocated) {
return NS_ERROR_FAILURE;
}
error = mViERender->AddRenderer(mCapIndex, webrtc::kVideoI420, (webrtc::ExternalRenderer*)this);
if (error == -1) {
return NS_ERROR_FAILURE;
}
error = mViERender->StartRender(mCapIndex);
if (error == -1) {
return NS_ERROR_FAILURE;
}
// Wait for the condition variable, will be set in DeliverFrame.
// We use a while loop, because even if PR_WaitCondVar returns, it's not
// guaranteed that the condition variable changed.
while (mInSnapshotMode) {
PR_WaitCondVar(mSnapshotCondVar, PR_INTERVAL_NO_TIMEOUT);
}
// If we get here, DeliverFrame received at least one frame.
PR_Unlock(mSnapshotLock);
PR_DestroyCondVar(mSnapshotCondVar);
PR_DestroyLock(mSnapshotLock);
webrtc::ViEFile* vieFile = webrtc::ViEFile::GetInterface(mVideoEngine);
if (!vieFile) {
return NS_ERROR_FAILURE;
}
// Create a temporary file on the main thread and put the snapshot in it.
// See Run() in MediaEngineWebRTCVideo.h (sets mSnapshotPath).
NS_DispatchToMainThread(this, NS_DISPATCH_SYNC);
if (!mSnapshotPath) {
return NS_ERROR_FAILURE;
}
const char* path = NS_ConvertUTF16toUTF8(*mSnapshotPath).get();
if (vieFile->GetCaptureDeviceSnapshot(mCapIndex, path) < 0) {
delete mSnapshotPath;
mSnapshotPath = NULL;
return NS_ERROR_FAILURE;
}
// Stop the camera.
mViERender->StopRender(mCapIndex);
mViERender->RemoveRenderer(mCapIndex);
nsCOMPtr<nsIFile> file;
nsresult rv = NS_NewLocalFile(*mSnapshotPath, false, getter_AddRefs(file));
delete mSnapshotPath;
mSnapshotPath = NULL;
NS_ENSURE_SUCCESS(rv, rv);
NS_ADDREF(*aFile = new nsDOMFileFile(file));
return NS_OK;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:92,代码来源:MediaEngineWebRTCVideo.cpp
示例17: defined
nsresult
nsXREDirProvider::GetUserDataDirectoryHome(nsIFile** aFile, bool aLocal)
{
// Copied from nsAppFileLocationProvider (more or less)
nsresult rv;
nsCOMPtr<nsIFile> localDir;
#if defined(XP_MACOSX)
FSRef fsRef;
OSType folderType;
if (aLocal) {
folderType = kCachedDataFolderType;
} else {
#ifdef MOZ_THUNDERBIRD
folderType = kDomainLibraryFolderType;
#else
folderType = kApplicationSupportFolderType;
#endif
}
OSErr err = ::FSFindFolder(kUserDomain, folderType, kCreateFolder, &fsRef);
NS_ENSURE_FALSE(err, NS_ERROR_FAILURE);
rv = NS_NewNativeLocalFile(EmptyCString(), true, getter_AddRefs(localDir));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILocalFileMac> dirFileMac = do_QueryInterface(localDir);
NS_ENSURE_TRUE(dirFileMac, NS_ERROR_UNEXPECTED);
rv = dirFileMac->InitWithFSRef(&fsRef);
NS_ENSURE_SUCCESS(rv, rv);
localDir = do_QueryInterface(dirFileMac, &rv);
#elif defined(XP_WIN)
nsString path;
if (aLocal) {
rv = GetShellFolderPath(CSIDL_LOCAL_APPDATA, path);
if (NS_FAILED(rv))
rv = GetRegWindowsAppDataFolder(aLocal, path);
}
if (!aLocal || NS_FAILED(rv)) {
rv = GetShellFolderPath(CSIDL_APPDATA, path);
if (NS_FAILED(rv)) {
if (!aLocal)
rv = GetRegWindowsAppDataFolder(aLocal, path);
}
}
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewLocalFile(path, true, getter_AddRefs(localDir));
#elif defined(XP_OS2)
#if 0 /* For OS/2 we want to always use MOZILLA_HOME */
// we want an environment variable of the form
// FIREFOX_HOME, etc
if (!gAppData)
return NS_ERROR_FAILURE;
nsDependentCString envVar(nsDependentCString(gAppData->name));
envVar.Append("_HOME");
char *pHome = getenv(envVar.get());
#endif
char *pHome = getenv("MOZILLA_HOME");
if (pHome && *pHome) {
rv = NS_NewNativeLocalFile(nsDependentCString(pHome), true,
getter_AddRefs(localDir));
} else {
PPIB ppib;
PTIB ptib;
char appDir[CCHMAXPATH];
DosGetInfoBlocks(&ptib, &ppib);
DosQueryModuleName(ppib->pib_hmte, CCHMAXPATH, appDir);
*strrchr(appDir, '\\') = '\0';
rv = NS_NewNativeLocalFile(nsDependentCString(appDir), true, getter_AddRefs(localDir));
}
#elif defined(MOZ_WIDGET_GONK)
rv = NS_NewNativeLocalFile(NS_LITERAL_CSTRING("/data/b2g"), true,
getter_AddRefs(localDir));
#elif defined(XP_UNIX)
const char* homeDir = getenv("HOME");
if (!homeDir || !*homeDir)
return NS_ERROR_FAILURE;
#ifdef ANDROID /* We want (ProfD == ProfLD) on Android. */
aLocal = false;
#endif
if (aLocal) {
// If $XDG_CACHE_HOME is defined use it, otherwise use $HOME/.cache.
const char* cacheHome = getenv("XDG_CACHE_HOME");
if (cacheHome && *cacheHome) {
rv = NS_NewNativeLocalFile(nsDependentCString(cacheHome), true,
getter_AddRefs(localDir));
} else {
rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
getter_AddRefs(localDir));
if (NS_SUCCEEDED(rv))
rv = localDir->AppendNative(NS_LITERAL_CSTRING(".cache"));
}
} else {
rv = NS_NewNativeLocalFile(nsDependentCString(homeDir), true,
getter_AddRefs(localDir));
//.........这里部分代码省略.........
开发者ID:julianpistorius,项目名称:gp-revolution-gecko,代码行数:101,代码来源:nsXREDirProvider.cpp
|
请发表评论