| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windows.h> | 10 #include <windows.h> |
| 11 #include <shellapi.h> | 11 #include <shellapi.h> |
| 12 #include <shlobj.h> | 12 #include <shlobj.h> |
| 13 | 13 |
| 14 #include "chrome/installer/util/shell_util.h" | 14 #include "chrome/installer/util/shell_util.h" |
| 15 | 15 |
| 16 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 19 #include "base/registry.h" | 20 #include "base/registry.h" |
| 20 #include "base/scoped_ptr.h" | 21 #include "base/scoped_ptr.h" |
| 21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
| 22 #include "base/win_util.h" | 23 #include "base/win_util.h" |
| 23 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/installer/util/browser_distribution.h" | 26 #include "chrome/installer/util/browser_distribution.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // in case of problem. | 285 // in case of problem. |
| 285 scoped_ptr<WorkItemList> items(WorkItem::CreateWorkItemList()); | 286 scoped_ptr<WorkItemList> items(WorkItem::CreateWorkItemList()); |
| 286 | 287 |
| 287 std::list<RegistryEntry*> entries = RegistryEntry::GetAllEntries(chrome_exe); | 288 std::list<RegistryEntry*> entries = RegistryEntry::GetAllEntries(chrome_exe); |
| 288 for (std::list<RegistryEntry*>::iterator itr = entries.begin(); | 289 for (std::list<RegistryEntry*>::iterator itr = entries.begin(); |
| 289 itr != entries.end(); ++itr) { | 290 itr != entries.end(); ++itr) { |
| 290 (*itr)->AddToWorkItemList(root_key, items.get()); | 291 (*itr)->AddToWorkItemList(root_key, items.get()); |
| 291 delete (*itr); | 292 delete (*itr); |
| 292 } | 293 } |
| 293 | 294 |
| 295 // Append the App Paths registry entries. Do this only if we are an admin, |
| 296 // since they are always written to HKLM. |
| 297 if (IsUserAnAdmin()) |
| 298 ShellUtil::AddChromeAppPathWorkItems(chrome_exe, items.get()); |
| 299 |
| 294 // Apply all the registry changes and if there is a problem, rollback. | 300 // Apply all the registry changes and if there is a problem, rollback. |
| 295 if (!items->Do()) { | 301 if (!items->Do()) { |
| 296 LOG(ERROR) << "Failed to add Chrome to Set Program Access and Defaults"; | 302 LOG(ERROR) << "Failed to add Chrome to Set Program Access and Defaults"; |
| 297 items->Rollback(); | 303 items->Rollback(); |
| 298 return false; | 304 return false; |
| 299 } | 305 } |
| 300 | 306 |
| 301 return true; | 307 return true; |
| 302 } | 308 } |
| 303 | 309 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } else { | 435 } else { |
| 430 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, | 436 if (FAILED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, |
| 431 SHGFP_TYPE_CURRENT, qlaunch))) | 437 SHGFP_TYPE_CURRENT, qlaunch))) |
| 432 return false; | 438 return false; |
| 433 *path = qlaunch; | 439 *path = qlaunch; |
| 434 } | 440 } |
| 435 file_util::AppendToPath(path, kQuickLaunchPath); | 441 file_util::AppendToPath(path, kQuickLaunchPath); |
| 436 return true; | 442 return true; |
| 437 } | 443 } |
| 438 | 444 |
| 445 void ShellUtil::AddChromeAppPathWorkItems( |
| 446 const std::wstring& chrome_exe, WorkItemList* item_list) { |
| 447 WorkItem* create_work_item = WorkItem::CreateCreateRegKeyWorkItem( |
| 448 HKEY_LOCAL_MACHINE, installer_util::kAppPathsRegistryKey); |
| 449 |
| 450 item_list->AddWorkItem(create_work_item); |
| 451 |
| 452 WorkItem* set_default_value_work_item = |
| 453 WorkItem::CreateSetRegValueWorkItem(HKEY_LOCAL_MACHINE, |
| 454 installer_util::kAppPathsRegistryKey, |
| 455 installer_util::kAppPathsRegistryDefaultName, |
| 456 chrome_exe, true); |
| 457 item_list->AddWorkItem(set_default_value_work_item); |
| 458 |
| 459 FilePath chrome_path(chrome_exe); |
| 460 WorkItem* set_path_value_work_item = |
| 461 WorkItem::CreateSetRegValueWorkItem(HKEY_LOCAL_MACHINE, |
| 462 installer_util::kAppPathsRegistryKey, |
| 463 installer_util::kAppPathsRegistryPathName, |
| 464 chrome_path.DirName().value(), true); |
| 465 item_list->AddWorkItem(set_path_value_work_item); |
| 466 } |
| 467 |
| 439 bool ShellUtil::CreateChromeDesktopShortcut(const std::wstring& chrome_exe, | 468 bool ShellUtil::CreateChromeDesktopShortcut(const std::wstring& chrome_exe, |
| 440 int shell_change, | 469 int shell_change, |
| 441 bool create_new) { | 470 bool create_new) { |
| 442 std::wstring shortcut_name; | 471 std::wstring shortcut_name; |
| 443 if (!ShellUtil::GetChromeShortcutName(&shortcut_name)) | 472 if (!ShellUtil::GetChromeShortcutName(&shortcut_name)) |
| 444 return false; | 473 return false; |
| 445 | 474 |
| 446 bool ret = true; | 475 bool ret = true; |
| 447 if (shell_change & ShellUtil::CURRENT_USER) { | 476 if (shell_change & ShellUtil::CURRENT_USER) { |
| 448 std::wstring shortcut_path; | 477 std::wstring shortcut_path; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 return file_util::UpdateShortcutLink(chrome_exe.c_str(), // target | 645 return file_util::UpdateShortcutLink(chrome_exe.c_str(), // target |
| 617 shortcut.c_str(), // shortcut | 646 shortcut.c_str(), // shortcut |
| 618 chrome_path.c_str(), // working dir | 647 chrome_path.c_str(), // working dir |
| 619 NULL, // arguments | 648 NULL, // arguments |
| 620 NULL, // description | 649 NULL, // description |
| 621 chrome_exe.c_str(), // icon file | 650 chrome_exe.c_str(), // icon file |
| 622 0); // icon index | 651 0); // icon index |
| 623 } | 652 } |
| 624 } | 653 } |
| 625 | 654 |
| OLD | NEW |