| Index: Source/modules/permissions/Permissions.cpp
|
| diff --git a/Source/modules/permissions/Permissions.cpp b/Source/modules/permissions/Permissions.cpp
|
| index cd5771c131025dad4981beed50033b314516c32b..7a773ea8e1763c9a03050d6a6261fa944d07b320 100644
|
| --- a/Source/modules/permissions/Permissions.cpp
|
| +++ b/Source/modules/permissions/Permissions.cpp
|
| @@ -6,24 +6,71 @@
|
| #include "modules/permissions/Permissions.h"
|
|
|
| #include "bindings/core/v8/ScriptPromise.h"
|
| +#include "bindings/core/v8/ScriptPromiseResolver.h"
|
| #include "core/dom/DOMException.h"
|
| +#include "core/dom/Document.h"
|
| #include "core/dom/ExceptionCode.h"
|
| +#include "modules/permissions/PermissionController.h"
|
| +#include "modules/permissions/PermissionQueryCallback.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/modules/permissions/WebPermissionClient.h"
|
|
|
| namespace blink {
|
|
|
| -Permissions::~Permissions()
|
| +namespace {
|
| +
|
| +WebPermissionClient* permissionClient(ExecutionContext* executionContext)
|
| {
|
| + if (executionContext->isDocument()) {
|
| + Document* document = toDocument(executionContext);
|
| + if (!document->frame())
|
| + return nullptr;
|
| + PermissionController* controller = PermissionController::from(*document->frame());
|
| + return controller ? controller->client() : nullptr;
|
| + }
|
| + return Platform::current()->permissionClient();
|
| }
|
|
|
| -DEFINE_TRACE(Permissions)
|
| +} // anonymous namespace
|
| +
|
| +Permissions::~Permissions()
|
| {
|
| }
|
|
|
| // static
|
| ScriptPromise Permissions::query(ScriptState* scriptState, const AtomicString& permissionName)
|
| {
|
| - // FIXME: implement.
|
| - return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "Feature not yet supported."));
|
| + WebPermissionClient* client = permissionClient(scriptState->executionContext());
|
| + if (!client)
|
| + return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions."));
|
| +
|
| + WebPermissionType type;
|
| + if (permissionName == "geolocation") {
|
| + type = WebPermissionTypeGeolocation;
|
| + } else if (permissionName == "notifications") {
|
| + type = WebPermissionTypeNotifications;
|
| + } else if (permissionName == "push-notifications") {
|
| + type = WebPermissionTypePushNotifications;
|
| + } else if (permissionName == "midi-sysex") {
|
| + type = WebPermissionTypeMidiSysEx;
|
| + } else {
|
| + ASSERT_NOT_REACHED();
|
| + type = WebPermissionTypeGeolocation;
|
| + }
|
| +
|
| + RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
|
| + ScriptPromise promise = resolver->promise();
|
| +
|
| + // If the current origin is a file scheme, it will unlikely return a
|
| + // meaningful value because most APIs are broken on file scheme and no
|
| + // permission prompt will be shown even if the returned permission will most
|
| + // likely be "prompt".
|
| + client->queryPermission(type, KURL(KURL(), scriptState->executionContext()->securityOrigin()->toString()), new PermissionQueryCallback(resolver, type));
|
| + return promise;
|
| +}
|
| +
|
| +DEFINE_TRACE(Permissions)
|
| +{
|
| }
|
|
|
| } // namespace blink
|
|
|