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

Side by Side Diff: Source/modules/geolocation/Geolocation.cpp

Issue 745503002: Replace Dictionary with PositionOptions in geolocation/. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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 /* 1 /*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009 Torch Mobile, Inc. 3 * Copyright (C) 2009 Torch Mobile, Inc.
4 * Copyright 2010, The Android Open Source Project 4 * Copyright 2010, The Android Open Source Project
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 // It is required by canAccessFeatureRequiringSecureOrigin() but isn't 148 // It is required by canAccessFeatureRequiringSecureOrigin() but isn't
149 // actually used. This could be used later if a warning is shown in the 149 // actually used. This could be used later if a warning is shown in the
150 // developer console. 150 // developer console.
151 String insecureOriginMsg; 151 String insecureOriginMsg;
152 UseCounter::Feature counter = document->securityOrigin()->canAccessFeatureRe quiringSecureOrigin(insecureOriginMsg) 152 UseCounter::Feature counter = document->securityOrigin()->canAccessFeatureRe quiringSecureOrigin(insecureOriginMsg)
153 ? UseCounter::GeolocationSecureOrigin : UseCounter::GeolocationInsecureO rigin; 153 ? UseCounter::GeolocationSecureOrigin : UseCounter::GeolocationInsecureO rigin;
154 UseCounter::count(document, counter); 154 UseCounter::count(document, counter);
155 } 155 }
156 156
157 void Geolocation::getCurrentPosition(PositionCallback* successCallback, Position ErrorCallback* errorCallback, const Dictionary& options) 157 void Geolocation::getCurrentPosition(PositionCallback* successCallback, Position ErrorCallback* errorCallback, const PositionOptions& options)
158 { 158 {
159 if (!frame()) 159 if (!frame())
160 return; 160 return;
161 161
162 recordOriginTypeAccess(); 162 recordOriginTypeAccess();
163 163
164 GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCall back, PositionOptions::create(options)); 164 GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCall back, options);
165 startRequest(notifier); 165 startRequest(notifier);
166 166
167 m_oneShots.add(notifier); 167 m_oneShots.add(notifier);
168 } 168 }
169 169
170 int Geolocation::watchPosition(PositionCallback* successCallback, PositionErrorC allback* errorCallback, const Dictionary& options) 170 int Geolocation::watchPosition(PositionCallback* successCallback, PositionErrorC allback* errorCallback, const PositionOptions& options)
171 { 171 {
172 if (!frame()) 172 if (!frame())
173 return 0; 173 return 0;
174 174
175 recordOriginTypeAccess(); 175 recordOriginTypeAccess();
176 176
177 GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCall back, PositionOptions::create(options)); 177 GeoNotifier* notifier = GeoNotifier::create(this, successCallback, errorCall back, options);
178 startRequest(notifier); 178 startRequest(notifier);
179 179
180 int watchID; 180 int watchID;
181 // Keep asking for the next id until we're given one that we don't already h ave. 181 // Keep asking for the next id until we're given one that we don't already h ave.
182 do { 182 do {
183 watchID = executionContext()->circularSequentialID(); 183 watchID = executionContext()->circularSequentialID();
184 } while (!m_watchers.add(watchID, notifier)); 184 } while (!m_watchers.add(watchID, notifier));
185 return watchID; 185 return watchID;
186 } 186 }
187 187
188 void Geolocation::startRequest(GeoNotifier *notifier) 188 void Geolocation::startRequest(GeoNotifier *notifier)
189 { 189 {
190 // Check whether permissions have already been denied. Note that if this is the case, 190 // Check whether permissions have already been denied. Note that if this is the case,
191 // the permission state can not change again in the lifetime of this page. 191 // the permission state can not change again in the lifetime of this page.
192 if (isDenied()) 192 if (isDenied())
193 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_ DENIED, permissionDeniedErrorMessage)); 193 notifier->setFatalError(PositionError::create(PositionError::PERMISSION_ DENIED, permissionDeniedErrorMessage));
194 else if (haveSuitableCachedPosition(notifier->options())) 194 else if (haveSuitableCachedPosition(notifier->options()))
195 notifier->setUseCachedPosition(); 195 notifier->setUseCachedPosition();
196 else if (!notifier->options()->timeout()) 196 else if (!notifier->options().timeout())
197 notifier->startTimer(); 197 notifier->startTimer();
198 else if (!isAllowed()) { 198 else if (!isAllowed()) {
199 // if we don't yet have permission, request for permission before callin g startUpdating() 199 // if we don't yet have permission, request for permission before callin g startUpdating()
200 m_pendingForPermissionNotifiers.add(notifier); 200 m_pendingForPermissionNotifiers.add(notifier);
201 requestPermission(); 201 requestPermission();
202 } else if (startUpdating(notifier)) 202 } else if (startUpdating(notifier))
203 notifier->startTimer(); 203 notifier->startTimer();
204 else 204 else
205 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN AVAILABLE, failedToStartServiceErrorMessage)); 205 notifier->setFatalError(PositionError::create(PositionError::POSITION_UN AVAILABLE, failedToStartServiceErrorMessage));
206 } 206 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // asynchronously, so we don't need to worry about it being modified from 242 // asynchronously, so we don't need to worry about it being modified from
243 // the callbacks. 243 // the callbacks.
244 for (GeoNotifier* notifier : m_requestsAwaitingCachedPosition) { 244 for (GeoNotifier* notifier : m_requestsAwaitingCachedPosition) {
245 notifier->runSuccessCallback(lastPosition()); 245 notifier->runSuccessCallback(lastPosition());
246 246
247 // If this is a one-shot request, stop it. Otherwise, if the watch still 247 // If this is a one-shot request, stop it. Otherwise, if the watch still
248 // exists, start the service to get updates. 248 // exists, start the service to get updates.
249 if (m_oneShots.contains(notifier)) 249 if (m_oneShots.contains(notifier))
250 m_oneShots.remove(notifier); 250 m_oneShots.remove(notifier);
251 else if (m_watchers.contains(notifier)) { 251 else if (m_watchers.contains(notifier)) {
252 if (!notifier->options()->timeout() || startUpdating(notifier)) 252 if (!notifier->options().timeout() || startUpdating(notifier))
253 notifier->startTimer(); 253 notifier->startTimer();
254 else 254 else
255 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); 255 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage));
256 } 256 }
257 } 257 }
258 258
259 m_requestsAwaitingCachedPosition.clear(); 259 m_requestsAwaitingCachedPosition.clear();
260 260
261 if (!hasListeners()) 261 if (!hasListeners())
262 stopUpdating(); 262 stopUpdating();
263 } 263 }
264 264
265 void Geolocation::requestTimedOut(GeoNotifier* notifier) 265 void Geolocation::requestTimedOut(GeoNotifier* notifier)
266 { 266 {
267 // If this is a one-shot request, stop it. 267 // If this is a one-shot request, stop it.
268 m_oneShots.remove(notifier); 268 m_oneShots.remove(notifier);
269 269
270 if (!hasListeners()) 270 if (!hasListeners())
271 stopUpdating(); 271 stopUpdating();
272 } 272 }
273 273
274 bool Geolocation::haveSuitableCachedPosition(PositionOptions* options) 274 bool Geolocation::haveSuitableCachedPosition(const PositionOptions& options)
275 { 275 {
276 Geoposition* cachedPosition = lastPosition(); 276 Geoposition* cachedPosition = lastPosition();
277 if (!cachedPosition) 277 if (!cachedPosition)
278 return false; 278 return false;
279 if (!options->maximumAge()) 279 if (!options.maximumAge())
280 return false; 280 return false;
281 DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime()) ; 281 DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime()) ;
282 return cachedPosition->timestamp() > currentTimeMillis - options->maximumAge (); 282 return cachedPosition->timestamp() > currentTimeMillis - options.maximumAge( );
283 } 283 }
284 284
285 void Geolocation::clearWatch(int watchID) 285 void Geolocation::clearWatch(int watchID)
286 { 286 {
287 if (watchID <= 0) 287 if (watchID <= 0)
288 return; 288 return;
289 289
290 if (GeoNotifier* notifier = m_watchers.find(watchID)) 290 if (GeoNotifier* notifier = m_watchers.find(watchID))
291 m_pendingForPermissionNotifiers.remove(notifier); 291 m_pendingForPermissionNotifiers.remove(notifier);
292 m_watchers.remove(watchID); 292 m_watchers.remove(watchID);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 { 491 {
492 handleError(createPositionError(error)); 492 handleError(createPositionError(error));
493 } 493 }
494 494
495 bool Geolocation::startUpdating(GeoNotifier* notifier) 495 bool Geolocation::startUpdating(GeoNotifier* notifier)
496 { 496 {
497 LocalFrame* frame = this->frame(); 497 LocalFrame* frame = this->frame();
498 if (!frame) 498 if (!frame)
499 return false; 499 return false;
500 500
501 GeolocationController::from(frame)->addObserver(this, notifier->options()->e nableHighAccuracy()); 501 GeolocationController::from(frame)->addObserver(this, notifier->options().en ableHighAccuracy());
502 return true; 502 return true;
503 } 503 }
504 504
505 void Geolocation::stopUpdating() 505 void Geolocation::stopUpdating()
506 { 506 {
507 LocalFrame* frame = this->frame(); 507 LocalFrame* frame = this->frame();
508 if (!frame) 508 if (!frame)
509 return; 509 return;
510 510
511 GeolocationController::from(frame)->removeObserver(this); 511 GeolocationController::from(frame)->removeObserver(this);
(...skipping 11 matching lines...) Expand all
523 notifier->startTimer(); 523 notifier->startTimer();
524 else 524 else
525 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage)); 525 notifier->setFatalError(PositionError::create(PositionError::POS ITION_UNAVAILABLE, failedToStartServiceErrorMessage));
526 } else { 526 } else {
527 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage)); 527 notifier->setFatalError(PositionError::create(PositionError::PERMISS ION_DENIED, permissionDeniedErrorMessage));
528 } 528 }
529 } 529 }
530 } 530 }
531 531
532 } // namespace blink 532 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698