v8::Handle<v8::Value> V8NotificationCenter::requestPermissionCallback(const v8::Arguments& args)
{
    INC_STATS(L"DOM.NotificationCenter.RequestPermission()");
    NotificationCenter* notificationCenter = V8NotificationCenter::toNative(args.Holder());
    ScriptExecutionContext* context = notificationCenter->context();

    // Make sure that script execution context is valid.
    if (!context)
        return throwError(INVALID_STATE_ERR);

    // Requesting permission is only valid from a page context.
    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();
}
JSValue JSNotificationCenter::requestPermission(ExecState* exec, const ArgList& args)
{
    // Permission request is only valid from page context.
    ScriptExecutionContext* context = impl()->context();
    if (context->isWorkerContext())
        return throwError(exec, SyntaxError);

    if (!args.at(0).isObject())
        return throwError(exec, TypeError);

    PassRefPtr<JSCustomVoidCallback> callback = JSCustomVoidCallback::create(args.at(0).getObject(), toJSDOMGlobalObject(static_cast<Document*>(context), exec));

    impl()->requestPermission(callback);
    return jsUndefined();
}
Exemplo n.º 3
0
JSValue JSNotificationCenter::requestPermission(ExecState* exec)
{
    ScriptExecutionContext* context = impl()->scriptExecutionContext();

    // Make sure that script execution context is valid.
    if (!context) {
        setDOMException(exec, INVALID_STATE_ERR);
        return jsUndefined();
    }

    // Permission request is only valid from page context.
    if (context->isWorkerContext())
        return throwSyntaxError(exec);

    // If a callback function is provided as first argument, convert to a VoidCallback.
    RefPtr<JSVoidCallback> callback;
    if (exec->argument(0).isObject()) {
        callback = JSVoidCallback::create(exec->argument(0).getObject(), toJSDOMGlobalObject(static_cast<Document*>(context), exec));
        if (exec->hadException())
            return jsUndefined();
    }
    impl()->requestPermission(callback.release());
    return jsUndefined();
}