| 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/manifest_handlers/theme_handler.h" | 5 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "extensions/common/manifest.h" | 11 #include "extensions/common/manifest.h" |
| 12 #include "extensions/common/manifest_constants.h" | 12 #include "extensions/common/manifest_constants.h" |
| 13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 namespace keys = manifest_keys; | 18 namespace keys = manifest_keys; |
| 19 namespace errors = manifest_errors; | 19 namespace errors = manifest_errors; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 bool LoadImages(const base::DictionaryValue* theme_value, | 23 bool LoadImages(const base::DictionaryValue* theme_value, |
| 24 string16* error, | 24 base::string16* error, |
| 25 ThemeInfo* theme_info) { | 25 ThemeInfo* theme_info) { |
| 26 const base::DictionaryValue* images_value = NULL; | 26 const base::DictionaryValue* images_value = NULL; |
| 27 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | 27 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { |
| 28 // Validate that the images are all strings. | 28 // Validate that the images are all strings. |
| 29 for (base::DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); | 29 for (base::DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); |
| 30 iter.Advance()) { | 30 iter.Advance()) { |
| 31 // The value may be a dictionary of scales and files paths. | 31 // The value may be a dictionary of scales and files paths. |
| 32 // Or the value may be a file path, in which case a scale | 32 // Or the value may be a file path, in which case a scale |
| 33 // of 100% is assumed. | 33 // of 100% is assumed. |
| 34 if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { | 34 if (iter.value().IsType(base::Value::TYPE_DICTIONARY)) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | 49 *error = ASCIIToUTF16(errors::kInvalidThemeImages); |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 theme_info->theme_images_.reset(images_value->DeepCopy()); | 53 theme_info->theme_images_.reset(images_value->DeepCopy()); |
| 54 } | 54 } |
| 55 return true; | 55 return true; |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool LoadColors(const base::DictionaryValue* theme_value, | 58 bool LoadColors(const base::DictionaryValue* theme_value, |
| 59 string16* error, | 59 base::string16* error, |
| 60 ThemeInfo* theme_info) { | 60 ThemeInfo* theme_info) { |
| 61 const base::DictionaryValue* colors_value = NULL; | 61 const base::DictionaryValue* colors_value = NULL; |
| 62 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { | 62 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { |
| 63 // Validate that the colors are RGB or RGBA lists. | 63 // Validate that the colors are RGB or RGBA lists. |
| 64 for (base::DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); | 64 for (base::DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); |
| 65 iter.Advance()) { | 65 iter.Advance()) { |
| 66 const base::ListValue* color_list = NULL; | 66 const base::ListValue* color_list = NULL; |
| 67 double alpha = 0.0; | 67 double alpha = 0.0; |
| 68 int color = 0; | 68 int color = 0; |
| 69 // The color must be a list... | 69 // The color must be a list... |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 *error = ASCIIToUTF16(errors::kInvalidThemeColors); | 81 *error = ASCIIToUTF16(errors::kInvalidThemeColors); |
| 82 return false; | 82 return false; |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 theme_info->theme_colors_.reset(colors_value->DeepCopy()); | 85 theme_info->theme_colors_.reset(colors_value->DeepCopy()); |
| 86 } | 86 } |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool LoadTints(const base::DictionaryValue* theme_value, | 90 bool LoadTints(const base::DictionaryValue* theme_value, |
| 91 string16* error, | 91 base::string16* error, |
| 92 ThemeInfo* theme_info) { | 92 ThemeInfo* theme_info) { |
| 93 const base::DictionaryValue* tints_value = NULL; | 93 const base::DictionaryValue* tints_value = NULL; |
| 94 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) | 94 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) |
| 95 return true; | 95 return true; |
| 96 | 96 |
| 97 // Validate that the tints are all reals. | 97 // Validate that the tints are all reals. |
| 98 for (base::DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); | 98 for (base::DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); |
| 99 iter.Advance()) { | 99 iter.Advance()) { |
| 100 const base::ListValue* tint_list = NULL; | 100 const base::ListValue* tint_list = NULL; |
| 101 double v = 0.0; | 101 double v = 0.0; |
| 102 if (!iter.value().GetAsList(&tint_list) || | 102 if (!iter.value().GetAsList(&tint_list) || |
| 103 tint_list->GetSize() != 3 || | 103 tint_list->GetSize() != 3 || |
| 104 !tint_list->GetDouble(0, &v) || | 104 !tint_list->GetDouble(0, &v) || |
| 105 !tint_list->GetDouble(1, &v) || | 105 !tint_list->GetDouble(1, &v) || |
| 106 !tint_list->GetDouble(2, &v)) { | 106 !tint_list->GetDouble(2, &v)) { |
| 107 *error = ASCIIToUTF16(errors::kInvalidThemeTints); | 107 *error = ASCIIToUTF16(errors::kInvalidThemeTints); |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 theme_info->theme_tints_.reset(tints_value->DeepCopy()); | 111 theme_info->theme_tints_.reset(tints_value->DeepCopy()); |
| 112 return true; | 112 return true; |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool LoadDisplayProperties(const base::DictionaryValue* theme_value, | 115 bool LoadDisplayProperties(const base::DictionaryValue* theme_value, |
| 116 string16* error, | 116 base::string16* error, |
| 117 ThemeInfo* theme_info) { | 117 ThemeInfo* theme_info) { |
| 118 const base::DictionaryValue* display_properties_value = NULL; | 118 const base::DictionaryValue* display_properties_value = NULL; |
| 119 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | 119 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, |
| 120 &display_properties_value)) { | 120 &display_properties_value)) { |
| 121 theme_info->theme_display_properties_.reset( | 121 theme_info->theme_display_properties_.reset( |
| 122 display_properties_value->DeepCopy()); | 122 display_properties_value->DeepCopy()); |
| 123 } | 123 } |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 const ThemeInfo* theme_info = GetInfo(extension); | 160 const ThemeInfo* theme_info = GetInfo(extension); |
| 161 return theme_info ? theme_info->theme_display_properties_.get() : NULL; | 161 return theme_info ? theme_info->theme_display_properties_.get() : NULL; |
| 162 } | 162 } |
| 163 | 163 |
| 164 ThemeHandler::ThemeHandler() { | 164 ThemeHandler::ThemeHandler() { |
| 165 } | 165 } |
| 166 | 166 |
| 167 ThemeHandler::~ThemeHandler() { | 167 ThemeHandler::~ThemeHandler() { |
| 168 } | 168 } |
| 169 | 169 |
| 170 bool ThemeHandler::Parse(Extension* extension, string16* error) { | 170 bool ThemeHandler::Parse(Extension* extension, base::string16* error) { |
| 171 const base::DictionaryValue* theme_value = NULL; | 171 const base::DictionaryValue* theme_value = NULL; |
| 172 if (!extension->manifest()->GetDictionary(keys::kTheme, &theme_value)) { | 172 if (!extension->manifest()->GetDictionary(keys::kTheme, &theme_value)) { |
| 173 *error = ASCIIToUTF16(errors::kInvalidTheme); | 173 *error = ASCIIToUTF16(errors::kInvalidTheme); |
| 174 return false; | 174 return false; |
| 175 } | 175 } |
| 176 | 176 |
| 177 scoped_ptr<ThemeInfo> theme_info(new ThemeInfo); | 177 scoped_ptr<ThemeInfo> theme_info(new ThemeInfo); |
| 178 if (!LoadImages(theme_value, error, theme_info.get())) | 178 if (!LoadImages(theme_value, error, theme_info.get())) |
| 179 return false; | 179 return false; |
| 180 if (!LoadColors(theme_value, error, theme_info.get())) | 180 if (!LoadColors(theme_value, error, theme_info.get())) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 return true; | 215 return true; |
| 216 } | 216 } |
| 217 | 217 |
| 218 const std::vector<std::string> ThemeHandler::Keys() const { | 218 const std::vector<std::string> ThemeHandler::Keys() const { |
| 219 return SingleKey(keys::kTheme); | 219 return SingleKey(keys::kTheme); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace extensions | 222 } // namespace extensions |
| OLD | NEW |