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_linux.h" | 5 #include "chrome/browser/shell_integration_linux.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 return UNKNOWN_DEFAULT; | 201 return UNKNOWN_DEFAULT; |
202 } | 202 } |
203 | 203 |
204 // Allow any reply that starts with "yes". | 204 // Allow any reply that starts with "yes". |
205 return base::StartsWith(reply, "yes", base::CompareCase::SENSITIVE) | 205 return base::StartsWith(reply, "yes", base::CompareCase::SENSITIVE) |
206 ? IS_DEFAULT | 206 ? IS_DEFAULT |
207 : NOT_DEFAULT; | 207 : NOT_DEFAULT; |
208 #endif | 208 #endif |
209 } | 209 } |
210 | 210 |
211 // https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased | |
212 // The WM_CLASS property should be set to the same as the *.desktop file without | |
213 // the .desktop extension. We cannot simply use argv[0] in this case, because | |
214 // on the stable channel, the executable name is google-chrome-stable, but the | |
215 // desktop file is google-chrome.desktop. | |
216 std::string GetDesktopBaseName(const std::string& desktop_file_name) { | |
217 static const char kDesktopExtension[] = ".desktop"; | |
218 if (base::EndsWith(desktop_file_name, kDesktopExtension, | |
219 base::CompareCase::SENSITIVE)) { | |
220 return desktop_file_name.substr( | |
221 0, desktop_file_name.length() - strlen(kDesktopExtension)); | |
222 } | |
223 return desktop_file_name; | |
224 } | |
225 | |
226 } // namespace | 211 } // namespace |
227 | 212 |
228 bool SetAsDefaultBrowser() { | 213 bool SetAsDefaultBrowser() { |
229 return SetDefaultWebClient(std::string()); | 214 return SetDefaultWebClient(std::string()); |
230 } | 215 } |
231 | 216 |
232 bool SetAsDefaultProtocolClient(const std::string& protocol) { | 217 bool SetAsDefaultProtocolClient(const std::string& protocol) { |
233 return SetDefaultWebClient(protocol); | 218 return SetDefaultWebClient(protocol); |
234 } | 219 } |
235 | 220 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 search_paths.push_back(data_dir); | 569 search_paths.push_back(data_dir); |
585 } | 570 } |
586 } else { | 571 } else { |
587 search_paths.push_back(base::FilePath("/usr/local/share")); | 572 search_paths.push_back(base::FilePath("/usr/local/share")); |
588 search_paths.push_back(base::FilePath("/usr/share")); | 573 search_paths.push_back(base::FilePath("/usr/share")); |
589 } | 574 } |
590 | 575 |
591 return search_paths; | 576 return search_paths; |
592 } | 577 } |
593 | 578 |
594 namespace internal { | |
595 | |
596 std::string GetProgramClassName(const base::CommandLine& command_line, | |
597 const std::string& desktop_file_name) { | |
598 std::string class_name = | |
599 shell_integration::GetDesktopBaseName(desktop_file_name); | |
600 std::string user_data_dir = | |
601 command_line.GetSwitchValueNative(switches::kUserDataDir); | |
602 // If the user launches with e.g. --user-data-dir=/tmp/my-user-data, set the | |
603 // class name to "Chrome (/tmp/my-user-data)". The class name will show up in | |
604 // the alt-tab list in gnome-shell if you're running a binary that doesn't | |
605 // have a matching .desktop file. | |
606 return user_data_dir.empty() | |
607 ? class_name | |
608 : class_name + " (" + user_data_dir + ")"; | |
609 } | |
610 | |
611 std::string GetProgramClassClass(const base::CommandLine& command_line, | |
612 const std::string& desktop_file_name) { | |
613 if (command_line.HasSwitch(switches::kWmClass)) | |
614 return command_line.GetSwitchValueASCII(switches::kWmClass); | |
615 std::string class_class = | |
616 shell_integration::GetDesktopBaseName(desktop_file_name); | |
617 if (!class_class.empty()) { | |
618 // Capitalize the first character like gtk does. | |
619 class_class[0] = base::ToUpperASCII(class_class[0]); | |
620 } | |
621 return class_class; | |
622 } | |
623 | |
624 } // namespace internal | |
625 | |
626 std::string GetProgramClassName() { | 579 std::string GetProgramClassName() { |
627 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 580 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
628 return internal::GetProgramClassName(*base::CommandLine::ForCurrentProcess(), | 581 std::string desktop_file(GetDesktopName(env.get())); |
629 GetDesktopName(env.get())); | 582 std::size_t last = desktop_file.find(".desktop"); |
630 } | 583 if (last != std::string::npos) |
631 | 584 return desktop_file.substr(0, last); |
632 std::string GetProgramClassClass() { | 585 return desktop_file; |
633 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
634 return internal::GetProgramClassClass(*base::CommandLine::ForCurrentProcess(), | |
635 GetDesktopName(env.get())); | |
636 } | 586 } |
637 | 587 |
638 std::string GetDesktopName(base::Environment* env) { | 588 std::string GetDesktopName(base::Environment* env) { |
639 #if defined(GOOGLE_CHROME_BUILD) | 589 #if defined(GOOGLE_CHROME_BUILD) |
640 version_info::Channel product_channel(chrome::GetChannel()); | 590 version_info::Channel product_channel(chrome::GetChannel()); |
641 switch (product_channel) { | 591 switch (product_channel) { |
642 case version_info::Channel::DEV: | 592 case version_info::Channel::DEV: |
643 return "google-chrome-unstable.desktop"; | 593 return "google-chrome-unstable.desktop"; |
644 case version_info::Channel::BETA: | 594 case version_info::Channel::BETA: |
645 return "google-chrome-beta.desktop"; | 595 return "google-chrome-beta.desktop"; |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1106 base::FilePath applications_menu = GetDataWriteLocation(env.get()); | 1056 base::FilePath applications_menu = GetDataWriteLocation(env.get()); |
1107 applications_menu = applications_menu.AppendASCII("applications"); | 1057 applications_menu = applications_menu.AppendASCII("applications"); |
1108 std::vector<base::FilePath> shortcut_filenames_app_menu = | 1058 std::vector<base::FilePath> shortcut_filenames_app_menu = |
1109 GetExistingProfileShortcutFilenames(profile_path, applications_menu); | 1059 GetExistingProfileShortcutFilenames(profile_path, applications_menu); |
1110 for (const auto& menu : shortcut_filenames_app_menu) { | 1060 for (const auto& menu : shortcut_filenames_app_menu) { |
1111 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); | 1061 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); |
1112 } | 1062 } |
1113 } | 1063 } |
1114 | 1064 |
1115 } // namespace shell_integration_linux | 1065 } // namespace shell_integration_linux |
OLD | NEW |