Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 client->queryPermission(type, KURL(KURL(), scriptState->executionContext()-> securityOrigin()->toString()), new PermissionQueryCallback(resolver, type)); | |
|
jochen (gone - plz use gerrit)
2015/03/10 13:16:42
what happens if you use the permission API on file
mlamouri (slow - plz ping)
2015/03/11 10:56:57
Good point. I would not say that it does not work
| |
| 65 return promise; | |
| 66 } | |
| 67 | |
| 18 DEFINE_TRACE(Permissions) | 68 DEFINE_TRACE(Permissions) |
| 19 { | 69 { |
| 20 } | 70 } |
| 21 | 71 |
| 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 | 72 } // namespace blink |
| OLD | NEW |