Chromium Code Reviews| Index: chrome/browser/shell_integration_linux.cc |
| diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc |
| index 7e63e1dd943f06c7071f0bbffa990b6a4699728b..128bb132fc9004d9cbb58f1901c80dc7819dfa6a 100644 |
| --- a/chrome/browser/shell_integration_linux.cc |
| +++ b/chrome/browser/shell_integration_linux.cc |
| @@ -208,6 +208,18 @@ DefaultWebClientState GetIsDefaultWebClient(const std::string& protocol) { |
| #endif |
| } |
| +// https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased |
| +// The WM_CLASS property should be set to the same as the *.desktop file without |
| +// the .desktop extension. We cannot simply use argv[0] in this case, because |
| +// on the stable channel, the executable name is google-chrome-stable, but the |
| +// desktop file is google-chrome.desktop. |
| +std::string GetDesktopBaseName(const std::string& desktop_file_name) { |
| + std::size_t last = desktop_file_name.find(".desktop"); |
|
Lei Zhang
2016/07/28 21:28:46
BTW, std::string::find() in the worst case has a m
Tom (Use chromium acct)
2016/07/28 23:02:13
Done.
|
| + if (last != std::string::npos) |
| + return desktop_file_name.substr(0, last); |
| + return desktop_file_name; |
| +} |
| + |
| } // namespace |
| bool SetAsDefaultBrowser() { |
| @@ -576,13 +588,49 @@ std::vector<base::FilePath> GetDataSearchLocations(base::Environment* env) { |
| return search_paths; |
| } |
| +namespace internal { |
| + |
| +std::string GetProgramClassName(const base::CommandLine& command_line, |
| + const std::string& desktop_file_name) { |
| + std::string class_name = |
| + shell_integration::GetDesktopBaseName(desktop_file_name); |
| + if (command_line.HasSwitch(switches::kUserDataDir)) { |
|
Lei Zhang
2016/07/28 21:28:46
I wouldn't bother with this. I'd just call command
Tom (Use chromium acct)
2016/07/28 23:02:13
Done.
|
| + // Set the class name to e.g. "Chrome (/tmp/my-user-data)". The |
| + // class name will show up in the alt-tab list in gnome-shell if |
| + // you're running a binary that doesn't have a matching .desktop |
| + // file. |
| + const std::string user_data_dir = |
| + command_line.GetSwitchValueNative(switches::kUserDataDir); |
| + class_name += " (" + user_data_dir + ")"; |
| + } |
| + return class_name; |
| +} |
| + |
| +std::string GetProgramClassClass(const base::CommandLine& command_line, |
| + const std::string& desktop_file_name) { |
| + std::string class_class = |
|
Lei Zhang
2016/07/28 21:28:46
Call this after handling the switch?
Tom (Use chromium acct)
2016/07/28 23:02:13
Done.
|
| + shell_integration::GetDesktopBaseName(desktop_file_name); |
| + if (command_line.HasSwitch(switches::kWmClass)) |
| + return command_line.GetSwitchValueASCII(switches::kWmClass); |
| + if (!class_class.empty()) { |
| + // Capitalize the first character like gtk does. |
| + class_class[0] = base::ToUpperASCII(class_class[0]); |
| + } |
| + return class_class; |
| +} |
| + |
| +} // namespace internal |
| + |
| std::string GetProgramClassName() { |
| std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| - std::string desktop_file(GetDesktopName(env.get())); |
| - std::size_t last = desktop_file.find(".desktop"); |
| - if (last != std::string::npos) |
| - return desktop_file.substr(0, last); |
| - return desktop_file; |
| + return internal::GetProgramClassName(*base::CommandLine::ForCurrentProcess(), |
| + GetDesktopName(env.get())); |
| +} |
| + |
| +std::string GetProgramClassClass() { |
| + std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| + return internal::GetProgramClassClass(*base::CommandLine::ForCurrentProcess(), |
| + GetDesktopName(env.get())); |
| } |
| std::string GetDesktopName(base::Environment* env) { |