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

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

Issue 13864015: Move app launcher and chrome apps shortcut strings into the installer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_app_id_fix
Patch Set: fix win compile, change LOG(INFO)s to VLOG(1) Created 7 years 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
OLDNEW
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_linux.h" 5 #include "chrome/browser/shell_integration_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <glib.h> 8 #include <glib.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 } 581 }
582 582
583 ShellIntegration::ShortcutLocations GetExistingShortcutLocations( 583 ShellIntegration::ShortcutLocations GetExistingShortcutLocations(
584 base::Environment* env, 584 base::Environment* env,
585 const base::FilePath& profile_path, 585 const base::FilePath& profile_path,
586 const std::string& extension_id) { 586 const std::string& extension_id) {
587 base::FilePath desktop_path; 587 base::FilePath desktop_path;
588 // If Get returns false, just leave desktop_path empty. 588 // If Get returns false, just leave desktop_path empty.
589 PathService::Get(base::DIR_USER_DESKTOP, &desktop_path); 589 PathService::Get(base::DIR_USER_DESKTOP, &desktop_path);
590 return GetExistingShortcutLocations(env, profile_path, extension_id, 590 return GetExistingShortcutLocations(env, profile_path, extension_id,
591 desktop_path); 591 desktop_path);
592 } 592 }
593 593
594 ShellIntegration::ShortcutLocations GetExistingShortcutLocations( 594 ShellIntegration::ShortcutLocations GetExistingShortcutLocations(
595 base::Environment* env, 595 base::Environment* env,
596 const base::FilePath& profile_path, 596 const base::FilePath& profile_path,
597 const std::string& extension_id, 597 const std::string& extension_id,
598 const base::FilePath& desktop_path) { 598 const base::FilePath& desktop_path) {
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
600 600
601 base::FilePath shortcut_filename = GetExtensionShortcutFilename( 601 base::FilePath shortcut_filename = GetExtensionShortcutFilename(
602 profile_path, extension_id); 602 profile_path, extension_id);
603 DCHECK(!shortcut_filename.empty()); 603 DCHECK(!shortcut_filename.empty());
604 ShellIntegration::ShortcutLocations locations; 604 ShellIntegration::ShortcutLocations locations;
605 605
606 // Determine whether there is a shortcut on desktop. 606 // Determine whether there is a shortcut on desktop.
607 if (!desktop_path.empty()) { 607 if (!desktop_path.empty()) {
608 locations.on_desktop = 608 locations.on_desktop =
609 base::PathExists(desktop_path.Append(shortcut_filename)); 609 base::PathExists(desktop_path.Append(shortcut_filename));
610 } 610 }
611 611
612 // Determine whether there is a shortcut in the applications directory. 612 // Determine whether there is a shortcut in the applications directory.
613 std::string shortcut_contents; 613 std::string shortcut_contents;
614 if (GetExistingShortcutContents(env, shortcut_filename, &shortcut_contents)) { 614 if (GetExistingShortcutContents(env, shortcut_filename, &shortcut_contents)) {
615 // Whether this counts as "hidden" or "in_applications_menu" depends on 615 // Whether this counts as "hidden" or "APP_MENU_LOCATION_SUBDIR_CHROMEAPPS"
616 // whether it contains NoDisplay=true. 616 // depends on whether it contains NoDisplay=true. Since these shortcuts are
617 if (GetNoDisplayFromDesktopFile(shortcut_contents)) 617 // for apps, they are always in the "Chrome Apps" directory.
618 if (GetNoDisplayFromDesktopFile(shortcut_contents)) {
618 locations.hidden = true; 619 locations.hidden = true;
619 else 620 } else {
620 locations.in_applications_menu = true; 621 locations.applications_menu_location =
622 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
623 }
621 } 624 }
622 625
623 return locations; 626 return locations;
624 } 627 }
625 628
626 bool GetExistingShortcutContents(base::Environment* env, 629 bool GetExistingShortcutContents(base::Environment* env,
627 const base::FilePath& desktop_filename, 630 const base::FilePath& desktop_filename,
628 std::string* output) { 631 std::string* output) {
629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 632 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
630 633
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
838 841
839 base::FilePath shortcut_filename; 842 base::FilePath shortcut_filename;
840 if (!shortcut_info.extension_id.empty()) { 843 if (!shortcut_info.extension_id.empty()) {
841 shortcut_filename = GetExtensionShortcutFilename( 844 shortcut_filename = GetExtensionShortcutFilename(
842 shortcut_info.profile_path, shortcut_info.extension_id); 845 shortcut_info.profile_path, shortcut_info.extension_id);
843 // For extensions we do not want duplicate shortcuts. So, delete any that 846 // For extensions we do not want duplicate shortcuts. So, delete any that
844 // already exist and replace them. 847 // already exist and replace them.
845 if (creation_locations.on_desktop) 848 if (creation_locations.on_desktop)
846 DeleteShortcutOnDesktop(shortcut_filename); 849 DeleteShortcutOnDesktop(shortcut_filename);
847 if (creation_locations.in_applications_menu || creation_locations.hidden) 850 // The 'applications_menu_location' and 'hidden' locations are actually the
851 // same place ('applications').
852 if (creation_locations.applications_menu_location !=
853 ShellIntegration::APP_MENU_LOCATION_NONE ||
854 creation_locations.hidden)
848 DeleteShortcutInApplicationsMenu(shortcut_filename, base::FilePath()); 855 DeleteShortcutInApplicationsMenu(shortcut_filename, base::FilePath());
849 } else { 856 } else {
850 shortcut_filename = GetWebShortcutFilename(shortcut_info.url); 857 shortcut_filename = GetWebShortcutFilename(shortcut_info.url);
851 } 858 }
852 if (shortcut_filename.empty()) 859 if (shortcut_filename.empty())
853 return false; 860 return false;
854 861
855 std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename); 862 std::string icon_name = CreateShortcutIcon(shortcut_info, shortcut_filename);
856 863
857 std::string app_name = 864 std::string app_name =
(...skipping 14 matching lines...) Expand all
872 shortcut_info.url, 879 shortcut_info.url,
873 shortcut_info.extension_id, 880 shortcut_info.extension_id,
874 shortcut_info.extension_path, 881 shortcut_info.extension_path,
875 shortcut_info.title, 882 shortcut_info.title,
876 icon_name, 883 icon_name,
877 shortcut_info.profile_path, 884 shortcut_info.profile_path,
878 false); 885 false);
879 success = CreateShortcutOnDesktop(shortcut_filename, contents); 886 success = CreateShortcutOnDesktop(shortcut_filename, contents);
880 } 887 }
881 888
882 // The 'in_applications_menu' and 'hidden' locations are actually the same 889 if (creation_locations.applications_menu_location !=
883 // place ('applications'). 890 ShellIntegration::APP_MENU_LOCATION_NONE ||
884 if (creation_locations.in_applications_menu || creation_locations.hidden) { 891 creation_locations.hidden) {
885 base::FilePath directory_filename; 892 base::FilePath directory_filename;
886 std::string directory_contents; 893 std::string directory_contents;
887 if (!creation_locations.applications_menu_subdir.empty()) { 894 switch (creation_locations.applications_menu_location) {
888 directory_filename = base::FilePath(kDirectoryFilename); 895 case ShellIntegration::APP_MENU_LOCATION_NONE:
889 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents( 896 case ShellIntegration::APP_MENU_LOCATION_ROOT:
890 creation_locations.applications_menu_subdir, ""); 897 break;
898 case ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS:
899 directory_filename = base::FilePath(kDirectoryFilename);
900 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents(
901 ShellIntegration::GetAppShortcutsSubdirName(), "");
902 break;
903 default:
904 NOTREACHED();
905 break;
891 } 906 }
892 // Set NoDisplay=true if hidden but not in_applications_menu. This will hide 907 // Set NoDisplay=true if hidden but not in the applications menu. This will
893 // the application from user-facing menus. 908 // hide the application from user-facing menus.
894 std::string contents = ShellIntegrationLinux::GetDesktopFileContents( 909 std::string contents = ShellIntegrationLinux::GetDesktopFileContents(
895 chrome_exe_path, 910 chrome_exe_path,
896 app_name, 911 app_name,
897 shortcut_info.url, 912 shortcut_info.url,
898 shortcut_info.extension_id, 913 shortcut_info.extension_id,
899 shortcut_info.extension_path, 914 shortcut_info.extension_path,
900 shortcut_info.title, 915 shortcut_info.title,
901 icon_name, 916 icon_name,
902 shortcut_info.profile_path, 917 shortcut_info.profile_path,
903 !creation_locations.in_applications_menu); 918 creation_locations.applications_menu_location ==
919 ShellIntegration::APP_MENU_LOCATION_NONE);
904 success = CreateShortcutInApplicationsMenu( 920 success = CreateShortcutInApplicationsMenu(
905 shortcut_filename, contents, directory_filename, directory_contents) && 921 shortcut_filename, contents, directory_filename, directory_contents) &&
906 success; 922 success;
907 } 923 }
908 924
909 return success; 925 return success;
910 } 926 }
911 927
912 void DeleteDesktopShortcuts(const base::FilePath& profile_path, 928 void DeleteDesktopShortcuts(const base::FilePath& profile_path,
913 const std::string& extension_id) { 929 const std::string& extension_id) {
914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 930 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
915 931
916 base::FilePath shortcut_filename = GetExtensionShortcutFilename( 932 base::FilePath shortcut_filename = GetExtensionShortcutFilename(
917 profile_path, extension_id); 933 profile_path, extension_id);
918 DCHECK(!shortcut_filename.empty()); 934 DCHECK(!shortcut_filename.empty());
919 935
920 DeleteShortcutOnDesktop(shortcut_filename); 936 DeleteShortcutOnDesktop(shortcut_filename);
921 // Delete shortcuts from |kDirectoryFilename|. 937 // Delete shortcuts from |kDirectoryFilename|.
922 // Note that it is possible that shortcuts were not created in the Chrome Apps 938 // Note that it is possible that shortcuts were not created in the Chrome Apps
923 // directory (depending on the value of |applications_menu_subdir| when they 939 // directory. It doesn't matter: this will still delete the shortcut even if
924 // were created). It doesn't matter: this will still delete the shortcut even 940 // it isn't in the directory.
925 // if it isn't in the directory.
926 DeleteShortcutInApplicationsMenu(shortcut_filename, 941 DeleteShortcutInApplicationsMenu(shortcut_filename,
927 base::FilePath(kDirectoryFilename)); 942 base::FilePath(kDirectoryFilename));
928 } 943 }
929 944
930 void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) { 945 void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) {
931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 946 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
932 947
933 scoped_ptr<base::Environment> env(base::Environment::Create()); 948 scoped_ptr<base::Environment> env(base::Environment::Create());
934 949
935 // Delete shortcuts from Desktop. 950 // Delete shortcuts from Desktop.
(...skipping 17 matching lines...) Expand all
953 for (std::vector<base::FilePath>::const_iterator it = 968 for (std::vector<base::FilePath>::const_iterator it =
954 shortcut_filenames_app_menu.begin(); 969 shortcut_filenames_app_menu.begin();
955 it != shortcut_filenames_app_menu.end(); ++it) { 970 it != shortcut_filenames_app_menu.end(); ++it) {
956 DeleteShortcutInApplicationsMenu(*it, 971 DeleteShortcutInApplicationsMenu(*it,
957 base::FilePath(kDirectoryFilename)); 972 base::FilePath(kDirectoryFilename));
958 } 973 }
959 } 974 }
960 } 975 }
961 976
962 } // namespace ShellIntegrationLinux 977 } // namespace ShellIntegrationLinux
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_linux.h ('k') | chrome/browser/shell_integration_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698