Merge pull request #11329 from electron/remove-classes-key
fix: Properly cleanup in `removeAsDefaultProtocolClient`
This commit is contained in:
commit
5fa29fcf58
3 changed files with 107 additions and 6 deletions
|
@ -153,15 +153,19 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|||
|
||||
// Main Registry Key
|
||||
HKEY root = HKEY_CURRENT_USER;
|
||||
base::string16 keyPath = base::UTF8ToUTF16("Software\\Classes\\" + protocol);
|
||||
base::string16 keyPath = L"Software\\Classes\\";
|
||||
|
||||
// Command Key
|
||||
base::string16 cmdPath = keyPath + L"\\shell\\open\\command";
|
||||
base::string16 wprotocol = base::UTF8ToUTF16(protocol);
|
||||
base::string16 shellPath = wprotocol + L"\\shell";
|
||||
base::string16 cmdPath = keyPath + shellPath + L"\\open\\command";
|
||||
|
||||
base::win::RegKey key;
|
||||
base::win::RegKey classesKey;
|
||||
base::win::RegKey commandKey;
|
||||
if (FAILED(key.Open(root, keyPath.c_str(), KEY_ALL_ACCESS)))
|
||||
// Key doesn't even exist, we can confirm that it is not set
|
||||
|
||||
if (FAILED(classesKey.Open(root, keyPath.c_str(), KEY_ALL_ACCESS)))
|
||||
// Classes key doesn't exist, that's concerning, but I guess
|
||||
// we're not the default handler
|
||||
return true;
|
||||
|
||||
if (FAILED(commandKey.Open(root, cmdPath.c_str(), KEY_ALL_ACCESS)))
|
||||
|
@ -179,9 +183,25 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
|
|||
|
||||
if (keyVal == exe) {
|
||||
// Let's kill the key
|
||||
if (FAILED(key.DeleteKey(L"shell")))
|
||||
if (FAILED(classesKey.DeleteKey(shellPath.c_str())))
|
||||
return false;
|
||||
|
||||
// Let's clean up after ourselves
|
||||
base::win::RegKey protocolKey;
|
||||
base::string16 protocolPath = keyPath + wprotocol;
|
||||
|
||||
if (SUCCEEDED(protocolKey
|
||||
.Open(root, protocolPath.c_str(), KEY_ALL_ACCESS))) {
|
||||
protocolKey.DeleteValue(L"URL Protocol");
|
||||
|
||||
// Overwrite the default value to be empty, we can't delete it right away
|
||||
protocolKey.WriteValue(L"", L"");
|
||||
protocolKey.DeleteValue(L"");
|
||||
}
|
||||
|
||||
// If now empty, delete the whole key
|
||||
classesKey.DeleteEmptyKey(wprotocol.c_str());
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue