本文整理汇总了C++中nsCOMPtr::Create方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCOMPtr::Create方法的具体用法?C++ nsCOMPtr::Create怎么用?C++ nsCOMPtr::Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCOMPtr
的用法示例。
在下文中一共展示了nsCOMPtr::Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetOutputIconPath
// (static) Obtains the ICO file for the favicon at page aFaviconPageURI
// If successful, the file path on disk is in the format:
// <ProfLDS>\jumpListCache\<hash(aFaviconPageURI)>.ico
nsresult JumpListShortcut::GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
nsCOMPtr<nsIFile> &aICOFile)
{
// Hash the input URI and replace any / with _
nsCAutoString inputURIHash;
nsCOMPtr<nsICryptoHash> cryptoHash;
nsresult rv = JumpListItem::HashURI(cryptoHash, aFaviconPageURI,
inputURIHash);
NS_ENSURE_SUCCESS(rv, rv);
char* cur = inputURIHash.BeginWriting();
char* end = inputURIHash.EndWriting();
for (; cur < end; ++cur) {
if ('/' == *cur) {
*cur = '_';
}
}
// Obtain the local profile directory and construct the output icon file path
rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(aICOFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = aICOFile->AppendNative(nsDependentCString(JumpListItem::kJumpListCacheDir));
NS_ENSURE_SUCCESS(rv, rv);
// Try to create the directory if it's not there yet
rv = aICOFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS) {
return rv;
}
// Append the icon extension
inputURIHash.Append(".ico");
rv = aICOFile->AppendNative(inputURIHash);
return rv;
}
示例2: InitEmbedding
//.........这里部分代码省略.........
{"XRE_NotifyProfile", (NSFuncPtr*)&XRE_NotifyProfile},
{"XRE_LockProfileDirectory", (NSFuncPtr*)&XRE_LockProfileDirectory},
{0, 0}
};
rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv)) {
cerr << "Could not load XUL functions." << endl;
return 4;
}
// strip the filename from xpcom so we have the dir instead
size_t lastslash = xpcomPath.find_last_of("/\\");
if (lastslash == string::npos) {
cerr << "Invalid path to xpcom:" << xpcomPath << "." << endl;
return 3;
}
string xpcomDir = xpcomPath.substr(0, lastslash);
// create nsILocalFile pointing to xpcomDir
nsCOMPtr<nsILocalFile> xuldir;
rv = NS_NewNativeLocalFile(nsCString(xpcomDir.c_str()), PR_FALSE,
getter_AddRefs(xuldir));
if (NS_FAILED(rv)) {
cerr << "Unable to create nsILocalFile for xuldir " << xpcomDir
<< "." << endl;
return 6;
}
// create nsILocalFile pointing to appdir
char self[MAX_PATH];
#ifdef WIN32
GetModuleFileNameA(GetModuleHandle(NULL), self, sizeof(self));
#else
// TODO: works on linux, need solution for unices which do not support this
ssize_t len;
if ((len = readlink("/proc/self/exe", self, sizeof(self)-1)) != -1)
self[len] = '\0';
#endif
string selfPath(self);
lastslash = selfPath.find_last_of("/\\");
if (lastslash == string::npos) {
cerr << "Invalid module filename: " << self << "." << endl;
return 7;
}
selfPath = selfPath.substr(0, lastslash);
nsCOMPtr<nsILocalFile> appdir;
rv = NS_NewNativeLocalFile(nsCString(selfPath.c_str()), PR_FALSE,
getter_AddRefs(appdir));
if (NS_FAILED(rv)) {
cerr << "Unable to create nsILocalFile for appdir." << endl;
return 8;
}
// setup profile dir
nsCString pr(aProfilePath);
if (!pr.IsEmpty()) {
rv = NS_NewNativeLocalFile(pr, PR_FALSE,
getter_AddRefs(sProfileDir));
NS_ENSURE_SUCCESS(rv, rv);
} else {
// for now use a subdir under appdir
nsCOMPtr<nsIFile> profFile;
rv = appdir->Clone(getter_AddRefs(profFile));
NS_ENSURE_SUCCESS(rv, rv);
sProfileDir = do_QueryInterface(profFile);
sProfileDir->AppendNative(NS_LITERAL_CSTRING("mozembed"));
}
// create dir if needed
PRBool dirExists;
rv = sProfileDir->Exists(&dirExists);
NS_ENSURE_SUCCESS(rv, rv);
if (!dirExists) {
sProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
}
// Lock profile directory
if (sProfileDir && !sProfileLock) {
rv = XRE_LockProfileDirectory(sProfileDir, &sProfileLock);
NS_ENSURE_SUCCESS(rv, rv);
}
// init embedding
rv = XRE_InitEmbedding2(xuldir, appdir,
const_cast<MozEmbedDirectoryProvider*>(&kDirectoryProvider));
if (NS_FAILED(rv)) {
cerr << "XRE_InitEmbedding2 failed." << endl;
return 9;
}
// initialize profile:
XRE_NotifyProfile();
NS_LogTerm();
return NS_OK;
}
示例3: AssertIsOnIOThread
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;
}