New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly cleanup in `removeAsDefaultProtocolClient` #11329

merged 10 commits into from Dec 6, 2017

🔧 Make it actually work

  • Loading branch information...
felixrieseberg committed Dec 4, 2017
commit f62e0a4ed438a4d34cfd91e644d2f644d75d32cf
Copy path View file
@@ -156,12 +156,14 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
base::string16 keyPath = L"Software\\Classes\\";
// Command Key
base::string16 protocol16 = base::UTF8ToUTF16(protocol);
base::string16 cmdPath = keyPath + protocol16 + 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)))
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;
@@ -180,11 +182,22 @@ bool Browser::RemoveAsDefaultProtocolClient(const std::string& protocol,
if (keyVal == exe) {
// Let's kill the key
if (FAILED(key.DeleteKey(protocol16 + L"shell")))
if (FAILED(classesKey.DeleteKey(shellPath.c_str())))
return false;
// If empty, delete
// 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"");
// If now empty, delete the whole key
return true;
} else {
ProTip! Use n and p to navigate between commits in a pull request.