| OLD | NEW |
| 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 23 matching lines...) Expand all Loading... |
| 34 #include "bindings/core/v8/ScriptState.h" | 34 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 35 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
| 38 #include "core/dom/ExecutionContextTask.h" | 38 #include "core/dom/ExecutionContextTask.h" |
| 39 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 39 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" |
| 40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 41 #include "core/frame/UseCounter.h" | 41 #include "core/frame/UseCounter.h" |
| 42 #include "modules/notifications/NotificationAction.h" | 42 #include "modules/notifications/NotificationAction.h" |
| 43 #include "modules/notifications/NotificationData.h" | 43 #include "modules/notifications/NotificationData.h" |
| 44 #include "modules/notifications/NotificationManager.h" |
| 44 #include "modules/notifications/NotificationOptions.h" | 45 #include "modules/notifications/NotificationOptions.h" |
| 45 #include "modules/notifications/NotificationPermissionClient.h" | 46 #include "modules/notifications/NotificationPermissionClient.h" |
| 46 #include "modules/notifications/NotificationResourcesLoader.h" | 47 #include "modules/notifications/NotificationResourcesLoader.h" |
| 47 #include "platform/RuntimeEnabledFeatures.h" | 48 #include "platform/RuntimeEnabledFeatures.h" |
| 48 #include "platform/UserGestureIndicator.h" | 49 #include "platform/UserGestureIndicator.h" |
| 50 #include "platform/mojo/MojoHelper.h" |
| 49 #include "public/platform/Platform.h" | 51 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebSecurityOrigin.h" | 52 #include "public/platform/WebSecurityOrigin.h" |
| 51 #include "public/platform/WebString.h" | 53 #include "public/platform/WebString.h" |
| 52 #include "public/platform/modules/notifications/WebNotificationAction.h" | |
| 53 #include "public/platform/modules/notifications/WebNotificationConstants.h" | 54 #include "public/platform/modules/notifications/WebNotificationConstants.h" |
| 54 #include "public/platform/modules/notifications/WebNotificationManager.h" | 55 #include "public/platform/modules/permissions/permission_status.mojom.h" |
| 55 #include "wtf/Functional.h" | 56 #include "wtf/Functional.h" |
| 56 | 57 |
| 57 namespace blink { | 58 namespace blink { |
| 58 namespace { | |
| 59 | |
| 60 const int64_t kInvalidPersistentId = -1; | |
| 61 | |
| 62 WebNotificationManager* notificationManager() | |
| 63 { | |
| 64 return Platform::current()->notificationManager(); | |
| 65 } | |
| 66 | |
| 67 } // namespace | |
| 68 | 59 |
| 69 Notification* Notification::create(ExecutionContext* context, const String& titl
e, const NotificationOptions& options, ExceptionState& exceptionState) | 60 Notification* Notification::create(ExecutionContext* context, const String& titl
e, const NotificationOptions& options, ExceptionState& exceptionState) |
| 70 { | 61 { |
| 71 // The Web Notification constructor may be disabled through a runtime featur
e. The | 62 // The Web Notification constructor may be disabled through a runtime featur
e. The |
| 72 // behavior of the constructor is changing, but not completely agreed upon y
et. | 63 // behavior of the constructor is changing, but not completely agreed upon y
et. |
| 73 if (!RuntimeEnabledFeatures::notificationConstructorEnabled()) { | 64 if (!RuntimeEnabledFeatures::notificationConstructorEnabled()) { |
| 74 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg
istration.showNotification() instead."); | 65 exceptionState.throwTypeError("Illegal constructor. Use ServiceWorkerReg
istration.showNotification() instead."); |
| 75 return nullptr; | 66 return nullptr; |
| 76 } | 67 } |
| 77 | 68 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 90 if (context->isSecureContext(insecureOriginMessage)) { | 81 if (context->isSecureContext(insecureOriginMessage)) { |
| 91 UseCounter::count(context, UseCounter::NotificationSecureOrigin); | 82 UseCounter::count(context, UseCounter::NotificationSecureOrigin); |
| 92 if (context->isDocument()) | 83 if (context->isDocument()) |
| 93 UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter
::NotificationAPISecureOriginIframe); | 84 UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter
::NotificationAPISecureOriginIframe); |
| 94 } else { | 85 } else { |
| 95 UseCounter::count(context, UseCounter::NotificationInsecureOrigin); | 86 UseCounter::count(context, UseCounter::NotificationInsecureOrigin); |
| 96 if (context->isDocument()) | 87 if (context->isDocument()) |
| 97 UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter
::NotificationAPIInsecureOriginIframe); | 88 UseCounter::countCrossOriginIframe(*toDocument(context), UseCounter
::NotificationAPIInsecureOriginIframe); |
| 98 } | 89 } |
| 99 | 90 |
| 100 WebNotificationData data = createWebNotificationData(context, title, options
, exceptionState); | 91 mojom::blink::NotificationPtr data = createNotificationData(context, title,
options, exceptionState); |
| 101 if (exceptionState.hadException()) | 92 if (exceptionState.hadException()) |
| 102 return nullptr; | 93 return nullptr; |
| 103 | 94 |
| 104 Notification* notification = new Notification(context, data); | 95 Notification* notification = new Notification(context, std::move(data)); |
| 105 notification->schedulePrepareShow(); | 96 notification->schedulePrepareShow(); |
| 106 notification->suspendIfNeeded(); | 97 notification->suspendIfNeeded(); |
| 107 | 98 |
| 108 return notification; | 99 return notification; |
| 109 } | 100 } |
| 110 | 101 |
| 111 Notification* Notification::create(ExecutionContext* context, int64_t persistent
Id, const WebNotificationData& data, bool showing) | 102 Notification* Notification::create(ExecutionContext* context, mojom::blink::Noti
ficationPtr data, bool showing) |
| 112 { | 103 { |
| 113 Notification* notification = new Notification(context, data); | 104 Notification* notification = new Notification(context, std::move(data)); |
| 114 notification->setPersistentId(persistentId); | |
| 115 notification->setState(showing ? NotificationStateShowing : NotificationStat
eClosed); | 105 notification->setState(showing ? NotificationStateShowing : NotificationStat
eClosed); |
| 116 notification->suspendIfNeeded(); | 106 notification->suspendIfNeeded(); |
| 117 | 107 |
| 118 return notification; | 108 return notification; |
| 119 } | 109 } |
| 120 | 110 |
| 121 Notification::Notification(ExecutionContext* context, const WebNotificationData&
data) | 111 Notification::Notification(ExecutionContext* context, mojom::blink::Notification
Ptr data) |
| 122 : ActiveScriptWrappable(this) | 112 : ActiveScriptWrappable(this) |
| 123 , ActiveDOMObject(context) | 113 , ActiveDOMObject(context) |
| 124 , m_data(data) | 114 , m_data(std::move(data)) |
| 125 , m_persistentId(kInvalidPersistentId) | |
| 126 , m_state(NotificationStateIdle) | 115 , m_state(NotificationStateIdle) |
| 127 , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &N
otification::prepareShow)) | 116 , m_prepareShowMethodRunner(AsyncMethodRunner<Notification>::create(this, &N
otification::prepareShow)) |
| 117 , m_binding(this) |
| 128 { | 118 { |
| 129 ASSERT(notificationManager()); | |
| 130 } | 119 } |
| 131 | 120 |
| 132 Notification::~Notification() | 121 Notification::~Notification() |
| 133 { | 122 { |
| 134 } | 123 } |
| 135 | 124 |
| 125 NotificationManager* Notification::manager() const |
| 126 { |
| 127 return NotificationManager::from(getExecutionContext()); |
| 128 } |
| 129 |
| 136 void Notification::schedulePrepareShow() | 130 void Notification::schedulePrepareShow() |
| 137 { | 131 { |
| 138 ASSERT(m_state == NotificationStateIdle); | 132 DCHECK_EQ(NotificationStateIdle, m_state); |
| 139 ASSERT(!m_prepareShowMethodRunner->isActive()); | 133 DCHECK(!m_prepareShowMethodRunner->isActive()); |
| 140 | 134 |
| 141 m_prepareShowMethodRunner->runAsync(); | 135 m_prepareShowMethodRunner->runAsync(); |
| 142 } | 136 } |
| 143 | 137 |
| 144 void Notification::prepareShow() | 138 void Notification::prepareShow() |
| 145 { | 139 { |
| 146 ASSERT(m_state == NotificationStateIdle); | 140 DCHECK_EQ(NotificationStateIdle, m_state); |
| 147 if (Notification::checkPermission(getExecutionContext()) != mojom::Permissio
nStatus::GRANTED) { | 141 if (manager()->permissionStatus() != mojom::PermissionStatus::GRANTED) { |
| 148 dispatchErrorEvent(); | 142 dispatchEvent(Event::create(EventTypeNames::error)); |
| 149 return; | 143 return; |
| 150 } | 144 } |
| 151 | 145 |
| 152 m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*
>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)
)); | 146 m_state = NotificationStateLoading; |
| 153 m_loader->start(getExecutionContext(), m_data); | 147 |
| 148 m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*
, mojom::blink::NotificationPtr>(&Notification::didLoadResources, WeakPersistent
ThisPointer<Notification>(this))); |
| 149 m_loader->start(getExecutionContext(), m_data.Clone()); |
| 154 } | 150 } |
| 155 | 151 |
| 156 void Notification::didLoadResources(NotificationResourcesLoader* loader) | 152 void Notification::didLoadResources(NotificationResourcesLoader* loader, mojom::
blink::NotificationPtr notification) |
| 157 { | 153 { |
| 158 DCHECK_EQ(loader, m_loader.get()); | 154 DCHECK_EQ(loader, m_loader.get()); |
| 155 DCHECK(!m_binding.is_bound()); |
| 159 | 156 |
| 160 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); | 157 manager()->display(std::move(notification), loader->getResources(), m_bindin
g.CreateInterfacePtrAndBind(), sameThreadBindForMojo(&Notification::didShowNotif
ication, this)); |
| 161 ASSERT(origin); | |
| 162 | 158 |
| 163 notificationManager()->show(WebSecurityOrigin(origin), m_data, loader->getRe
sources(), this); | |
| 164 m_loader.clear(); | 159 m_loader.clear(); |
| 160 } |
| 161 |
| 162 void Notification::didShowNotification(mojom::blink::NotificationDisplayResult r
esult, const String& id) |
| 163 { |
| 164 DCHECK_EQ(NotificationStateLoading, m_state); |
| 165 |
| 166 // TODO(peter): Fire the error event when |result| is not SUCCESS? |
| 167 |
| 168 DCHECK(!id.isNull()); |
| 165 | 169 |
| 166 m_state = NotificationStateShowing; | 170 m_state = NotificationStateShowing; |
| 171 m_data->id = id; |
| 172 |
| 173 dispatchEvent(Event::create(EventTypeNames::show)); |
| 167 } | 174 } |
| 168 | 175 |
| 169 void Notification::close() | 176 void Notification::close() |
| 170 { | 177 { |
| 171 if (m_state != NotificationStateShowing) | 178 if (m_state != NotificationStateShowing) |
| 172 return; | 179 return; |
| 173 | 180 |
| 174 if (m_persistentId == kInvalidPersistentId) { | 181 DCHECK(!m_data->id.isNull()); |
| 175 // Fire the close event asynchronously. | |
| 176 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTask(&N
otification::dispatchCloseEvent, this)); | |
| 177 | 182 |
| 178 m_state = NotificationStateClosing; | 183 manager()->close(m_data->id, sameThreadBindForMojo(&Notification::OnClose, t
his)); |
| 179 notificationManager()->close(this); | |
| 180 } else { | |
| 181 m_state = NotificationStateClosed; | |
| 182 | 184 |
| 183 SecurityOrigin* origin = getExecutionContext()->getSecurityOrigin(); | 185 m_state = NotificationStateClosing; |
| 184 ASSERT(origin); | |
| 185 | |
| 186 notificationManager()->closePersistent(WebSecurityOrigin(origin), m_pers
istentId); | |
| 187 } | |
| 188 } | 186 } |
| 189 | 187 |
| 190 void Notification::dispatchShowEvent() | 188 void Notification::OnClick() |
| 191 { | 189 { |
| 192 dispatchEvent(Event::create(EventTypeNames::show)); | 190 ASSERT(getExecutionContext()->isContextThread()); |
| 193 } | |
| 194 | 191 |
| 195 void Notification::dispatchClickEvent() | |
| 196 { | |
| 197 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); | 192 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); |
| 198 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext()); | 193 ScopedWindowFocusAllowedIndicator windowFocusAllowed(getExecutionContext()); |
| 199 dispatchEvent(Event::create(EventTypeNames::click)); | 194 dispatchEvent(Event::create(EventTypeNames::click)); |
| 200 } | 195 } |
| 201 | 196 |
| 202 void Notification::dispatchErrorEvent() | 197 void Notification::OnClose(mojom::blink::NotificationCloseResult reason) |
| 203 { | 198 { |
| 204 dispatchEvent(Event::create(EventTypeNames::error)); | 199 ASSERT(getExecutionContext()->isContextThread()); |
| 205 } | |
| 206 | 200 |
| 207 void Notification::dispatchCloseEvent() | |
| 208 { | |
| 209 // The notification will be showing when the user initiated the close, or it
will be | 201 // The notification will be showing when the user initiated the close, or it
will be |
| 210 // closing if the developer initiated the close. | 202 // closing if the developer initiated the close. |
| 211 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi
ng) | 203 if (m_state != NotificationStateShowing && m_state != NotificationStateClosi
ng) |
| 212 return; | 204 return; |
| 213 | 205 |
| 214 m_state = NotificationStateClosed; | 206 m_state = NotificationStateClosed; |
| 215 dispatchEvent(Event::create(EventTypeNames::close)); | 207 |
| 208 // Only fire the "close" event if the notification was in fact closed. |
| 209 if (reason == mojom::blink::NotificationCloseResult::CLOSED) |
| 210 dispatchEvent(Event::create(EventTypeNames::close)); |
| 216 } | 211 } |
| 217 | 212 |
| 218 String Notification::title() const | 213 String Notification::title() const |
| 219 { | 214 { |
| 220 return m_data.title; | 215 return m_data->title; |
| 221 } | 216 } |
| 222 | 217 |
| 223 String Notification::dir() const | 218 String Notification::dir() const |
| 224 { | 219 { |
| 225 switch (m_data.direction) { | 220 switch (m_data->direction) { |
| 226 case WebNotificationData::DirectionLeftToRight: | 221 case mojom::blink::NotificationDirection::LEFT_TO_RIGHT: |
| 227 return "ltr"; | 222 return "ltr"; |
| 228 case WebNotificationData::DirectionRightToLeft: | 223 case mojom::blink::NotificationDirection::RIGHT_TO_LEFT: |
| 229 return "rtl"; | 224 return "rtl"; |
| 230 case WebNotificationData::DirectionAuto: | 225 case mojom::blink::NotificationDirection::AUTO: |
| 231 return "auto"; | 226 return "auto"; |
| 232 } | 227 } |
| 233 | 228 |
| 234 ASSERT_NOT_REACHED(); | 229 ASSERT_NOT_REACHED(); |
| 235 return String(); | 230 return String(); |
| 236 } | 231 } |
| 237 | 232 |
| 238 String Notification::lang() const | 233 String Notification::lang() const |
| 239 { | 234 { |
| 240 return m_data.lang; | 235 return m_data->lang; |
| 241 } | 236 } |
| 242 | 237 |
| 243 String Notification::body() const | 238 String Notification::body() const |
| 244 { | 239 { |
| 245 return m_data.body; | 240 return m_data->body; |
| 246 } | 241 } |
| 247 | 242 |
| 248 String Notification::tag() const | 243 String Notification::tag() const |
| 249 { | 244 { |
| 250 return m_data.tag; | 245 return m_data->tag; |
| 251 } | 246 } |
| 252 | 247 |
| 253 String Notification::icon() const | 248 String Notification::icon() const |
| 254 { | 249 { |
| 255 return m_data.icon.string(); | 250 return m_data->icon; |
| 256 } | 251 } |
| 257 | 252 |
| 258 String Notification::badge() const | 253 String Notification::badge() const |
| 259 { | 254 { |
| 260 return m_data.badge.string(); | 255 return m_data->badge; |
| 261 } | 256 } |
| 262 | 257 |
| 263 NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const | 258 NavigatorVibration::VibrationPattern Notification::vibrate(bool& isNull) const |
| 264 { | 259 { |
| 265 NavigatorVibration::VibrationPattern pattern; | 260 NavigatorVibration::VibrationPattern pattern; |
| 266 pattern.appendRange(m_data.vibrate.begin(), m_data.vibrate.end()); | 261 pattern.appendRange(m_data->vibration_pattern.storage().begin(), m_data->vib
ration_pattern.storage().end()); |
| 267 | 262 |
| 268 if (!pattern.size()) | 263 if (!pattern.size()) |
| 269 isNull = true; | 264 isNull = true; |
| 270 | 265 |
| 271 return pattern; | 266 return pattern; |
| 272 } | 267 } |
| 273 | 268 |
| 274 DOMTimeStamp Notification::timestamp() const | 269 DOMTimeStamp Notification::timestamp() const |
| 275 { | 270 { |
| 276 return m_data.timestamp; | 271 return m_data->timestamp; |
| 277 } | 272 } |
| 278 | 273 |
| 279 bool Notification::renotify() const | 274 bool Notification::renotify() const |
| 280 { | 275 { |
| 281 return m_data.renotify; | 276 return m_data->renotify; |
| 282 } | 277 } |
| 283 | 278 |
| 284 bool Notification::silent() const | 279 bool Notification::silent() const |
| 285 { | 280 { |
| 286 return m_data.silent; | 281 return m_data->silent; |
| 287 } | 282 } |
| 288 | 283 |
| 289 bool Notification::requireInteraction() const | 284 bool Notification::requireInteraction() const |
| 290 { | 285 { |
| 291 return m_data.requireInteraction; | 286 return m_data->require_interaction; |
| 292 } | 287 } |
| 293 | 288 |
| 294 ScriptValue Notification::data(ScriptState* scriptState) | 289 ScriptValue Notification::data(ScriptState* scriptState) |
| 295 { | 290 { |
| 296 if (m_developerData.isEmpty()) { | 291 if (m_developerData.isEmpty()) { |
| 297 RefPtr<SerializedScriptValue> serializedValue; | 292 RefPtr<SerializedScriptValue> serializedValue; |
| 298 | 293 |
| 299 const WebVector<char>& serializedData = m_data.data; | 294 const WebVector<char>& serializedData = m_data->data.storage(); |
| 300 if (serializedData.size()) | 295 if (serializedData.size()) |
| 301 serializedValue = SerializedScriptValueFactory::instance().createFro
mWireBytes(serializedData.data(), serializedData.size()); | 296 serializedValue = SerializedScriptValueFactory::instance().createFro
mWireBytes(serializedData.data(), serializedData.size()); |
| 302 else | 297 else |
| 303 serializedValue = SerializedScriptValueFactory::instance().create(); | 298 serializedValue = SerializedScriptValueFactory::instance().create(); |
| 304 | 299 |
| 305 m_developerData = ScriptValue(scriptState, serializedValue->deserialize(
scriptState->isolate())); | 300 m_developerData = ScriptValue(scriptState, serializedValue->deserialize(
scriptState->isolate())); |
| 306 } | 301 } |
| 307 | 302 |
| 308 return m_developerData; | 303 return m_developerData; |
| 309 } | 304 } |
| 310 | 305 |
| 311 HeapVector<NotificationAction> Notification::actions() const | 306 HeapVector<NotificationAction> Notification::actions() const |
| 312 { | 307 { |
| 313 HeapVector<NotificationAction> actions; | 308 HeapVector<NotificationAction> actions; |
| 314 actions.grow(m_data.actions.size()); | 309 actions.grow(m_data->actions.size()); |
| 315 | 310 |
| 316 for (size_t i = 0; i < m_data.actions.size(); ++i) { | 311 for (size_t i = 0; i < m_data->actions.size(); ++i) { |
| 317 switch (m_data.actions[i].type) { | 312 const auto& action = m_data->actions[i]; |
| 318 case WebNotificationAction::Button: | 313 |
| 314 switch (action->type) { |
| 315 case mojom::blink::NotificationActionType::BUTTON: |
| 319 actions[i].setType("button"); | 316 actions[i].setType("button"); |
| 320 break; | 317 break; |
| 321 case WebNotificationAction::Text: | 318 case mojom::blink::NotificationActionType::TEXT: |
| 322 actions[i].setType("text"); | 319 actions[i].setType("text"); |
| 323 break; | 320 break; |
| 324 default: | 321 default: |
| 325 NOTREACHED() << "Unknown action type: " << m_data.actions[i].type; | 322 NOTREACHED() << "Unknown action type: " << action->type; |
| 326 } | 323 } |
| 327 actions[i].setAction(m_data.actions[i].action); | 324 |
| 328 actions[i].setTitle(m_data.actions[i].title); | 325 actions[i].setAction(action->action); |
| 329 actions[i].setIcon(m_data.actions[i].icon.string()); | 326 actions[i].setTitle(action->title); |
| 330 actions[i].setPlaceholder(m_data.actions[i].placeholder); | 327 actions[i].setIcon(action->icon); |
| 328 actions[i].setPlaceholder(action->placeholder); |
| 331 } | 329 } |
| 332 | 330 |
| 333 return actions; | 331 return actions; |
| 334 } | 332 } |
| 335 | 333 |
| 336 String Notification::permissionString(mojom::PermissionStatus permission) | 334 String Notification::permissionString(mojom::PermissionStatus permission) |
| 337 { | 335 { |
| 338 switch (permission) { | 336 switch (permission) { |
| 339 case mojom::PermissionStatus::GRANTED: | 337 case mojom::PermissionStatus::GRANTED: |
| 340 return "granted"; | 338 return "granted"; |
| 341 case mojom::PermissionStatus::DENIED: | 339 case mojom::PermissionStatus::DENIED: |
| 342 return "denied"; | 340 return "denied"; |
| 343 case mojom::PermissionStatus::ASK: | 341 case mojom::PermissionStatus::ASK: |
| 344 return "default"; | 342 return "default"; |
| 345 } | 343 } |
| 346 | 344 |
| 347 ASSERT_NOT_REACHED(); | 345 ASSERT_NOT_REACHED(); |
| 348 return "denied"; | 346 return "denied"; |
| 349 } | 347 } |
| 350 | 348 |
| 351 String Notification::permission(ExecutionContext* context) | 349 String Notification::permission(ExecutionContext* context) |
| 352 { | 350 { |
| 353 return permissionString(checkPermission(context)); | 351 return permissionString(NotificationManager::from(context)->permissionStatus
()); |
| 354 } | |
| 355 | |
| 356 mojom::PermissionStatus Notification::checkPermission(ExecutionContext* context) | |
| 357 { | |
| 358 SecurityOrigin* origin = context->getSecurityOrigin(); | |
| 359 ASSERT(origin); | |
| 360 | |
| 361 return notificationManager()->checkPermission(WebSecurityOrigin(origin)); | |
| 362 } | 352 } |
| 363 | 353 |
| 364 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica
tionPermissionCallback* deprecatedCallback) | 354 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica
tionPermissionCallback* deprecatedCallback) |
| 365 { | 355 { |
| 366 ExecutionContext* context = scriptState->getExecutionContext(); | 356 ExecutionContext* context = scriptState->getExecutionContext(); |
| 367 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) | 357 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) |
| 368 return permissionClient->requestPermission(scriptState, deprecatedCallba
ck); | 358 return permissionClient->requestPermission(scriptState, deprecatedCallba
ck); |
| 369 | 359 |
| 370 // The context has been detached. Return a promise that will never settle. | 360 // The context has been detached. Return a promise that will never settle. |
| 371 ASSERT(context->activeDOMObjectsAreStopped()); | 361 ASSERT(context->activeDOMObjectsAreStopped()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 383 return EventTarget::dispatchEventInternal(event); | 373 return EventTarget::dispatchEventInternal(event); |
| 384 } | 374 } |
| 385 | 375 |
| 386 const AtomicString& Notification::interfaceName() const | 376 const AtomicString& Notification::interfaceName() const |
| 387 { | 377 { |
| 388 return EventTargetNames::Notification; | 378 return EventTargetNames::Notification; |
| 389 } | 379 } |
| 390 | 380 |
| 391 void Notification::stop() | 381 void Notification::stop() |
| 392 { | 382 { |
| 393 notificationManager()->notifyDelegateDestroyed(this); | |
| 394 | |
| 395 m_state = NotificationStateClosed; | 383 m_state = NotificationStateClosed; |
| 396 | 384 |
| 397 m_prepareShowMethodRunner->stop(); | 385 m_prepareShowMethodRunner->stop(); |
| 398 | 386 |
| 399 if (m_loader) | 387 if (m_loader) |
| 400 m_loader->stop(); | 388 m_loader->stop(); |
| 401 } | 389 } |
| 402 | 390 |
| 403 bool Notification::hasPendingActivity() const | 391 bool Notification::hasPendingActivity() const |
| 404 { | 392 { |
| 405 return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isA
ctive() || m_loader; | 393 return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isA
ctive() || m_loader; |
| 406 } | 394 } |
| 407 | 395 |
| 408 DEFINE_TRACE(Notification) | 396 DEFINE_TRACE(Notification) |
| 409 { | 397 { |
| 410 visitor->trace(m_prepareShowMethodRunner); | 398 visitor->trace(m_prepareShowMethodRunner); |
| 411 visitor->trace(m_loader); | 399 visitor->trace(m_loader); |
| 412 EventTargetWithInlineData::trace(visitor); | 400 EventTargetWithInlineData::trace(visitor); |
| 413 ActiveDOMObject::trace(visitor); | 401 ActiveDOMObject::trace(visitor); |
| 414 } | 402 } |
| 415 | 403 |
| 416 } // namespace blink | 404 } // namespace blink |
| OLD | NEW |