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 "modules/permissions/Permissions.h" | 5 #include "modules/permissions/Permissions.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "bindings/core/v8/Nullable.h" | 9 #include "bindings/core/v8/Nullable.h" |
| 10 #include "bindings/core/v8/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
| 11 #include "bindings/core/v8/ScriptPromiseResolver.h" | 11 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 12 #include "bindings/modules/v8/V8MidiPermissionDescriptor.h" | 12 #include "bindings/modules/v8/V8MidiPermissionDescriptor.h" |
| 13 #include "bindings/modules/v8/V8PermissionDescriptor.h" | 13 #include "bindings/modules/v8/V8PermissionDescriptor.h" |
| 14 #include "bindings/modules/v8/V8PushPermissionDescriptor.h" | 14 #include "bindings/modules/v8/V8PushPermissionDescriptor.h" |
| 15 #include "core/dom/DOMException.h" | 15 #include "core/dom/DOMException.h" |
| 16 #include "core/dom/Document.h" | 16 #include "core/dom/Document.h" |
| 17 #include "core/dom/ExceptionCode.h" | 17 #include "core/dom/ExceptionCode.h" |
| 18 #include "core/dom/ExecutionContext.h" | 18 #include "core/dom/ExecutionContext.h" |
| 19 #include "core/frame/LocalFrame.h" | 19 #include "core/frame/LocalFrame.h" |
| 20 #include "modules/permissions/PermissionDescriptor.h" | 20 #include "modules/permissions/PermissionDescriptor.h" |
| 21 #include "modules/permissions/PermissionStatus.h" | 21 #include "modules/permissions/PermissionStatus.h" |
| 22 #include "modules/permissions/PermissionUtils.h" | 22 #include "modules/permissions/PermissionUtils.h" |
| 23 #include "platform/RuntimeEnabledFeatures.h" | |
| 23 #include "platform/UserGestureIndicator.h" | 24 #include "platform/UserGestureIndicator.h" |
| 24 #include "platform/wtf/Functional.h" | 25 #include "platform/wtf/Functional.h" |
| 25 #include "platform/wtf/NotFound.h" | 26 #include "platform/wtf/NotFound.h" |
| 26 #include "platform/wtf/PtrUtil.h" | 27 #include "platform/wtf/PtrUtil.h" |
| 27 #include "platform/wtf/Vector.h" | 28 #include "platform/wtf/Vector.h" |
| 28 #include "public/platform/Platform.h" | 29 #include "public/platform/Platform.h" |
| 29 | 30 |
| 30 namespace blink { | 31 namespace blink { |
| 31 | 32 |
| 32 using mojom::blink::PermissionDescriptorPtr; | 33 using mojom::blink::PermissionDescriptorPtr; |
| 33 using mojom::blink::PermissionName; | 34 using mojom::blink::PermissionName; |
| 34 using mojom::blink::PermissionService; | 35 using mojom::blink::PermissionService; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 39 bool IsSensorRuntimeFlagEnabled(ExceptionState& exception_state) { | |
| 40 if (!RuntimeEnabledFeatures::sensorEnabled()) { | |
| 41 exception_state.ThrowTypeError("GenericSensor flag is not enabled."); | |
| 42 return false; | |
| 43 } | |
| 44 return true; | |
| 45 } | |
| 46 | |
| 38 // Parses the raw permission dictionary and returns the Mojo | 47 // Parses the raw permission dictionary and returns the Mojo |
| 39 // PermissionDescriptor if parsing was successful. If an exception occurs, it | 48 // PermissionDescriptor if parsing was successful. If an exception occurs, it |
| 40 // will be stored in |exceptionState| and null will be returned. Therefore, the | 49 // will be stored in |exceptionState| and null will be returned. Therefore, the |
| 41 // |exceptionState| should be checked before attempting to use the returned | 50 // |exceptionState| should be checked before attempting to use the returned |
| 42 // permission as the non-null assert will be fired otherwise. | 51 // permission as the non-null assert will be fired otherwise. |
| 43 // | 52 // |
| 44 // Websites will be able to run code when `name()` is called, changing the | 53 // Websites will be able to run code when `name()` is called, changing the |
| 45 // current context. The caller should make sure that no assumption is made | 54 // current context. The caller should make sure that no assumption is made |
| 46 // after this has been called. | 55 // after this has been called. |
| 47 PermissionDescriptorPtr ParsePermission(ScriptState* script_state, | 56 PermissionDescriptorPtr ParsePermission(ScriptState* script_state, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 } | 93 } |
| 85 if (name == "midi") { | 94 if (name == "midi") { |
| 86 MidiPermissionDescriptor midi_permission = | 95 MidiPermissionDescriptor midi_permission = |
| 87 NativeValueTraits<MidiPermissionDescriptor>::NativeValue( | 96 NativeValueTraits<MidiPermissionDescriptor>::NativeValue( |
| 88 script_state->GetIsolate(), raw_permission.V8Value(), | 97 script_state->GetIsolate(), raw_permission.V8Value(), |
| 89 exception_state); | 98 exception_state); |
| 90 return CreateMidiPermissionDescriptor(midi_permission.sysex()); | 99 return CreateMidiPermissionDescriptor(midi_permission.sysex()); |
| 91 } | 100 } |
| 92 if (name == "background-sync") | 101 if (name == "background-sync") |
| 93 return CreatePermissionDescriptor(PermissionName::BACKGROUND_SYNC); | 102 return CreatePermissionDescriptor(PermissionName::BACKGROUND_SYNC); |
| 103 // TODO(riju): Remove runtime flag check when Generic Sensor feature is | |
| 104 // stable. | |
| 105 if (name == "ambient-light-sensor" && | |
| 106 IsSensorRuntimeFlagEnabled(exception_state)) | |
|
mlamouri (slow - plz ping)
2017/04/20 13:26:32
Instead of checking for the flag N times, could yo
riju_
2017/07/19 06:56:46
Done.
| |
| 107 return CreatePermissionDescriptor(PermissionName::AMBIENT_LIGHT_SENSOR); | |
| 108 if (name == "accelerometer" && IsSensorRuntimeFlagEnabled(exception_state)) | |
| 109 return CreatePermissionDescriptor(PermissionName::ACCELEROMETER); | |
| 110 if (name == "gyroscope" && IsSensorRuntimeFlagEnabled(exception_state)) | |
| 111 return CreatePermissionDescriptor(PermissionName::GYROSCOPE); | |
| 112 if (name == "magnetometer" && IsSensorRuntimeFlagEnabled(exception_state)) | |
| 113 return CreatePermissionDescriptor(PermissionName::MAGNETOMETER); | |
| 94 | 114 |
| 95 return nullptr; | 115 return nullptr; |
| 96 } | 116 } |
| 97 | 117 |
| 98 } // anonymous namespace | 118 } // anonymous namespace |
| 99 | 119 |
| 100 ScriptPromise Permissions::query(ScriptState* script_state, | 120 ScriptPromise Permissions::query(ScriptState* script_state, |
| 101 const Dictionary& raw_permission) { | 121 const Dictionary& raw_permission) { |
| 102 ExceptionState exception_state(script_state->GetIsolate(), | 122 ExceptionState exception_state(script_state->GetIsolate(), |
| 103 ExceptionState::kGetterContext, "Permissions", | 123 ExceptionState::kGetterContext, "Permissions", |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 result.ReserveInitialCapacity(caller_index_to_internal_index.size()); | 319 result.ReserveInitialCapacity(caller_index_to_internal_index.size()); |
| 300 for (int internal_index : caller_index_to_internal_index) { | 320 for (int internal_index : caller_index_to_internal_index) { |
| 301 result.push_back(PermissionStatus::CreateAndListen( | 321 result.push_back(PermissionStatus::CreateAndListen( |
| 302 resolver->GetExecutionContext(), results[internal_index], | 322 resolver->GetExecutionContext(), results[internal_index], |
| 303 descriptors[internal_index]->Clone())); | 323 descriptors[internal_index]->Clone())); |
| 304 } | 324 } |
| 305 resolver->Resolve(result); | 325 resolver->Resolve(result); |
| 306 } | 326 } |
| 307 | 327 |
| 308 } // namespace blink | 328 } // namespace blink |
| OLD | NEW |