forked from mirrors/gecko-dev
Bug 1758997 - Remove RoInitialize/RoUninitialize from OSPreferences_win. r=Jamie
As per bug 1757647 comment 4, the main thread already initializes COM early, and we should be able to rely on it in OSPreferences. Differential Revision: https://phabricator.services.mozilla.com/D140745
This commit is contained in:
parent
a1ba0b4ade
commit
1353b25e32
2 changed files with 31 additions and 45 deletions
|
|
@ -35,56 +35,43 @@ bool OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList) {
|
||||||
// Try to get language list from GlobalizationPreferences; if this fails,
|
// Try to get language list from GlobalizationPreferences; if this fails,
|
||||||
// we'll fall back to GetUserPreferredUILanguages.
|
// we'll fall back to GetUserPreferredUILanguages.
|
||||||
// Per MSDN, these APIs are not available prior to Win8.
|
// Per MSDN, these APIs are not available prior to Win8.
|
||||||
|
ComPtr<IGlobalizationPreferencesStatics> globalizationPrefs;
|
||||||
// RoInitialize may fail with "cannot change thread mode after it is set",
|
ComPtr<IVectorView<HSTRING>> languages;
|
||||||
// if the runtime was already initialized on this thread.
|
uint32_t count;
|
||||||
// This appears to be harmless, and we can proceed to attempt the following
|
if (SUCCEEDED(RoGetActivationFactory(
|
||||||
// runtime calls.
|
HStringReference(
|
||||||
HRESULT inited = RoInitialize(RO_INIT_MULTITHREADED);
|
RuntimeClass_Windows_System_UserProfile_GlobalizationPreferences)
|
||||||
if (SUCCEEDED(inited) || inited == RPC_E_CHANGED_MODE) {
|
.Get(),
|
||||||
ComPtr<IGlobalizationPreferencesStatics> globalizationPrefs;
|
IID_PPV_ARGS(&globalizationPrefs))) &&
|
||||||
ComPtr<IVectorView<HSTRING>> languages;
|
SUCCEEDED(globalizationPrefs->get_Languages(&languages)) &&
|
||||||
uint32_t count;
|
SUCCEEDED(languages->get_Size(&count))) {
|
||||||
if (SUCCEEDED(RoGetActivationFactory(
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
HStringReference(
|
HString lang;
|
||||||
RuntimeClass_Windows_System_UserProfile_GlobalizationPreferences)
|
if (SUCCEEDED(languages->GetAt(i, lang.GetAddressOf()))) {
|
||||||
.Get(),
|
unsigned int length;
|
||||||
IID_PPV_ARGS(&globalizationPrefs))) &&
|
const wchar_t* text = lang.GetRawBuffer(&length);
|
||||||
SUCCEEDED(globalizationPrefs->get_Languages(&languages)) &&
|
NS_LossyConvertUTF16toASCII loc(text, length);
|
||||||
SUCCEEDED(languages->get_Size(&count))) {
|
if (CanonicalizeLanguageTag(loc)) {
|
||||||
for (uint32_t i = 0; i < count; ++i) {
|
if (!loc.Contains('-')) {
|
||||||
HString lang;
|
// DirectWrite font-name code doesn't like to be given a bare
|
||||||
if (SUCCEEDED(languages->GetAt(i, lang.GetAddressOf()))) {
|
// language code with no region subtag, but the
|
||||||
unsigned int length;
|
// GlobalizationPreferences API may give us one (e.g. "ja").
|
||||||
const wchar_t* text = lang.GetRawBuffer(&length);
|
// So if there's no hyphen in the string at this point, we use
|
||||||
NS_LossyConvertUTF16toASCII loc(text, length);
|
// AddLikelySubtags to get a suitable region code to
|
||||||
if (CanonicalizeLanguageTag(loc)) {
|
// go with it.
|
||||||
if (!loc.Contains('-')) {
|
Locale locale;
|
||||||
// DirectWrite font-name code doesn't like to be given a bare
|
auto result = LocaleParser::TryParse(loc, locale);
|
||||||
// language code with no region subtag, but the
|
if (result.isOk() && locale.AddLikelySubtags().isOk() &&
|
||||||
// GlobalizationPreferences API may give us one (e.g. "ja").
|
locale.Region().Present()) {
|
||||||
// So if there's no hyphen in the string at this point, we use
|
loc.Append('-');
|
||||||
// AddLikelySubtags to get a suitable region code to
|
loc.Append(locale.Region().Span());
|
||||||
// go with it.
|
|
||||||
Locale locale;
|
|
||||||
auto result = LocaleParser::TryParse(loc, locale);
|
|
||||||
if (result.isOk() && locale.AddLikelySubtags().isOk() &&
|
|
||||||
locale.Region().Present()) {
|
|
||||||
loc.Append('-');
|
|
||||||
loc.Append(locale.Region().Span());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
aLocaleList.AppendElement(loc);
|
|
||||||
}
|
}
|
||||||
|
aLocaleList.AppendElement(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only close the runtime if we successfully initialized it above,
|
|
||||||
// otherwise we assume it was already in use and should be left as is.
|
|
||||||
if (SUCCEEDED(inited)) {
|
|
||||||
RoUninitialize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ forbid-mscom-init:
|
||||||
- browser/components/shell/nsWindowsShellService.cpp
|
- browser/components/shell/nsWindowsShellService.cpp
|
||||||
- gfx/thebes/gfxWindowsPlatform.cpp
|
- gfx/thebes/gfxWindowsPlatform.cpp
|
||||||
- image/DecodePool.cpp
|
- image/DecodePool.cpp
|
||||||
- intl/locale/windows/OSPreferences_win.cpp
|
|
||||||
- ipc/glue/BrowserProcessSubThread.cpp
|
- ipc/glue/BrowserProcessSubThread.cpp
|
||||||
- netwerk/system/win32/nsNotifyAddrListener.cpp
|
- netwerk/system/win32/nsNotifyAddrListener.cpp
|
||||||
- toolkit/components/parentalcontrols/nsParentalControlsServiceWin.cpp
|
- toolkit/components/parentalcontrols/nsParentalControlsServiceWin.cpp
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue