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_piece.h" | 17 #include "base/string_piece.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( | 818 image_paths.insert( |
818 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); | 819 base::FilePath::FromWStringHack(UTF8ToWide(iter->second))); |
819 } | 820 } |
820 | 821 |
821 // Theme images. | 822 // Theme images. |
822 DictionaryValue* theme_images = GetThemeImages(); | 823 DictionaryValue* theme_images = ThemeInfo::GetThemeImages(this); |
823 if (theme_images) { | 824 if (theme_images) { |
824 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); | 825 for (DictionaryValue::Iterator it(*theme_images); !it.IsAtEnd(); |
825 it.Advance()) { | 826 it.Advance()) { |
826 std::string val; | 827 std::string val; |
827 if (it.value().GetAsString(&val)) | 828 if (it.value().GetAsString(&val)) |
828 image_paths.insert(base::FilePath::FromWStringHack(UTF8ToWide(val))); | 829 image_paths.insert(base::FilePath::FromWStringHack(UTF8ToWide(val))); |
829 } | 830 } |
830 } | 831 } |
831 | 832 |
832 if (page_action_info() && !page_action_info()->default_icon.empty()) { | 833 if (page_action_info() && !page_action_info()->default_icon.empty()) { |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 | 1481 |
1481 if (!LoadAppIsolation(api_permissions, error)) | 1482 if (!LoadAppIsolation(api_permissions, error)) |
1482 return false; | 1483 return false; |
1483 | 1484 |
1484 if (!LoadSharedFeatures(api_permissions, error)) | 1485 if (!LoadSharedFeatures(api_permissions, error)) |
1485 return false; | 1486 return false; |
1486 | 1487 |
1487 if (!LoadExtensionFeatures(&api_permissions, error)) | 1488 if (!LoadExtensionFeatures(&api_permissions, error)) |
1488 return false; | 1489 return false; |
1489 | 1490 |
1490 if (!LoadThemeFeatures(error)) | |
1491 return false; | |
1492 | |
1493 if (!LoadManagedModeFeatures(error)) | 1491 if (!LoadManagedModeFeatures(error)) |
1494 return false; | 1492 return false; |
1495 | 1493 |
1496 if (HasMultipleUISurfaces()) { | 1494 if (HasMultipleUISurfaces()) { |
1497 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); | 1495 *error = ASCIIToUTF16(errors::kOneUISurfaceOnly); |
1498 return false; | 1496 return false; |
1499 } | 1497 } |
1500 | 1498 |
1501 finished_parsing_manifest_ = true; | 1499 finished_parsing_manifest_ = true; |
1502 | 1500 |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2449 // TODO(abarth): Should we continue to let extensions override the | 2447 // TODO(abarth): Should we continue to let extensions override the |
2450 // default Content-Security-Policy? | 2448 // default Content-Security-Policy? |
2451 content_security_policy_ = is_platform_app() ? | 2449 content_security_policy_ = is_platform_app() ? |
2452 kDefaultPlatformAppContentSecurityPolicy : | 2450 kDefaultPlatformAppContentSecurityPolicy : |
2453 kDefaultContentSecurityPolicy; | 2451 kDefaultContentSecurityPolicy; |
2454 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); | 2452 CHECK(ContentSecurityPolicyIsSecure(content_security_policy_, GetType())); |
2455 } | 2453 } |
2456 return true; | 2454 return true; |
2457 } | 2455 } |
2458 | 2456 |
2459 bool Extension::LoadThemeFeatures(string16* error) { | |
2460 if (!manifest_->HasKey(keys::kTheme)) | |
2461 return true; | |
2462 DictionaryValue* theme_value = NULL; | |
2463 if (!manifest_->GetDictionary(keys::kTheme, &theme_value)) { | |
2464 *error = ASCIIToUTF16(errors::kInvalidTheme); | |
2465 return false; | |
2466 } | |
2467 if (!LoadThemeImages(theme_value, error)) | |
2468 return false; | |
2469 if (!LoadThemeColors(theme_value, error)) | |
2470 return false; | |
2471 if (!LoadThemeTints(theme_value, error)) | |
2472 return false; | |
2473 if (!LoadThemeDisplayProperties(theme_value, error)) | |
2474 return false; | |
2475 | |
2476 return true; | |
2477 } | |
2478 | |
2479 bool Extension::LoadThemeImages(const DictionaryValue* theme_value, | |
2480 string16* error) { | |
2481 const DictionaryValue* images_value = NULL; | |
2482 if (theme_value->GetDictionary(keys::kThemeImages, &images_value)) { | |
2483 // Validate that the images are all strings | |
2484 for (DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); | |
2485 iter.Advance()) { | |
2486 std::string val; | |
2487 if (!iter.value().GetAsString(&val)) { | |
2488 *error = ASCIIToUTF16(errors::kInvalidThemeImages); | |
2489 return false; | |
2490 } | |
2491 } | |
2492 theme_images_.reset(images_value->DeepCopy()); | |
2493 } | |
2494 return true; | |
2495 } | |
2496 | |
2497 bool Extension::LoadThemeColors(const DictionaryValue* theme_value, | |
2498 string16* error) { | |
2499 const DictionaryValue* colors_value = NULL; | |
2500 if (theme_value->GetDictionary(keys::kThemeColors, &colors_value)) { | |
2501 // Validate that the colors are RGB or RGBA lists | |
2502 for (DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); | |
2503 iter.Advance()) { | |
2504 const ListValue* color_list = NULL; | |
2505 double alpha = 0.0; | |
2506 int color = 0; | |
2507 // The color must be a list | |
2508 if (!iter.value().GetAsList(&color_list) || | |
2509 // And either 3 items (RGB) or 4 (RGBA) | |
2510 ((color_list->GetSize() != 3) && | |
2511 ((color_list->GetSize() != 4) || | |
2512 // For RGBA, the fourth item must be a real or int alpha value. | |
2513 // Note that GetDouble() can get an integer value. | |
2514 !color_list->GetDouble(3, &alpha))) || | |
2515 // For both RGB and RGBA, the first three items must be ints (R,G,B) | |
2516 !color_list->GetInteger(0, &color) || | |
2517 !color_list->GetInteger(1, &color) || | |
2518 !color_list->GetInteger(2, &color)) { | |
2519 *error = ASCIIToUTF16(errors::kInvalidThemeColors); | |
2520 return false; | |
2521 } | |
2522 } | |
2523 theme_colors_.reset(colors_value->DeepCopy()); | |
2524 } | |
2525 return true; | |
2526 } | |
2527 | |
2528 bool Extension::LoadThemeTints(const DictionaryValue* theme_value, | |
2529 string16* error) { | |
2530 const DictionaryValue* tints_value = NULL; | |
2531 if (!theme_value->GetDictionary(keys::kThemeTints, &tints_value)) | |
2532 return true; | |
2533 | |
2534 // Validate that the tints are all reals. | |
2535 for (DictionaryValue::Iterator iter(*tints_value); !iter.IsAtEnd(); | |
2536 iter.Advance()) { | |
2537 const ListValue* tint_list = NULL; | |
2538 double v = 0.0; | |
2539 if (!iter.value().GetAsList(&tint_list) || | |
2540 tint_list->GetSize() != 3 || | |
2541 !tint_list->GetDouble(0, &v) || | |
2542 !tint_list->GetDouble(1, &v) || | |
2543 !tint_list->GetDouble(2, &v)) { | |
2544 *error = ASCIIToUTF16(errors::kInvalidThemeTints); | |
2545 return false; | |
2546 } | |
2547 } | |
2548 theme_tints_.reset(tints_value->DeepCopy()); | |
2549 return true; | |
2550 } | |
2551 | |
2552 bool Extension::LoadThemeDisplayProperties(const DictionaryValue* theme_value, | |
2553 string16* error) { | |
2554 const DictionaryValue* display_properties_value = NULL; | |
2555 if (theme_value->GetDictionary(keys::kThemeDisplayProperties, | |
2556 &display_properties_value)) { | |
2557 theme_display_properties_.reset( | |
2558 display_properties_value->DeepCopy()); | |
2559 } | |
2560 return true; | |
2561 } | |
2562 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, | 2457 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, |
2563 const gfx::Size& max_size) const { | 2458 const gfx::Size& max_size) const { |
2564 const base::FilePath& path = source.relative_path(); | 2459 const base::FilePath& path = source.relative_path(); |
2565 | 2460 |
2566 // Look for exact size match. | 2461 // Look for exact size match. |
2567 ImageCache::iterator i = image_cache_.find( | 2462 ImageCache::iterator i = image_cache_.find( |
2568 ImageCacheKey(path, SizeToString(max_size))); | 2463 ImageCacheKey(path, SizeToString(max_size))); |
2569 if (i != image_cache_.end()) | 2464 if (i != image_cache_.end()) |
2570 return &(i->second); | 2465 return &(i->second); |
2571 | 2466 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2997 | 2892 |
2998 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( | 2893 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo( |
2999 const Extension* extension, | 2894 const Extension* extension, |
3000 const PermissionSet* permissions, | 2895 const PermissionSet* permissions, |
3001 Reason reason) | 2896 Reason reason) |
3002 : reason(reason), | 2897 : reason(reason), |
3003 extension(extension), | 2898 extension(extension), |
3004 permissions(permissions) {} | 2899 permissions(permissions) {} |
3005 | 2900 |
3006 } // namespace extensions | 2901 } // namespace extensions |
OLD | NEW |