| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "core/inspector/InspectorInstrumentation.h" | 29 #include "core/inspector/InspectorInstrumentation.h" |
| 30 #include "modules/geolocation/GeolocationClient.h" | 30 #include "modules/geolocation/GeolocationClient.h" |
| 31 #include "modules/geolocation/GeolocationError.h" | 31 #include "modules/geolocation/GeolocationError.h" |
| 32 #include "modules/geolocation/GeolocationPosition.h" | 32 #include "modules/geolocation/GeolocationPosition.h" |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 GeolocationController::GeolocationController(Page* page, GeolocationClient* clie
nt) | 36 GeolocationController::GeolocationController(Page* page, GeolocationClient* clie
nt) |
| 37 : PageLifecycleObserver(page) | 37 : PageLifecycleObserver(page) |
| 38 , m_client(client) | 38 , m_client(client) |
| 39 , m_isClientUpdating(false) |
| 39 { | 40 { |
| 40 } | 41 } |
| 41 | 42 |
| 43 void GeolocationController::startUpdatingIfNeeded() |
| 44 { |
| 45 if (m_isClientUpdating) |
| 46 return; |
| 47 m_isClientUpdating = true; |
| 48 m_client->startUpdating(); |
| 49 } |
| 50 |
| 51 void GeolocationController::stopUpdatingIfNeeded() |
| 52 { |
| 53 if (!m_isClientUpdating) |
| 54 return; |
| 55 m_isClientUpdating = false; |
| 56 m_client->stopUpdating(); |
| 57 } |
| 58 |
| 42 GeolocationController::~GeolocationController() | 59 GeolocationController::~GeolocationController() |
| 43 { | 60 { |
| 44 ASSERT(m_observers.isEmpty()); | 61 ASSERT(m_observers.isEmpty()); |
| 45 | 62 |
| 46 if (m_client) | 63 if (m_client) |
| 47 m_client->geolocationDestroyed(); | 64 m_client->geolocationDestroyed(); |
| 48 } | 65 } |
| 49 | 66 |
| 50 PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, Geol
ocationClient* client) | 67 PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, Geol
ocationClient* client) |
| 51 { | 68 { |
| 52 return adoptPtr(new GeolocationController(page, client)); | 69 return adoptPtr(new GeolocationController(page, client)); |
| 53 } | 70 } |
| 54 | 71 |
| 55 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc
curacy) | 72 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc
curacy) |
| 56 { | 73 { |
| 57 // This may be called multiple times with the same observer, though removeOb
server() | 74 // This may be called multiple times with the same observer, though removeOb
server() |
| 58 // is called only once with each. | 75 // is called only once with each. |
| 59 bool wasEmpty = m_observers.isEmpty(); | 76 bool wasEmpty = m_observers.isEmpty(); |
| 60 m_observers.add(observer); | 77 m_observers.add(observer); |
| 61 if (enableHighAccuracy) | 78 if (enableHighAccuracy) |
| 62 m_highAccuracyObservers.add(observer); | 79 m_highAccuracyObservers.add(observer); |
| 63 | 80 |
| 64 if (m_client) { | 81 if (m_client) { |
| 65 if (enableHighAccuracy) | 82 if (enableHighAccuracy) |
| 66 m_client->setEnableHighAccuracy(true); | 83 m_client->setEnableHighAccuracy(true); |
| 67 if (wasEmpty && page() && page()->visibilityState() == PageVisibilitySta
teVisible) | 84 if (wasEmpty && page() && page()->visibilityState() == PageVisibilitySta
teVisible) |
| 68 m_client->startUpdating(); | 85 startUpdatingIfNeeded(); |
| 69 } | 86 } |
| 70 } | 87 } |
| 71 | 88 |
| 72 void GeolocationController::removeObserver(Geolocation* observer) | 89 void GeolocationController::removeObserver(Geolocation* observer) |
| 73 { | 90 { |
| 74 if (!m_observers.contains(observer)) | 91 if (!m_observers.contains(observer)) |
| 75 return; | 92 return; |
| 76 | 93 |
| 77 m_observers.remove(observer); | 94 m_observers.remove(observer); |
| 78 m_highAccuracyObservers.remove(observer); | 95 m_highAccuracyObservers.remove(observer); |
| 79 | 96 |
| 80 if (m_client) { | 97 if (m_client) { |
| 81 if (m_observers.isEmpty()) | 98 if (m_observers.isEmpty()) |
| 82 m_client->stopUpdating(); | 99 stopUpdatingIfNeeded(); |
| 83 else if (m_highAccuracyObservers.isEmpty()) | 100 else if (m_highAccuracyObservers.isEmpty()) |
| 84 m_client->setEnableHighAccuracy(false); | 101 m_client->setEnableHighAccuracy(false); |
| 85 } | 102 } |
| 86 } | 103 } |
| 87 | 104 |
| 88 void GeolocationController::requestPermission(Geolocation* geolocation) | 105 void GeolocationController::requestPermission(Geolocation* geolocation) |
| 89 { | 106 { |
| 90 if (m_client) | 107 if (m_client) |
| 91 m_client->requestPermission(geolocation); | 108 m_client->requestPermission(geolocation); |
| 92 } | 109 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 146 |
| 130 return m_client->lastPosition(); | 147 return m_client->lastPosition(); |
| 131 } | 148 } |
| 132 | 149 |
| 133 void GeolocationController::pageVisibilityChanged() | 150 void GeolocationController::pageVisibilityChanged() |
| 134 { | 151 { |
| 135 if (m_observers.isEmpty() || !m_client) | 152 if (m_observers.isEmpty() || !m_client) |
| 136 return; | 153 return; |
| 137 | 154 |
| 138 if (page() && page()->visibilityState() == PageVisibilityStateVisible) | 155 if (page() && page()->visibilityState() == PageVisibilityStateVisible) |
| 139 m_client->startUpdating(); | 156 startUpdatingIfNeeded(); |
| 140 else | 157 else |
| 141 m_client->stopUpdating(); | 158 stopUpdatingIfNeeded(); |
| 142 } | 159 } |
| 143 | 160 |
| 144 const char* GeolocationController::supplementName() | 161 const char* GeolocationController::supplementName() |
| 145 { | 162 { |
| 146 return "GeolocationController"; | 163 return "GeolocationController"; |
| 147 } | 164 } |
| 148 | 165 |
| 149 void provideGeolocationTo(Page* page, GeolocationClient* client) | 166 void provideGeolocationTo(Page* page, GeolocationClient* client) |
| 150 { | 167 { |
| 151 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), G
eolocationController::create(page, client)); | 168 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), G
eolocationController::create(page, client)); |
| 152 } | 169 } |
| 153 | 170 |
| 154 } // namespace WebCore | 171 } // namespace WebCore |
| OLD | NEW |