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 16 matching lines...) Expand all Loading... | |
27 #include "modules/geolocation/GeolocationController.h" | 27 #include "modules/geolocation/GeolocationController.h" |
28 | 28 |
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 : m_client(client) | 37 : PageLifecycleObserver(page) |
38 , m_client(client) | |
38 , m_page(page) | 39 , m_page(page) |
abarth-chromium
2013/10/15 20:57:50
Can we delete m_page and just use the one in PageL
Inactive
2013/10/15 21:32:09
Done.
| |
39 { | 40 { |
40 } | 41 } |
41 | 42 |
42 GeolocationController::~GeolocationController() | 43 GeolocationController::~GeolocationController() |
43 { | 44 { |
44 ASSERT(m_observers.isEmpty()); | 45 ASSERT(m_observers.isEmpty()); |
45 | 46 |
46 if (m_client) | 47 if (m_client) |
47 m_client->geolocationDestroyed(); | 48 m_client->geolocationDestroyed(); |
48 } | 49 } |
49 | 50 |
50 PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, Geol ocationClient* client) | 51 PassOwnPtr<GeolocationController> GeolocationController::create(Page* page, Geol ocationClient* client) |
51 { | 52 { |
52 return adoptPtr(new GeolocationController(page, client)); | 53 return adoptPtr(new GeolocationController(page, client)); |
53 } | 54 } |
54 | 55 |
55 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc curacy) | 56 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc curacy) |
56 { | 57 { |
57 // This may be called multiple times with the same observer, though removeOb server() | 58 // This may be called multiple times with the same observer, though removeOb server() |
58 // is called only once with each. | 59 // is called only once with each. |
59 bool wasEmpty = m_observers.isEmpty(); | 60 bool wasEmpty = m_observers.isEmpty(); |
60 m_observers.add(observer); | 61 m_observers.add(observer); |
61 if (enableHighAccuracy) | 62 if (enableHighAccuracy) |
62 m_highAccuracyObservers.add(observer); | 63 m_highAccuracyObservers.add(observer); |
63 | 64 |
64 if (m_client) { | 65 if (m_client) { |
65 if (enableHighAccuracy) | 66 if (enableHighAccuracy) |
66 m_client->setEnableHighAccuracy(true); | 67 m_client->setEnableHighAccuracy(true); |
67 if (wasEmpty) | 68 if (wasEmpty && page()->visibilityState() == PageVisibilityStateVisible) |
68 m_client->startUpdating(); | 69 m_client->startUpdating(); |
69 } | 70 } |
70 } | 71 } |
71 | 72 |
72 void GeolocationController::removeObserver(Geolocation* observer) | 73 void GeolocationController::removeObserver(Geolocation* observer) |
73 { | 74 { |
74 if (!m_observers.contains(observer)) | 75 if (!m_observers.contains(observer)) |
75 return; | 76 return; |
76 | 77 |
77 m_observers.remove(observer); | 78 m_observers.remove(observer); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 { | 124 { |
124 if (m_lastPosition.get()) | 125 if (m_lastPosition.get()) |
125 return m_lastPosition.get(); | 126 return m_lastPosition.get(); |
126 | 127 |
127 if (!m_client) | 128 if (!m_client) |
128 return 0; | 129 return 0; |
129 | 130 |
130 return m_client->lastPosition(); | 131 return m_client->lastPosition(); |
131 } | 132 } |
132 | 133 |
134 void GeolocationController::pageVisibilityChanged() | |
135 { | |
136 if (m_observers.isEmpty() || !m_client) | |
137 return; | |
138 | |
139 if (page()->visibilityState() == PageVisibilityStateVisible) | |
140 m_client->startUpdating(); | |
141 else | |
142 m_client->stopUpdating(); | |
143 } | |
144 | |
133 const char* GeolocationController::supplementName() | 145 const char* GeolocationController::supplementName() |
134 { | 146 { |
135 return "GeolocationController"; | 147 return "GeolocationController"; |
136 } | 148 } |
137 | 149 |
138 void provideGeolocationTo(Page* page, GeolocationClient* client) | 150 void provideGeolocationTo(Page* page, GeolocationClient* client) |
139 { | 151 { |
140 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), G eolocationController::create(page, client)); | 152 Supplement<Page>::provideTo(page, GeolocationController::supplementName(), G eolocationController::create(page, client)); |
141 } | 153 } |
142 | 154 |
143 } // namespace WebCore | 155 } // namespace WebCore |
OLD | NEW |