| 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/notifications/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "grit/browser_resources.h" | 37 #include "grit/browser_resources.h" |
| 38 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
| 39 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 40 #include "grit/theme_resources.h" | 40 #include "grit/theme_resources.h" |
| 41 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
| 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 43 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/layout.h" | 44 #include "ui/base/layout.h" |
| 45 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 46 | 46 |
| 47 #if defined(USE_ASH) | |
| 48 #include "ash/ash_switches.h" | |
| 49 #include "base/command_line.h" | |
| 50 | |
| 51 namespace { | |
| 52 | |
| 53 bool IsAshNotifyEnabled() { | |
| 54 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 55 ash::switches::kAshNotifyDisabled); | |
| 56 } | |
| 57 | |
| 58 } // namespace | |
| 59 #endif | |
| 60 | |
| 61 using content::BrowserThread; | 47 using content::BrowserThread; |
| 62 using content::RenderViewHost; | 48 using content::RenderViewHost; |
| 63 using content::WebContents; | 49 using content::WebContents; |
| 64 using WebKit::WebNotificationPresenter; | 50 using WebKit::WebNotificationPresenter; |
| 65 using WebKit::WebTextDirection; | 51 using WebKit::WebTextDirection; |
| 66 using WebKit::WebSecurityOrigin; | 52 using WebKit::WebSecurityOrigin; |
| 67 | 53 |
| 68 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; | 54 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; |
| 69 | 55 |
| 70 // NotificationPermissionInfoBarDelegate -------------------------------------- | 56 // NotificationPermissionInfoBarDelegate -------------------------------------- |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // static | 221 // static |
| 236 std::string DesktopNotificationService::AddNotification( | 222 std::string DesktopNotificationService::AddNotification( |
| 237 const GURL& origin_url, | 223 const GURL& origin_url, |
| 238 const string16& title, | 224 const string16& title, |
| 239 const string16& message, | 225 const string16& message, |
| 240 const GURL& icon_url, | 226 const GURL& icon_url, |
| 241 const string16& replace_id, | 227 const string16& replace_id, |
| 242 NotificationDelegate* delegate, | 228 NotificationDelegate* delegate, |
| 243 Profile* profile) { | 229 Profile* profile) { |
| 244 #if defined(USE_ASH) | 230 #if defined(USE_ASH) |
| 245 if (IsAshNotifyEnabled()) { | 231 // For Ash create a non-HTML notification with |icon_url|. |
| 246 // For Ash create a non-HTML notification with |icon_url|. | 232 Notification notification(GURL(), icon_url, title, message, |
| 247 Notification notification(GURL(), icon_url, title, message, | 233 WebKit::WebTextDirectionDefault, |
| 248 WebKit::WebTextDirectionDefault, | 234 string16(), replace_id, delegate); |
| 249 string16(), replace_id, delegate); | 235 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 250 g_browser_process->notification_ui_manager()->Add(notification, profile); | 236 return notification.notification_id(); |
| 251 return notification.notification_id(); | 237 #else |
| 252 } | |
| 253 #endif | |
| 254 // Generate a data URL embedding the icon URL, title, and message. | 238 // Generate a data URL embedding the icon URL, title, and message. |
| 255 GURL content_url(CreateDataUrl( | 239 GURL content_url(CreateDataUrl( |
| 256 icon_url, title, message, WebKit::WebTextDirectionDefault)); | 240 icon_url, title, message, WebKit::WebTextDirectionDefault)); |
| 257 Notification notification( | 241 Notification notification( |
| 258 GURL(), content_url, string16(), replace_id, delegate); | 242 GURL(), content_url, string16(), replace_id, delegate); |
| 259 g_browser_process->notification_ui_manager()->Add(notification, profile); | 243 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 260 return notification.notification_id(); | 244 return notification.notification_id(); |
| 245 #endif |
| 261 } | 246 } |
| 262 | 247 |
| 263 // static | 248 // static |
| 264 std::string DesktopNotificationService::AddIconNotification( | 249 std::string DesktopNotificationService::AddIconNotification( |
| 265 const GURL& origin_url, | 250 const GURL& origin_url, |
| 266 const string16& title, | 251 const string16& title, |
| 267 const string16& message, | 252 const string16& message, |
| 268 const gfx::ImageSkia& icon, | 253 const gfx::ImageSkia& icon, |
| 269 const string16& replace_id, | 254 const string16& replace_id, |
| 270 NotificationDelegate* delegate, | 255 NotificationDelegate* delegate, |
| 271 Profile* profile) { | 256 Profile* profile) { |
| 272 #if defined(USE_ASH) | 257 #if defined(USE_ASH) |
| 273 if (IsAshNotifyEnabled()) { | 258 // For Ash create a non-HTML notification with |icon|. |
| 274 // For Ash create a non-HTML notification with |icon|. | 259 Notification notification(GURL(), icon, title, message, |
| 275 Notification notification(GURL(), icon, title, message, | 260 WebKit::WebTextDirectionDefault, |
| 276 WebKit::WebTextDirectionDefault, | 261 string16(), replace_id, delegate); |
| 277 string16(), replace_id, delegate); | 262 g_browser_process->notification_ui_manager()->Add(notification, profile); |
| 278 g_browser_process->notification_ui_manager()->Add(notification, profile); | 263 return notification.notification_id(); |
| 279 return notification.notification_id(); | 264 #else |
| 280 } | |
| 281 #endif | |
| 282 GURL icon_url; | 265 GURL icon_url; |
| 283 if (!icon.isNull()) | 266 if (!icon.isNull()) |
| 284 icon_url = GURL(web_ui_util::GetImageDataUrl(icon)); | 267 icon_url = GURL(web_ui_util::GetImageDataUrl(icon)); |
| 285 return AddNotification( | 268 return AddNotification( |
| 286 origin_url, title, message, icon_url, replace_id, delegate, profile); | 269 origin_url, title, message, icon_url, replace_id, delegate, profile); |
| 270 #endif |
| 287 } | 271 } |
| 288 | 272 |
| 289 // static | 273 // static |
| 290 void DesktopNotificationService::RemoveNotification( | 274 void DesktopNotificationService::RemoveNotification( |
| 291 const std::string& notification_id) { | 275 const std::string& notification_id) { |
| 292 g_browser_process->notification_ui_manager()->CancelById(notification_id); | 276 g_browser_process->notification_ui_manager()->CancelById(notification_id); |
| 293 } | 277 } |
| 294 | 278 |
| 295 DesktopNotificationService::DesktopNotificationService(Profile* profile, | 279 DesktopNotificationService::DesktopNotificationService(Profile* profile, |
| 296 NotificationUIManager* ui_manager) | 280 NotificationUIManager* ui_manager) |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 510 |
| 527 if (setting == CONTENT_SETTING_ALLOW) | 511 if (setting == CONTENT_SETTING_ALLOW) |
| 528 return WebKit::WebNotificationPresenter::PermissionAllowed; | 512 return WebKit::WebNotificationPresenter::PermissionAllowed; |
| 529 if (setting == CONTENT_SETTING_BLOCK) | 513 if (setting == CONTENT_SETTING_BLOCK) |
| 530 return WebKit::WebNotificationPresenter::PermissionDenied; | 514 return WebKit::WebNotificationPresenter::PermissionDenied; |
| 531 if (setting == CONTENT_SETTING_ASK) | 515 if (setting == CONTENT_SETTING_ASK) |
| 532 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 516 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 533 NOTREACHED() << "Invalid notifications settings value: " << setting; | 517 NOTREACHED() << "Invalid notifications settings value: " << setting; |
| 534 return WebKit::WebNotificationPresenter::PermissionNotAllowed; | 518 return WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 535 } | 519 } |
| OLD | NEW |