| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
| 10 | 10 |
| 11 #include "app/win_util.h" | 11 #include "app/win_util.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 26 #include "chrome/installer/util/work_item.h" | 26 #include "chrome/installer/util/work_item.h" |
| 27 #include "chrome/installer/util/work_item_list.h" | 27 #include "chrome/installer/util/work_item_list.h" |
| 28 | 28 |
| 29 bool ShellIntegration::SetAsDefaultBrowser() { | 29 bool ShellIntegration::SetAsDefaultBrowser() { |
| 30 std::wstring chrome_exe; | 30 std::wstring chrome_exe; |
| 31 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 31 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 32 LOG(ERROR) << "Error getting app exe path"; | 32 LOG(ERROR) << "Error getting app exe path"; |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 | 35 |
| 36 ShellUtil::RegisterStatus register_status = | |
| 37 ShellUtil::AddChromeToSetAccessDefaults(chrome_exe, false); | |
| 38 if (register_status == ShellUtil::FAILURE) { | |
| 39 LOG(ERROR) << "Chrome could not be registered on the machine."; | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 // From UI currently we only allow setting default browser for current user. | 36 // From UI currently we only allow setting default browser for current user. |
| 44 if (!ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER, chrome_exe)) { | 37 if (!ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER, |
| 38 chrome_exe, true)) { |
| 45 LOG(ERROR) << "Chrome could not be set as default browser."; | 39 LOG(ERROR) << "Chrome could not be set as default browser."; |
| 46 return false; | 40 return false; |
| 47 } | 41 } |
| 48 | 42 |
| 49 LOG(INFO) << "Chrome registered as default browser."; | 43 LOG(INFO) << "Chrome registered as default browser."; |
| 50 return true; | 44 return true; |
| 51 } | 45 } |
| 52 | 46 |
| 53 bool ShellIntegration::IsDefaultBrowser() { | 47 bool ShellIntegration::IsDefaultBrowser() { |
| 54 // First determine the app path. If we can't determine what that is, we have | 48 // First determine the app path. If we can't determine what that is, we have |
| (...skipping 15 matching lines...) Expand all Loading... |
| 70 const std::wstring kChromeProtocols[] = {L"http", L"https"}; | 64 const std::wstring kChromeProtocols[] = {L"http", L"https"}; |
| 71 | 65 |
| 72 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { | 66 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { |
| 73 IApplicationAssociationRegistration* pAAR; | 67 IApplicationAssociationRegistration* pAAR; |
| 74 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, | 68 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
| 75 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), | 69 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), |
| 76 (void**)&pAAR); | 70 (void**)&pAAR); |
| 77 if (!SUCCEEDED(hr)) | 71 if (!SUCCEEDED(hr)) |
| 78 return false; | 72 return false; |
| 79 | 73 |
| 74 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 75 std::wstring app_name = dist->GetApplicationName(); |
| 76 std::wstring app_name_with_suffix; |
| 77 ShellUtil::GetUserSpecificDefaultBrowserSuffix(&app_name_with_suffix); |
| 78 app_name_with_suffix = app_name + app_name_with_suffix; |
| 80 for (int i = 0; i < _countof(kChromeProtocols); i++) { | 79 for (int i = 0; i < _countof(kChromeProtocols); i++) { |
| 81 BOOL result = TRUE; | 80 BOOL result = TRUE; |
| 82 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 83 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, | 81 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, |
| 84 AL_EFFECTIVE, dist->GetApplicationName().c_str(), &result); | 82 AL_EFFECTIVE, app_name_with_suffix.c_str(), &result); |
| 85 if (!SUCCEEDED(hr) || (result == FALSE)) { | 83 if (!SUCCEEDED(hr) || (result == FALSE)) { |
| 86 pAAR->Release(); | 84 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), |
| 87 return false; | 85 AT_URLPROTOCOL, AL_EFFECTIVE, app_name.c_str(), &result); |
| 86 if (!SUCCEEDED(hr) || (result == FALSE)) { |
| 87 pAAR->Release(); |
| 88 return false; |
| 89 } |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 pAAR->Release(); | 92 pAAR->Release(); |
| 91 } else { | 93 } else { |
| 92 std::wstring short_app_path; | 94 std::wstring short_app_path; |
| 93 GetShortPathName(app_path.c_str(), WriteInto(&short_app_path, MAX_PATH), | 95 GetShortPathName(app_path.c_str(), WriteInto(&short_app_path, MAX_PATH), |
| 94 MAX_PATH); | 96 MAX_PATH); |
| 95 | 97 |
| 96 // open command for protocol associations | 98 // open command for protocol associations |
| 97 for (int i = 0; i < _countof(kChromeProtocols); i++) { | 99 for (int i = 0; i < _countof(kChromeProtocols); i++) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 std::wstring key_path(L"http"); | 146 std::wstring key_path(L"http"); |
| 145 key_path.append(ShellUtil::kRegShellOpen); | 147 key_path.append(ShellUtil::kRegShellOpen); |
| 146 RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); | 148 RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); |
| 147 std::wstring app_cmd; | 149 std::wstring app_cmd; |
| 148 if (key.Valid() && key.ReadValue(L"", &app_cmd) && | 150 if (key.Valid() && key.ReadValue(L"", &app_cmd) && |
| 149 std::wstring::npos != StringToLowerASCII(app_cmd).find(L"firefox")) | 151 std::wstring::npos != StringToLowerASCII(app_cmd).find(L"firefox")) |
| 150 ff_default = true; | 152 ff_default = true; |
| 151 } | 153 } |
| 152 return ff_default; | 154 return ff_default; |
| 153 } | 155 } |
| OLD | NEW |