Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: chrome/browser/notifications/desktop_notification_service_win.cc

Issue 271052: Browser side support (sans UI) for desktop notifications.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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"
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_object_proxy.h"
15 #include "chrome/browser/renderer_host/render_process_host.h"
16 #include "chrome/browser/renderer_host/site_instance.h"
17 #include "chrome/browser/worker_host/worker_process_host.h"
18 #include "chrome/common/child_process_host.h"
19 #include "grit/browser_resources.h"
20 #include "grit/generated_resources.h"
21
22 // Creates a data:xxxx URL which contains the full HTML for a notification
23 // using supplied icon, title, and text, run through a template which contains
24 // the standard formatting for notifications.
25 static string16 CreateDataUrl(const GURL& icon_url, const string16& title,
26 const string16& body) {
27 const base::StringPiece template_html(
28 ResourceBundle::GetSharedInstance().GetRawDataResource(
29 IDR_NOTIFICATION_HTML));
30
31 if (template_html.empty()) {
32 NOTREACHED() << "unable to load template. ID: " << IDR_NOTIFICATION_HTML;
33 return EmptyString16();
34 }
35
36 std::vector<string16> subst;
37 if (icon_url.is_valid())
38 subst.push_back(UTF8ToUTF16(icon_url.spec()));
39 else
40 subst.push_back(EmptyString16());
41
42 subst.push_back(title);
43 subst.push_back(body);
44
45 if (icon_url.is_valid()) {
46 subst.push_back(ASCIIToUTF16("block"));
47 subst.push_back(ASCIIToUTF16("60"));
48 } else {
49 subst.push_back(ASCIIToUTF16("none"));
50 subst.push_back(ASCIIToUTF16("5"));
51 }
52
53 string16 format_string = ASCIIToUTF16("data:text/html;charset=utf-8,"
54 + template_html.as_string());
55 return ReplaceStringPlaceholders(format_string, subst, NULL);
56 }
57
58 // This will call the notification manager on the UI thread to actually
59 // put the notification with the requested parameters on the desktop.
60 void DesktopNotificationService::ShowNotification(
61 const Notification& notification) {
62 SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_);
63 // TODO(johnnyg): When UI Manager is available, add from here.
64 // ui_manager_->Add(notification, profile_, site_instance);
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
OLDNEW
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service_mac.mm ('k') | chrome/browser/notifications/notification.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698