Chromium Code Reviews| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Closing the crash notification balloon for the app/extension here should | 135 // Closing the crash notification balloon for the app/extension here should |
| 136 // be OK, but it causes a crash on Mac, see: http://crbug.com/78167 | 136 // be OK, but it causes a crash on Mac, see: http://crbug.com/78167 |
| 137 ScheduleCloseBalloon(copied_extension_id); | 137 ScheduleCloseBalloon(copied_extension_id); |
| 138 } | 138 } |
| 139 | 139 |
| 140 virtual bool HasClickedListener() OVERRIDE { return true; } | 140 virtual bool HasClickedListener() OVERRIDE { return true; } |
| 141 | 141 |
| 142 virtual std::string id() const OVERRIDE { | 142 virtual std::string id() const OVERRIDE { |
| 143 return kNotificationPrefix + extension_id_; | 143 return BackgroundContentsService::GetNotificationIdForExtension( |
| 144 extension_id_); | |
| 144 } | 145 } |
| 145 | 146 |
| 146 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { | 147 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { |
| 147 return NULL; | 148 return NULL; |
| 148 } | 149 } |
| 149 | 150 |
| 150 private: | 151 private: |
| 151 virtual ~CrashNotificationDelegate() {} | 152 virtual ~CrashNotificationDelegate() {} |
| 152 | 153 |
| 153 Profile* profile_; | 154 Profile* profile_; |
| 154 bool is_hosted_app_; | 155 bool is_hosted_app_; |
| 155 bool is_platform_app_; | 156 bool is_platform_app_; |
| 156 std::string extension_id_; | 157 std::string extension_id_; |
| 157 | 158 |
| 158 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); | 159 DISALLOW_COPY_AND_ASSIGN(CrashNotificationDelegate); |
| 159 }; | 160 }; |
| 160 | 161 |
| 161 #if defined(ENABLE_NOTIFICATIONS) | 162 #if defined(ENABLE_NOTIFICATIONS) |
| 162 void NotificationImageReady( | 163 void NotificationImageReady( |
| 163 const std::string extension_name, | 164 const std::string extension_name, |
| 164 const base::string16 message, | 165 const base::string16 message, |
| 165 scoped_refptr<CrashNotificationDelegate> delegate, | 166 scoped_refptr<CrashNotificationDelegate> delegate, |
| 166 Profile* profile, | 167 Profile* profile, |
| 167 const gfx::Image& icon) { | 168 const gfx::Image& icon) { |
| 168 gfx::Image notification_icon(icon); | 169 gfx::Image notification_icon(icon); |
| 169 if (icon.IsEmpty()) { | 170 if (notification_icon.IsEmpty()) { |
|
Andrew T Wilson (Slow)
2014/02/17 17:12:32
Why is this changing to use notification_icon inst
Jun Mukai
2014/02/17 19:48:43
suggestion from the other reviewer.
We created 'no
| |
| 170 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 171 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 171 notification_icon = rb.GetImageNamed(IDR_EXTENSION_DEFAULT_ICON); | 172 notification_icon = rb.GetImageNamed(IDR_EXTENSION_DEFAULT_ICON); |
| 172 } | 173 } |
| 173 | 174 |
| 174 // Origin URL must be different from the crashed extension to avoid the | 175 // Origin URL must be different from the crashed extension to avoid the |
| 175 // conflict. NotificationSystemObserver will cancel all notifications from | 176 // conflict. NotificationSystemObserver will cancel all notifications from |
| 176 // the same origin when NOTIFICATION_EXTENSION_UNLOADED. | 177 // the same origin when NOTIFICATION_EXTENSION_UNLOADED. |
| 177 // TODO(mukai, dewittj): remove this and switch to message center | 178 // TODO(mukai, dewittj): remove this and switch to message center |
| 178 // notifications. | 179 // notifications. |
| 179 DesktopNotificationService::AddIconNotification( | 180 DesktopNotificationService::AddIconNotification( |
| 180 GURL() /* empty origin */, | 181 GURL() /* empty origin */, |
| 181 base::string16(), | 182 base::string16(), |
| 182 message, | 183 message, |
| 183 icon, | 184 notification_icon, |
| 184 base::string16(), | 185 base::string16(), |
| 185 delegate.get(), | 186 delegate.get(), |
| 186 profile); | 187 profile); |
| 187 } | 188 } |
| 188 #endif | 189 #endif |
| 189 | 190 |
| 190 // Show a popup notification balloon with a crash message for a given app/ | |
| 191 // extension. | |
| 192 void ShowBalloon(const Extension* extension, Profile* profile) { | |
| 193 #if defined(ENABLE_NOTIFICATIONS) | |
| 194 const base::string16 message = l10n_util::GetStringFUTF16( | |
| 195 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : | |
| 196 IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, | |
| 197 base::UTF8ToUTF16(extension->name())); | |
| 198 extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_MEDIUM); | |
| 199 extensions::ExtensionResource resource = | |
| 200 extensions::IconsInfo::GetIconResource( | |
| 201 extension, size, ExtensionIconSet::MATCH_SMALLER); | |
| 202 // We can't just load the image in the Observe method below because, despite | |
| 203 // what this method is called, it may call the callback synchronously. | |
| 204 // However, it's possible that the extension went away during the interim, | |
| 205 // so we'll bind all the pertinent data here. | |
| 206 extensions::ImageLoader::Get(profile)->LoadImageAsync( | |
| 207 extension, | |
| 208 resource, | |
| 209 gfx::Size(size, size), | |
| 210 base::Bind( | |
| 211 &NotificationImageReady, | |
| 212 extension->name(), | |
| 213 message, | |
| 214 make_scoped_refptr(new CrashNotificationDelegate(profile, extension)), | |
| 215 profile)); | |
| 216 #endif | |
| 217 } | |
| 218 | |
| 219 void ReloadExtension(const std::string& extension_id, Profile* profile) { | 191 void ReloadExtension(const std::string& extension_id, Profile* profile) { |
| 220 if (g_browser_process->IsShuttingDown() || | 192 if (g_browser_process->IsShuttingDown() || |
| 221 !g_browser_process->profile_manager()->IsValidProfile(profile)) { | 193 !g_browser_process->profile_manager()->IsValidProfile(profile)) { |
| 222 return; | 194 return; |
| 223 } | 195 } |
| 224 extensions::ExtensionSystem* extension_system = | 196 extensions::ExtensionSystem* extension_system = |
| 225 extensions::ExtensionSystem::Get(profile); | 197 extensions::ExtensionSystem::Get(profile); |
| 226 if (!extension_system || !extension_system->extension_service()) | 198 if (!extension_system || !extension_system->extension_service()) |
| 227 return; | 199 return; |
| 228 if (!extension_system->extension_service()-> | 200 if (!extension_system->extension_service()-> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 DCHECK(contents_map_.empty()); | 245 DCHECK(contents_map_.empty()); |
| 274 } | 246 } |
| 275 | 247 |
| 276 // static | 248 // static |
| 277 void BackgroundContentsService:: | 249 void BackgroundContentsService:: |
| 278 SetRestartDelayForForceInstalledAppsAndExtensionsForTesting( | 250 SetRestartDelayForForceInstalledAppsAndExtensionsForTesting( |
| 279 int restart_delay_in_ms) { | 251 int restart_delay_in_ms) { |
| 280 restart_delay_in_ms_ = restart_delay_in_ms; | 252 restart_delay_in_ms_ = restart_delay_in_ms; |
| 281 } | 253 } |
| 282 | 254 |
| 255 // static | |
| 256 std::string BackgroundContentsService::GetNotificationIdForExtension( | |
| 257 const std::string& extension_id) { | |
| 258 return kNotificationPrefix + extension_id; | |
| 259 } | |
| 260 | |
| 261 // static | |
| 262 void BackgroundContentsService::ShowBalloon(const Extension* extension, | |
| 263 Profile* profile) { | |
| 264 #if defined(ENABLE_NOTIFICATIONS) | |
| 265 const base::string16 message = l10n_util::GetStringFUTF16( | |
| 266 extension->is_app() ? IDS_BACKGROUND_CRASHED_APP_BALLOON_MESSAGE : | |
| 267 IDS_BACKGROUND_CRASHED_EXTENSION_BALLOON_MESSAGE, | |
| 268 base::UTF8ToUTF16(extension->name())); | |
| 269 extension_misc::ExtensionIcons size(extension_misc::EXTENSION_ICON_MEDIUM); | |
| 270 extensions::ExtensionResource resource = | |
| 271 extensions::IconsInfo::GetIconResource( | |
| 272 extension, size, ExtensionIconSet::MATCH_SMALLER); | |
| 273 // We can't just load the image in the Observe method below because, despite | |
| 274 // what this method is called, it may call the callback synchronously. | |
| 275 // However, it's possible that the extension went away during the interim, | |
| 276 // so we'll bind all the pertinent data here. | |
| 277 extensions::ImageLoader::Get(profile)->LoadImageAsync( | |
| 278 extension, | |
| 279 resource, | |
| 280 gfx::Size(size, size), | |
| 281 base::Bind( | |
| 282 &NotificationImageReady, | |
| 283 extension->name(), | |
| 284 message, | |
| 285 make_scoped_refptr(new CrashNotificationDelegate(profile, extension)), | |
| 286 profile)); | |
| 287 #endif | |
| 288 } | |
| 289 | |
| 283 std::vector<BackgroundContents*> | 290 std::vector<BackgroundContents*> |
| 284 BackgroundContentsService::GetBackgroundContents() const | 291 BackgroundContentsService::GetBackgroundContents() const |
| 285 { | 292 { |
| 286 std::vector<BackgroundContents*> contents; | 293 std::vector<BackgroundContents*> contents; |
| 287 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); | 294 for (BackgroundContentsMap::const_iterator it = contents_map_.begin(); |
| 288 it != contents_map_.end(); ++it) | 295 it != contents_map_.end(); ++it) |
| 289 contents.push_back(it->second.contents); | 296 contents.push_back(it->second.contents); |
| 290 return contents; | 297 return contents; |
| 291 } | 298 } |
| 292 | 299 |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 bool user_gesture, | 773 bool user_gesture, |
| 767 bool* was_blocked) { | 774 bool* was_blocked) { |
| 768 Browser* browser = chrome::FindLastActiveWithProfile( | 775 Browser* browser = chrome::FindLastActiveWithProfile( |
| 769 Profile::FromBrowserContext(new_contents->GetBrowserContext()), | 776 Profile::FromBrowserContext(new_contents->GetBrowserContext()), |
| 770 chrome::GetActiveDesktop()); | 777 chrome::GetActiveDesktop()); |
| 771 if (browser) { | 778 if (browser) { |
| 772 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 779 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
| 773 initial_pos, user_gesture, was_blocked); | 780 initial_pos, user_gesture, was_blocked); |
| 774 } | 781 } |
| 775 } | 782 } |
| OLD | NEW |