Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/browser/shell_integration_win.cc

Issue 200025: Allow the default browser check to return "unknown" and reflect that in the UI. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 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
(...skipping 26 matching lines...) Expand all
37 if (!ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER, 37 if (!ShellUtil::MakeChromeDefault(ShellUtil::CURRENT_USER,
38 chrome_exe, true)) { 38 chrome_exe, true)) {
39 LOG(ERROR) << "Chrome could not be set as default browser."; 39 LOG(ERROR) << "Chrome could not be set as default browser.";
40 return false; 40 return false;
41 } 41 }
42 42
43 LOG(INFO) << "Chrome registered as default browser."; 43 LOG(INFO) << "Chrome registered as default browser.";
44 return true; 44 return true;
45 } 45 }
46 46
47 bool ShellIntegration::IsDefaultBrowser() { 47 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() {
48 // 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
49 // bigger fish to fry... 49 // bigger fish to fry...
50 std::wstring app_path; 50 std::wstring app_path;
51 if (!PathService::Get(base::FILE_EXE, &app_path)) { 51 if (!PathService::Get(base::FILE_EXE, &app_path)) {
52 LOG(ERROR) << "Error getting app exe path"; 52 LOG(ERROR) << "Error getting app exe path";
53 return false; 53 return UNKNOWN_DEFAULT_BROWSER;
54 } 54 }
55 // When we check for default browser we don't necessarily want to count file 55 // When we check for default browser we don't necessarily want to count file
56 // type handlers and icons as having changed the default browser status, 56 // type handlers and icons as having changed the default browser status,
57 // since the user may have changed their shell settings to cause HTML files 57 // since the user may have changed their shell settings to cause HTML files
58 // to open with a text editor for example. We also don't want to aggressively 58 // to open with a text editor for example. We also don't want to aggressively
59 // claim FTP, since the user may have a separate FTP client. It is an open 59 // claim FTP, since the user may have a separate FTP client. It is an open
60 // question as to how to "heal" these settings. Perhaps the user should just 60 // question as to how to "heal" these settings. Perhaps the user should just
61 // re-run the installer or run with the --set-default-browser command line 61 // re-run the installer or run with the --set-default-browser command line
62 // flag. There is doubtless some other key we can hook into to cause "Repair" 62 // flag. There is doubtless some other key we can hook into to cause "Repair"
63 // to show up in Add/Remove programs for us. 63 // to show up in Add/Remove programs for us.
64 const std::wstring kChromeProtocols[] = {L"http", L"https"}; 64 const std::wstring kChromeProtocols[] = {L"http", L"https"};
65 65
66 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { 66 if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) {
67 IApplicationAssociationRegistration* pAAR; 67 IApplicationAssociationRegistration* pAAR;
68 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, 68 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration,
69 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), 69 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration),
70 (void**)&pAAR); 70 (void**)&pAAR);
71 if (!SUCCEEDED(hr)) 71 if (!SUCCEEDED(hr))
72 return false; 72 return UNKNOWN_DEFAULT_BROWSER;
73 73
74 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 74 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
75 std::wstring app_name = dist->GetApplicationName(); 75 std::wstring app_name = dist->GetApplicationName();
76 // If a user specific default browser entry exists, we check for that 76 // If a user specific default browser entry exists, we check for that
77 // app name being default. If not, then default browser is just called 77 // app name being default. If not, then default browser is just called
78 // Google Chrome or Chromium so we do not append suffix to app name. 78 // Google Chrome or Chromium so we do not append suffix to app name.
79 std::wstring suffix; 79 std::wstring suffix;
80 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(&suffix)) 80 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(&suffix))
81 app_name += suffix; 81 app_name += suffix;
82 82
83 for (int i = 0; i < _countof(kChromeProtocols); i++) { 83 for (int i = 0; i < _countof(kChromeProtocols); i++) {
84 BOOL result = TRUE; 84 BOOL result = TRUE;
85 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, 85 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL,
86 AL_EFFECTIVE, app_name.c_str(), &result); 86 AL_EFFECTIVE, app_name.c_str(), &result);
87 if (!SUCCEEDED(hr) || (result == FALSE)) { 87 if (!SUCCEEDED(hr)) {
88 pAAR->Release(); 88 pAAR->Release();
89 return false; 89 return UNKNOWN_DEFAULT_BROWSER;
90 }
91 if (result == FALSE) {
92 pAAR->Release();
93 return NOT_DEFAULT_BROWSER;
90 } 94 }
91 } 95 }
92 pAAR->Release(); 96 pAAR->Release();
93 } else { 97 } else {
94 std::wstring short_app_path; 98 std::wstring short_app_path;
95 GetShortPathName(app_path.c_str(), WriteInto(&short_app_path, MAX_PATH), 99 GetShortPathName(app_path.c_str(), WriteInto(&short_app_path, MAX_PATH),
96 MAX_PATH); 100 MAX_PATH);
97 101
98 // open command for protocol associations 102 // open command for protocol associations
99 for (int i = 0; i < _countof(kChromeProtocols); i++) { 103 for (int i = 0; i < _countof(kChromeProtocols); i++) {
100 // Check in HKEY_CLASSES_ROOT that is the result of merge between 104 // Check in HKEY_CLASSES_ROOT that is the result of merge between
101 // HKLM and HKCU 105 // HKLM and HKCU
102 HKEY root_key = HKEY_CLASSES_ROOT; 106 HKEY root_key = HKEY_CLASSES_ROOT;
103 // Check <protocol>\shell\open\command 107 // Check <protocol>\shell\open\command
104 std::wstring key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen); 108 std::wstring key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen);
105 RegKey key(root_key, key_path.c_str(), KEY_READ); 109 RegKey key(root_key, key_path.c_str(), KEY_READ);
106 std::wstring value; 110 std::wstring value;
107 if (!key.Valid() || !key.ReadValue(L"", &value)) 111 if (!key.Valid() || !key.ReadValue(L"", &value))
108 return false; 112 return NOT_DEFAULT_BROWSER; // Or UNKNOWN_DEFAULT_BROWSER?
Evan Martin 2009/09/04 22:46:15 If this registry key is something we set when we *
Mike Mammarella 2009/09/04 22:56:27 I looked through the RegKey source but it wasn't c
kuchhal 2009/09/04 23:05:12 These are keys like <root>\Software\Classes\http\s
109 // Need to normalize path in case it's been munged. 113 // Need to normalize path in case it's been munged.
110 CommandLine command_line(L""); 114 CommandLine command_line(L"");
111 command_line.ParseFromString(value); 115 command_line.ParseFromString(value);
112 std::wstring short_path; 116 std::wstring short_path;
113 GetShortPathName(command_line.program().c_str(), 117 GetShortPathName(command_line.program().c_str(),
114 WriteInto(&short_path, MAX_PATH), MAX_PATH); 118 WriteInto(&short_path, MAX_PATH), MAX_PATH);
115 if ((short_path.size() != short_app_path.size()) || 119 if ((short_path.size() != short_app_path.size()) ||
116 (!std::equal(short_path.begin(), 120 (!std::equal(short_path.begin(),
117 short_path.end(), 121 short_path.end(),
118 short_app_path.begin(), 122 short_app_path.begin(),
119 CaseInsensitiveCompare<wchar_t>()))) 123 CaseInsensitiveCompare<wchar_t>())))
120 return false; 124 return NOT_DEFAULT_BROWSER;
121 } 125 }
122 } 126 }
123 return true; 127 return IS_DEFAULT_BROWSER;
124 } 128 }
125 129
126 // There is no reliable way to say which browser is default on a machine (each 130 // There is no reliable way to say which browser is default on a machine (each
127 // browser can have some of the protocols/shortcuts). So we look for only HTTP 131 // browser can have some of the protocols/shortcuts). So we look for only HTTP
128 // protocol handler. Even this handler is located at different places in 132 // protocol handler. Even this handler is located at different places in
129 // registry on XP and Vista: 133 // registry on XP and Vista:
130 // - HKCR\http\shell\open\command (XP) 134 // - HKCR\http\shell\open\command (XP)
131 // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ 135 // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\
132 // http\UserChoice (Vista) 136 // http\UserChoice (Vista)
133 // This method checks if Firefox is defualt browser by checking these 137 // This method checks if Firefox is defualt browser by checking these
(...skipping 12 matching lines...) Expand all
146 std::wstring key_path(L"http"); 150 std::wstring key_path(L"http");
147 key_path.append(ShellUtil::kRegShellOpen); 151 key_path.append(ShellUtil::kRegShellOpen);
148 RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); 152 RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ);
149 std::wstring app_cmd; 153 std::wstring app_cmd;
150 if (key.Valid() && key.ReadValue(L"", &app_cmd) && 154 if (key.Valid() && key.ReadValue(L"", &app_cmd) &&
151 std::wstring::npos != StringToLowerASCII(app_cmd).find(L"firefox")) 155 std::wstring::npos != StringToLowerASCII(app_cmd).find(L"firefox"))
152 ff_default = true; 156 ff_default = true;
153 } 157 }
154 return ff_default; 158 return ff_default;
155 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698