Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1457)

Unified Diff: Source/modules/push_messaging/PushPermissionCallback.cpp

Issue 658723003: Blink implementation of PushManager#hasPermission() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rename enum to a more understandable name Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0358cb65eb4defbd2a63773e071f7b228a43f150
--- /dev/null
+++ b/Source/modules/push_messaging/PushPermissionCallback.cpp
@@ -0,0 +1,56 @@
+// 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"
+
mlamouri (slow - plz ping) 2014/10/17 09:22:01 nit: no new line between "config.h" and the header
Miguel Garcia 2014/10/20 09:58:10 Done.
+#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"
+
+
+namespace blink {
+
+PushPermissionCallback::PushPermissionCallback(PassRefPtr<ScriptPromiseResolver> script_resolver) :
+ m_resolver(script_resolver)
+{
+}
+
+PushPermissionCallback::~PushPermissionCallback()
+{
+}
+
+
+/* static */ const String& PushPermissionCallback::permissionString(PushPermissionStatus type)
+{
+ DEFINE_STATIC_LOCAL(const String, grantedPermission, ("granted"));
+ DEFINE_STATIC_LOCAL(const String, deniedPermission, ("denied"));
+ DEFINE_STATIC_LOCAL(const String, defaultPermission, ("default"));
mlamouri (slow - plz ping) 2014/10/17 09:22:01 I think "default" is an unfortunate name :(
Miguel Garcia 2014/10/20 09:58:10 not much I can do here talk to Michael, he is a sp
+
+ 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)
+{
+ m_resolver->resolve(permissionString(type));
mlamouri (slow - plz ping) 2014/10/17 09:22:01 Actually, do you really need permissionString() to
Miguel Garcia 2014/10/20 09:58:10 It seems nicer but this is just a matter of tase (
+}
+
+void PushPermissionCallback::onError()
+{
+ m_resolver->reject(DOMException::create(SecurityError, "Could not check permission"));
mlamouri (slow - plz ping) 2014/10/17 09:22:01 I would not use SecurityError because this isn't a
Miguel Garcia 2014/10/20 09:58:10 OperationError ?
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698