Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: third_party/WebKit/Source/modules/sensor/Sensor.cpp

Issue 2644873002: [Sensors] Fix reading updates after page refresh (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/sensor/Sensor.h" 5 #include "modules/sensor/Sensor.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/dom/ExecutionContextTask.h" 9 #include "core/dom/ExecutionContextTask.h"
10 #include "core/dom/TaskRunnerHelper.h" 10 #include "core/dom/TaskRunnerHelper.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 void Sensor::start(ScriptState* scriptState, ExceptionState& exceptionState) { 64 void Sensor::start(ScriptState* scriptState, ExceptionState& exceptionState) {
65 if (m_state != Sensor::SensorState::Idle && 65 if (m_state != Sensor::SensorState::Idle &&
66 m_state != Sensor::SensorState::Errored) { 66 m_state != Sensor::SensorState::Errored) {
67 exceptionState.throwDOMException( 67 exceptionState.throwDOMException(
68 InvalidStateError, 68 InvalidStateError,
69 "Cannot start because SensorState is not Idle or errored"); 69 "Cannot start because SensorState is not Idle or errored");
70 return; 70 return;
71 } 71 }
72 72
73 initSensorProxyIfNeeded(); 73 initSensorProxyIfNeeded();
shalamov 2017/01/20 09:25:32 Should we pass / use execution context of a start(
Mikhail 2017/01/24 12:00:18 Does it make any practical change? haraken@, wdyt?
74 74
75 if (!m_sensorProxy) { 75 if (!m_sensorProxy) {
76 exceptionState.throwDOMException( 76 exceptionState.throwDOMException(
77 InvalidStateError, "The Sensor is no longer associated to a frame."); 77 InvalidStateError, "The Sensor is no longer associated to a frame.");
78 return; 78 return;
79 } 79 }
80 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime(); 80 m_lastUpdateTimestamp = WTF::monotonicallyIncreasingTime();
81 startListening(); 81 startListening();
82 } 82 }
83 83
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return; 157 return;
158 158
159 Document* document = toDocument(getExecutionContext()); 159 Document* document = toDocument(getExecutionContext());
160 if (!document || !document->frame()) 160 if (!document || !document->frame())
161 return; 161 return;
162 162
163 auto provider = SensorProviderProxy::from(document->frame()); 163 auto provider = SensorProviderProxy::from(document->frame());
164 m_sensorProxy = provider->getSensorProxy(m_type); 164 m_sensorProxy = provider->getSensorProxy(m_type);
165 165
166 if (!m_sensorProxy) { 166 if (!m_sensorProxy) {
167 m_sensorProxy = provider->createSensorProxy(m_type, document, 167 m_sensorProxy = provider->createSensorProxy(m_type, document->page(),
shalamov 2017/01/20 09:25:32 should we throw "InvalidStateError" if context is
Mikhail 2017/01/24 12:00:18 page is used only in PageVisibilityObserver which
168 createSensorReadingFactory()); 168 createSensorReadingFactory());
169 } 169 }
170 } 170 }
171 171
172 void Sensor::contextDestroyed(ExecutionContext*) { 172 void Sensor::contextDestroyed(ExecutionContext*) {
173 if (m_state == Sensor::SensorState::Activated || 173 if (m_state == Sensor::SensorState::Activated ||
174 m_state == Sensor::SensorState::Activating) 174 m_state == Sensor::SensorState::Activating)
175 stopListening(); 175 stopListening();
176 } 176 }
177 177
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 void Sensor::notifyOnActivate() { 294 void Sensor::notifyOnActivate() {
295 dispatchEvent(Event::create(EventTypeNames::activate)); 295 dispatchEvent(Event::create(EventTypeNames::activate));
296 } 296 }
297 297
298 void Sensor::notifyError(DOMException* error) { 298 void Sensor::notifyError(DOMException* error) {
299 dispatchEvent( 299 dispatchEvent(
300 SensorErrorEvent::create(EventTypeNames::error, std::move(error))); 300 SensorErrorEvent::create(EventTypeNames::error, std::move(error)));
301 } 301 }
302 302
303 } // namespace blink 303 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698