| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/geolocation/GeolocationInspectorAgent.h" | 32 #include "modules/geolocation/GeolocationInspectorAgent.h" |
| 33 | 33 |
| 34 #include "modules/geolocation/GeolocationController.h" | 34 #include "modules/geolocation/GeolocationController.h" |
| 35 | 35 |
| 36 namespace WebCore { | 36 namespace WebCore { |
| 37 | 37 |
| 38 PassOwnPtr<GeolocationInspectorAgent> GeolocationInspectorAgent::create(Geolocat
ionController* controller) | 38 PassOwnPtr<GeolocationInspectorAgent> GeolocationInspectorAgent::create() |
| 39 { | 39 { |
| 40 return adoptPtr(new GeolocationInspectorAgent(controller)); | 40 return adoptPtr(new GeolocationInspectorAgent()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 GeolocationInspectorAgent::~GeolocationInspectorAgent() | 43 GeolocationInspectorAgent::~GeolocationInspectorAgent() |
| 44 { | 44 { |
| 45 } | 45 } |
| 46 | 46 |
| 47 GeolocationInspectorAgent::GeolocationInspectorAgent(GeolocationController* cont
roller) | 47 GeolocationInspectorAgent::GeolocationInspectorAgent() |
| 48 : InspectorBaseAgent<GeolocationInspectorAgent>("Geolocation") | 48 : InspectorBaseAgent<GeolocationInspectorAgent>("Geolocation") |
| 49 , m_controller(controller) | |
| 50 , m_geolocationOverridden(false) | 49 , m_geolocationOverridden(false) |
| 51 { | 50 { |
| 52 } | 51 } |
| 53 | 52 |
| 54 void GeolocationInspectorAgent::setGeolocationOverride(ErrorString* error, const
double* latitude, const double* longitude, const double* accuracy) | 53 void GeolocationInspectorAgent::setGeolocationOverride(ErrorString* error, const
double* latitude, const double* longitude, const double* accuracy) |
| 55 { | 54 { |
| 56 GeolocationPosition* position = m_controller->lastPosition(); | 55 GeolocationPosition* position = (*m_controllers.begin())->lastPosition(); |
| 57 if (!m_geolocationOverridden && position) | 56 if (!m_geolocationOverridden && position) |
| 58 m_platformGeolocationPosition = position; | 57 m_platformGeolocationPosition = position; |
| 59 | 58 |
| 60 m_geolocationOverridden = true; | 59 m_geolocationOverridden = true; |
| 61 if (latitude && longitude && accuracy) | 60 if (latitude && longitude && accuracy) |
| 62 m_geolocationPosition = GeolocationPosition::create(currentTime(), *lati
tude, *longitude, *accuracy); | 61 m_geolocationPosition = GeolocationPosition::create(currentTime(), *lati
tude, *longitude, *accuracy); |
| 63 else | 62 else |
| 64 m_geolocationPosition.clear(); | 63 m_geolocationPosition.clear(); |
| 65 | 64 |
| 66 m_controller->positionChanged(0); // Kick location update. | 65 for (WTF::HashSet<GeolocationController*>::iterator it = m_controllers.begin
(); it != m_controllers.end(); ++it) |
| 66 (*it)->positionChanged(0); // Kick location update. |
| 67 } | 67 } |
| 68 | 68 |
| 69 void GeolocationInspectorAgent::clearGeolocationOverride(ErrorString*) | 69 void GeolocationInspectorAgent::clearGeolocationOverride(ErrorString*) |
| 70 { | 70 { |
| 71 if (!m_geolocationOverridden) | 71 if (!m_geolocationOverridden) |
| 72 return; | 72 return; |
| 73 m_geolocationOverridden = false; | 73 m_geolocationOverridden = false; |
| 74 m_geolocationPosition.clear(); | 74 m_geolocationPosition.clear(); |
| 75 | 75 |
| 76 if (m_platformGeolocationPosition.get()) | 76 if (m_platformGeolocationPosition.get()) { |
| 77 m_controller->positionChanged(m_platformGeolocationPosition.get()); | 77 for (WTF::HashSet<GeolocationController*>::iterator it = m_controllers.b
egin(); it != m_controllers.end(); ++it) |
| 78 (*it)->positionChanged(m_platformGeolocationPosition.get()); |
| 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 80 GeolocationPosition* GeolocationInspectorAgent::overrideGeolocationPosition(Geol
ocationPosition* position) | 82 GeolocationPosition* GeolocationInspectorAgent::overrideGeolocationPosition(Geol
ocationPosition* position) |
| 81 { | 83 { |
| 82 if (m_geolocationOverridden) { | 84 if (m_geolocationOverridden) { |
| 83 if (position) | 85 if (position) |
| 84 m_platformGeolocationPosition = position; | 86 m_platformGeolocationPosition = position; |
| 85 return m_geolocationPosition.get(); | 87 return m_geolocationPosition.get(); |
| 86 } | 88 } |
| 87 return position; | 89 return position; |
| 88 } | 90 } |
| 89 | 91 |
| 92 void GeolocationInspectorAgent::AddController(GeolocationController* controller) |
| 93 { |
| 94 m_controllers.add(controller); |
| 95 } |
| 96 |
| 97 void GeolocationInspectorAgent::RemoveController(GeolocationController* controll
er) |
| 98 { |
| 99 m_controllers.remove(controller); |
| 100 } |
| 101 |
| 90 } // namespace WebCore | 102 } // namespace WebCore |
| OLD | NEW |