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

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

Issue 2186813002: Linux: Support the --class argument (Reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert gtk2_util.cc Created 4 years, 4 months 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 <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
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
211 } // namespace 226 } // namespace
212 227
213 bool SetAsDefaultBrowser() { 228 bool SetAsDefaultBrowser() {
214 return SetDefaultWebClient(std::string()); 229 return SetDefaultWebClient(std::string());
215 } 230 }
216 231
217 bool SetAsDefaultProtocolClient(const std::string& protocol) { 232 bool SetAsDefaultProtocolClient(const std::string& protocol) {
218 return SetDefaultWebClient(protocol); 233 return SetDefaultWebClient(protocol);
219 } 234 }
220 235
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 search_paths.push_back(data_dir); 584 search_paths.push_back(data_dir);
570 } 585 }
571 } else { 586 } else {
572 search_paths.push_back(base::FilePath("/usr/local/share")); 587 search_paths.push_back(base::FilePath("/usr/local/share"));
573 search_paths.push_back(base::FilePath("/usr/share")); 588 search_paths.push_back(base::FilePath("/usr/share"));
574 } 589 }
575 590
576 return search_paths; 591 return search_paths;
577 } 592 }
578 593
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
579 std::string GetProgramClassName() { 626 std::string GetProgramClassName() {
580 std::unique_ptr<base::Environment> env(base::Environment::Create()); 627 std::unique_ptr<base::Environment> env(base::Environment::Create());
581 std::string desktop_file(GetDesktopName(env.get())); 628 return internal::GetProgramClassName(*base::CommandLine::ForCurrentProcess(),
582 std::size_t last = desktop_file.find(".desktop"); 629 GetDesktopName(env.get()));
583 if (last != std::string::npos) 630 }
584 return desktop_file.substr(0, last); 631
585 return desktop_file; 632 std::string GetProgramClassClass() {
633 std::unique_ptr<base::Environment> env(base::Environment::Create());
634 return internal::GetProgramClassClass(*base::CommandLine::ForCurrentProcess(),
635 GetDesktopName(env.get()));
586 } 636 }
587 637
588 std::string GetDesktopName(base::Environment* env) { 638 std::string GetDesktopName(base::Environment* env) {
589 #if defined(GOOGLE_CHROME_BUILD) 639 #if defined(GOOGLE_CHROME_BUILD)
590 version_info::Channel product_channel(chrome::GetChannel()); 640 version_info::Channel product_channel(chrome::GetChannel());
591 switch (product_channel) { 641 switch (product_channel) {
592 case version_info::Channel::DEV: 642 case version_info::Channel::DEV:
593 return "google-chrome-unstable.desktop"; 643 return "google-chrome-unstable.desktop";
594 case version_info::Channel::BETA: 644 case version_info::Channel::BETA:
595 return "google-chrome-beta.desktop"; 645 return "google-chrome-beta.desktop";
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 base::FilePath applications_menu = GetDataWriteLocation(env.get()); 1106 base::FilePath applications_menu = GetDataWriteLocation(env.get());
1057 applications_menu = applications_menu.AppendASCII("applications"); 1107 applications_menu = applications_menu.AppendASCII("applications");
1058 std::vector<base::FilePath> shortcut_filenames_app_menu = 1108 std::vector<base::FilePath> shortcut_filenames_app_menu =
1059 GetExistingProfileShortcutFilenames(profile_path, applications_menu); 1109 GetExistingProfileShortcutFilenames(profile_path, applications_menu);
1060 for (const auto& menu : shortcut_filenames_app_menu) { 1110 for (const auto& menu : shortcut_filenames_app_menu) {
1061 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); 1111 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename));
1062 } 1112 }
1063 } 1113 }
1064 1114
1065 } // namespace shell_integration_linux 1115 } // namespace shell_integration_linux
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