Home | History | Annotate | Download | only in notifications
      1 // Copyright (c) 2010 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/chromeos/notifications/system_notification_factory.h"
      6 
      7 #include "base/utf_string_conversions.h"
      8 #include "chrome/browser/notifications/desktop_notification_service.h"
      9 #include "grit/browser_resources.h"
     10 #include "net/base/escape.h"
     11 
     12 namespace chromeos {
     13 
     14 using WebKit::WebTextDirection;
     15 
     16 // static
     17 Notification SystemNotificationFactory::Create(
     18     const GURL& icon, const string16& title,
     19     const string16& text,
     20     NotificationDelegate* delegate) {
     21   string16 content_url = DesktopNotificationService::CreateDataUrl(
     22       icon, title, text, WebKit::WebTextDirectionDefault);
     23   return Notification(GURL(), GURL(content_url), string16(), string16(),
     24                       delegate);
     25 }
     26 
     27 // static
     28 Notification SystemNotificationFactory::Create(
     29     const GURL& icon, const string16& title,
     30     const string16& text, const string16& link,
     31     NotificationDelegate* delegate) {
     32   // Create an icon notification with or without a footer link
     33   // See code in DesktopNotificationService::CreateDataUrl
     34   WebTextDirection dir = WebKit::WebTextDirectionDefault;
     35   std::vector<std::string> subst;
     36   int resource = IDR_NOTIFICATION_ICON_HTML;
     37   subst.push_back(icon.spec());
     38   subst.push_back(EscapeForHTML(UTF16ToUTF8(title)));
     39   subst.push_back(EscapeForHTML(UTF16ToUTF8(text)));
     40   // icon float position
     41   subst.push_back(dir == WebKit::WebTextDirectionRightToLeft ?
     42                   "right" : "left");
     43   // body text direction
     44   subst.push_back(dir == WebKit::WebTextDirectionRightToLeft ?
     45                   "rtl" : "ltr");
     46   // if link is not empty, then use template with link
     47   if (!link.empty()) {
     48     resource = IDR_NOTIFICATION_ICON_LINK_HTML;
     49     subst.push_back(EscapeForHTML(UTF16ToUTF8(link)));
     50   }
     51 
     52   string16 content_url = DesktopNotificationService::CreateDataUrl(resource,
     53                                                                    subst);
     54   return Notification(GURL(), GURL(content_url), string16(), string16(),
     55                       delegate);
     56 }
     57 
     58 }  // namespace chromeos
     59