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

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

Issue 2344983003: Merge the code paths for closing different kinds of notifications. (Closed)
Patch Set: Merge the close methods Created 4 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
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 DCHECK(origin); 160 DCHECK(origin);
161 161
162 notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getRe sources(), this); 162 notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getRe sources(), this);
163 m_loader.clear(); 163 m_loader.clear();
164 164
165 m_state = State::Showing; 165 m_state = State::Showing;
166 } 166 }
167 167
168 void Notification::close() 168 void Notification::close()
169 { 169 {
170 if (m_state != State::Showing) 170 if (m_state != State::Showing || m_notificationId.isEmpty())
johnme 2016/09/23 16:14:58 Is this possible? Or can it just be a DCHECK? If i
Peter Beverloo 2016/10/04 10:27:23 This would happen in time it takes for the Show IP
171 return; 171 return;
172 172
173 // Schedule the "close" event to be fired for non-persistent notifications. 173 // Schedule the "close" event to be fired for non-persistent notifications.
174 // Persistent notifications won't get such events for programmatic closes. 174 // Persistent notifications won't get such events for programmatic closes.
175 if (m_type == Type::NonPersistent) { 175 if (m_type == Type::NonPersistent) {
176 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N otification::dispatchCloseEvent, wrapPersistent(this))); 176 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N otification::didCloseNotification, wrapPersistent(this)));
177 m_state = State::Closing; 177 m_state = State::Closing;
178 178 } else {
179 notificationManager()->close(this); 179 m_state = State::Closed;
180 return;
181 } 180 }
182 181
183 m_state = State::Closed;
184
185 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); 182 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
186 DCHECK(origin); 183 DCHECK(origin);
187 184
188 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_data.tag , m_notificationId); 185 notificationManager()->close(WebSecurityOrigin(origin), m_data.tag, m_notifi cationId);
189 } 186 }
190 187
191 void Notification::dispatchShowEvent() 188 void Notification::didShowNotification(const WebString& notificationId)
192 { 189 {
190 DCHECK(m_notificationId.isEmpty());
191 m_notificationId = notificationId;
192
193 dispatchEvent(Event::create(EventTypeNames::show)); 193 dispatchEvent(Event::create(EventTypeNames::show));
194 } 194 }
195 195
196 void Notification::dispatchClickEvent() 196 void Notification::didClickNotification()
197 { 197 {
198 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 198 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
199 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext()); 199 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext());
200 dispatchEvent(Event::create(EventTypeNames::click)); 200 dispatchEvent(Event::create(EventTypeNames::click));
201 } 201 }
202 202
203 void Notification::dispatchErrorEvent() 203 void Notification::didCloseNotification()
204 {
205 dispatchEvent(Event::create(EventTypeNames::error));
206 }
207
208 void Notification::dispatchCloseEvent()
209 { 204 {
210 // The notification will be showing when the user initiated the close, or it will be 205 // The notification will be showing when the user initiated the close, or it will be
211 // closing if the developer initiated the close. 206 // closing if the developer initiated the close.
212 if (m_state != State::Showing && m_state != State::Closing) 207 if (m_state != State::Showing && m_state != State::Closing)
213 return; 208 return;
214 209
215 m_state = State::Closed; 210 m_state = State::Closed;
216 dispatchEvent(Event::create(EventTypeNames::close)); 211 dispatchEvent(Event::create(EventTypeNames::close));
217 } 212 }
218 213
214 void Notification::dispatchErrorEvent()
215 {
216 dispatchEvent(Event::create(EventTypeNames::error));
217 }
218
219 String Notification::title() const 219 String Notification::title() const
220 { 220 {
221 return m_data.title; 221 return m_data.title;
222 } 222 }
223 223
224 String Notification::dir() const 224 String Notification::dir() const
225 { 225 {
226 switch (m_data.direction) { 226 switch (m_data.direction) {
227 case WebNotificationData::DirectionLeftToRight: 227 case WebNotificationData::DirectionLeftToRight:
228 return "ltr"; 228 return "ltr";
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 DEFINE_TRACE(Notification) 401 DEFINE_TRACE(Notification)
402 { 402 {
403 visitor->trace(m_prepareShowMethodRunner); 403 visitor->trace(m_prepareShowMethodRunner);
404 visitor->trace(m_loader); 404 visitor->trace(m_loader);
405 EventTargetWithInlineData::trace(visitor); 405 EventTargetWithInlineData::trace(visitor);
406 ActiveDOMObject::trace(visitor); 406 ActiveDOMObject::trace(visitor);
407 } 407 }
408 408
409 } // namespace blink 409 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698