diff options
author | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-27 00:26:27 +0000 |
---|---|---|
committer | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-27 00:26:27 +0000 |
commit | 50686c3b965d1a09c9c4f37ee08f7bb45714b304 (patch) | |
tree | 6fd93b4cf92b3a7362b84b3bbc10b5d6c78ed3db | |
parent | 11e618958e97c0c5ca6da15618753f7d225b2cac (diff) | |
download | chromium_src-50686c3b965d1a09c9c4f37ee08f7bb45714b304.zip chromium_src-50686c3b965d1a09c9c4f37ee08f7bb45714b304.tar.gz chromium_src-50686c3b965d1a09c9c4f37ee08f7bb45714b304.tar.bz2 |
Fetch extension icon for extension/app crashed notifications.
Since the switch to Rich (non-HTML) Notifications, this notification
has not been displayed with an icon because there is no longer a way
to render arbitrary URLs in notifications. This adds an ImageLoader
to grab the extension's icon from disk and passes a gfx::Image directly
to the notification.
BUG=233207
Review URL: https://chromiumcodereview.appspot.com/13890004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196898 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/background/background_contents_service.cc | 61 | ||||
-rw-r--r-- | chrome/browser/extensions/app_background_page_apitest.cc | 7 | ||||
-rw-r--r-- | chrome/browser/extensions/app_process_apitest.cc | 2 |
3 files changed, 61 insertions, 9 deletions
diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc index ac9cb00..605ae54 100644 --- a/chrome/browser/background/background_contents_service.cc +++ b/chrome/browser/background/background_contents_service.cc @@ -17,6 +17,7 @@ #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" +#include "chrome/browser/extensions/image_loader.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -38,8 +39,11 @@ #include "content/public/browser/site_instance.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" +#include "grit/theme_resources.h" #include "ipc/ipc_message.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" using content::SiteInstance; using content::WebContents; @@ -119,20 +123,59 @@ class CrashNotificationDelegate : public NotificationDelegate { DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); }; +#if defined(ENABLE_NOTIFICATIONS) +void NotificationImageReady( + const std::string extension_name, + const string16 message, + const GURL extension_url, + scoped_refptr<CrashNotificationDelegate> delegate, + Profile* profile, + const gfx::Image& icon) { + gfx::Image notification_icon(icon); + if (icon.IsEmpty()) { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + notification_icon = rb.GetImageNamed(IDR_EXTENSION_DEFAULT_ICON); + } + string16 title; // no notification title + DesktopNotificationService::AddIconNotification( + extension_url, + title, + message, + notification_icon, + string16(), + delegate, + profile); +} +#endif + void ShowBalloon(const Extension* extension, Profile* profile) { #if defined(ENABLE_NOTIFICATIONS) - string16 title; // no notifiaction title string16 message = l10n_util::GetStringFUTF16( - extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : - IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, + extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : + IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, UTF8ToUTF16(extension->name())); - GURL icon_url(extensions::IconsInfo::GetIconURL( + + extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_MEDIUM); + extensions::ExtensionResource resource = + extensions::IconsInfo::GetIconResource( + extension, size, ExtensionIconSet::MATCH_SMALLER); + scoped_refptr<CrashNotificationDelegate> delegate = + new CrashNotificationDelegate(profile, extension); + // We can't just load the image in the Observe method below because, despite + // what this method is called, it may call the callback synchronously. + // However, it's possible that the extension went away during the interim, + // so we'll bind all the pertinent data here. + extensions::ImageLoader::Get(profile)->LoadImageAsync( extension, - extension_misc::EXTENSION_ICON_SMALLISH, - ExtensionIconSet::MATCH_BIGGER)); - DesktopNotificationService::AddNotification( - extension->url(), title, message, icon_url, string16(), - new CrashNotificationDelegate(profile, extension), profile); + resource, + gfx::Size(size, size), + base::Bind( + &NotificationImageReady, + extension->name(), + message, + extension->url(), + delegate, + profile)); #endif } diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc index ec55fcf..4f1cbbc 100644 --- a/chrome/browser/extensions/app_background_page_apitest.cc +++ b/chrome/browser/extensions/app_background_page_apitest.cc @@ -186,6 +186,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) { ASSERT_TRUE( BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); + UnloadExtension(extension->id()); } IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { @@ -236,6 +237,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); EXPECT_EQ(0u, background_deleted_tracker.size()); + UnloadExtension(extension->id()); } IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { @@ -275,6 +277,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) << message_; + UnloadExtension(extension->id()); } IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { @@ -301,7 +304,9 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { base::FilePath app_dir; ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); ASSERT_TRUE(LoadExtension(app_dir)); + const Extension* extension = GetSingleLoadedExtension(); ASSERT_TRUE(RunExtensionTest("app_background_page/two_pages")) << message_; + UnloadExtension(extension->id()); } IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoPagesWithManifest) { @@ -332,8 +337,10 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoPagesWithManifest) { base::FilePath app_dir; ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); ASSERT_TRUE(LoadExtension(app_dir)); + const Extension* extension = GetSingleLoadedExtension(); ASSERT_TRUE(RunExtensionTest("app_background_page/two_with_manifest")) << message_; + UnloadExtension(extension->id()); } // Times out occasionally -- see crbug.com/108493 diff --git a/chrome/browser/extensions/app_process_apitest.cc b/chrome/browser/extensions/app_process_apitest.cc index 4b7f53f..952bf21 100644 --- a/chrome/browser/extensions/app_process_apitest.cc +++ b/chrome/browser/extensions/app_process_apitest.cc @@ -71,6 +71,7 @@ class AppApiTest : public ExtensionApiTest { ASSERT_TRUE(LoadExtension( test_data_dir_.AppendASCII(app_name))); + const Extension* extension = GetSingleLoadedExtension(); // Open two tabs in the app, one outside it. GURL base_url = GetTestBaseURL(app_name); @@ -119,6 +120,7 @@ class AppApiTest : public ExtensionApiTest { LOG(INFO) << "WindowOpenHelper 1."; OpenWindow(tab2, base_url.Resolve("path2/empty.html"), true, NULL); LOG(INFO) << "End of test."; + UnloadExtension(extension->id()); } }; |