| 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> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/base_paths.h" | 17 #include "base/base_paths.h" |
| 18 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 19 #include "base/environment.h" | 19 #include "base/environment.h" |
| 20 #include "base/file_path.h" | 20 #include "base/file_path.h" |
| 21 #include "base/file_util.h" | 21 #include "base/file_util.h" |
| 22 #include "base/files/scoped_temp_dir.h" |
| 22 #include "base/i18n/file_util_icu.h" | 23 #include "base/i18n/file_util_icu.h" |
| 23 #include "base/message_loop.h" | 24 #include "base/message_loop.h" |
| 24 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 25 #include "base/posix/eintr_wrapper.h" | 26 #include "base/posix/eintr_wrapper.h" |
| 26 #include "base/process_util.h" | 27 #include "base/process_util.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 "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 36 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
| 37 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return base::WaitForExitCode(handle, exit_code); | 69 return base::WaitForExitCode(handle, exit_code); |
| 70 } | 70 } |
| 71 | 71 |
| 72 std::string CreateShortcutIcon( | 72 std::string CreateShortcutIcon( |
| 73 const ShellIntegration::ShortcutInfo& shortcut_info, | 73 const ShellIntegration::ShortcutInfo& shortcut_info, |
| 74 const FilePath& shortcut_filename) { | 74 const FilePath& shortcut_filename) { |
| 75 if (shortcut_info.favicon.IsEmpty()) | 75 if (shortcut_info.favicon.IsEmpty()) |
| 76 return std::string(); | 76 return std::string(); |
| 77 | 77 |
| 78 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. | 78 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. |
| 79 ScopedTempDir temp_dir; | 79 base::ScopedTempDir temp_dir; |
| 80 if (!temp_dir.CreateUniqueTempDir()) | 80 if (!temp_dir.CreateUniqueTempDir()) |
| 81 return std::string(); | 81 return std::string(); |
| 82 | 82 |
| 83 FilePath temp_file_path = temp_dir.path().Append( | 83 FilePath temp_file_path = temp_dir.path().Append( |
| 84 shortcut_filename.ReplaceExtension("png")); | 84 shortcut_filename.ReplaceExtension("png")); |
| 85 | 85 |
| 86 std::vector<unsigned char> png_data; | 86 std::vector<unsigned char> png_data; |
| 87 const SkBitmap* bitmap = shortcut_info.favicon.ToSkBitmap(); | 87 const SkBitmap* bitmap = shortcut_info.favicon.ToSkBitmap(); |
| 88 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); | 88 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); |
| 89 int bytes_written = file_util::WriteFile(temp_file_path, | 89 int bytes_written = file_util::WriteFile(temp_file_path, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 154 } |
| 155 | 155 |
| 156 void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) { | 156 void DeleteShortcutOnDesktop(const FilePath& shortcut_filename) { |
| 157 FilePath desktop_path; | 157 FilePath desktop_path; |
| 158 if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) | 158 if (PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) |
| 159 file_util::Delete(desktop_path.Append(shortcut_filename), false); | 159 file_util::Delete(desktop_path.Append(shortcut_filename), false); |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename, | 162 bool CreateShortcutInApplicationsMenu(const FilePath& shortcut_filename, |
| 163 const std::string& contents) { | 163 const std::string& contents) { |
| 164 ScopedTempDir temp_dir; | 164 base::ScopedTempDir temp_dir; |
| 165 if (!temp_dir.CreateUniqueTempDir()) | 165 if (!temp_dir.CreateUniqueTempDir()) |
| 166 return false; | 166 return false; |
| 167 | 167 |
| 168 FilePath temp_file_path = temp_dir.path().Append(shortcut_filename); | 168 FilePath temp_file_path = temp_dir.path().Append(shortcut_filename); |
| 169 | 169 |
| 170 int bytes_written = file_util::WriteFile(temp_file_path, contents.data(), | 170 int bytes_written = file_util::WriteFile(temp_file_path, contents.data(), |
| 171 contents.length()); | 171 contents.length()); |
| 172 | 172 |
| 173 if (bytes_written != static_cast<int>(contents.length())) | 173 if (bytes_written != static_cast<int>(contents.length())) |
| 174 return false; | 174 return false; |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 | 679 |
| 680 FilePath shortcut_filename = GetExtensionShortcutFilename( | 680 FilePath shortcut_filename = GetExtensionShortcutFilename( |
| 681 profile_path, extension_id); | 681 profile_path, extension_id); |
| 682 DCHECK(!shortcut_filename.empty()); | 682 DCHECK(!shortcut_filename.empty()); |
| 683 | 683 |
| 684 DeleteShortcutOnDesktop(shortcut_filename); | 684 DeleteShortcutOnDesktop(shortcut_filename); |
| 685 DeleteShortcutInApplicationsMenu(shortcut_filename); | 685 DeleteShortcutInApplicationsMenu(shortcut_filename); |
| 686 } | 686 } |
| 687 | 687 |
| 688 } // namespace ShellIntegrationLinux | 688 } // namespace ShellIntegrationLinux |
| OLD | NEW |