Chromium Code Reviews| Index: Source/modules/push_messaging/PushPermissionCallback.cpp |
| diff --git a/Source/modules/push_messaging/PushPermissionCallback.cpp b/Source/modules/push_messaging/PushPermissionCallback.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5c28f5b7268a59a3cfc86447ce313c35a2b78f1a |
| --- /dev/null |
| +++ b/Source/modules/push_messaging/PushPermissionCallback.cpp |
| @@ -0,0 +1,53 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "modules/push_messaging/PushPermissionCallback.h" |
| + |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "core/dom/ExceptionCode.h" |
| +#include "wtf/text/WTFString.h" |
| + |
| +namespace blink { |
| + |
| +PushPermissionCallback::PushPermissionCallback(PassRefPtr<ScriptPromiseResolver> script_resolver) |
|
Peter Beverloo
2014/10/23 11:33:37
s/script_resolver/scriptResolver/. Or just "resolv
Miguel Garcia
2014/10/23 13:59:51
Done.
|
| + : m_resolver(script_resolver) |
| +{ |
| +} |
| + |
| +PushPermissionCallback::~PushPermissionCallback() |
| +{ |
| +} |
| + |
| +// static |
| +const String& PushPermissionCallback::permissionString(WebPushPermissionStatus status) |
|
Peter Beverloo
2014/10/23 11:33:37
nit: move this to the last definition in the file
Miguel Garcia
2014/10/23 13:59:51
Done.
|
| +{ |
| + DEFINE_STATIC_LOCAL(const String, grantedPermission, ("granted")); |
| + DEFINE_STATIC_LOCAL(const String, deniedPermission, ("denied")); |
| + DEFINE_STATIC_LOCAL(const String, defaultPermission, ("default")); |
| + |
| + switch (status) { |
| + case WebPushPermissionStatusGranted: |
| + return grantedPermission; |
| + case WebPushPermissionStatusDenied: |
| + return deniedPermission; |
| + case WebPushPermissionStatusDefault: |
| + return defaultPermission; |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return deniedPermission; |
| +} |
| + |
| +void PushPermissionCallback::onSuccess(WebPushPermissionStatus status) |
| +{ |
| + m_resolver->resolve(permissionString(status)); |
| +} |
| + |
| +void PushPermissionCallback::onError() |
| +{ |
| + m_resolver->reject(); |
| +} |
| + |
| +} // namespace blink |