NS_IMETHODIMP MozEmbedDirectoryProvider::GetFile(const char *aKey, PRBool *aPersist, nsIFile* *aResult) { if (sAppFileLocProvider) { nsresult rv = sAppFileLocProvider->GetFile(aKey, aPersist, aResult); if (NS_SUCCEEDED(rv)) return rv; } if (sProfileDir && !strcmp(aKey, NS_APP_USER_PROFILE_50_DIR)) { *aPersist = PR_TRUE; return sProfileDir->Clone(aResult); } if (sProfileDir && !strcmp(aKey, NS_APP_PROFILE_DIR_STARTUP)) { *aPersist = PR_TRUE; return sProfileDir->Clone(aResult); } if (sProfileDir && !strcmp(aKey, NS_APP_CACHE_PARENT_DIR)) { *aPersist = PR_TRUE; return sProfileDir->Clone(aResult); } return NS_ERROR_FAILURE; }
NS_IMETHODIMP XPCShellDirProvider::GetFile(const char* prop, bool* persistent, nsIFile* *result) { if (mGREDir && !strcmp(prop, NS_GRE_DIR)) { *persistent = true; return mGREDir->Clone(result); } else if (mGREBinDir && !strcmp(prop, NS_GRE_BIN_DIR)) { *persistent = true; return mGREBinDir->Clone(result); } else if (mAppFile && !strcmp(prop, XRE_EXECUTABLE_FILE)) { *persistent = true; return mAppFile->Clone(result); } else if (mGREDir && !strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR)) { nsCOMPtr<nsIFile> file; *persistent = true; if (NS_FAILED(mGREDir->Clone(getter_AddRefs(file))) || NS_FAILED(file->AppendNative(NS_LITERAL_CSTRING("defaults"))) || NS_FAILED(file->AppendNative(NS_LITERAL_CSTRING("pref")))) return NS_ERROR_FAILURE; file.forget(result); return NS_OK; } return NS_ERROR_FAILURE; }
NS_IMETHODIMP XPCShellDirProvider::GetFiles(const char* prop, nsISimpleEnumerator* *result) { if (mGREDir && !strcmp(prop, "ChromeML")) { nsCOMArray<nsIFile> dirs; nsCOMPtr<nsIFile> file; mGREDir->Clone(getter_AddRefs(file)); file->AppendNative(NS_LITERAL_CSTRING("chrome")); dirs.AppendObject(file); nsresult rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) dirs.AppendObject(file); return NS_NewArrayEnumerator(result, dirs); } else if (!strcmp(prop, NS_APP_PREFS_DEFAULTS_DIR_LIST)) { nsCOMArray<nsIFile> dirs; nsCOMPtr<nsIFile> appDir; bool exists; if (mAppDir && NS_SUCCEEDED(mAppDir->Clone(getter_AddRefs(appDir))) && NS_SUCCEEDED(appDir->AppendNative(NS_LITERAL_CSTRING("defaults"))) && NS_SUCCEEDED(appDir->AppendNative(NS_LITERAL_CSTRING("preferences"))) && NS_SUCCEEDED(appDir->Exists(&exists)) && exists) { dirs.AppendObject(appDir); return NS_NewArrayEnumerator(result, dirs); } return NS_ERROR_FAILURE; } else if (!strcmp(prop, NS_APP_PLUGINS_DIR_LIST)) { nsCOMArray<nsIFile> dirs; // Add the test plugin location passed in by the caller or through // runxpcshelltests. if (mPluginDir) { dirs.AppendObject(mPluginDir); // If there was no path specified, default to the one set up by automation } else { nsCOMPtr<nsIFile> file; bool exists; // We have to add this path, buildbot copies the test plugin directory // to (app)/bin when unpacking test zips. if (mGREDir) { mGREDir->Clone(getter_AddRefs(file)); if (NS_SUCCEEDED(mGREDir->Clone(getter_AddRefs(file)))) { file->AppendNative(NS_LITERAL_CSTRING("plugins")); if (NS_SUCCEEDED(file->Exists(&exists)) && exists) { dirs.AppendObject(file); } } } } return NS_NewArrayEnumerator(result, dirs); } return NS_ERROR_FAILURE; }
static bool GetFileBase(const nsAString& aPluginPath, nsCOMPtr<nsIFile>& aLibDirectory, nsCOMPtr<nsIFile>& aFileBase, nsAutoString& aBaseName) { nsresult rv = NS_NewLocalFile(aPluginPath, true, getter_AddRefs(aFileBase)); if (NS_FAILED(rv)) { return false; } if (NS_FAILED(aFileBase->Clone(getter_AddRefs(aLibDirectory)))) { return false; } 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; }
NS_IMETHODIMP nsIncrementalDownload::GetDestination(nsIFile **result) { if (!mDest) { *result = nullptr; return NS_OK; } // Return a clone of mDest so that callers may modify the resulting nsIFile // without corrupting our internal object. This also works around the fact // that some nsIFile impls may cache the result of stat'ing the filesystem. return mDest->Clone(result); }
void XPCShellDirProvider::SetGREDirs(nsIFile* greDir) { mGREDir = greDir; mGREDir->Clone(getter_AddRefs(mGREBinDir)); #ifdef XP_MACOSX nsAutoCString leafName; mGREDir->GetNativeLeafName(leafName); if (leafName.Equals("Resources")) { mGREBinDir->SetNativeLeafName(NS_LITERAL_CSTRING("MacOS")); } #endif }
void URLMainThread::SetProtocol(const nsAString& aProtocol, ErrorResult& aRv) { nsAString::const_iterator start, end; aProtocol.BeginReading(start); aProtocol.EndReading(end); nsAString::const_iterator iter(start); FindCharInReadable(':', iter, end); // Changing the protocol of a URL, changes the "nature" of the URI // implementation. In order to do this properly, we have to serialize the // existing URL and reparse it in a new object. nsCOMPtr<nsIURI> clone; nsresult rv = mURI->Clone(getter_AddRefs(clone)); if (NS_WARN_IF(NS_FAILED(rv)) || !clone) { return; } rv = clone->SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter))); if (NS_WARN_IF(NS_FAILED(rv))) { return; } nsAutoCString href; rv = clone->GetSpec(href); if (NS_WARN_IF(NS_FAILED(rv))) { return; } nsCOMPtr<nsIURI> uri; rv = NS_NewURI(getter_AddRefs(uri), href); if (NS_WARN_IF(NS_FAILED(rv))) { return; } mURI = uri; }
// Iterates over the files in the "path" directory, and adds subfolders to // parent for each mailbox file found. nsresult nsMsgBrkMBoxStore::AddSubFolders(nsIMsgFolder *parent, nsCOMPtr<nsIFile> &path, bool deep) { nsresult rv; nsCOMPtr<nsIFile> tmp; // at top level so we can safely assign to path bool isDirectory; path->IsDirectory(&isDirectory); if (!isDirectory) { rv = path->Clone(getter_AddRefs(tmp)); path = tmp; NS_ENSURE_SUCCESS(rv, rv); nsAutoString leafName; path->GetLeafName(leafName); leafName.AppendLiteral(".sbd"); path->SetLeafName(leafName); path->IsDirectory(&isDirectory); } if (!isDirectory) return NS_OK; // first find out all the current subfolders and files, before using them // while creating new subfolders; we don't want to modify and iterate the same // directory at once. nsCOMArray<nsIFile> currentDirEntries; nsCOMPtr<nsISimpleEnumerator> directoryEnumerator; rv = path->GetDirectoryEntries(getter_AddRefs(directoryEnumerator)); NS_ENSURE_SUCCESS(rv, rv); bool hasMore; while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) { nsCOMPtr<nsISupports> aSupport; directoryEnumerator->GetNext(getter_AddRefs(aSupport)); nsCOMPtr<nsIFile> currentFile(do_QueryInterface(aSupport, &rv)); if (currentFile) currentDirEntries.AppendObject(currentFile); } // add the folders int32_t count = currentDirEntries.Count(); for (int32_t i = 0; i < count; ++i) { nsCOMPtr<nsIFile> currentFile(currentDirEntries[i]); nsAutoString leafName; currentFile->GetLeafName(leafName); directoryEnumerator->HasMoreElements(&hasMore); // here we should handle the case where the current file is a .sbd directory // w/o a matching folder file, or a directory w/o the name .sbd if (nsShouldIgnoreFile(leafName)) continue; nsCOMPtr<nsIMsgFolder> child; rv = parent->AddSubfolder(leafName, getter_AddRefs(child)); if (child) { nsString folderName; child->GetName(folderName); // try to get it from cache/db if (folderName.IsEmpty()) child->SetPrettyName(leafName); if (deep) { nsCOMPtr<nsIFile> path; rv = child->GetFilePath(getter_AddRefs(path)); AddSubFolders(child, path, true); } } } return rv == NS_MSG_FOLDER_EXISTS ? NS_OK : rv; }
nsresult ParentRunnable::ReadMetadata() { AssertIsOnIOThread(); MOZ_ASSERT(mState == eReadyToReadMetadata); QuotaManager* qm = QuotaManager::Get(); MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread"); nsresult rv = qm->EnsureOriginIsInitialized(quota::PERSISTENCE_TYPE_TEMPORARY, mSuffix, mGroup, mOrigin, getter_AddRefs(mDirectory)); if (NS_WARN_IF(NS_FAILED(rv))) { mResult = JS::AsmJSCache_StorageInitFailure; return rv; } rv = mDirectory->Append(NS_LITERAL_STRING(ASMJSCACHE_DIRECTORY_NAME)); NS_ENSURE_SUCCESS(rv, rv); bool exists; rv = mDirectory->Exists(&exists); NS_ENSURE_SUCCESS(rv, rv); if (!exists) { rv = mDirectory->Create(nsIFile::DIRECTORY_TYPE, 0755); NS_ENSURE_SUCCESS(rv, rv); } else { DebugOnly<bool> isDirectory; MOZ_ASSERT(NS_SUCCEEDED(mDirectory->IsDirectory(&isDirectory))); MOZ_ASSERT(isDirectory, "Should have caught this earlier!"); } rv = mDirectory->Clone(getter_AddRefs(mMetadataFile)); NS_ENSURE_SUCCESS(rv, rv); rv = mMetadataFile->Append(NS_LITERAL_STRING(ASMJSCACHE_METADATA_FILE_NAME)); NS_ENSURE_SUCCESS(rv, rv); rv = mMetadataFile->Exists(&exists); NS_ENSURE_SUCCESS(rv, rv); if (exists && NS_FAILED(ReadMetadataFile(mMetadataFile, mMetadata))) { exists = false; } if (!exists) { // If we are reading, we can't possibly have a cache hit. if (mOpenMode == eOpenForRead) { return NS_ERROR_FILE_NOT_FOUND; } // Initialize Metadata with a valid empty state for the LRU cache. for (unsigned i = 0; i < Metadata::kNumEntries; i++) { Metadata::Entry& entry = mMetadata.mEntries[i]; entry.mModuleIndex = i; entry.clear(); } } return NS_OK; }