зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1240892 - Disable default-app hash storage. r=dolske
This commit is contained in:
Родитель
efb0e5df11
Коммит
d07d8912ea
|
@ -86,38 +86,6 @@ OpenKeyForReading(HKEY aKeyRoot, const nsAString& aKeyName, HKEY* aKey)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static bool
|
||||
GetPrefString(const nsCString& aPrefName, nsAString& aValue)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (!prefs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsAutoCString prefCStr;
|
||||
nsresult rv = prefs->GetCharPref(aPrefName.get(),
|
||||
getter_Copies(prefCStr));
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
CopyUTF8toUTF16(prefCStr, aValue);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
SetPrefString(const nsCString& aPrefName, const nsString& aValue)
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (!prefs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsresult rv = prefs->SetCharPref(aPrefName.get(),
|
||||
NS_ConvertUTF16toUTF8(aValue).get());
|
||||
return NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Default Browser Registry Settings
|
||||
//
|
||||
|
@ -376,145 +344,7 @@ IsAARDefault(const RefPtr<IApplicationAssociationRegistration>& pAAR,
|
|||
}
|
||||
|
||||
static void
|
||||
GetUserChoiceKeyName(LPCWSTR aClassName, bool aIsProtocol,
|
||||
nsAString& aKeyName)
|
||||
{
|
||||
aKeyName.AssignLiteral(aIsProtocol
|
||||
? "Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\"
|
||||
: "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\");
|
||||
aKeyName.Append(aClassName);
|
||||
aKeyName.AppendLiteral("\\UserChoice");
|
||||
}
|
||||
|
||||
static void
|
||||
GetHashPrefName(LPCWSTR aClassName, nsACString& aPrefName)
|
||||
{
|
||||
aPrefName.AssignLiteral("browser.shell.associationHash.");
|
||||
aPrefName.Append(NS_ConvertUTF16toUTF8(*aClassName == L'.' ? aClassName + 1
|
||||
: aClassName));
|
||||
}
|
||||
|
||||
static bool
|
||||
SaveWin8RegistryHash(const RefPtr<IApplicationAssociationRegistration>& pAAR,
|
||||
LPCWSTR aClassName)
|
||||
{
|
||||
bool isProtocol = *aClassName != L'.';
|
||||
bool isDefault = IsAARDefault(pAAR, aClassName);
|
||||
// We can save the value only if Firefox is the default.
|
||||
if (!isDefault) {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
nsAutoString keyName;
|
||||
GetUserChoiceKeyName(aClassName, isProtocol, keyName);
|
||||
|
||||
nsCOMPtr<nsIWindowsRegKey> regKey =
|
||||
do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
||||
if (!regKey) {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
||||
keyName, nsIWindowsRegKey::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
nsAutoString hash;
|
||||
rv = regKey->ReadStringValue(NS_LITERAL_STRING("Hash"), hash);
|
||||
if (NS_FAILED(rv)) {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
nsAutoCString prefName;
|
||||
GetHashPrefName(aClassName, prefName);
|
||||
SetPrefString(prefName, hash);
|
||||
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
static bool
|
||||
RestoreWin8RegistryHash(const RefPtr<IApplicationAssociationRegistration>& pAAR,
|
||||
LPCWSTR aClassName)
|
||||
{
|
||||
nsAutoCString prefName;
|
||||
GetHashPrefName(aClassName, prefName);
|
||||
nsAutoString hash;
|
||||
if (!GetPrefString(prefName, hash)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isProtocol = *aClassName != L'.';
|
||||
nsString progId = isProtocol ? NS_LITERAL_STRING("FirefoxURL")
|
||||
: NS_LITERAL_STRING("FirefoxHTML");
|
||||
|
||||
nsAutoString keyName;
|
||||
GetUserChoiceKeyName(aClassName, isProtocol, keyName);
|
||||
|
||||
nsCOMPtr<nsIWindowsRegKey> regKey =
|
||||
do_CreateInstance("@mozilla.org/windows-registry-key;1");
|
||||
if (!regKey) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
||||
keyName, nsIWindowsRegKey::ACCESS_READ);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoString currValue;
|
||||
if (NS_SUCCEEDED(regKey->ReadStringValue(NS_LITERAL_STRING("Hash"),
|
||||
currValue)) &&
|
||||
currValue.Equals(hash) &&
|
||||
NS_SUCCEEDED(regKey->ReadStringValue(NS_LITERAL_STRING("ProgId"),
|
||||
currValue)) &&
|
||||
currValue.Equals(progId)) {
|
||||
// The value is already set.
|
||||
return true;
|
||||
}
|
||||
// We need to close this explicitly because nsIWindowsRegKey::SetKey
|
||||
// does not close the old key.
|
||||
regKey->Close();
|
||||
}
|
||||
|
||||
// We have to use the registry function directly because
|
||||
// nsIWindowsRegKey::Create will only return NS_ERROR_FAILURE
|
||||
// on failure.
|
||||
HKEY theKey;
|
||||
DWORD res = ::RegOpenKeyExW(HKEY_CURRENT_USER, keyName.get(), 0,
|
||||
KEY_READ | KEY_SET_VALUE, &theKey);
|
||||
if (REG_FAILED(res)) {
|
||||
if (res != ERROR_ACCESS_DENIED && res != ERROR_FILE_NOT_FOUND) {
|
||||
return false;
|
||||
}
|
||||
if (res == ERROR_ACCESS_DENIED) {
|
||||
res = ::RegDeleteKeyW(HKEY_CURRENT_USER, keyName.get());
|
||||
if (REG_FAILED(res)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
res = ::RegCreateKeyExW(HKEY_CURRENT_USER, keyName.get(), 0,
|
||||
nullptr, 0, KEY_READ | KEY_SET_VALUE,
|
||||
nullptr, &theKey, nullptr);
|
||||
if (REG_FAILED(res)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
regKey->SetKey(theKey);
|
||||
|
||||
rv = regKey->WriteStringValue(NS_LITERAL_STRING("Hash"), hash);
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rv = regKey->WriteStringValue(NS_LITERAL_STRING("ProgId"), progId);
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsAARDefault(pAAR, aClassName);
|
||||
}
|
||||
|
||||
static void
|
||||
SaveWin8RegistryHashes(bool aCheckAllTypes, bool* aIsDefaultBrowser)
|
||||
IsDefaultBrowserWin8(bool aCheckAllTypes, bool* aIsDefaultBrowser)
|
||||
{
|
||||
RefPtr<IApplicationAssociationRegistration> pAAR;
|
||||
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
|
||||
|
@ -526,48 +356,14 @@ SaveWin8RegistryHashes(bool aCheckAllTypes, bool* aIsDefaultBrowser)
|
|||
return;
|
||||
}
|
||||
|
||||
bool res = SaveWin8RegistryHash(pAAR, L"http");
|
||||
bool res = IsAARDefault(pAAR, L"http");
|
||||
if (*aIsDefaultBrowser) {
|
||||
*aIsDefaultBrowser = res;
|
||||
}
|
||||
SaveWin8RegistryHash(pAAR, L"https");
|
||||
SaveWin8RegistryHash(pAAR, L"ftp");
|
||||
res = SaveWin8RegistryHash(pAAR, L".html");
|
||||
res = IsAARDefault(pAAR, L".html");
|
||||
if (*aIsDefaultBrowser && aCheckAllTypes) {
|
||||
*aIsDefaultBrowser = res;
|
||||
}
|
||||
SaveWin8RegistryHash(pAAR, L".htm");
|
||||
SaveWin8RegistryHash(pAAR, L".shtml");
|
||||
SaveWin8RegistryHash(pAAR, L".xhtml");
|
||||
SaveWin8RegistryHash(pAAR, L".xht");
|
||||
}
|
||||
|
||||
static bool
|
||||
RestoreWin8RegistryHashes(bool aClaimAllTypes)
|
||||
{
|
||||
RefPtr<IApplicationAssociationRegistration> pAAR;
|
||||
HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
|
||||
nullptr,
|
||||
CLSCTX_INPROC,
|
||||
IID_IApplicationAssociationRegistration,
|
||||
getter_AddRefs(pAAR));
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool res = RestoreWin8RegistryHash(pAAR, L"http");
|
||||
res = RestoreWin8RegistryHash(pAAR, L"https") && res;
|
||||
RestoreWin8RegistryHash(pAAR, L"ftp");
|
||||
bool res2 = RestoreWin8RegistryHash(pAAR, L".html");
|
||||
res2 = RestoreWin8RegistryHash(pAAR, L".htm") && res2;
|
||||
if (aClaimAllTypes) {
|
||||
res = res && res2;
|
||||
}
|
||||
RestoreWin8RegistryHash(pAAR, L".shtml");
|
||||
RestoreWin8RegistryHash(pAAR, L".xhtml");
|
||||
RestoreWin8RegistryHash(pAAR, L".xht");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -695,7 +491,7 @@ nsWindowsShellService::IsDefaultBrowser(bool aStartupCheck,
|
|||
if (*aIsDefaultBrowser) {
|
||||
IsDefaultBrowserVista(aForAllTypes, aIsDefaultBrowser);
|
||||
if (IsWin8OrLater()) {
|
||||
SaveWin8RegistryHashes(aForAllTypes, aIsDefaultBrowser);
|
||||
IsDefaultBrowserWin8(aForAllTypes, aIsDefaultBrowser);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -924,8 +720,7 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
|
|||
}
|
||||
|
||||
nsresult rv = LaunchHelper(appHelperPath);
|
||||
if (NS_SUCCEEDED(rv) && IsWin8OrLater() &&
|
||||
!RestoreWin8RegistryHashes(aClaimAllTypes)) {
|
||||
if (NS_SUCCEEDED(rv) && IsWin8OrLater()) {
|
||||
if (aClaimAllTypes) {
|
||||
if (IsWin10OrLater()) {
|
||||
rv = LaunchModernSettingsDialogDefaultApps();
|
||||
|
@ -955,8 +750,6 @@ nsWindowsShellService::SetDefaultBrowser(bool aClaimAllTypes, bool aForAllUsers)
|
|||
if (NS_FAILED(rv)) {
|
||||
rv = LaunchControlPanelDefaultsSelectionUI();
|
||||
}
|
||||
bool isDefault;
|
||||
SaveWin8RegistryHashes(aClaimAllTypes, &isDefault);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1733,12 +1733,8 @@ this.UITour = {
|
|||
appinfo["defaultBrowser"] = isDefaultBrowser;
|
||||
|
||||
let canSetDefaultBrowserInBackground = true;
|
||||
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) {
|
||||
let prefBranch =
|
||||
Services.prefs.getBranch("browser.shell.associationHash");
|
||||
let prefChildren = prefBranch.getChildList("");
|
||||
canSetDefaultBrowserInBackground = prefChildren.length > 0;
|
||||
} else if (AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")) {
|
||||
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2") ||
|
||||
AppConstants.isPlatformAndVersionAtLeast("macosx", "10.10")) {
|
||||
canSetDefaultBrowserInBackground = false;
|
||||
} else if (AppConstants.platform == "linux") {
|
||||
// The ShellService may not exist on some versions of Linux.
|
||||
|
|
|
@ -65,31 +65,4 @@ var tests = [
|
|||
done();
|
||||
});
|
||||
}),
|
||||
|
||||
taskify(function* test_setInBackgroundWhenPrefExists(done) {
|
||||
Services.prefs.setCharPref("browser.shell.associationHash.http", "ABCDEFG");
|
||||
gContentAPI.getConfiguration("appinfo", (data) => {
|
||||
let canSetInBackground = true;
|
||||
is(canSetInBackground, data.canSetDefaultBrowserInBackground,
|
||||
"canSetDefaultBrowserInBackground should be true when a hash is present");
|
||||
Services.prefs.clearUserPref("browser.shell.associationHash.http");
|
||||
done();
|
||||
});
|
||||
}),
|
||||
|
||||
taskify(function* test_setInBackgroundWhenPrefDoesntExist(done) {
|
||||
/* The association hashes are only supported on Windows. */
|
||||
Cu.import("resource://gre/modules/AppConstants.jsm");
|
||||
if (AppConstants.platform != "win") {
|
||||
info("Skipping test_setInBackgroundWhenPrefDoesntExist on non-Windows platform");
|
||||
return;
|
||||
}
|
||||
|
||||
gContentAPI.getConfiguration("appinfo", (data) => {
|
||||
let canSetInBackground = false;
|
||||
is(canSetInBackground, data.canSetDefaultBrowserInBackground,
|
||||
"canSetDefaultBrowserInBackground should be false when no hashes are present");
|
||||
done();
|
||||
});
|
||||
})
|
||||
];
|
||||
|
|
Загрузка…
Ссылка в новой задаче