OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
15 #include "base/third_party/nss/blapi.h" | 15 #include "base/third_party/nss/blapi.h" |
16 #include "base/third_party/nss/sha256.h" | 16 #include "base/third_party/nss/sha256.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
20 #include "chrome/common/extensions/extension_error_reporter.h" | 20 #include "chrome/common/extensions/extension_error_reporter.h" |
21 #include "chrome/common/extensions/extension_error_utils.h" | 21 #include "chrome/common/extensions/extension_error_utils.h" |
22 #include "chrome/common/extensions/extension_l10n_util.h" | 22 #include "chrome/common/extensions/extension_l10n_util.h" |
23 #include "chrome/common/extensions/user_script.h" | 23 #include "chrome/common/extensions/user_script.h" |
24 #include "chrome/common/notification_service.h" | 24 #include "chrome/common/notification_service.h" |
25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
26 #include "net/base/base64.h" | 26 #include "net/base/base64.h" |
| 27 #include "webkit/glue/image_decoder.h" |
27 | 28 |
28 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
29 #include "base/registry.h" | 30 #include "base/registry.h" |
30 #endif | 31 #endif |
31 | 32 |
32 namespace keys = extension_manifest_keys; | 33 namespace keys = extension_manifest_keys; |
33 namespace values = extension_manifest_values; | 34 namespace values = extension_manifest_values; |
34 namespace errors = extension_manifest_errors; | 35 namespace errors = extension_manifest_errors; |
35 | 36 |
36 namespace { | 37 namespace { |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 // If we're going from not having api permissions to having them, it's a | 635 // If we're going from not having api permissions to having them, it's a |
635 // privilege increase. | 636 // privilege increase. |
636 if (old_extension->api_permissions().size() == 0 && | 637 if (old_extension->api_permissions().size() == 0 && |
637 new_extension->api_permissions().size() > 0) | 638 new_extension->api_permissions().size() > 0) |
638 return true; | 639 return true; |
639 | 640 |
640 // Nothing much has changed. | 641 // Nothing much has changed. |
641 return false; | 642 return false; |
642 } | 643 } |
643 | 644 |
| 645 // static |
| 646 void Extension::DecodeIcon(Extension* extension, |
| 647 Icons icon_size, |
| 648 scoped_ptr<SkBitmap>* result) { |
| 649 FilePath icon_path = extension->GetIconPath(icon_size).GetFilePath(); |
| 650 DecodeIconFromPath(icon_path, icon_size, result); |
| 651 } |
| 652 |
| 653 // static |
| 654 void Extension::DecodeIconFromPath(const FilePath& icon_path, |
| 655 Icons icon_size, |
| 656 scoped_ptr<SkBitmap>* result) { |
| 657 if (icon_path.empty()) |
| 658 return; |
| 659 |
| 660 std::string file_contents; |
| 661 if (!file_util::ReadFileToString(icon_path, &file_contents)) { |
| 662 LOG(ERROR) << "Could not read icon file: " |
| 663 << WideToUTF8(icon_path.ToWStringHack()); |
| 664 return; |
| 665 } |
| 666 |
| 667 // Decode the image using WebKit's image decoder. |
| 668 const unsigned char* data = |
| 669 reinterpret_cast<const unsigned char*>(file_contents.data()); |
| 670 webkit_glue::ImageDecoder decoder; |
| 671 scoped_ptr<SkBitmap> decoded(new SkBitmap()); |
| 672 *decoded = decoder.Decode(data, file_contents.length()); |
| 673 if (decoded->empty()) { |
| 674 LOG(ERROR) << "Could not decode icon file: " |
| 675 << WideToUTF8(icon_path.ToWStringHack()); |
| 676 return; |
| 677 } |
| 678 |
| 679 if (decoded->width() != icon_size || decoded->height() != icon_size) { |
| 680 LOG(ERROR) << "Icon file has unexpected size: " |
| 681 << IntToString(decoded->width()) << "x" |
| 682 << IntToString(decoded->height()); |
| 683 return; |
| 684 } |
| 685 |
| 686 result->swap(decoded); |
| 687 } |
| 688 |
644 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, | 689 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, |
645 std::string* error) { | 690 std::string* error) { |
646 if (source.HasKey(keys::kPublicKey)) { | 691 if (source.HasKey(keys::kPublicKey)) { |
647 std::string public_key_bytes; | 692 std::string public_key_bytes; |
648 if (!source.GetString(keys::kPublicKey, &public_key_) || | 693 if (!source.GetString(keys::kPublicKey, &public_key_) || |
649 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || | 694 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || |
650 !GenerateId(public_key_bytes, &id_)) { | 695 !GenerateId(public_key_bytes, &id_)) { |
651 *error = errors::kInvalidKey; | 696 *error = errors::kInvalidKey; |
652 return false; | 697 return false; |
653 } | 698 } |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 UserScript::PatternList::const_iterator pattern = | 1300 UserScript::PatternList::const_iterator pattern = |
1256 content_script->url_patterns().begin(); | 1301 content_script->url_patterns().begin(); |
1257 for (; pattern != content_script->url_patterns().end(); ++pattern) { | 1302 for (; pattern != content_script->url_patterns().end(); ++pattern) { |
1258 if (pattern->match_subdomains() && pattern->host().empty()) | 1303 if (pattern->match_subdomains() && pattern->host().empty()) |
1259 return true; | 1304 return true; |
1260 } | 1305 } |
1261 } | 1306 } |
1262 | 1307 |
1263 return false; | 1308 return false; |
1264 } | 1309 } |
OLD | NEW |