| 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" |
| 49 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
| 50 #include "public/platform/WebSecurityOrigin.h" | 51 #include "public/platform/WebSecurityOrigin.h" |
| 51 #include "public/platform/WebString.h" | 52 #include "public/platform/WebString.h" |
| 52 #include "public/platform/modules/notifications/WebNotificationAction.h" | 53 #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/notifications/WebNotificationManager.h" |
| 56 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" |
| 55 #include "wtf/Assertions.h" | 57 #include "wtf/Assertions.h" |
| 56 #include "wtf/Functional.h" | 58 #include "wtf/Functional.h" |
| 57 | 59 |
| 58 namespace blink { | 60 namespace blink { |
| 59 namespace { | 61 namespace { |
| 60 | 62 |
| 61 const int64_t kInvalidPersistentId = -1; | 63 const int64_t kInvalidPersistentId = -1; |
| 62 | 64 |
| 63 WebNotificationManager* notificationManager() | 65 WebNotificationManager* notificationManager() |
| 64 { | 66 { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 { | 140 { |
| 139 DCHECK_EQ(m_state, NotificationStateIdle); | 141 DCHECK_EQ(m_state, NotificationStateIdle); |
| 140 DCHECK(!m_prepareShowMethodRunner->isActive()); | 142 DCHECK(!m_prepareShowMethodRunner->isActive()); |
| 141 | 143 |
| 142 m_prepareShowMethodRunner->runAsync(); | 144 m_prepareShowMethodRunner->runAsync(); |
| 143 } | 145 } |
| 144 | 146 |
| 145 void Notification::prepareShow() | 147 void Notification::prepareShow() |
| 146 { | 148 { |
| 147 DCHECK_EQ(m_state, NotificationStateIdle); | 149 DCHECK_EQ(m_state, NotificationStateIdle); |
| 148 if (Notification::checkPermission(getExecutionContext()) != mojom::blink::Pe
rmissionStatus::GRANTED) { | 150 if (NotificationManager::from(getExecutionContext())->permissionStatus() !=
mojom::blink::PermissionStatus::GRANTED) { |
| 149 dispatchErrorEvent(); | 151 dispatchErrorEvent(); |
| 150 return; | 152 return; |
| 151 } | 153 } |
| 152 | 154 |
| 153 m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*
>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)
)); | 155 m_loader = new NotificationResourcesLoader(bind<NotificationResourcesLoader*
>(&Notification::didLoadResources, WeakPersistentThisPointer<Notification>(this)
)); |
| 154 m_loader->start(getExecutionContext(), m_data); | 156 m_loader->start(getExecutionContext(), m_data); |
| 155 } | 157 } |
| 156 | 158 |
| 157 void Notification::didLoadResources(NotificationResourcesLoader* loader) | 159 void Notification::didLoadResources(NotificationResourcesLoader* loader) |
| 158 { | 160 { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 case mojom::blink::PermissionStatus::ASK: | 340 case mojom::blink::PermissionStatus::ASK: |
| 339 return "default"; | 341 return "default"; |
| 340 } | 342 } |
| 341 | 343 |
| 342 NOTREACHED(); | 344 NOTREACHED(); |
| 343 return "denied"; | 345 return "denied"; |
| 344 } | 346 } |
| 345 | 347 |
| 346 String Notification::permission(ExecutionContext* context) | 348 String Notification::permission(ExecutionContext* context) |
| 347 { | 349 { |
| 348 return permissionString(checkPermission(context)); | 350 return permissionString(NotificationManager::from(context)->permissionStatus
()); |
| 349 } | |
| 350 | |
| 351 mojom::blink::PermissionStatus Notification::checkPermission(ExecutionContext* c
ontext) | |
| 352 { | |
| 353 SecurityOrigin* origin = context->getSecurityOrigin(); | |
| 354 DCHECK(origin); | |
| 355 | |
| 356 return notificationManager()->checkPermission(WebSecurityOrigin(origin)); | |
| 357 } | 351 } |
| 358 | 352 |
| 359 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica
tionPermissionCallback* deprecatedCallback) | 353 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica
tionPermissionCallback* deprecatedCallback) |
| 360 { | 354 { |
| 361 ExecutionContext* context = scriptState->getExecutionContext(); | 355 ExecutionContext* context = scriptState->getExecutionContext(); |
| 362 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) | 356 if (NotificationPermissionClient* permissionClient = NotificationPermissionC
lient::from(context)) |
| 363 return permissionClient->requestPermission(scriptState, deprecatedCallba
ck); | 357 return permissionClient->requestPermission(scriptState, deprecatedCallba
ck); |
| 364 | 358 |
| 365 // The context has been detached. Return a promise that will never settle. | 359 // The context has been detached. Return a promise that will never settle. |
| 366 DCHECK(context->activeDOMObjectsAreStopped()); | 360 DCHECK(context->activeDOMObjectsAreStopped()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 397 |
| 404 DEFINE_TRACE(Notification) | 398 DEFINE_TRACE(Notification) |
| 405 { | 399 { |
| 406 visitor->trace(m_prepareShowMethodRunner); | 400 visitor->trace(m_prepareShowMethodRunner); |
| 407 visitor->trace(m_loader); | 401 visitor->trace(m_loader); |
| 408 EventTargetWithInlineData::trace(visitor); | 402 EventTargetWithInlineData::trace(visitor); |
| 409 ActiveDOMObject::trace(visitor); | 403 ActiveDOMObject::trace(visitor); |
| 410 } | 404 } |
| 411 | 405 |
| 412 } // namespace blink | 406 } // namespace blink |
| OLD | NEW |