OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/sensor/NavigatorAmbientLightSensor.h" |
| 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/dom/ExecutionContext.h" |
| 9 #include "core/frame/Navigator.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 NavigatorAmbientLightSensor::NavigatorAmbientLightSensor() |
| 14 { |
| 15 } |
| 16 |
| 17 // static |
| 18 NavigatorAmbientLightSensor& NavigatorAmbientLightSensor::from(Navigator& naviga
tor) |
| 19 { |
| 20 NavigatorAmbientLightSensor* supplement = static_cast<NavigatorAmbientLightS
ensor*>(Supplement<Navigator>::from(navigator, supplementName())); |
| 21 if (!supplement) { |
| 22 supplement = new NavigatorAmbientLightSensor(); |
| 23 provideTo(navigator, supplementName(), supplement); |
| 24 } |
| 25 return *supplement; |
| 26 } |
| 27 |
| 28 // static |
| 29 AmbientLightSensor* NavigatorAmbientLightSensor::lightSensor(ExecutionContext* c
ontext, Navigator& navigator, ExceptionState& exceptionState) |
| 30 { |
| 31 NavigatorAmbientLightSensor& self = NavigatorAmbientLightSensor::from(naviga
tor); |
| 32 if (!self.m_lightSensors) |
| 33 self.m_lightSensors = AmbientLightSensor::create(context, exceptionState
); |
| 34 |
| 35 if (exceptionState.hadException()) |
| 36 return nullptr; |
| 37 |
| 38 return self.m_lightSensors.get(); |
| 39 } |
| 40 |
| 41 // static |
| 42 const char* NavigatorAmbientLightSensor::supplementName() |
| 43 { |
| 44 return "NavigatorAmbientLightSensor"; |
| 45 } |
| 46 |
| 47 NavigatorAmbientLightSensor::~NavigatorAmbientLightSensor() |
| 48 { |
| 49 } |
| 50 |
| 51 DEFINE_TRACE(NavigatorAmbientLightSensor) |
| 52 { |
| 53 visitor->trace(m_lightSensors); |
| 54 Supplement<Navigator>::trace(visitor); |
| 55 } |
| 56 |
| 57 } // namespace blink |
OLD | NEW |