Commit a7e4b7e2 authored by iclelland's avatar iclelland Committed by Commit bot

Revert of [sensors] Ambient light sensor bindings implementation (patchset #5...

Revert of [sensors] Ambient light sensor bindings implementation (patchset #5 id:80001 of https://codereview.chromium.org/2332323002/ )

Reason for revert:
Sorry for the revert -- two new tests are failing immediately on several Blink bots:
sensor/mock-sensor.html
sensor/ambient-light-sensor.html

See
https://test-results.appspot.com/dashboards/flakiness_dashboard.html#tests=sensor%2Fambient-light-sensor.html%2C%20sensor%2Fmock-sensor.html

First failed build on MacOS 10.10:
https://build.chromium.org/p/chromium.webkit/builders/WebKit%20Mac10.10/builds/23859

Original issue's description:
> [sensors] Ambient light sensor bindings implementation
>
> This patch implements AmbientLightSensor [1] blink bindings and adds
> LayoutTest helpers for testing sensors that are based on Generic Sensor API.
>
> Following layout tests added to test new functionality:
> IDL tests.
>  - third_party/WebKit/LayoutTests/sensor/idl-AmbientLightSensor.html
>  - third_party/WebKit/LayoutTests/sensor/idl-AmbientLightSensorReading.html
> AmbientLightSensor tests.
>  - third_party/WebKit/LayoutTests/sensor/ambient-light-sensor.html
>
> Intent to Implement:
> https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/TkfdVqYAYiE/xLGN2b1-AAAJ
>
> [1] ED specification for Ambient Light Sensor http://w3c.github.io/ambient-light/
>
> BUG=606766
>
> Committed: https://crrev.com/c457d06894e8f01b24ae83750203fb5d8819c560
> Cr-Commit-Position: refs/heads/master@{#419438}

TBR=jochen@chromium.org,haraken@chromium.org,mikhail.pozdnyakov@intel.com,rijubrata.bhaumik@intel.com,timvolodine@chromium.org,alexander.shalamov@intel.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=606766

Review-Url: https://codereview.chromium.org/2348333002
Cr-Commit-Position: refs/heads/master@{#419453}
parent 5cc683b9
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/mojo-helpers.js"></script>
<script src="resources/sensor-helpers.js"></script>
<script>
'use strict';
if (!window.testRunner)
debug('This test cannot be run without the TestRunner');
const kDefaultReadingValue = 3.1415;
function update_sensor_reading(buffer) {
buffer[0] = window.performance.now();
buffer[1] = kDefaultReadingValue;
}
sensor_test(sensor => {
let ambientLightSensor = new AmbientLightSensor({frequency: 60});
ambientLightSensor.start();
let testPromise = sensor.mockSensorProvider.getCreatedSensor()
.then((mockSensor) => {
return new Promise((resolve, reject) => {
ambientLightSensor.onstatechange = event => {
if (ambientLightSensor.state === 'idle') {
resolve(mockSensor);
}
if (ambientLightSensor.state === 'active') {
ambientLightSensor.stop();
}
};
ambientLightSensor.onerror = reject;
});
})
.then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
return testPromise;
}, 'Test that sensor can be successfully created if sensor is supported.');
sensor_test(sensor => {
let ambientLightSensor = new AmbientLightSensor();
ambientLightSensor.start();
let testPromise = sensor.mockSensorProvider.getCreatedSensor()
.then((mockSensor) => {
return new Promise((resolve, reject) => {
ambientLightSensor.onstatechange = event => {
if (ambientLightSensor.state === 'idle') {
resolve(mockSensor);
}
if (ambientLightSensor.state === 'active') {
ambientLightSensor.stop();
}
};
ambientLightSensor.onerror = reject;
});
})
.then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
return testPromise;
}, 'Test that sensor can be constructed with default configuration.');
sensor_test(sensor => {
let ambientLightSensor = new AmbientLightSensor({frequency: 60});
ambientLightSensor.start();
let testPromise = sensor.mockSensorProvider.getCreatedSensor()
.then(mockSensor => { return mockSensor.addConfigurationCalled(); })
.then(mockSensor => {
return new Promise((resolve, reject) => {
ambientLightSensor.onstatechange = event => {
if (ambientLightSensor.state === 'idle') {
resolve(mockSensor);
}
if (ambientLightSensor.state === 'active') {
ambientLightSensor.stop();
}
};
});
})
.then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
return testPromise;
}, 'Test that addConfiguration and removeConfiguration is called.');
sensor_test(sensor => {
let ambientLightSensor = new AmbientLightSensor({frequency: 60});
ambientLightSensor.start();
let testPromise = sensor.mockSensorProvider.getCreatedSensor()
.then(mockSensor => {
return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
})
.then((mockSensor) => {
return new Promise((resolve, reject) => {
ambientLightSensor.onstatechange = event => {
if (ambientLightSensor.state === 'idle') {
resolve(mockSensor);
}
};
ambientLightSensor.onchange = e => {
assert_equals(e.reading.illuminance, kDefaultReadingValue);
ambientLightSensor.stop();
};
ambientLightSensor.onerror = reject;
});
})
.then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
return testPromise;
}, 'Test that onChange is called and sensor reading is valid.');
sensor_test(sensor => {
let ambientLightSensor = new AmbientLightSensor({frequency: 60});
ambientLightSensor.start();
let testPromise = sensor.mockSensorProvider.getCreatedSensor()
.then(mockSensor => {
return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
})
.then((mockSensor) => {
return new Promise((resolve, reject) => {
ambientLightSensor.onstatechange = () => {
if (ambientLightSensor.state === 'idle') {
assert_equals(ambientLightSensor.reading, null);
resolve(mockSensor);
}
}
ambientLightSensor.onchange = e => {
assert_equals(e.reading.illuminance, kDefaultReadingValue);
ambientLightSensor.stop();
}
ambientLightSensor.onerror = reject;
});
})
.then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
return testPromise;
}, 'Test that sensor reading is not updated when sensor is stopped.');
sensor_test(sensor => {
let ambientLightSensor = new AmbientLightSensor();
ambientLightSensor.start();
let testPromise = sensor.mockSensorProvider.getCreatedSensor()
.then(mockSensor => {
return mockSensor.setUpdateSensorReadingFunction(update_sensor_reading);
})
.then((mockSensor) => {
return new Promise((resolve, reject) => {
ambientLightSensor.onchange = e => {
if (e.reading.illuminance == kDefaultReadingValue) {
resolve(mockSensor);
}
}
ambientLightSensor.onerror = reject;
});
})
.then((mockSensor) => {
testRunner.setPageVisibility("hidden");
return mockSensor.suspendCalled();
})
.then((mockSensor) => {
testRunner.setPageVisibility("visible");
return mockSensor.resumeCalled();
})
.then((mockSensor) => {
return new Promise((resolve, reject) => {
ambientLightSensor.onstatechange = () => {
if (ambientLightSensor.state === 'idle') {
resolve(mockSensor);
}
}
ambientLightSensor.stop();
ambientLightSensor.onerror = reject;
});
})
.then(mockSensor => { return mockSensor.removeConfigurationCalled(); });
return testPromise;
}, 'Test that sensor receives suspend / resume notifications when page'
+' visibility changes.');
</script>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
test(function() {
// Test that AmbientLightSensor interface exists
assert_true(new AmbientLightSensor() instanceof AmbientLightSensor);
}, 'AmbientLightSensor IDL test');
</script>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
test(function() {
// Test that AmbientLightSensorReading interface exists
assert_true(new AmbientLightSensorReading({illuminance: 1}) instanceof AmbientLightSensorReading);
}, 'AmbientLightSensorReading IDL test');
</script>
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/mojo-helpers.js"></script>
<script src="resources/sensor-helpers.js"></script>
<script>
'use strict';
sensor_test(sensor => {
assert_true(sensor instanceof Object);
assert_true(sensor.mockSensorProvider instanceof Object);
}, 'Sensor Mojo bindings and mock interfaces are available to tests.')
</script>
\ No newline at end of file
'use strict';
function sensor_mocks(mojo) {
return define('Generic Sensor API mocks', [
'mojo/public/js/core',
'mojo/public/js/bindings',
'mojo/public/js/connection',
'device/generic_sensor/public/interfaces/sensor_provider.mojom',
'device/generic_sensor/public/interfaces/sensor.mojom',
], (core, bindings, connection, sensor_provider, sensor) => {
// Helper function that returns resolved promise with result.
function sensorResponse(success) {
return Promise.resolve({success});
}
// Class that mocks Sensor interface defined in sensor.mojom
class MockSensor {
constructor(stub, handle, offset, size, reportingMode) {
this.client_ = null;
this.stub_ = stub;
this.start_should_fail_ = false;
this.reporting_mode_ = reportingMode;
this.sensor_reading_timer_id_ = null;
this.update_reading_function_ = null;
this.suspend_called_ = null;
this.resume_called_ = null;
this.add_configuration_called_ = null;
this.remove_configuration_called_ = null;
this.active_sensor_configurations_ = [];
let rv = core.mapBuffer(handle, offset, size,
core.MAP_BUFFER_FLAG_NONE);
assert_equals(rv.result, core.RESULT_OK, "Failed to map shared buffer");
this.buffer_array_ = rv.buffer;
this.buffer_ = new Float64Array(this.buffer_array_);
bindings.StubBindings(this.stub_).delegate = this;
bindings.StubBindings(this.stub_).connectionErrorHandler = () => {
reset();
};
}
// Returns default configuration.
getDefaultConfiguration() {
return Promise.resolve({frequency: 5});
}
// Adds configuration for the sensor and starts reporting fake data
// through update_reading_function_ callback.
addConfiguration(configuration) {
assert_not_equals(configuration, null, "Invalid sensor configuration.");
if (this.add_configuration_called_ != null) {
this.add_configuration_called_(this);
}
if (!this.start_should_fail_ && this.update_reading_function_ != null) {
let timeout = (1 / configuration.frequency) * 1000;
this.sensor_reading_timer_id_ = window.setTimeout(() => {
this.update_reading_function_(this.buffer_);
if (this.reporting_mode_ === sensor.ReportingMode.ON_CHANGE) {
this.client_.sensorReadingChanged();
}
}, timeout);
this.active_sensor_configurations_.push(configuration);
}
return sensorResponse(!this.start_should_fail_);
}
// Removes sensor configuration from the list of active configurations and
// stops notification about sensor reading changes if
// active_sensor_configurations_ is empty.
removeConfiguration(configuration) {
if (this.remove_configuration_called_ != null) {
this.remove_configuration_called_(this);
}
let index = this.active_sensor_configurations_.indexOf(configuration);
if (index !== -1) {
this.active_sensor_configurations_.splice(index, 1);
} else {
return sensorResponse(false);
}
if (this.sensor_reading_timer_id_ != null
&& this.active_sensor_configurations_.length === 0) {
window.clearTimeout(this.sensor_reading_timer_id_);
this.sensor_reading_timer_id_ = null;
}
return sensorResponse(true);
}
// Suspends sensor.
suspend() {
if (this.suspend_called_ != null) {
this.suspend_called_(this);
}
}
// Resumes sensor.
resume() {
if (this.resume_called_ != null) {
this.resume_called_(this);
}
}
// Mock functions
// Resets mock Sensor state.
reset() {
if (this.sensor_reading_timer_id_) {
window.clearTimeout(this.sensor_reading_timer_id_);
}
this.start_should_fail_ = false;
this.sensor_reading_timer_id_ = null;
this.active_sensor_configurations_ = [];
this.suspend_called_ = null;
this.resume_called_ = null;
this.add_configuration_called_ = null;
this.remove_configuration_called_ = null;
for (let i = 0; i < this.buffer_.length; ++i) {
this.buffer_[i] = 0;
}
}
// Sets callback that is used to deliver sensor reading updates.
setUpdateSensorReadingFunction(update_reading_function) {
this.update_reading_function_ = update_reading_function;
return Promise.resolve(this);
}
// Sets flag that forces sensor to fail when addConfiguration is invoked.
setStartShouldFail(should_fail) {
this.start_should_fail_ = should_fail;
}
// Returns resolved promise if suspend() was called, rejected otherwise.
suspendCalled() {
return new Promise((resolve, reject) => {
this.suspend_called_ = resolve;
});
}
// Returns resolved promise if resume() was called, rejected otherwise.
resumeCalled() {
return new Promise((resolve, reject) => {
this.resume_called_ = resolve;
});
}
// Resolves promise when addConfiguration() is called.
addConfigurationCalled() {
return new Promise((resolve, reject) => {
this.add_configuration_called_ = resolve;
});
}
// Resolves promise when removeConfiguration() is called.
removeConfigurationCalled() {
return new Promise((resolve, reject) => {
this.remove_configuration_called_ = resolve;
});
}
}
// Helper function that returns resolved promise for getSensor() function.
function getSensorResponse(init_params, client_request) {
return Promise.resolve({init_params, client_request});
}
// Class that mocks SensorProvider interface defined in
// sensor_provider.mojom
class MockSensorProvider {
constructor() {
this.reading_size_in_bytes_ =
sensor_provider.SensorInitParams.kReadBufferSize;
this.shared_buffer_size_in_bytes_ = this.reading_size_in_bytes_ *
sensor.SensorType.LAST;
let rv =
core.createSharedBuffer(
this.shared_buffer_size_in_bytes_,
core.CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE);
assert_equals(rv.result, core.RESULT_OK, "Failed to create buffer");
this.shared_buffer_handle_ = rv.handle;
this.active_sensor_ = null;
this.get_sensor_should_fail_ = false;
this.resolve_func_ = null;
this.is_continuous_ = false;
}
// Returns initialized Sensor proxy to the client.
getSensor(type, stub) {
if (this.get_sensor_should_fail_) {
return getSensorResponse(null, null);
}
let offset =
(sensor.SensorType.LAST - type) * this.reading_size_in_bytes_;
let reporting_mode = sensor.ReportingMode.ON_CHANGE;
if (this.is_continuous_) {
reporting_mode = sensor.ReportingMode.CONTINUOUS;
}
if (this.active_sensor_ == null) {
let mockSensor = new MockSensor(stub, this.shared_buffer_handle_,
offset, this.reading_size_in_bytes_, reporting_mode);
this.active_sensor_ = mockSensor;
}
let rv =
core.duplicateBufferHandle(
this.shared_buffer_handle_,
core.DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE);
assert_equals(rv.result, core.RESULT_OK);
let default_config = {frequency: 5};
let init_params =
new sensor_provider.SensorInitParams(
{ memory: rv.handle,
buffer_offset: offset,
mode: reporting_mode,
default_configuration: default_config });
if (this.resolve_func_ !== null) {
this.resolve_func_(this.active_sensor_);
}
var client_handle = connection.bindProxy(proxy => {
this.active_sensor_.client_ = proxy;
}, sensor.SensorClient);
return getSensorResponse(init_params, client_handle);
}
// Binds object to mojo message pipe
bindToPipe(pipe) {
this.stub_ = connection.bindHandleToStub(
pipe, sensor_provider.SensorProvider);
bindings.StubBindings(this.stub_).delegate = this;
}
// Mock functions
// Resets state of mock SensorProvider between test runs.
reset() {
if (this.active_sensor_ != null) {
this.active_sensor_.reset();
}
this.get_sensor_should_fail_ = false;
this.resolve_func_ = null;
}
// Sets flag that forces mock SensorProvider to fail when getSensor() is
// invoked.
setGetSensorShouldFail(should_fail) {
this.get_sensor_should_fail_ = should_fail;
}
// Returns mock sensor that was created in getSensor to the layout test.
getCreatedSensor() {
if (this.active_sensor_ != null) {
return Promise.resolve(this.active_sensor_);
}
return new Promise((resolve, reject) => {
this.resolve_func_ = resolve;
});
}
// Forces sensor to use |reporting_mode| as an update mode.
setContinuousReportingMode(reporting_mode) {
this.is_continuous_ = reporting_mode;
}
}
let mockSensorProvider = new MockSensorProvider;
mojo.frameInterfaces.addInterfaceOverrideForTesting(
sensor_provider.SensorProvider.name,
pipe => {
mockSensorProvider.bindToPipe(pipe);
});
return Promise.resolve({
mockSensorProvider: mockSensorProvider,
});
});
}
function sensor_test(func, name, properties) {
mojo_test(mojo => sensor_mocks(mojo).then(sensor => {
let result = Promise.resolve(func(sensor));
let cleanUp = () => { sensor.mockSensorProvider.reset(); };
return result.then(cleanUp, cleanUp);
}), name, properties);
}
...@@ -17,14 +17,6 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE ...@@ -17,14 +17,6 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
[INTERFACES] [INTERFACES]
interface AmbientLightSensor : Sensor
attribute @@toStringTag
getter reading
method constructor
interface AmbientLightSensorReading : SensorReading
attribute @@toStringTag
getter illuminance
method constructor
interface AnalyserNode : AudioNode interface AnalyserNode : AudioNode
attribute @@toStringTag attribute @@toStringTag
getter fftSize getter fftSize
......
...@@ -216,8 +216,6 @@ modules_idl_files = ...@@ -216,8 +216,6 @@ modules_idl_files =
"remoteplayback/RemotePlayback.idl", "remoteplayback/RemotePlayback.idl",
"remoteplayback/RemotePlaybackAvailability.idl", "remoteplayback/RemotePlaybackAvailability.idl",
"screen_orientation/ScreenOrientation.idl", "screen_orientation/ScreenOrientation.idl",
"sensor/AmbientLightSensor.idl",
"sensor/AmbientLightSensorReading.idl",
"sensor/Sensor.idl", "sensor/Sensor.idl",
"sensor/SensorErrorEvent.idl", "sensor/SensorErrorEvent.idl",
"sensor/SensorReading.idl", "sensor/SensorReading.idl",
...@@ -447,7 +445,6 @@ modules_dictionary_idl_files = ...@@ -447,7 +445,6 @@ modules_dictionary_idl_files =
"push_messaging/PushEventInit.idl", "push_messaging/PushEventInit.idl",
"push_messaging/PushSubscriptionOptionsInit.idl", "push_messaging/PushSubscriptionOptionsInit.idl",
"quota/StorageEstimate.idl", "quota/StorageEstimate.idl",
"sensor/AmbientLightSensorReadingInit.idl",
"sensor/SensorErrorEventInit.idl", "sensor/SensorErrorEventInit.idl",
"sensor/SensorReadingEventInit.idl", "sensor/SensorReadingEventInit.idl",
"sensor/SensorOptions.idl", "sensor/SensorOptions.idl",
...@@ -772,8 +769,6 @@ generated_modules_dictionary_files = [ ...@@ -772,8 +769,6 @@ generated_modules_dictionary_files = [
"$blink_modules_output_dir/push_messaging/PushSubscriptionOptionsInit.h", "$blink_modules_output_dir/push_messaging/PushSubscriptionOptionsInit.h",
"$blink_modules_output_dir/quota/StorageEstimate.cpp", "$blink_modules_output_dir/quota/StorageEstimate.cpp",
"$blink_modules_output_dir/quota/StorageEstimate.h", "$blink_modules_output_dir/quota/StorageEstimate.h",
"$blink_modules_output_dir/sensor/AmbientLightSensorReadingInit.cpp",
"$blink_modules_output_dir/sensor/AmbientLightSensorReadingInit.h",
"$blink_modules_output_dir/sensor/SensorErrorEventInit.cpp", "$blink_modules_output_dir/sensor/SensorErrorEventInit.cpp",
"$blink_modules_output_dir/sensor/SensorErrorEventInit.h", "$blink_modules_output_dir/sensor/SensorErrorEventInit.h",
"$blink_modules_output_dir/sensor/SensorReadingEventInit.cpp", "$blink_modules_output_dir/sensor/SensorReadingEventInit.cpp",
......
// 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 "modules/sensor/AmbientLightSensorReading.h"
using device::mojom::blink::SensorType;
namespace blink {
// static
AmbientLightSensor* AmbientLightSensor::create(ExecutionContext* context, const SensorOptions& sensorOptions)
{
return new AmbientLightSensor(context, sensorOptions);
}
// static
AmbientLightSensor* AmbientLightSensor::create(ExecutionContext* context)
{
return create(context, SensorOptions());
}
AmbientLightSensor::AmbientLightSensor(ExecutionContext* executionContext, const SensorOptions& sensorOptions)
: Sensor(executionContext, sensorOptions, SensorType::AMBIENT_LIGHT)
{
}
AmbientLightSensorReading* AmbientLightSensor::reading() const
{
return static_cast<AmbientLightSensorReading*>(Sensor::reading());
}
SensorReading* AmbientLightSensor::createSensorReading(SensorProxy* proxy)
{
return AmbientLightSensorReading::create(proxy);
}
auto AmbientLightSensor::createSensorConfig(const SensorOptions& options, const SensorConfiguration& defaultConfig) -> SensorConfigurationPtr
{
auto result = device::mojom::blink::SensorConfiguration::New();
result->frequency = options.hasFrequency() ? options.frequency() : defaultConfig.frequency;
return result;
}
DEFINE_TRACE(AmbientLightSensor)
{
Sensor::trace(visitor);
}
} // namespace blink
// 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.
#ifndef AmbientLightSensor_h
#define AmbientLightSensor_h
#include "modules/sensor/Sensor.h"
namespace blink {
class AmbientLightSensorReading;
class AmbientLightSensor final : public Sensor {
USING_GARBAGE_COLLECTED_MIXIN(AmbientLightSensor);
DEFINE_WRAPPERTYPEINFO();
public:
static AmbientLightSensor* create(ExecutionContext*, const SensorOptions&);
static AmbientLightSensor* create(ExecutionContext*);
AmbientLightSensorReading* reading() const;
DECLARE_VIRTUAL_TRACE();
private:
AmbientLightSensor(ExecutionContext*, const SensorOptions&);
// Sensor overrides.
SensorReading* createSensorReading(SensorProxy*) override;
SensorConfigurationPtr createSensorConfig(const SensorOptions&, const SensorConfiguration& defaultConfig) override;
};
} // namespace blink
#endif // AmbientLightSensor_h
// 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.
// Specification at:
// https://w3c.github.io/ambient-light/#ambient-light-sensor-interface
[
RuntimeEnabled=Sensor,
Constructor(optional SensorOptions sensorOptions),
ConstructorCallWith=ExecutionContext,
] interface AmbientLightSensor : Sensor {
readonly attribute AmbientLightSensorReading? reading;
};
// 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/AmbientLightSensorReading.h"
#include "modules/sensor/SensorProxy.h"
namespace blink {
AmbientLightSensorReading::AmbientLightSensorReading(const AmbientLightSensorReadingInit& init)
: SensorReading(nullptr)
, mAmbientLightSensorReadingInit(init)
{
}
AmbientLightSensorReading::AmbientLightSensorReading(SensorProxy* proxy)
: SensorReading(proxy)
, mAmbientLightSensorReadingInit(AmbientLightSensorReadingInit())
{
}
AmbientLightSensorReading::~AmbientLightSensorReading() = default;
double AmbientLightSensorReading::illuminance() const
{
if (mAmbientLightSensorReadingInit.hasIlluminance())
return mAmbientLightSensorReadingInit.illuminance();
if (!m_sensorProxy)
return 0.0;
return m_sensorProxy->reading().reading[0];
}
bool AmbientLightSensorReading::isReadingUpdated(const SensorProxy::Reading& previous) const
{
if (!m_sensorProxy)
return false;
return previous.reading[0] != illuminance();
}
DEFINE_TRACE(AmbientLightSensorReading)
{
SensorReading::trace(visitor);
}
} // namespace blink
// 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.
#ifndef AmbientLightSensorReading_h
#define AmbientLightSensorReading_h
#include "modules/sensor/AmbientLightSensorReadingInit.h"
#include "modules/sensor/SensorReading.h"
namespace blink {
class AmbientLightSensorReading final
: public GarbageCollectedFinalized<AmbientLightSensorReading>
, public SensorReading {
USING_GARBAGE_COLLECTED_MIXIN(AmbientLightSensorReading);
DEFINE_WRAPPERTYPEINFO();
public:
static AmbientLightSensorReading* create(const AmbientLightSensorReadingInit& init)
{
return new AmbientLightSensorReading(init);
}
static AmbientLightSensorReading* create(SensorProxy* proxy)
{
return new AmbientLightSensorReading(proxy);
}
~AmbientLightSensorReading();
double illuminance() const;
bool isReadingUpdated(const SensorProxy::Reading&) const override;
DECLARE_VIRTUAL_TRACE();
private:
explicit AmbientLightSensorReading(const AmbientLightSensorReadingInit&);
explicit AmbientLightSensorReading(SensorProxy*);
private:
AmbientLightSensorReadingInit mAmbientLightSensorReadingInit;
};
} // namepsace blink
#endif // AmbientLightSensorReading_h
// 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.
// Specification at:
// https://w3c.github.io/ambient-light/#ambient-light-sensor-reading-interface
[
RuntimeEnabled=Sensor,
Constructor(AmbientLightSensorReadingInit ambientLightSensorReadingInit)
] interface AmbientLightSensorReading : SensorReading {
readonly attribute unrestricted double illuminance;
};
// 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.
// Specification at:
// https://w3c.github.io/ambient-light/#dictdef-ambientlightsensorreadinginit
dictionary AmbientLightSensorReadingInit {
unrestricted double illuminance;
};
...@@ -6,10 +6,6 @@ import("//third_party/WebKit/Source/modules/modules.gni") ...@@ -6,10 +6,6 @@ import("//third_party/WebKit/Source/modules/modules.gni")
blink_modules_sources("sensor") { blink_modules_sources("sensor") {
sources = [ sources = [
"AmbientLightSensor.cpp",
"AmbientLightSensor.h",
"AmbientLightSensorReading.cpp",
"AmbientLightSensorReading.h",
"Sensor.cpp", "Sensor.cpp",
"Sensor.h", "Sensor.h",
"SensorErrorEvent.cpp", "SensorErrorEvent.cpp",
......
...@@ -14,6 +14,7 @@ namespace blink { ...@@ -14,6 +14,7 @@ namespace blink {
SensorReading::SensorReading(SensorProxy* sensorProxy) SensorReading::SensorReading(SensorProxy* sensorProxy)
: m_sensorProxy(sensorProxy) : m_sensorProxy(sensorProxy)
{ {
DCHECK(m_sensorProxy);
} }
DEFINE_TRACE(SensorReading) DEFINE_TRACE(SensorReading)
...@@ -30,15 +31,6 @@ DOMHighResTimeStamp SensorReading::timeStamp(ScriptState* scriptState) const ...@@ -30,15 +31,6 @@ DOMHighResTimeStamp SensorReading::timeStamp(ScriptState* scriptState) const
Performance* performance = DOMWindowPerformance::performance(*window); Performance* performance = DOMWindowPerformance::performance(*window);
DCHECK(performance); DCHECK(performance);
if (!m_sensorProxy) {
// In cases when SensorReading derived classes are constructed from JS
// side, e.g. to create syntetic SensorReadingEvent for testing
// purposes, |m_sensorProxy| will be null and SensorReading.timeStamp
// would return current DOMHighResTimeStamp, while reading value should
// be provided by derived classes.
return performance->now();
}
return performance->monotonicTimeToDOMHighResTimeStamp(m_sensorProxy->reading().timestamp); return performance->monotonicTimeToDOMHighResTimeStamp(m_sensorProxy->reading().timestamp);
} }
......
...@@ -16,7 +16,7 @@ class ExecutionContext; ...@@ -16,7 +16,7 @@ class ExecutionContext;
class ScriptState; class ScriptState;
class SensorReading class SensorReading
: public GarbageCollectedMixin : public GarbageCollected<SensorReading>
, public ScriptWrappable { , public ScriptWrappable {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment