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..05b6dbbae0efd4729f6e502eee413715cb196dd6 |
--- /dev/null |
+++ b/Source/modules/push_messaging/PushPermissionCallback.cpp |
@@ -0,0 +1,55 @@ |
+// 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/DOMException.h" |
+#include "core/dom/ExceptionCode.h" |
+#include "wtf/text/WTFString.h" |
+ |
Peter Beverloo
2014/10/20 12:23:49
nit: excess newline.
Miguel Garcia
2014/10/22 12:58:43
Acknowledged.
|
+ |
+namespace blink { |
+ |
+PushPermissionCallback::PushPermissionCallback(PassRefPtr<ScriptPromiseResolver> script_resolver) : |
Peter Beverloo
2014/10/20 12:23:49
nit: The colon needs to be on the next line.
Miguel Garcia
2014/10/22 12:58:43
Acknowledged.
|
+ m_resolver(script_resolver) |
+{ |
+} |
+ |
+PushPermissionCallback::~PushPermissionCallback() |
+{ |
+} |
+ |
Peter Beverloo
2014/10/20 12:23:49
nit: excess newline.
Miguel Garcia
2014/10/22 12:58:43
Acknowledged.
|
+ |
+/* static */ const String& PushPermissionCallback::permissionString(PushPermissionStatus type) |
Michael van Ouwerkerk
2014/10/20 11:25:42
We don't tend to comment on static in cpp files in
Peter Beverloo
2014/10/20 12:23:49
s/type/status/.
Miguel Garcia
2014/10/22 12:58:43
Done.
Miguel Garcia
2014/10/22 12:58:43
Done.
|
+{ |
+ DEFINE_STATIC_LOCAL(const String, grantedPermission, ("granted")); |
+ DEFINE_STATIC_LOCAL(const String, deniedPermission, ("denied")); |
+ DEFINE_STATIC_LOCAL(const String, defaultPermission, ("default")); |
+ |
+ switch (type) { |
+ case PushPermissionStatus::PushPermissionGranted: |
+ return grantedPermission; |
+ case PushPermissionStatus::PushPermissionDenied: |
+ return deniedPermission; |
+ case PushPermissionStatus::PushPermissionDefault: |
+ return defaultPermission; |
+ } |
+ |
+ ASSERT_NOT_REACHED(); |
+ return deniedPermission; |
+} |
+ |
+void PushPermissionCallback::onSuccess(PushPermissionStatus type) |
Peter Beverloo
2014/10/20 12:23:49
s/type/status/.
Miguel Garcia
2014/10/22 12:58:43
Done.
|
+{ |
+ m_resolver->resolve(permissionString(type)); |
+} |
+ |
+void PushPermissionCallback::onError() |
+{ |
+ m_resolver->reject(DOMException::create(OperationError, "Could not check permission")); |
Michael van Ouwerkerk
2014/10/20 11:25:42
Again, this diverges from the spec so please open
Peter Beverloo
2014/10/20 12:23:49
I don't think having an OperationError saying "Cou
Miguel Garcia
2014/10/22 12:58:43
I will just reject here for now then.
On 2014/10/
Miguel Garcia
2014/10/22 12:58:43
Acknowledged.
|
+} |
+ |
+} // namespace blink |