| 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::GetAppId(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::GetAppModelId(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::GetAppModelId(const string16& app_name, |
| 554 const FilePath& profile_path) { | 556 const FilePath& profile_path) { |
| 555 string16 app_id(app_name); | 557 string16 app_id(app_name); |
| 556 | 558 |
| 557 string16 profile_id(GetProfileIdFromPath(profile_path)); | 559 string16 profile_id(GetProfileIdFromPath(profile_path)); |
| 558 if (!profile_id.empty()) { | 560 if (!profile_id.empty()) { |
| 559 app_id += L"."; | 561 app_id += L"."; |
| 560 app_id += profile_id; | 562 app_id += profile_id; |
| 561 } | 563 } |
| 562 | 564 |
| 563 // App id should be less than 128 chars. | 565 // App id should be less than 64 chars. |
| 564 DCHECK(app_id.length() < 128); | 566 DCHECK_LT(app_id.length(), 64U); |
| 565 return app_id; | 567 return app_id; |
| 566 } | 568 } |
| 567 | 569 |
| 568 string16 ShellIntegration::GetChromiumAppId(const FilePath& profile_path) { | 570 string16 ShellIntegration::GetChromiumModelId(const FilePath& profile_path) { |
| 569 return GetAppId(BrowserDistribution::GetDistribution()->GetBrowserAppId(), | 571 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 570 profile_path); | 572 FilePath chrome_exe; |
| 573 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 574 NOTREACHED(); |
| 575 return dist->GetBaseAppId(); |
| 576 } |
| 577 return GetAppModelId( |
| 578 ShellUtil::GetAppId(dist, chrome_exe.value()), profile_path); |
| 571 } | 579 } |
| 572 | 580 |
| 573 string16 ShellIntegration::GetChromiumIconPath() { | 581 string16 ShellIntegration::GetChromiumIconPath() { |
| 574 // Determine the app path. If we can't determine what that is, we have | 582 // Determine the app path. If we can't determine what that is, we have |
| 575 // bigger fish to fry... | 583 // bigger fish to fry... |
| 576 FilePath app_path; | 584 FilePath app_path; |
| 577 if (!PathService::Get(base::FILE_EXE, &app_path)) { | 585 if (!PathService::Get(base::FILE_EXE, &app_path)) { |
| 578 NOTREACHED(); | 586 NOTREACHED(); |
| 579 return string16(); | 587 return string16(); |
| 580 } | 588 } |
| 581 | 589 |
| 582 string16 icon_path(app_path.value()); | 590 string16 icon_path(app_path.value()); |
| 583 icon_path.push_back(','); | 591 icon_path.push_back(','); |
| 584 icon_path += base::IntToString16( | 592 icon_path += base::IntToString16( |
| 585 BrowserDistribution::GetDistribution()->GetIconIndex()); | 593 BrowserDistribution::GetDistribution()->GetIconIndex()); |
| 586 return icon_path; | 594 return icon_path; |
| 587 } | 595 } |
| 588 | 596 |
| 589 void ShellIntegration::MigrateChromiumShortcuts() { | 597 void ShellIntegration::MigrateChromiumShortcuts() { |
| 590 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 598 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 591 return; | 599 return; |
| 592 | 600 |
| 593 BrowserThread::PostTask( | 601 BrowserThread::PostTask( |
| 594 BrowserThread::FILE, FROM_HERE, | 602 BrowserThread::FILE, FROM_HERE, |
| 595 base::Bind(&MigrateChromiumShortcutsCallback)); | 603 base::Bind(&MigrateChromiumShortcutsCallback)); |
| 596 } | 604 } |
| 597 | 605 |
| 598 bool ShellIntegration::ActivateMetroChrome() { | 606 bool ShellIntegration::ActivateMetroChrome() { |
| 599 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 607 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 600 const string16 app_id(dist->GetBrowserAppId()); | 608 FilePath chrome_exe; |
| 609 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 610 NOTREACHED(); |
| 611 return false; |
| 612 } |
| 613 const string16 app_id(ShellUtil::GetAppId(dist, chrome_exe.value())); |
| 601 return ActivateApplication(app_id); | 614 return ActivateApplication(app_id); |
| 602 } | 615 } |
| OLD | NEW |