| OLD | NEW |
| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 namespace blink { | 46 namespace blink { |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 const char kPermissionDeniedErrorMessage[] = "User denied Geolocation"; | 49 const char kPermissionDeniedErrorMessage[] = "User denied Geolocation"; |
| 50 const char kFailedToStartServiceErrorMessage[] = | 50 const char kFailedToStartServiceErrorMessage[] = |
| 51 "Failed to start Geolocation service"; | 51 "Failed to start Geolocation service"; |
| 52 const char kFramelessDocumentErrorMessage[] = | 52 const char kFramelessDocumentErrorMessage[] = |
| 53 "Geolocation cannot be used in frameless documents"; | 53 "Geolocation cannot be used in frameless documents"; |
| 54 | 54 |
| 55 Geoposition* CreateGeoposition( | 55 Position* CreatePosition(const device::mojom::blink::Geoposition& position) { |
| 56 const device::mojom::blink::Geoposition& position) { | |
| 57 Coordinates* coordinates = Coordinates::Create( | 56 Coordinates* coordinates = Coordinates::Create( |
| 58 position.latitude, position.longitude, | 57 position.latitude, position.longitude, |
| 59 // Lowest point on land is at approximately -400 meters. | 58 // Lowest point on land is at approximately -400 meters. |
| 60 position.altitude > -10000., position.altitude, position.accuracy, | 59 position.altitude > -10000., position.altitude, position.accuracy, |
| 61 position.altitude_accuracy >= 0., position.altitude_accuracy, | 60 position.altitude_accuracy >= 0., position.altitude_accuracy, |
| 62 position.heading >= 0. && position.heading <= 360., position.heading, | 61 position.heading >= 0. && position.heading <= 360., position.heading, |
| 63 position.speed >= 0., position.speed); | 62 position.speed >= 0., position.speed); |
| 64 return Geoposition::Create(coordinates, | 63 return Position::Create(coordinates, |
| 65 ConvertSecondsToDOMTimeStamp(position.timestamp)); | 64 ConvertSecondsToDOMTimeStamp(position.timestamp)); |
| 66 } | 65 } |
| 67 | 66 |
| 68 PositionError* CreatePositionError( | 67 PositionError* CreatePositionError( |
| 69 device::mojom::blink::Geoposition::ErrorCode mojom_error_code, | 68 device::mojom::blink::Geoposition::ErrorCode mojom_error_code, |
| 70 const String& error) { | 69 const String& error) { |
| 71 PositionError::ErrorCode error_code = PositionError::kPositionUnavailable; | 70 PositionError::ErrorCode error_code = PositionError::kPositionUnavailable; |
| 72 switch (mojom_error_code) { | 71 switch (mojom_error_code) { |
| 73 case device::mojom::blink::Geoposition::ErrorCode::PERMISSION_DENIED: | 72 case device::mojom::blink::Geoposition::ErrorCode::PERMISSION_DENIED: |
| 74 error_code = PositionError::kPermissionDenied; | 73 error_code = PositionError::kPermissionDenied; |
| 75 break; | 74 break; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 pending_for_permission_notifiers_.Clear(); | 329 pending_for_permission_notifiers_.Clear(); |
| 331 } | 330 } |
| 332 | 331 |
| 333 void Geolocation::SendError(GeoNotifierVector& notifiers, | 332 void Geolocation::SendError(GeoNotifierVector& notifiers, |
| 334 PositionError* error) { | 333 PositionError* error) { |
| 335 for (GeoNotifier* notifier : notifiers) | 334 for (GeoNotifier* notifier : notifiers) |
| 336 notifier->RunErrorCallback(error); | 335 notifier->RunErrorCallback(error); |
| 337 } | 336 } |
| 338 | 337 |
| 339 void Geolocation::SendPosition(GeoNotifierVector& notifiers, | 338 void Geolocation::SendPosition(GeoNotifierVector& notifiers, |
| 340 Geoposition* position) { | 339 Position* position) { |
| 341 for (GeoNotifier* notifier : notifiers) | 340 for (GeoNotifier* notifier : notifiers) |
| 342 notifier->RunSuccessCallback(position); | 341 notifier->RunSuccessCallback(position); |
| 343 } | 342 } |
| 344 | 343 |
| 345 void Geolocation::StopTimer(GeoNotifierVector& notifiers) { | 344 void Geolocation::StopTimer(GeoNotifierVector& notifiers) { |
| 346 for (GeoNotifier* notifier : notifiers) | 345 for (GeoNotifier* notifier : notifiers) |
| 347 notifier->StopTimer(); | 346 notifier->StopTimer(); |
| 348 } | 347 } |
| 349 | 348 |
| 350 void Geolocation::StopTimersForOneShots() { | 349 void Geolocation::StopTimersForOneShots() { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 | 529 |
| 531 void Geolocation::QueryNextPosition() { | 530 void Geolocation::QueryNextPosition() { |
| 532 geolocation_service_->QueryNextPosition(ConvertToBaseCallback( | 531 geolocation_service_->QueryNextPosition(ConvertToBaseCallback( |
| 533 WTF::Bind(&Geolocation::OnPositionUpdated, WrapPersistent(this)))); | 532 WTF::Bind(&Geolocation::OnPositionUpdated, WrapPersistent(this)))); |
| 534 } | 533 } |
| 535 | 534 |
| 536 void Geolocation::OnPositionUpdated( | 535 void Geolocation::OnPositionUpdated( |
| 537 device::mojom::blink::GeopositionPtr position) { | 536 device::mojom::blink::GeopositionPtr position) { |
| 538 disconnected_geolocation_service_ = false; | 537 disconnected_geolocation_service_ = false; |
| 539 if (position->valid) { | 538 if (position->valid) { |
| 540 last_position_ = CreateGeoposition(*position); | 539 last_position_ = CreatePosition(*position); |
| 541 PositionChanged(); | 540 PositionChanged(); |
| 542 } else { | 541 } else { |
| 543 HandleError( | 542 HandleError( |
| 544 CreatePositionError(position->error_code, position->error_message)); | 543 CreatePositionError(position->error_code, position->error_message)); |
| 545 } | 544 } |
| 546 if (!disconnected_geolocation_service_) | 545 if (!disconnected_geolocation_service_) |
| 547 QueryNextPosition(); | 546 QueryNextPosition(); |
| 548 } | 547 } |
| 549 | 548 |
| 550 void Geolocation::PageVisibilityChanged() { | 549 void Geolocation::PageVisibilityChanged() { |
| 551 UpdateGeolocationServiceConnection(); | 550 UpdateGeolocationServiceConnection(); |
| 552 } | 551 } |
| 553 | 552 |
| 554 void Geolocation::OnGeolocationConnectionError() { | 553 void Geolocation::OnGeolocationConnectionError() { |
| 555 PositionError* error = PositionError::Create( | 554 PositionError* error = PositionError::Create( |
| 556 PositionError::kPositionUnavailable, kFailedToStartServiceErrorMessage); | 555 PositionError::kPositionUnavailable, kFailedToStartServiceErrorMessage); |
| 557 error->SetIsFatal(true); | 556 error->SetIsFatal(true); |
| 558 HandleError(error); | 557 HandleError(error); |
| 559 } | 558 } |
| 560 | 559 |
| 561 void Geolocation::OnPermissionConnectionError() { | 560 void Geolocation::OnPermissionConnectionError() { |
| 562 OnGeolocationPermissionUpdated(mojom::blink::PermissionStatus::DENIED); | 561 OnGeolocationPermissionUpdated(mojom::blink::PermissionStatus::DENIED); |
| 563 } | 562 } |
| 564 | 563 |
| 565 } // namespace blink | 564 } // namespace blink |
| OLD | NEW |