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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 if (ran_ok && exit_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { | 157 if (ran_ok && exit_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { |
158 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { | 158 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { |
159 ran_ok = LaunchXdgUtility(argv, &exit_code); | 159 ran_ok = LaunchXdgUtility(argv, &exit_code); |
160 } | 160 } |
161 } | 161 } |
162 | 162 |
163 return ran_ok && exit_code == EXIT_SUCCESS; | 163 return ran_ok && exit_code == EXIT_SUCCESS; |
164 #endif | 164 #endif |
165 } | 165 } |
166 | 166 |
167 // If |protocol| is empty this function checks if Chrome is the default browser, | 167 #if !defined(OS_CHROMEOS) |
168 // otherwise it checks if Chrome is the default handler application for | 168 // If |check| is true, returns the output of "xdg-settings check {property} |
169 // |protocol|. | 169 // *.desktop", otherwise returns the output of "xdg-settings get {property}", |
170 DefaultWebClientState GetIsDefaultWebClient(const std::string& protocol) { | 170 // where property is "default-web-browser" if |protocol| is empty or |
171 #if defined(OS_CHROMEOS) | 171 // "default-url-scheme-handler |protocol|" otherwise. Returns "" if |
172 return UNKNOWN_DEFAULT; | 172 // xdg-settings fails for any reason. |
173 #else | 173 std::string GetXdgSettingsOutput(bool check, |
174 base::ThreadRestrictions::AssertIOAllowed(); | 174 const std::string& protocol, |
175 | 175 base::Environment* env) { |
176 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
177 | |
178 std::vector<std::string> argv; | 176 std::vector<std::string> argv; |
179 argv.push_back(kXdgSettings); | 177 argv.push_back(kXdgSettings); |
180 argv.push_back("check"); | 178 argv.push_back(check ? "check" : "get"); |
181 if (protocol.empty()) { | 179 if (protocol.empty()) { |
182 argv.push_back(kXdgSettingsDefaultBrowser); | 180 argv.push_back(kXdgSettingsDefaultBrowser); |
183 } else { | 181 } else { |
184 argv.push_back(kXdgSettingsDefaultSchemeHandler); | 182 argv.push_back(kXdgSettingsDefaultSchemeHandler); |
185 argv.push_back(protocol); | 183 argv.push_back(protocol); |
186 } | 184 } |
187 argv.push_back(shell_integration_linux::GetDesktopName(env.get())); | 185 if (check) |
186 argv.push_back(shell_integration_linux::GetDesktopName(env)); | |
188 | 187 |
189 std::string reply; | 188 std::string reply; |
190 int success_code; | 189 int success_code; |
191 bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply, | 190 bool ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply, |
192 &success_code); | 191 &success_code); |
193 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { | 192 if (ran_ok && success_code == EXIT_XDG_SETTINGS_SYNTAX_ERROR) { |
194 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { | 193 if (GetChromeVersionOfScript(kXdgSettings, &argv[0])) { |
195 ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply, | 194 ran_ok = base::GetAppOutputWithExitCode(base::CommandLine(argv), &reply, |
196 &success_code); | 195 &success_code); |
197 } | 196 } |
198 } | 197 } |
199 | 198 |
200 if (!ran_ok || success_code != EXIT_SUCCESS) { | 199 if (!ran_ok || success_code != EXIT_SUCCESS) { |
201 // xdg-settings failed: we can't determine or set the default browser. | 200 // xdg-settings failed: we can't determine or set the default browser. |
Lei Zhang
2017/03/10 02:04:45
Move this comment down to line 239?
Tom (Use chromium acct)
2017/03/10 02:25:45
Done.
| |
202 return UNKNOWN_DEFAULT; | 201 return std::string(); |
203 } | 202 } |
204 | 203 |
205 // Allow any reply that starts with "yes". | 204 return reply; |
206 return base::StartsWith(reply, "yes", base::CompareCase::SENSITIVE) | 205 } |
207 ? IS_DEFAULT | 206 #endif |
208 : NOT_DEFAULT; | 207 |
208 // If |protocol| is empty this function checks if Chrome is the default browser, | |
209 // otherwise it checks if Chrome is the default handler application for | |
210 // |protocol|. | |
211 DefaultWebClientState GetIsDefaultWebClient(const std::string& protocol) { | |
Lei Zhang
2017/03/10 02:04:45
Can we remove this to just GetDefaultWebClient() w
Tom (Use chromium acct)
2017/03/10 02:25:45
Done.
| |
212 #if defined(OS_CHROMEOS) | |
213 return UNKNOWN_DEFAULT; | |
214 #else | |
215 base::ThreadRestrictions::AssertIOAllowed(); | |
216 | |
217 std::unique_ptr<base::Environment> env(base::Environment::Create()); | |
218 std::string xdg_is_default = GetXdgSettingsOutput(true, protocol, env.get()); | |
219 if (base::StartsWith(xdg_is_default, "yes", base::CompareCase::SENSITIVE)) { | |
220 return IS_DEFAULT; | |
221 } else if (base::StartsWith(xdg_is_default, "no", | |
Lei Zhang
2017/03/10 02:04:45
No need for else-if after a return.
Tom (Use chromium acct)
2017/03/10 02:25:45
So you mean to change it to just 'if'?
Done.
| |
222 base::CompareCase::SENSITIVE)) { | |
223 // An output of "no" does not necessarily mean Chrom[e,ium] is not the | |
224 // default. According to the xdg-settings man page, this can happen when | |
225 // "only some of the underlying settings actually reflect that value". Don't | |
226 // return NOT_DEFAULT unless we're sure, or else an annoying "Chrome is not | |
227 // your default browser" banner will appear on every launch | |
228 // (crbug.com/578888). | |
Lei Zhang
2017/03/10 02:04:45
Add https:// so code search can auto-linkify.
Tom (Use chromium acct)
2017/03/10 02:25:45
Done.
| |
229 if (base::StartsWith(GetXdgSettingsOutput(false, protocol, env.get()), | |
230 shell_integration_linux::GetDesktopName(env.get()), | |
231 base::CompareCase::SENSITIVE)) { | |
232 // This is the odd case where 'xdg-settings check' said that Chrome wasn't | |
233 // the default, but 'xdg-settings get' returned Chrome as the default. | |
234 return UNKNOWN_DEFAULT; | |
235 } | |
236 // xdg-settings says the default is non-Chrome, and is self-consistent. | |
237 return NOT_DEFAULT; | |
238 } | |
239 | |
240 return UNKNOWN_DEFAULT; | |
209 #endif | 241 #endif |
210 } | 242 } |
211 | 243 |
212 // https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased | 244 // https://wiki.gnome.org/Projects/GnomeShell/ApplicationBased |
213 // The WM_CLASS property should be set to the same as the *.desktop file without | 245 // The WM_CLASS property should be set to the same as the *.desktop file without |
214 // the .desktop extension. We cannot simply use argv[0] in this case, because | 246 // the .desktop extension. We cannot simply use argv[0] in this case, because |
215 // on the stable channel, the executable name is google-chrome-stable, but the | 247 // on the stable channel, the executable name is google-chrome-stable, but the |
216 // desktop file is google-chrome.desktop. | 248 // desktop file is google-chrome.desktop. |
217 std::string GetDesktopBaseName(const std::string& desktop_file_name) { | 249 std::string GetDesktopBaseName(const std::string& desktop_file_name) { |
218 static const char kDesktopExtension[] = ".desktop"; | 250 static const char kDesktopExtension[] = ".desktop"; |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1107 base::FilePath applications_menu = GetDataWriteLocation(env.get()); | 1139 base::FilePath applications_menu = GetDataWriteLocation(env.get()); |
1108 applications_menu = applications_menu.AppendASCII("applications"); | 1140 applications_menu = applications_menu.AppendASCII("applications"); |
1109 std::vector<base::FilePath> shortcut_filenames_app_menu = | 1141 std::vector<base::FilePath> shortcut_filenames_app_menu = |
1110 GetExistingProfileShortcutFilenames(profile_path, applications_menu); | 1142 GetExistingProfileShortcutFilenames(profile_path, applications_menu); |
1111 for (const auto& menu : shortcut_filenames_app_menu) { | 1143 for (const auto& menu : shortcut_filenames_app_menu) { |
1112 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); | 1144 DeleteShortcutInApplicationsMenu(menu, base::FilePath(kDirectoryFilename)); |
1113 } | 1145 } |
1114 } | 1146 } |
1115 | 1147 |
1116 } // namespace shell_integration_linux | 1148 } // namespace shell_integration_linux |
OLD | NEW |