Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "modules/notifications/Notification.h" | 31 #include "modules/notifications/Notification.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
| 34 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 34 #include "bindings/core/v8/ScriptState.h" | 35 #include "bindings/core/v8/ScriptState.h" |
| 35 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 36 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
| 36 #include "bindings/modules/v8/V8NotificationAction.h" | 37 #include "bindings/modules/v8/V8NotificationAction.h" |
| 37 #include "core/dom/Document.h" | 38 #include "core/dom/Document.h" |
| 38 #include "core/dom/ExecutionContext.h" | 39 #include "core/dom/ExecutionContext.h" |
| 39 #include "core/dom/ExecutionContextTask.h" | 40 #include "core/dom/ExecutionContextTask.h" |
| 40 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" | 41 #include "core/dom/ScopedWindowFocusAllowedIndicator.h" |
| 41 #include "core/events/Event.h" | 42 #include "core/events/Event.h" |
| 42 #include "core/frame/UseCounter.h" | 43 #include "core/frame/UseCounter.h" |
| 43 #include "modules/notifications/NotificationAction.h" | 44 #include "modules/notifications/NotificationAction.h" |
| 44 #include "modules/notifications/NotificationData.h" | 45 #include "modules/notifications/NotificationData.h" |
| 45 #include "modules/notifications/NotificationManager.h" | 46 #include "modules/notifications/NotificationManager.h" |
| 46 #include "modules/notifications/NotificationOptions.h" | 47 #include "modules/notifications/NotificationOptions.h" |
| 47 #include "modules/notifications/NotificationPermissionClient.h" | 48 #include "modules/notifications/NotificationPermissionCallback.h" |
| 48 #include "modules/notifications/NotificationResourcesLoader.h" | 49 #include "modules/notifications/NotificationResourcesLoader.h" |
| 50 #include "modules/permissions/Permissions.h" | |
| 49 #include "platform/RuntimeEnabledFeatures.h" | 51 #include "platform/RuntimeEnabledFeatures.h" |
| 50 #include "platform/UserGestureIndicator.h" | 52 #include "platform/UserGestureIndicator.h" |
| 51 #include "public/platform/Platform.h" | 53 #include "public/platform/Platform.h" |
| 52 #include "public/platform/WebSecurityOrigin.h" | 54 #include "public/platform/WebSecurityOrigin.h" |
| 53 #include "public/platform/WebString.h" | |
| 54 #include "public/platform/modules/notifications/WebNotificationAction.h" | 55 #include "public/platform/modules/notifications/WebNotificationAction.h" |
| 55 #include "public/platform/modules/notifications/WebNotificationConstants.h" | 56 #include "public/platform/modules/notifications/WebNotificationConstants.h" |
| 56 #include "public/platform/modules/notifications/WebNotificationManager.h" | 57 #include "public/platform/modules/notifications/WebNotificationManager.h" |
| 57 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" | |
| 58 #include "wtf/Assertions.h" | 58 #include "wtf/Assertions.h" |
| 59 #include "wtf/Functional.h" | 59 #include "wtf/Functional.h" |
| 60 | 60 |
| 61 namespace blink { | 61 namespace blink { |
| 62 namespace { | 62 namespace { |
| 63 | 63 |
| 64 const int64_t kInvalidPersistentId = -1; | 64 const int64_t kInvalidPersistentId = -1; |
| 65 | 65 |
| 66 WebNotificationManager* notificationManager() | 66 WebNotificationManager* notificationManager() |
| 67 { | 67 { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } | 348 } |
| 349 | 349 |
| 350 String Notification::permission(ExecutionContext* context) | 350 String Notification::permission(ExecutionContext* context) |
| 351 { | 351 { |
| 352 return permissionString(NotificationManager::from(context)->permissionStatus ()); | 352 return permissionString(NotificationManager::from(context)->permissionStatus ()); |
| 353 } | 353 } |
| 354 | 354 |
| 355 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica tionPermissionCallback* deprecatedCallback) | 355 ScriptPromise Notification::requestPermission(ScriptState* scriptState, Notifica tionPermissionCallback* deprecatedCallback) |
| 356 { | 356 { |
| 357 ExecutionContext* context = scriptState->getExecutionContext(); | 357 ExecutionContext* context = scriptState->getExecutionContext(); |
| 358 if (NotificationPermissionClient* permissionClient = NotificationPermissionC lient::from(context)) | |
| 359 return permissionClient->requestPermission(scriptState, deprecatedCallba ck); | |
| 360 | 358 |
| 361 // The context has been detached. Return a promise that will never settle. | 359 mojom::blink::PermissionServicePtr permissionService; |
| 362 DCHECK(context->activeDOMObjectsAreStopped()); | 360 Permissions::connectToService(context, mojo::GetProxy(&permissionService)); |
| 363 | 361 |
| 364 return ScriptPromise(); | 362 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 363 ScriptPromise promise = resolver->promise(); | |
| 364 | |
| 365 mojom::blink::PermissionService* rawPermissionService = permissionService.ge t(); | |
| 366 rawPermissionService->RequestPermission( | |
|
esprehn
2016/08/12 23:24:32
I thought the Ptr wrapper could be called through
Reilly Grant (use Gerrit)
2016/08/12 23:28:59
The arguments will be evaluated before the object
| |
| 367 mojom::blink::PermissionName::NOTIFICATIONS, context->getSecurityOrigin( ), UserGestureIndicator::processingUserGesture(), | |
| 368 convertToBaseCallback(WTF::bind(&Notification::onPermissionRequestComple te, passed(std::move(permissionService)), wrapPersistent(resolver), wrapPersiste nt(deprecatedCallback)))); | |
| 369 | |
| 370 return promise; | |
| 365 } | 371 } |
| 366 | 372 |
| 367 size_t Notification::maxActions() | 373 size_t Notification::maxActions() |
| 368 { | 374 { |
| 369 return kWebNotificationMaxActions; | 375 return kWebNotificationMaxActions; |
| 370 } | 376 } |
| 371 | 377 |
| 372 DispatchEventResult Notification::dispatchEventInternal(Event* event) | 378 DispatchEventResult Notification::dispatchEventInternal(Event* event) |
| 373 { | 379 { |
| 374 DCHECK(getExecutionContext()->isContextThread()); | 380 DCHECK(getExecutionContext()->isContextThread()); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 390 | 396 |
| 391 if (m_loader) | 397 if (m_loader) |
| 392 m_loader->stop(); | 398 m_loader->stop(); |
| 393 } | 399 } |
| 394 | 400 |
| 395 bool Notification::hasPendingActivity() const | 401 bool Notification::hasPendingActivity() const |
| 396 { | 402 { |
| 397 return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isA ctive() || m_loader; | 403 return m_state == NotificationStateShowing || m_prepareShowMethodRunner->isA ctive() || m_loader; |
| 398 } | 404 } |
| 399 | 405 |
| 406 void Notification::onPermissionRequestComplete(mojom::blink::PermissionServicePt r permissionService, ScriptPromiseResolver* resolver, NotificationPermissionCall back* deprecatedCallback, mojom::blink::PermissionStatus status) | |
| 407 { | |
| 408 String statusString = permissionString(status); | |
| 409 if (deprecatedCallback) | |
| 410 deprecatedCallback->handleEvent(statusString); | |
| 411 | |
| 412 resolver->resolve(statusString); | |
| 413 } | |
| 414 | |
| 400 DEFINE_TRACE(Notification) | 415 DEFINE_TRACE(Notification) |
| 401 { | 416 { |
| 402 visitor->trace(m_prepareShowMethodRunner); | 417 visitor->trace(m_prepareShowMethodRunner); |
| 403 visitor->trace(m_loader); | 418 visitor->trace(m_loader); |
| 404 EventTargetWithInlineData::trace(visitor); | 419 EventTargetWithInlineData::trace(visitor); |
| 405 ActiveDOMObject::trace(visitor); | 420 ActiveDOMObject::trace(visitor); |
| 406 } | 421 } |
| 407 | 422 |
| 408 } // namespace blink | 423 } // namespace blink |
| OLD | NEW |