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

Side by Side Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 2743007: Properly escape user input for notifications, since URL-encoded characters ar... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: feedback addressed & test Created 10 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/notifications/desktop_notifications_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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"
(...skipping 25 matching lines...) Expand all
36 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h" 36 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPresenter.h"
37 37
38 using WebKit::WebNotificationPresenter; 38 using WebKit::WebNotificationPresenter;
39 39
40 // static 40 // static
41 string16 DesktopNotificationService::CreateDataUrl( 41 string16 DesktopNotificationService::CreateDataUrl(
42 const GURL& icon_url, const string16& title, const string16& body) { 42 const GURL& icon_url, const string16& title, const string16& body) {
43 int resource; 43 int resource;
44 string16 line_name; 44 string16 line_name;
45 string16 line; 45 string16 line;
46 std::vector<string16> subst; 46 std::vector<std::string> subst;
47 if (icon_url.is_valid()) { 47 if (icon_url.is_valid()) {
48 resource = IDR_NOTIFICATION_ICON_HTML; 48 resource = IDR_NOTIFICATION_ICON_HTML;
49 subst.push_back(UTF8ToUTF16(icon_url.spec())); 49 subst.push_back(icon_url.spec());
50 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(title)))); 50 subst.push_back(EscapeForHTML(UTF16ToUTF8(title)));
51 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(body)))); 51 subst.push_back(EscapeForHTML(UTF16ToUTF8(body)));
52 } else if (title.empty() || body.empty()) { 52 } else if (title.empty() || body.empty()) {
53 resource = IDR_NOTIFICATION_1LINE_HTML; 53 resource = IDR_NOTIFICATION_1LINE_HTML;
54 line = title.empty() ? body : title; 54 line = title.empty() ? body : title;
55 // Strings are div names in the template file. 55 // Strings are div names in the template file.
56 line_name = title.empty() ? ASCIIToUTF16("description") 56 line_name = title.empty() ? ASCIIToUTF16("description")
57 : ASCIIToUTF16("title"); 57 : ASCIIToUTF16("title");
58 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(line_name)))); 58 subst.push_back(EscapeForHTML(UTF16ToUTF8(line_name)));
59 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(line)))); 59 subst.push_back(EscapeForHTML(UTF16ToUTF8(line)));
60 } else { 60 } else {
61 resource = IDR_NOTIFICATION_2LINE_HTML; 61 resource = IDR_NOTIFICATION_2LINE_HTML;
62 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(title)))); 62 subst.push_back(EscapeForHTML(UTF16ToUTF8(title)));
63 subst.push_back(UTF8ToUTF16(EscapeForHTML(UTF16ToUTF8(body)))); 63 subst.push_back(EscapeForHTML(UTF16ToUTF8(body)));
64 } 64 }
65 65
66 const base::StringPiece template_html( 66 const base::StringPiece template_html(
67 ResourceBundle::GetSharedInstance().GetRawDataResource( 67 ResourceBundle::GetSharedInstance().GetRawDataResource(
68 resource)); 68 resource));
69 69
70 if (template_html.empty()) { 70 if (template_html.empty()) {
71 NOTREACHED() << "unable to load template. ID: " << resource; 71 NOTREACHED() << "unable to load template. ID: " << resource;
72 return string16(); 72 return string16();
73 } 73 }
74 74
75 string16 format_string = ASCIIToUTF16("data:text/html;charset=utf-8," 75 std::string data = ReplaceStringPlaceholders(template_html, subst, NULL);
76 + template_html.as_string()); 76 return UTF8ToUTF16("data:text/html;charset=utf-8," +
77 return ReplaceStringPlaceholders(format_string, subst, NULL); 77 EscapeQueryParamValue(data, false));
78 } 78 }
79 79
80 // A task object which calls the renderer to inform the web page that the 80 // A task object which calls the renderer to inform the web page that the
81 // permission request has completed. 81 // permission request has completed.
82 class NotificationPermissionCallbackTask : public Task { 82 class NotificationPermissionCallbackTask : public Task {
83 public: 83 public:
84 NotificationPermissionCallbackTask(int process_id, int route_id, 84 NotificationPermissionCallbackTask(int process_id, int route_id,
85 int request_id) 85 int request_id)
86 : process_id_(process_id), 86 : process_id_(process_id),
87 route_id_(route_id), 87 route_id_(route_id),
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 if (origin.SchemeIs(chrome::kExtensionScheme)) { 441 if (origin.SchemeIs(chrome::kExtensionScheme)) {
442 ExtensionsService* ext_service = profile_->GetExtensionsService(); 442 ExtensionsService* ext_service = profile_->GetExtensionsService();
443 if (ext_service) { 443 if (ext_service) {
444 Extension* extension = ext_service->GetExtensionByURL(origin); 444 Extension* extension = ext_service->GetExtensionByURL(origin);
445 if (extension) 445 if (extension)
446 return UTF8ToWide(extension->name()); 446 return UTF8ToWide(extension->name());
447 } 447 }
448 } 448 }
449 return UTF8ToWide(origin.host()); 449 return UTF8ToWide(origin.host());
450 } 450 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/notifications/desktop_notifications_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698