| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/notifications/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/thread.h" | 9 #include "base/thread.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_list.h" | 11 #include "chrome/browser/browser_list.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 40 // using supplied icon, title, and text, run through a template which contains | 40 // using supplied icon, title, and text, run through a template which contains |
| 41 // the standard formatting for notifications. | 41 // the standard formatting for notifications. |
| 42 static string16 CreateDataUrl(const GURL& icon_url, const string16& title, | 42 static string16 CreateDataUrl(const GURL& icon_url, const string16& title, |
| 43 const string16& body) { | 43 const string16& body) { |
| 44 const base::StringPiece template_html( | 44 const base::StringPiece template_html( |
| 45 ResourceBundle::GetSharedInstance().GetRawDataResource( | 45 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 46 IDR_NOTIFICATION_HTML)); | 46 IDR_NOTIFICATION_HTML)); |
| 47 | 47 |
| 48 if (template_html.empty()) { | 48 if (template_html.empty()) { |
| 49 NOTREACHED() << "unable to load template. ID: " << IDR_NOTIFICATION_HTML; | 49 NOTREACHED() << "unable to load template. ID: " << IDR_NOTIFICATION_HTML; |
| 50 return EmptyString16(); | 50 return string16(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 std::vector<string16> subst; | 53 std::vector<string16> subst; |
| 54 if (icon_url.is_valid()) | 54 if (icon_url.is_valid()) |
| 55 subst.push_back(UTF8ToUTF16(icon_url.spec())); | 55 subst.push_back(UTF8ToUTF16(icon_url.spec())); |
| 56 else | 56 else |
| 57 subst.push_back(EmptyString16()); | 57 subst.push_back(string16()); |
| 58 | 58 |
| 59 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(title)))); | 59 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(title)))); |
| 60 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(body)))); | 60 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(body)))); |
| 61 | 61 |
| 62 if (icon_url.is_valid()) { | 62 if (icon_url.is_valid()) { |
| 63 subst.push_back(ASCIIToUTF16("margin-left:56px;")); | 63 subst.push_back(ASCIIToUTF16("margin-left:56px;")); |
| 64 } else { | 64 } else { |
| 65 subst.push_back(EmptyString16()); | 65 subst.push_back(string16()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 string16 format_string = ASCIIToUTF16("data:text/html;charset=utf-8," | 68 string16 format_string = ASCIIToUTF16("data:text/html;charset=utf-8," |
| 69 + template_html.as_string()); | 69 + template_html.as_string()); |
| 70 return ReplaceStringPlaceholders(format_string, subst, NULL); | 70 return ReplaceStringPlaceholders(format_string, subst, NULL); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // A task object which calls the renderer to inform the web page that the | 73 // A task object which calls the renderer to inform the web page that the |
| 74 // permission request has completed. | 74 // permission request has completed. |
| 75 class NotificationPermissionCallbackTask : public Task { | 75 class NotificationPermissionCallbackTask : public Task { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (origin.SchemeIs(chrome::kExtensionScheme)) { | 360 if (origin.SchemeIs(chrome::kExtensionScheme)) { |
| 361 ExtensionsService* ext_service = profile_->GetExtensionsService(); | 361 ExtensionsService* ext_service = profile_->GetExtensionsService(); |
| 362 if (ext_service) { | 362 if (ext_service) { |
| 363 Extension* extension = ext_service->GetExtensionByURL(origin); | 363 Extension* extension = ext_service->GetExtensionByURL(origin); |
| 364 if (extension) | 364 if (extension) |
| 365 return ASCIIToWide(extension->name()); | 365 return ASCIIToWide(extension->name()); |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 return UTF8ToWide(origin.spec()); | 368 return UTF8ToWide(origin.spec()); |
| 369 } | 369 } |
| OLD | NEW |