summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 19:03:06 +0000
committerjstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-25 19:03:06 +0000
commit248075e81cfc2a529bcb54cd095f82baee313385 (patch)
tree6a219d201884754850a9c0d0d42725133aab424a
parent18752aca8f8f9de95a460a1783b3330539b8719a (diff)
downloadchromium_src-248075e81cfc2a529bcb54cd095f82baee313385.zip
chromium_src-248075e81cfc2a529bcb54cd095f82baee313385.tar.gz
chromium_src-248075e81cfc2a529bcb54cd095f82baee313385.tar.bz2
Fix crash when creating a desktop shortcut for apps with missing icons (use the default app icon instead).
BUG=79282 TEST=See bug. Review URL: http://codereview.chromium.org/7065037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86665 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc9
-rw-r--r--chrome/browser/ui/views/create_application_shortcut_view.cc10
-rw-r--r--chrome/browser/ui/webui/extension_icon_source.cc21
-rw-r--r--chrome/browser/ui/webui/extension_icon_source.h4
4 files changed, 25 insertions, 19 deletions
diff --git a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc
index d28e71a..7f2f728 100644
--- a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc
+++ b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
+#include "chrome/browser/ui/webui/extension_icon_source.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_resource.h"
#include "content/browser/browser_thread.h"
@@ -20,6 +21,7 @@
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/gtk_util.h"
@@ -324,10 +326,9 @@ CreateChromeApplicationShortcutsDialogGtk::
// Called by tracker_ when the app's icon is loaded.
void CreateChromeApplicationShortcutsDialogGtk::OnImageLoaded(
SkBitmap* image, const ExtensionResource& resource, int index) {
- if (image->isNull()) {
- NOTREACHED() << "Corrupt image in profile?";
- return;
- }
+ if (!image || image->isNull())
+ image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON);
+
shortcut_info_.favicon = *image;
CreateIconPixBuf(*image);
diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc
index 8f714ad..bcc4af4 100644
--- a/chrome/browser/ui/views/create_application_shortcut_view.cc
+++ b/chrome/browser/ui/views/create_application_shortcut_view.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/web_applications/web_app_ui.h"
+#include "chrome/browser/ui/webui/extension_icon_source.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_resource.h"
@@ -21,6 +22,7 @@
#include "content/browser/tab_contents/tab_contents_delegate.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+#include "grit/theme_resources.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_request.h"
#include "third_party/skia/include/core/SkRect.h"
@@ -520,11 +522,9 @@ CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {}
// Called by tracker_ when the app's icon is loaded.
void CreateChromeApplicationShortcutView::OnImageLoaded(
SkBitmap* image, const ExtensionResource& resource, int index) {
- if (image->isNull()) {
- NOTREACHED() << "Corrupt image in profile?";
- return;
- }
+ if (!image || image->isNull())
+ image = ExtensionIconSource::LoadImageByResourceId(IDR_APP_DEFAULT_ICON);
+
shortcut_info_.favicon = *image;
static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon);
}
-
diff --git a/chrome/browser/ui/webui/extension_icon_source.cc b/chrome/browser/ui/webui/extension_icon_source.cc
index 0e355b8..8981179 100644
--- a/chrome/browser/ui/webui/extension_icon_source.cc
+++ b/chrome/browser/ui/webui/extension_icon_source.cc
@@ -52,16 +52,6 @@ SkBitmap* ToBitmap(const unsigned char* data, size_t size) {
return decoded;
}
-SkBitmap* LoadImageByResourceId(int resource_id) {
- std::string contents = ResourceBundle::GetSharedInstance()
- .GetRawDataResource(resource_id).as_string();
-
- // Convert and return it.
- const unsigned char* data =
- reinterpret_cast<const unsigned char*>(contents.data());
- return ToBitmap(data, contents.length());
-}
-
} // namespace
@@ -100,6 +90,17 @@ GURL ExtensionIconSource::GetIconURL(const Extension* extension,
return icon_url;
}
+// static
+SkBitmap* ExtensionIconSource::LoadImageByResourceId(int resource_id) {
+ std::string contents = ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(resource_id).as_string();
+
+ // Convert and return it.
+ const unsigned char* data =
+ reinterpret_cast<const unsigned char*>(contents.data());
+ return ToBitmap(data, contents.length());
+}
+
std::string ExtensionIconSource::GetMimeType(const std::string&) const {
// We need to explicitly return a mime type, otherwise if the user tries to
// drag the image they get no extension.
diff --git a/chrome/browser/ui/webui/extension_icon_source.h b/chrome/browser/ui/webui/extension_icon_source.h
index 745be27..2d797c4 100644
--- a/chrome/browser/ui/webui/extension_icon_source.h
+++ b/chrome/browser/ui/webui/extension_icon_source.h
@@ -63,6 +63,10 @@ class ExtensionIconSource : public ChromeURLDataManager::DataSource,
ExtensionIconSet::MatchType match,
bool grayscale);
+ // A public utility function for accessing the bitmap of the image specified
+ // by |resource_id|.
+ static SkBitmap* LoadImageByResourceId(int resource_id);
+
// ChromeURLDataManager::DataSource
virtual std::string GetMimeType(const std::string&) const;