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

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

Issue 561813002: Move the logic for creating data: URLs out of DesktopNotificationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/notification.cc
diff --git a/chrome/browser/notifications/notification.cc b/chrome/browser/notifications/notification.cc
index 7fcf601f2b7726165830679bce058058ef7688ff..389e751e3971195927dd697f757f2d96c0d89cb8 100644
--- a/chrome/browser/notifications/notification.cc
+++ b/chrome/browser/notifications/notification.cc
@@ -5,9 +5,66 @@
#include "chrome/browser/notifications/notification.h"
#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
Jun Mukai 2014/09/10 18:18:59 You can remove this include right?
Peter Beverloo 2014/09/11 16:02:26 Done.
+#include "grit/browser_resources.h"
+#include "net/base/escape.h"
+#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/web_ui_util.h"
+namespace {
+
+// 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.
+base::string16 CreateDataUrlForNotificationData(const GURL& icon_url,
+ const base::string16& title,
+ const base::string16& body,
+ blink::WebTextDirection dir) {
+ int resource;
+ std::vector<std::string> subst;
+ if (icon_url.is_valid()) {
+ resource = IDR_NOTIFICATION_ICON_HTML;
+ subst.push_back(icon_url.spec());
+ subst.push_back(net::EscapeForHTML(base::UTF16ToUTF8(title)));
+ subst.push_back(net::EscapeForHTML(base::UTF16ToUTF8(body)));
+ // icon float position
+ subst.push_back(dir == blink::WebTextDirectionRightToLeft ?
+ "right" : "left");
+ } else if (title.empty() || body.empty()) {
+ resource = IDR_NOTIFICATION_1LINE_HTML;
+ base::string16 line = title.empty() ? body : title;
+ // Strings are div names in the template file.
+ base::string16 line_name =
+ title.empty() ? base::ASCIIToUTF16("description")
+ : base::ASCIIToUTF16("title");
+ subst.push_back(net::EscapeForHTML(base::UTF16ToUTF8(line_name)));
+ subst.push_back(net::EscapeForHTML(base::UTF16ToUTF8(line)));
+ } else {
+ resource = IDR_NOTIFICATION_2LINE_HTML;
+ subst.push_back(net::EscapeForHTML(base::UTF16ToUTF8(title)));
+ subst.push_back(net::EscapeForHTML(base::UTF16ToUTF8(body)));
+ }
+ // body text direction
+ subst.push_back(dir == blink::WebTextDirectionRightToLeft ?
+ "rtl" : "ltr");
+
+ const base::StringPiece template_html(
+ ResourceBundle::GetSharedInstance().GetRawDataResource(
+ resource));
+
+ if (template_html.empty()) {
+ NOTREACHED() << "unable to load template. ID: " << resource;
+ return base::string16();
+ }
+
+ std::string data = ReplaceStringPlaceholders(template_html, subst, NULL);
+ return base::UTF8ToUTF16("data:text/html;charset=utf-8," +
+ net::EscapeQueryParamValue(data, false));
+}
+
+} // namespace
+
Notification::Notification(const GURL& origin_url,
const GURL& icon_url,
const base::string16& title,
@@ -30,7 +87,7 @@ Notification::Notification(const GURL& origin_url,
replace_id_(replace_id),
delegate_(delegate) {
// "Upconvert" the string parameters to a data: URL.
- content_url_ = GURL(DesktopNotificationService::CreateDataUrl(
+ content_url_ = GURL(CreateDataUrlForNotificationData(
icon_url, title, body, dir));
}
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service_factory.cc ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698