| Index: third_party/WebKit/Source/modules/sensor/AmbientLightSensor.cpp
|
| diff --git a/third_party/WebKit/Source/modules/sensor/AmbientLightSensor.cpp b/third_party/WebKit/Source/modules/sensor/AmbientLightSensor.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a333944048fb8e5b1b4200fe1f79c05384892f99
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/sensor/AmbientLightSensor.cpp
|
| @@ -0,0 +1,92 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "modules/sensor/AmbientLightSensor.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/events/Event.h"
|
| +
|
| +#include "modules/sensor/AmbientLightSensorDispatcher.h"
|
| +#include "modules/sensor/AmbientLightSensorReading.h"
|
| +#include "modules/sensor/SensorReadingEvent.h"
|
| +
|
| +namespace blink {
|
| +
|
| +// static
|
| +AmbientLightSensor* AmbientLightSensor::create(ExecutionContext* context, SensorOptions sensorOptions, ExceptionState& exceptionState)
|
| +{
|
| + AmbientLightSensor* sensor = new AmbientLightSensor(context, sensorOptions);
|
| + sensor->suspendIfNeeded();
|
| + return sensor;
|
| +}
|
| +
|
| +// static
|
| +AmbientLightSensor* AmbientLightSensor::create(ExecutionContext* context, ExceptionState& exceptionState)
|
| +{
|
| + return create(context, SensorOptions(), exceptionState);
|
| +}
|
| +
|
| +AmbientLightSensor::~AmbientLightSensor()
|
| +{
|
| + stopUpdating();
|
| +}
|
| +
|
| +AmbientLightSensor::AmbientLightSensor(ExecutionContext* executionContext, SensorOptions sensorOptions)
|
| + : Sensor(executionContext, sensorOptions)
|
| +{
|
| +}
|
| +
|
| +AmbientLightSensorReading& AmbientLightSensor::reading()
|
| +{
|
| + return *m_lightReading.get();
|
| +}
|
| +
|
| +void AmbientLightSensor::didUpdateData()
|
| +{
|
| + if (!m_lightReading)
|
| + m_lightReading = AmbientLightSensorReading::create();
|
| +
|
| + AmbientLightSensorReadingProxy oldReading(m_lightReading.get()->timeStamp(), m_lightReading.get()->illuminance());
|
| + AmbientLightSensorReadingProxy currentReading = *AmbientLightSensorDispatcher::instance().latestData();
|
| +
|
| + Document* document = toDocument(getExecutionContext());
|
| + DCHECK(document);
|
| +
|
| + if (document->activeDOMObjectsAreSuspended() || document->activeDOMObjectsAreStopped())
|
| + return;
|
| +
|
| + m_lightReading.get()->setTimeStamp(currentReading.timeStamp);
|
| + m_lightReading.get()->setIlluminance(currentReading.illuminance);
|
| +
|
| + // TODO(riju) : Implement threshold when it is specs.
|
| + if (currentReading.illuminance != oldReading.illuminance)
|
| + dispatchEvent(SensorReadingEvent::create(EventTypeNames::change, *m_lightReading.get()));
|
| +}
|
| +
|
| +void AmbientLightSensor::registerWithDispatcher()
|
| +{
|
| + AmbientLightSensorDispatcher::instance().addController(this);
|
| +}
|
| +
|
| +void AmbientLightSensor::unregisterWithDispatcher()
|
| +{
|
| + AmbientLightSensorDispatcher::instance().removeController(this);
|
| +}
|
| +
|
| +bool AmbientLightSensor::hasLastData()
|
| +{
|
| + return AmbientLightSensorDispatcher::instance().latestData();
|
| +}
|
| +
|
| +DEFINE_TRACE(AmbientLightSensor)
|
| +{
|
| + ActiveDOMObject::trace(visitor);
|
| + Sensor::trace(visitor);
|
| + visitor->trace(m_lightReading);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|