| 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 #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> |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 286 } |
| 287 | 287 |
| 288 string16 app_name; | 288 string16 app_name; |
| 289 if (command_line.HasSwitch(switches::kApp)) { | 289 if (command_line.HasSwitch(switches::kApp)) { |
| 290 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( | 290 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromURL( |
| 291 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); | 291 GURL(command_line.GetSwitchValueASCII(switches::kApp)))); |
| 292 } else if (command_line.HasSwitch(switches::kAppId)) { | 292 } else if (command_line.HasSwitch(switches::kAppId)) { |
| 293 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromExtensionId( | 293 app_name = UTF8ToUTF16(web_app::GenerateApplicationNameFromExtensionId( |
| 294 command_line.GetSwitchValueASCII(switches::kAppId))); | 294 command_line.GetSwitchValueASCII(switches::kAppId))); |
| 295 } else { | 295 } else { |
| 296 app_name = BrowserDistribution::GetDistribution()->GetBrowserAppId(); | 296 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 297 app_name = ShellUtil::GetBrowserModelId(dist, chrome_exe.value()); |
| 297 } | 298 } |
| 298 | 299 |
| 299 expected_app_id->assign(ShellIntegration::GetAppId(app_name, profile_path)); | 300 expected_app_id->assign( |
| 301 ShellIntegration::GetAppModelIdForProfile(app_name, profile_path)); |
| 300 return true; | 302 return true; |
| 301 } | 303 } |
| 302 | 304 |
| 303 void MigrateWin7ShortcutsInPath( | 305 void MigrateWin7ShortcutsInPath( |
| 304 const FilePath& chrome_exe, const FilePath& path) { | 306 const FilePath& chrome_exe, const FilePath& path) { |
| 305 // Enumerate all pinned shortcuts in the given path directly. | 307 // Enumerate all pinned shortcuts in the given path directly. |
| 306 file_util::FileEnumerator shortcuts_enum( | 308 file_util::FileEnumerator shortcuts_enum( |
| 307 path, false, // not recursive | 309 path, false, // not recursive |
| 308 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | 310 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
| 309 | 311 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 key_path.append(ShellUtil::kRegShellOpen); | 545 key_path.append(ShellUtil::kRegShellOpen); |
| 544 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); | 546 base::win::RegKey key(HKEY_CLASSES_ROOT, key_path.c_str(), KEY_READ); |
| 545 string16 app_cmd; | 547 string16 app_cmd; |
| 546 if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) && | 548 if (key.Valid() && (key.ReadValue(L"", &app_cmd) == ERROR_SUCCESS) && |
| 547 string16::npos != StringToLowerASCII(app_cmd).find(L"firefox")) | 549 string16::npos != StringToLowerASCII(app_cmd).find(L"firefox")) |
| 548 ff_default = true; | 550 ff_default = true; |
| 549 } | 551 } |
| 550 return ff_default; | 552 return ff_default; |
| 551 } | 553 } |
| 552 | 554 |
| 553 string16 ShellIntegration::GetAppId(const string16& app_name, | 555 string16 ShellIntegration::GetAppModelIdForProfile( |
| 554 const FilePath& profile_path) { | 556 const string16& app_name, |
| 555 string16 app_id(app_name); | 557 const FilePath& profile_path) { |
| 556 | 558 std::vector<string16> components; |
| 557 string16 profile_id(GetProfileIdFromPath(profile_path)); | 559 components.push_back(app_name); |
| 558 if (!profile_id.empty()) { | 560 const string16 profile_id(GetProfileIdFromPath(profile_path)); |
| 559 app_id += L"."; | 561 if (!profile_id.empty()) |
| 560 app_id += profile_id; | 562 components.push_back(profile_id); |
| 561 } | 563 return ShellUtil::BuildAppModelId(components); |
| 562 | |
| 563 // App id should be less than 128 chars. | |
| 564 DCHECK(app_id.length() < 128); | |
| 565 return app_id; | |
| 566 } | 564 } |
| 567 | 565 |
| 568 string16 ShellIntegration::GetChromiumAppId(const FilePath& profile_path) { | 566 string16 ShellIntegration::GetChromiumModelIdForProfile( |
| 569 return GetAppId(BrowserDistribution::GetDistribution()->GetBrowserAppId(), | 567 const FilePath& profile_path) { |
| 570 profile_path); | 568 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 569 FilePath chrome_exe; |
| 570 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 571 NOTREACHED(); |
| 572 return dist->GetBaseAppId(); |
| 573 } |
| 574 return GetAppModelIdForProfile( |
| 575 ShellUtil::GetBrowserModelId(dist, chrome_exe.value()), profile_path); |
| 571 } | 576 } |
| 572 | 577 |
| 573 string16 ShellIntegration::GetChromiumIconPath() { | 578 string16 ShellIntegration::GetChromiumIconPath() { |
| 574 // Determine the app path. If we can't determine what that is, we have | 579 // Determine the app path. If we can't determine what that is, we have |
| 575 // bigger fish to fry... | 580 // bigger fish to fry... |
| 576 FilePath app_path; | 581 FilePath app_path; |
| 577 if (!PathService::Get(base::FILE_EXE, &app_path)) { | 582 if (!PathService::Get(base::FILE_EXE, &app_path)) { |
| 578 NOTREACHED(); | 583 NOTREACHED(); |
| 579 return string16(); | 584 return string16(); |
| 580 } | 585 } |
| 581 | 586 |
| 582 string16 icon_path(app_path.value()); | 587 string16 icon_path(app_path.value()); |
| 583 icon_path.push_back(','); | 588 icon_path.push_back(','); |
| 584 icon_path += base::IntToString16( | 589 icon_path += base::IntToString16( |
| 585 BrowserDistribution::GetDistribution()->GetIconIndex()); | 590 BrowserDistribution::GetDistribution()->GetIconIndex()); |
| 586 return icon_path; | 591 return icon_path; |
| 587 } | 592 } |
| 588 | 593 |
| 589 void ShellIntegration::MigrateChromiumShortcuts() { | 594 void ShellIntegration::MigrateChromiumShortcuts() { |
| 590 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 595 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 591 return; | 596 return; |
| 592 | 597 |
| 593 BrowserThread::PostTask( | 598 BrowserThread::PostTask( |
| 594 BrowserThread::FILE, FROM_HERE, | 599 BrowserThread::FILE, FROM_HERE, |
| 595 base::Bind(&MigrateChromiumShortcutsCallback)); | 600 base::Bind(&MigrateChromiumShortcutsCallback)); |
| 596 } | 601 } |
| 597 | 602 |
| 598 bool ShellIntegration::ActivateMetroChrome() { | 603 bool ShellIntegration::ActivateMetroChrome() { |
| 599 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 604 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 600 const string16 app_id(dist->GetBrowserAppId()); | 605 FilePath chrome_exe; |
| 606 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 607 NOTREACHED(); |
| 608 return false; |
| 609 } |
| 610 const string16 app_id( |
| 611 ShellUtil::GetBrowserModelId(dist, chrome_exe.value())); |
| 601 return ActivateApplication(app_id); | 612 return ActivateApplication(app_id); |
| 602 } | 613 } |
| OLD | NEW |