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