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

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

Issue 620343002: DevTools: Remove geolocation override from renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 13 matching lines...) Expand all
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 "core/page/Page.h"
32 #include "modules/geolocation/GeolocationClient.h" 32 #include "modules/geolocation/GeolocationClient.h"
33 #include "modules/geolocation/GeolocationError.h" 33 #include "modules/geolocation/GeolocationError.h"
34 #include "modules/geolocation/GeolocationInspectorAgent.h"
35 #include "modules/geolocation/GeolocationPosition.h" 34 #include "modules/geolocation/GeolocationPosition.h"
36 35
37 namespace blink { 36 namespace blink {
38 37
39 GeolocationController::GeolocationController(LocalFrame& frame, GeolocationClien t* client) 38 GeolocationController::GeolocationController(LocalFrame& frame, GeolocationClien t* client)
40 : PageLifecycleObserver(frame.page()) 39 : PageLifecycleObserver(frame.page())
41 , m_client(client) 40 , m_client(client)
42 , m_hasClientForTest(false) 41 , m_hasClientForTest(false)
43 , m_isClientUpdating(false) 42 , m_isClientUpdating(false)
44 , m_inspectorAgent(nullptr)
45 { 43 {
46 // FIXME: Once GeolocationInspectorAgent is per frame, there will be a 1:1 r elationship between
47 // it and this class. Until then, there's one GeolocationInspectorAgent per page that the main
48 // frame is responsible for creating.
49 if (frame.isMainFrame()) {
50 OwnPtrWillBeRawPtr<GeolocationInspectorAgent> geolocationAgent(Geolocati onInspectorAgent::create());
51 m_inspectorAgent = geolocationAgent.get();
52 frame.page()->inspectorController().registerModuleAgent(geolocationAgent .release());
53 } else if (frame.page()->mainFrame()->isLocalFrame()) {
54 m_inspectorAgent = GeolocationController::from(frame.page()->deprecatedL ocalMainFrame())->m_inspectorAgent;
55 }
56
57 // m_inspectorAgent is 0 for out of process iframe instantiations, since ins pector is currently unable
58 // to handle that scenario.
59 if (m_inspectorAgent)
60 m_inspectorAgent->addController(this);
61
62 if (!frame.isMainFrame() && frame.page()->mainFrame()->isLocalFrame()) { 44 if (!frame.isMainFrame() && frame.page()->mainFrame()->isLocalFrame()) {
63 // internals.setGeolocationClientMock is per page. 45 // internals.setGeolocationClientMock is per page.
64 GeolocationController* mainController = GeolocationController::from(fram e.page()->deprecatedLocalMainFrame()); 46 GeolocationController* mainController = GeolocationController::from(fram e.page()->deprecatedLocalMainFrame());
65 if (mainController->hasClientForTest()) 47 if (mainController->hasClientForTest())
66 setClientForTest(mainController->client()); 48 setClientForTest(mainController->client());
67 } 49 }
68 } 50 }
69 51
70 void GeolocationController::startUpdatingIfNeeded() 52 void GeolocationController::startUpdatingIfNeeded()
71 { 53 {
72 if (m_isClientUpdating) 54 if (m_isClientUpdating)
73 return; 55 return;
74 m_isClientUpdating = true; 56 m_isClientUpdating = true;
75 m_client->startUpdating(); 57 m_client->startUpdating();
76 } 58 }
77 59
78 void GeolocationController::stopUpdatingIfNeeded() 60 void GeolocationController::stopUpdatingIfNeeded()
79 { 61 {
80 if (!m_isClientUpdating) 62 if (!m_isClientUpdating)
81 return; 63 return;
82 m_isClientUpdating = false; 64 m_isClientUpdating = false;
83 m_client->stopUpdating(); 65 m_client->stopUpdating();
84 } 66 }
85 67
86 GeolocationController::~GeolocationController() 68 GeolocationController::~GeolocationController()
87 { 69 {
88 ASSERT(m_observers.isEmpty()); 70 ASSERT(m_observers.isEmpty());
89 #if !ENABLE(OILPAN) 71 #if !ENABLE(OILPAN)
90 if (page() && m_inspectorAgent) {
91 m_inspectorAgent->removeController(this);
92 m_inspectorAgent = nullptr;
93 }
94
95 if (m_hasClientForTest) { 72 if (m_hasClientForTest) {
96 m_client->controllerForTestRemoved(this); 73 m_client->controllerForTestRemoved(this);
97 m_hasClientForTest = false; 74 m_hasClientForTest = false;
98 } 75 }
99 #endif 76 #endif
100 } 77 }
101 78
102 PassOwnPtrWillBeRawPtr<GeolocationController> GeolocationController::create(Loca lFrame& frame, GeolocationClient* client) 79 PassOwnPtrWillBeRawPtr<GeolocationController> GeolocationController::create(Loca lFrame& frame, GeolocationClient* client)
103 { 80 {
104 return adoptPtrWillBeNoop(new GeolocationController(frame, client)); 81 return adoptPtrWillBeNoop(new GeolocationController(frame, client));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 121 }
145 122
146 void GeolocationController::cancelPermissionRequest(Geolocation* geolocation) 123 void GeolocationController::cancelPermissionRequest(Geolocation* geolocation)
147 { 124 {
148 if (m_client) 125 if (m_client)
149 m_client->cancelPermissionRequest(geolocation); 126 m_client->cancelPermissionRequest(geolocation);
150 } 127 }
151 128
152 void GeolocationController::positionChanged(GeolocationPosition* position) 129 void GeolocationController::positionChanged(GeolocationPosition* position)
153 { 130 {
154 position = m_inspectorAgent->overrideGeolocationPosition(position);
155 if (!position) { 131 if (!position) {
156 errorOccurred(GeolocationError::create(GeolocationError::PositionUnavail able, "PositionUnavailable")); 132 errorOccurred(GeolocationError::create(GeolocationError::PositionUnavail able, "PositionUnavailable"));
157 return; 133 return;
158 } 134 }
159 m_lastPosition = position; 135 m_lastPosition = position;
160 HeapVector<Member<Geolocation> > observersVector; 136 HeapVector<Member<Geolocation> > observersVector;
161 copyToVector(m_observers, observersVector); 137 copyToVector(m_observers, observersVector);
162 for (size_t i = 0; i < observersVector.size(); ++i) 138 for (size_t i = 0; i < observersVector.size(); ++i)
163 observersVector[i]->positionChanged(); 139 observersVector[i]->positionChanged();
164 } 140 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 { 183 {
208 return "GeolocationController"; 184 return "GeolocationController";
209 } 185 }
210 186
211 void GeolocationController::trace(Visitor* visitor) 187 void GeolocationController::trace(Visitor* visitor)
212 { 188 {
213 visitor->trace(m_client); 189 visitor->trace(m_client);
214 visitor->trace(m_lastPosition); 190 visitor->trace(m_lastPosition);
215 visitor->trace(m_observers); 191 visitor->trace(m_observers);
216 visitor->trace(m_highAccuracyObservers); 192 visitor->trace(m_highAccuracyObservers);
217 visitor->trace(m_inspectorAgent);
218 WillBeHeapSupplement<LocalFrame>::trace(visitor); 193 WillBeHeapSupplement<LocalFrame>::trace(visitor);
219 } 194 }
220 195
221 void provideGeolocationTo(LocalFrame& frame, GeolocationClient* client) 196 void provideGeolocationTo(LocalFrame& frame, GeolocationClient* client)
222 { 197 {
223 WillBeHeapSupplement<LocalFrame>::provideTo(frame, GeolocationController::su pplementName(), GeolocationController::create(frame, client)); 198 WillBeHeapSupplement<LocalFrame>::provideTo(frame, GeolocationController::su pplementName(), GeolocationController::create(frame, client));
224 } 199 }
225 200
226 } // namespace blink 201 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/geolocation/GeolocationController.h ('k') | Source/modules/geolocation/GeolocationInspectorAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698