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

Side by Side Diff: Source/modules/permissions/Permissions.cpp

Issue 804553003: Implement Permissions.query() and static PermissionStatus. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: review comments Created 5 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/permissions/Permissions.h" 6 #include "modules/permissions/Permissions.h"
7 7
8 #include "bindings/core/v8/ScriptPromise.h" 8 #include "bindings/core/v8/ScriptPromise.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h"
9 #include "core/dom/DOMException.h" 10 #include "core/dom/DOMException.h"
11 #include "core/dom/Document.h"
10 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "modules/permissions/PermissionController.h"
14 #include "modules/permissions/PermissionQueryCallback.h"
15 #include "public/platform/Platform.h"
16 #include "public/platform/modules/permissions/WebPermissionClient.h"
11 17
12 namespace blink { 18 namespace blink {
13 19
20 namespace {
21
22 WebPermissionClient* permissionClient(ExecutionContext* executionContext)
23 {
24 if (executionContext->isDocument()) {
25 Document* document = toDocument(executionContext);
26 if (!document->frame())
27 return nullptr;
28 PermissionController* controller = PermissionController::from(*document- >frame());
29 return controller ? controller->client() : nullptr;
30 }
31 return Platform::current()->permissionClient();
32 }
33
34 } // anonymous namespace
35
14 Permissions::~Permissions() 36 Permissions::~Permissions()
15 { 37 {
16 } 38 }
17 39
40 // static
41 ScriptPromise Permissions::query(ScriptState* scriptState, const AtomicString& p ermissionName)
42 {
43 WebPermissionClient* client = permissionClient(scriptState->executionContext ());
44 if (!client)
45 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidStateError, "In its current state, the global scope can't query pe rmissions."));
46
47 WebPermissionType type;
48 if (permissionName == "geolocation") {
49 type = WebPermissionTypeGeolocation;
50 } else if (permissionName == "notifications") {
51 type = WebPermissionTypeNotifications;
52 } else if (permissionName == "push-notifications") {
53 type = WebPermissionTypePushNotifications;
54 } else if (permissionName == "midi-sysex") {
55 type = WebPermissionTypeMidiSysEx;
56 } else {
57 ASSERT_NOT_REACHED();
58 type = WebPermissionTypeGeolocation;
59 }
60
61 RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scrip tState);
62 ScriptPromise promise = resolver->promise();
63
64 // If the current origin is a file scheme, it will unlikely return a
65 // meaningful value because most APIs are broken on file scheme and no
66 // permission prompt will be shown even if the returned permission will most
67 // likely be "prompt".
68 client->queryPermission(type, KURL(KURL(), scriptState->executionContext()-> securityOrigin()->toString()), new PermissionQueryCallback(resolver, type));
69 return promise;
70 }
71
18 DEFINE_TRACE(Permissions) 72 DEFINE_TRACE(Permissions)
19 { 73 {
20 } 74 }
21 75
22 // static
23 ScriptPromise Permissions::query(ScriptState* scriptState, const AtomicString& p ermissionName)
24 {
25 // FIXME: implement.
26 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "Feature not yet supported."));
27 }
28
29 } // namespace blink 76 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/permissions/PermissionStatus.cpp ('k') | Source/modules/permissions/Permissions.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698