Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: chrome/browser/shell_integration_linux.cc

Issue 12881003: ShortcutInfo::favicon is now a gfx::ImageFamily instead of gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added test suite for icon_family. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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" 39 #include "ui/gfx/icon_family.h"
40 #include "ui/gfx/image/image_skia_rep.h"
41 40
42 using content::BrowserThread; 41 using content::BrowserThread;
43 42
44 namespace { 43 namespace {
45 44
46 // Helper to launch xdg scripts. We don't want them to ask any questions on the 45 // Helper to launch xdg scripts. We don't want them to ask any questions on the
47 // terminal etc. The function returns true if the utility launches and exits 46 // terminal etc. The function returns true if the utility launches and exits
48 // cleanly, in which case |exit_code| returns the utility's exit code. 47 // cleanly, in which case |exit_code| returns the utility's exit code.
49 bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) { 48 bool LaunchXdgUtility(const std::vector<std::string>& argv, int* exit_code) {
50 // xdg-settings internally runs xdg-mime, which uses mv to move newly-created 49 // xdg-settings internally runs xdg-mime, which uses mv to move newly-created
(...skipping 17 matching lines...) Expand all
68 return false; 67 return false;
69 } 68 }
70 close(devnull); 69 close(devnull);
71 70
72 return base::WaitForExitCode(handle, exit_code); 71 return base::WaitForExitCode(handle, exit_code);
73 } 72 }
74 73
75 std::string CreateShortcutIcon( 74 std::string CreateShortcutIcon(
76 const ShellIntegration::ShortcutInfo& shortcut_info, 75 const ShellIntegration::ShortcutInfo& shortcut_info,
77 const base::FilePath& shortcut_filename) { 76 const base::FilePath& shortcut_filename) {
78 if (shortcut_info.favicon.IsEmpty()) 77 if (shortcut_info.favicon.empty())
79 return std::string(); 78 return std::string();
80 79
81 // TODO(phajdan.jr): Report errors from this function, possibly as infobars. 80 // TODO(phajdan.jr): Report errors from this function, possibly as infobars.
82 base::ScopedTempDir temp_dir; 81 base::ScopedTempDir temp_dir;
83 if (!temp_dir.CreateUniqueTempDir()) 82 if (!temp_dir.CreateUniqueTempDir())
84 return std::string(); 83 return std::string();
85 84
86 base::FilePath temp_file_path = temp_dir.path().Append( 85 base::FilePath temp_file_path = temp_dir.path().Append(
87 shortcut_filename.ReplaceExtension("png")); 86 shortcut_filename.ReplaceExtension("png"));
88 std::string icon_name = temp_file_path.BaseName().RemoveExtension().value(); 87 std::string icon_name = temp_file_path.BaseName().RemoveExtension().value();
89 88
90 std::vector<gfx::ImageSkiaRep> image_reps = 89 for (gfx::IconFamily::const_iterator it = shortcut_info.favicon.begin();
91 shortcut_info.favicon.ToImageSkia()->image_reps(); 90 it != shortcut_info.favicon.end(); ++it) {
92 for (std::vector<gfx::ImageSkiaRep>::const_iterator it = image_reps.begin();
93 it != image_reps.end(); ++it) {
94 std::vector<unsigned char> png_data; 91 std::vector<unsigned char> png_data;
95 const SkBitmap& bitmap = it->sk_bitmap(); 92 const SkBitmap& bitmap = *it->bitmap();
96 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data)) { 93 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data)) {
97 // If the bitmap could not be encoded to PNG format, skip it. 94 // If the bitmap could not be encoded to PNG format, skip it.
98 LOG(WARNING) << "Could not encode icon " << icon_name << ".png at size " 95 LOG(WARNING) << "Could not encode icon " << icon_name << ".png at size "
99 << bitmap.width() << "."; 96 << bitmap.width() << ".";
100 continue; 97 continue;
101 } 98 }
102 int bytes_written = file_util::WriteFile(temp_file_path, 99 int bytes_written = file_util::WriteFile(temp_file_path,
103 reinterpret_cast<char*>(png_data.data()), png_data.size()); 100 reinterpret_cast<char*>(png_data.data()), png_data.size());
104 101
105 if (bytes_written != static_cast<int>(png_data.size())) 102 if (bytes_written != static_cast<int>(png_data.size()))
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 836
840 base::FilePath shortcut_filename = GetExtensionShortcutFilename( 837 base::FilePath shortcut_filename = GetExtensionShortcutFilename(
841 profile_path, extension_id); 838 profile_path, extension_id);
842 DCHECK(!shortcut_filename.empty()); 839 DCHECK(!shortcut_filename.empty());
843 840
844 DeleteShortcutOnDesktop(shortcut_filename); 841 DeleteShortcutOnDesktop(shortcut_filename);
845 DeleteShortcutInApplicationsMenu(shortcut_filename); 842 DeleteShortcutInApplicationsMenu(shortcut_filename);
846 } 843 }
847 844
848 } // namespace ShellIntegrationLinux 845 } // namespace ShellIntegrationLinux
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698