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 11 matching lines...) Expand all Loading... |
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 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | 29 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and |
30 // SystemIndicator have been moved out of Extension. | 30 // SystemIndicator have been moved out of Extension. |
31 #include "chrome/common/extensions/api/extension_action/action_info.h" | 31 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 32 #include "chrome/common/extensions/api/themes/theme_handler.h" |
32 #include "chrome/common/extensions/csp_validator.h" | 33 #include "chrome/common/extensions/csp_validator.h" |
33 #include "chrome/common/extensions/extension_manifest_constants.h" | 34 #include "chrome/common/extensions/extension_manifest_constants.h" |
34 #include "chrome/common/extensions/extension_resource.h" | 35 #include "chrome/common/extensions/extension_resource.h" |
35 #include "chrome/common/extensions/feature_switch.h" | 36 #include "chrome/common/extensions/feature_switch.h" |
36 #include "chrome/common/extensions/features/base_feature_provider.h" | 37 #include "chrome/common/extensions/features/base_feature_provider.h" |
37 #include "chrome/common/extensions/features/feature.h" | 38 #include "chrome/common/extensions/features/feature.h" |
38 #include "chrome/common/extensions/manifest.h" | 39 #include "chrome/common/extensions/manifest.h" |
39 #include "chrome/common/extensions/manifest_handler.h" | 40 #include "chrome/common/extensions/manifest_handler.h" |
40 #include "chrome/common/extensions/manifest_handler_helpers.h" | 41 #include "chrome/common/extensions/manifest_handler_helpers.h" |
41 #include "chrome/common/extensions/manifest_url_handler.h" | 42 #include "chrome/common/extensions/manifest_url_handler.h" |
(...skipping 848 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 | 1557 |
1557 if (!LoadAppIsolation(api_permissions, error)) | 1558 if (!LoadAppIsolation(api_permissions, error)) |
1558 return false; | 1559 return false; |
1559 | 1560 |
1560 if (!LoadSharedFeatures(api_permissions, error)) | 1561 if (!LoadSharedFeatures(api_permissions, error)) |
1561 return false; | 1562 return false; |
1562 | 1563 |
1563 if (!LoadExtensionFeatures(&api_permissions, error)) | 1564 if (!LoadExtensionFeatures(&api_permissions, error)) |
1564 return false; | 1565 return false; |
1565 | 1566 |
1566 if (!LoadThemeFeatures(error)) | |
1567 return false; | |
1568 | |
1569 if (!LoadManagedModeFeatures(error)) | 1567 if (!LoadManagedModeFeatures(error)) |
1570 return false; | 1568 return false; |
1571 | 1569 |
1572 if (HasMultipleUISurfaces()) { | 1570 if (HasMultipleUISurfaces()) { |
1573 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1571 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
1574 return false; | 1572 return false; |
1575 } | 1573 } |
1576 | 1574 |
1577 finished_parsing_manifest_ = true; | 1575 finished_parsing_manifest_ = true; |
1578 | 1576 |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2537 // TODO(abarth): Should we continue to let extensions override the | 2535 // TODO(abarth): Should we continue to let extensions override the |
2538 // default Content-Security-Policy? | 2536 // default Content-Security-Policy? |
2539 content_security_policy_ = is_platform_app() ? | 2537 content_security_policy_ = is_platform_app() ? |
2540 kDefaultPlatformAppContentSecurityPolicy : | 2538 kDefaultPlatformAppContentSecurityPolicy : |
2541 kDefaultContentSecurityPolicy; | 2539 kDefaultContentSecurityPolicy; |
2542 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); | 2540 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); |
2543 } | 2541 } |
2544 return true; | 2542 return true; |
2545 } | 2543 } |
2546 | 2544 |
2547 bool Extension::LoadThemeFeatures(string16* error) { | |
2548 if (!manifest_->HasKey(keys::kTheme)) | |
2549 return true; | |
2550 DictionaryValue* theme_value = NULL; | |
2551 if (!manifest_->GetDictionary(keys::kTheme, &theme_value)) { | |
2552 *error = ASCIIToUTF16(errors::kInvalidTheme); | |
2553 return false; | |
2554 } | |
2555 if (!LoadThemeImages(theme_value, error)) | |
2556 return false; | |
2557 if (!LoadThemeColors(theme_value, error)) | |
2558 return false; | |
2559 if (!LoadThemeTints(theme_value, error)) | |
2560 return false; | |
2561 if (!LoadThemeDisplayProperties(theme_value, error)) | |
2562 return false; | |
2563 | |
2564 return true; | |
2565 } | |
2566 | |
2567 bool Extension::LoadThemeImages(const DictionaryValue* theme_value, | |
2568 string16* error) { | |
2569 const DictionaryValue* images_value = NULL; | |
2570 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | |
2571 // Validate that the images are all strings | |
2572 for (DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); | |
2573 iter.Advance()) { | |
2574 std::string val; | |
2575 if (!iter.value().GetAsString(&val)) { | |
2576 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | |
2577 return false; | |
2578 } | |
2579 } | |
2580 theme_images_.reset(images_value->DeepCopy()); | |
2581 } | |
2582 return true; | |
2583 } | |
2584 | |
2585 bool Extension::LoadThemeColors(const DictionaryValue* theme_value, | |
2586 string16* error) { | |
2587 const DictionaryValue* colors_value = NULL; | |
2588 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { | |
2589 // Validate that the colors are RGB or RGBA lists | |
2590 for (DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); | |
2591 iter.Advance()) { | |
2592 const ListValue* color_list = NULL; | |
2593 double alpha = 0.0; | |
2594 int color = 0; | |
2595 // The color must be a list | |
2596 if (!iter.value().GetAsList(&color_list) || | |
2597 // And either 3 items (RGB) or 4 (RGBA) | |
2598 ((color_list->GetSize() != 3) && | |
2599 ((color_list->GetSize() != 4) || | |
2600 // For RGBA, the fourth item must be a real or int alpha value. | |
2601 // Note that GetDouble() can get an integer value. | |
2602 !color_list->GetDouble(3, &alpha))) || | |
2603 // For both RGB and RGBA, the first three items must be ints (R,G,B) | |
2604 !color_list->GetInteger(0, &color) || | |
2605 !color_list->GetInteger(1, &color) || | |
2606 !color_list->GetInteger(2, &color)) { | |
2607 *error = ASCIIToUTF16(errors::kInvalidThemeColors); | |
2608 return false; | |
2609 } | |
2610 } | |
2611 theme_colors_.reset(colors_value->DeepCopy()); | |
2612 } | |
2613 return true; | |
2614 } | |
2615 | |
2616 bool Extension::LoadThemeTints(const DictionaryValue* theme_value, | |
2617 string16* error) { | |
2618 const DictionaryValue* tints_value = NULL; | |
2619 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) | |
2620 return true; | |
2621 | |
2622 // Validate that the tints are all reals. | |
2623 for (DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); | |
2624 iter.Advance()) { | |
2625 const ListValue* tint_list = NULL; | |
2626 double v = 0.0; | |
2627 if (!iter.value().GetAsList(&tint_list) || | |
2628 tint_list->GetSize() != 3 || | |
2629 !tint_list->GetDouble(0, &v) || | |
2630 !tint_list->GetDouble(1, &v) || | |
2631 !tint_list->GetDouble(2, &v)) { | |
2632 *error = ASCIIToUTF16(errors::kInvalidThemeTints); | |
2633 return false; | |
2634 } | |
2635 } | |
2636 theme_tints_.reset(tints_value->DeepCopy()); | |
2637 return true; | |
2638 } | |
2639 | |
2640 bool Extension::LoadThemeDisplayProperties(const DictionaryValue* theme_value, | |
2641 string16* error) { | |
2642 const DictionaryValue* display_properties_value = NULL; | |
2643 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | |
2644 &display_properties_value)) { | |
2645 theme_display_properties_.reset( | |
2646 display_properties_value->DeepCopy()); | |
2647 } | |
2648 return true; | |
2649 } | |
2650 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, | 2545 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, |
2651 const gfx::Size& max_size) const { | 2546 const gfx::Size& max_size) const { |
2652 const FilePath& path = source.relative_path(); | 2547 const FilePath& path = source.relative_path(); |
2653 | 2548 |
2654 // Look for exact size match. | 2549 // Look for exact size match. |
2655 ImageCache::iterator i = image_cache_.find( | 2550 ImageCache::iterator i = image_cache_.find( |
2656 ImageCacheKey(path, SizeToString(max_size))); | 2551 ImageCacheKey(path, SizeToString(max_size))); |
2657 if (i != image_cache_.end()) | 2552 if (i != image_cache_.end()) |
2658 return &(i->second); | 2553 return &(i->second); |
2659 | 2554 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3128 | 3023 |
3129 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 3024 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
3130 const Extension* extension, | 3025 const Extension* extension, |
3131 const PermissionSet* permissions, | 3026 const PermissionSet* permissions, |
3132 Reason reason) | 3027 Reason reason) |
3133 : reason(reason), | 3028 : reason(reason), |
3134 extension(extension), | 3029 extension(extension), |
3135 permissions(permissions) {} | 3030 permissions(permissions) {} |
3136 | 3031 |
3137 } // namespace extensions | 3032 } // namespace extensions |
OLD | NEW |