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

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

Issue 9346013: Publish app shortcuts on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win build Created 8 years, 10 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
« no previous file with comments | « chrome/browser/shell_integration.h ('k') | chrome/browser/web_applications/web_app.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <shobjidl.h> 8 #include <shobjidl.h>
9 #include <propkey.h> 9 #include <propkey.h>
10 #include <propvarutil.h> 10 #include <propvarutil.h>
11 11
(...skipping 24 matching lines...) Expand all
36 #include "chrome/installer/util/work_item_list.h" 36 #include "chrome/installer/util/work_item_list.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 38
39 using content::BrowserThread; 39 using content::BrowserThread;
40 40
41 namespace { 41 namespace {
42 42
43 // Helper function for ShellIntegration::GetAppId to generates profile id 43 // Helper function for ShellIntegration::GetAppId to generates profile id
44 // from profile path. "profile_id" is composed of sanitized basenames of 44 // from profile path. "profile_id" is composed of sanitized basenames of
45 // user data dir and profile dir joined by a ".". 45 // user data dir and profile dir joined by a ".".
46 std::wstring GetProfileIdFromPath(const FilePath& profile_path) { 46 string16 GetProfileIdFromPath(const FilePath& profile_path) {
47 // Return empty string if profile_path is empty 47 // Return empty string if profile_path is empty
48 if (profile_path.empty()) 48 if (profile_path.empty())
49 return std::wstring(); 49 return string16();
50 50
51 FilePath default_user_data_dir; 51 FilePath default_user_data_dir;
52 // Return empty string if profile_path is in default user data 52 // Return empty string if profile_path is in default user data
53 // dir and is the default profile. 53 // dir and is the default profile.
54 if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) && 54 if (chrome::GetDefaultUserDataDirectory(&default_user_data_dir) &&
55 profile_path.DirName() == default_user_data_dir && 55 profile_path.DirName() == default_user_data_dir &&
56 profile_path.BaseName().value() == 56 profile_path.BaseName().value() ==
57 ASCIIToUTF16(chrome::kInitialProfile)) { 57 ASCIIToUTF16(chrome::kInitialProfile)) {
58 return std::wstring(); 58 return string16();
59 } 59 }
60 60
61 // Get joined basenames of user data dir and profile. 61 // Get joined basenames of user data dir and profile.
62 std::wstring basenames = profile_path.DirName().BaseName().value() + 62 string16 basenames = profile_path.DirName().BaseName().value() +
63 L"." + profile_path.BaseName().value(); 63 L"." + profile_path.BaseName().value();
64 64
65 std::wstring profile_id; 65 string16 profile_id;
66 profile_id.reserve(basenames.size()); 66 profile_id.reserve(basenames.size());
67 67
68 // Generate profile_id from sanitized basenames. 68 // Generate profile_id from sanitized basenames.
69 for (size_t i = 0; i < basenames.length(); ++i) { 69 for (size_t i = 0; i < basenames.length(); ++i) {
70 if (IsAsciiAlpha(basenames[i]) || 70 if (IsAsciiAlpha(basenames[i]) ||
71 IsAsciiDigit(basenames[i]) || 71 IsAsciiDigit(basenames[i]) ||
72 basenames[i] == L'.') 72 basenames[i] == L'.')
73 profile_id += basenames[i]; 73 profile_id += basenames[i];
74 } 74 }
75 75
76 return profile_id; 76 return profile_id;
77 } 77 }
78 78
79 bool GetShortcutAppId(IShellLink* shell_link, std::wstring* app_id) { 79 bool GetShortcutAppId(IShellLink* shell_link, string16* app_id) {
80 DCHECK(shell_link); 80 DCHECK(shell_link);
81 DCHECK(app_id); 81 DCHECK(app_id);
82 82
83 app_id->clear(); 83 app_id->clear();
84 84
85 base::win::ScopedComPtr<IPropertyStore> property_store; 85 base::win::ScopedComPtr<IPropertyStore> property_store;
86 if (FAILED(property_store.QueryFrom(shell_link))) 86 if (FAILED(property_store.QueryFrom(shell_link)))
87 return false; 87 return false;
88 88
89 PROPVARIANT appid_value; 89 PROPVARIANT appid_value;
90 PropVariantInit(&appid_value); 90 PropVariantInit(&appid_value);
91 if (FAILED(property_store->GetValue(PKEY_AppUserModel_ID, &appid_value))) 91 if (FAILED(property_store->GetValue(PKEY_AppUserModel_ID, &appid_value)))
92 return false; 92 return false;
93 93
94 if (appid_value.vt == VT_LPWSTR || appid_value.vt == VT_BSTR) 94 if (appid_value.vt == VT_LPWSTR || appid_value.vt == VT_BSTR)
95 app_id->assign(appid_value.pwszVal); 95 app_id->assign(appid_value.pwszVal);
96 96
97 PropVariantClear(&appid_value); 97 PropVariantClear(&appid_value);
98 return true; 98 return true;
99 } 99 }
100 100
101 // Gets expected app id for given chrome shortcut. Returns true if the shortcut 101 // Gets expected app id for given chrome shortcut. Returns true if the shortcut
102 // points to chrome and expected app id is successfully derived. 102 // points to chrome and expected app id is successfully derived.
103 bool GetExpectedAppId(const FilePath& chrome_exe, 103 bool GetExpectedAppId(const FilePath& chrome_exe,
104 IShellLink* shell_link, 104 IShellLink* shell_link,
105 std::wstring* expected_app_id) { 105 string16* expected_app_id) {
106 DCHECK(shell_link); 106 DCHECK(shell_link);
107 DCHECK(expected_app_id); 107 DCHECK(expected_app_id);
108 108
109 expected_app_id->clear(); 109 expected_app_id->clear();
110 110
111 // Check if the shortcut points to chrome_exe. 111 // Check if the shortcut points to chrome_exe.
112 std::wstring source; 112 string16 source;
113 if (FAILED(shell_link->GetPath(WriteInto(&source, MAX_PATH), MAX_PATH, NULL, 113 if (FAILED(shell_link->GetPath(WriteInto(&source, MAX_PATH), MAX_PATH, NULL,
114 SLGP_RAWPATH)) || 114 SLGP_RAWPATH)) ||
115 lstrcmpi(chrome_exe.value().c_str(), source.c_str())) 115 lstrcmpi(chrome_exe.value().c_str(), source.c_str()))
116 return false; 116 return false;
117 117
118 std::wstring arguments; 118 string16 arguments;
119 if (FAILED(shell_link->GetArguments(WriteInto(&arguments, MAX_PATH), 119 if (FAILED(shell_link->GetArguments(WriteInto(&arguments, MAX_PATH),
120 MAX_PATH))) 120 MAX_PATH)))
121 return false; 121 return false;
122 122
123 // Get expected app id from shortcut command line. 123 // Get expected app id from shortcut command line.
124 CommandLine command_line = CommandLine::FromString(base::StringPrintf( 124 CommandLine command_line = CommandLine::FromString(base::StringPrintf(
125 L"\"%ls\" %ls", source.c_str(), arguments.c_str())); 125 L"\"%ls\" %ls", source.c_str(), arguments.c_str()));
126 126
127 FilePath profile_path; 127 FilePath profile_path;
128 if (command_line.HasSwitch(switches::kUserDataDir)) { 128 if (command_line.HasSwitch(switches::kUserDataDir)) {
129 profile_path = 129 profile_path =
130 command_line.GetSwitchValuePath(switches::kUserDataDir).AppendASCII( 130 command_line.GetSwitchValuePath(switches::kUserDataDir).AppendASCII(
131 chrome::kInitialProfile); 131 chrome::kInitialProfile);
132 } 132 }
133 133
134 std::wstring app_name; 134 string16 app_name;
135 if (command_line.HasSwitch(switches::kApp)) { 135 if (command_line.HasSwitch(switches::kApp)) {
136 app_name = UTF8ToWide(web_app::GenerateApplicationNameFromURL( 136 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromURL(
137 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); 137 GURL(command_line.GetSwitchValueASCII(switches::kApp))));
138 } else if (command_line.HasSwitch(switches::kAppId)) { 138 } else if (command_line.HasSwitch(switches::kAppId)) {
139 app_name = UTF8ToWide(web_app::GenerateApplicationNameFromExtensionId( 139 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromExtensionId(
140 command_line.GetSwitchValueASCII(switches::kAppId))); 140 command_line.GetSwitchValueASCII(switches::kAppId)));
141 } else { 141 } else {
142 app_name = BrowserDistribution::GetDistribution()->GetBrowserAppId(); 142 app_name = BrowserDistribution::GetDistribution()->GetBrowserAppId();
143 } 143 }
144 144
145 expected_app_id->assign(ShellIntegration::GetAppId(app_name, profile_path)); 145 expected_app_id->assign(ShellIntegration::GetAppId(app_name, profile_path));
146 return true; 146 return true;
147 } 147 }
148 148
149 void MigrateWin7ShortcutsInPath( 149 void MigrateWin7ShortcutsInPath(
(...skipping 14 matching lines...) Expand all
164 } 164 }
165 165
166 base::win::ScopedComPtr<IPersistFile> persist_file; 166 base::win::ScopedComPtr<IPersistFile> persist_file;
167 if (FAILED(persist_file.QueryFrom(shell_link)) || 167 if (FAILED(persist_file.QueryFrom(shell_link)) ||
168 FAILED(persist_file->Load(shortcut.value().c_str(), STGM_READ))) { 168 FAILED(persist_file->Load(shortcut.value().c_str(), STGM_READ))) {
169 NOTREACHED(); 169 NOTREACHED();
170 return; 170 return;
171 } 171 }
172 172
173 // Get expected app id from shortcut. 173 // Get expected app id from shortcut.
174 std::wstring expected_app_id; 174 string16 expected_app_id;
175 if (!GetExpectedAppId(chrome_exe, shell_link, &expected_app_id) || 175 if (!GetExpectedAppId(chrome_exe, shell_link, &expected_app_id) ||
176 expected_app_id.empty()) 176 expected_app_id.empty())
177 continue; 177 continue;
178 178
179 // Get existing app id from shortcut if any. 179 // Get existing app id from shortcut if any.
180 std::wstring existing_app_id; 180 string16 existing_app_id;
181 GetShortcutAppId(shell_link, &existing_app_id); 181 GetShortcutAppId(shell_link, &existing_app_id);
182 182
183 if (expected_app_id != existing_app_id) { 183 if (expected_app_id != existing_app_id) {
184 file_util::UpdateShortcutLink(NULL, shortcut.value().c_str(), NULL, NULL, 184 file_util::UpdateShortcutLink(NULL, shortcut.value().c_str(), NULL, NULL,
185 NULL, NULL, 0, expected_app_id.c_str()); 185 NULL, NULL, 0, expected_app_id.c_str());
186 } 186 }
187 } 187 }
188 } 188 }
189 189
190 void MigrateChromiumShortcutsCallback() { 190 void MigrateChromiumShortcutsCallback() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { 258 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) {
259 if (protocol.empty()) 259 if (protocol.empty())
260 return false; 260 return false;
261 261
262 FilePath chrome_exe; 262 FilePath chrome_exe;
263 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 263 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
264 LOG(ERROR) << "Error getting app exe path"; 264 LOG(ERROR) << "Error getting app exe path";
265 return false; 265 return false;
266 } 266 }
267 267
268 std::wstring wprotocol = UTF8ToWide(protocol); 268 string16 wprotocol = UTF8ToUTF16(protocol);
269 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 269 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
270 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(), 270 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(),
271 wprotocol)) { 271 wprotocol)) {
272 LOG(ERROR) << "Chrome could not be set as default handler for " 272 LOG(ERROR) << "Chrome could not be set as default handler for "
273 << protocol << "."; 273 << protocol << ".";
274 return false; 274 return false;
275 } 275 }
276 276
277 VLOG(1) << "Chrome registered as default handler for " << protocol << "."; 277 VLOG(1) << "Chrome registered as default handler for " << protocol << ".";
278 return true; 278 return true;
279 } 279 }
280 280
281 ShellIntegration::DefaultWebClientState ShellIntegration::IsDefaultBrowser() { 281 ShellIntegration::DefaultWebClientState ShellIntegration::IsDefaultBrowser() {
282 // First determine the app path. If we can't determine what that is, we have 282 // First determine the app path. If we can't determine what that is, we have
283 // bigger fish to fry... 283 // bigger fish to fry...
284 FilePath app_path; 284 FilePath app_path;
285 if (!PathService::Get(base::FILE_EXE, &app_path)) { 285 if (!PathService::Get(base::FILE_EXE, &app_path)) {
286 LOG(ERROR) << "Error getting app exe path"; 286 LOG(ERROR) << "Error getting app exe path";
287 return UNKNOWN_DEFAULT_WEB_CLIENT; 287 return UNKNOWN_DEFAULT_WEB_CLIENT;
288 } 288 }
289 // When we check for default browser we don't necessarily want to count file 289 // When we check for default browser we don't necessarily want to count file
290 // type handlers and icons as having changed the default browser status, 290 // type handlers and icons as having changed the default browser status,
291 // since the user may have changed their shell settings to cause HTML files 291 // since the user may have changed their shell settings to cause HTML files
292 // to open with a text editor for example. We also don't want to aggressively 292 // to open with a text editor for example. We also don't want to aggressively
293 // claim FTP, since the user may have a separate FTP client. It is an open 293 // claim FTP, since the user may have a separate FTP client. It is an open
294 // question as to how to "heal" these settings. Perhaps the user should just 294 // question as to how to "heal" these settings. Perhaps the user should just
295 // re-run the installer or run with the --set-default-browser command line 295 // re-run the installer or run with the --set-default-browser command line
296 // flag. There is doubtless some other key we can hook into to cause "Repair" 296 // flag. There is doubtless some other key we can hook into to cause "Repair"
297 // to show up in Add/Remove programs for us. 297 // to show up in Add/Remove programs for us.
298 const std::wstring kChromeProtocols[] = {L"http", L"https"}; 298 const string16 kChromeProtocols[] = {L"http", L"https"};
299 299
300 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 300 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
301 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 301 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
302 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 302 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
303 NULL, CLSCTX_INPROC); 303 NULL, CLSCTX_INPROC);
304 if (!SUCCEEDED(hr)) 304 if (!SUCCEEDED(hr))
305 return NOT_DEFAULT_WEB_CLIENT; 305 return NOT_DEFAULT_WEB_CLIENT;
306 306
307 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 307 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
308 std::wstring app_name = dist->GetApplicationName(); 308 string16 app_name = dist->GetApplicationName();
309 // If a user specific default browser entry exists, we check for that 309 // If a user specific default browser entry exists, we check for that
310 // app name being default. If not, then default browser is just called 310 // app name being default. If not, then default browser is just called
311 // Google Chrome or Chromium so we do not append suffix to app name. 311 // Google Chrome or Chromium so we do not append suffix to app name.
312 std::wstring suffix; 312 string16 suffix;
313 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) 313 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix))
314 app_name += suffix; 314 app_name += suffix;
315 315
316 for (int i = 0; i < _countof(kChromeProtocols); i++) { 316 for (int i = 0; i < _countof(kChromeProtocols); i++) {
317 BOOL result = TRUE; 317 BOOL result = TRUE;
318 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, 318 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL,
319 AL_EFFECTIVE, app_name.c_str(), &result); 319 AL_EFFECTIVE, app_name.c_str(), &result);
320 if (!SUCCEEDED(hr) || result == FALSE) { 320 if (!SUCCEEDED(hr) || result == FALSE) {
321 return NOT_DEFAULT_WEB_CLIENT; 321 return NOT_DEFAULT_WEB_CLIENT;
322 } 322 }
323 } 323 }
324 } else { 324 } else {
325 std::wstring short_app_path; 325 string16 short_app_path;
326 DWORD get_path_result = GetShortPathName(app_path.value().c_str(), 326 DWORD get_path_result = GetShortPathName(app_path.value().c_str(),
327 WriteInto(&short_app_path, MAX_PATH), MAX_PATH); 327 WriteInto(&short_app_path, MAX_PATH), MAX_PATH);
328 if (!get_path_result || get_path_result > MAX_PATH) { 328 if (!get_path_result || get_path_result > MAX_PATH) {
329 LOG(ERROR) << "GetShortPathName error in IsDefaultBrowser."; 329 LOG(ERROR) << "GetShortPathName error in IsDefaultBrowser.";
330 return UNKNOWN_DEFAULT_WEB_CLIENT; 330 return UNKNOWN_DEFAULT_WEB_CLIENT;
331 } 331 }
332 332
333 // open command for protocol associations 333 // open command for protocol associations
334 for (int i = 0; i < _countof(kChromeProtocols); i++) { 334 for (int i = 0; i < _countof(kChromeProtocols); i++) {
335 // Check in HKEY_CLASSES_ROOT that is the result of merge between 335 // Check in HKEY_CLASSES_ROOT that is the result of merge between
336 // HKLM and HKCU 336 // HKLM and HKCU
337 HKEY root_key = HKEY_CLASSES_ROOT; 337 HKEY root_key = HKEY_CLASSES_ROOT;
338 // Check <protocol>\shell\open\command 338 // Check <protocol>\shell\open\command
339 std::wstring key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen); 339 string16 key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen);
340 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ); 340 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ);
341 std::wstring value; 341 string16 value;
342 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS)) 342 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS))
343 return NOT_DEFAULT_WEB_CLIENT; 343 return NOT_DEFAULT_WEB_CLIENT;
344 // Need to normalize path in case it's been munged. 344 // Need to normalize path in case it's been munged.
345 CommandLine command_line = CommandLine::FromString(value); 345 CommandLine command_line = CommandLine::FromString(value);
346 std::wstring short_path; 346 string16 short_path;
347 get_path_result = GetShortPathName( 347 get_path_result = GetShortPathName(
348 command_line.GetProgram().value().c_str(), 348 command_line.GetProgram().value().c_str(),
349 WriteInto(&short_path, MAX_PATH), MAX_PATH); 349 WriteInto(&short_path, MAX_PATH), MAX_PATH);
350 if (!get_path_result || get_path_result > MAX_PATH) { 350 if (!get_path_result || get_path_result > MAX_PATH) {
351 LOG(ERROR) << "GetShortPathName error in IsDefaultBrowser."; 351 LOG(ERROR) << "GetShortPathName error in IsDefaultBrowser.";
352 return UNKNOWN_DEFAULT_WEB_CLIENT; 352 return UNKNOWN_DEFAULT_WEB_CLIENT;
353 } 353 }
354 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) 354 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path))
355 return NOT_DEFAULT_WEB_CLIENT; 355 return NOT_DEFAULT_WEB_CLIENT;
356 } 356 }
357 } 357 }
358 return IS_DEFAULT_WEB_CLIENT; 358 return IS_DEFAULT_WEB_CLIENT;
359 } 359 }
360 360
361 ShellIntegration::DefaultWebClientState 361 ShellIntegration::DefaultWebClientState
362 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { 362 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) {
363 if (protocol.empty()) 363 if (protocol.empty())
364 return UNKNOWN_DEFAULT_WEB_CLIENT; 364 return UNKNOWN_DEFAULT_WEB_CLIENT;
365 365
366 // Determine the app path. If we can't determine what that is, we have 366 // Determine the app path. If we can't determine what that is, we have
367 // bigger fish to fry... 367 // bigger fish to fry...
368 FilePath app_path; 368 FilePath app_path;
369 if (!PathService::Get(base::FILE_EXE, &app_path)) { 369 if (!PathService::Get(base::FILE_EXE, &app_path)) {
370 LOG(ERROR) << "Error getting app exe path"; 370 LOG(ERROR) << "Error getting app exe path";
371 return UNKNOWN_DEFAULT_WEB_CLIENT; 371 return UNKNOWN_DEFAULT_WEB_CLIENT;
372 } 372 }
373 373
374 std::wstring wprotocol = UTF8ToWide(protocol); 374 string16 wprotocol = UTF8ToUTF16(protocol);
375 375
376 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 376 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
377 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; 377 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR;
378 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, 378 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration,
379 NULL, CLSCTX_INPROC); 379 NULL, CLSCTX_INPROC);
380 if (!SUCCEEDED(hr)) 380 if (!SUCCEEDED(hr))
381 return NOT_DEFAULT_WEB_CLIENT; 381 return NOT_DEFAULT_WEB_CLIENT;
382 382
383 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 383 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
384 std::wstring app_name = dist->GetApplicationName(); 384 string16 app_name = dist->GetApplicationName();
385 // If a user specific default browser entry exists, we check for that 385 // If a user specific default browser entry exists, we check for that
386 // app name being default. If not, then default browser is just called 386 // app name being default. If not, then default browser is just called
387 // Google Chrome or Chromium so we do not append suffix to app name. 387 // Google Chrome or Chromium so we do not append suffix to app name.
388 std::wstring suffix; 388 string16 suffix;
389 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) 389 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix))
390 app_name += suffix; 390 app_name += suffix;
391 391
392 BOOL result = TRUE; 392 BOOL result = TRUE;
393 hr = pAAR->QueryAppIsDefault(wprotocol.c_str(), AT_URLPROTOCOL, 393 hr = pAAR->QueryAppIsDefault(wprotocol.c_str(), AT_URLPROTOCOL,
394 AL_EFFECTIVE, app_name.c_str(), &result); 394 AL_EFFECTIVE, app_name.c_str(), &result);
395 if (!SUCCEEDED(hr) || result == FALSE) { 395 if (!SUCCEEDED(hr) || result == FALSE) {
396 return NOT_DEFAULT_WEB_CLIENT; 396 return NOT_DEFAULT_WEB_CLIENT;
397 } 397 }
398 } else { 398 } else {
399 std::wstring short_app_path; 399 string16 short_app_path;
400 DWORD get_path_result = GetShortPathName(app_path.value().c_str(), 400 DWORD get_path_result = GetShortPathName(app_path.value().c_str(),
401 WriteInto(&short_app_path, MAX_PATH), MAX_PATH); 401 WriteInto(&short_app_path, MAX_PATH), MAX_PATH);
402 if (!get_path_result || get_path_result > MAX_PATH) { 402 if (!get_path_result || get_path_result > MAX_PATH) {
403 LOG(ERROR) << "GetShortPathName error in IsDefaultProtocolClient."; 403 LOG(ERROR) << "GetShortPathName error in IsDefaultProtocolClient.";
404 return UNKNOWN_DEFAULT_WEB_CLIENT; 404 return UNKNOWN_DEFAULT_WEB_CLIENT;
405 } 405 }
406 406
407 // open command for protocol associations 407 // open command for protocol associations
408 // Check in HKEY_CLASSES_ROOT that is the result of merge between 408 // Check in HKEY_CLASSES_ROOT that is the result of merge between
409 // HKLM and HKCU 409 // HKLM and HKCU
410 HKEY root_key = HKEY_CLASSES_ROOT; 410 HKEY root_key = HKEY_CLASSES_ROOT;
411 // Check <protocol>\shell\open\command 411 // Check <protocol>\shell\open\command
412 std::wstring key_path(wprotocol + ShellUtil::kRegShellOpen); 412 string16 key_path(wprotocol + ShellUtil::kRegShellOpen);
413 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ); 413 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ);
414 std::wstring value; 414 string16 value;
415 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS)) 415 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS))
416 return NOT_DEFAULT_WEB_CLIENT; 416 return NOT_DEFAULT_WEB_CLIENT;
417 // Need to normalize path in case it's been munged. 417 // Need to normalize path in case it's been munged.
418 CommandLine command_line = CommandLine::FromString(value); 418 CommandLine command_line = CommandLine::FromString(value);
419 std::wstring short_path; 419 string16 short_path;
420 get_path_result = GetShortPathName( 420 get_path_result = GetShortPathName(
421 command_line.GetProgram().value().c_str(), 421 command_line.GetProgram().value().c_str(),
422 WriteInto(&short_path, MAX_PATH), MAX_PATH); 422 WriteInto(&short_path, MAX_PATH), MAX_PATH);
423 if (!get_path_result || get_path_result > MAX_PATH) { 423 if (!get_path_result || get_path_result > MAX_PATH) {
424 LOG(ERROR) << "GetShortPathName error in IsDefaultProtocolClient."; 424 LOG(ERROR) << "GetShortPathName error in IsDefaultProtocolClient.";
425 return UNKNOWN_DEFAULT_WEB_CLIENT; 425 return UNKNOWN_DEFAULT_WEB_CLIENT;
426 } 426 }
427 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) 427 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path))
428 return NOT_DEFAULT_WEB_CLIENT; 428 return NOT_DEFAULT_WEB_CLIENT;
429 } 429 }
430 return IS_DEFAULT_WEB_CLIENT; 430 return IS_DEFAULT_WEB_CLIENT;
431 } 431 }
432 432
433 // There is no reliable way to say which browser is default on a machine (each 433 // There is no reliable way to say which browser is default on a machine (each
434 // browser can have some of the protocols/shortcuts). So we look for only HTTP 434 // browser can have some of the protocols/shortcuts). So we look for only HTTP
435 // protocol handler. Even this handler is located at different places in 435 // protocol handler. Even this handler is located at different places in
436 // registry on XP and Vista: 436 // registry on XP and Vista:
437 // - HKCR\http\shell\open\command (XP) 437 // - HKCR\http\shell\open\command (XP)
438 // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ 438 // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\
439 // http\UserChoice (Vista) 439 // http\UserChoice (Vista)
440 // This method checks if Firefox is defualt browser by checking these 440 // This method checks if Firefox is defualt browser by checking these
441 // locations and returns true if Firefox traces are found there. In case of 441 // locations and returns true if Firefox traces are found there. In case of
442 // error (or if Firefox is not found)it returns the default value which 442 // error (or if Firefox is not found)it returns the default value which
443 // is false. 443 // is false.
444 bool ShellIntegration::IsFirefoxDefaultBrowser() { 444 bool ShellIntegration::IsFirefoxDefaultBrowser() {
445 bool ff_default = false; 445 bool ff_default = false;
446 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 446 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
447 std::wstring app_cmd; 447 string16 app_cmd;
448 base::win::RegKey key(HKEY_CURRENT_USER, 448 base::win::RegKey key(HKEY_CURRENT_USER,
449 ShellUtil::kRegVistaUrlPrefs, KEY_READ); 449 ShellUtil::kRegVistaUrlPrefs, KEY_READ);
450 if (key.Valid() && (key.ReadValue(L"Progid", &app_cmd) == ERROR_SUCCESS) && 450 if (key.Valid() && (key.ReadValue(L"Progid", &app_cmd) == ERROR_SUCCESS) &&
451 app_cmd == L"FirefoxURL") 451 app_cmd == L"FirefoxURL")
452 ff_default = true; 452 ff_default = true;
453 } else { 453 } else {
454 std::wstring key_path(L"http"); 454 string16 key_path(L"http");
455 key_path.append(ShellUtil::kRegShellOpen); 455 key_path.append(ShellUtil::kRegShellOpen);
456 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); 456 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ);
457 std::wstring app_cmd; 457 string16 app_cmd;
458 if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) && 458 if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) &&
459 std::wstring::npos != StringToLowerASCII(app_cmd).find(L"firefox")) 459 string16::npos != StringToLowerASCII(app_cmd).find(L"firefox"))
460 ff_default = true; 460 ff_default = true;
461 } 461 }
462 return ff_default; 462 return ff_default;
463 } 463 }
464 464
465 std::wstring ShellIntegration::GetAppId(const std::wstring& app_name, 465 string16 ShellIntegration::GetAppId(const string16& app_name,
466 const FilePath& profile_path) { 466 const FilePath& profile_path) {
467 std::wstring app_id(app_name); 467 string16 app_id(app_name);
468 468
469 std::wstring profile_id(GetProfileIdFromPath(profile_path)); 469 string16 profile_id(GetProfileIdFromPath(profile_path));
470 if (!profile_id.empty()) { 470 if (!profile_id.empty()) {
471 app_id += L"."; 471 app_id += L".";
472 app_id += profile_id; 472 app_id += profile_id;
473 } 473 }
474 474
475 // App id should be less than 128 chars. 475 // App id should be less than 128 chars.
476 DCHECK(app_id.length() < 128); 476 DCHECK(app_id.length() < 128);
477 return app_id; 477 return app_id;
478 } 478 }
479 479
480 std::wstring ShellIntegration::GetChromiumAppId(const FilePath& profile_path) { 480 string16 ShellIntegration::GetChromiumAppId(const FilePath& profile_path) {
481 return GetAppId(BrowserDistribution::GetDistribution()->GetBrowserAppId(), 481 return GetAppId(BrowserDistribution::GetDistribution()->GetBrowserAppId(),
482 profile_path); 482 profile_path);
483 } 483 }
484 484
485 string16 ShellIntegration::GetChromiumIconPath() { 485 string16 ShellIntegration::GetChromiumIconPath() {
486 // Determine the app path. If we can't determine what that is, we have 486 // Determine the app path. If we can't determine what that is, we have
487 // bigger fish to fry... 487 // bigger fish to fry...
488 FilePath app_path; 488 FilePath app_path;
489 if (!PathService::Get(base::FILE_EXE, &app_path)) { 489 if (!PathService::Get(base::FILE_EXE, &app_path)) {
490 NOTREACHED(); 490 NOTREACHED();
491 return string16(); 491 return string16();
492 } 492 }
493 493
494 string16 icon_path(app_path.value()); 494 string16 icon_path(app_path.value());
495 icon_path.push_back(','); 495 icon_path.push_back(',');
496 icon_path += base::IntToString16( 496 icon_path += base::IntToString16(
497 BrowserDistribution::GetDistribution()->GetIconIndex()); 497 BrowserDistribution::GetDistribution()->GetIconIndex());
498 return icon_path; 498 return icon_path;
499 } 499 }
500 500
501 void ShellIntegration::MigrateChromiumShortcuts() { 501 void ShellIntegration::MigrateChromiumShortcuts() {
502 if (base::win::GetVersion() < base::win::VERSION_WIN7) 502 if (base::win::GetVersion() < base::win::VERSION_WIN7)
503 return; 503 return;
504 504
505 BrowserThread::PostTask( 505 BrowserThread::PostTask(
506 BrowserThread::FILE, FROM_HERE, 506 BrowserThread::FILE, FROM_HERE,
507 base::Bind(&MigrateChromiumShortcutsCallback)); 507 base::Bind(&MigrateChromiumShortcutsCallback));
508 } 508 }
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration.h ('k') | chrome/browser/web_applications/web_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698