OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 path_ = path; | 753 path_ = path; |
754 #endif | 754 #endif |
755 } | 755 } |
756 | 756 |
757 ExtensionResource Extension::GetResource(const std::string& relative_path) { | 757 ExtensionResource Extension::GetResource(const std::string& relative_path) { |
758 #if defined(OS_POSIX) | 758 #if defined(OS_POSIX) |
759 FilePath relative_file_path(relative_path); | 759 FilePath relative_file_path(relative_path); |
760 #elif defined(OS_WIN) | 760 #elif defined(OS_WIN) |
761 FilePath relative_file_path(UTF8ToWide(relative_path)); | 761 FilePath relative_file_path(UTF8ToWide(relative_path)); |
762 #endif | 762 #endif |
763 return ExtensionResource(path(), relative_file_path); | 763 return ExtensionResource(id(), path(), relative_file_path); |
764 } | 764 } |
765 | 765 |
766 ExtensionResource Extension::GetResource(const FilePath& relative_file_path) { | 766 ExtensionResource Extension::GetResource(const FilePath& relative_file_path) { |
767 return ExtensionResource(path(), relative_file_path); | 767 return ExtensionResource(id(), path(), relative_file_path); |
768 } | 768 } |
769 | 769 |
770 // TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a | 770 // TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a |
771 // util class in base: | 771 // util class in base: |
772 // http://code.google.com/p/chromium/issues/detail?id=13572 | 772 // http://code.google.com/p/chromium/issues/detail?id=13572 |
773 bool Extension::ParsePEMKeyBytes(const std::string& input, | 773 bool Extension::ParsePEMKeyBytes(const std::string& input, |
774 std::string* output) { | 774 std::string* output) { |
775 DCHECK(output); | 775 DCHECK(output); |
776 if (!output) | 776 if (!output) |
777 return false; | 777 return false; |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 | 1577 |
1578 void Extension::SetBackgroundPageReady() { | 1578 void Extension::SetBackgroundPageReady() { |
1579 DCHECK(!background_url().is_empty()); | 1579 DCHECK(!background_url().is_empty()); |
1580 background_page_ready_ = true; | 1580 background_page_ready_ = true; |
1581 NotificationService::current()->Notify( | 1581 NotificationService::current()->Notify( |
1582 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, | 1582 NotificationType::EXTENSION_BACKGROUND_PAGE_READY, |
1583 Source<Extension>(this), | 1583 Source<Extension>(this), |
1584 NotificationService::NoDetails()); | 1584 NotificationService::NoDetails()); |
1585 } | 1585 } |
1586 | 1586 |
| 1587 static std::string SizeToString(const gfx::Size& max_size) { |
| 1588 return IntToString(max_size.width()) + "x" + IntToString(max_size.height()); |
| 1589 } |
| 1590 |
1587 void Extension::SetCachedImage(const ExtensionResource& source, | 1591 void Extension::SetCachedImage(const ExtensionResource& source, |
1588 const SkBitmap& image) { | 1592 const SkBitmap& image, |
| 1593 const gfx::Size& original_size) { |
1589 DCHECK(source.extension_root() == path()); // The resource must come from | 1594 DCHECK(source.extension_root() == path()); // The resource must come from |
1590 // this extension. | 1595 // this extension. |
1591 image_cache_[source.relative_path()] = image; | 1596 const FilePath& path = source.relative_path(); |
| 1597 gfx::Size actual_size(image.width(), image.height()); |
| 1598 if (actual_size == original_size) { |
| 1599 image_cache_[ImageCacheKey(path, std::string())] = image; |
| 1600 } else { |
| 1601 image_cache_[ImageCacheKey(path, SizeToString(actual_size))] = image; |
| 1602 } |
1592 } | 1603 } |
1593 | 1604 |
1594 bool Extension::HasCachedImage(const ExtensionResource& source) { | 1605 bool Extension::HasCachedImage(const ExtensionResource& source, |
| 1606 const gfx::Size& max_size) { |
1595 DCHECK(source.extension_root() == path()); // The resource must come from | 1607 DCHECK(source.extension_root() == path()); // The resource must come from |
1596 // this extension. | 1608 // this extension. |
1597 return image_cache_.find(source.relative_path()) != image_cache_.end(); | 1609 return GetCachedImageImpl(source, max_size) != NULL; |
1598 } | 1610 } |
1599 | 1611 |
1600 SkBitmap Extension::GetCachedImage(const ExtensionResource& source) { | 1612 SkBitmap Extension::GetCachedImage(const ExtensionResource& source, |
| 1613 const gfx::Size& max_size) { |
1601 DCHECK(source.extension_root() == path()); // The resource must come from | 1614 DCHECK(source.extension_root() == path()); // The resource must come from |
1602 // this extension. | 1615 // this extension. |
1603 ImageCache::iterator i = image_cache_.find(source.relative_path()); | 1616 SkBitmap* image = GetCachedImageImpl(source, max_size); |
1604 if (i == image_cache_.end()) | 1617 return image ? *image : SkBitmap(); |
1605 return SkBitmap(); | |
1606 return i->second; | |
1607 } | 1618 } |
1608 | 1619 |
| 1620 SkBitmap* Extension::GetCachedImageImpl(const ExtensionResource& source, |
| 1621 const gfx::Size& max_size) { |
| 1622 const FilePath& path = source.relative_path(); |
| 1623 |
| 1624 // Look for exact size match. |
| 1625 ImageCache::iterator i = image_cache_.find( |
| 1626 ImageCacheKey(path, SizeToString(max_size))); |
| 1627 if (i != image_cache_.end()) |
| 1628 return &(i->second); |
| 1629 |
| 1630 // If we have the original size version cached, return that if it's small |
| 1631 // enough. |
| 1632 i = image_cache_.find(ImageCacheKey(path, std::string())); |
| 1633 if (i != image_cache_.end()) { |
| 1634 SkBitmap& image = i->second; |
| 1635 if (image.width() <= max_size.width() && |
| 1636 image.height() <= max_size.height()) |
| 1637 return &(i->second); |
| 1638 } |
| 1639 |
| 1640 return NULL; |
| 1641 } |
| 1642 |
| 1643 |
1609 ExtensionResource Extension::GetIconPath(Icons icon) { | 1644 ExtensionResource Extension::GetIconPath(Icons icon) { |
1610 std::map<int, std::string>::const_iterator iter = icons_.find(icon); | 1645 std::map<int, std::string>::const_iterator iter = icons_.find(icon); |
1611 if (iter == icons_.end()) | 1646 if (iter == icons_.end()) |
1612 return ExtensionResource(); | 1647 return ExtensionResource(); |
1613 return GetResource(iter->second); | 1648 return GetResource(iter->second); |
1614 } | 1649 } |
1615 | 1650 |
1616 Extension::Icons Extension::GetIconPathAllowLargerSize( | 1651 Extension::Icons Extension::GetIconPathAllowLargerSize( |
1617 ExtensionResource* resource, Icons icon) { | 1652 ExtensionResource* resource, Icons icon) { |
1618 *resource = GetIconPath(icon); | 1653 *resource = GetIconPath(icon); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 } else { | 1741 } else { |
1707 return false; | 1742 return false; |
1708 } | 1743 } |
1709 } else { | 1744 } else { |
1710 return true; | 1745 return true; |
1711 } | 1746 } |
1712 } | 1747 } |
1713 } | 1748 } |
1714 return false; | 1749 return false; |
1715 } | 1750 } |
OLD | NEW |