Chromium Code Reviews| Index: third_party/WebKit/Source/modules/sensor/Sensor.cpp |
| diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.cpp b/third_party/WebKit/Source/modules/sensor/Sensor.cpp |
| index 872afd786fdd7de5f4333a06813c33abd1eb43ad..716713c93032958ce442a110052e43f0a7b8632b 100644 |
| --- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp |
| +++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp |
| @@ -17,15 +17,40 @@ using namespace device::mojom::blink; |
| namespace blink { |
| -Sensor::Sensor(ExecutionContext* executionContext, const SensorOptions& sensorOptions, SensorType type) |
| +Sensor::Sensor(ScriptState* scriptState, const SensorOptions& sensorOptions, ExceptionState& exceptionState, SensorType type) |
| : ActiveScriptWrappable(this) |
| - , ContextLifecycleObserver(executionContext) |
| - , PageVisibilityObserver(toDocument(executionContext)->page()) |
| + , ContextLifecycleObserver(scriptState->getExecutionContext()) |
| + , PageVisibilityObserver(toDocument(scriptState->getExecutionContext())->page()) |
| , m_sensorOptions(sensorOptions) |
| , m_type(type) |
| , m_state(Sensor::SensorState::IDLE) |
| , m_storedData() |
| { |
| + // Check secure context. |
| + String errorMessage; |
| + if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { |
| + exceptionState.throwDOMException(SecurityError, errorMessage); |
| + return; |
| + } |
| + |
| + // Check top-level browsing context. |
| + if (!scriptState->domWindow() || !scriptState->domWindow()->frame() || !scriptState->domWindow()->frame()->isMainFrame()) { |
| + exceptionState.throwSecurityError("Must be in a top-level browsing context"); |
| + return; |
| + } |
| + |
| + // Check the given frequency value. |
| + if (m_sensorOptions.hasFrequency()) { |
| + double frequency = m_sensorOptions.frequency(); |
| + if (frequency <= 0.0) { |
| + exceptionState.throwRangeError("Frequency must be positive."); |
| + return; |
| + } |
| + // Cap to 60.0 Hz |
| + const double kMaxAllowedFrequency = 60.0; |
|
timvolodine
2016/09/19 16:52:13
think this should be a more 'global' constant some
Mikhail
2016/09/20 13:29:37
Done.
|
| + if (frequency > kMaxAllowedFrequency) |
| + m_sensorOptions.setFrequency(kMaxAllowedFrequency); |
| + } |
|
timvolodine
2016/09/19 16:52:13
don't know what the spec says here, maybe output s
Mikhail
2016/09/20 13:29:37
Done.
|
| } |
| Sensor::~Sensor() = default; |