| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/background/background_contents_service.h" | 5 #include "chrome/browser/background/background_contents_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "apps/app_load_service.h" | 9 #include "apps/app_load_service.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "extensions/common/extension_icon_set.h" | 49 #include "extensions/common/extension_icon_set.h" |
| 50 #include "extensions/common/extension_set.h" | 50 #include "extensions/common/extension_set.h" |
| 51 #include "extensions/common/manifest_handlers/background_info.h" | 51 #include "extensions/common/manifest_handlers/background_info.h" |
| 52 #include "extensions/common/manifest_handlers/icons_handler.h" | 52 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 53 #include "extensions/common/one_shot_event.h" | 53 #include "extensions/common/one_shot_event.h" |
| 54 #include "extensions/grit/extensions_browser_resources.h" | 54 #include "extensions/grit/extensions_browser_resources.h" |
| 55 #include "ipc/ipc_message.h" | 55 #include "ipc/ipc_message.h" |
| 56 #include "ui/base/l10n/l10n_util.h" | 56 #include "ui/base/l10n/l10n_util.h" |
| 57 #include "ui/base/resource/resource_bundle.h" | 57 #include "ui/base/resource/resource_bundle.h" |
| 58 #include "ui/gfx/image/image.h" | 58 #include "ui/gfx/image/image.h" |
| 59 | |
| 60 #if defined(ENABLE_NOTIFICATIONS) | |
| 61 #include "ui/message_center/message_center.h" | 59 #include "ui/message_center/message_center.h" |
| 62 #include "ui/message_center/notification_types.h" | 60 #include "ui/message_center/notification_types.h" |
| 63 #include "ui/message_center/notifier_settings.h" | 61 #include "ui/message_center/notifier_settings.h" |
| 64 #endif | |
| 65 | 62 |
| 66 using content::SiteInstance; | 63 using content::SiteInstance; |
| 67 using content::WebContents; | 64 using content::WebContents; |
| 68 using extensions::BackgroundInfo; | 65 using extensions::BackgroundInfo; |
| 69 using extensions::Extension; | 66 using extensions::Extension; |
| 70 using extensions::UnloadedExtensionInfo; | 67 using extensions::UnloadedExtensionInfo; |
| 71 | 68 |
| 72 namespace { | 69 namespace { |
| 73 | 70 |
| 74 const char kNotificationPrefix[] = "app.background.crashed."; | 71 const char kNotificationPrefix[] = "app.background.crashed."; |
| 75 const char kNotifierId[] = "app.background.crashed"; | 72 const char kNotifierId[] = "app.background.crashed"; |
| 76 bool g_disable_close_balloon_for_testing = false; | 73 bool g_disable_close_balloon_for_testing = false; |
| 77 | 74 |
| 78 void CloseBalloon(const std::string& balloon_id, ProfileID profile_id) { | 75 void CloseBalloon(const std::string& balloon_id, ProfileID profile_id) { |
| 79 NotificationUIManager* notification_ui_manager = | 76 NotificationUIManager* notification_ui_manager = |
| 80 g_browser_process->notification_ui_manager(); | 77 g_browser_process->notification_ui_manager(); |
| 81 bool cancelled = notification_ui_manager->CancelById(balloon_id, profile_id); | 78 bool cancelled = notification_ui_manager->CancelById(balloon_id, profile_id); |
| 82 if (cancelled) { | 79 if (cancelled) { |
| 83 #if defined(ENABLE_NOTIFICATIONS) | |
| 84 // TODO(dewittj): Add this functionality to the notification UI manager's | 80 // TODO(dewittj): Add this functionality to the notification UI manager's |
| 85 // API. | 81 // API. |
| 86 g_browser_process->message_center()->SetVisibility( | 82 g_browser_process->message_center()->SetVisibility( |
| 87 message_center::VISIBILITY_TRANSIENT); | 83 message_center::VISIBILITY_TRANSIENT); |
| 88 #endif | |
| 89 } | 84 } |
| 90 } | 85 } |
| 91 | 86 |
| 92 // Closes the crash notification balloon for the app/extension with this id. | 87 // Closes the crash notification balloon for the app/extension with this id. |
| 93 void ScheduleCloseBalloon(const std::string& extension_id, Profile* profile) { | 88 void ScheduleCloseBalloon(const std::string& extension_id, Profile* profile) { |
| 94 if (g_disable_close_balloon_for_testing) | 89 if (g_disable_close_balloon_for_testing) |
| 95 return; | 90 return; |
| 96 base::ThreadTaskRunnerHandle::Get()->PostTask( | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 97 FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id, | 92 FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id, |
| 98 NotificationUIManager::GetProfileID(profile))); | 93 NotificationUIManager::GetProfileID(profile))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 ~CrashNotificationDelegate() override {} | 146 ~CrashNotificationDelegate() override {} |
| 152 | 147 |
| 153 Profile* profile_; | 148 Profile* profile_; |
| 154 bool is_hosted_app_; | 149 bool is_hosted_app_; |
| 155 bool is_platform_app_; | 150 bool is_platform_app_; |
| 156 std::string extension_id_; | 151 std::string extension_id_; |
| 157 | 152 |
| 158 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); | 153 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); |
| 159 }; | 154 }; |
| 160 | 155 |
| 161 #if defined(ENABLE_NOTIFICATIONS) | |
| 162 void NotificationImageReady( | 156 void NotificationImageReady( |
| 163 const std::string extension_name, | 157 const std::string extension_name, |
| 164 const base::string16 message, | 158 const base::string16 message, |
| 165 scoped_refptr<CrashNotificationDelegate> delegate, | 159 scoped_refptr<CrashNotificationDelegate> delegate, |
| 166 Profile* profile, | 160 Profile* profile, |
| 167 const gfx::Image& icon) { | 161 const gfx::Image& icon) { |
| 168 if (g_browser_process->IsShuttingDown()) | 162 if (g_browser_process->IsShuttingDown()) |
| 169 return; | 163 return; |
| 170 | 164 |
| 171 gfx::Image notification_icon(icon); | 165 gfx::Image notification_icon(icon); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 185 message_center::NotifierId::SYSTEM_COMPONENT, | 179 message_center::NotifierId::SYSTEM_COMPONENT, |
| 186 kNotifierId), | 180 kNotifierId), |
| 187 base::string16(), | 181 base::string16(), |
| 188 GURL("chrome://extension-crash"), | 182 GURL("chrome://extension-crash"), |
| 189 delegate->id(), | 183 delegate->id(), |
| 190 message_center::RichNotificationData(), | 184 message_center::RichNotificationData(), |
| 191 delegate.get()); | 185 delegate.get()); |
| 192 | 186 |
| 193 g_browser_process->notification_ui_manager()->Add(notification, profile); | 187 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 194 } | 188 } |
| 195 #endif | |
| 196 | 189 |
| 197 // Show a popup notification balloon with a crash message for a given app/ | 190 // Show a popup notification balloon with a crash message for a given app/ |
| 198 // extension. | 191 // extension. |
| 199 void ShowBalloon(const Extension* extension, Profile* profile) { | 192 void ShowBalloon(const Extension* extension, Profile* profile) { |
| 200 #if defined(ENABLE_NOTIFICATIONS) | |
| 201 const base::string16 message = l10n_util::GetStringFUTF16( | 193 const base::string16 message = l10n_util::GetStringFUTF16( |
| 202 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : | 194 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : |
| 203 IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, | 195 IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, |
| 204 base::UTF8ToUTF16(extension->name())); | 196 base::UTF8ToUTF16(extension->name())); |
| 205 extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_LARGE); | 197 extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_LARGE); |
| 206 extensions::ExtensionResource resource = | 198 extensions::ExtensionResource resource = |
| 207 extensions::IconsInfo::GetIconResource( | 199 extensions::IconsInfo::GetIconResource( |
| 208 extension, size, ExtensionIconSet::MATCH_SMALLER); | 200 extension, size, ExtensionIconSet::MATCH_SMALLER); |
| 209 // We can't just load the image in the Observe method below because, despite | 201 // We can't just load the image in the Observe method below because, despite |
| 210 // what this method is called, it may call the callback synchronously. | 202 // what this method is called, it may call the callback synchronously. |
| 211 // However, it's possible that the extension went away during the interim, | 203 // However, it's possible that the extension went away during the interim, |
| 212 // so we'll bind all the pertinent data here. | 204 // so we'll bind all the pertinent data here. |
| 213 extensions::ImageLoader::Get(profile)->LoadImageAsync( | 205 extensions::ImageLoader::Get(profile)->LoadImageAsync( |
| 214 extension, | 206 extension, |
| 215 resource, | 207 resource, |
| 216 gfx::Size(size, size), | 208 gfx::Size(size, size), |
| 217 base::Bind( | 209 base::Bind( |
| 218 &NotificationImageReady, | 210 &NotificationImageReady, |
| 219 extension->name(), | 211 extension->name(), |
| 220 message, | 212 message, |
| 221 make_scoped_refptr(new CrashNotificationDelegate(profile, extension)), | 213 make_scoped_refptr(new CrashNotificationDelegate(profile, extension)), |
| 222 profile)); | 214 profile)); |
| 223 #endif | |
| 224 } | 215 } |
| 225 | 216 |
| 226 void ReloadExtension(const std::string& extension_id, Profile* profile) { | 217 void ReloadExtension(const std::string& extension_id, Profile* profile) { |
| 227 if (g_browser_process->IsShuttingDown() || | 218 if (g_browser_process->IsShuttingDown() || |
| 228 !g_browser_process->profile_manager()->IsValidProfile(profile)) { | 219 !g_browser_process->profile_manager()->IsValidProfile(profile)) { |
| 229 return; | 220 return; |
| 230 } | 221 } |
| 231 | 222 |
| 232 extensions::ExtensionSystem* extension_system = | 223 extensions::ExtensionSystem* extension_system = |
| 233 extensions::ExtensionSystem::Get(profile); | 224 extensions::ExtensionSystem::Get(profile); |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 const gfx::Rect& initial_rect, | 848 const gfx::Rect& initial_rect, |
| 858 bool user_gesture, | 849 bool user_gesture, |
| 859 bool* was_blocked) { | 850 bool* was_blocked) { |
| 860 Browser* browser = chrome::FindLastActiveWithProfile( | 851 Browser* browser = chrome::FindLastActiveWithProfile( |
| 861 Profile::FromBrowserContext(new_contents->GetBrowserContext())); | 852 Profile::FromBrowserContext(new_contents->GetBrowserContext())); |
| 862 if (browser) { | 853 if (browser) { |
| 863 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 854 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 864 initial_rect, user_gesture, was_blocked); | 855 initial_rect, user_gesture, was_blocked); |
| 865 } | 856 } |
| 866 } | 857 } |
| OLD | NEW |