Skip to content
Snippets Groups Projects
Commit 3a99802b authored by johnnyg@chromium.org's avatar johnnyg@chromium.org
Browse files

Now that the UI layer is accessible cross-platform, coalesce the...

Now that the UI layer is accessible cross-platform, coalesce the DesktopNotificationService layer into one common module.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/343066

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30652 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b48e1b1
No related merge requests found
......@@ -6,12 +6,15 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/thread.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/notifications_prefs_cache.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_process_host.h"
......@@ -24,13 +27,50 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/common/render_messages.h"
#include "webkit/api/public/WebNotificationPresenter.h"
#include "grit/browser_resources.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "webkit/api/public/WebNotificationPresenter.h"
using WebKit::WebNotificationPresenter;
// 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);
}
// A task object which calls the renderer to inform the web page that the
// permission request has completed.
class NotificationPermissionCallbackTask : public Task {
......@@ -228,3 +268,37 @@ void DesktopNotificationService::RequestPermission(
tab->AddInfoBar(new NotificationPermissionInfoBarDelegate(tab, origin,
callback_context));
}
void DesktopNotificationService::ShowNotification(
const Notification& notification) {
ui_manager_->Add(notification, profile_);
}
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;
}
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;
}
// 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"
bool DesktopNotificationService::ShowDesktopNotification(
const GURL& url,
const GURL&,
int process_id,
int route_id,
NotificationSource source,
int notification_id) {
// TODO(johnnyg): http://crbug.com/23954 Linux support coming soon.
return false;
}
bool DesktopNotificationService::ShowDesktopNotificationText(
const GURL& origin,
const GURL& url,
const string16& title,
const string16& text,
int process_id,
int route_id,
NotificationSource source,
int notification_id) {
// TODO(johnnyg): http://crbug.com/23066 Linux support coming soon.
// Coming soon.
return false;
}
// 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"
bool DesktopNotificationService::ShowDesktopNotification(
const GURL& url,
const GURL&,
int process_id,
int route_id,
NotificationSource source,
int notification_id) {
// TODO(johnnyg): http://crbug.com/23066 Mac support coming soon.
return false;
}
bool DesktopNotificationService::ShowDesktopNotificationText(
const GURL& origin,
const GURL& url,
const string16& title,
const string16& text,
int process_id,
int route_id,
NotificationSource source,
int notification_id) {
// TODO(johnnyg): http://crbug.com/23066 Integration with Growl will go here
// Coming soon.
return false;
}
// 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"
#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_object_proxy.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/site_instance.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) {
ui_manager_->Add(notification, profile_);
}
// 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;
}
......@@ -1818,9 +1818,6 @@
'browser/notifications/balloon_collection_linux.cc',
'browser/notifications/desktop_notification_service.cc',
'browser/notifications/desktop_notification_service.h',
'browser/notifications/desktop_notification_service_linux.cc',
'browser/notifications/desktop_notification_service_mac.mm',
'browser/notifications/desktop_notification_service_win.cc',
'browser/notifications/notification.h',
'browser/notifications/notification_object_proxy.cc',
'browser/notifications/notification_object_proxy.h',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment