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

Unified Diff: chrome/browser/notifications/desktop_notification_service_win.cc

Issue 194108: adds DesktopNotificationService to Profile (Closed)
Patch Set: more feedback 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/desktop_notification_service_win.cc
diff --git a/chrome/browser/notifications/desktop_notification_service_win.cc b/chrome/browser/notifications/desktop_notification_service_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..95d326fc3f8ae2ca3e3815d2a4227ca88517794b
--- /dev/null
+++ b/chrome/browser/notifications/desktop_notification_service_win.cc
@@ -0,0 +1,97 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/string_piece.h"
+#include "base/string_util.h"
+#include "base/values.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/notifications/notification_object_proxy.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/renderer_host/site_instance.h"
+#include "chrome/browser/worker_host/worker_process_host.h"
+#include "chrome/common/child_process_host.h"
+#include "grit/browser_resources.h"
+#include "grit/generated_resources.h"
+
+// Creates a data:xxxx URL which contains the full HTML for a notification
+// using supplied icon, title, and text, run through a template which contains
+// the standard formatting for notifications.
+static string16 CreateDataUrl(const GURL& icon_url, const string16& title,
+ const string16& body) {
+ const base::StringPiece template_html(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ IDR_NOTIFICATION_HTML));
+
+ if (template_html.empty()) {
+ NOTREACHED() << "unable to load template. ID: " << IDR_NOTIFICATION_HTML;
+ return EmptyString16();
+ }
+
+ std::vector<string16> subst;
+ if (icon_url.is_valid())
+ subst.push_back(UTF8ToUTF16(icon_url.spec()));
+ else
+ subst.push_back(EmptyString16());
+
+ subst.push_back(title);
+ subst.push_back(body);
+
+ if (icon_url.is_valid()) {
+ subst.push_back(ASCIIToUTF16("block"));
+ subst.push_back(ASCIIToUTF16("60"));
+ } else {
+ subst.push_back(ASCIIToUTF16("none"));
+ subst.push_back(ASCIIToUTF16("5"));
+ }
+
+ string16 format_string = ASCIIToUTF16("data:text/html;charset=utf-8,"
+ + template_html.as_string());
+ return ReplaceStringPlaceholders(format_string, subst, NULL);
+}
+
+// This will call the notification manager on the UI thread to actually
+// put the notification with the requested parameters on the desktop.
+void DesktopNotificationService::ShowNotification(
+ const Notification& notification) {
+ SiteInstance* site_instance = SiteInstance::CreateSiteInstance(profile_);
+ ui_manager_->Add(notification, profile_, site_instance);
michaeln 2009/10/10 19:10:51 Right now, the instance will always be NULL in chr
+}
+
+// Shows a notification bubble which contains the contents of url.
+bool DesktopNotificationService::ShowDesktopNotification(
+ const GURL& origin, const GURL& url, int process_id, int route_id,
+ NotificationSource source, int notification_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ NotificationObjectProxy* proxy =
+ new NotificationObjectProxy(process_id, route_id,
+ notification_id,
+ source == WorkerNotification);
+ Notification notif(origin, url, proxy);
+ ShowNotification(notif);
+ return true;
+}
+
+// Shows a notification constructed from an icon, title, and text.
+bool DesktopNotificationService::ShowDesktopNotificationText(
+ const GURL& origin, const GURL& icon, const string16& title,
+ const string16& text, int process_id, int route_id,
+ NotificationSource source, int notification_id) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ NotificationObjectProxy* proxy =
+ new NotificationObjectProxy(process_id, route_id,
+ notification_id,
+ source == WorkerNotification);
+ // "upconvert" the string parameters to a data: URL.
+ string16 data_url = CreateDataUrl(icon, title, text);
+ Notification notif(origin, GURL(data_url), proxy);
+ ShowNotification(notif);
+ return true;
+}
+

Powered by Google App Engine
This is Rietveld 408576698