| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 MessageLoop::current()->PostTask( | 58 MessageLoop::current()->PostTask( |
| 59 FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id)); | 59 FROM_HERE, base::Bind(&CloseBalloon, kNotificationPrefix + extension_id)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 class CrashNotificationDelegate : public NotificationDelegate { | 62 class CrashNotificationDelegate : public NotificationDelegate { |
| 63 public: | 63 public: |
| 64 CrashNotificationDelegate(Profile* profile, | 64 CrashNotificationDelegate(Profile* profile, |
| 65 const Extension* extension) | 65 const Extension* extension) |
| 66 : profile_(profile), | 66 : profile_(profile), |
| 67 is_hosted_app_(extension->is_hosted_app()), | 67 is_hosted_app_(extension->is_hosted_app()), |
| 68 is_platform_app_(extension->is_platform_app()), |
| 68 extension_id_(extension->id()) { | 69 extension_id_(extension->id()) { |
| 69 } | 70 } |
| 70 | 71 |
| 71 virtual void Display() OVERRIDE {} | 72 virtual void Display() OVERRIDE {} |
| 72 | 73 |
| 73 virtual void Error() OVERRIDE {} | 74 virtual void Error() OVERRIDE {} |
| 74 | 75 |
| 75 virtual void Close(bool by_user) OVERRIDE {} | 76 virtual void Close(bool by_user) OVERRIDE {} |
| 76 | 77 |
| 77 virtual void Click() OVERRIDE { | 78 virtual void Click() OVERRIDE { |
| 78 if (is_hosted_app_) { | 79 if (is_hosted_app_) { |
| 79 // There can be a race here: user clicks the balloon, and simultaneously | 80 // There can be a race here: user clicks the balloon, and simultaneously |
| 80 // reloads the sad tab for the app. So we check here to be safe before | 81 // reloads the sad tab for the app. So we check here to be safe before |
| 81 // loading the background page. | 82 // loading the background page. |
| 82 BackgroundContentsService* service = | 83 BackgroundContentsService* service = |
| 83 BackgroundContentsServiceFactory::GetForProfile(profile_); | 84 BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 84 if (!service->GetAppBackgroundContents(ASCIIToUTF16(extension_id_))) | 85 if (!service->GetAppBackgroundContents(ASCIIToUTF16(extension_id_))) |
| 85 service->LoadBackgroundContentsForExtension(profile_, extension_id_); | 86 service->LoadBackgroundContentsForExtension(profile_, extension_id_); |
| 87 } else if (is_platform_app_) { |
| 88 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 89 RestartExtension(extension_id_); |
| 86 } else { | 90 } else { |
| 87 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 91 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 88 ReloadExtension(extension_id_); | 92 ReloadExtension(extension_id_); |
| 89 } | 93 } |
| 90 | 94 |
| 91 // Closing the balloon here should be OK, but it causes a crash on Mac | 95 // Closing the balloon here should be OK, but it causes a crash on Mac |
| 92 // http://crbug.com/78167 | 96 // http://crbug.com/78167 |
| 93 ScheduleCloseBalloon(extension_id_); | 97 ScheduleCloseBalloon(extension_id_); |
| 94 } | 98 } |
| 95 | 99 |
| 96 virtual std::string id() const OVERRIDE { | 100 virtual std::string id() const OVERRIDE { |
| 97 return kNotificationPrefix + extension_id_; | 101 return kNotificationPrefix + extension_id_; |
| 98 } | 102 } |
| 99 | 103 |
| 100 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | 104 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
| 101 return NULL; | 105 return NULL; |
| 102 } | 106 } |
| 103 | 107 |
| 104 private: | 108 private: |
| 105 virtual ~CrashNotificationDelegate() {} | 109 virtual ~CrashNotificationDelegate() {} |
| 106 | 110 |
| 107 Profile* profile_; | 111 Profile* profile_; |
| 108 bool is_hosted_app_; | 112 bool is_hosted_app_; |
| 113 bool is_platform_app_; |
| 109 std::string extension_id_; | 114 std::string extension_id_; |
| 110 | 115 |
| 111 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); | 116 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); |
| 112 }; | 117 }; |
| 113 | 118 |
| 114 void ShowBalloon(const Extension* extension, Profile* profile) { | 119 void ShowBalloon(const Extension* extension, Profile* profile) { |
| 115 #if defined(ENABLE_NOTIFICATIONS) | 120 #if defined(ENABLE_NOTIFICATIONS) |
| 116 string16 title; // no notifiaction title | 121 string16 title; // no notifiaction title |
| 117 string16 message = l10n_util::GetStringFUTF16( | 122 string16 message = l10n_util::GetStringFUTF16( |
| 118 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : | 123 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 bool user_gesture, | 630 bool user_gesture, |
| 626 bool* was_blocked) { | 631 bool* was_blocked) { |
| 627 Browser* browser = chrome::FindLastActiveWithProfile( | 632 Browser* browser = chrome::FindLastActiveWithProfile( |
| 628 Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 633 Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
| 629 chrome::GetActiveDesktop()); | 634 chrome::GetActiveDesktop()); |
| 630 if (browser) { | 635 if (browser) { |
| 631 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 636 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 632 initial_pos, user_gesture, was_blocked); | 637 initial_pos, user_gesture, was_blocked); |
| 633 } | 638 } |
| 634 } | 639 } |
| OLD | NEW |