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

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

Issue 2458453002: [sensors] Add Permission guard to the generic sensor apis.
Patch Set: rebase + blink reformat Created 3 years, 8 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/TaskRunnerHelper.h" 9 #include "core/dom/TaskRunnerHelper.h"
10 #include "core/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (sensor_proxy_) 154 if (sensor_proxy_)
155 return; 155 return;
156 156
157 Document* document = ToDocument(GetExecutionContext()); 157 Document* document = ToDocument(GetExecutionContext());
158 if (!document || !document->GetFrame()) 158 if (!document || !document->GetFrame())
159 return; 159 return;
160 160
161 auto provider = SensorProviderProxy::From(document->GetFrame()); 161 auto provider = SensorProviderProxy::From(document->GetFrame());
162 sensor_proxy_ = provider->GetSensorProxy(type_); 162 sensor_proxy_ = provider->GetSensorProxy(type_);
163 163
164 if (!sensor_proxy_) 164 if (!sensor_proxy_) {
165 sensor_proxy_ = provider->CreateSensorProxy(type_, document->GetPage()); 165 RefPtr<SecurityOrigin> origin = GetExecutionContext()->GetSecurityOrigin();
166 DCHECK(origin);
167 sensor_proxy_ = provider->CreateSensorProxy(type_, document->GetPage(),
168 std::move(origin));
169 }
166 } 170 }
167 171
168 void Sensor::ContextDestroyed(ExecutionContext*) { 172 void Sensor::ContextDestroyed(ExecutionContext*) {
169 if (state_ == Sensor::SensorState::kActivated || 173 if (state_ == Sensor::SensorState::kActivated ||
170 state_ == Sensor::SensorState::kActivating) 174 state_ == Sensor::SensorState::kActivating)
171 StopListening(); 175 StopListening();
172 } 176 }
173 177
174 void Sensor::OnSensorInitialized() { 178 void Sensor::OnSensorInitialized() {
175 if (state_ != Sensor::SensorState::kActivating) 179 if (state_ != Sensor::SensorState::kActivating)
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 299 }
296 300
297 bool Sensor::CanReturnReadings() const { 301 bool Sensor::CanReturnReadings() const {
298 if (!IsActivated()) 302 if (!IsActivated())
299 return false; 303 return false;
300 DCHECK(sensor_proxy_); 304 DCHECK(sensor_proxy_);
301 return sensor_proxy_->Reading().timestamp != 0.0; 305 return sensor_proxy_->Reading().timestamp != 0.0;
302 } 306 }
303 307
304 } // namespace blink 308 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/DEPS ('k') | third_party/WebKit/Source/modules/sensor/SensorProviderProxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698