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 <glib.h> | 8 #include <glib.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "base/path_service.h" | 25 #include "base/path_service.h" |
26 #include "base/process_util.h" | 26 #include "base/process_util.h" |
27 #include "base/scoped_temp_dir.h" | 27 #include "base/scoped_temp_dir.h" |
28 #include "base/string_number_conversions.h" | 28 #include "base/string_number_conversions.h" |
29 #include "base/string_tokenizer.h" | 29 #include "base/string_tokenizer.h" |
30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
31 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
32 #include "build/build_config.h" | 32 #include "build/build_config.h" |
33 #include "chrome/browser/web_applications/web_app.h" | 33 #include "chrome/browser/web_applications/web_app.h" |
34 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| 35 #include "chrome/common/chrome_paths.h" |
35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
36 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
37 #include "ui/gfx/codec/png_codec.h" | 38 #include "ui/gfx/codec/png_codec.h" |
38 | 39 |
39 using content::BrowserThread; | 40 using content::BrowserThread; |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Helper to launch xdg scripts. We don't want them to ask any questions on the | 44 // Helper to launch xdg scripts. We don't want them to ask any questions on the |
44 // terminal etc. The function returns true if the utility launches and exits | 45 // terminal etc. The function returns true if the utility launches and exits |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 LaunchXdgUtility(argv, &exit_code); | 112 LaunchXdgUtility(argv, &exit_code); |
112 return icon_name; | 113 return icon_name; |
113 } | 114 } |
114 | 115 |
115 bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, | 116 bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, |
116 const std::string& contents) { | 117 const std::string& contents) { |
117 // Make sure that we will later call openat in a secure way. | 118 // Make sure that we will later call openat in a secure way. |
118 DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value()); | 119 DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value()); |
119 | 120 |
120 FilePath desktop_path; | 121 FilePath desktop_path; |
121 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) | 122 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) |
122 return false; | 123 return false; |
123 | 124 |
124 int desktop_fd = open(desktop_path.value().c_str(), O_RDONLY | O_DIRECTORY); | 125 int desktop_fd = open(desktop_path.value().c_str(), O_RDONLY | O_DIRECTORY); |
125 if (desktop_fd < 0) | 126 if (desktop_fd < 0) |
126 return false; | 127 return false; |
127 | 128 |
128 int fd = openat(desktop_fd, shortcut_filename.value().c_str(), | 129 int fd = openat(desktop_fd, shortcut_filename.value().c_str(), |
129 O_CREAT | O_EXCL | O_WRONLY, | 130 O_CREAT | O_EXCL | O_WRONLY, |
130 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); | 131 S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); |
131 if (fd < 0) { | 132 if (fd < 0) { |
(...skipping 16 matching lines...) Expand all Loading... |
148 } | 149 } |
149 | 150 |
150 if (HANDLE_EINTR(close(desktop_fd)) < 0) | 151 if (HANDLE_EINTR(close(desktop_fd)) < 0) |
151 PLOG(ERROR) << "close"; | 152 PLOG(ERROR) << "close"; |
152 | 153 |
153 return true; | 154 return true; |
154 } | 155 } |
155 | 156 |
156 void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) { | 157 void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) { |
157 FilePath desktop_path; | 158 FilePath desktop_path; |
158 if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) | 159 if (PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) |
159 file_util::Delete(desktop_path.Append(shortcut_filename), false); | 160 file_util::Delete(desktop_path.Append(shortcut_filename), false); |
160 } | 161 } |
161 | 162 |
162 bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename, | 163 bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename, |
163 const std::string& contents) { | 164 const std::string& contents) { |
164 ScopedTempDir temp_dir; | 165 ScopedTempDir temp_dir; |
165 if (!temp_dir.CreateUniqueTempDir()) | 166 if (!temp_dir.CreateUniqueTempDir()) |
166 return false; | 167 return false; |
167 | 168 |
168 FilePath temp_file_path = temp_dir.path().Append(shortcut_filename); | 169 FilePath temp_file_path = temp_dir.path().Append(shortcut_filename); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 return false; | 477 return false; |
477 } | 478 } |
478 | 479 |
479 FilePath GetWebShortcutFilename(const GURL& url) { | 480 FilePath GetWebShortcutFilename(const GURL& url) { |
480 // Use a prefix, because xdg-desktop-menu requires it. | 481 // Use a prefix, because xdg-desktop-menu requires it. |
481 std::string filename = | 482 std::string filename = |
482 std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec(); | 483 std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec(); |
483 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); | 484 file_util::ReplaceIllegalCharactersInPath(&filename, '_'); |
484 | 485 |
485 FilePath desktop_path; | 486 FilePath desktop_path; |
486 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) | 487 if (!PathService::Get(chrome::DIR_USER_DESKTOP, &desktop_path)) |
487 return FilePath(); | 488 return FilePath(); |
488 | 489 |
489 FilePath filepath = desktop_path.Append(filename); | 490 FilePath filepath = desktop_path.Append(filename); |
490 FilePath alternative_filepath(filepath.value() + ".desktop"); | 491 FilePath alternative_filepath(filepath.value() + ".desktop"); |
491 for (size_t i = 1; i < 100; ++i) { | 492 for (size_t i = 1; i < 100; ++i) { |
492 if (file_util::PathExists(FilePath(alternative_filepath))) { | 493 if (file_util::PathExists(FilePath(alternative_filepath))) { |
493 alternative_filepath = FilePath( | 494 alternative_filepath = FilePath( |
494 filepath.value() + "_" + base::IntToString(i) + ".desktop"); | 495 filepath.value() + "_" + base::IntToString(i) + ".desktop"); |
495 } else { | 496 } else { |
496 return FilePath(alternative_filepath).BaseName(); | 497 return FilePath(alternative_filepath).BaseName(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 | 680 |
680 FilePath shortcut_filename = GetExtensionShortcutFilename( | 681 FilePath shortcut_filename = GetExtensionShortcutFilename( |
681 profile_path, extension_id); | 682 profile_path, extension_id); |
682 DCHECK(!shortcut_filename.empty()); | 683 DCHECK(!shortcut_filename.empty()); |
683 | 684 |
684 DeleteShortcutOnDesktop(shortcut_filename); | 685 DeleteShortcutOnDesktop(shortcut_filename); |
685 DeleteShortcutInApplicationsMenu(shortcut_filename); | 686 DeleteShortcutInApplicationsMenu(shortcut_filename); |
686 } | 687 } |
687 | 688 |
688 } // namespace ShellIntegrationLinux | 689 } // namespace ShellIntegrationLinux |
OLD | NEW |