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/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/string16.h" | 18 #include "base/string16.h" |
19 #include "base/string_number_conversions.h" | 19 #include "base/string_number_conversions.h" |
20 #include "base/string_piece.h" | 20 #include "base/string_piece.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "base/version.h" | 25 #include "base/version.h" |
26 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/chrome_version_info.h" | 28 #include "chrome/common/chrome_version_info.h" |
29 #include "chrome/common/extensions/csp_validator.h" | 29 #include "chrome/common/extensions/csp_validator.h" |
30 #include "chrome/common/extensions/extension_error_utils.h" | |
31 #include "chrome/common/extensions/extension_manifest_constants.h" | 30 #include "chrome/common/extensions/extension_manifest_constants.h" |
32 #include "chrome/common/extensions/extension_resource.h" | 31 #include "chrome/common/extensions/extension_resource.h" |
33 #include "chrome/common/extensions/feature_switch.h" | 32 #include "chrome/common/extensions/feature_switch.h" |
34 #include "chrome/common/extensions/features/feature.h" | 33 #include "chrome/common/extensions/features/feature.h" |
35 #include "chrome/common/extensions/features/simple_feature_provider.h" | 34 #include "chrome/common/extensions/features/simple_feature_provider.h" |
36 #include "chrome/common/extensions/file_browser_handler.h" | 35 #include "chrome/common/extensions/file_browser_handler.h" |
37 #include "chrome/common/extensions/manifest.h" | 36 #include "chrome/common/extensions/manifest.h" |
38 #include "chrome/common/extensions/permissions/permission_set.h" | 37 #include "chrome/common/extensions/permissions/permission_set.h" |
39 #include "chrome/common/extensions/permissions/permissions_info.h" | 38 #include "chrome/common/extensions/permissions/permissions_info.h" |
40 #include "chrome/common/extensions/url_pattern_set.h" | |
41 #include "chrome/common/extensions/user_script.h" | 39 #include "chrome/common/extensions/user_script.h" |
42 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
43 #include "crypto/sha2.h" | 41 #include "crypto/sha2.h" |
44 #include "extensions/common/constants.h" | 42 #include "extensions/common/constants.h" |
| 43 #include "extensions/common/error_utils.h" |
| 44 #include "extensions/common/url_pattern_set.h" |
45 #include "googleurl/src/url_util.h" | 45 #include "googleurl/src/url_util.h" |
46 #include "grit/chromium_strings.h" | 46 #include "grit/chromium_strings.h" |
47 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
48 #include "third_party/skia/include/core/SkBitmap.h" | 48 #include "third_party/skia/include/core/SkBitmap.h" |
49 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
50 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
51 #include "webkit/glue/image_decoder.h" | 51 #include "webkit/glue/image_decoder.h" |
52 #include "webkit/glue/web_intent_service_data.h" | 52 #include "webkit/glue/web_intent_service_data.h" |
53 | 53 |
54 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 const int* icon_sizes, | 150 const int* icon_sizes, |
151 size_t num_icon_sizes, | 151 size_t num_icon_sizes, |
152 ExtensionIconSet* icons, | 152 ExtensionIconSet* icons, |
153 string16* error) { | 153 string16* error) { |
154 DCHECK(icons); | 154 DCHECK(icons); |
155 for (size_t i = 0; i < num_icon_sizes; ++i) { | 155 for (size_t i = 0; i < num_icon_sizes; ++i) { |
156 std::string key = base::IntToString(icon_sizes[i]); | 156 std::string key = base::IntToString(icon_sizes[i]); |
157 if (icons_value->HasKey(key)) { | 157 if (icons_value->HasKey(key)) { |
158 std::string icon_path; | 158 std::string icon_path; |
159 if (!icons_value->GetString(key, &icon_path)) { | 159 if (!icons_value->GetString(key, &icon_path)) { |
160 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 160 *error = ErrorUtils::FormatErrorMessageUTF16( |
161 errors::kInvalidIconPath, key); | 161 errors::kInvalidIconPath, key); |
162 return false; | 162 return false; |
163 } | 163 } |
164 | 164 |
165 if (!NormalizeAndValidatePath(&icon_path)) { | 165 if (!NormalizeAndValidatePath(&icon_path)) { |
166 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 166 *error = ErrorUtils::FormatErrorMessageUTF16( |
167 errors::kInvalidIconPath, key); | 167 errors::kInvalidIconPath, key); |
168 return false; | 168 return false; |
169 } | 169 } |
170 | 170 |
171 icons->Add(icon_sizes[i], icon_path); | 171 icons->Add(icon_sizes[i], icon_path); |
172 } | 172 } |
173 } | 173 } |
174 return true; | 174 return true; |
175 } | 175 } |
176 | 176 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 } | 258 } |
259 | 259 |
260 bool ReadLaunchDimension(const extensions::Manifest* manifest, | 260 bool ReadLaunchDimension(const extensions::Manifest* manifest, |
261 const char* key, | 261 const char* key, |
262 int* target, | 262 int* target, |
263 bool is_valid_container, | 263 bool is_valid_container, |
264 string16* error) { | 264 string16* error) { |
265 Value* temp = NULL; | 265 Value* temp = NULL; |
266 if (manifest->Get(key, &temp)) { | 266 if (manifest->Get(key, &temp)) { |
267 if (!is_valid_container) { | 267 if (!is_valid_container) { |
268 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 268 *error = ErrorUtils::FormatErrorMessageUTF16( |
269 errors::kInvalidLaunchValueContainer, | 269 errors::kInvalidLaunchValueContainer, |
270 key); | 270 key); |
271 return false; | 271 return false; |
272 } | 272 } |
273 if (!temp->GetAsInteger(target) || *target < 0) { | 273 if (!temp->GetAsInteger(target) || *target < 0) { |
274 *target = 0; | 274 *target = 0; |
275 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 275 *error = ErrorUtils::FormatErrorMessageUTF16( |
276 errors::kInvalidLaunchValue, | 276 errors::kInvalidLaunchValue, |
277 key); | 277 key); |
278 return false; | 278 return false; |
279 } | 279 } |
280 } | 280 } |
281 return true; | 281 return true; |
282 } | 282 } |
283 | 283 |
284 } // namespace | 284 } // namespace |
285 | 285 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 // Helper method that loads a UserScript object from a dictionary in the | 603 // Helper method that loads a UserScript object from a dictionary in the |
604 // content_script list of the manifest. | 604 // content_script list of the manifest. |
605 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, | 605 bool Extension::LoadUserScriptHelper(const DictionaryValue* content_script, |
606 int definition_index, | 606 int definition_index, |
607 string16* error, | 607 string16* error, |
608 UserScript* result) { | 608 UserScript* result) { |
609 // run_at | 609 // run_at |
610 if (content_script->HasKey(keys::kRunAt)) { | 610 if (content_script->HasKey(keys::kRunAt)) { |
611 std::string run_location; | 611 std::string run_location; |
612 if (!content_script->GetString(keys::kRunAt, &run_location)) { | 612 if (!content_script->GetString(keys::kRunAt, &run_location)) { |
613 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 613 *error = ErrorUtils::FormatErrorMessageUTF16( |
614 errors::kInvalidRunAt, | 614 errors::kInvalidRunAt, |
615 base::IntToString(definition_index)); | 615 base::IntToString(definition_index)); |
616 return false; | 616 return false; |
617 } | 617 } |
618 | 618 |
619 if (run_location == values::kRunAtDocumentStart) { | 619 if (run_location == values::kRunAtDocumentStart) { |
620 result->set_run_location(UserScript::DOCUMENT_START); | 620 result->set_run_location(UserScript::DOCUMENT_START); |
621 } else if (run_location == values::kRunAtDocumentEnd) { | 621 } else if (run_location == values::kRunAtDocumentEnd) { |
622 result->set_run_location(UserScript::DOCUMENT_END); | 622 result->set_run_location(UserScript::DOCUMENT_END); |
623 } else if (run_location == values::kRunAtDocumentIdle) { | 623 } else if (run_location == values::kRunAtDocumentIdle) { |
624 result->set_run_location(UserScript::DOCUMENT_IDLE); | 624 result->set_run_location(UserScript::DOCUMENT_IDLE); |
625 } else { | 625 } else { |
626 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 626 *error = ErrorUtils::FormatErrorMessageUTF16( |
627 errors::kInvalidRunAt, | 627 errors::kInvalidRunAt, |
628 base::IntToString(definition_index)); | 628 base::IntToString(definition_index)); |
629 return false; | 629 return false; |
630 } | 630 } |
631 } | 631 } |
632 | 632 |
633 // all frames | 633 // all frames |
634 if (content_script->HasKey(keys::kAllFrames)) { | 634 if (content_script->HasKey(keys::kAllFrames)) { |
635 bool all_frames = false; | 635 bool all_frames = false; |
636 if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) { | 636 if (!content_script->GetBoolean(keys::kAllFrames, &all_frames)) { |
637 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 637 *error = ErrorUtils::FormatErrorMessageUTF16( |
638 errors::kInvalidAllFrames, base::IntToString(definition_index)); | 638 errors::kInvalidAllFrames, base::IntToString(definition_index)); |
639 return false; | 639 return false; |
640 } | 640 } |
641 result->set_match_all_frames(all_frames); | 641 result->set_match_all_frames(all_frames); |
642 } | 642 } |
643 | 643 |
644 // matches (required) | 644 // matches (required) |
645 const ListValue* matches = NULL; | 645 const ListValue* matches = NULL; |
646 if (!content_script->GetList(keys::kMatches, &matches)) { | 646 if (!content_script->GetList(keys::kMatches, &matches)) { |
647 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 647 *error = ErrorUtils::FormatErrorMessageUTF16( |
648 errors::kInvalidMatches, | 648 errors::kInvalidMatches, |
649 base::IntToString(definition_index)); | 649 base::IntToString(definition_index)); |
650 return false; | 650 return false; |
651 } | 651 } |
652 | 652 |
653 if (matches->GetSize() == 0) { | 653 if (matches->GetSize() == 0) { |
654 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 654 *error = ErrorUtils::FormatErrorMessageUTF16( |
655 errors::kInvalidMatchCount, | 655 errors::kInvalidMatchCount, |
656 base::IntToString(definition_index)); | 656 base::IntToString(definition_index)); |
657 return false; | 657 return false; |
658 } | 658 } |
659 for (size_t j = 0; j < matches->GetSize(); ++j) { | 659 for (size_t j = 0; j < matches->GetSize(); ++j) { |
660 std::string match_str; | 660 std::string match_str; |
661 if (!matches->GetString(j, &match_str)) { | 661 if (!matches->GetString(j, &match_str)) { |
662 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 662 *error = ErrorUtils::FormatErrorMessageUTF16( |
663 errors::kInvalidMatch, | 663 errors::kInvalidMatch, |
664 base::IntToString(definition_index), | 664 base::IntToString(definition_index), |
665 base::IntToString(j), | 665 base::IntToString(j), |
666 errors::kExpectString); | 666 errors::kExpectString); |
667 return false; | 667 return false; |
668 } | 668 } |
669 | 669 |
670 URLPattern pattern(UserScript::kValidUserScriptSchemes); | 670 URLPattern pattern(UserScript::kValidUserScriptSchemes); |
671 if (CanExecuteScriptEverywhere()) | 671 if (CanExecuteScriptEverywhere()) |
672 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); | 672 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); |
673 | 673 |
674 URLPattern::ParseResult parse_result = pattern.Parse(match_str); | 674 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
675 if (parse_result != URLPattern::PARSE_SUCCESS) { | 675 if (parse_result != URLPattern::PARSE_SUCCESS) { |
676 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 676 *error = ErrorUtils::FormatErrorMessageUTF16( |
677 errors::kInvalidMatch, | 677 errors::kInvalidMatch, |
678 base::IntToString(definition_index), | 678 base::IntToString(definition_index), |
679 base::IntToString(j), | 679 base::IntToString(j), |
680 URLPattern::GetParseResultString(parse_result)); | 680 URLPattern::GetParseResultString(parse_result)); |
681 return false; | 681 return false; |
682 } | 682 } |
683 | 683 |
684 if (pattern.MatchesScheme(chrome::kFileScheme) && | 684 if (pattern.MatchesScheme(chrome::kFileScheme) && |
685 !CanExecuteScriptEverywhere()) { | 685 !CanExecuteScriptEverywhere()) { |
686 wants_file_access_ = true; | 686 wants_file_access_ = true; |
687 if (!(creation_flags_ & ALLOW_FILE_ACCESS)) { | 687 if (!(creation_flags_ & ALLOW_FILE_ACCESS)) { |
688 pattern.SetValidSchemes( | 688 pattern.SetValidSchemes( |
689 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 689 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 result->add_url_pattern(pattern); | 693 result->add_url_pattern(pattern); |
694 } | 694 } |
695 | 695 |
696 // exclude_matches | 696 // exclude_matches |
697 if (content_script->HasKey(keys::kExcludeMatches)) { // optional | 697 if (content_script->HasKey(keys::kExcludeMatches)) { // optional |
698 const ListValue* exclude_matches = NULL; | 698 const ListValue* exclude_matches = NULL; |
699 if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) { | 699 if (!content_script->GetList(keys::kExcludeMatches, &exclude_matches)) { |
700 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 700 *error = ErrorUtils::FormatErrorMessageUTF16( |
701 errors::kInvalidExcludeMatches, | 701 errors::kInvalidExcludeMatches, |
702 base::IntToString(definition_index)); | 702 base::IntToString(definition_index)); |
703 return false; | 703 return false; |
704 } | 704 } |
705 | 705 |
706 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) { | 706 for (size_t j = 0; j < exclude_matches->GetSize(); ++j) { |
707 std::string match_str; | 707 std::string match_str; |
708 if (!exclude_matches->GetString(j, &match_str)) { | 708 if (!exclude_matches->GetString(j, &match_str)) { |
709 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 709 *error = ErrorUtils::FormatErrorMessageUTF16( |
710 errors::kInvalidExcludeMatch, | 710 errors::kInvalidExcludeMatch, |
711 base::IntToString(definition_index), | 711 base::IntToString(definition_index), |
712 base::IntToString(j), | 712 base::IntToString(j), |
713 errors::kExpectString); | 713 errors::kExpectString); |
714 return false; | 714 return false; |
715 } | 715 } |
716 | 716 |
717 URLPattern pattern(UserScript::kValidUserScriptSchemes); | 717 URLPattern pattern(UserScript::kValidUserScriptSchemes); |
718 if (CanExecuteScriptEverywhere()) | 718 if (CanExecuteScriptEverywhere()) |
719 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); | 719 pattern.SetValidSchemes(URLPattern::SCHEME_ALL); |
720 URLPattern::ParseResult parse_result = pattern.Parse(match_str); | 720 URLPattern::ParseResult parse_result = pattern.Parse(match_str); |
721 if (parse_result != URLPattern::PARSE_SUCCESS) { | 721 if (parse_result != URLPattern::PARSE_SUCCESS) { |
722 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 722 *error = ErrorUtils::FormatErrorMessageUTF16( |
723 errors::kInvalidExcludeMatch, | 723 errors::kInvalidExcludeMatch, |
724 base::IntToString(definition_index), base::IntToString(j), | 724 base::IntToString(definition_index), base::IntToString(j), |
725 URLPattern::GetParseResultString(parse_result)); | 725 URLPattern::GetParseResultString(parse_result)); |
726 return false; | 726 return false; |
727 } | 727 } |
728 | 728 |
729 result->add_exclude_url_pattern(pattern); | 729 result->add_exclude_url_pattern(pattern); |
730 } | 730 } |
731 } | 731 } |
732 | 732 |
733 // include/exclude globs (mostly for Greasemonkey compatibility) | 733 // include/exclude globs (mostly for Greasemonkey compatibility) |
734 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, | 734 if (!LoadGlobsHelper(content_script, definition_index, keys::kIncludeGlobs, |
735 error, &UserScript::add_glob, result)) { | 735 error, &UserScript::add_glob, result)) { |
736 return false; | 736 return false; |
737 } | 737 } |
738 | 738 |
739 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, | 739 if (!LoadGlobsHelper(content_script, definition_index, keys::kExcludeGlobs, |
740 error, &UserScript::add_exclude_glob, result)) { | 740 error, &UserScript::add_exclude_glob, result)) { |
741 return false; | 741 return false; |
742 } | 742 } |
743 | 743 |
744 // js and css keys | 744 // js and css keys |
745 const ListValue* js = NULL; | 745 const ListValue* js = NULL; |
746 if (content_script->HasKey(keys::kJs) && | 746 if (content_script->HasKey(keys::kJs) && |
747 !content_script->GetList(keys::kJs, &js)) { | 747 !content_script->GetList(keys::kJs, &js)) { |
748 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 748 *error = ErrorUtils::FormatErrorMessageUTF16( |
749 errors::kInvalidJsList, | 749 errors::kInvalidJsList, |
750 base::IntToString(definition_index)); | 750 base::IntToString(definition_index)); |
751 return false; | 751 return false; |
752 } | 752 } |
753 | 753 |
754 const ListValue* css = NULL; | 754 const ListValue* css = NULL; |
755 if (content_script->HasKey(keys::kCss) && | 755 if (content_script->HasKey(keys::kCss) && |
756 !content_script->GetList(keys::kCss, &css)) { | 756 !content_script->GetList(keys::kCss, &css)) { |
757 *error = ExtensionErrorUtils:: | 757 *error = ErrorUtils:: |
758 FormatErrorMessageUTF16(errors::kInvalidCssList, | 758 FormatErrorMessageUTF16(errors::kInvalidCssList, |
759 base::IntToString(definition_index)); | 759 base::IntToString(definition_index)); |
760 return false; | 760 return false; |
761 } | 761 } |
762 | 762 |
763 // The manifest needs to have at least one js or css user script definition. | 763 // The manifest needs to have at least one js or css user script definition. |
764 if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) { | 764 if (((js ? js->GetSize() : 0) + (css ? css->GetSize() : 0)) == 0) { |
765 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 765 *error = ErrorUtils::FormatErrorMessageUTF16( |
766 errors::kMissingFile, | 766 errors::kMissingFile, |
767 base::IntToString(definition_index)); | 767 base::IntToString(definition_index)); |
768 return false; | 768 return false; |
769 } | 769 } |
770 | 770 |
771 if (js) { | 771 if (js) { |
772 for (size_t script_index = 0; script_index < js->GetSize(); | 772 for (size_t script_index = 0; script_index < js->GetSize(); |
773 ++script_index) { | 773 ++script_index) { |
774 const Value* value; | 774 const Value* value; |
775 std::string relative; | 775 std::string relative; |
776 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { | 776 if (!js->Get(script_index, &value) || !value->GetAsString(&relative)) { |
777 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 777 *error = ErrorUtils::FormatErrorMessageUTF16( |
778 errors::kInvalidJs, | 778 errors::kInvalidJs, |
779 base::IntToString(definition_index), | 779 base::IntToString(definition_index), |
780 base::IntToString(script_index)); | 780 base::IntToString(script_index)); |
781 return false; | 781 return false; |
782 } | 782 } |
783 GURL url = GetResourceURL(relative); | 783 GURL url = GetResourceURL(relative); |
784 ExtensionResource resource = GetResource(relative); | 784 ExtensionResource resource = GetResource(relative); |
785 result->js_scripts().push_back(UserScript::File( | 785 result->js_scripts().push_back(UserScript::File( |
786 resource.extension_root(), resource.relative_path(), url)); | 786 resource.extension_root(), resource.relative_path(), url)); |
787 } | 787 } |
788 } | 788 } |
789 | 789 |
790 if (css) { | 790 if (css) { |
791 for (size_t script_index = 0; script_index < css->GetSize(); | 791 for (size_t script_index = 0; script_index < css->GetSize(); |
792 ++script_index) { | 792 ++script_index) { |
793 const Value* value; | 793 const Value* value; |
794 std::string relative; | 794 std::string relative; |
795 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { | 795 if (!css->Get(script_index, &value) || !value->GetAsString(&relative)) { |
796 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 796 *error = ErrorUtils::FormatErrorMessageUTF16( |
797 errors::kInvalidCss, | 797 errors::kInvalidCss, |
798 base::IntToString(definition_index), | 798 base::IntToString(definition_index), |
799 base::IntToString(script_index)); | 799 base::IntToString(script_index)); |
800 return false; | 800 return false; |
801 } | 801 } |
802 GURL url = GetResourceURL(relative); | 802 GURL url = GetResourceURL(relative); |
803 ExtensionResource resource = GetResource(relative); | 803 ExtensionResource resource = GetResource(relative); |
804 result->css_scripts().push_back(UserScript::File( | 804 result->css_scripts().push_back(UserScript::File( |
805 resource.extension_root(), resource.relative_path(), url)); | 805 resource.extension_root(), resource.relative_path(), url)); |
806 } | 806 } |
807 } | 807 } |
808 | 808 |
809 return true; | 809 return true; |
810 } | 810 } |
811 | 811 |
812 bool Extension::LoadGlobsHelper( | 812 bool Extension::LoadGlobsHelper( |
813 const DictionaryValue* content_script, | 813 const DictionaryValue* content_script, |
814 int content_script_index, | 814 int content_script_index, |
815 const char* globs_property_name, | 815 const char* globs_property_name, |
816 string16* error, | 816 string16* error, |
817 void(UserScript::*add_method)(const std::string& glob), | 817 void(UserScript::*add_method)(const std::string& glob), |
818 UserScript* instance) { | 818 UserScript* instance) { |
819 if (!content_script->HasKey(globs_property_name)) | 819 if (!content_script->HasKey(globs_property_name)) |
820 return true; // they are optional | 820 return true; // they are optional |
821 | 821 |
822 const ListValue* list = NULL; | 822 const ListValue* list = NULL; |
823 if (!content_script->GetList(globs_property_name, &list)) { | 823 if (!content_script->GetList(globs_property_name, &list)) { |
824 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 824 *error = ErrorUtils::FormatErrorMessageUTF16( |
825 errors::kInvalidGlobList, | 825 errors::kInvalidGlobList, |
826 base::IntToString(content_script_index), | 826 base::IntToString(content_script_index), |
827 globs_property_name); | 827 globs_property_name); |
828 return false; | 828 return false; |
829 } | 829 } |
830 | 830 |
831 for (size_t i = 0; i < list->GetSize(); ++i) { | 831 for (size_t i = 0; i < list->GetSize(); ++i) { |
832 std::string glob; | 832 std::string glob; |
833 if (!list->GetString(i, &glob)) { | 833 if (!list->GetString(i, &glob)) { |
834 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 834 *error = ErrorUtils::FormatErrorMessageUTF16( |
835 errors::kInvalidGlob, | 835 errors::kInvalidGlob, |
836 base::IntToString(content_script_index), | 836 base::IntToString(content_script_index), |
837 globs_property_name, | 837 globs_property_name, |
838 base::IntToString(i)); | 838 base::IntToString(i)); |
839 return false; | 839 return false; |
840 } | 840 } |
841 | 841 |
842 (instance->*add_method)(glob); | 842 (instance->*add_method)(glob); |
843 } | 843 } |
844 | 844 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 } | 922 } |
923 | 923 |
924 // Read the action's |popup| (optional). | 924 // Read the action's |popup| (optional). |
925 const char* popup_key = NULL; | 925 const char* popup_key = NULL; |
926 if (extension_action->HasKey(keys::kPageActionDefaultPopup)) | 926 if (extension_action->HasKey(keys::kPageActionDefaultPopup)) |
927 popup_key = keys::kPageActionDefaultPopup; | 927 popup_key = keys::kPageActionDefaultPopup; |
928 | 928 |
929 if (manifest_version_ == 1 && | 929 if (manifest_version_ == 1 && |
930 extension_action->HasKey(keys::kPageActionPopup)) { | 930 extension_action->HasKey(keys::kPageActionPopup)) { |
931 if (popup_key) { | 931 if (popup_key) { |
932 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 932 *error = ErrorUtils::FormatErrorMessageUTF16( |
933 errors::kInvalidPageActionOldAndNewKeys, | 933 errors::kInvalidPageActionOldAndNewKeys, |
934 keys::kPageActionDefaultPopup, | 934 keys::kPageActionDefaultPopup, |
935 keys::kPageActionPopup); | 935 keys::kPageActionPopup); |
936 return scoped_ptr<ActionInfo>(); | 936 return scoped_ptr<ActionInfo>(); |
937 } | 937 } |
938 popup_key = keys::kPageActionPopup; | 938 popup_key = keys::kPageActionPopup; |
939 } | 939 } |
940 | 940 |
941 if (popup_key) { | 941 if (popup_key) { |
942 const DictionaryValue* popup = NULL; | 942 const DictionaryValue* popup = NULL; |
943 std::string url_str; | 943 std::string url_str; |
944 | 944 |
945 if (extension_action->GetString(popup_key, &url_str)) { | 945 if (extension_action->GetString(popup_key, &url_str)) { |
946 // On success, |url_str| is set. Nothing else to do. | 946 // On success, |url_str| is set. Nothing else to do. |
947 } else if (manifest_version_ == 1 && | 947 } else if (manifest_version_ == 1 && |
948 extension_action->GetDictionary(popup_key, &popup)) { | 948 extension_action->GetDictionary(popup_key, &popup)) { |
949 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { | 949 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { |
950 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 950 *error = ErrorUtils::FormatErrorMessageUTF16( |
951 errors::kInvalidPageActionPopupPath, "<missing>"); | 951 errors::kInvalidPageActionPopupPath, "<missing>"); |
952 return scoped_ptr<ActionInfo>(); | 952 return scoped_ptr<ActionInfo>(); |
953 } | 953 } |
954 } else { | 954 } else { |
955 *error = ASCIIToUTF16(errors::kInvalidPageActionPopup); | 955 *error = ASCIIToUTF16(errors::kInvalidPageActionPopup); |
956 return scoped_ptr<ActionInfo>(); | 956 return scoped_ptr<ActionInfo>(); |
957 } | 957 } |
958 | 958 |
959 if (!url_str.empty()) { | 959 if (!url_str.empty()) { |
960 // An empty string is treated as having no popup. | 960 // An empty string is treated as having no popup. |
961 result->default_popup_url = GetResourceURL(url_str); | 961 result->default_popup_url = GetResourceURL(url_str); |
962 if (!result->default_popup_url.is_valid()) { | 962 if (!result->default_popup_url.is_valid()) { |
963 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 963 *error = ErrorUtils::FormatErrorMessageUTF16( |
964 errors::kInvalidPageActionPopupPath, url_str); | 964 errors::kInvalidPageActionPopupPath, url_str); |
965 return scoped_ptr<ActionInfo>(); | 965 return scoped_ptr<ActionInfo>(); |
966 } | 966 } |
967 } else { | 967 } else { |
968 DCHECK(result->default_popup_url.is_empty()) | 968 DCHECK(result->default_popup_url.is_empty()) |
969 << "Shouldn't be possible for the popup to be set."; | 969 << "Shouldn't be possible for the popup to be set."; |
970 } | 970 } |
971 } | 971 } |
972 | 972 |
973 return result.Pass(); | 973 return result.Pass(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 | 1107 |
1108 if (temp_pattern_value->GetType() != Value::TYPE_LIST) { | 1108 if (temp_pattern_value->GetType() != Value::TYPE_LIST) { |
1109 *error = ASCIIToUTF16(list_error); | 1109 *error = ASCIIToUTF16(list_error); |
1110 return false; | 1110 return false; |
1111 } | 1111 } |
1112 | 1112 |
1113 ListValue* pattern_list = static_cast<ListValue*>(temp_pattern_value); | 1113 ListValue* pattern_list = static_cast<ListValue*>(temp_pattern_value); |
1114 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { | 1114 for (size_t i = 0; i < pattern_list->GetSize(); ++i) { |
1115 std::string pattern_string; | 1115 std::string pattern_string; |
1116 if (!pattern_list->GetString(i, &pattern_string)) { | 1116 if (!pattern_list->GetString(i, &pattern_string)) { |
1117 *error = ExtensionErrorUtils::FormatErrorMessageUTF16(value_error, | 1117 *error = ErrorUtils::FormatErrorMessageUTF16(value_error, |
1118 base::UintToString(i), | 1118 base::UintToString(i), |
1119 errors::kExpectString); | 1119 errors::kExpectString); |
1120 return false; | 1120 return false; |
1121 } | 1121 } |
1122 | 1122 |
1123 URLPattern pattern(kValidWebExtentSchemes); | 1123 URLPattern pattern(kValidWebExtentSchemes); |
1124 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string); | 1124 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string); |
1125 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) { | 1125 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) { |
1126 pattern_string += "/"; | 1126 pattern_string += "/"; |
1127 parse_result = pattern.Parse(pattern_string); | 1127 parse_result = pattern.Parse(pattern_string); |
1128 } | 1128 } |
1129 | 1129 |
1130 if (parse_result != URLPattern::PARSE_SUCCESS) { | 1130 if (parse_result != URLPattern::PARSE_SUCCESS) { |
1131 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1131 *error = ErrorUtils::FormatErrorMessageUTF16( |
1132 value_error, | 1132 value_error, |
1133 base::UintToString(i), | 1133 base::UintToString(i), |
1134 URLPattern::GetParseResultString(parse_result)); | 1134 URLPattern::GetParseResultString(parse_result)); |
1135 return false; | 1135 return false; |
1136 } | 1136 } |
1137 | 1137 |
1138 // Do not allow authors to claim "<all_urls>". | 1138 // Do not allow authors to claim "<all_urls>". |
1139 if (pattern.match_all_urls()) { | 1139 if (pattern.match_all_urls()) { |
1140 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1140 *error = ErrorUtils::FormatErrorMessageUTF16( |
1141 value_error, | 1141 value_error, |
1142 base::UintToString(i), | 1142 base::UintToString(i), |
1143 errors::kCannotClaimAllURLsInExtent); | 1143 errors::kCannotClaimAllURLsInExtent); |
1144 return false; | 1144 return false; |
1145 } | 1145 } |
1146 | 1146 |
1147 // Do not allow authors to claim "*" for host. | 1147 // Do not allow authors to claim "*" for host. |
1148 if (pattern.host().empty()) { | 1148 if (pattern.host().empty()) { |
1149 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1149 *error = ErrorUtils::FormatErrorMessageUTF16( |
1150 value_error, | 1150 value_error, |
1151 base::UintToString(i), | 1151 base::UintToString(i), |
1152 errors::kCannotClaimAllHostsInExtent); | 1152 errors::kCannotClaimAllHostsInExtent); |
1153 return false; | 1153 return false; |
1154 } | 1154 } |
1155 | 1155 |
1156 // We do not allow authors to put wildcards in their paths. Instead, we | 1156 // We do not allow authors to put wildcards in their paths. Instead, we |
1157 // imply one at the end. | 1157 // imply one at the end. |
1158 if (pattern.path().find('*') != std::string::npos) { | 1158 if (pattern.path().find('*') != std::string::npos) { |
1159 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1159 *error = ErrorUtils::FormatErrorMessageUTF16( |
1160 value_error, | 1160 value_error, |
1161 base::UintToString(i), | 1161 base::UintToString(i), |
1162 errors::kNoWildCardsInPaths); | 1162 errors::kNoWildCardsInPaths); |
1163 return false; | 1163 return false; |
1164 } | 1164 } |
1165 pattern.SetPath(pattern.path() + '*'); | 1165 pattern.SetPath(pattern.path() + '*'); |
1166 | 1166 |
1167 extent->AddPattern(pattern); | 1167 extent->AddPattern(pattern); |
1168 } | 1168 } |
1169 | 1169 |
(...skipping 11 matching lines...) Expand all Loading... |
1181 return false; | 1181 return false; |
1182 } | 1182 } |
1183 | 1183 |
1184 if (manifest_->Get(keys::kWebURLs, NULL)) { | 1184 if (manifest_->Get(keys::kWebURLs, NULL)) { |
1185 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive); | 1185 *error = ASCIIToUTF16(errors::kLaunchPathAndExtentAreExclusive); |
1186 return false; | 1186 return false; |
1187 } | 1187 } |
1188 | 1188 |
1189 std::string launch_path; | 1189 std::string launch_path; |
1190 if (!temp->GetAsString(&launch_path)) { | 1190 if (!temp->GetAsString(&launch_path)) { |
1191 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1191 *error = ErrorUtils::FormatErrorMessageUTF16( |
1192 errors::kInvalidLaunchValue, | 1192 errors::kInvalidLaunchValue, |
1193 keys::kLaunchLocalPath); | 1193 keys::kLaunchLocalPath); |
1194 return false; | 1194 return false; |
1195 } | 1195 } |
1196 | 1196 |
1197 // Ensure the launch path is a valid relative URL. | 1197 // Ensure the launch path is a valid relative URL. |
1198 GURL resolved = url().Resolve(launch_path); | 1198 GURL resolved = url().Resolve(launch_path); |
1199 if (!resolved.is_valid() || resolved.GetOrigin() != url()) { | 1199 if (!resolved.is_valid() || resolved.GetOrigin() != url()) { |
1200 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1200 *error = ErrorUtils::FormatErrorMessageUTF16( |
1201 errors::kInvalidLaunchValue, | 1201 errors::kInvalidLaunchValue, |
1202 keys::kLaunchLocalPath); | 1202 keys::kLaunchLocalPath); |
1203 return false; | 1203 return false; |
1204 } | 1204 } |
1205 | 1205 |
1206 launch_local_path_ = launch_path; | 1206 launch_local_path_ = launch_path; |
1207 } else if (manifest_->Get(keys::kLaunchWebURL, &temp)) { | 1207 } else if (manifest_->Get(keys::kLaunchWebURL, &temp)) { |
1208 std::string launch_url; | 1208 std::string launch_url; |
1209 if (!temp->GetAsString(&launch_url)) { | 1209 if (!temp->GetAsString(&launch_url)) { |
1210 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1210 *error = ErrorUtils::FormatErrorMessageUTF16( |
1211 errors::kInvalidLaunchValue, | 1211 errors::kInvalidLaunchValue, |
1212 keys::kLaunchWebURL); | 1212 keys::kLaunchWebURL); |
1213 return false; | 1213 return false; |
1214 } | 1214 } |
1215 | 1215 |
1216 // Ensure the launch URL is a valid absolute URL and web extent scheme. | 1216 // Ensure the launch URL is a valid absolute URL and web extent scheme. |
1217 GURL url(launch_url); | 1217 GURL url(launch_url); |
1218 URLPattern pattern(kValidWebExtentSchemes); | 1218 URLPattern pattern(kValidWebExtentSchemes); |
1219 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { | 1219 if (!url.is_valid() || !pattern.SetScheme(url.scheme())) { |
1220 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1220 *error = ErrorUtils::FormatErrorMessageUTF16( |
1221 errors::kInvalidLaunchValue, | 1221 errors::kInvalidLaunchValue, |
1222 keys::kLaunchWebURL); | 1222 keys::kLaunchWebURL); |
1223 return false; | 1223 return false; |
1224 } | 1224 } |
1225 | 1225 |
1226 launch_web_url_ = launch_url; | 1226 launch_web_url_ = launch_url; |
1227 } else if (is_legacy_packaged_app() || is_hosted_app()) { | 1227 } else if (is_legacy_packaged_app() || is_hosted_app()) { |
1228 *error = ASCIIToUTF16(errors::kLaunchURLRequired); | 1228 *error = ASCIIToUTF16(errors::kLaunchURLRequired); |
1229 return false; | 1229 return false; |
1230 } | 1230 } |
1231 | 1231 |
1232 // If there is no extent, we default the extent based on the launch URL. | 1232 // If there is no extent, we default the extent based on the launch URL. |
1233 if (web_extent().is_empty() && !launch_web_url().empty()) { | 1233 if (web_extent().is_empty() && !launch_web_url().empty()) { |
1234 GURL launch_url(launch_web_url()); | 1234 GURL launch_url(launch_web_url()); |
1235 URLPattern pattern(kValidWebExtentSchemes); | 1235 URLPattern pattern(kValidWebExtentSchemes); |
1236 if (!pattern.SetScheme("*")) { | 1236 if (!pattern.SetScheme("*")) { |
1237 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1237 *error = ErrorUtils::FormatErrorMessageUTF16( |
1238 errors::kInvalidLaunchValue, | 1238 errors::kInvalidLaunchValue, |
1239 keys::kLaunchWebURL); | 1239 keys::kLaunchWebURL); |
1240 return false; | 1240 return false; |
1241 } | 1241 } |
1242 pattern.SetHost(launch_url.host()); | 1242 pattern.SetHost(launch_url.host()); |
1243 pattern.SetPath("/*"); | 1243 pattern.SetPath("/*"); |
1244 extent_.AddPattern(pattern); | 1244 extent_.AddPattern(pattern); |
1245 } | 1245 } |
1246 | 1246 |
1247 // In order for the --apps-gallery-url switch to work with the gallery | 1247 // In order for the --apps-gallery-url switch to work with the gallery |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); | 1379 *error = ASCIIToUTF16(errors::kInvalidManifestVersion); |
1380 return false; | 1380 return false; |
1381 } | 1381 } |
1382 } | 1382 } |
1383 | 1383 |
1384 manifest_version_ = manifest_->GetManifestVersion(); | 1384 manifest_version_ = manifest_->GetManifestVersion(); |
1385 if (creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION && | 1385 if (creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION && |
1386 manifest_version_ < kModernManifestVersion && | 1386 manifest_version_ < kModernManifestVersion && |
1387 !CommandLine::ForCurrentProcess()->HasSwitch( | 1387 !CommandLine::ForCurrentProcess()->HasSwitch( |
1388 switches::kAllowLegacyExtensionManifests)) { | 1388 switches::kAllowLegacyExtensionManifests)) { |
1389 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1389 *error = ErrorUtils::FormatErrorMessageUTF16( |
1390 errors::kInvalidManifestVersionOld, | 1390 errors::kInvalidManifestVersionOld, |
1391 base::IntToString(kModernManifestVersion)); | 1391 base::IntToString(kModernManifestVersion)); |
1392 return false; | 1392 return false; |
1393 } | 1393 } |
1394 | 1394 |
1395 return true; | 1395 return true; |
1396 } | 1396 } |
1397 | 1397 |
1398 bool Extension::LoadHomepageURL(string16* error) { | 1398 bool Extension::LoadHomepageURL(string16* error) { |
1399 if (!manifest_->HasKey(keys::kHomepageURL)) | 1399 if (!manifest_->HasKey(keys::kHomepageURL)) |
1400 return true; | 1400 return true; |
1401 std::string tmp_homepage_url; | 1401 std::string tmp_homepage_url; |
1402 if (!manifest_->GetString(keys::kHomepageURL, &tmp_homepage_url)) { | 1402 if (!manifest_->GetString(keys::kHomepageURL, &tmp_homepage_url)) { |
1403 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1403 *error = ErrorUtils::FormatErrorMessageUTF16( |
1404 errors::kInvalidHomepageURL, ""); | 1404 errors::kInvalidHomepageURL, ""); |
1405 return false; | 1405 return false; |
1406 } | 1406 } |
1407 homepage_url_ = GURL(tmp_homepage_url); | 1407 homepage_url_ = GURL(tmp_homepage_url); |
1408 if (!homepage_url_.is_valid() || | 1408 if (!homepage_url_.is_valid() || |
1409 (!homepage_url_.SchemeIs("http") && | 1409 (!homepage_url_.SchemeIs("http") && |
1410 !homepage_url_.SchemeIs("https"))) { | 1410 !homepage_url_.SchemeIs("https"))) { |
1411 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1411 *error = ErrorUtils::FormatErrorMessageUTF16( |
1412 errors::kInvalidHomepageURL, tmp_homepage_url); | 1412 errors::kInvalidHomepageURL, tmp_homepage_url); |
1413 return false; | 1413 return false; |
1414 } | 1414 } |
1415 return true; | 1415 return true; |
1416 } | 1416 } |
1417 | 1417 |
1418 bool Extension::LoadUpdateURL(string16* error) { | 1418 bool Extension::LoadUpdateURL(string16* error) { |
1419 if (!manifest_->HasKey(keys::kUpdateURL)) | 1419 if (!manifest_->HasKey(keys::kUpdateURL)) |
1420 return true; | 1420 return true; |
1421 std::string tmp_update_url; | 1421 std::string tmp_update_url; |
1422 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { | 1422 if (!manifest_->GetString(keys::kUpdateURL, &tmp_update_url)) { |
1423 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1423 *error = ErrorUtils::FormatErrorMessageUTF16( |
1424 errors::kInvalidUpdateURL, ""); | 1424 errors::kInvalidUpdateURL, ""); |
1425 return false; | 1425 return false; |
1426 } | 1426 } |
1427 update_url_ = GURL(tmp_update_url); | 1427 update_url_ = GURL(tmp_update_url); |
1428 if (!update_url_.is_valid() || | 1428 if (!update_url_.is_valid() || |
1429 update_url_.has_ref()) { | 1429 update_url_.has_ref()) { |
1430 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1430 *error = ErrorUtils::FormatErrorMessageUTF16( |
1431 errors::kInvalidUpdateURL, tmp_update_url); | 1431 errors::kInvalidUpdateURL, tmp_update_url); |
1432 return false; | 1432 return false; |
1433 } | 1433 } |
1434 return true; | 1434 return true; |
1435 } | 1435 } |
1436 | 1436 |
1437 bool Extension::LoadIcons(string16* error) { | 1437 bool Extension::LoadIcons(string16* error) { |
1438 if (!manifest_->HasKey(keys::kIcons)) | 1438 if (!manifest_->HasKey(keys::kIcons)) |
1439 return true; | 1439 return true; |
1440 DictionaryValue* icons_value = NULL; | 1440 DictionaryValue* icons_value = NULL; |
(...skipping 11 matching lines...) Expand all Loading... |
1452 | 1452 |
1453 bool Extension::LoadCommands(string16* error) { | 1453 bool Extension::LoadCommands(string16* error) { |
1454 if (manifest_->HasKey(keys::kCommands)) { | 1454 if (manifest_->HasKey(keys::kCommands)) { |
1455 DictionaryValue* commands = NULL; | 1455 DictionaryValue* commands = NULL; |
1456 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { | 1456 if (!manifest_->GetDictionary(keys::kCommands, &commands)) { |
1457 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); | 1457 *error = ASCIIToUTF16(errors::kInvalidCommandsKey); |
1458 return false; | 1458 return false; |
1459 } | 1459 } |
1460 | 1460 |
1461 if (commands->size() > kMaxCommandsPerExtension) { | 1461 if (commands->size() > kMaxCommandsPerExtension) { |
1462 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1462 *error = ErrorUtils::FormatErrorMessageUTF16( |
1463 errors::kInvalidKeyBindingTooMany, | 1463 errors::kInvalidKeyBindingTooMany, |
1464 base::IntToString(kMaxCommandsPerExtension)); | 1464 base::IntToString(kMaxCommandsPerExtension)); |
1465 return false; | 1465 return false; |
1466 } | 1466 } |
1467 | 1467 |
1468 int command_index = 0; | 1468 int command_index = 0; |
1469 for (DictionaryValue::key_iterator iter = commands->begin_keys(); | 1469 for (DictionaryValue::key_iterator iter = commands->begin_keys(); |
1470 iter != commands->end_keys(); ++iter) { | 1470 iter != commands->end_keys(); ++iter) { |
1471 ++command_index; | 1471 ++command_index; |
1472 | 1472 |
1473 DictionaryValue* command = NULL; | 1473 DictionaryValue* command = NULL; |
1474 if (!commands->GetDictionary(*iter, &command)) { | 1474 if (!commands->GetDictionary(*iter, &command)) { |
1475 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1475 *error = ErrorUtils::FormatErrorMessageUTF16( |
1476 errors::kInvalidKeyBindingDictionary, | 1476 errors::kInvalidKeyBindingDictionary, |
1477 base::IntToString(command_index)); | 1477 base::IntToString(command_index)); |
1478 return false; | 1478 return false; |
1479 } | 1479 } |
1480 | 1480 |
1481 scoped_ptr<extensions::Command> binding(new extensions::Command()); | 1481 scoped_ptr<extensions::Command> binding(new extensions::Command()); |
1482 if (!binding->Parse(command, *iter, command_index, error)) | 1482 if (!binding->Parse(command, *iter, command_index, error)) |
1483 return false; // |error| already set. | 1483 return false; // |error| already set. |
1484 | 1484 |
1485 std::string command_name = binding->command_name(); | 1485 std::string command_name = binding->command_name(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 | 1521 |
1522 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1522 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1523 DictionaryValue* plugin_value = NULL; | 1523 DictionaryValue* plugin_value = NULL; |
1524 if (!list_value->GetDictionary(i, &plugin_value)) { | 1524 if (!list_value->GetDictionary(i, &plugin_value)) { |
1525 *error = ASCIIToUTF16(errors::kInvalidPlugins); | 1525 *error = ASCIIToUTF16(errors::kInvalidPlugins); |
1526 return false; | 1526 return false; |
1527 } | 1527 } |
1528 // Get plugins[i].path. | 1528 // Get plugins[i].path. |
1529 std::string path_str; | 1529 std::string path_str; |
1530 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) { | 1530 if (!plugin_value->GetString(keys::kPluginsPath, &path_str)) { |
1531 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1531 *error = ErrorUtils::FormatErrorMessageUTF16( |
1532 errors::kInvalidPluginsPath, base::IntToString(i)); | 1532 errors::kInvalidPluginsPath, base::IntToString(i)); |
1533 return false; | 1533 return false; |
1534 } | 1534 } |
1535 | 1535 |
1536 // Get plugins[i].content (optional). | 1536 // Get plugins[i].content (optional). |
1537 bool is_public = false; | 1537 bool is_public = false; |
1538 if (plugin_value->HasKey(keys::kPluginsPublic)) { | 1538 if (plugin_value->HasKey(keys::kPluginsPublic)) { |
1539 if (!plugin_value->GetBoolean(keys::kPluginsPublic, &is_public)) { | 1539 if (!plugin_value->GetBoolean(keys::kPluginsPublic, &is_public)) { |
1540 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1540 *error = ErrorUtils::FormatErrorMessageUTF16( |
1541 errors::kInvalidPluginsPublic, base::IntToString(i)); | 1541 errors::kInvalidPluginsPublic, base::IntToString(i)); |
1542 return false; | 1542 return false; |
1543 } | 1543 } |
1544 } | 1544 } |
1545 | 1545 |
1546 // We don't allow extensions to load NPAPI plugins on Chrome OS, or under | 1546 // We don't allow extensions to load NPAPI plugins on Chrome OS, or under |
1547 // Windows 8 Metro mode, but still parse the entries to display consistent | 1547 // Windows 8 Metro mode, but still parse the entries to display consistent |
1548 // error messages. If the extension actually requires the plugins then | 1548 // error messages. If the extension actually requires the plugins then |
1549 // LoadRequirements will prevent it loading. | 1549 // LoadRequirements will prevent it loading. |
1550 #if defined(OS_CHROMEOS) | 1550 #if defined(OS_CHROMEOS) |
(...skipping 22 matching lines...) Expand all Loading... |
1573 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1573 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1574 DictionaryValue* module_value = NULL; | 1574 DictionaryValue* module_value = NULL; |
1575 if (!list_value->GetDictionary(i, &module_value)) { | 1575 if (!list_value->GetDictionary(i, &module_value)) { |
1576 *error = ASCIIToUTF16(errors::kInvalidNaClModules); | 1576 *error = ASCIIToUTF16(errors::kInvalidNaClModules); |
1577 return false; | 1577 return false; |
1578 } | 1578 } |
1579 | 1579 |
1580 // Get nacl_modules[i].path. | 1580 // Get nacl_modules[i].path. |
1581 std::string path_str; | 1581 std::string path_str; |
1582 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) { | 1582 if (!module_value->GetString(keys::kNaClModulesPath, &path_str)) { |
1583 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1583 *error = ErrorUtils::FormatErrorMessageUTF16( |
1584 errors::kInvalidNaClModulesPath, base::IntToString(i)); | 1584 errors::kInvalidNaClModulesPath, base::IntToString(i)); |
1585 return false; | 1585 return false; |
1586 } | 1586 } |
1587 | 1587 |
1588 // Get nacl_modules[i].mime_type. | 1588 // Get nacl_modules[i].mime_type. |
1589 std::string mime_type; | 1589 std::string mime_type; |
1590 if (!module_value->GetString(keys::kNaClModulesMIMEType, &mime_type)) { | 1590 if (!module_value->GetString(keys::kNaClModulesMIMEType, &mime_type)) { |
1591 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1591 *error = ErrorUtils::FormatErrorMessageUTF16( |
1592 errors::kInvalidNaClModulesMIMEType, base::IntToString(i)); | 1592 errors::kInvalidNaClModulesMIMEType, base::IntToString(i)); |
1593 return false; | 1593 return false; |
1594 } | 1594 } |
1595 | 1595 |
1596 nacl_modules_.push_back(NaClModuleInfo()); | 1596 nacl_modules_.push_back(NaClModuleInfo()); |
1597 nacl_modules_.back().url = GetResourceURL(path_str); | 1597 nacl_modules_.back().url = GetResourceURL(path_str); |
1598 nacl_modules_.back().mime_type = mime_type; | 1598 nacl_modules_.back().mime_type = mime_type; |
1599 } | 1599 } |
1600 | 1600 |
1601 return true; | 1601 return true; |
1602 } | 1602 } |
1603 | 1603 |
1604 bool Extension::LoadWebAccessibleResources(string16* error) { | 1604 bool Extension::LoadWebAccessibleResources(string16* error) { |
1605 if (!manifest_->HasKey(keys::kWebAccessibleResources)) | 1605 if (!manifest_->HasKey(keys::kWebAccessibleResources)) |
1606 return true; | 1606 return true; |
1607 ListValue* list_value = NULL; | 1607 ListValue* list_value = NULL; |
1608 if (!manifest_->GetList(keys::kWebAccessibleResources, &list_value)) { | 1608 if (!manifest_->GetList(keys::kWebAccessibleResources, &list_value)) { |
1609 *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList); | 1609 *error = ASCIIToUTF16(errors::kInvalidWebAccessibleResourcesList); |
1610 return false; | 1610 return false; |
1611 } | 1611 } |
1612 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1612 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1613 std::string relative_path; | 1613 std::string relative_path; |
1614 if (!list_value->GetString(i, &relative_path)) { | 1614 if (!list_value->GetString(i, &relative_path)) { |
1615 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1615 *error = ErrorUtils::FormatErrorMessageUTF16( |
1616 errors::kInvalidWebAccessibleResource, base::IntToString(i)); | 1616 errors::kInvalidWebAccessibleResource, base::IntToString(i)); |
1617 return false; | 1617 return false; |
1618 } | 1618 } |
1619 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 1619 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
1620 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { | 1620 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { |
1621 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1621 *error = ErrorUtils::FormatErrorMessageUTF16( |
1622 errors::kInvalidURLPatternError, extension_url_.spec()); | 1622 errors::kInvalidURLPatternError, extension_url_.spec()); |
1623 return false; | 1623 return false; |
1624 } | 1624 } |
1625 while (relative_path[0] == '/') | 1625 while (relative_path[0] == '/') |
1626 relative_path = relative_path.substr(1, relative_path.length() - 1); | 1626 relative_path = relative_path.substr(1, relative_path.length() - 1); |
1627 pattern.SetPath(pattern.path() + relative_path); | 1627 pattern.SetPath(pattern.path() + relative_path); |
1628 web_accessible_resources_.AddPattern(pattern); | 1628 web_accessible_resources_.AddPattern(pattern); |
1629 } | 1629 } |
1630 | 1630 |
1631 return true; | 1631 return true; |
1632 } | 1632 } |
1633 | 1633 |
1634 bool Extension::LoadSandboxedPages(string16* error) { | 1634 bool Extension::LoadSandboxedPages(string16* error) { |
1635 if (!manifest_->HasPath(keys::kSandboxedPages)) | 1635 if (!manifest_->HasPath(keys::kSandboxedPages)) |
1636 return true; | 1636 return true; |
1637 | 1637 |
1638 ListValue* list_value = NULL; | 1638 ListValue* list_value = NULL; |
1639 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { | 1639 if (!manifest_->GetList(keys::kSandboxedPages, &list_value)) { |
1640 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); | 1640 *error = ASCIIToUTF16(errors::kInvalidSandboxedPagesList); |
1641 return false; | 1641 return false; |
1642 } | 1642 } |
1643 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 1643 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
1644 std::string relative_path; | 1644 std::string relative_path; |
1645 if (!list_value->GetString(i, &relative_path)) { | 1645 if (!list_value->GetString(i, &relative_path)) { |
1646 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1646 *error = ErrorUtils::FormatErrorMessageUTF16( |
1647 errors::kInvalidSandboxedPage, base::IntToString(i)); | 1647 errors::kInvalidSandboxedPage, base::IntToString(i)); |
1648 return false; | 1648 return false; |
1649 } | 1649 } |
1650 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 1650 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
1651 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { | 1651 if (pattern.Parse(extension_url_.spec()) != URLPattern::PARSE_SUCCESS) { |
1652 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1652 *error = ErrorUtils::FormatErrorMessageUTF16( |
1653 errors::kInvalidURLPatternError, extension_url_.spec()); | 1653 errors::kInvalidURLPatternError, extension_url_.spec()); |
1654 return false; | 1654 return false; |
1655 } | 1655 } |
1656 while (relative_path[0] == '/') | 1656 while (relative_path[0] == '/') |
1657 relative_path = relative_path.substr(1, relative_path.length() - 1); | 1657 relative_path = relative_path.substr(1, relative_path.length() - 1); |
1658 pattern.SetPath(pattern.path() + relative_path); | 1658 pattern.SetPath(pattern.path() + relative_path); |
1659 sandboxed_pages_.AddPattern(pattern); | 1659 sandboxed_pages_.AddPattern(pattern); |
1660 } | 1660 } |
1661 | 1661 |
1662 if (manifest_->HasPath(keys::kSandboxedPagesCSP)) { | 1662 if (manifest_->HasPath(keys::kSandboxedPagesCSP)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { | 1697 if (!manifest_->GetDictionary(keys::kRequirements, &requirements_value)) { |
1698 *error = ASCIIToUTF16(errors::kInvalidRequirements); | 1698 *error = ASCIIToUTF16(errors::kInvalidRequirements); |
1699 return false; | 1699 return false; |
1700 } | 1700 } |
1701 | 1701 |
1702 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); | 1702 for (DictionaryValue::key_iterator it = requirements_value->begin_keys(); |
1703 it != requirements_value->end_keys(); ++it) { | 1703 it != requirements_value->end_keys(); ++it) { |
1704 DictionaryValue* requirement_value; | 1704 DictionaryValue* requirement_value; |
1705 if (!requirements_value->GetDictionaryWithoutPathExpansion( | 1705 if (!requirements_value->GetDictionaryWithoutPathExpansion( |
1706 *it, &requirement_value)) { | 1706 *it, &requirement_value)) { |
1707 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1707 *error = ErrorUtils::FormatErrorMessageUTF16( |
1708 errors::kInvalidRequirement, *it); | 1708 errors::kInvalidRequirement, *it); |
1709 return false; | 1709 return false; |
1710 } | 1710 } |
1711 | 1711 |
1712 if (*it == "plugins") { | 1712 if (*it == "plugins") { |
1713 for (DictionaryValue::key_iterator plugin_it = | 1713 for (DictionaryValue::key_iterator plugin_it = |
1714 requirement_value->begin_keys(); | 1714 requirement_value->begin_keys(); |
1715 plugin_it != requirement_value->end_keys(); ++plugin_it) { | 1715 plugin_it != requirement_value->end_keys(); ++plugin_it) { |
1716 bool plugin_required = false; | 1716 bool plugin_required = false; |
1717 if (!requirement_value->GetBoolean(*plugin_it, &plugin_required)) { | 1717 if (!requirement_value->GetBoolean(*plugin_it, &plugin_required)) { |
1718 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1718 *error = ErrorUtils::FormatErrorMessageUTF16( |
1719 errors::kInvalidRequirement, *it); | 1719 errors::kInvalidRequirement, *it); |
1720 return false; | 1720 return false; |
1721 } | 1721 } |
1722 if (*plugin_it == "npapi") { | 1722 if (*plugin_it == "npapi") { |
1723 requirements_.npapi = plugin_required; | 1723 requirements_.npapi = plugin_required; |
1724 } else { | 1724 } else { |
1725 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1725 *error = ErrorUtils::FormatErrorMessageUTF16( |
1726 errors::kInvalidRequirement, *it); | 1726 errors::kInvalidRequirement, *it); |
1727 return false; | 1727 return false; |
1728 } | 1728 } |
1729 } | 1729 } |
1730 } else if (*it == "3D") { | 1730 } else if (*it == "3D") { |
1731 ListValue* features = NULL; | 1731 ListValue* features = NULL; |
1732 if (!requirement_value->GetListWithoutPathExpansion("features", | 1732 if (!requirement_value->GetListWithoutPathExpansion("features", |
1733 &features) || | 1733 &features) || |
1734 !features) { | 1734 !features) { |
1735 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1735 *error = ErrorUtils::FormatErrorMessageUTF16( |
1736 errors::kInvalidRequirement, *it); | 1736 errors::kInvalidRequirement, *it); |
1737 return false; | 1737 return false; |
1738 } | 1738 } |
1739 | 1739 |
1740 for (base::ListValue::iterator feature_it = features->begin(); | 1740 for (base::ListValue::iterator feature_it = features->begin(); |
1741 feature_it != features->end(); | 1741 feature_it != features->end(); |
1742 ++feature_it) { | 1742 ++feature_it) { |
1743 std::string feature; | 1743 std::string feature; |
1744 if ((*feature_it)->GetAsString(&feature)) { | 1744 if ((*feature_it)->GetAsString(&feature)) { |
1745 if (feature == "webgl") { | 1745 if (feature == "webgl") { |
1746 requirements_.webgl = true; | 1746 requirements_.webgl = true; |
1747 } else if (feature == "css3d") { | 1747 } else if (feature == "css3d") { |
1748 requirements_.css3d = true; | 1748 requirements_.css3d = true; |
1749 } else { | 1749 } else { |
1750 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1750 *error = ErrorUtils::FormatErrorMessageUTF16( |
1751 errors::kInvalidRequirement, *it); | 1751 errors::kInvalidRequirement, *it); |
1752 return false; | 1752 return false; |
1753 } | 1753 } |
1754 } | 1754 } |
1755 } | 1755 } |
1756 } else { | 1756 } else { |
1757 *error = ASCIIToUTF16(errors::kInvalidRequirements); | 1757 *error = ASCIIToUTF16(errors::kInvalidRequirements); |
1758 return false; | 1758 return false; |
1759 } | 1759 } |
1760 } | 1760 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 if (background_scripts_value->GetType() != Value::TYPE_LIST) { | 1834 if (background_scripts_value->GetType() != Value::TYPE_LIST) { |
1835 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); | 1835 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); |
1836 return false; | 1836 return false; |
1837 } | 1837 } |
1838 | 1838 |
1839 ListValue* background_scripts = | 1839 ListValue* background_scripts = |
1840 static_cast<ListValue*>(background_scripts_value); | 1840 static_cast<ListValue*>(background_scripts_value); |
1841 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { | 1841 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { |
1842 std::string script; | 1842 std::string script; |
1843 if (!background_scripts->GetString(i, &script)) { | 1843 if (!background_scripts->GetString(i, &script)) { |
1844 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1844 *error = ErrorUtils::FormatErrorMessageUTF16( |
1845 errors::kInvalidBackgroundScript, base::IntToString(i)); | 1845 errors::kInvalidBackgroundScript, base::IntToString(i)); |
1846 return false; | 1846 return false; |
1847 } | 1847 } |
1848 background_scripts_.push_back(script); | 1848 background_scripts_.push_back(script); |
1849 } | 1849 } |
1850 | 1850 |
1851 return true; | 1851 return true; |
1852 } | 1852 } |
1853 | 1853 |
1854 bool Extension::LoadBackgroundPage( | 1854 bool Extension::LoadBackgroundPage( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 DCHECK(error); | 1963 DCHECK(error); |
1964 webkit_glue::WebIntentServiceData service; | 1964 webkit_glue::WebIntentServiceData service; |
1965 std::string value; | 1965 std::string value; |
1966 | 1966 |
1967 service.action = UTF8ToUTF16(action_name); | 1967 service.action = UTF8ToUTF16(action_name); |
1968 | 1968 |
1969 const ListValue* mime_types = NULL; | 1969 const ListValue* mime_types = NULL; |
1970 if (!intent_service.HasKey(keys::kIntentType) || | 1970 if (!intent_service.HasKey(keys::kIntentType) || |
1971 !intent_service.GetList(keys::kIntentType, &mime_types) || | 1971 !intent_service.GetList(keys::kIntentType, &mime_types) || |
1972 mime_types->GetSize() == 0) { | 1972 mime_types->GetSize() == 0) { |
1973 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1973 *error = ErrorUtils::FormatErrorMessageUTF16( |
1974 errors::kInvalidIntentType, action_name); | 1974 errors::kInvalidIntentType, action_name); |
1975 return false; | 1975 return false; |
1976 } | 1976 } |
1977 | 1977 |
1978 std::string href; | 1978 std::string href; |
1979 if (intent_service.HasKey(keys::kIntentPath)) { | 1979 if (intent_service.HasKey(keys::kIntentPath)) { |
1980 if (!intent_service.GetString(keys::kIntentPath, &href)) { | 1980 if (!intent_service.GetString(keys::kIntentPath, &href)) { |
1981 *error = ASCIIToUTF16(errors::kInvalidIntentHref); | 1981 *error = ASCIIToUTF16(errors::kInvalidIntentHref); |
1982 return false; | 1982 return false; |
1983 } | 1983 } |
1984 } | 1984 } |
1985 | 1985 |
1986 if (intent_service.HasKey(keys::kIntentHref)) { | 1986 if (intent_service.HasKey(keys::kIntentHref)) { |
1987 if (!href.empty()) { | 1987 if (!href.empty()) { |
1988 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 1988 *error = ErrorUtils::FormatErrorMessageUTF16( |
1989 errors::kInvalidIntentHrefOldAndNewKey, action_name, | 1989 errors::kInvalidIntentHrefOldAndNewKey, action_name, |
1990 keys::kIntentPath, keys::kIntentHref); | 1990 keys::kIntentPath, keys::kIntentHref); |
1991 return false; | 1991 return false; |
1992 } | 1992 } |
1993 if (!intent_service.GetString(keys::kIntentHref, &href)) { | 1993 if (!intent_service.GetString(keys::kIntentHref, &href)) { |
1994 *error = ASCIIToUTF16(errors::kInvalidIntentHref); | 1994 *error = ASCIIToUTF16(errors::kInvalidIntentHref); |
1995 return false; | 1995 return false; |
1996 } | 1996 } |
1997 } | 1997 } |
1998 | 1998 |
1999 // For packaged/hosted apps, empty href implies the respective launch URLs. | 1999 // For packaged/hosted apps, empty href implies the respective launch URLs. |
2000 if (href.empty()) { | 2000 if (href.empty()) { |
2001 if (is_hosted_app()) { | 2001 if (is_hosted_app()) { |
2002 href = launch_web_url(); | 2002 href = launch_web_url(); |
2003 } else if (is_legacy_packaged_app()) { | 2003 } else if (is_legacy_packaged_app()) { |
2004 href = launch_local_path(); | 2004 href = launch_local_path(); |
2005 } | 2005 } |
2006 } | 2006 } |
2007 | 2007 |
2008 // If there still is not an href, the manifest is malformed, unless this is a | 2008 // If there still is not an href, the manifest is malformed, unless this is a |
2009 // platform app in which case the href should not be present. | 2009 // platform app in which case the href should not be present. |
2010 if (href.empty() && !is_platform_app()) { | 2010 if (href.empty() && !is_platform_app()) { |
2011 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2011 *error = ErrorUtils::FormatErrorMessageUTF16( |
2012 errors::kInvalidIntentHrefEmpty, action_name); | 2012 errors::kInvalidIntentHrefEmpty, action_name); |
2013 return false; | 2013 return false; |
2014 } else if (!href.empty() && is_platform_app()) { | 2014 } else if (!href.empty() && is_platform_app()) { |
2015 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2015 *error = ErrorUtils::FormatErrorMessageUTF16( |
2016 errors::kInvalidIntentHrefInPlatformApp, action_name); | 2016 errors::kInvalidIntentHrefInPlatformApp, action_name); |
2017 return false; | 2017 return false; |
2018 } | 2018 } |
2019 | 2019 |
2020 GURL service_url(href); | 2020 GURL service_url(href); |
2021 if (is_hosted_app()) { | 2021 if (is_hosted_app()) { |
2022 // Hosted apps require an absolute URL for intents. | 2022 // Hosted apps require an absolute URL for intents. |
2023 if (!service_url.is_valid() || | 2023 if (!service_url.is_valid() || |
2024 !(web_extent().MatchesURL(service_url))) { | 2024 !(web_extent().MatchesURL(service_url))) { |
2025 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2025 *error = ErrorUtils::FormatErrorMessageUTF16( |
2026 errors::kInvalidIntentPageInHostedApp, action_name); | 2026 errors::kInvalidIntentPageInHostedApp, action_name); |
2027 return false; | 2027 return false; |
2028 } | 2028 } |
2029 service.service_url = service_url; | 2029 service.service_url = service_url; |
2030 } else if (is_platform_app()) { | 2030 } else if (is_platform_app()) { |
2031 service.service_url = GetBackgroundURL(); | 2031 service.service_url = GetBackgroundURL(); |
2032 } else { | 2032 } else { |
2033 // We do not allow absolute intent URLs in non-hosted apps. | 2033 // We do not allow absolute intent URLs in non-hosted apps. |
2034 if (service_url.is_valid()) { | 2034 if (service_url.is_valid()) { |
2035 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2035 *error = ErrorUtils::FormatErrorMessageUTF16( |
2036 errors::kCannotAccessPage, href); | 2036 errors::kCannotAccessPage, href); |
2037 return false; | 2037 return false; |
2038 } | 2038 } |
2039 service.service_url = GetResourceURL(href); | 2039 service.service_url = GetResourceURL(href); |
2040 } | 2040 } |
2041 | 2041 |
2042 if (intent_service.HasKey(keys::kIntentTitle) && | 2042 if (intent_service.HasKey(keys::kIntentTitle) && |
2043 !intent_service.GetString(keys::kIntentTitle, &service.title)) { | 2043 !intent_service.GetString(keys::kIntentTitle, &service.title)) { |
2044 *error = ASCIIToUTF16(errors::kInvalidIntentTitle); | 2044 *error = ASCIIToUTF16(errors::kInvalidIntentTitle); |
2045 return false; | 2045 return false; |
2046 } | 2046 } |
2047 | 2047 |
2048 if (intent_service.HasKey(keys::kIntentDisposition)) { | 2048 if (intent_service.HasKey(keys::kIntentDisposition)) { |
2049 if (is_platform_app()) { | 2049 if (is_platform_app()) { |
2050 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2050 *error = ErrorUtils::FormatErrorMessageUTF16( |
2051 errors::kInvalidIntentDispositionInPlatformApp, action_name); | 2051 errors::kInvalidIntentDispositionInPlatformApp, action_name); |
2052 return false; | 2052 return false; |
2053 } | 2053 } |
2054 if (!intent_service.GetString(keys::kIntentDisposition, &value) || | 2054 if (!intent_service.GetString(keys::kIntentDisposition, &value) || |
2055 (value != values::kIntentDispositionWindow && | 2055 (value != values::kIntentDispositionWindow && |
2056 value != values::kIntentDispositionInline)) { | 2056 value != values::kIntentDispositionInline)) { |
2057 *error = ASCIIToUTF16(errors::kInvalidIntentDisposition); | 2057 *error = ASCIIToUTF16(errors::kInvalidIntentDisposition); |
2058 return false; | 2058 return false; |
2059 } | 2059 } |
2060 if (value == values::kIntentDispositionInline) { | 2060 if (value == values::kIntentDispositionInline) { |
2061 service.disposition = | 2061 service.disposition = |
2062 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE; | 2062 webkit_glue::WebIntentServiceData::DISPOSITION_INLINE; |
2063 } else { | 2063 } else { |
2064 service.disposition = | 2064 service.disposition = |
2065 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; | 2065 webkit_glue::WebIntentServiceData::DISPOSITION_WINDOW; |
2066 } | 2066 } |
2067 } | 2067 } |
2068 | 2068 |
2069 for (size_t i = 0; i < mime_types->GetSize(); ++i) { | 2069 for (size_t i = 0; i < mime_types->GetSize(); ++i) { |
2070 if (!mime_types->GetString(i, &service.type)) { | 2070 if (!mime_types->GetString(i, &service.type)) { |
2071 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2071 *error = ErrorUtils::FormatErrorMessageUTF16( |
2072 errors::kInvalidIntentTypeElement, action_name, | 2072 errors::kInvalidIntentTypeElement, action_name, |
2073 std::string(base::IntToString(i))); | 2073 std::string(base::IntToString(i))); |
2074 return false; | 2074 return false; |
2075 } | 2075 } |
2076 intents_services_.push_back(service); | 2076 intents_services_.push_back(service); |
2077 } | 2077 } |
2078 return true; | 2078 return true; |
2079 } | 2079 } |
2080 | 2080 |
2081 bool Extension::LoadWebIntentServices(string16* error) { | 2081 bool Extension::LoadWebIntentServices(string16* error) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2127 webkit_glue::WebIntentServiceData service; | 2127 webkit_glue::WebIntentServiceData service; |
2128 | 2128 |
2129 // TODO(jeremya): use a file-handler-specific data structure instead of web | 2129 // TODO(jeremya): use a file-handler-specific data structure instead of web |
2130 // intents. | 2130 // intents. |
2131 service.action = ASCIIToUTF16("http://webintents.org/view"); | 2131 service.action = ASCIIToUTF16("http://webintents.org/view"); |
2132 | 2132 |
2133 const ListValue* mime_types = NULL; | 2133 const ListValue* mime_types = NULL; |
2134 if (!handler_info.HasKey(keys::kFileHandlerTypes) || | 2134 if (!handler_info.HasKey(keys::kFileHandlerTypes) || |
2135 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types) || | 2135 !handler_info.GetList(keys::kFileHandlerTypes, &mime_types) || |
2136 mime_types->GetSize() == 0) { | 2136 mime_types->GetSize() == 0) { |
2137 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2137 *error = ErrorUtils::FormatErrorMessageUTF16( |
2138 errors::kInvalidFileHandlerType, handler_id); | 2138 errors::kInvalidFileHandlerType, handler_id); |
2139 return false; | 2139 return false; |
2140 } | 2140 } |
2141 | 2141 |
2142 service.service_url = GetBackgroundURL(); | 2142 service.service_url = GetBackgroundURL(); |
2143 | 2143 |
2144 if (handler_info.HasKey(keys::kFileHandlerTitle) && | 2144 if (handler_info.HasKey(keys::kFileHandlerTitle) && |
2145 !handler_info.GetString(keys::kFileHandlerTitle, &service.title)) { | 2145 !handler_info.GetString(keys::kFileHandlerTitle, &service.title)) { |
2146 *error = ASCIIToUTF16(errors::kInvalidFileHandlerTitle); | 2146 *error = ASCIIToUTF16(errors::kInvalidFileHandlerTitle); |
2147 return false; | 2147 return false; |
2148 } | 2148 } |
2149 | 2149 |
2150 for (size_t i = 0; i < mime_types->GetSize(); ++i) { | 2150 for (size_t i = 0; i < mime_types->GetSize(); ++i) { |
2151 if (!mime_types->GetString(i, &service.type)) { | 2151 if (!mime_types->GetString(i, &service.type)) { |
2152 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2152 *error = ErrorUtils::FormatErrorMessageUTF16( |
2153 errors::kInvalidFileHandlerTypeElement, handler_id, | 2153 errors::kInvalidFileHandlerTypeElement, handler_id, |
2154 std::string(base::IntToString(i))); | 2154 std::string(base::IntToString(i))); |
2155 return false; | 2155 return false; |
2156 } | 2156 } |
2157 intents_services_.push_back(service); | 2157 intents_services_.push_back(service); |
2158 } | 2158 } |
2159 return true; | 2159 return true; |
2160 } | 2160 } |
2161 | 2161 |
2162 bool Extension::LoadFileHandlers(string16* error) { | 2162 bool Extension::LoadFileHandlers(string16* error) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 bool shortcut_ctrl = false; | 2245 bool shortcut_ctrl = false; |
2246 bool shortcut_shift = false; | 2246 bool shortcut_shift = false; |
2247 | 2247 |
2248 if (!list_value->GetDictionary(i, &module_value)) { | 2248 if (!list_value->GetDictionary(i, &module_value)) { |
2249 *error = ASCIIToUTF16(errors::kInvalidInputComponents); | 2249 *error = ASCIIToUTF16(errors::kInvalidInputComponents); |
2250 return false; | 2250 return false; |
2251 } | 2251 } |
2252 | 2252 |
2253 // Get input_components[i].name. | 2253 // Get input_components[i].name. |
2254 if (!module_value->GetString(keys::kName, &name_str)) { | 2254 if (!module_value->GetString(keys::kName, &name_str)) { |
2255 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2255 *error = ErrorUtils::FormatErrorMessageUTF16( |
2256 errors::kInvalidInputComponentName, base::IntToString(i)); | 2256 errors::kInvalidInputComponentName, base::IntToString(i)); |
2257 return false; | 2257 return false; |
2258 } | 2258 } |
2259 | 2259 |
2260 // Get input_components[i].type. | 2260 // Get input_components[i].type. |
2261 std::string type_str; | 2261 std::string type_str; |
2262 if (module_value->GetString(keys::kType, &type_str)) { | 2262 if (module_value->GetString(keys::kType, &type_str)) { |
2263 if (type_str == "ime") { | 2263 if (type_str == "ime") { |
2264 type = INPUT_COMPONENT_TYPE_IME; | 2264 type = INPUT_COMPONENT_TYPE_IME; |
2265 } else { | 2265 } else { |
2266 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2266 *error = ErrorUtils::FormatErrorMessageUTF16( |
2267 errors::kInvalidInputComponentType, base::IntToString(i)); | 2267 errors::kInvalidInputComponentType, base::IntToString(i)); |
2268 return false; | 2268 return false; |
2269 } | 2269 } |
2270 } else { | 2270 } else { |
2271 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2271 *error = ErrorUtils::FormatErrorMessageUTF16( |
2272 errors::kInvalidInputComponentType, base::IntToString(i)); | 2272 errors::kInvalidInputComponentType, base::IntToString(i)); |
2273 return false; | 2273 return false; |
2274 } | 2274 } |
2275 | 2275 |
2276 // Get input_components[i].id. | 2276 // Get input_components[i].id. |
2277 if (!module_value->GetString(keys::kId, &id_str)) { | 2277 if (!module_value->GetString(keys::kId, &id_str)) { |
2278 id_str = ""; | 2278 id_str = ""; |
2279 } | 2279 } |
2280 | 2280 |
2281 // Get input_components[i].description. | 2281 // Get input_components[i].description. |
2282 if (!module_value->GetString(keys::kDescription, &description_str)) { | 2282 if (!module_value->GetString(keys::kDescription, &description_str)) { |
2283 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2283 *error = ErrorUtils::FormatErrorMessageUTF16( |
2284 errors::kInvalidInputComponentDescription, base::IntToString(i)); | 2284 errors::kInvalidInputComponentDescription, base::IntToString(i)); |
2285 return false; | 2285 return false; |
2286 } | 2286 } |
2287 // Get input_components[i].language. | 2287 // Get input_components[i].language. |
2288 if (!module_value->GetString(keys::kLanguage, &language_str)) { | 2288 if (!module_value->GetString(keys::kLanguage, &language_str)) { |
2289 language_str = ""; | 2289 language_str = ""; |
2290 } | 2290 } |
2291 | 2291 |
2292 // Get input_components[i].layouts. | 2292 // Get input_components[i].layouts. |
2293 ListValue* layouts_value = NULL; | 2293 ListValue* layouts_value = NULL; |
2294 if (!module_value->GetList(keys::kLayouts, &layouts_value)) { | 2294 if (!module_value->GetList(keys::kLayouts, &layouts_value)) { |
2295 *error = ASCIIToUTF16(errors::kInvalidInputComponentLayouts); | 2295 *error = ASCIIToUTF16(errors::kInvalidInputComponentLayouts); |
2296 return false; | 2296 return false; |
2297 } | 2297 } |
2298 | 2298 |
2299 for (size_t j = 0; j < layouts_value->GetSize(); ++j) { | 2299 for (size_t j = 0; j < layouts_value->GetSize(); ++j) { |
2300 std::string layout_name_str; | 2300 std::string layout_name_str; |
2301 if (!layouts_value->GetString(j, &layout_name_str)) { | 2301 if (!layouts_value->GetString(j, &layout_name_str)) { |
2302 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2302 *error = ErrorUtils::FormatErrorMessageUTF16( |
2303 errors::kInvalidInputComponentLayoutName, base::IntToString(i), | 2303 errors::kInvalidInputComponentLayoutName, base::IntToString(i), |
2304 base::IntToString(j)); | 2304 base::IntToString(j)); |
2305 return false; | 2305 return false; |
2306 } | 2306 } |
2307 layouts.insert(layout_name_str); | 2307 layouts.insert(layout_name_str); |
2308 } | 2308 } |
2309 | 2309 |
2310 if (module_value->HasKey(keys::kShortcutKey)) { | 2310 if (module_value->HasKey(keys::kShortcutKey)) { |
2311 DictionaryValue* shortcut_value = NULL; | 2311 DictionaryValue* shortcut_value = NULL; |
2312 if (!module_value->GetDictionary(keys::kShortcutKey, &shortcut_value)) { | 2312 if (!module_value->GetDictionary(keys::kShortcutKey, &shortcut_value)) { |
2313 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2313 *error = ErrorUtils::FormatErrorMessageUTF16( |
2314 errors::kInvalidInputComponentShortcutKey, base::IntToString(i)); | 2314 errors::kInvalidInputComponentShortcutKey, base::IntToString(i)); |
2315 return false; | 2315 return false; |
2316 } | 2316 } |
2317 | 2317 |
2318 // Get input_components[i].shortcut_keycode. | 2318 // Get input_components[i].shortcut_keycode. |
2319 if (!shortcut_value->GetString(keys::kKeycode, &shortcut_keycode_str)) { | 2319 if (!shortcut_value->GetString(keys::kKeycode, &shortcut_keycode_str)) { |
2320 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2320 *error = ErrorUtils::FormatErrorMessageUTF16( |
2321 errors::kInvalidInputComponentShortcutKeycode, | 2321 errors::kInvalidInputComponentShortcutKeycode, |
2322 base::IntToString(i)); | 2322 base::IntToString(i)); |
2323 return false; | 2323 return false; |
2324 } | 2324 } |
2325 | 2325 |
2326 // Get input_components[i].shortcut_alt. | 2326 // Get input_components[i].shortcut_alt. |
2327 if (!shortcut_value->GetBoolean(keys::kAltKey, &shortcut_alt)) { | 2327 if (!shortcut_value->GetBoolean(keys::kAltKey, &shortcut_alt)) { |
2328 shortcut_alt = false; | 2328 shortcut_alt = false; |
2329 } | 2329 } |
2330 | 2330 |
(...skipping 29 matching lines...) Expand all Loading... |
2360 return true; | 2360 return true; |
2361 ListValue* list_value; | 2361 ListValue* list_value; |
2362 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { | 2362 if (!manifest_->GetList(keys::kContentScripts, &list_value)) { |
2363 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); | 2363 *error = ASCIIToUTF16(errors::kInvalidContentScriptsList); |
2364 return false; | 2364 return false; |
2365 } | 2365 } |
2366 | 2366 |
2367 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2367 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
2368 DictionaryValue* content_script = NULL; | 2368 DictionaryValue* content_script = NULL; |
2369 if (!list_value->GetDictionary(i, &content_script)) { | 2369 if (!list_value->GetDictionary(i, &content_script)) { |
2370 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2370 *error = ErrorUtils::FormatErrorMessageUTF16( |
2371 errors::kInvalidContentScript, base::IntToString(i)); | 2371 errors::kInvalidContentScript, base::IntToString(i)); |
2372 return false; | 2372 return false; |
2373 } | 2373 } |
2374 | 2374 |
2375 UserScript script; | 2375 UserScript script; |
2376 if (!LoadUserScriptHelper(content_script, i, error, &script)) | 2376 if (!LoadUserScriptHelper(content_script, i, error, &script)) |
2377 return false; // Failed to parse script context definition. | 2377 return false; // Failed to parse script context definition. |
2378 script.set_extension_id(id()); | 2378 script.set_extension_id(id()); |
2379 if (converted_from_user_script_) { | 2379 if (converted_from_user_script_) { |
2380 script.set_emulate_greasemonkey(true); | 2380 script.set_emulate_greasemonkey(true); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 if (!file_browser_handler->GetList(keys::kFileAccessList, | 2565 if (!file_browser_handler->GetList(keys::kFileAccessList, |
2566 &access_list_value) || | 2566 &access_list_value) || |
2567 access_list_value->empty()) { | 2567 access_list_value->empty()) { |
2568 *error = ASCIIToUTF16(errors::kInvalidFileAccessList); | 2568 *error = ASCIIToUTF16(errors::kInvalidFileAccessList); |
2569 return NULL; | 2569 return NULL; |
2570 } | 2570 } |
2571 for (size_t i = 0; i < access_list_value->GetSize(); ++i) { | 2571 for (size_t i = 0; i < access_list_value->GetSize(); ++i) { |
2572 std::string access; | 2572 std::string access; |
2573 if (!access_list_value->GetString(i, &access) || | 2573 if (!access_list_value->GetString(i, &access) || |
2574 result->AddFileAccessPermission(access)) { | 2574 result->AddFileAccessPermission(access)) { |
2575 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2575 *error = ErrorUtils::FormatErrorMessageUTF16( |
2576 errors::kInvalidFileAccessValue, base::IntToString(i)); | 2576 errors::kInvalidFileAccessValue, base::IntToString(i)); |
2577 return NULL; | 2577 return NULL; |
2578 } | 2578 } |
2579 } | 2579 } |
2580 } | 2580 } |
2581 if (!result->ValidateFileAccessPermissions()) { | 2581 if (!result->ValidateFileAccessPermissions()) { |
2582 *error = ASCIIToUTF16(errors::kInvalidFileAccessList); | 2582 *error = ASCIIToUTF16(errors::kInvalidFileAccessList); |
2583 return NULL; | 2583 return NULL; |
2584 } | 2584 } |
2585 | 2585 |
2586 // Initialize file filters (mandatory, unless "create" access is specified, | 2586 // Initialize file filters (mandatory, unless "create" access is specified, |
2587 // in which case is ignored). | 2587 // in which case is ignored). |
2588 if (!result->HasCreateAccessPermission()) { | 2588 if (!result->HasCreateAccessPermission()) { |
2589 const ListValue* list_value = NULL; | 2589 const ListValue* list_value = NULL; |
2590 if (!file_browser_handler->HasKey(keys::kFileFilters) || | 2590 if (!file_browser_handler->HasKey(keys::kFileFilters) || |
2591 !file_browser_handler->GetList(keys::kFileFilters, &list_value) || | 2591 !file_browser_handler->GetList(keys::kFileFilters, &list_value) || |
2592 list_value->empty()) { | 2592 list_value->empty()) { |
2593 *error = ASCIIToUTF16(errors::kInvalidFileFiltersList); | 2593 *error = ASCIIToUTF16(errors::kInvalidFileFiltersList); |
2594 return NULL; | 2594 return NULL; |
2595 } | 2595 } |
2596 for (size_t i = 0; i < list_value->GetSize(); ++i) { | 2596 for (size_t i = 0; i < list_value->GetSize(); ++i) { |
2597 std::string filter; | 2597 std::string filter; |
2598 if (!list_value->GetString(i, &filter)) { | 2598 if (!list_value->GetString(i, &filter)) { |
2599 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2599 *error = ErrorUtils::FormatErrorMessageUTF16( |
2600 errors::kInvalidFileFilterValue, base::IntToString(i)); | 2600 errors::kInvalidFileFilterValue, base::IntToString(i)); |
2601 return NULL; | 2601 return NULL; |
2602 } | 2602 } |
2603 StringToLowerASCII(&filter); | 2603 StringToLowerASCII(&filter); |
2604 if (!StartsWithASCII(filter, | 2604 if (!StartsWithASCII(filter, |
2605 std::string(chrome::kFileSystemScheme) + ':', | 2605 std::string(chrome::kFileSystemScheme) + ':', |
2606 true)) { | 2606 true)) { |
2607 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2607 *error = ErrorUtils::FormatErrorMessageUTF16( |
2608 errors::kInvalidURLPatternError, filter); | 2608 errors::kInvalidURLPatternError, filter); |
2609 return NULL; | 2609 return NULL; |
2610 } | 2610 } |
2611 // The user inputs filesystem:*; we don't actually implement scheme | 2611 // The user inputs filesystem:*; we don't actually implement scheme |
2612 // wildcards in URLPattern, so transform to what will match correctly. | 2612 // wildcards in URLPattern, so transform to what will match correctly. |
2613 filter.replace(0, 11, "chrome-extension://*/"); | 2613 filter.replace(0, 11, "chrome-extension://*/"); |
2614 URLPattern pattern(URLPattern::SCHEME_EXTENSION); | 2614 URLPattern pattern(URLPattern::SCHEME_EXTENSION); |
2615 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { | 2615 if (pattern.Parse(filter) != URLPattern::PARSE_SUCCESS) { |
2616 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2616 *error = ErrorUtils::FormatErrorMessageUTF16( |
2617 errors::kInvalidURLPatternError, filter); | 2617 errors::kInvalidURLPatternError, filter); |
2618 return NULL; | 2618 return NULL; |
2619 } | 2619 } |
2620 std::string path = pattern.path(); | 2620 std::string path = pattern.path(); |
2621 bool allowed = path == "/*" || path == "/*.*" || | 2621 bool allowed = path == "/*" || path == "/*.*" || |
2622 (path.compare(0, 3, "/*.") == 0 && | 2622 (path.compare(0, 3, "/*.") == 0 && |
2623 path.find_first_of('*', 3) == std::string::npos); | 2623 path.find_first_of('*', 3) == std::string::npos); |
2624 if (!allowed) { | 2624 if (!allowed) { |
2625 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2625 *error = ErrorUtils::FormatErrorMessageUTF16( |
2626 errors::kInvalidURLPatternError, filter); | 2626 errors::kInvalidURLPatternError, filter); |
2627 return NULL; | 2627 return NULL; |
2628 } | 2628 } |
2629 result->AddPattern(pattern); | 2629 result->AddPattern(pattern); |
2630 } | 2630 } |
2631 } | 2631 } |
2632 | 2632 |
2633 std::string default_icon; | 2633 std::string default_icon; |
2634 // Read the file browser action |default_icon| (optional). | 2634 // Read the file browser action |default_icon| (optional). |
2635 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) { | 2635 if (file_browser_handler->HasKey(keys::kPageActionDefaultIcon)) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2680 } | 2680 } |
2681 // Replace the entry with a fully qualified chrome-extension:// URL. | 2681 // Replace the entry with a fully qualified chrome-extension:// URL. |
2682 chrome_url_overrides_[page] = GetResourceURL(val); | 2682 chrome_url_overrides_[page] = GetResourceURL(val); |
2683 | 2683 |
2684 // For component extensions, add override URL to extent patterns. | 2684 // For component extensions, add override URL to extent patterns. |
2685 if (is_legacy_packaged_app() && location() == COMPONENT) { | 2685 if (is_legacy_packaged_app() && location() == COMPONENT) { |
2686 URLPattern pattern(URLPattern::SCHEME_CHROMEUI); | 2686 URLPattern pattern(URLPattern::SCHEME_CHROMEUI); |
2687 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat, | 2687 std::string url = base::StringPrintf(kOverrideExtentUrlPatternFormat, |
2688 page.c_str()); | 2688 page.c_str()); |
2689 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { | 2689 if (pattern.Parse(url) != URLPattern::PARSE_SUCCESS) { |
2690 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2690 *error = ErrorUtils::FormatErrorMessageUTF16( |
2691 errors::kInvalidURLPatternError, url); | 2691 errors::kInvalidURLPatternError, url); |
2692 return false; | 2692 return false; |
2693 } | 2693 } |
2694 extent_.AddPattern(pattern); | 2694 extent_.AddPattern(pattern); |
2695 } | 2695 } |
2696 } | 2696 } |
2697 | 2697 |
2698 // An extension may override at most one page. | 2698 // An extension may override at most one page. |
2699 if (overrides->size() > 1) { | 2699 if (overrides->size() > 1) { |
2700 *error = ASCIIToUTF16(errors::kMultipleOverrides); | 2700 *error = ASCIIToUTF16(errors::kMultipleOverrides); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2873 | 2873 |
2874 if (tmp_isolation->GetType() != Value::TYPE_LIST) { | 2874 if (tmp_isolation->GetType() != Value::TYPE_LIST) { |
2875 *error = ASCIIToUTF16(errors::kInvalidIsolation); | 2875 *error = ASCIIToUTF16(errors::kInvalidIsolation); |
2876 return false; | 2876 return false; |
2877 } | 2877 } |
2878 | 2878 |
2879 ListValue* isolation_list = static_cast<ListValue*>(tmp_isolation); | 2879 ListValue* isolation_list = static_cast<ListValue*>(tmp_isolation); |
2880 for (size_t i = 0; i < isolation_list->GetSize(); ++i) { | 2880 for (size_t i = 0; i < isolation_list->GetSize(); ++i) { |
2881 std::string isolation_string; | 2881 std::string isolation_string; |
2882 if (!isolation_list->GetString(i, &isolation_string)) { | 2882 if (!isolation_list->GetString(i, &isolation_string)) { |
2883 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 2883 *error = ErrorUtils::FormatErrorMessageUTF16( |
2884 errors::kInvalidIsolationValue, | 2884 errors::kInvalidIsolationValue, |
2885 base::UintToString(i)); | 2885 base::UintToString(i)); |
2886 return false; | 2886 return false; |
2887 } | 2887 } |
2888 | 2888 |
2889 // Check for isolated storage. | 2889 // Check for isolated storage. |
2890 if (isolation_string == values::kIsolatedStorage) { | 2890 if (isolation_string == values::kIsolatedStorage) { |
2891 is_storage_isolated_ = true; | 2891 is_storage_isolated_ = true; |
2892 } else { | 2892 } else { |
2893 DLOG(WARNING) << "Did not recognize isolation type: " << isolation_string; | 2893 DLOG(WARNING) << "Did not recognize isolation type: " << isolation_string; |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3427 return path.empty() ? GURL() : GetResourceURL(path); | 3427 return path.empty() ? GURL() : GetResourceURL(path); |
3428 } | 3428 } |
3429 | 3429 |
3430 bool Extension::ParsePermissions(const char* key, | 3430 bool Extension::ParsePermissions(const char* key, |
3431 string16* error, | 3431 string16* error, |
3432 APIPermissionSet* api_permissions, | 3432 APIPermissionSet* api_permissions, |
3433 URLPatternSet* host_permissions) { | 3433 URLPatternSet* host_permissions) { |
3434 if (manifest_->HasKey(key)) { | 3434 if (manifest_->HasKey(key)) { |
3435 ListValue* permissions = NULL; | 3435 ListValue* permissions = NULL; |
3436 if (!manifest_->GetList(key, &permissions)) { | 3436 if (!manifest_->GetList(key, &permissions)) { |
3437 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3437 *error = ErrorUtils::FormatErrorMessageUTF16( |
3438 errors::kInvalidPermissions, ""); | 3438 errors::kInvalidPermissions, ""); |
3439 return false; | 3439 return false; |
3440 } | 3440 } |
3441 | 3441 |
3442 // NOTE: We need to get the APIPermission before we check if features | 3442 // NOTE: We need to get the APIPermission before we check if features |
3443 // associated with them are available because the feature system does not | 3443 // associated with them are available because the feature system does not |
3444 // know about aliases. | 3444 // know about aliases. |
3445 | 3445 |
3446 std::vector<std::string> host_data; | 3446 std::vector<std::string> host_data; |
3447 if (!APIPermissionSet::ParseFromJSON(permissions, api_permissions, | 3447 if (!APIPermissionSet::ParseFromJSON(permissions, api_permissions, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3498 | 3498 |
3499 for (std::vector<std::string>::const_iterator it = host_data.begin(); | 3499 for (std::vector<std::string>::const_iterator it = host_data.begin(); |
3500 it != host_data.end(); ++it) { | 3500 it != host_data.end(); ++it) { |
3501 const std::string& permission_str = *it; | 3501 const std::string& permission_str = *it; |
3502 | 3502 |
3503 // Check if it's a host pattern permission. | 3503 // Check if it's a host pattern permission. |
3504 URLPattern pattern = URLPattern(kAllowedSchemes); | 3504 URLPattern pattern = URLPattern(kAllowedSchemes); |
3505 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); | 3505 URLPattern::ParseResult parse_result = pattern.Parse(permission_str); |
3506 if (parse_result == URLPattern::PARSE_SUCCESS) { | 3506 if (parse_result == URLPattern::PARSE_SUCCESS) { |
3507 if (!CanSpecifyHostPermission(pattern, *api_permissions)) { | 3507 if (!CanSpecifyHostPermission(pattern, *api_permissions)) { |
3508 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 3508 *error = ErrorUtils::FormatErrorMessageUTF16( |
3509 errors::kInvalidPermissionScheme, permission_str); | 3509 errors::kInvalidPermissionScheme, permission_str); |
3510 return false; | 3510 return false; |
3511 } | 3511 } |
3512 | 3512 |
3513 // The path component is not used for host permissions, so we force it | 3513 // The path component is not used for host permissions, so we force it |
3514 // to match all paths. | 3514 // to match all paths. |
3515 pattern.SetPath("/*"); | 3515 pattern.SetPath("/*"); |
3516 | 3516 |
3517 if (pattern.MatchesScheme(chrome::kFileScheme) && | 3517 if (pattern.MatchesScheme(chrome::kFileScheme) && |
3518 !CanExecuteScriptEverywhere()) { | 3518 !CanExecuteScriptEverywhere()) { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3722 return script->MatchesURL(document_url); | 3722 return script->MatchesURL(document_url); |
3723 | 3723 |
3724 // Otherwise, see if this extension has permission to execute script | 3724 // Otherwise, see if this extension has permission to execute script |
3725 // programmatically on pages. | 3725 // programmatically on pages. |
3726 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( | 3726 if (runtime_data_.GetActivePermissions()->HasExplicitAccessToOrigin( |
3727 document_url)) { | 3727 document_url)) { |
3728 return true; | 3728 return true; |
3729 } | 3729 } |
3730 | 3730 |
3731 if (error) { | 3731 if (error) { |
3732 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 3732 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
3733 document_url.spec()); | 3733 document_url.spec()); |
3734 } | 3734 } |
3735 | 3735 |
3736 return false; | 3736 return false; |
3737 } | 3737 } |
3738 | 3738 |
3739 bool Extension::ShowConfigureContextMenus() const { | 3739 bool Extension::ShowConfigureContextMenus() const { |
3740 // Don't show context menu for component extensions. We might want to show | 3740 // Don't show context menu for component extensions. We might want to show |
3741 // options for component extension button but now there is no component | 3741 // options for component extension button but now there is no component |
3742 // extension with options. All other menu items like uninstall have | 3742 // extension with options. All other menu items like uninstall have |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3787 if (tab_permissions.get() && | 3787 if (tab_permissions.get() && |
3788 tab_permissions->explicit_hosts().MatchesSecurityOrigin(page_url)) { | 3788 tab_permissions->explicit_hosts().MatchesSecurityOrigin(page_url)) { |
3789 return true; | 3789 return true; |
3790 } | 3790 } |
3791 } | 3791 } |
3792 | 3792 |
3793 if (HasHostPermission(page_url) || page_url.GetOrigin() == url()) | 3793 if (HasHostPermission(page_url) || page_url.GetOrigin() == url()) |
3794 return true; | 3794 return true; |
3795 | 3795 |
3796 if (error) { | 3796 if (error) { |
3797 *error = ExtensionErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, | 3797 *error = ErrorUtils::FormatErrorMessage(errors::kCannotAccessPage, |
3798 page_url.spec()); | 3798 page_url.spec()); |
3799 } | 3799 } |
3800 return false; | 3800 return false; |
3801 } | 3801 } |
3802 | 3802 |
3803 bool Extension::UpdatesFromGallery() const { | 3803 bool Extension::UpdatesFromGallery() const { |
3804 return extension_urls::IsWebstoreUpdateUrl(update_url()); | 3804 return extension_urls::IsWebstoreUpdateUrl(update_url()); |
3805 } | 3805 } |
3806 | 3806 |
3807 bool Extension::OverlapsWithOrigin(const GURL& origin) const { | 3807 bool Extension::OverlapsWithOrigin(const GURL& origin) const { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4000 return false; | 4000 return false; |
4001 } | 4001 } |
4002 | 4002 |
4003 Version current_version(current_version_info.Version()); | 4003 Version current_version(current_version_info.Version()); |
4004 if (!current_version.IsValid()) { | 4004 if (!current_version.IsValid()) { |
4005 DCHECK(false); | 4005 DCHECK(false); |
4006 return false; | 4006 return false; |
4007 } | 4007 } |
4008 | 4008 |
4009 if (current_version.CompareTo(minimum_version) < 0) { | 4009 if (current_version.CompareTo(minimum_version) < 0) { |
4010 *error = ExtensionErrorUtils::FormatErrorMessageUTF16( | 4010 *error = ErrorUtils::FormatErrorMessageUTF16( |
4011 errors::kChromeVersionTooLow, | 4011 errors::kChromeVersionTooLow, |
4012 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), | 4012 l10n_util::GetStringUTF8(IDS_PRODUCT_NAME), |
4013 minimum_version_string); | 4013 minimum_version_string); |
4014 return false; | 4014 return false; |
4015 } | 4015 } |
4016 return true; | 4016 return true; |
4017 } | 4017 } |
4018 | 4018 |
4019 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const { | 4019 bool Extension::CheckPlatformAppFeatures(std::string* utf8_error) const { |
4020 if (!is_platform_app()) | 4020 if (!is_platform_app()) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4094 | 4094 |
4095 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 4095 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
4096 const Extension* extension, | 4096 const Extension* extension, |
4097 const PermissionSet* permissions, | 4097 const PermissionSet* permissions, |
4098 Reason reason) | 4098 Reason reason) |
4099 : reason(reason), | 4099 : reason(reason), |
4100 extension(extension), | 4100 extension(extension), |
4101 permissions(permissions) {} | 4101 permissions(permissions) {} |
4102 | 4102 |
4103 } // namespace extensions | 4103 } // namespace extensions |
OLD | NEW |