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 <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 18 matching lines...) Expand all Loading... | |
| 29 #include "base/strings/string_tokenizer.h" | 29 #include "base/strings/string_tokenizer.h" |
| 30 #include "base/threading/thread.h" | 30 #include "base/threading/thread.h" |
| 31 #include "base/threading/thread_restrictions.h" | 31 #include "base/threading/thread_restrictions.h" |
| 32 #include "base/utf_string_conversions.h" | 32 #include "base/utf_string_conversions.h" |
| 33 #include "build/build_config.h" | 33 #include "build/build_config.h" |
| 34 #include "chrome/browser/web_applications/web_app.h" | 34 #include "chrome/browser/web_applications/web_app.h" |
| 35 #include "chrome/common/chrome_constants.h" | 35 #include "chrome/common/chrome_constants.h" |
| 36 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 37 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
| 38 #include "ui/gfx/codec/png_codec.h" | 38 #include "ui/gfx/codec/png_codec.h" |
| 39 #include "ui/gfx/image/image_skia.h" | |
| 40 #include "ui/gfx/image/image_skia_rep.h" | |
| 39 | 41 |
| 40 using content::BrowserThread; | 42 using content::BrowserThread; |
| 41 | 43 |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| 44 // Helper to launch xdg scripts. We don't want them to ask any questions on the | 46 // Helper to launch xdg scripts. We don't want them to ask any questions on the |
| 45 // terminal etc. The function returns true if the utility launches and exits | 47 // terminal etc. The function returns true if the utility launches and exits |
| 46 // cleanly, in which case |exit_code| returns the utility's exit code. | 48 // cleanly, in which case |exit_code| returns the utility's exit code. |
| 47 bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) { | 49 bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) { |
| 48 // xdg-settings internally runs xdg-mime, which uses mv to move newly-created | 50 // xdg-settings internally runs xdg-mime, which uses mv to move newly-created |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 76 if (shortcut_info.favicon.IsEmpty()) | 78 if (shortcut_info.favicon.IsEmpty()) |
| 77 return std::string(); | 79 return std::string(); |
| 78 | 80 |
| 79 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. | 81 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. |
| 80 base::ScopedTempDir temp_dir; | 82 base::ScopedTempDir temp_dir; |
| 81 if (!temp_dir.CreateUniqueTempDir()) | 83 if (!temp_dir.CreateUniqueTempDir()) |
| 82 return std::string(); | 84 return std::string(); |
| 83 | 85 |
| 84 FilePath temp_file_path = temp_dir.path().Append( | 86 FilePath temp_file_path = temp_dir.path().Append( |
| 85 shortcut_filename.ReplaceExtension("png")); | 87 shortcut_filename.ReplaceExtension("png")); |
| 88 std::string icon_name = temp_file_path.BaseName().RemoveExtension().value(); | |
| 86 | 89 |
| 87 std::vector<unsigned char> png_data; | 90 std::vector<unsigned char> png_data; |
| 88 const SkBitmap* bitmap = shortcut_info.favicon.ToSkBitmap(); | 91 std::vector<gfx::ImageSkiaRep> image_reps = |
| 89 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); | 92 shortcut_info.favicon.ToImageSkia()->image_reps(); |
| 90 int bytes_written = file_util::WriteFile(temp_file_path, | 93 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin(); |
| 91 reinterpret_cast<char*>(png_data.data()), png_data.size()); | 94 it != image_reps.end(); ++it) |
| 95 { | |
|
sky
2013/02/11 17:45:27
{ on previous line
Matt Giuca
2013/02/11 23:58:56
Done.
| |
| 96 const SkBitmap& bitmap = it->sk_bitmap(); | |
| 97 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data); | |
|
sky
2013/02/11 17:45:27
You're not checking return value here. Worse yet,
Matt Giuca
2013/02/11 23:58:56
Good catch. Fixed both.
While we're checking retu
| |
| 98 int bytes_written = file_util::WriteFile(temp_file_path, | |
| 99 reinterpret_cast<char*>(png_data.data()), png_data.size()); | |
| 92 | 100 |
| 93 if (bytes_written != static_cast<int>(png_data.size())) | 101 if (bytes_written != static_cast<int>(png_data.size())) |
| 94 return std::string(); | 102 return std::string(); |
| 95 | 103 |
| 96 std::vector<std::string> argv; | 104 std::vector<std::string> argv; |
| 97 argv.push_back("xdg-icon-resource"); | 105 argv.push_back("xdg-icon-resource"); |
| 98 argv.push_back("install"); | 106 argv.push_back("install"); |
| 99 | 107 |
| 100 // Always install in user mode, even if someone runs the browser as root | 108 // Always install in user mode, even if someone runs the browser as root |
| 101 // (people do that). | 109 // (people do that). |
| 102 argv.push_back("--mode"); | 110 argv.push_back("--mode"); |
| 103 argv.push_back("user"); | 111 argv.push_back("user"); |
| 104 | 112 |
| 105 argv.push_back("--size"); | 113 argv.push_back("--size"); |
| 106 argv.push_back(base::IntToString(bitmap->width())); | 114 argv.push_back(base::IntToString(bitmap.width())); |
| 107 | 115 |
| 108 argv.push_back(temp_file_path.value()); | 116 argv.push_back(temp_file_path.value()); |
| 109 std::string icon_name = temp_file_path.BaseName().RemoveExtension().value(); | 117 argv.push_back(icon_name); |
| 110 argv.push_back(icon_name); | 118 int exit_code; |
| 111 int exit_code; | 119 LaunchXdgUtility(argv, &exit_code); |
| 112 LaunchXdgUtility(argv, &exit_code); | 120 } |
| 113 return icon_name; | 121 return icon_name; |
| 114 } | 122 } |
| 115 | 123 |
| 116 bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, | 124 bool CreateShortcutOnDesktop(const FilePath& shortcut_filename, |
| 117 const std::string& contents) { | 125 const std::string& contents) { |
| 118 // Make sure that we will later call openat in a secure way. | 126 // Make sure that we will later call openat in a secure way. |
| 119 DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value()); | 127 DCHECK_EQ(shortcut_filename.BaseName().value(), shortcut_filename.value()); |
| 120 | 128 |
| 121 FilePath desktop_path; | 129 FilePath desktop_path; |
| 122 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) | 130 if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 | 717 |
| 710 FilePath shortcut_filename = GetExtensionShortcutFilename( | 718 FilePath shortcut_filename = GetExtensionShortcutFilename( |
| 711 profile_path, extension_id); | 719 profile_path, extension_id); |
| 712 DCHECK(!shortcut_filename.empty()); | 720 DCHECK(!shortcut_filename.empty()); |
| 713 | 721 |
| 714 DeleteShortcutOnDesktop(shortcut_filename); | 722 DeleteShortcutOnDesktop(shortcut_filename); |
| 715 DeleteShortcutInApplicationsMenu(shortcut_filename); | 723 DeleteShortcutInApplicationsMenu(shortcut_filename); |
| 716 } | 724 } |
| 717 | 725 |
| 718 } // namespace ShellIntegrationLinux | 726 } // namespace ShellIntegrationLinux |
| OLD | NEW |