OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "chrome/common/extensions/extension_resource.h" | 34 #include "chrome/common/extensions/extension_resource.h" |
35 #include "chrome/common/extensions/feature_switch.h" | 35 #include "chrome/common/extensions/feature_switch.h" |
36 #include "chrome/common/extensions/features/base_feature_provider.h" | 36 #include "chrome/common/extensions/features/base_feature_provider.h" |
37 #include "chrome/common/extensions/features/feature.h" | 37 #include "chrome/common/extensions/features/feature.h" |
38 #include "chrome/common/extensions/manifest.h" | 38 #include "chrome/common/extensions/manifest.h" |
39 #include "chrome/common/extensions/manifest_handler.h" | 39 #include "chrome/common/extensions/manifest_handler.h" |
40 #include "chrome/common/extensions/manifest_handler_helpers.h" | 40 #include "chrome/common/extensions/manifest_handler_helpers.h" |
41 #include "chrome/common/extensions/manifest_url_handler.h" | 41 #include "chrome/common/extensions/manifest_url_handler.h" |
42 #include "chrome/common/extensions/permissions/permission_set.h" | 42 #include "chrome/common/extensions/permissions/permission_set.h" |
43 #include "chrome/common/extensions/permissions/permissions_info.h" | 43 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 44 #include "chrome/common/extensions/theme_handler.h" |
44 #include "chrome/common/extensions/user_script.h" | 45 #include "chrome/common/extensions/user_script.h" |
45 #include "chrome/common/url_constants.h" | 46 #include "chrome/common/url_constants.h" |
46 #include "crypto/sha2.h" | 47 #include "crypto/sha2.h" |
47 #include "extensions/common/constants.h" | 48 #include "extensions/common/constants.h" |
48 #include "extensions/common/error_utils.h" | 49 #include "extensions/common/error_utils.h" |
49 #include "extensions/common/url_pattern_set.h" | 50 #include "extensions/common/url_pattern_set.h" |
50 #include "googleurl/src/url_util.h" | 51 #include "googleurl/src/url_util.h" |
51 #include "grit/chromium_strings.h" | 52 #include "grit/chromium_strings.h" |
52 #include "grit/theme_resources.h" | 53 #include "grit/theme_resources.h" |
53 #include "third_party/skia/include/core/SkBitmap.h" | 54 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 891 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
891 // indicate that we're doing something wrong. | 892 // indicate that we're doing something wrong. |
892 | 893 |
893 // Extension icons. | 894 // Extension icons. |
894 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 895 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
895 iter != icons().map().end(); ++iter) { | 896 iter != icons().map().end(); ++iter) { |
896 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 897 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
897 } | 898 } |
898 | 899 |
899 // Theme images. | 900 // Theme images. |
900 DictionaryValue* theme_images = GetThemeImages(); | 901 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); |
901 if (theme_images) { | 902 if (theme_images) { |
902 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | 903 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
903 it.Advance()) { | 904 it.Advance()) { |
904 std::string val; | 905 std::string val; |
905 if (it.value().GetAsString(&val)) | 906 if (it.value().GetAsString(&val)) |
906 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); | 907 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); |
907 } | 908 } |
908 } | 909 } |
909 | 910 |
910 if (page_action_info() && !page_action_info()->default_icon.empty()) { | 911 if (page_action_info() && !page_action_info()->default_icon.empty()) { |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 | 1552 |
1552 if (!LoadAppIsolation(api_permissions, error)) | 1553 if (!LoadAppIsolation(api_permissions, error)) |
1553 return false; | 1554 return false; |
1554 | 1555 |
1555 if (!LoadSharedFeatures(api_permissions, error)) | 1556 if (!LoadSharedFeatures(api_permissions, error)) |
1556 return false; | 1557 return false; |
1557 | 1558 |
1558 if (!LoadExtensionFeatures(&api_permissions, error)) | 1559 if (!LoadExtensionFeatures(&api_permissions, error)) |
1559 return false; | 1560 return false; |
1560 | 1561 |
1561 if (!LoadThemeFeatures(error)) | |
1562 return false; | |
1563 | |
1564 if (!LoadManagedModeFeatures(error)) | 1562 if (!LoadManagedModeFeatures(error)) |
1565 return false; | 1563 return false; |
1566 | 1564 |
1567 if (HasMultipleUISurfaces()) { | 1565 if (HasMultipleUISurfaces()) { |
1568 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1566 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
1569 return false; | 1567 return false; |
1570 } | 1568 } |
1571 | 1569 |
1572 finished_parsing_manifest_ = true; | 1570 finished_parsing_manifest_ = true; |
1573 | 1571 |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2623 // TODO(abarth): Should we continue to let extensions override the | 2621 // TODO(abarth): Should we continue to let extensions override the |
2624 // default Content-Security-Policy? | 2622 // default Content-Security-Policy? |
2625 content_security_policy_ = is_platform_app() ? | 2623 content_security_policy_ = is_platform_app() ? |
2626 kDefaultPlatformAppContentSecurityPolicy : | 2624 kDefaultPlatformAppContentSecurityPolicy : |
2627 kDefaultContentSecurityPolicy; | 2625 kDefaultContentSecurityPolicy; |
2628 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); | 2626 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); |
2629 } | 2627 } |
2630 return true; | 2628 return true; |
2631 } | 2629 } |
2632 | 2630 |
2633 bool Extension::LoadThemeFeatures(string16* error) { | |
2634 if (!manifest_->HasKey(keys::kTheme)) | |
2635 return true; | |
2636 DictionaryValue* theme_value = NULL; | |
2637 if (!manifest_->GetDictionary(keys::kTheme, &theme_value)) { | |
2638 *error = ASCIIToUTF16(errors::kInvalidTheme); | |
2639 return false; | |
2640 } | |
2641 if (!LoadThemeImages(theme_value, error)) | |
2642 return false; | |
2643 if (!LoadThemeColors(theme_value, error)) | |
2644 return false; | |
2645 if (!LoadThemeTints(theme_value, error)) | |
2646 return false; | |
2647 if (!LoadThemeDisplayProperties(theme_value, error)) | |
2648 return false; | |
2649 | |
2650 return true; | |
2651 } | |
2652 | |
2653 bool Extension::LoadThemeImages(const DictionaryValue* theme_value, | |
2654 string16* error) { | |
2655 const DictionaryValue* images_value = NULL; | |
2656 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | |
2657 // Validate that the images are all strings | |
2658 for (DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); | |
2659 iter.Advance()) { | |
2660 std::string val; | |
2661 if (!iter.value().GetAsString(&val)) { | |
2662 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | |
2663 return false; | |
2664 } | |
2665 } | |
2666 theme_images_.reset(images_value->DeepCopy()); | |
2667 } | |
2668 return true; | |
2669 } | |
2670 | |
2671 bool Extension::LoadThemeColors(const DictionaryValue* theme_value, | |
2672 string16* error) { | |
2673 const DictionaryValue* colors_value = NULL; | |
2674 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { | |
2675 // Validate that the colors are RGB or RGBA lists | |
2676 for (DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); | |
2677 iter.Advance()) { | |
2678 const ListValue* color_list = NULL; | |
2679 double alpha = 0.0; | |
2680 int color = 0; | |
2681 // The color must be a list | |
2682 if (!iter.value().GetAsList(&color_list) || | |
2683 // And either 3 items (RGB) or 4 (RGBA) | |
2684 ((color_list->GetSize() != 3) && | |
2685 ((color_list->GetSize() != 4) || | |
2686 // For RGBA, the fourth item must be a real or int alpha value. | |
2687 // Note that GetDouble() can get an integer value. | |
2688 !color_list->GetDouble(3, &alpha))) || | |
2689 // For both RGB and RGBA, the first three items must be ints (R,G,B) | |
2690 !color_list->GetInteger(0, &color) || | |
2691 !color_list->GetInteger(1, &color) || | |
2692 !color_list->GetInteger(2, &color)) { | |
2693 *error = ASCIIToUTF16(errors::kInvalidThemeColors); | |
2694 return false; | |
2695 } | |
2696 } | |
2697 theme_colors_.reset(colors_value->DeepCopy()); | |
2698 } | |
2699 return true; | |
2700 } | |
2701 | |
2702 bool Extension::LoadThemeTints(const DictionaryValue* theme_value, | |
2703 string16* error) { | |
2704 const DictionaryValue* tints_value = NULL; | |
2705 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) | |
2706 return true; | |
2707 | |
2708 // Validate that the tints are all reals. | |
2709 for (DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); | |
2710 iter.Advance()) { | |
2711 const ListValue* tint_list = NULL; | |
2712 double v = 0.0; | |
2713 if (!iter.value().GetAsList(&tint_list) || | |
2714 tint_list->GetSize() != 3 || | |
2715 !tint_list->GetDouble(0, &v) || | |
2716 !tint_list->GetDouble(1, &v) || | |
2717 !tint_list->GetDouble(2, &v)) { | |
2718 *error = ASCIIToUTF16(errors::kInvalidThemeTints); | |
2719 return false; | |
2720 } | |
2721 } | |
2722 theme_tints_.reset(tints_value->DeepCopy()); | |
2723 return true; | |
2724 } | |
2725 | |
2726 bool Extension::LoadThemeDisplayProperties(const DictionaryValue* theme_value, | |
2727 string16* error) { | |
2728 const DictionaryValue* display_properties_value = NULL; | |
2729 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | |
2730 &display_properties_value)) { | |
2731 theme_display_properties_.reset( | |
2732 display_properties_value->DeepCopy()); | |
2733 } | |
2734 return true; | |
2735 } | |
2736 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, | 2631 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, |
2737 const gfx::Size& max_size) const { | 2632 const gfx::Size& max_size) const { |
2738 const FilePath& path = source.relative_path(); | 2633 const FilePath& path = source.relative_path(); |
2739 | 2634 |
2740 // Look for exact size match. | 2635 // Look for exact size match. |
2741 ImageCache::iterator i = image_cache_.find( | 2636 ImageCache::iterator i = image_cache_.find( |
2742 ImageCacheKey(path, SizeToString(max_size))); | 2637 ImageCacheKey(path, SizeToString(max_size))); |
2743 if (i != image_cache_.end()) | 2638 if (i != image_cache_.end()) |
2744 return &(i->second); | 2639 return &(i->second); |
2745 | 2640 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3214 | 3109 |
3215 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3110 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3216 const Extension* extension, | 3111 const Extension* extension, |
3217 const PermissionSet* permissions, | 3112 const PermissionSet* permissions, |
3218 Reason reason) | 3113 Reason reason) |
3219 : reason(reason), | 3114 : reason(reason), |
3220 extension(extension), | 3115 extension(extension), |
3221 permissions(permissions) {} | 3116 permissions(permissions) {} |
3222 | 3117 |
3223 } // namespace extensions | 3118 } // namespace extensions |
OLD | NEW |