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