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 std::size_t last = desktop_file_name.find(".desktop"); |
| 218 if (last != std::string::npos) |
| 219 return desktop_file_name.substr(0, last); |
| 220 return desktop_file_name; |
| 221 } |
| 222 |
211 } // namespace | 223 } // namespace |
212 | 224 |
213 bool SetAsDefaultBrowser() { | 225 bool SetAsDefaultBrowser() { |
214 return SetDefaultWebClient(std::string()); | 226 return SetDefaultWebClient(std::string()); |
215 } | 227 } |
216 | 228 |
217 bool SetAsDefaultProtocolClient(const std::string& protocol) { | 229 bool SetAsDefaultProtocolClient(const std::string& protocol) { |
218 return SetDefaultWebClient(protocol); | 230 return SetDefaultWebClient(protocol); |
219 } | 231 } |
220 | 232 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 search_paths.push_back(data_dir); | 581 search_paths.push_back(data_dir); |
570 } | 582 } |
571 } else { | 583 } else { |
572 search_paths.push_back(base::FilePath("/usr/local/share")); | 584 search_paths.push_back(base::FilePath("/usr/local/share")); |
573 search_paths.push_back(base::FilePath("/usr/share")); | 585 search_paths.push_back(base::FilePath("/usr/share")); |
574 } | 586 } |
575 | 587 |
576 return search_paths; | 588 return search_paths; |
577 } | 589 } |
578 | 590 |
| 591 std::string GetProgramClassName(const base::CommandLine& command_line, |
| 592 const std::string& desktop_file_name) { |
| 593 std::string class_name = |
| 594 shell_integration::GetDesktopBaseName(desktop_file_name); |
| 595 if (command_line.HasSwitch(switches::kUserDataDir)) { |
| 596 // Set the class name to e.g. "Chrome (/tmp/my-user-data)". The |
| 597 // class name will show up in the alt-tab list in gnome-shell if |
| 598 // you're running a binary that doesn't have a matching .desktop |
| 599 // file. |
| 600 const std::string user_data_dir = |
| 601 command_line.GetSwitchValueNative(switches::kUserDataDir); |
| 602 class_name += " (" + user_data_dir + ")"; |
| 603 } |
| 604 return class_name; |
| 605 } |
| 606 |
579 std::string GetProgramClassName() { | 607 std::string GetProgramClassName() { |
580 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 608 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
581 std::string desktop_file(GetDesktopName(env.get())); | 609 return GetProgramClassName(*base::CommandLine::ForCurrentProcess(), |
582 std::size_t last = desktop_file.find(".desktop"); | 610 GetDesktopName(env.get())); |
583 if (last != std::string::npos) | 611 } |
584 return desktop_file.substr(0, last); | 612 |
585 return desktop_file; | 613 std::string GetProgramClassClass(const base::CommandLine& command_line, |
| 614 const std::string& desktop_file_name) { |
| 615 std::string class_class = |
| 616 shell_integration::GetDesktopBaseName(desktop_file_name); |
| 617 if (command_line.HasSwitch(switches::kWmClass)) |
| 618 return command_line.GetSwitchValueASCII(switches::kWmClass); |
| 619 if (!class_class.empty()) { |
| 620 // Capitalize the first character like gtk does. |
| 621 class_class[0] = base::ToUpperASCII(class_class[0]); |
| 622 } |
| 623 return class_class; |
| 624 } |
| 625 |
| 626 std::string GetProgramClassClass() { |
| 627 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 628 return GetProgramClassClass(*base::CommandLine::ForCurrentProcess(), |
| 629 GetDesktopName(env.get())); |
586 } | 630 } |
587 | 631 |
588 std::string GetDesktopName(base::Environment* env) { | 632 std::string GetDesktopName(base::Environment* env) { |
589 #if defined(GOOGLE_CHROME_BUILD) | 633 #if defined(GOOGLE_CHROME_BUILD) |
590 version_info::Channel product_channel(chrome::GetChannel()); | 634 version_info::Channel product_channel(chrome::GetChannel()); |
591 switch (product_channel) { | 635 switch (product_channel) { |
592 case version_info::Channel::DEV: | 636 case version_info::Channel::DEV: |
593 return "google-chrome-unstable.desktop"; | 637 return "google-chrome-unstable.desktop"; |
594 case version_info::Channel::BETA: | 638 case version_info::Channel::BETA: |
595 return "google-chrome-beta.desktop"; | 639 return "google-chrome-beta.desktop"; |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 base::FilePath applications_menu = GetDataWriteLocation(env.get()); | 1100 base::FilePath applications_menu = GetDataWriteLocation(env.get()); |
1057 applications_menu = applications_menu.AppendASCII("applications"); | 1101 applications_menu = applications_menu.AppendASCII("applications"); |
1058 std::vector<base::FilePath> shortcut_filenames_app_menu = | 1102 std::vector<base::FilePath> shortcut_filenames_app_menu = |
1059 GetExistingProfileShortcutFilenames(profile_path, applications_menu); | 1103 GetExistingProfileShortcutFilenames(profile_path, applications_menu); |
1060 for (const auto& menu : shortcut_filenames_app_menu) { | 1104 for (const auto& menu : shortcut_filenames_app_menu) { |
1061 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); | 1105 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); |
1062 } | 1106 } |
1063 } | 1107 } |
1064 | 1108 |
1065 } // namespace shell_integration_linux | 1109 } // namespace shell_integration_linux |
OLD | NEW |