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

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

Issue 2537863003: Remove [ConstructorCallWith=ScriptState] from Sensor (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
12 #include "modules/sensor/SensorErrorEvent.h" 12 #include "modules/sensor/SensorErrorEvent.h"
13 #include "modules/sensor/SensorProviderProxy.h" 13 #include "modules/sensor/SensorProviderProxy.h"
14 #include "modules/sensor/SensorReading.h" 14 #include "modules/sensor/SensorReading.h"
15 #include "modules/sensor/SensorUpdateNotificationStrategy.h" 15 #include "modules/sensor/SensorUpdateNotificationStrategy.h"
16 16
17 using namespace device::mojom::blink; 17 using namespace device::mojom::blink;
18 18
19 namespace blink { 19 namespace blink {
20 20
21 Sensor::Sensor(ScriptState* scriptState, 21 Sensor::Sensor(ExecutionContext* executionContext,
22 const SensorOptions& sensorOptions, 22 const SensorOptions& sensorOptions,
23 ExceptionState& exceptionState, 23 ExceptionState& exceptionState,
24 SensorType type) 24 SensorType type)
25 : ActiveScriptWrappable(this), 25 : ActiveScriptWrappable(this),
26 ContextLifecycleObserver(scriptState->getExecutionContext()), 26 ContextLifecycleObserver(executionContext),
27 m_sensorOptions(sensorOptions), 27 m_sensorOptions(sensorOptions),
28 m_type(type), 28 m_type(type),
29 m_state(Sensor::SensorState::Idle) { 29 m_state(Sensor::SensorState::Idle) {
30 // Check secure context. 30 // Check secure context.
31 String errorMessage; 31 String errorMessage;
32 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { 32 if (!executionContext->isSecureContext(errorMessage)) {
33 exceptionState.throwDOMException(SecurityError, errorMessage); 33 exceptionState.throwDOMException(SecurityError, errorMessage);
34 return; 34 return;
35 } 35 }
36 36
37 // Check top-level browsing context. 37 // Check top-level browsing context.
38 if (!scriptState->domWindow() || !scriptState->domWindow()->frame() || 38 if (!toDocument(executionContext)->domWindow()->frame() ||
39 !scriptState->domWindow()->frame()->isMainFrame()) { 39 !toDocument(executionContext)->frame()->isMainFrame()) {
40 exceptionState.throwSecurityError( 40 exceptionState.throwSecurityError(
41 "Must be in a top-level browsing context"); 41 "Must be in a top-level browsing context");
42 return; 42 return;
43 } 43 }
44 44
45 // Check the given frequency value. 45 // Check the given frequency value.
46 if (m_sensorOptions.hasFrequency()) { 46 if (m_sensorOptions.hasFrequency()) {
47 double frequency = m_sensorOptions.frequency(); 47 double frequency = m_sensorOptions.frequency();
48 if (frequency <= 0.0) { 48 if (frequency <= 0.0) {
49 exceptionState.throwRangeError("Frequency must be positive."); 49 exceptionState.throwRangeError("Frequency must be positive.");
50 return; 50 return;
51 } 51 }
52 52
53 if (frequency > SensorConfiguration::kMaxAllowedFrequency) { 53 if (frequency > SensorConfiguration::kMaxAllowedFrequency) {
54 m_sensorOptions.setFrequency(SensorConfiguration::kMaxAllowedFrequency); 54 m_sensorOptions.setFrequency(SensorConfiguration::kMaxAllowedFrequency);
55 ConsoleMessage* consoleMessage = ConsoleMessage::create( 55 ConsoleMessage* consoleMessage = ConsoleMessage::create(
56 JSMessageSource, InfoMessageLevel, "Frequency is limited to 60 Hz."); 56 JSMessageSource, InfoMessageLevel, "Frequency is limited to 60 Hz.");
57 scriptState->getExecutionContext()->addConsoleMessage(consoleMessage); 57 executionContext->addConsoleMessage(consoleMessage);
58 } 58 }
59 } 59 }
60 } 60 }
61 61
62 Sensor::~Sensor() = default; 62 Sensor::~Sensor() = default;
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(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void Sensor::notifyOnActivate() { 314 void Sensor::notifyOnActivate() {
315 dispatchEvent(Event::create(EventTypeNames::activate)); 315 dispatchEvent(Event::create(EventTypeNames::activate));
316 } 316 }
317 317
318 void Sensor::notifyError(DOMException* error) { 318 void Sensor::notifyError(DOMException* error) {
319 dispatchEvent( 319 dispatchEvent(
320 SensorErrorEvent::create(EventTypeNames::error, std::move(error))); 320 SensorErrorEvent::create(EventTypeNames::error, std::move(error)));
321 } 321 }
322 322
323 } // namespace blink 323 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698