 Chromium Code Reviews
 Chromium Code Reviews Issue 194108:
  adds DesktopNotificationService to Profile  (Closed)
    
  
    Issue 194108:
  adds DesktopNotificationService to Profile  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/notifications/desktop_notification_service.h" | |
| 
michaeln
2009/10/12 16:27:52
Also, there's nothing windowzy about this _win.cc
 
John Gregg
2009/10/12 16:37:37
The current design is that only Windows Chrome wil
 | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "app/resource_bundle.h" | |
| 9 #include "base/string_piece.h" | |
| 10 #include "base/string_util.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chrome/browser/browser_list.h" | |
| 13 #include "chrome/browser/chrome_thread.h" | |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 15 #include "chrome/browser/notifications/notification_object_proxy.h" | |
| 16 #include "chrome/browser/renderer_host/render_process_host.h" | |
| 17 #include "chrome/browser/renderer_host/site_instance.h" | |
| 18 #include "chrome/browser/worker_host/worker_process_host.h" | |
| 19 #include "chrome/common/child_process_host.h" | |
| 20 #include "grit/browser_resources.h" | |
| 21 #include "grit/generated_resources.h" | |
| 22 | |
| 23 // Creates a data:xxxx URL which contains the full HTML for a notification | |
| 24 // using supplied icon, title, and text, run through a template which contains | |
| 25 // the standard formatting for notifications. | |
| 26 static string16 CreateDataUrl(const GURL& icon_url, const string16& title, | |
| 27 const string16& body) { | |
| 28 const base::StringPiece template_html( | |
| 29 ResourceBundle::GetSharedInstance().GetRawDataResource( | |
| 30 IDR_NOTIFICATION_HTML)); | |
| 31 | |
| 32 if (template_html.empty()) { | |
| 33 NOTREACHED() << "unable to load template. ID: " << IDR_NOTIFICATION_HTML; | |
| 34 return EmptyString16(); | |
| 35 } | |
| 36 | |
| 37 std::vector<string16> subst; | |
| 38 if (icon_url.is_valid()) | |
| 39 subst.push_back(UTF8ToUTF16(icon_url.spec())); | |
| 40 else | |
| 41 subst.push_back(EmptyString16()); | |
| 42 | |
| 43 subst.push_back(title); | |
| 44 subst.push_back(body); | |
| 45 | |
| 46 if (icon_url.is_valid()) { | |
| 47 subst.push_back(ASCIIToUTF16("block")); | |
| 48 subst.push_back(ASCIIToUTF16("60")); | |
| 49 } else { | |
| 50 subst.push_back(ASCIIToUTF16("none")); | |
| 51 subst.push_back(ASCIIToUTF16("5")); | |
| 52 } | |
| 53 | |
| 54 string16 format_string = ASCIIToUTF16("data:text/html;charset=utf-8," | |
| 55 + template_html.as_string()); | |
| 56 return ReplaceStringPlaceholders(format_string, subst, NULL); | |
| 57 } | |
| 58 | |
| 59 // This will call the notification manager on the UI thread to actually | |
| 60 // put the notification with the requested parameters on the desktop. | |
| 61 void DesktopNotificationService::ShowNotification( | |
| 62 const Notification& notification) { | |
| 63 SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_); | |
| 64 ui_manager_->Add(notification, profile_, site_instance); | |
| 
michaeln
2009/10/10 19:10:51
Right now, the instance will always be NULL in chr
 | |
| 65 } | |
| 66 | |
| 67 // Shows a notification bubble which contains the contents of url. | |
| 68 bool DesktopNotificationService::ShowDesktopNotification( | |
| 69 const GURL& origin, const GURL& url, int process_id, int route_id, | |
| 70 NotificationSource source, int notification_id) { | |
| 71 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 72 NotificationObjectProxy* proxy = | |
| 73 new NotificationObjectProxy(process_id, route_id, | |
| 74 notification_id, | |
| 75 source == WorkerNotification); | |
| 76 Notification notif(origin, url, proxy); | |
| 77 ShowNotification(notif); | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 // Shows a notification constructed from an icon, title, and text. | |
| 82 bool DesktopNotificationService::ShowDesktopNotificationText( | |
| 83 const GURL& origin, const GURL& icon, const string16& title, | |
| 84 const string16& text, int process_id, int route_id, | |
| 85 NotificationSource source, int notification_id) { | |
| 86 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | |
| 87 NotificationObjectProxy* proxy = | |
| 88 new NotificationObjectProxy(process_id, route_id, | |
| 89 notification_id, | |
| 90 source == WorkerNotification); | |
| 91 // "upconvert" the string parameters to a data: URL. | |
| 92 string16 data_url = CreateDataUrl(icon, title, text); | |
| 93 Notification notif(origin, GURL(data_url), proxy); | |
| 94 ShowNotification(notif); | |
| 95 return true; | |
| 96 } | |
| 97 | |
| OLD | NEW |