| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 class CrashNotificationDelegate : public NotificationDelegate { | 56 class CrashNotificationDelegate : public NotificationDelegate { |
| 57 public: | 57 public: |
| 58 CrashNotificationDelegate(Profile* profile, const Extension* extension) | 58 CrashNotificationDelegate(Profile* profile, const Extension* extension) |
| 59 : profile_(profile), | 59 : profile_(profile), |
| 60 is_hosted_app_(extension->is_hosted_app()), | 60 is_hosted_app_(extension->is_hosted_app()), |
| 61 extension_id_(extension->id()) { | 61 extension_id_(extension->id()) { |
| 62 } | 62 } |
| 63 | 63 |
| 64 ~CrashNotificationDelegate() { | |
| 65 } | |
| 66 | |
| 67 void Display() {} | 64 void Display() {} |
| 68 | 65 |
| 69 void Error() {} | 66 void Error() {} |
| 70 | 67 |
| 71 void Close(bool by_user) {} | 68 void Close(bool by_user) {} |
| 72 | 69 |
| 73 void Click() { | 70 void Click() { |
| 74 if (is_hosted_app_) { | 71 if (is_hosted_app_) { |
| 75 // There can be a race here: user clicks the balloon, and simultaneously | 72 // There can be a race here: user clicks the balloon, and simultaneously |
| 76 // reloads the sad tab for the app. So we check here to be safe before | 73 // reloads the sad tab for the app. So we check here to be safe before |
| 77 // loading the background page. | 74 // loading the background page. |
| 78 BackgroundContentsService* service = | 75 BackgroundContentsService* service = |
| 79 BackgroundContentsServiceFactory::GetForProfile(profile_); | 76 BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 80 if (!service->GetAppBackgroundContents(ASCIIToUTF16(extension_id_))) | 77 if (!service->GetAppBackgroundContents(ASCIIToUTF16(extension_id_))) |
| 81 service->LoadBackgroundContentsForExtension(profile_, extension_id_); | 78 service->LoadBackgroundContentsForExtension(profile_, extension_id_); |
| 82 } else { | 79 } else { |
| 83 profile_->GetExtensionService()->ReloadExtension(extension_id_); | 80 profile_->GetExtensionService()->ReloadExtension(extension_id_); |
| 84 } | 81 } |
| 85 | 82 |
| 86 // Closing the balloon here should be OK, but it causes a crash on Mac | 83 // Closing the balloon here should be OK, but it causes a crash on Mac |
| 87 // http://crbug.com/78167 | 84 // http://crbug.com/78167 |
| 88 ScheduleCloseBalloon(extension_id_); | 85 ScheduleCloseBalloon(extension_id_); |
| 89 } | 86 } |
| 90 | 87 |
| 91 std::string id() const { | 88 std::string id() const { |
| 92 return kNotificationPrefix + extension_id_; | 89 return kNotificationPrefix + extension_id_; |
| 93 } | 90 } |
| 94 | 91 |
| 95 private: | 92 private: |
| 93 virtual ~CrashNotificationDelegate() {} |
| 94 |
| 96 Profile* profile_; | 95 Profile* profile_; |
| 97 bool is_hosted_app_; | 96 bool is_hosted_app_; |
| 98 std::string extension_id_; | 97 std::string extension_id_; |
| 99 | 98 |
| 100 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); | 99 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 void ShowBalloon(const Extension* extension, Profile* profile) { | 102 void ShowBalloon(const Extension* extension, Profile* profile) { |
| 104 #if defined(ENABLE_NOTIFICATIONS) | 103 #if defined(ENABLE_NOTIFICATIONS) |
| 105 string16 message = l10n_util::GetStringFUTF16( | 104 string16 message = l10n_util::GetStringFUTF16( |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 WebContents* new_contents, | 575 WebContents* new_contents, |
| 577 WindowOpenDisposition disposition, | 576 WindowOpenDisposition disposition, |
| 578 const gfx::Rect& initial_pos, | 577 const gfx::Rect& initial_pos, |
| 579 bool user_gesture) { | 578 bool user_gesture) { |
| 580 Browser* browser = BrowserList::GetLastActiveWithProfile( | 579 Browser* browser = BrowserList::GetLastActiveWithProfile( |
| 581 Profile::FromBrowserContext(new_contents->GetBrowserContext())); | 580 Profile::FromBrowserContext(new_contents->GetBrowserContext())); |
| 582 if (!browser) | 581 if (!browser) |
| 583 return; | 582 return; |
| 584 browser->AddWebContents(new_contents, disposition, initial_pos, user_gesture); | 583 browser->AddWebContents(new_contents, disposition, initial_pos, user_gesture); |
| 585 } | 584 } |
| OLD | NEW |