OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/importer/importer.h" | 5 #include "chrome/browser/importer/importer.h" |
6 | 6 |
7 #include "chrome/browser/importer/importer_bridge.h" | 7 #include "chrome/browser/importer/importer_bridge.h" |
8 #include "chrome/browser/importer/importer_data_types.h" | 8 #include "chrome/browser/importer/importer_data_types.h" |
9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
11 #include "ui/gfx/codec/png_codec.h" | 11 #include "ui/gfx/codec/png_codec.h" |
12 #include "ui/gfx/favicon_size.h" | 12 #include "ui/gfx/favicon_size.h" |
13 #include "webkit/glue/image_decoder.h" | 13 #include "webkit/glue/image_decoder.h" |
14 | 14 |
15 void Importer::Cancel() { | 15 void Importer::Cancel() { |
16 cancelled_ = true; | 16 cancelled_ = true; |
17 } | 17 } |
18 | 18 |
19 Importer::Importer() | 19 Importer::Importer() : cancelled_(false) { |
20 : import_to_bookmark_bar_(false), | |
21 bookmark_bar_disabled_(false), | |
22 cancelled_(false) { | |
23 } | 20 } |
24 | 21 |
25 Importer::~Importer() { | 22 Importer::~Importer() { |
26 } | 23 } |
27 | 24 |
28 // static | 25 // static |
29 bool Importer::ReencodeFavicon(const unsigned char* src_data, | 26 bool Importer::ReencodeFavicon(const unsigned char* src_data, |
30 size_t src_len, | 27 size_t src_len, |
31 std::vector<unsigned char>* png_data) { | 28 std::vector<unsigned char>* png_data) { |
32 // Decode the favicon using WebKit's image decoder. | 29 // Decode the favicon using WebKit's image decoder. |
33 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); | 30 webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); |
34 SkBitmap decoded = decoder.Decode(src_data, src_len); | 31 SkBitmap decoded = decoder.Decode(src_data, src_len); |
35 if (decoded.empty()) | 32 if (decoded.empty()) |
36 return false; // Unable to decode. | 33 return false; // Unable to decode. |
37 | 34 |
38 if (decoded.width() != kFaviconSize || decoded.height() != kFaviconSize) { | 35 if (decoded.width() != kFaviconSize || decoded.height() != kFaviconSize) { |
39 // The bitmap is not the correct size, re-sample. | 36 // The bitmap is not the correct size, re-sample. |
40 int new_width = decoded.width(); | 37 int new_width = decoded.width(); |
41 int new_height = decoded.height(); | 38 int new_height = decoded.height(); |
42 calc_favicon_target_size(&new_width, &new_height); | 39 calc_favicon_target_size(&new_width, &new_height); |
43 decoded = skia::ImageOperations::Resize( | 40 decoded = skia::ImageOperations::Resize( |
44 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); | 41 decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); |
45 } | 42 } |
46 | 43 |
47 // Encode our bitmap as a PNG. | 44 // Encode our bitmap as a PNG. |
48 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); | 45 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); |
49 return true; | 46 return true; |
50 } | 47 } |
OLD | NEW |