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

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

Issue 2300093002: Make //content responsible for generating notification Ids (Closed)
Patch Set: comments Created 4 years, 3 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "public/platform/WebSecurityOrigin.h" 51 #include "public/platform/WebSecurityOrigin.h"
52 #include "public/platform/modules/notifications/WebNotificationAction.h" 52 #include "public/platform/modules/notifications/WebNotificationAction.h"
53 #include "public/platform/modules/notifications/WebNotificationConstants.h" 53 #include "public/platform/modules/notifications/WebNotificationConstants.h"
54 #include "public/platform/modules/notifications/WebNotificationManager.h" 54 #include "public/platform/modules/notifications/WebNotificationManager.h"
55 #include "wtf/Assertions.h" 55 #include "wtf/Assertions.h"
56 #include "wtf/Functional.h" 56 #include "wtf/Functional.h"
57 57
58 namespace blink { 58 namespace blink {
59 namespace { 59 namespace {
60 60
61 const int64_t kInvalidPersistentId = -1;
62
63 WebNotificationManager* notificationManager() 61 WebNotificationManager* notificationManager()
64 { 62 {
65 return Platform::current()->notificationManager(); 63 return Platform::current()->notificationManager();
66 } 64 }
67 65
68 } // namespace 66 } // namespace
69 67
70 Notification* Notification::create(ExecutionContext* context, const String& titl e, const NotificationOptions& options, ExceptionState& exceptionState) 68 Notification* Notification::create(ExecutionContext* context, const String& titl e, const NotificationOptions& options, ExceptionState& exceptionState)
71 { 69 {
72 // The Web Notification constructor may be disabled through a runtime featur e. The 70 // The Web Notification constructor may be disabled through a runtime featur e. The
(...skipping 29 matching lines...) Expand all
102 if (exceptionState.hadException()) 100 if (exceptionState.hadException())
103 return nullptr; 101 return nullptr;
104 102
105 Notification* notification = new Notification(context, data); 103 Notification* notification = new Notification(context, data);
106 notification->schedulePrepareShow(); 104 notification->schedulePrepareShow();
107 notification->suspendIfNeeded(); 105 notification->suspendIfNeeded();
108 106
109 return notification; 107 return notification;
110 } 108 }
111 109
112 Notification* Notification::create(ExecutionContext* context, int64_t persistent Id, const WebNotificationData& data, bool showing) 110 Notification* Notification::create(ExecutionContext* context, const String& noti ficationId, const WebNotificationData& data, bool showing)
113 { 111 {
114 Notification* notification = new Notification(context, data); 112 Notification* notification = new Notification(context, data);
115 notification->setPersistentId(persistentId); 113 notification->setNotificationId(notificationId);
116 notification->setState(showing ? NotificationStateShowing : NotificationStat eClosed); 114 notification->setState(showing ? NotificationStateShowing : NotificationStat eClosed);
117 notification->suspendIfNeeded(); 115 notification->suspendIfNeeded();
118 116
119 return notification; 117 return notification;
120 } 118 }
121 119
122 Notification::Notification(ExecutionContext* context, const WebNotificationData& data) 120 Notification::Notification(ExecutionContext* context, const WebNotificationData& data)
123 : ActiveScriptWrappable(this) 121 : ActiveScriptWrappable(this)
124 , ActiveDOMObject(context) 122 , ActiveDOMObject(context)
125 , m_data(data) 123 , m_data(data)
126 , m_persistentId(kInvalidPersistentId)
127 , m_state(NotificationStateIdle) 124 , m_state(NotificationStateIdle)
128 , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &N otification::prepareShow)) 125 , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &N otification::prepareShow))
129 { 126 {
130 DCHECK(notificationManager()); 127 DCHECK(notificationManager());
131 } 128 }
132 129
133 Notification::~Notification() 130 Notification::~Notification()
134 { 131 {
135 } 132 }
136 133
(...skipping 28 matching lines...) Expand all
165 m_loader.clear(); 162 m_loader.clear();
166 163
167 m_state = NotificationStateShowing; 164 m_state = NotificationStateShowing;
168 } 165 }
169 166
170 void Notification::close() 167 void Notification::close()
171 { 168 {
172 if (m_state != NotificationStateShowing) 169 if (m_state != NotificationStateShowing)
173 return; 170 return;
174 171
175 if (m_persistentId == kInvalidPersistentId) { 172 if (m_notificationId.isNull()) {
176 // Fire the close event asynchronously. 173 // Fire the close event asynchronously.
177 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N otification::dispatchCloseEvent, wrapPersistent(this))); 174 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N otification::dispatchCloseEvent, wrapPersistent(this)));
178 175
179 m_state = NotificationStateClosing; 176 m_state = NotificationStateClosing;
180 notificationManager()->close(this); 177 notificationManager()->close(this);
181 } else { 178 } else {
182 m_state = NotificationStateClosed; 179 m_state = NotificationStateClosed;
183 180
184 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); 181 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin();
185 DCHECK(origin); 182 DCHECK(origin);
186 183
187 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_pers istentId); 184 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_data .tag, m_notificationId);
188 } 185 }
189 } 186 }
190 187
191 void Notification::dispatchShowEvent() 188 void Notification::dispatchShowEvent()
192 { 189 {
193 dispatchEvent(Event::create(EventTypeNames::show)); 190 dispatchEvent(Event::create(EventTypeNames::show));
194 } 191 }
195 192
196 void Notification::dispatchClickEvent() 193 void Notification::dispatchClickEvent()
197 { 194 {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 391
395 DEFINE_TRACE(Notification) 392 DEFINE_TRACE(Notification)
396 { 393 {
397 visitor->trace(m_prepareShowMethodRunner); 394 visitor->trace(m_prepareShowMethodRunner);
398 visitor->trace(m_loader); 395 visitor->trace(m_loader);
399 EventTargetWithInlineData::trace(visitor); 396 EventTargetWithInlineData::trace(visitor);
400 ActiveDOMObject::trace(visitor); 397 ActiveDOMObject::trace(visitor);
401 } 398 }
402 399
403 } // namespace blink 400 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698