| 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "base/version.h" | 23 #include "base/version.h" |
| 24 #include "chrome/common/chrome_constants.h" | 24 #include "chrome/common/chrome_constants.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/chrome_version_info.h" | 26 #include "chrome/common/chrome_version_info.h" |
| 27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and | 27 // TODO(rdevlin.cronin): Remove this once PageAction, BrowserAction, and |
| 28 // SystemIndicator have been moved out of Extension. | 28 // SystemIndicator have been moved out of Extension. |
| 29 #include "chrome/common/extensions/api/extension_action/action_info.h" | 29 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 30 #include "chrome/common/extensions/api/themes/theme_handler.h" |
| 30 #include "chrome/common/extensions/csp_validator.h" | 31 #include "chrome/common/extensions/csp_validator.h" |
| 31 #include "chrome/common/extensions/extension_manifest_constants.h" | 32 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 32 #include "chrome/common/extensions/extension_resource.h" | 33 #include "chrome/common/extensions/extension_resource.h" |
| 33 #include "chrome/common/extensions/feature_switch.h" | 34 #include "chrome/common/extensions/feature_switch.h" |
| 34 #include "chrome/common/extensions/features/base_feature_provider.h" | 35 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 35 #include "chrome/common/extensions/features/feature.h" | 36 #include "chrome/common/extensions/features/feature.h" |
| 36 #include "chrome/common/extensions/manifest.h" | 37 #include "chrome/common/extensions/manifest.h" |
| 37 #include "chrome/common/extensions/manifest_handler.h" | 38 #include "chrome/common/extensions/manifest_handler.h" |
| 38 #include "chrome/common/extensions/manifest_handler_helpers.h" | 39 #include "chrome/common/extensions/manifest_handler_helpers.h" |
| 39 #include "chrome/common/extensions/manifest_url_handler.h" | 40 #include "chrome/common/extensions/manifest_url_handler.h" |
| (...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| | 812 // TODO(viettrungluu): These |FilePath::FromWStringHack(UTF8ToWide())| |
| 812 // indicate that we're doing something wrong. | 813 // indicate that we're doing something wrong. |
| 813 | 814 |
| 814 // Extension icons. | 815 // Extension icons. |
| 815 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); | 816 for (ExtensionIconSet::IconMap::const_iterator iter = icons().map().begin(); |
| 816 iter != icons().map().end(); ++iter) { | 817 iter != icons().map().end(); ++iter) { |
| 817 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 818 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
| 818 } | 819 } |
| 819 | 820 |
| 820 // Theme images. | 821 // Theme images. |
| 821 DictionaryValue* theme_images = GetThemeImages(); | 822 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); |
| 822 if (theme_images) { | 823 if (theme_images) { |
| 823 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | 824 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
| 824 it.Advance()) { | 825 it.Advance()) { |
| 825 std::string val; | 826 std::string val; |
| 826 if (it.value().GetAsString(&val)) | 827 if (it.value().GetAsString(&val)) |
| 827 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); | 828 image_paths.insert(FilePath::FromWStringHack(UTF8ToWide(val))); |
| 828 } | 829 } |
| 829 } | 830 } |
| 830 | 831 |
| 831 if (page_action_info() && !page_action_info()->default_icon.empty()) { | 832 if (page_action_info() && !page_action_info()->default_icon.empty()) { |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 | 1478 |
| 1478 if (!LoadAppIsolation(api_permissions, error)) | 1479 if (!LoadAppIsolation(api_permissions, error)) |
| 1479 return false; | 1480 return false; |
| 1480 | 1481 |
| 1481 if (!LoadSharedFeatures(api_permissions, error)) | 1482 if (!LoadSharedFeatures(api_permissions, error)) |
| 1482 return false; | 1483 return false; |
| 1483 | 1484 |
| 1484 if (!LoadExtensionFeatures(&api_permissions, error)) | 1485 if (!LoadExtensionFeatures(&api_permissions, error)) |
| 1485 return false; | 1486 return false; |
| 1486 | 1487 |
| 1487 if (!LoadThemeFeatures(error)) | |
| 1488 return false; | |
| 1489 | |
| 1490 if (!LoadManagedModeFeatures(error)) | 1488 if (!LoadManagedModeFeatures(error)) |
| 1491 return false; | 1489 return false; |
| 1492 | 1490 |
| 1493 if (HasMultipleUISurfaces()) { | 1491 if (HasMultipleUISurfaces()) { |
| 1494 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1492 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
| 1495 return false; | 1493 return false; |
| 1496 } | 1494 } |
| 1497 | 1495 |
| 1498 finished_parsing_manifest_ = true; | 1496 finished_parsing_manifest_ = true; |
| 1499 | 1497 |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2445 // TODO(abarth): Should we continue to let extensions override the | 2443 // TODO(abarth): Should we continue to let extensions override the |
| 2446 // default Content-Security-Policy? | 2444 // default Content-Security-Policy? |
| 2447 content_security_policy_ = is_platform_app() ? | 2445 content_security_policy_ = is_platform_app() ? |
| 2448 kDefaultPlatformAppContentSecurityPolicy : | 2446 kDefaultPlatformAppContentSecurityPolicy : |
| 2449 kDefaultContentSecurityPolicy; | 2447 kDefaultContentSecurityPolicy; |
| 2450 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); | 2448 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); |
| 2451 } | 2449 } |
| 2452 return true; | 2450 return true; |
| 2453 } | 2451 } |
| 2454 | 2452 |
| 2455 bool Extension::LoadThemeFeatures(string16* error) { | |
| 2456 if (!manifest_->HasKey(keys::kTheme)) | |
| 2457 return true; | |
| 2458 DictionaryValue* theme_value = NULL; | |
| 2459 if (!manifest_->GetDictionary(keys::kTheme, &theme_value)) { | |
| 2460 *error = ASCIIToUTF16(errors::kInvalidTheme); | |
| 2461 return false; | |
| 2462 } | |
| 2463 if (!LoadThemeImages(theme_value, error)) | |
| 2464 return false; | |
| 2465 if (!LoadThemeColors(theme_value, error)) | |
| 2466 return false; | |
| 2467 if (!LoadThemeTints(theme_value, error)) | |
| 2468 return false; | |
| 2469 if (!LoadThemeDisplayProperties(theme_value, error)) | |
| 2470 return false; | |
| 2471 | |
| 2472 return true; | |
| 2473 } | |
| 2474 | |
| 2475 bool Extension::LoadThemeImages(const DictionaryValue* theme_value, | |
| 2476 string16* error) { | |
| 2477 const DictionaryValue* images_value = NULL; | |
| 2478 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | |
| 2479 // Validate that the images are all strings | |
| 2480 for (DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); | |
| 2481 iter.Advance()) { | |
| 2482 std::string val; | |
| 2483 if (!iter.value().GetAsString(&val)) { | |
| 2484 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | |
| 2485 return false; | |
| 2486 } | |
| 2487 } | |
| 2488 theme_images_.reset(images_value->DeepCopy()); | |
| 2489 } | |
| 2490 return true; | |
| 2491 } | |
| 2492 | |
| 2493 bool Extension::LoadThemeColors(const DictionaryValue* theme_value, | |
| 2494 string16* error) { | |
| 2495 const DictionaryValue* colors_value = NULL; | |
| 2496 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { | |
| 2497 // Validate that the colors are RGB or RGBA lists | |
| 2498 for (DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); | |
| 2499 iter.Advance()) { | |
| 2500 const ListValue* color_list = NULL; | |
| 2501 double alpha = 0.0; | |
| 2502 int color = 0; | |
| 2503 // The color must be a list | |
| 2504 if (!iter.value().GetAsList(&color_list) || | |
| 2505 // And either 3 items (RGB) or 4 (RGBA) | |
| 2506 ((color_list->GetSize() != 3) && | |
| 2507 ((color_list->GetSize() != 4) || | |
| 2508 // For RGBA, the fourth item must be a real or int alpha value. | |
| 2509 // Note that GetDouble() can get an integer value. | |
| 2510 !color_list->GetDouble(3, &alpha))) || | |
| 2511 // For both RGB and RGBA, the first three items must be ints (R,G,B) | |
| 2512 !color_list->GetInteger(0, &color) || | |
| 2513 !color_list->GetInteger(1, &color) || | |
| 2514 !color_list->GetInteger(2, &color)) { | |
| 2515 *error = ASCIIToUTF16(errors::kInvalidThemeColors); | |
| 2516 return false; | |
| 2517 } | |
| 2518 } | |
| 2519 theme_colors_.reset(colors_value->DeepCopy()); | |
| 2520 } | |
| 2521 return true; | |
| 2522 } | |
| 2523 | |
| 2524 bool Extension::LoadThemeTints(const DictionaryValue* theme_value, | |
| 2525 string16* error) { | |
| 2526 const DictionaryValue* tints_value = NULL; | |
| 2527 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) | |
| 2528 return true; | |
| 2529 | |
| 2530 // Validate that the tints are all reals. | |
| 2531 for (DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); | |
| 2532 iter.Advance()) { | |
| 2533 const ListValue* tint_list = NULL; | |
| 2534 double v = 0.0; | |
| 2535 if (!iter.value().GetAsList(&tint_list) || | |
| 2536 tint_list->GetSize() != 3 || | |
| 2537 !tint_list->GetDouble(0, &v) || | |
| 2538 !tint_list->GetDouble(1, &v) || | |
| 2539 !tint_list->GetDouble(2, &v)) { | |
| 2540 *error = ASCIIToUTF16(errors::kInvalidThemeTints); | |
| 2541 return false; | |
| 2542 } | |
| 2543 } | |
| 2544 theme_tints_.reset(tints_value->DeepCopy()); | |
| 2545 return true; | |
| 2546 } | |
| 2547 | |
| 2548 bool Extension::LoadThemeDisplayProperties(const DictionaryValue* theme_value, | |
| 2549 string16* error) { | |
| 2550 const DictionaryValue* display_properties_value = NULL; | |
| 2551 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | |
| 2552 &display_properties_value)) { | |
| 2553 theme_display_properties_.reset( | |
| 2554 display_properties_value->DeepCopy()); | |
| 2555 } | |
| 2556 return true; | |
| 2557 } | |
| 2558 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, | 2453 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, |
| 2559 const gfx::Size& max_size) const { | 2454 const gfx::Size& max_size) const { |
| 2560 const FilePath& path = source.relative_path(); | 2455 const FilePath& path = source.relative_path(); |
| 2561 | 2456 |
| 2562 // Look for exact size match. | 2457 // Look for exact size match. |
| 2563 ImageCache::iterator i = image_cache_.find( | 2458 ImageCache::iterator i = image_cache_.find( |
| 2564 ImageCacheKey(path, SizeToString(max_size))); | 2459 ImageCacheKey(path, SizeToString(max_size))); |
| 2565 if (i != image_cache_.end()) | 2460 if (i != image_cache_.end()) |
| 2566 return &(i->second); | 2461 return &(i->second); |
| 2567 | 2462 |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 | 2888 |
| 2994 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2889 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
| 2995 const Extension* extension, | 2890 const Extension* extension, |
| 2996 const PermissionSet* permissions, | 2891 const PermissionSet* permissions, |
| 2997 Reason reason) | 2892 Reason reason) |
| 2998 : reason(reason), | 2893 : reason(reason), |
| 2999 extension(extension), | 2894 extension(extension), |
| 3000 permissions(permissions) {} | 2895 permissions(permissions) {} |
| 3001 | 2896 |
| 3002 } // namespace extensions | 2897 } // namespace extensions |
| OLD | NEW |