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/common/extensions/unpacker.h" | 5 #include "chrome/common/extensions/unpacker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/json/json_file_value_serializer.h" | 13 #include "base/json/json_file_value_serializer.h" |
14 #include "base/memory/scoped_handle.h" | 14 #include "base/memory/scoped_handle.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" | 19 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "chrome/common/extensions/extension_file_util.h" | 21 #include "chrome/common/extensions/extension_file_util.h" |
22 #include "chrome/common/extensions/extension_l10n_util.h" | 22 #include "chrome/common/extensions/extension_l10n_util.h" |
23 #include "chrome/common/extensions/extension_manifest_constants.h" | 23 #include "chrome/common/extensions/extension_manifest_constants.h" |
24 #include "chrome/common/extensions/manifest.h" | 24 #include "chrome/common/extensions/manifest.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/child/image_decoder_utils.h" |
26 #include "content/public/common/common_param_traits.h" | 27 #include "content/public/common/common_param_traits.h" |
27 #include "extensions/common/constants.h" | 28 #include "extensions/common/constants.h" |
28 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
29 #include "ipc/ipc_message_utils.h" | 30 #include "ipc/ipc_message_utils.h" |
30 #include "net/base/file_stream.h" | 31 #include "net/base/file_stream.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "third_party/zlib/google/zip.h" | 33 #include "third_party/zlib/google/zip.h" |
33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
34 #include "webkit/glue/image_decoder.h" | 35 #include "ui/gfx/size.h" |
35 | 36 |
36 namespace errors = extension_manifest_errors; | 37 namespace errors = extension_manifest_errors; |
37 namespace keys = extension_manifest_keys; | 38 namespace keys = extension_manifest_keys; |
38 namespace filenames = extension_filenames; | 39 namespace filenames = extension_filenames; |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 // A limit to stop us passing dangerously large canvases to the browser. | 43 // A limit to stop us passing dangerously large canvases to the browser. |
43 const int kMaxImageCanvas = 4096 * 4096; | 44 const int kMaxImageCanvas = 4096 * 4096; |
44 | 45 |
45 SkBitmap DecodeImage(const base::FilePath& path) { | 46 SkBitmap DecodeImage(const base::FilePath& path) { |
46 // Read the file from disk. | 47 // Read the file from disk. |
47 std::string file_contents; | 48 std::string file_contents; |
48 if (!file_util::PathExists(path) || | 49 if (!file_util::PathExists(path) || |
49 !file_util::ReadFileToString(path, &file_contents)) { | 50 !file_util::ReadFileToString(path, &file_contents)) { |
50 return SkBitmap(); | 51 return SkBitmap(); |
51 } | 52 } |
52 | 53 |
53 // Decode the image using WebKit's image decoder. | 54 // Decode the image using WebKit's image decoder. |
54 const unsigned char* data = | 55 const unsigned char* data = |
55 reinterpret_cast<const unsigned char*>(file_contents.data()); | 56 reinterpret_cast<const unsigned char*>(file_contents.data()); |
56 webkit_glue::ImageDecoder decoder; | 57 SkBitmap bitmap = content::DecodeImage(data, |
57 SkBitmap bitmap = decoder.Decode(data, file_contents.length()); | 58 gfx::Size(), |
| 59 file_contents.length()); |
58 Sk64 bitmap_size = bitmap.getSize64(); | 60 Sk64 bitmap_size = bitmap.getSize64(); |
59 if (!bitmap_size.is32() || bitmap_size.get32() > kMaxImageCanvas) | 61 if (!bitmap_size.is32() || bitmap_size.get32() > kMaxImageCanvas) |
60 return SkBitmap(); | 62 return SkBitmap(); |
61 return bitmap; | 63 return bitmap; |
62 } | 64 } |
63 | 65 |
64 bool PathContainsParentDirectory(const base::FilePath& path) { | 66 bool PathContainsParentDirectory(const base::FilePath& path) { |
65 const base::FilePath::StringType kSeparators(base::FilePath::kSeparators); | 67 const base::FilePath::StringType kSeparators(base::FilePath::kSeparators); |
66 const base::FilePath::StringType kParentDirectory( | 68 const base::FilePath::StringType kParentDirectory( |
67 base::FilePath::kParentDirectory); | 69 base::FilePath::kParentDirectory); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 | 339 |
338 void Unpacker::SetError(const std::string &error) { | 340 void Unpacker::SetError(const std::string &error) { |
339 SetUTF16Error(UTF8ToUTF16(error)); | 341 SetUTF16Error(UTF8ToUTF16(error)); |
340 } | 342 } |
341 | 343 |
342 void Unpacker::SetUTF16Error(const string16 &error) { | 344 void Unpacker::SetUTF16Error(const string16 &error) { |
343 error_message_ = error; | 345 error_message_ = error; |
344 } | 346 } |
345 | 347 |
346 } // namespace extensions | 348 } // namespace extensions |
OLD | NEW |