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

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

Issue 661643002: Adds a context message of the security origin for web notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_browsertest.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/scoped_user_pref_update.h" 9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
25 #include "components/pref_registry/pref_registry_syncable.h" 25 #include "components/pref_registry/pref_registry_syncable.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/desktop_notification_delegate.h" 27 #include "content/public/browser/desktop_notification_delegate.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/render_frame_host.h" 29 #include "content/public/browser/render_frame_host.h"
30 #include "content/public/browser/render_process_host.h" 30 #include "content/public/browser/render_process_host.h"
31 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
33 #include "content/public/common/show_desktop_notification_params.h" 33 #include "content/public/common/show_desktop_notification_params.h"
34 #include "net/base/net_util.h"
34 #include "ui/base/webui/web_ui_util.h" 35 #include "ui/base/webui/web_ui_util.h"
35 #include "ui/message_center/notifier_settings.h" 36 #include "ui/message_center/notifier_settings.h"
36 37
37 #if defined(ENABLE_EXTENSIONS) 38 #if defined(ENABLE_EXTENSIONS)
38 #include "chrome/browser/extensions/api/notifications/notifications_api.h" 39 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
39 #include "chrome/browser/extensions/extension_service.h" 40 #include "chrome/browser/extensions/extension_service.h"
40 #include "extensions/browser/event_router.h" 41 #include "extensions/browser/event_router.h"
41 #include "extensions/browser/extension_registry.h" 42 #include "extensions/browser/extension_registry.h"
42 #include "extensions/browser/extension_system.h" 43 #include "extensions/browser/extension_system.h"
43 #include "extensions/browser/extension_util.h" 44 #include "extensions/browser/extension_util.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void DesktopNotificationService::ShowDesktopNotification( 156 void DesktopNotificationService::ShowDesktopNotification(
156 const content::ShowDesktopNotificationHostMsgParams& params, 157 const content::ShowDesktopNotificationHostMsgParams& params,
157 content::RenderFrameHost* render_frame_host, 158 content::RenderFrameHost* render_frame_host,
158 scoped_ptr<content::DesktopNotificationDelegate> delegate, 159 scoped_ptr<content::DesktopNotificationDelegate> delegate,
159 base::Closure* cancel_callback) { 160 base::Closure* cancel_callback) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
161 const GURL& origin = params.origin; 162 const GURL& origin = params.origin;
162 NotificationObjectProxy* proxy = 163 NotificationObjectProxy* proxy =
163 new NotificationObjectProxy(render_frame_host, delegate.Pass()); 164 new NotificationObjectProxy(render_frame_host, delegate.Pass());
164 165
166 int process_id = render_frame_host->GetProcess()->GetID();
167
168 // TODO(dewittj): The origin of file:// URLs always appears to be the empty
169 // URL. We need a better way to display this than returning an empty string.
165 base::string16 display_source = DisplayNameForOriginInProcessId( 170 base::string16 display_source = DisplayNameForOriginInProcessId(
166 origin, render_frame_host->GetProcess()->GetID()); 171 origin, process_id);
172
167 Notification notification(origin, params.icon_url, params.title, 173 Notification notification(origin, params.icon_url, params.title,
168 params.body, params.direction, display_source, params.replace_id, 174 params.body, params.direction, display_source, params.replace_id,
169 proxy); 175 proxy);
170 176
177 // Web notifications should display their origin
178 notification.set_context_message(display_source);
179
171 // The webkit notification doesn't timeout. 180 // The webkit notification doesn't timeout.
172 notification.set_never_timeout(true); 181 notification.set_never_timeout(true);
173 182
174 g_browser_process->notification_ui_manager()->Add(notification, profile_); 183 g_browser_process->notification_ui_manager()->Add(notification, profile_);
175 if (cancel_callback) 184 if (cancel_callback)
176 *cancel_callback = 185 *cancel_callback =
177 base::Bind(&CancelNotification, 186 base::Bind(&CancelNotification,
178 proxy->id(), 187 proxy->id(),
179 NotificationUIManager::GetProfileID(profile_)); 188 NotificationUIManager::GetProfileID(profile_));
180 189
(...skipping 17 matching lines...) Expand all
198 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); 207 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
199 iter != extensions.end(); ++iter) { 208 iter != extensions.end(); ++iter) {
200 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id()); 209 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
201 if (IsNotifierEnabled(notifier_id)) 210 if (IsNotifierEnabled(notifier_id))
202 return base::UTF8ToUTF16((*iter)->name()); 211 return base::UTF8ToUTF16((*iter)->name());
203 } 212 }
204 } 213 }
205 } 214 }
206 #endif 215 #endif
207 216
208 return base::UTF8ToUTF16(origin.host()); 217 std::string languages =
218 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages);
219
220 std::string displayed_origin;
221 if (origin.SchemeIsHTTPOrHTTPS()) {
222 base::string16 rv = net::IDNToUnicode(origin.host(), languages);
Peter Beverloo 2014/10/17 11:17:59 What does |rv| stand for? Can we use a clearer nam
dewittj 2014/10/17 18:24:13 Done.
223 if (origin.has_port()) {
224 rv.push_back(':');
225 std::string port = origin.port();
226 rv.insert(rv.end(), port.begin(), port.end());
Jun Mukai 2014/10/16 22:43:22 rv.append(base::UTF8ToUTF16(origin.port())) would
dewittj 2014/10/17 18:24:12 Done.
227 }
228 return rv;
229 }
230
231 return net::FormatUrl(GURL(displayed_origin), languages);
Peter Beverloo 2014/10/17 11:17:59 |displayed_origin| is guaranteed to be an empty st
dewittj 2014/10/17 18:24:13 Yes, I had some uncommitted fixes in my tree that
209 } 232 }
210 233
211 bool DesktopNotificationService::IsNotifierEnabled( 234 bool DesktopNotificationService::IsNotifierEnabled(
212 const NotifierId& notifier_id) { 235 const NotifierId& notifier_id) {
213 switch (notifier_id.type) { 236 switch (notifier_id.type) {
214 case NotifierId::APPLICATION: 237 case NotifierId::APPLICATION:
215 return disabled_extension_ids_.find(notifier_id.id) == 238 return disabled_extension_ids_.find(notifier_id.id) ==
216 disabled_extension_ids_.end(); 239 disabled_extension_ids_.end();
217 case NotifierId::WEB_PAGE: 240 case NotifierId::WEB_PAGE:
218 return DesktopNotificationProfileUtil::GetContentSetting( 241 return DesktopNotificationProfileUtil::GetContentSetting(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // Tell the IO thread that this extension's permission for notifications 372 // Tell the IO thread that this extension's permission for notifications
350 // has changed. 373 // has changed.
351 extensions::InfoMap* extension_info_map = 374 extensions::InfoMap* extension_info_map =
352 extensions::ExtensionSystem::Get(profile_)->info_map(); 375 extensions::ExtensionSystem::Get(profile_)->info_map();
353 BrowserThread::PostTask( 376 BrowserThread::PostTask(
354 BrowserThread::IO, FROM_HERE, 377 BrowserThread::IO, FROM_HERE,
355 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, 378 base::Bind(&extensions::InfoMap::SetNotificationsDisabled,
356 extension_info_map, notifier_id.id, !enabled)); 379 extension_info_map, notifier_id.id, !enabled));
357 #endif 380 #endif
358 } 381 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/notifications/notification_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698