OLD | NEW |
---|---|
1 // Copyright (c) 2012 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 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
8 // this class. | 8 // this class. |
9 | 9 |
10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 | 197 |
198 // Returns the Windows Default Programs capabilities key for Chrome. For | 198 // Returns the Windows Default Programs capabilities key for Chrome. For |
199 // example: | 199 // example: |
200 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". | 200 // "Software\Clients\StartMenuInternet\Chromium[.user]\Capabilities". |
201 static string16 GetCapabilitiesKey(BrowserDistribution* dist, | 201 static string16 GetCapabilitiesKey(BrowserDistribution* dist, |
202 const string16& suffix) { | 202 const string16& suffix) { |
203 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); | 203 return GetBrowserClientKey(dist, suffix).append(L"\\Capabilities"); |
204 } | 204 } |
205 | 205 |
206 // This method returns a list of all the registry entries that | 206 // This method returns a list of all the registry entries that |
207 // are needed to register Chromium ProgIds. | 207 // are needed to register this installation's ProgId and AppId. |
208 // These entries should be registered in HKCU for user-level installs and in | 208 // These entries should be registered in HKCU for user-level installs and in |
209 // HKLM for system-level installs. | 209 // HKLM for system-level installs. |
210 static bool GetProgIdEntries(BrowserDistribution* dist, | 210 static void GetProgIdEntries(BrowserDistribution* dist, |
211 const string16& chrome_exe, | 211 const string16& chrome_exe, |
212 const string16& suffix, | 212 const string16& suffix, |
213 std::list<RegistryEntry*>* entries) { | 213 std::list<RegistryEntry*>* entries) { |
214 string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe)); | 214 string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe)); |
215 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); | 215 string16 open_cmd(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
216 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); | 216 string16 delegate_command(ShellUtil::GetChromeDelegateCommand(chrome_exe)); |
217 // For user-level installs: entries for the app id and DelegateExecute verb | 217 // For user-level installs: entries for the app id and DelegateExecute verb |
218 // handler will be in HKCU; thus we do not need a suffix on those entries. | 218 // handler will be in HKCU; thus we do not need a suffix on those entries. |
219 string16 app_id(ShellUtil::GetBrowserModelId(dist, chrome_exe)); | 219 string16 app_id(ShellUtil::GetBrowserModelId(dist, chrome_exe)); |
220 string16 delegate_guid; | 220 string16 delegate_guid; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 entries->push_front(new RegistryEntry( | 295 entries->push_front(new RegistryEntry( |
296 chrome_application, ShellUtil::kRegApplicationName, | 296 chrome_application, ShellUtil::kRegApplicationName, |
297 dist->GetAppShortCutName())); | 297 dist->GetAppShortCutName())); |
298 entries->push_front(new RegistryEntry( | 298 entries->push_front(new RegistryEntry( |
299 chrome_application, ShellUtil::kRegApplicationDescription, | 299 chrome_application, ShellUtil::kRegApplicationDescription, |
300 dist->GetAppDescription())); | 300 dist->GetAppDescription())); |
301 entries->push_front(new RegistryEntry( | 301 entries->push_front(new RegistryEntry( |
302 chrome_application, ShellUtil::kRegApplicationCompany, | 302 chrome_application, ShellUtil::kRegApplicationCompany, |
303 dist->GetPublisherName())); | 303 dist->GetPublisherName())); |
304 } | 304 } |
305 | |
306 return true; | |
307 } | 305 } |
308 | 306 |
309 // This method returns a list of the registry entries needed to declare a | 307 // This method returns a list of the registry entries needed to declare a |
310 // capability of handling a protocol on Windows. | 308 // capability of handling a protocol on Windows. |
311 static bool GetProtocolCapabilityEntries(BrowserDistribution* dist, | 309 static void GetProtocolCapabilityEntries(BrowserDistribution* dist, |
312 const string16& suffix, | 310 const string16& suffix, |
313 const string16& protocol, | 311 const string16& protocol, |
314 std::list<RegistryEntry*>* entries) { | 312 std::list<RegistryEntry*>* entries) { |
315 entries->push_front(new RegistryEntry( | 313 entries->push_front(new RegistryEntry( |
316 GetCapabilitiesKey(dist, suffix).append(L"\\URLAssociations"), | 314 GetCapabilitiesKey(dist, suffix).append(L"\\URLAssociations"), |
317 protocol, GetBrowserProgId(suffix))); | 315 protocol, GetBrowserProgId(suffix))); |
318 return true; | |
319 } | 316 } |
320 | 317 |
321 // This method returns a list of all the registry entries required to fully | 318 // This method returns a list of the registry entries required to register |
322 // integrate Chrome with Windows (i.e. StartMenuInternet, Default Programs, | 319 // this installation in "RegisteredApplications" on Windows (to appear in |
323 // AppPaths, etc.). This entries need to be registered in HKLM prior to Win8. | 320 // Default Programs, StartMenuInternet, etc.). |
324 static bool GetShellIntegrationEntries(BrowserDistribution* dist, | 321 // These entries need to be registered in HKLM prior to Win8. |
322 // If |suffix| is not empty, these entries are guaranteed to be unique on this | |
323 // machine. | |
324 static void GetShellIntegrationEntries(BrowserDistribution* dist, | |
325 const string16& chrome_exe, | 325 const string16& chrome_exe, |
326 const string16& suffix, | 326 const string16& suffix, |
327 std::list<RegistryEntry*>* entries) { | 327 std::list<RegistryEntry*>* entries) { |
328 string16 icon_path = ShellUtil::GetChromeIcon(dist, chrome_exe); | 328 const string16 icon_path(ShellUtil::GetChromeIcon(dist, chrome_exe)); |
329 string16 quoted_exe_path = L"\"" + chrome_exe + L"\""; | 329 const string16 quoted_exe_path(L"\"" + chrome_exe + L"\""); |
330 | 330 |
331 // Register for the Start Menu "Internet" link (pre-Win7). | 331 // Register for the Start Menu "Internet" link (pre-Win7). |
332 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); | 332 const string16 start_menu_entry(GetBrowserClientKey(dist, suffix)); |
333 // Register Chrome's display name. | 333 // Register Chrome's display name. |
334 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see | 334 // TODO(grt): http://crbug.com/75152 Also set LocalizedString; see |
335 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85) .aspx#registering_the_display_name | 335 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc144109(v=VS.85) .aspx#registering_the_display_name |
336 entries->push_front(new RegistryEntry( | 336 entries->push_front(new RegistryEntry( |
337 start_menu_entry, dist->GetAppShortCutName())); | 337 start_menu_entry, dist->GetAppShortCutName())); |
338 // Register the "open" verb for launching Chrome via the "Internet" link. | 338 // Register the "open" verb for launching Chrome via the "Internet" link. |
339 entries->push_front(new RegistryEntry( | 339 entries->push_front(new RegistryEntry( |
340 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); | 340 start_menu_entry + ShellUtil::kRegShellOpen, quoted_exe_path)); |
341 // Register Chrome's icon for the Start Menu "Internet" link. | 341 // Register Chrome's icon for the Start Menu "Internet" link. |
342 entries->push_front(new RegistryEntry( | 342 entries->push_front(new RegistryEntry( |
343 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); | 343 start_menu_entry + ShellUtil::kRegDefaultIcon, icon_path)); |
344 | 344 |
345 // Register installation information. | 345 // Register installation information. |
346 string16 install_info(start_menu_entry + L"\\InstallInfo"); | 346 string16 install_info(start_menu_entry + L"\\InstallInfo"); |
347 // Note: not using CommandLine since it has ambiguous rules for quoting | 347 // Note: not using CommandLine since it has ambiguous rules for quoting |
348 // strings. | 348 // strings. |
349 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, | 349 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, |
350 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); | 350 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); |
351 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", | 351 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", |
352 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); | 352 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); |
353 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", | 353 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", |
354 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); | 354 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); |
355 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); | 355 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); |
356 | 356 |
357 // Register with Default Programs. | 357 // Register with Default Programs. |
358 string16 reg_app_name(dist->GetBaseAppName().append(suffix)); | 358 const string16 reg_app_name(dist->GetBaseAppName().append(suffix)); |
359 // Tell Windows where to find Chrome's Default Programs info. | 359 // Tell Windows where to find Chrome's Default Programs info. |
360 string16 capabilities(GetCapabilitiesKey(dist, suffix)); | 360 const string16 capabilities(GetCapabilitiesKey(dist, suffix)); |
361 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, | 361 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, |
362 reg_app_name, capabilities)); | 362 reg_app_name, capabilities)); |
363 // Write out Chrome's Default Programs info. | 363 // Write out Chrome's Default Programs info. |
364 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 364 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
365 // resource rather than this. | 365 // resource rather than this. |
366 entries->push_front(new RegistryEntry( | 366 entries->push_front(new RegistryEntry( |
367 capabilities, ShellUtil::kRegApplicationDescription, | 367 capabilities, ShellUtil::kRegApplicationDescription, |
368 dist->GetLongAppDescription())); | 368 dist->GetLongAppDescription())); |
369 entries->push_front(new RegistryEntry( | 369 entries->push_front(new RegistryEntry( |
370 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 370 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
371 entries->push_front(new RegistryEntry( | 371 entries->push_front(new RegistryEntry( |
372 capabilities, ShellUtil::kRegApplicationName, | 372 capabilities, ShellUtil::kRegApplicationName, |
373 dist->GetAppShortCutName())); | 373 dist->GetAppShortCutName())); |
374 | 374 |
375 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", | 375 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", |
376 L"StartMenuInternet", reg_app_name)); | 376 L"StartMenuInternet", reg_app_name)); |
377 | 377 |
378 string16 html_prog_id(GetBrowserProgId(suffix)); | 378 const string16 html_prog_id(GetBrowserProgId(suffix)); |
379 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { | 379 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
380 entries->push_front(new RegistryEntry( | 380 entries->push_front(new RegistryEntry( |
381 capabilities + L"\\FileAssociations", | 381 capabilities + L"\\FileAssociations", |
382 ShellUtil::kFileAssociations[i], html_prog_id)); | 382 ShellUtil::kFileAssociations[i], html_prog_id)); |
383 } | 383 } |
384 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; | 384 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; |
385 i++) { | 385 i++) { |
386 entries->push_front(new RegistryEntry( | 386 entries->push_front(new RegistryEntry( |
387 capabilities + L"\\URLAssociations", | 387 capabilities + L"\\URLAssociations", |
388 ShellUtil::kPotentialProtocolAssociations[i], html_prog_id)); | 388 ShellUtil::kPotentialProtocolAssociations[i], html_prog_id)); |
389 } | 389 } |
390 } | |
390 | 391 |
391 // Application Registration. | 392 // This method returns a list of the registry entries required for this |
392 FilePath chrome_path(chrome_exe); | 393 // installation to be registered in the Windows shell. |
394 // In particular: App Paths and File Associations. | |
robertshield
2012/08/05 15:01:12
Please add links to http://msdn.microsoft.com/en-u
gab
2012/08/06 19:39:27
Done.
| |
395 // These entries should be registered in HKCU for user-level installs and in | |
396 // HKLM for system-level installs. | |
397 static void GetAppRegistrationEntries(const string16& chrome_exe, | |
398 const string16& suffix, | |
399 std::list<RegistryEntry*>* entries) { | |
robertshield
2012/08/05 15:01:12
any reason not to use base::ScopedVector here? it
gab
2012/08/06 19:39:27
shell_util has been using std::list forever, but I
| |
400 const FilePath chrome_path(chrome_exe); | |
393 string16 app_path_key(ShellUtil::kAppPathsRegistryKey); | 401 string16 app_path_key(ShellUtil::kAppPathsRegistryKey); |
394 app_path_key.push_back(FilePath::kSeparators[0]); | 402 app_path_key.push_back(FilePath::kSeparators[0]); |
395 app_path_key.append(chrome_path.BaseName().value()); | 403 app_path_key.append(chrome_path.BaseName().value()); |
396 entries->push_front(new RegistryEntry(app_path_key, chrome_exe)); | 404 entries->push_front(new RegistryEntry(app_path_key, chrome_exe)); |
397 entries->push_front(new RegistryEntry(app_path_key, | 405 entries->push_front(new RegistryEntry(app_path_key, |
398 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); | 406 ShellUtil::kAppPathsRegistryPathName, chrome_path.DirName().value())); |
399 | 407 |
400 // TODO: add chrome to open with list (Bug 16726). | 408 const string16 html_prog_id(GetBrowserProgId(suffix)); |
401 return true; | 409 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
410 string16 key(ShellUtil::kRegClasses); | |
411 key.push_back(FilePath::kSeparators[0]); | |
412 key.append(ShellUtil::kFileAssociations[i]); | |
413 key.push_back(FilePath::kSeparators[0]); | |
414 key.append(ShellUtil::kRegOpenWithProgids); | |
415 entries->push_front(new RegistryEntry(key, html_prog_id, string16())); | |
416 } | |
402 } | 417 } |
403 | 418 |
404 // This method returns a list of all the user level registry entries that | 419 // This method returns a list of all the user level registry entries that |
405 // are needed to make Chromium the default handler for a protocol. | 420 // are needed to make Chromium the default handler for a protocol. |
406 static bool GetUserProtocolEntries(const string16& protocol, | 421 static void GetUserProtocolEntries(const string16& protocol, |
407 const string16& chrome_icon, | 422 const string16& chrome_icon, |
408 const string16& chrome_open, | 423 const string16& chrome_open, |
409 std::list<RegistryEntry*>* entries) { | 424 std::list<RegistryEntry*>* entries) { |
410 // Protocols associations. | 425 // Protocols associations. |
411 string16 url_key(ShellUtil::kRegClasses); | 426 string16 url_key(ShellUtil::kRegClasses); |
412 url_key.push_back(FilePath::kSeparators[0]); | 427 url_key.push_back(FilePath::kSeparators[0]); |
413 url_key.append(protocol); | 428 url_key.append(protocol); |
414 | 429 |
415 // This registry value tells Windows that this 'class' is a URL scheme | 430 // This registry value tells Windows that this 'class' is a URL scheme |
416 // so IE, explorer and other apps will route it to our handler. | 431 // so IE, explorer and other apps will route it to our handler. |
417 // <root hkey>\Software\Classes\<protocol>\URL Protocol | 432 // <root hkey>\Software\Classes\<protocol>\URL Protocol |
418 entries->push_front(new RegistryEntry(url_key, | 433 entries->push_front(new RegistryEntry(url_key, |
419 ShellUtil::kRegUrlProtocol, L"")); | 434 ShellUtil::kRegUrlProtocol, L"")); |
420 | 435 |
421 // <root hkey>\Software\Classes\<protocol>\DefaultIcon | 436 // <root hkey>\Software\Classes\<protocol>\DefaultIcon |
422 string16 icon_key = url_key + ShellUtil::kRegDefaultIcon; | 437 string16 icon_key = url_key + ShellUtil::kRegDefaultIcon; |
423 entries->push_front(new RegistryEntry(icon_key, chrome_icon)); | 438 entries->push_front(new RegistryEntry(icon_key, chrome_icon)); |
424 | 439 |
425 // <root hkey>\Software\Classes\<protocol>\shell\open\command | 440 // <root hkey>\Software\Classes\<protocol>\shell\open\command |
426 string16 shell_key = url_key + ShellUtil::kRegShellOpen; | 441 string16 shell_key = url_key + ShellUtil::kRegShellOpen; |
427 entries->push_front(new RegistryEntry(shell_key, chrome_open)); | 442 entries->push_front(new RegistryEntry(shell_key, chrome_open)); |
428 | 443 |
429 // <root hkey>\Software\Classes\<protocol>\shell\open\ddeexec | 444 // <root hkey>\Software\Classes\<protocol>\shell\open\ddeexec |
430 string16 dde_key = url_key + L"\\shell\\open\\ddeexec"; | 445 string16 dde_key = url_key + L"\\shell\\open\\ddeexec"; |
431 entries->push_front(new RegistryEntry(dde_key, L"")); | 446 entries->push_front(new RegistryEntry(dde_key, L"")); |
432 | 447 |
433 // <root hkey>\Software\Classes\<protocol>\shell\@ | 448 // <root hkey>\Software\Classes\<protocol>\shell\@ |
434 string16 protocol_shell_key = url_key + ShellUtil::kRegShellPath; | 449 string16 protocol_shell_key = url_key + ShellUtil::kRegShellPath; |
435 entries->push_front(new RegistryEntry(protocol_shell_key, L"open")); | 450 entries->push_front(new RegistryEntry(protocol_shell_key, L"open")); |
436 | |
437 return true; | |
438 } | 451 } |
439 | 452 |
440 // This method returns a list of all the user level registry entries that | 453 // This method returns a list of all the user level registry entries that |
441 // are needed to make Chromium default browser. | 454 // are needed to make Chromium default browser. |
442 static bool GetUserEntries(BrowserDistribution* dist, | 455 // Some of these entries are irrelevant in recent versions of Windows, but |
443 const string16& chrome_exe, | 456 // we register them anyways as some legacy apps are hardcoded to lookup those |
444 const string16& suffix, | 457 // values. |
445 std::list<RegistryEntry*>* entries) { | 458 static void GetDefaultBrowserUserEntries(BrowserDistribution* dist, |
459 const string16& chrome_exe, | |
460 const string16& suffix, | |
461 std::list<RegistryEntry*>* entries) { | |
robertshield
2012/08/05 15:01:12
same comment about base::ScopedVector
gab
2012/08/06 19:39:27
Done.
| |
446 // File extension associations. | 462 // File extension associations. |
447 string16 html_prog_id(GetBrowserProgId(suffix)); | 463 string16 html_prog_id(GetBrowserProgId(suffix)); |
448 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { | 464 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
449 string16 ext_key(ShellUtil::kRegClasses); | 465 string16 ext_key(ShellUtil::kRegClasses); |
450 ext_key.push_back(FilePath::kSeparators[0]); | 466 ext_key.push_back(FilePath::kSeparators[0]); |
451 ext_key.append(ShellUtil::kFileAssociations[i]); | 467 ext_key.append(ShellUtil::kFileAssociations[i]); |
452 entries->push_front(new RegistryEntry(ext_key, html_prog_id)); | 468 entries->push_front(new RegistryEntry(ext_key, html_prog_id)); |
453 } | 469 } |
454 | 470 |
455 // Protocols associations. | 471 // Protocols associations. |
456 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | 472 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); |
457 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); | 473 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); |
458 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 474 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
459 GetUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], | 475 GetUserProtocolEntries(ShellUtil::kBrowserProtocolAssociations[i], |
460 chrome_icon, chrome_open, entries); | 476 chrome_icon, chrome_open, entries); |
461 } | 477 } |
462 | 478 |
463 // start->Internet shortcut. | 479 // start->Internet shortcut. |
464 string16 start_menu(ShellUtil::kRegStartMenuInternet); | 480 string16 start_menu(ShellUtil::kRegStartMenuInternet); |
465 string16 app_name = dist->GetBaseAppName() + suffix; | 481 string16 app_name = dist->GetBaseAppName() + suffix; |
466 entries->push_front(new RegistryEntry(start_menu, app_name)); | 482 entries->push_front(new RegistryEntry(start_menu, app_name)); |
467 return true; | |
468 } | 483 } |
469 | 484 |
470 // Generate work_item tasks required to create current registry entry and | 485 // Generate work_item tasks required to create current registry entry and |
471 // add them to the given work item list. | 486 // add them to the given work item list. |
472 void AddToWorkItemList(HKEY root, WorkItemList *items) const { | 487 void AddToWorkItemList(HKEY root, WorkItemList *items) const { |
473 items->AddCreateRegKeyWorkItem(root, _key_path); | 488 items->AddCreateRegKeyWorkItem(root, _key_path); |
474 if (_is_string) { | 489 if (_is_string) { |
475 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); | 490 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); |
476 } else { | 491 } else { |
477 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); | 492 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 } | 612 } |
598 | 613 |
599 // Checks that all required registry entries for Chrome are already present | 614 // Checks that all required registry entries for Chrome are already present |
600 // on this computer. | 615 // on this computer. |
601 bool IsChromeRegistered(BrowserDistribution* dist, | 616 bool IsChromeRegistered(BrowserDistribution* dist, |
602 const string16& chrome_exe, | 617 const string16& chrome_exe, |
603 const string16& suffix) { | 618 const string16& suffix) { |
604 std::list<RegistryEntry*> entries; | 619 std::list<RegistryEntry*> entries; |
605 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 620 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
606 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 621 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
607 RegistryEntry::GetShellIntegrationEntries( | 622 RegistryEntry::GetShellIntegrationEntries(dist, chrome_exe, suffix, &entries); |
608 dist, chrome_exe, suffix, &entries); | 623 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); |
609 return AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU_THEN_HKLM); | 624 return AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU_THEN_HKLM); |
610 } | 625 } |
611 | 626 |
612 // This method checks if Chrome is already registered on the local machine | 627 // This method checks if Chrome is already registered on the local machine |
613 // for the requested protocol. It just checks the one value required for this. | 628 // for the requested protocol. It just checks the one value required for this. |
614 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, | 629 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, |
615 const string16& suffix, | 630 const string16& suffix, |
616 const string16& protocol) { | 631 const string16& protocol) { |
617 std::list<RegistryEntry*> entries; | 632 std::list<RegistryEntry*> entries; |
618 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 633 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 } | 876 } |
862 | 877 |
863 // Returns the root registry key (HKLM or HKCU) into which shell integration | 878 // Returns the root registry key (HKLM or HKCU) into which shell integration |
864 // registration for default protocols must be placed. As of Windows 8 everything | 879 // registration for default protocols must be placed. As of Windows 8 everything |
865 // can go in HKCU for per-user installs. | 880 // can go in HKCU for per-user installs. |
866 HKEY DetermineShellIntegrationRoot(bool is_per_user) { | 881 HKEY DetermineShellIntegrationRoot(bool is_per_user) { |
867 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? | 882 return is_per_user && base::win::GetVersion() >= base::win::VERSION_WIN8 ? |
868 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 883 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
869 } | 884 } |
870 | 885 |
886 // Associates Chrome with supported protocols and file associations. This should | |
887 // not be required on Vista+ but since some applications still read | |
888 // Software\Classes\http key directly, we have to do this on Vista+ as well. | |
889 bool RegisterChromeAsDefaultForXP(BrowserDistribution* dist, | |
890 int shell_change, | |
891 const string16& chrome_exe) { | |
892 bool ret = true; | |
893 std::list<RegistryEntry*> entries; | |
894 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | |
895 RegistryEntry::GetDefaultBrowserUserEntries( | |
896 dist, chrome_exe, | |
897 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe), &entries); | |
898 // Change the default browser for current user. | |
robertshield
2012/08/05 15:01:12
nit: imo should add a blank line before the commen
gab
2012/08/06 19:39:27
Done.
| |
899 if ((shell_change & ShellUtil::CURRENT_USER) && | |
900 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | |
901 ret = false; | |
902 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | |
903 } | |
904 | |
905 // Chrome as default browser at system level. | |
906 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | |
907 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | |
908 ret = false; | |
909 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; | |
910 } | |
911 | |
912 return ret; | |
913 } | |
914 | |
871 } // namespace | 915 } // namespace |
872 | 916 |
873 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 917 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
874 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 918 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
875 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 919 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
876 const wchar_t* ShellUtil::kRegStartMenuInternet = | 920 const wchar_t* ShellUtil::kRegStartMenuInternet = |
877 L"Software\\Clients\\StartMenuInternet"; | 921 L"Software\\Clients\\StartMenuInternet"; |
878 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 922 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
879 const wchar_t* ShellUtil::kRegRegisteredApplications = | 923 const wchar_t* ShellUtil::kRegRegisteredApplications = |
880 L"Software\\RegisteredApplications"; | 924 L"Software\\RegisteredApplications"; |
(...skipping 26 matching lines...) Expand all Loading... | |
907 L"ApplicationDescription"; | 951 L"ApplicationDescription"; |
908 const wchar_t* ShellUtil::kRegApplicationName = L"ApplicationName"; | 952 const wchar_t* ShellUtil::kRegApplicationName = L"ApplicationName"; |
909 const wchar_t* ShellUtil::kRegApplicationIcon = L"ApplicationIcon"; | 953 const wchar_t* ShellUtil::kRegApplicationIcon = L"ApplicationIcon"; |
910 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; | 954 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; |
911 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; | 955 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; |
912 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; | 956 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; |
913 const wchar_t* ShellUtil::kRegVerbOpenNewWindow = L"opennewwindow"; | 957 const wchar_t* ShellUtil::kRegVerbOpenNewWindow = L"opennewwindow"; |
914 const wchar_t* ShellUtil::kRegVerbRun = L"run"; | 958 const wchar_t* ShellUtil::kRegVerbRun = L"run"; |
915 const wchar_t* ShellUtil::kRegCommand = L"command"; | 959 const wchar_t* ShellUtil::kRegCommand = L"command"; |
916 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 960 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
961 const wchar_t* ShellUtil::kRegOpenWithProgids = L"OpenWithProgids"; | |
917 | 962 |
918 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 963 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
919 const string16& chrome_exe, | 964 const string16& chrome_exe, |
920 const string16& suffix) { | 965 const string16& suffix) { |
921 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 966 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
922 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 967 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
923 } | 968 } |
924 | 969 |
925 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, | 970 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, |
926 const string16& chrome_exe, | 971 const string16& chrome_exe, |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 ShellUtil::kFileAssociations[i], AT_FILEEXTENSION); | 1326 ShellUtil::kFileAssociations[i], AT_FILEEXTENSION); |
1282 if (!SUCCEEDED(hr)) { | 1327 if (!SUCCEEDED(hr)) { |
1283 ret = false; | 1328 ret = false; |
1284 LOG(ERROR) << "Failed to register as default for file extension " | 1329 LOG(ERROR) << "Failed to register as default for file extension " |
1285 << ShellUtil::kFileAssociations[i] << " (" << hr << ")"; | 1330 << ShellUtil::kFileAssociations[i] << " (" << hr << ")"; |
1286 } | 1331 } |
1287 } | 1332 } |
1288 } | 1333 } |
1289 } | 1334 } |
1290 | 1335 |
1291 // Now use the old way to associate Chrome with supported protocols and file | 1336 if (!RegisterChromeAsDefaultForXP(dist, shell_change, chrome_exe)) |
1292 // associations. This should not be required on Vista but since some | |
1293 // applications still read Software\Classes\http key directly, we have to do | |
1294 // this on Vista also. | |
1295 | |
1296 std::list<RegistryEntry*> entries; | |
1297 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | |
1298 RegistryEntry::GetUserEntries( | |
1299 dist, chrome_exe, GetCurrentInstallationSuffix(dist, chrome_exe), | |
1300 &entries); | |
1301 // Change the default browser for current user. | |
1302 if ((shell_change & ShellUtil::CURRENT_USER) && | |
1303 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | |
1304 ret = false; | 1337 ret = false; |
1305 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | |
1306 } | |
1307 | |
1308 // Chrome as default browser at system level. | |
1309 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | |
1310 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | |
1311 ret = false; | |
1312 LOG(ERROR) << "Could not make Chrome default browser (XP/system level)."; | |
1313 } | |
1314 | 1338 |
1315 // Send Windows notification event so that it can update icons for | 1339 // Send Windows notification event so that it can update icons for |
1316 // file associations. | 1340 // file associations. |
1317 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); | 1341 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); |
1318 return ret; | 1342 return ret; |
1319 } | 1343 } |
1320 | 1344 |
1321 bool ShellUtil::ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist, | 1345 bool ShellUtil::ShowMakeChromeDefaultSystemUI(BrowserDistribution* dist, |
1322 const string16& chrome_exe) { | 1346 const string16& chrome_exe) { |
1323 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); | 1347 DCHECK_GE(base::win::GetVersion(), base::win::VERSION_WIN8); |
1324 if (!dist->CanSetAsDefault()) | 1348 if (!dist->CanSetAsDefault()) |
1325 return false; | 1349 return false; |
1326 | 1350 |
1327 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true)) | 1351 if (!RegisterChromeBrowser(dist, chrome_exe, string16(), true)) |
1328 return false; | 1352 return false; |
1329 | 1353 |
1330 // On Windows 8, you can't set yourself as the default handler | 1354 // On Windows 8, you can't set yourself as the default handler |
1331 // programatically. In other words IApplicationAssociationRegistration | 1355 // programatically. In other words IApplicationAssociationRegistration |
1332 // has been rendered useless. What you can do is to launch | 1356 // has been rendered useless. What you can do is to launch |
1333 // "Set Program Associations" section of the "Default Programs" | 1357 // "Set Program Associations" section of the "Default Programs" |
1334 // control panel, which is a mess, or pop the concise "How you want to open | 1358 // control panel, which is a mess, or pop the concise "How you want to open |
1335 // webpages?" dialog. We choose the latter. | 1359 // webpages?" dialog. We choose the latter. |
1336 // Return true only when the user took an action and there was no error. | 1360 // Return true only when the user took an action and there was no error. |
1337 return LaunchSelectDefaultProtocolHandlerDialog(L"http"); | 1361 const bool ret = LaunchSelectDefaultProtocolHandlerDialog(L"http"); |
1362 | |
1363 if (ret) { | |
1364 const int shell_change = | |
1365 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? CURRENT_USER : | |
1366 SYSTEM_LEVEL; | |
1367 RegisterChromeAsDefaultForXP(dist, shell_change, chrome_exe); | |
1368 } | |
1369 | |
1370 return ret; | |
1338 } | 1371 } |
1339 | 1372 |
1340 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, | 1373 bool ShellUtil::MakeChromeDefaultProtocolClient(BrowserDistribution* dist, |
1341 const string16& chrome_exe, | 1374 const string16& chrome_exe, |
1342 const string16& protocol) { | 1375 const string16& protocol) { |
1343 if (!dist->CanSetAsDefault()) | 1376 if (!dist->CanSetAsDefault()) |
1344 return false; | 1377 return false; |
1345 | 1378 |
1346 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); | 1379 ShellUtil::RegisterChromeForProtocol(dist, chrome_exe, L"", protocol, true); |
1347 | 1380 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 // Check if Chromium is already registered with this suffix. | 1439 // Check if Chromium is already registered with this suffix. |
1407 if (IsChromeRegistered(dist, chrome_exe, suffix)) | 1440 if (IsChromeRegistered(dist, chrome_exe, suffix)) |
1408 return true; | 1441 return true; |
1409 | 1442 |
1410 bool user_level = InstallUtil::IsPerUserInstall(chrome_exe.c_str()); | 1443 bool user_level = InstallUtil::IsPerUserInstall(chrome_exe.c_str()); |
1411 HKEY root = DetermineShellIntegrationRoot(user_level); | 1444 HKEY root = DetermineShellIntegrationRoot(user_level); |
1412 | 1445 |
1413 // Do the full registration if we can do it at user-level or if the user is an | 1446 // Do the full registration if we can do it at user-level or if the user is an |
1414 // admin. | 1447 // admin. |
1415 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { | 1448 if (root == HKEY_CURRENT_USER || IsUserAnAdmin()) { |
1416 std::list<RegistryEntry*> progids; | 1449 std::list<RegistryEntry*> progid_and_appreg_entries; |
1417 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); | 1450 STLElementDeleter<std::list<RegistryEntry*> > progdid_and_appreg_deleter( |
1451 &progid_and_appreg_entries); | |
1418 std::list<RegistryEntry*> shell_entries; | 1452 std::list<RegistryEntry*> shell_entries; |
1419 STLElementDeleter<std::list<RegistryEntry*> > shell_deleter(&shell_entries); | 1453 STLElementDeleter<std::list<RegistryEntry*> > shell_deleter(&shell_entries); |
1420 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); | 1454 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, |
1455 &progid_and_appreg_entries); | |
1456 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, | |
1457 &progid_and_appreg_entries); | |
1421 RegistryEntry::GetShellIntegrationEntries( | 1458 RegistryEntry::GetShellIntegrationEntries( |
1422 dist, chrome_exe, suffix, &shell_entries); | 1459 dist, chrome_exe, suffix, &shell_entries); |
1423 return AddRegistryEntries(user_level ? HKEY_CURRENT_USER : | 1460 return AddRegistryEntries(user_level ? HKEY_CURRENT_USER : |
1424 HKEY_LOCAL_MACHINE, | 1461 HKEY_LOCAL_MACHINE, |
1425 progids) && | 1462 progid_and_appreg_entries) && |
1426 AddRegistryEntries(root, shell_entries); | 1463 AddRegistryEntries(root, shell_entries); |
1427 } | 1464 } |
1428 | 1465 |
1429 // If the user is not an admin and OS is between Vista and Windows 7 | 1466 // If the user is not an admin and OS is between Vista and Windows 7 |
1430 // inclusively, try to elevate and register. This is only intended for | 1467 // inclusively, try to elevate and register. This is only intended for |
1431 // user-level installs as system-level installs should always be run with | 1468 // user-level installs as system-level installs should always be run with |
1432 // admin rights. | 1469 // admin rights. |
1433 if (elevate_if_not_admin && | 1470 if (elevate_if_not_admin && |
1434 base::win::GetVersion() >= base::win::VERSION_VISTA && | 1471 base::win::GetVersion() >= base::win::VERSION_VISTA && |
1435 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) | 1472 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) |
1436 return true; | 1473 return true; |
1437 | 1474 |
1438 // If we got to this point then all we can do is create ProgIds under HKCU. | 1475 // If we got to this point then all we can do is create ProgId and basic app |
1476 // registrations under HKCU. | |
1439 std::list<RegistryEntry*> entries; | 1477 std::list<RegistryEntry*> entries; |
1440 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1478 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
1441 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); | 1479 RegistryEntry::GetProgIdEntries(dist, chrome_exe, string16(), &entries); |
1442 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered with | 1480 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered with |
1443 // no suffix (as per the old registration style): in which case some other | 1481 // no suffix (as per the old registration style): in which case some other |
1444 // registry entries could refer to them and since we were not able to set our | 1482 // registry entries could refer to them and since we were not able to set our |
1445 // HKLM entries above, we are better off not altering these here. | 1483 // HKLM entries above, we are better off not altering these here. |
1446 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { | 1484 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { |
1447 if (!suffix.empty()) { | 1485 if (!suffix.empty()) { |
1448 STLDeleteElements(&entries); | 1486 STLDeleteElements(&entries); |
1449 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 1487 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
1488 RegistryEntry::GetAppRegistrationEntries(chrome_exe, suffix, &entries); | |
1450 } | 1489 } |
1451 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | 1490 return AddRegistryEntries(HKEY_CURRENT_USER, entries); |
1491 } else { | |
1492 // The ProgId is registered unsuffixed in HKCU, also register the app with | |
1493 // Windows in HKCU (this was not done in the old registration style and | |
1494 // thus needs to be done after the above check for the unsuffixed | |
1495 // registration). | |
1496 STLDeleteElements(&entries); | |
1497 RegistryEntry::GetAppRegistrationEntries(chrome_exe, string16(), &entries); | |
1498 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | |
1452 } | 1499 } |
1453 return true; | 1500 return true; |
1454 } | 1501 } |
1455 | 1502 |
1456 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 1503 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
1457 const string16& chrome_exe, | 1504 const string16& chrome_exe, |
1458 const string16& unique_suffix, | 1505 const string16& unique_suffix, |
1459 const string16& protocol, | 1506 const string16& protocol, |
1460 bool elevate_if_not_admin) { | 1507 bool elevate_if_not_admin) { |
1461 if (!dist->CanSetAsDefault()) | 1508 if (!dist->CanSetAsDefault()) |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1672 // are any left...). | 1719 // are any left...). |
1673 if (free_bits >= 8 && next_byte_index < size) { | 1720 if (free_bits >= 8 && next_byte_index < size) { |
1674 free_bits -= 8; | 1721 free_bits -= 8; |
1675 bit_stream += bytes[next_byte_index++] << free_bits; | 1722 bit_stream += bytes[next_byte_index++] << free_bits; |
1676 } | 1723 } |
1677 } | 1724 } |
1678 | 1725 |
1679 DCHECK_EQ(ret.length(), encoded_length); | 1726 DCHECK_EQ(ret.length(), encoded_length); |
1680 return ret; | 1727 return ret; |
1681 } | 1728 } |
OLD | NEW |