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

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

Issue 256843004: Get the WebGeolocationClient from WebFrameClient instead of WebViewClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fix linking errors Created 6 years, 6 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 /* 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 10 matching lines...) Expand all
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 27
28 #include "modules/geolocation/GeolocationController.h" 28 #include "modules/geolocation/GeolocationController.h"
29 29
30 #include "core/inspector/InspectorController.h" 30 #include "core/inspector/InspectorController.h"
31 #include "core/page/Page.h"
31 #include "modules/geolocation/GeolocationClient.h" 32 #include "modules/geolocation/GeolocationClient.h"
32 #include "modules/geolocation/GeolocationError.h" 33 #include "modules/geolocation/GeolocationError.h"
33 #include "modules/geolocation/GeolocationInspectorAgent.h" 34 #include "modules/geolocation/GeolocationInspectorAgent.h"
34 #include "modules/geolocation/GeolocationPosition.h" 35 #include "modules/geolocation/GeolocationPosition.h"
35 36
36 namespace WebCore { 37 namespace WebCore {
37 38
38 GeolocationController::GeolocationController(Page& page, GeolocationClient* clie nt) 39 GeolocationController::GeolocationController(LocalFrame& frame, GeolocationClien t* client)
39 : PageLifecycleObserver(&page) 40 : PageLifecycleObserver(frame.page())
40 , m_client(client) 41 , m_client(client)
41 , m_hasClientForTest(false) 42 , m_hasClientForTest(false)
42 , m_isClientUpdating(false) 43 , m_isClientUpdating(false)
43 , m_inspectorAgent() 44 , m_inspectorAgent()
44 { 45 {
45 OwnPtr<GeolocationInspectorAgent> geolocationAgent(GeolocationInspectorAgent ::create(this)); 46 // FIXME: Once GeolocationInspectorAgent is per frame, there will be a 1:1 r elationship between
46 m_inspectorAgent = geolocationAgent.get(); 47 // it and this class. Until then, there's one GeolocationInspectorAgent per page that the main
47 page.inspectorController().registerModuleAgent(geolocationAgent.release()); 48 // frame is responsible for creating.
49 if (frame.isMainFrame()) {
50 OwnPtr<GeolocationInspectorAgent> geolocationAgent(GeolocationInspectorA gent::create());
51 m_inspectorAgent = geolocationAgent.get();
52 frame.page()->inspectorController().registerModuleAgent(geolocationAgent .release());
53 } else {
54 m_inspectorAgent = GeolocationController::from(frame.page()->mainFrame() )->m_inspectorAgent;
55 }
56
57 m_inspectorAgent->AddController(this);
58
59 if (!frame.isMainFrame()) {
60 // internals.setGeolocationClientMock is per page.
61 GeolocationController* mainController = GeolocationController::from(fram e.page()->mainFrame());
62 if (mainController->hasClientForTest())
63 setClientForTest(mainController->client());
64 }
48 } 65 }
49 66
50 void GeolocationController::startUpdatingIfNeeded() 67 void GeolocationController::startUpdatingIfNeeded()
51 { 68 {
52 if (m_isClientUpdating) 69 if (m_isClientUpdating)
53 return; 70 return;
54 m_isClientUpdating = true; 71 m_isClientUpdating = true;
55 m_client->startUpdating(); 72 m_client->startUpdating();
56 } 73 }
57 74
58 void GeolocationController::stopUpdatingIfNeeded() 75 void GeolocationController::stopUpdatingIfNeeded()
59 { 76 {
60 if (!m_isClientUpdating) 77 if (!m_isClientUpdating)
61 return; 78 return;
62 m_isClientUpdating = false; 79 m_isClientUpdating = false;
63 m_client->stopUpdating(); 80 m_client->stopUpdating();
64 } 81 }
65 82
66 GeolocationController::~GeolocationController() 83 GeolocationController::~GeolocationController()
67 { 84 {
68 ASSERT(m_observers.isEmpty()); 85 ASSERT(m_observers.isEmpty());
86 if (page())
87 m_inspectorAgent->RemoveController(this);
88
89 if (m_hasClientForTest)
90 m_client->controllerForTestRemoved(this);
69 } 91 }
70 92
71 void GeolocationController::willBeDestroyed() 93 void GeolocationController::willBeDestroyed()
72 { 94 {
73 if (m_client) 95 if (m_client)
74 m_client->geolocationDestroyed(); 96 m_client->geolocationDestroyed();
75 } 97 }
76 98
77 PassOwnPtrWillBeRawPtr<GeolocationController> GeolocationController::create(Page & page, GeolocationClient* client) 99 PassOwnPtrWillBeRawPtr<GeolocationController> GeolocationController::create(Loca lFrame& frame, GeolocationClient* client)
78 { 100 {
79 return adoptPtrWillBeNoop(new GeolocationController(page, client)); 101 return adoptPtrWillBeNoop(new GeolocationController(frame, client));
80 } 102 }
81 103
82 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc curacy) 104 void GeolocationController::addObserver(Geolocation* observer, bool enableHighAc curacy)
83 { 105 {
84 // This may be called multiple times with the same observer, though removeOb server() 106 // This may be called multiple times with the same observer, though removeOb server()
85 // is called only once with each. 107 // is called only once with each.
86 bool wasEmpty = m_observers.isEmpty(); 108 bool wasEmpty = m_observers.isEmpty();
87 m_observers.add(observer); 109 m_observers.add(observer);
88 if (enableHighAccuracy) 110 if (enableHighAccuracy)
89 m_highAccuracyObservers.add(observer); 111 m_highAccuracyObservers.add(observer);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 if (!m_client) 176 if (!m_client)
155 return 0; 177 return 0;
156 178
157 return m_client->lastPosition(); 179 return m_client->lastPosition();
158 } 180 }
159 181
160 void GeolocationController::setClientForTest(GeolocationClient* client) 182 void GeolocationController::setClientForTest(GeolocationClient* client)
161 { 183 {
162 m_client = client; 184 m_client = client;
163 m_hasClientForTest = true; 185 m_hasClientForTest = true;
186
187 client->controllerForTestAdded(this);
164 } 188 }
165 189
166 void GeolocationController::pageVisibilityChanged() 190 void GeolocationController::pageVisibilityChanged()
167 { 191 {
168 if (m_observers.isEmpty() || !m_client) 192 if (m_observers.isEmpty() || !m_client)
169 return; 193 return;
170 194
171 if (page() && page()->visibilityState() == PageVisibilityStateVisible) 195 if (page() && page()->visibilityState() == PageVisibilityStateVisible)
172 startUpdatingIfNeeded(); 196 startUpdatingIfNeeded();
173 else 197 else
174 stopUpdatingIfNeeded(); 198 stopUpdatingIfNeeded();
175 } 199 }
176 200
177 const char* GeolocationController::supplementName() 201 const char* GeolocationController::supplementName()
178 { 202 {
179 return "GeolocationController"; 203 return "GeolocationController";
180 } 204 }
181 205
182 void GeolocationController::trace(Visitor* visitor) 206 void GeolocationController::trace(Visitor* visitor)
183 { 207 {
184 visitor->trace(m_lastPosition); 208 visitor->trace(m_lastPosition);
185 visitor->trace(m_observers); 209 visitor->trace(m_observers);
186 visitor->trace(m_highAccuracyObservers); 210 visitor->trace(m_highAccuracyObservers);
187 WillBeHeapSupplement<Page>::trace(visitor); 211 WillBeHeapSupplement<LocalFrame>::trace(visitor);
188 } 212 }
189 213
190 void provideGeolocationTo(Page& page, GeolocationClient* client) 214 void provideGeolocationTo(LocalFrame& frame, GeolocationClient* client)
191 { 215 {
192 WillBeHeapSupplement<Page>::provideTo(page, GeolocationController::supplemen tName(), GeolocationController::create(page, client)); 216 WillBeHeapSupplement<LocalFrame>::provideTo(frame, GeolocationController::su pplementName(), GeolocationController::create(frame, client));
193 } 217 }
194 218
195 } // namespace WebCore 219 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698