Chromium Code Reviews| 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"); | |
|
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.
| |
| 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 namespace internal { | |
| 592 | |
| 593 std::string GetProgramClassName(const base::CommandLine& command_line, | |
| 594 const std::string& desktop_file_name) { | |
| 595 std::string class_name = | |
| 596 shell_integration::GetDesktopBaseName(desktop_file_name); | |
| 597 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.
| |
| 598 // Set the class name to e.g. "Chrome (/tmp/my-user-data)". The | |
| 599 // class name will show up in the alt-tab list in gnome-shell if | |
| 600 // you're running a binary that doesn't have a matching .desktop | |
| 601 // file. | |
| 602 const std::string user_data_dir = | |
| 603 command_line.GetSwitchValueNative(switches::kUserDataDir); | |
| 604 class_name += " (" + user_data_dir + ")"; | |
| 605 } | |
| 606 return class_name; | |
| 607 } | |
| 608 | |
| 609 std::string GetProgramClassClass(const base::CommandLine& command_line, | |
| 610 const std::string& desktop_file_name) { | |
| 611 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.
| |
| 612 shell_integration::GetDesktopBaseName(desktop_file_name); | |
| 613 if (command_line.HasSwitch(switches::kWmClass)) | |
| 614 return command_line.GetSwitchValueASCII(switches::kWmClass); | |
| 615 if (!class_class.empty()) { | |
| 616 // Capitalize the first character like gtk does. | |
| 617 class_class[0] = base::ToUpperASCII(class_class[0]); | |
| 618 } | |
| 619 return class_class; | |
| 620 } | |
| 621 | |
| 622 } // namespace internal | |
| 623 | |
| 579 std::string GetProgramClassName() { | 624 std::string GetProgramClassName() { |
| 580 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 625 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 581 std::string desktop_file(GetDesktopName(env.get())); | 626 return internal::GetProgramClassName(*base::CommandLine::ForCurrentProcess(), |
| 582 std::size_t last = desktop_file.find(".desktop"); | 627 GetDesktopName(env.get())); |
| 583 if (last != std::string::npos) | 628 } |
| 584 return desktop_file.substr(0, last); | 629 |
| 585 return desktop_file; | 630 std::string GetProgramClassClass() { |
| 631 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
| 632 return internal::GetProgramClassClass(*base::CommandLine::ForCurrentProcess(), | |
| 633 GetDesktopName(env.get())); | |
| 586 } | 634 } |
| 587 | 635 |
| 588 std::string GetDesktopName(base::Environment* env) { | 636 std::string GetDesktopName(base::Environment* env) { |
| 589 #if defined(GOOGLE_CHROME_BUILD) | 637 #if defined(GOOGLE_CHROME_BUILD) |
| 590 version_info::Channel product_channel(chrome::GetChannel()); | 638 version_info::Channel product_channel(chrome::GetChannel()); |
| 591 switch (product_channel) { | 639 switch (product_channel) { |
| 592 case version_info::Channel::DEV: | 640 case version_info::Channel::DEV: |
| 593 return "google-chrome-unstable.desktop"; | 641 return "google-chrome-unstable.desktop"; |
| 594 case version_info::Channel::BETA: | 642 case version_info::Channel::BETA: |
| 595 return "google-chrome-beta.desktop"; | 643 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()); | 1104 base::FilePath applications_menu = GetDataWriteLocation(env.get()); |
| 1057 applications_menu = applications_menu.AppendASCII("applications"); | 1105 applications_menu = applications_menu.AppendASCII("applications"); |
| 1058 std::vector<base::FilePath> shortcut_filenames_app_menu = | 1106 std::vector<base::FilePath> shortcut_filenames_app_menu = |
| 1059 GetExistingProfileShortcutFilenames(profile_path, applications_menu); | 1107 GetExistingProfileShortcutFilenames(profile_path, applications_menu); |
| 1060 for (const auto& menu : shortcut_filenames_app_menu) { | 1108 for (const auto& menu : shortcut_filenames_app_menu) { |
| 1061 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); | 1109 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); |
| 1062 } | 1110 } |
| 1063 } | 1111 } |
| 1064 | 1112 |
| 1065 } // namespace shell_integration_linux | 1113 } // namespace shell_integration_linux |
| OLD | NEW |