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

Side by Side Diff: chrome/common/extensions/extension.cc

Issue 501130: Revert 34858 - Merge 34812 Add the rightclick context menu for Browser actio... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/src/
Patch Set: Created 11 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
28 27
29 #if defined(OS_WIN) 28 #if defined(OS_WIN)
30 #include "base/registry.h" 29 #include "base/registry.h"
31 #endif 30 #endif
32 31
33 namespace keys = extension_manifest_keys; 32 namespace keys = extension_manifest_keys;
34 namespace values = extension_manifest_values; 33 namespace values = extension_manifest_values;
35 namespace errors = extension_manifest_errors; 34 namespace errors = extension_manifest_errors;
36 35
37 namespace { 36 namespace {
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // If we're going from not having api permissions to having them, it's a 634 // If we're going from not having api permissions to having them, it's a
636 // privilege increase. 635 // privilege increase.
637 if (old_extension->api_permissions().size() == 0 && 636 if (old_extension->api_permissions().size() == 0 &&
638 new_extension->api_permissions().size() > 0) 637 new_extension->api_permissions().size() > 0)
639 return true; 638 return true;
640 639
641 // Nothing much has changed. 640 // Nothing much has changed.
642 return false; 641 return false;
643 } 642 }
644 643
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
689 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id, 644 bool Extension::InitFromValue(const DictionaryValue& source, bool require_id,
690 std::string* error) { 645 std::string* error) {
691 if (source.HasKey(keys::kPublicKey)) { 646 if (source.HasKey(keys::kPublicKey)) {
692 std::string public_key_bytes; 647 std::string public_key_bytes;
693 if (!source.GetString(keys::kPublicKey, &public_key_) || 648 if (!source.GetString(keys::kPublicKey, &public_key_) ||
694 !ParsePEMKeyBytes(public_key_, &public_key_bytes) || 649 !ParsePEMKeyBytes(public_key_, &public_key_bytes) ||
695 !GenerateId(public_key_bytes, &id_)) { 650 !GenerateId(public_key_bytes, &id_)) {
696 *error = errors::kInvalidKey; 651 *error = errors::kInvalidKey;
697 return false; 652 return false;
698 } 653 }
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 UserScript::PatternList::const_iterator pattern = 1255 UserScript::PatternList::const_iterator pattern =
1301 content_script->url_patterns().begin(); 1256 content_script->url_patterns().begin();
1302 for (; pattern != content_script->url_patterns().end(); ++pattern) { 1257 for (; pattern != content_script->url_patterns().end(); ++pattern) {
1303 if (pattern->match_subdomains() && pattern->host().empty()) 1258 if (pattern->match_subdomains() && pattern->host().empty())
1304 return true; 1259 return true;
1305 } 1260 }
1306 } 1261 }
1307 1262
1308 return false; 1263 return false;
1309 } 1264 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698