| 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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 using content::SiteInstance; | 61 using content::SiteInstance; |
| 62 using content::WebContents; | 62 using content::WebContents; |
| 63 using extensions::BackgroundInfo; | 63 using extensions::BackgroundInfo; |
| 64 using extensions::Extension; | 64 using extensions::Extension; |
| 65 using extensions::UnloadedExtensionInfo; | 65 using extensions::UnloadedExtensionInfo; |
| 66 | 66 |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 const char kNotificationPrefix[] = "app.background.crashed."; | 69 const char kNotificationPrefix[] = "app.background.crashed."; |
| 70 bool g_disable_close_balloon_for_testing = false; |
| 70 | 71 |
| 71 void CloseBalloon(const std::string& balloon_id, ProfileID profile_id) { | 72 void CloseBalloon(const std::string& balloon_id, ProfileID profile_id) { |
| 72 NotificationUIManager* notification_ui_manager = | 73 NotificationUIManager* notification_ui_manager = |
| 73 g_browser_process->notification_ui_manager(); | 74 g_browser_process->notification_ui_manager(); |
| 74 bool cancelled = notification_ui_manager->CancelById(balloon_id, profile_id); | 75 bool cancelled = notification_ui_manager->CancelById(balloon_id, profile_id); |
| 75 if (cancelled) { | 76 if (cancelled) { |
| 76 #if defined(ENABLE_NOTIFICATIONS) | 77 #if defined(ENABLE_NOTIFICATIONS) |
| 77 // TODO(dewittj): Add this functionality to the notification UI manager's | 78 // TODO(dewittj): Add this functionality to the notification UI manager's |
| 78 // API. | 79 // API. |
| 79 g_browser_process->message_center()->SetVisibility( | 80 g_browser_process->message_center()->SetVisibility( |
| 80 message_center::VISIBILITY_TRANSIENT); | 81 message_center::VISIBILITY_TRANSIENT); |
| 81 #endif | 82 #endif |
| 82 } | 83 } |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Closes the crash notification balloon for the app/extension with this id. | 86 // Closes the crash notification balloon for the app/extension with this id. |
| 86 void ScheduleCloseBalloon(const std::string& extension_id, Profile* profile) { | 87 void ScheduleCloseBalloon(const std::string& extension_id, Profile* profile) { |
| 87 if (!base::MessageLoop::current()) // For unit_tests | 88 if (g_disable_close_balloon_for_testing) |
| 88 return; | 89 return; |
| 89 base::MessageLoop::current()->PostTask( | 90 base::MessageLoop::current()->PostTask( |
| 90 FROM_HERE, | 91 FROM_HERE, |
| 91 base::Bind(&CloseBalloon, | 92 base::Bind(&CloseBalloon, |
| 92 kNotificationPrefix + extension_id, | 93 kNotificationPrefix + extension_id, |
| 93 NotificationUIManager::GetProfileID(profile))); | 94 NotificationUIManager::GetProfileID(profile))); |
| 94 } | 95 } |
| 95 | 96 |
| 96 // Delegate for the app/extension crash notification balloon. Restarts the | 97 // Delegate for the app/extension crash notification balloon. Restarts the |
| 97 // app/extension when the balloon is clicked. | 98 // app/extension when the balloon is clicked. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 return kNotificationPrefix + extension_id; | 287 return kNotificationPrefix + extension_id; |
| 287 } | 288 } |
| 288 | 289 |
| 289 // static | 290 // static |
| 290 void BackgroundContentsService::ShowBalloonForTesting( | 291 void BackgroundContentsService::ShowBalloonForTesting( |
| 291 const extensions::Extension* extension, | 292 const extensions::Extension* extension, |
| 292 Profile* profile) { | 293 Profile* profile) { |
| 293 ShowBalloon(extension, profile); | 294 ShowBalloon(extension, profile); |
| 294 } | 295 } |
| 295 | 296 |
| 297 // static |
| 298 void BackgroundContentsService::DisableCloseBalloonForTesting( |
| 299 bool disable_close_balloon_for_testing) { |
| 300 g_disable_close_balloon_for_testing = disable_close_balloon_for_testing; |
| 301 } |
| 302 |
| 296 std::vector<BackgroundContents*> | 303 std::vector<BackgroundContents*> |
| 297 BackgroundContentsService::GetBackgroundContents() const | 304 BackgroundContentsService::GetBackgroundContents() const |
| 298 { | 305 { |
| 299 std::vector<BackgroundContents*> contents; | 306 std::vector<BackgroundContents*> contents; |
| 300 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); | 307 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); |
| 301 it != contents_map_.end(); ++it) | 308 it != contents_map_.end(); ++it) |
| 302 contents.push_back(it->second.contents); | 309 contents.push_back(it->second.contents); |
| 303 return contents; | 310 return contents; |
| 304 } | 311 } |
| 305 | 312 |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 bool user_gesture, | 779 bool user_gesture, |
| 773 bool* was_blocked) { | 780 bool* was_blocked) { |
| 774 Browser* browser = chrome::FindLastActiveWithProfile( | 781 Browser* browser = chrome::FindLastActiveWithProfile( |
| 775 Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 782 Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
| 776 chrome::GetActiveDesktop()); | 783 chrome::GetActiveDesktop()); |
| 777 if (browser) { | 784 if (browser) { |
| 778 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 785 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 779 initial_rect, user_gesture, was_blocked); | 786 initial_rect, user_gesture, was_blocked); |
| 780 } | 787 } |
| 781 } | 788 } |
| OLD | NEW |