本文整理汇总了C++中nsAFlatString::First方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAFlatString::First方法的具体用法?C++ nsAFlatString::First怎么用?C++ nsAFlatString::First使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAFlatString
的用法示例。
在下文中一共展示了nsAFlatString::First方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assocType
already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFlatString& aFileExt, const char *aTypeHint)
{
if (aFileExt.IsEmpty())
return nullptr;
// windows registry assumes your file extension is going to include the '.'.
// so make sure it's there...
nsAutoString fileExtToUse;
if (aFileExt.First() != char16_t('.'))
fileExtToUse = char16_t('.');
fileExtToUse.Append(aFileExt);
// Try to get an entry from the windows registry.
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey)
return nullptr;
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
fileExtToUse,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv))
return nullptr;
nsAutoCString typeToUse;
if (aTypeHint && *aTypeHint) {
typeToUse.Assign(aTypeHint);
}
else {
nsAutoString temp;
if (NS_FAILED(regKey->ReadStringValue(NS_LITERAL_STRING("Content Type"),
temp)) || temp.IsEmpty()) {
return nullptr;
}
// Content-Type is always in ASCII
LossyAppendUTF16toASCII(temp, typeToUse);
}
nsRefPtr<nsMIMEInfoWin> mimeInfo = new nsMIMEInfoWin(typeToUse);
// don't append the '.'
mimeInfo->AppendExtension(NS_ConvertUTF16toUTF8(Substring(fileExtToUse, 1)));
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
nsAutoString appInfo;
bool found;
// Retrieve the default application for this extension
if (mAppAssoc) {
// Vista: use the new application association COM interfaces
// for resolving helpers.
nsString assocType(fileExtToUse);
wchar_t * pResult = nullptr;
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
AT_FILEEXTENSION, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
found = true;
appInfo.Assign(pResult);
CoTaskMemFree(pResult);
}
else {
found = false;
}
}
else
{
found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(),
appInfo));
}
// Bug 358297 - ignore the default handler, force the user to choose app
if (appInfo.EqualsLiteral("XPSViewer.Document"))
found = false;
if (!found) {
return nullptr;
}
// Get other nsIMIMEInfo fields from registry, if possible.
nsAutoString defaultDescription;
nsCOMPtr<nsIFile> defaultApplication;
if (NS_FAILED(GetDefaultAppInfo(appInfo, defaultDescription,
getter_AddRefs(defaultApplication)))) {
return nullptr;
}
mimeInfo->SetDefaultDescription(defaultDescription);
mimeInfo->SetDefaultApplicationHandler(defaultApplication);
// Grab the general description
GetMIMEInfoFromRegistry(appInfo, mimeInfo);
return mimeInfo.forget();
}