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

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

Issue 1093243003: [WIP] add "auto" attr in notifications Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 8 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
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 ASSERT(m_state == NotificationStateIdle); 160 ASSERT(m_state == NotificationStateIdle);
161 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) { 161 if (Notification::checkPermission(executionContext()) != WebNotificationPerm issionAllowed) {
162 dispatchErrorEvent(); 162 dispatchErrorEvent();
163 return; 163 return;
164 } 164 }
165 165
166 SecurityOrigin* origin = executionContext()->securityOrigin(); 166 SecurityOrigin* origin = executionContext()->securityOrigin();
167 ASSERT(origin); 167 ASSERT(origin);
168 168
169 // FIXME: Do CSP checks on the associated notification icon. 169 // FIXME: Do CSP checks on the associated notification icon.
170 WebNotificationData::Direction dir = m_dir == "rtl" ? WebNotificationData::D irectionRightToLeft : WebNotificationData::DirectionLeftToRight; 170 WebNotificationData::Direction dir = directionStringToEnum(m_dir);
171 171
172 // The lifetime and availability of non-persistent notifications is tied to the page 172 // The lifetime and availability of non-persistent notifications is tied to the page
173 // they were created by, and thus the data doesn't have to be known to the e mbedder. 173 // they were created by, and thus the data doesn't have to be known to the e mbedder.
174 String emptyDataAsWireString; 174 String emptyDataAsWireString;
175 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, emptyDataAsWireString); 175 WebNotificationData notificationData(m_title, dir, m_lang, m_body, m_tag, m_ iconUrl, m_silent, emptyDataAsWireString);
176 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this); 176 notificationManager()->show(WebSerializedOrigin(*origin), notificationData, this);
177 177
178 m_state = NotificationStateShowing; 178 m_state = NotificationStateShowing;
179 } 179 }
180 180
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 { 220 {
221 // The notification will be showing when the user initiated the close, or it will be 221 // The notification will be showing when the user initiated the close, or it will be
222 // closing if the developer initiated the close. 222 // closing if the developer initiated the close.
223 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi ng) 223 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi ng)
224 return; 224 return;
225 225
226 m_state = NotificationStateClosed; 226 m_state = NotificationStateClosed;
227 dispatchEvent(Event::create(EventTypeNames::close)); 227 dispatchEvent(Event::create(EventTypeNames::close));
228 } 228 }
229 229
230 TextDirection Notification::direction() const
231 {
232 // FIXME: Resolve dir()=="auto" against the document.
233 return dir() == "rtl" ? RTL : LTR;
234 }
235
236 String Notification::permissionString(WebNotificationPermission permission) 230 String Notification::permissionString(WebNotificationPermission permission)
237 { 231 {
238 switch (permission) { 232 switch (permission) {
239 case WebNotificationPermissionAllowed: 233 case WebNotificationPermissionAllowed:
240 return "granted"; 234 return "granted";
241 case WebNotificationPermissionDenied: 235 case WebNotificationPermissionDenied:
242 return "denied"; 236 return "denied";
243 case WebNotificationPermissionDefault: 237 case WebNotificationPermissionDefault:
244 return "default"; 238 return "default";
245 } 239 }
246 240
247 ASSERT_NOT_REACHED(); 241 ASSERT_NOT_REACHED();
248 return "denied"; 242 return "denied";
249 } 243 }
250 244
245 WebNotificationData Notification::directionStringToEnum(String direction)
246 {
247 switch (direction) {
248 case "ltr":
249 return DirectionLeftToRight;
250 case "rtl":
251 return DirectionRightToLeft;
252 case "auto":
253 return DirectionAuto;
254 }
255
256 ASSERT_NOT_REACHED();
257 return DirectionAuto;
258 }
259
251 String Notification::permission(ExecutionContext* context) 260 String Notification::permission(ExecutionContext* context)
252 { 261 {
253 return permissionString(checkPermission(context)); 262 return permissionString(checkPermission(context));
254 } 263 }
255 264
256 WebNotificationPermission Notification::checkPermission(ExecutionContext* contex t) 265 WebNotificationPermission Notification::checkPermission(ExecutionContext* contex t)
257 { 266 {
258 SecurityOrigin* origin = context->securityOrigin(); 267 SecurityOrigin* origin = context->securityOrigin();
259 ASSERT(origin); 268 ASSERT(origin);
260 269
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); 311 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate()));
303 } 312 }
304 313
305 DEFINE_TRACE(Notification) 314 DEFINE_TRACE(Notification)
306 { 315 {
307 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor); 316 RefCountedGarbageCollectedEventTargetWithInlineData<Notification>::trace(vis itor);
308 ActiveDOMObject::trace(visitor); 317 ActiveDOMObject::trace(visitor);
309 } 318 }
310 319
311 } // namespace blink 320 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/notifications/Notification.h ('k') | public/platform/modules/notifications/WebNotificationData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698