ScriptPromise Permissions::request(ScriptState* scriptState, const Dictionary& rawPermission)
{
    WebPermissionClient* client = getClient(scriptState->getExecutionContext());
    if (!client)
        return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions."));

    ExceptionState exceptionState(ExceptionState::GetterContext,  "request", "Permissions", scriptState->context()->Global(), scriptState->isolate());
    Nullable<WebPermissionType> type = parsePermission(scriptState, rawPermission, exceptionState);
    if (exceptionState.hadException())
        return exceptionState.reject(scriptState);

    ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
    ScriptPromise promise = resolver->promise();

    client->requestPermission(type.get(), KURL(KURL(), scriptState->getExecutionContext()->getSecurityOrigin()->toString()), new PermissionCallback(resolver, type.get()));
    return promise;
}
Exemplo n.º 2
0
ScriptPromise Permissions::request(ScriptState* scriptState, const Dictionary& rawPermission)
{
    WebPermissionClient* client = getClient(scriptState->executionContext());
    if (!client)
        return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions."));

    TrackExceptionState exceptionState;
    PermissionDescriptor permission = NativeValueTraits<PermissionDescriptor>::nativeValue(scriptState->isolate(), rawPermission.v8Value(), exceptionState);

    if (exceptionState.hadException())
        return ScriptPromise::reject(scriptState, v8::Exception::TypeError(v8String(scriptState->isolate(), exceptionState.message())));

    ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
    ScriptPromise promise = resolver->promise();

    WebPermissionType type = getPermissionType(scriptState, rawPermission, permission, exceptionState);
    if (handleNotSupportedPermission(scriptState, rawPermission, resolver, type, exceptionState))
        return promise;

    client->requestPermission(type, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new PermissionCallback(resolver, type));
    return promise;
}