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

Side by Side Diff: Source/modules/notifications/Notification.cpp

Issue 960163003: Add the "silent" property to the NotificationOptions dictionary. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 5 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 exceptionState.throwTypeError("Illegal constructor."); 71 exceptionState.throwTypeError("Illegal constructor.");
72 return nullptr; 72 return nullptr;
73 } 73 }
74 74
75 Notification* notification = new Notification(title, context); 75 Notification* notification = new Notification(title, context);
76 76
77 notification->setBody(options.body()); 77 notification->setBody(options.body());
78 notification->setTag(options.tag()); 78 notification->setTag(options.tag());
79 notification->setLang(options.lang()); 79 notification->setLang(options.lang());
80 notification->setDir(options.dir()); 80 notification->setDir(options.dir());
81 notification->setSilent(options.silent());
81 if (options.hasIcon()) { 82 if (options.hasIcon()) {
82 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon()); 83 KURL iconUrl = options.icon().isEmpty() ? KURL() : context->completeURL( options.icon());
83 if (!iconUrl.isEmpty() && iconUrl.isValid()) 84 if (!iconUrl.isEmpty() && iconUrl.isValid())
84 notification->setIconUrl(iconUrl); 85 notification->setIconUrl(iconUrl);
85 } 86 }
86 87
87 String insecureOriginMessage; 88 String insecureOriginMessage;
88 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage) 89 UseCounter::Feature feature = context->securityOrigin()->canAccessFeatureReq uiringSecureOrigin(insecureOriginMessage)
89 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin; 90 ? UseCounter::NotificationSecureOrigin : UseCounter::NotificationInsecur eOrigin;
90 UseCounter::count(context, feature); 91 UseCounter::count(context, feature);
91 92
92 notification->scheduleShow(); 93 notification->scheduleShow();
93 notification->suspendIfNeeded(); 94 notification->suspendIfNeeded();
94 return notification; 95 return notification;
95 } 96 }
96 97
97 Notification* Notification::create(ExecutionContext* context, const String& pers istentId, const WebNotificationData& data) 98 Notification* Notification::create(ExecutionContext* context, const String& pers istentId, const WebNotificationData& data)
98 { 99 {
99 Notification* notification = new Notification(data.title, context); 100 Notification* notification = new Notification(data.title, context);
100 101
101 notification->setPersistentId(persistentId); 102 notification->setPersistentId(persistentId);
102 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl"); 103 notification->setDir(data.direction == WebNotificationData::DirectionLeftToR ight ? "ltr" : "rtl");
103 notification->setLang(data.lang); 104 notification->setLang(data.lang);
104 notification->setBody(data.body); 105 notification->setBody(data.body);
105 notification->setTag(data.tag); 106 notification->setTag(data.tag);
107 notification->setSilent(data.silent);
106 108
107 if (!data.icon.isEmpty()) 109 if (!data.icon.isEmpty())
108 notification->setIconUrl(data.icon); 110 notification->setIconUrl(data.icon);
109 111
110 notification->setState(NotificationStateShowing); 112 notification->setState(NotificationStateShowing);
111 notification->suspendIfNeeded(); 113 notification->suspendIfNeeded();
112 return notification; 114 return notification;
113 } 115 }
114 116
115 Notification::Notification(const String& title, ExecutionContext* context) 117 Notification::Notification(const String& title, ExecutionContext* context)
116 : ActiveDOMObject(context) 118 : ActiveDOMObject(context)
117 , m_title(title) 119 , m_title(title)
118 , m_dir("auto") 120 , m_dir("auto")
121 , m_silent(false)
119 , m_state(NotificationStateIdle) 122 , m_state(NotificationStateIdle)
120 , m_asyncRunner(this, &Notification::show) 123 , m_asyncRunner(this, &Notification::show)
121 { 124 {
122 ASSERT(notificationManager()); 125 ASSERT(notificationManager());
123 } 126 }
124 127
125 Notification::~Notification() 128 Notification::~Notification()
126 { 129 {
127 } 130 }
128 131
(...skipping 11 matching lines...) Expand all
140 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { 143 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) {
141 dispatchErrorEvent(); 144 dispatchErrorEvent();
142 return; 145 return;
143 } 146 }
144 147
145 SecurityOrigin* origin = executionContext()->securityOrigin(); 148 SecurityOrigin* origin = executionContext()->securityOrigin();
146 ASSERT(origin); 149 ASSERT(origin);
147 150
148 // FIXME: Do CSP checks on the associated notification icon. 151 // FIXME: Do CSP checks on the associated notification icon.
149 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; 152 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight;
150 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl); 153 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent);
151 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); 154 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this);
152 155
153 m_state = NotificationStateShowing; 156 m_state = NotificationStateShowing;
154 } 157 }
155 158
156 void Notification::close() 159 void Notification::close()
157 { 160 {
158 if (m_state != NotificationStateShowing) 161 if (m_state != NotificationStateShowing)
159 return; 162 return;
160 163
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return m_state == NotificationStateShowing || m_asyncRunner.isActive(); 268 return m_state == NotificationStateShowing || m_asyncRunner.isActive();
266 } 269 }
267 270
268 DEFINE_TRACE(Notification) 271 DEFINE_TRACE(Notification)
269 { 272 {
270 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 273 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
271 ActiveDOMObject::trace(visitor); 274 ActiveDOMObject::trace(visitor);
272 } 275 }
273 276
274 } // namespace blink 277 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | Source/modules/notifications/Notification.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698