V8NotificationCenterCustom.cpp [plain text]
#include "config.h"
#if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)
#include "V8NotificationCenter.h"
#include "ExceptionCode.h"
#include "NotImplemented.h"
#include "Notification.h"
#include "NotificationCenter.h"
#include "V8Binding.h"
#include "V8CustomVoidCallback.h"
#include "V8EventListener.h"
#include "V8Notification.h"
#include "V8Proxy.h"
#include "V8Utilities.h"
#include "WorkerContext.h"
namespace WebCore {
v8::Handle<v8::Value> V8NotificationCenter::createHTMLNotificationCallback(const v8::Arguments& args)
{
INC_STATS("DOM.NotificationCenter.CreateHTMLNotification()");
NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder());
ExceptionCode ec = 0;
String url = toWebCoreString(args[0]);
RefPtr<Notification> notification = notificationCenter->createHTMLNotification(url, ec);
if (ec)
return throwError(ec);
notification->ref();
return toV8(notification.get(), args.GetIsolate());
}
v8::Handle<v8::Value> V8NotificationCenter::createNotificationCallback(const v8::Arguments& args)
{
INC_STATS("DOM.NotificationCenter.CreateNotification()");
NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder());
ExceptionCode ec = 0;
RefPtr<Notification> notification = notificationCenter->createNotification(toWebCoreString(args[0]), toWebCoreString(args[1]), toWebCoreString(args[2]), ec);
if (ec)
return throwError(ec);
notification->ref();
return toV8(notification.get(), args.GetIsolate());
}
v8::Handle<v8::Value> V8NotificationCenter::requestPermissionCallback(const v8::Arguments& args)
{
INC_STATS("DOM.NotificationCenter.RequestPermission()");
NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder());
ScriptExecutionContext* context = notificationCenter->scriptExecutionContext();
if (!context)
return throwError(INVALID_STATE_ERR);
if (context->isWorkerContext())
return throwError(NOT_SUPPORTED_ERR);
RefPtr<V8CustomVoidCallback> callback;
if (args.Length() > 0) {
if (!args[0]->IsObject())
return throwError("Callback must be of valid type.", V8Proxy::TypeError);
callback = V8CustomVoidCallback::create(args[0], context);
}
notificationCenter->requestPermission(callback.release());
return v8::Undefined();
}
}
#endif // ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS)