| 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.h" | 5 #include "chrome/browser/shell_integration.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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 close(devnull); | 68 close(devnull); |
| 69 | 69 |
| 70 return base::WaitForExitCode(handle, exit_code); | 70 return base::WaitForExitCode(handle, exit_code); |
| 71 } | 71 } |
| 72 | 72 |
| 73 std::string CreateShortcutIcon( | 73 std::string CreateShortcutIcon( |
| 74 const ShellIntegration::ShortcutInfo& shortcut_info, | 74 const ShellIntegration::ShortcutInfo& shortcut_info, |
| 75 const FilePath& shortcut_filename) { | 75 const FilePath& shortcut_filename) { |
| 76 if (shortcut_info.favicon.isNull()) | 76 if (shortcut_info.favicon.IsEmpty()) |
| 77 return std::string(); | 77 return std::string(); |
| 78 | 78 |
| 79 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. | 79 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. |
| 80 ScopedTempDir temp_dir; | 80 ScopedTempDir temp_dir; |
| 81 if (!temp_dir.CreateUniqueTempDir()) | 81 if (!temp_dir.CreateUniqueTempDir()) |
| 82 return std::string(); | 82 return std::string(); |
| 83 | 83 |
| 84 FilePath temp_file_path = temp_dir.path().Append( | 84 FilePath temp_file_path = temp_dir.path().Append( |
| 85 shortcut_filename.ReplaceExtension("png")); | 85 shortcut_filename.ReplaceExtension("png")); |
| 86 | 86 |
| 87 std::vector<unsigned char> png_data; | 87 std::vector<unsigned char> png_data; |
| 88 gfx::PNGCodec::EncodeBGRASkBitmap(shortcut_info.favicon, false, &png_data); | 88 const SkBitmap* bitmap = shortcut_info.favicon.ToSkBitmap(); |
| 89 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); |
| 89 int bytes_written = file_util::WriteFile(temp_file_path, | 90 int bytes_written = file_util::WriteFile(temp_file_path, |
| 90 reinterpret_cast<char*>(png_data.data()), png_data.size()); | 91 reinterpret_cast<char*>(png_data.data()), png_data.size()); |
| 91 | 92 |
| 92 if (bytes_written != static_cast<int>(png_data.size())) | 93 if (bytes_written != static_cast<int>(png_data.size())) |
| 93 return std::string(); | 94 return std::string(); |
| 94 | 95 |
| 95 std::vector<std::string> argv; | 96 std::vector<std::string> argv; |
| 96 argv.push_back("xdg-icon-resource"); | 97 argv.push_back("xdg-icon-resource"); |
| 97 argv.push_back("install"); | 98 argv.push_back("install"); |
| 98 | 99 |
| 99 // Always install in user mode, even if someone runs the browser as root | 100 // Always install in user mode, even if someone runs the browser as root |
| 100 // (people do that). | 101 // (people do that). |
| 101 argv.push_back("--mode"); | 102 argv.push_back("--mode"); |
| 102 argv.push_back("user"); | 103 argv.push_back("user"); |
| 103 | 104 |
| 104 argv.push_back("--size"); | 105 argv.push_back("--size"); |
| 105 argv.push_back(base::IntToString(shortcut_info.favicon.width())); | 106 argv.push_back(base::IntToString(bitmap->width())); |
| 106 | 107 |
| 107 argv.push_back(temp_file_path.value()); | 108 argv.push_back(temp_file_path.value()); |
| 108 std::string icon_name = temp_file_path.BaseName().RemoveExtension().value(); | 109 std::string icon_name = temp_file_path.BaseName().RemoveExtension().value(); |
| 109 argv.push_back(icon_name); | 110 argv.push_back(icon_name); |
| 110 int exit_code; | 111 int exit_code; |
| 111 LaunchXdgUtility(argv, &exit_code); | 112 LaunchXdgUtility(argv, &exit_code); |
| 112 return icon_name; | 113 return icon_name; |
| 113 } | 114 } |
| 114 | 115 |
| 115 void CreateShortcutOnDesktop(const FilePath& shortcut_filename, | 116 void CreateShortcutOnDesktop(const FilePath& shortcut_filename, |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 shortcut_info.extension_id, | 603 shortcut_info.extension_id, |
| 603 shortcut_info.title, | 604 shortcut_info.title, |
| 604 icon_name); | 605 icon_name); |
| 605 | 606 |
| 606 if (shortcut_info.create_on_desktop) | 607 if (shortcut_info.create_on_desktop) |
| 607 CreateShortcutOnDesktop(shortcut_filename, contents); | 608 CreateShortcutOnDesktop(shortcut_filename, contents); |
| 608 | 609 |
| 609 if (shortcut_info.create_in_applications_menu) | 610 if (shortcut_info.create_in_applications_menu) |
| 610 CreateShortcutInApplicationsMenu(shortcut_filename, contents); | 611 CreateShortcutInApplicationsMenu(shortcut_filename, contents); |
| 611 } | 612 } |
| OLD | NEW |