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

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: add #ifdef for linux only property Created 7 years, 1 month 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 if (creation_locations.applications_menu_location ==
895 ShellIntegration::APP_MENU_LOCATION_SUBDIR_CHROMEAPPS) {
888 directory_filename = base::FilePath(kDirectoryFilename); 896 directory_filename = base::FilePath(kDirectoryFilename);
889 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents( 897 directory_contents = ShellIntegrationLinux::GetDirectoryFileContents(
890 creation_locations.applications_menu_subdir, ""); 898 ShellIntegration::GetAppShortcutsSubdirName(), "");
891 } 899 }
892 // Set NoDisplay=true if hidden but not in_applications_menu. This will hide 900 // Set NoDisplay=true if hidden but not in the applications menu. This will
893 // the application from user-facing menus. 901 // hide the application from user-facing menus.
894 std::string contents = ShellIntegrationLinux::GetDesktopFileContents( 902 std::string contents = ShellIntegrationLinux::GetDesktopFileContents(
895 chrome_exe_path, 903 chrome_exe_path,
896 app_name, 904 app_name,
897 shortcut_info.url, 905 shortcut_info.url,
898 shortcut_info.extension_id, 906 shortcut_info.extension_id,
899 shortcut_info.extension_path, 907 shortcut_info.extension_path,
900 shortcut_info.title, 908 shortcut_info.title,
901 icon_name, 909 icon_name,
902 shortcut_info.profile_path, 910 shortcut_info.profile_path,
903 !creation_locations.in_applications_menu); 911 creation_locations.applications_menu_location ==
912 ShellIntegration::APP_MENU_LOCATION_NONE);
904 success = CreateShortcutInApplicationsMenu( 913 success = CreateShortcutInApplicationsMenu(
905 shortcut_filename, contents, directory_filename, directory_contents) && 914 shortcut_filename, contents, directory_filename, directory_contents) &&
906 success; 915 success;
907 } 916 }
908 917
909 return success; 918 return success;
910 } 919 }
911 920
912 void DeleteDesktopShortcuts(const base::FilePath& profile_path, 921 void DeleteDesktopShortcuts(const base::FilePath& profile_path,
913 const std::string& extension_id) { 922 const std::string& extension_id) {
914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
915 924
916 base::FilePath shortcut_filename = GetExtensionShortcutFilename( 925 base::FilePath shortcut_filename = GetExtensionShortcutFilename(
917 profile_path, extension_id); 926 profile_path, extension_id);
918 DCHECK(!shortcut_filename.empty()); 927 DCHECK(!shortcut_filename.empty());
919 928
920 DeleteShortcutOnDesktop(shortcut_filename); 929 DeleteShortcutOnDesktop(shortcut_filename);
921 // Delete shortcuts from |kDirectoryFilename|. 930 // Delete shortcuts from |kDirectoryFilename|.
922 // Note that it is possible that shortcuts were not created in the Chrome Apps 931 // 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 932 // 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 933 // it isn't in the directory.
925 // if it isn't in the directory.
926 DeleteShortcutInApplicationsMenu(shortcut_filename, 934 DeleteShortcutInApplicationsMenu(shortcut_filename,
927 base::FilePath(kDirectoryFilename)); 935 base::FilePath(kDirectoryFilename));
928 } 936 }
929 937
930 void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) { 938 void DeleteAllDesktopShortcuts(const base::FilePath& profile_path) {
931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
932 940
933 scoped_ptr<base::Environment> env(base::Environment::Create()); 941 scoped_ptr<base::Environment> env(base::Environment::Create());
934 942
935 // Delete shortcuts from Desktop. 943 // Delete shortcuts from Desktop.
(...skipping 17 matching lines...) Expand all
953 for (std::vector<base::FilePath>::const_iterator it = 961 for (std::vector<base::FilePath>::const_iterator it =
954 shortcut_filenames_app_menu.begin(); 962 shortcut_filenames_app_menu.begin();
955 it != shortcut_filenames_app_menu.end(); ++it) { 963 it != shortcut_filenames_app_menu.end(); ++it) {
956 DeleteShortcutInApplicationsMenu(*it, 964 DeleteShortcutInApplicationsMenu(*it,
957 base::FilePath(kDirectoryFilename)); 965 base::FilePath(kDirectoryFilename));
958 } 966 }
959 } 967 }
960 } 968 }
961 969
962 } // namespace ShellIntegrationLinux 970 } // namespace ShellIntegrationLinux
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698