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

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: 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 std::string GetDesktopBaseName() {
sky 2016/07/27 15:17:00 Please add comment.
Tom (Use chromium acct) 2016/07/27 19:33:09 Done.
212 std::unique_ptr<base::Environment> env(base::Environment::Create());
213 std::string desktop_file(shell_integration_linux::GetDesktopName(env.get()));
214 std::size_t last = desktop_file.find(".desktop");
215 if (last != std::string::npos)
216 return desktop_file.substr(0, last);
217 return desktop_file;
218 }
219
211 } // namespace 220 } // namespace
212 221
213 bool SetAsDefaultBrowser() { 222 bool SetAsDefaultBrowser() {
214 return SetDefaultWebClient(std::string()); 223 return SetDefaultWebClient(std::string());
215 } 224 }
216 225
217 bool SetAsDefaultProtocolClient(const std::string& protocol) { 226 bool SetAsDefaultProtocolClient(const std::string& protocol) {
218 return SetDefaultWebClient(protocol); 227 return SetDefaultWebClient(protocol);
219 } 228 }
220 229
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 579 }
571 } else { 580 } else {
572 search_paths.push_back(base::FilePath("/usr/local/share")); 581 search_paths.push_back(base::FilePath("/usr/local/share"));
573 search_paths.push_back(base::FilePath("/usr/share")); 582 search_paths.push_back(base::FilePath("/usr/share"));
574 } 583 }
575 584
576 return search_paths; 585 return search_paths;
577 } 586 }
578 587
579 std::string GetProgramClassName() { 588 std::string GetProgramClassName() {
580 std::unique_ptr<base::Environment> env(base::Environment::Create()); 589 std::string class_name = shell_integration::GetDesktopBaseName();
581 std::string desktop_file(GetDesktopName(env.get())); 590 const base::CommandLine& command_line =
582 std::size_t last = desktop_file.find(".desktop"); 591 *base::CommandLine::ForCurrentProcess();
583 if (last != std::string::npos) 592 if (command_line.HasSwitch(switches::kUserDataDir)) {
584 return desktop_file.substr(0, last); 593 // Set the class name to e.g. "Chrome (/tmp/my-user-data)". The
585 return desktop_file; 594 // class name will show up in the alt-tab list in gnome-shell if
595 // you're running a binary that doesn't have a matching .desktop
596 // file.
597 const std::string user_data_dir =
598 command_line.GetSwitchValueNative(switches::kUserDataDir);
599 class_name += " (" + user_data_dir + ")";
600 }
601 return class_name;
602 }
603
604 std::string GetProgramClassClass() {
605 const base::CommandLine& command_line =
606 *base::CommandLine::ForCurrentProcess();
607 if (command_line.HasSwitch(switches::kWmClass))
608 return command_line.GetSwitchValueASCII(switches::kWmClass);
609 std::string class_class = shell_integration::GetDesktopBaseName();
610 if (!class_class.empty()) {
611 // Capitalize the first character like gtk does.
612 class_class[0] = base::ToUpperASCII(class_class[0]);
613 }
614 return class_class;
586 } 615 }
587 616
588 std::string GetDesktopName(base::Environment* env) { 617 std::string GetDesktopName(base::Environment* env) {
589 #if defined(GOOGLE_CHROME_BUILD) 618 #if defined(GOOGLE_CHROME_BUILD)
590 version_info::Channel product_channel(chrome::GetChannel()); 619 version_info::Channel product_channel(chrome::GetChannel());
591 switch (product_channel) { 620 switch (product_channel) {
592 case version_info::Channel::DEV: 621 case version_info::Channel::DEV:
593 return "google-chrome-unstable.desktop"; 622 return "google-chrome-unstable.desktop";
594 case version_info::Channel::BETA: 623 case version_info::Channel::BETA:
595 return "google-chrome-beta.desktop"; 624 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()); 1085 base::FilePath applications_menu = GetDataWriteLocation(env.get());
1057 applications_menu = applications_menu.AppendASCII("applications"); 1086 applications_menu = applications_menu.AppendASCII("applications");
1058 std::vector<base::FilePath> shortcut_filenames_app_menu = 1087 std::vector<base::FilePath> shortcut_filenames_app_menu =
1059 GetExistingProfileShortcutFilenames(profile_path, applications_menu); 1088 GetExistingProfileShortcutFilenames(profile_path, applications_menu);
1060 for (const auto& menu : shortcut_filenames_app_menu) { 1089 for (const auto& menu : shortcut_filenames_app_menu) {
1061 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); 1090 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename));
1062 } 1091 }
1063 } 1092 }
1064 1093
1065 } // namespace shell_integration_linux 1094 } // namespace shell_integration_linux
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698